23 #include <basic/options/option.hh>
32 #include <ObjexxFCL/string.functions.hh>
35 #include <basic/Tracer.hh>
36 #include <utility/io/izstream.hh>
39 #include <utility/file/file_sys_util.hh>
40 #include <numeric/random/random.hh>
50 #include <basic/options/keys/out.OptionKeys.gen.hh>
52 #include <utility/vector1.hh>
56 #ifdef __native_client__
62 static basic::Tracer
tr(
"protocols.simple_filter.ExternalEvaluator");
64 static numeric::random::RandomGenerator
RG(5512489);
67 namespace simple_filters {
74 : evaluation::SingleValuePoseEvaluator<core::
Real>( tag ),
80 #ifndef __native_client__
82 using namespace basic::options;
83 if ( !option[ OptionKeys::out::path::scratch ].user() ) {
84 tr.Warning <<
"******************************************************************************************************\n"
85 <<
" no scratch dir defined \n" <<
" use -out:path:scratch \n"
86 <<
"******************************************************************************************************\n" << endl;
87 utility_exit_with_message(
" define your scratch dir with -out:path:scratch " );
90 scratch_dir_ = option[ OptionKeys::out::path::scratch ]();
94 string const tmp_file_name (
"_ExternalEvaluator_"+
name( 1 ));
97 if ( option[ OptionKeys::out::file::silent ].user() ) {
98 dir = option[ OptionKeys::out::file::silent ]();
105 string dircmd(
"echo `dirname "+dir+
"` | sed s@/@_@g");
106 FILE* get_dir = popen(dircmd.c_str(),
"r");
108 fgets(buf,500,get_dir);
109 buf[strlen(buf)-1]=
'\0';
110 sub_work_dir =
string( buf )+
"_"+tmp_file_name;
113 sub_work_dir = sub_work_dir+
"_"+ ObjexxFCL::string_of(
RG.random_range(0, 999999) );
117 MPI_Comm_rank( MPI_COMM_WORLD, (
int* )( &rank_ ) );
118 sub_work_dir =
"mpi_" + ObjexxFCL::string_of( rank_ ) + sub_work_dir;
123 string dircmd(
"pwd | sed s@/@_@g");
124 FILE* get_dir = popen(dircmd.c_str(),
"r");
126 fgets(buf,500,get_dir);
127 buf[strlen(buf)-1]=
'\0';
128 string tmp_id =
string( buf );
129 work_dir_ = tmp_id.substr( max(0, (
int)tmp_id.size()-40) );
135 tr.Info <<
"create scratch space... : " <<
work_dir_ << std::endl;
138 tr.Info <<
"create scratch space... : " <<
work_dir_ << std::endl;
147 using namespace basic::options;
153 string const pose_file_name(
work_dir_+
string(
"/__POSE.pdb") );
154 string const result_file_name(
work_dir_+
string(
"/__RESULT") );
155 std::ofstream pose_stream(pose_file_name.c_str() );
156 if ( !pose_stream )
tr.Error <<
"can't write pose to file " << pose_file_name << std::endl;
157 pose.
dump_pdb( pose_stream, pose_file_name );
159 tr.Info <<
"write pose : " << pose_file_name << endl;
160 tr.Info <<
"execute command: "<< command_buf << endl;
161 int ret(system(command_buf.c_str()));
163 tr.Warning <<
"Applying the external evaluator failed!" << endl;
170 utility::io::izstream result_file( result_file_name );
171 result_file >> result;
174 ret = system( delete_result_cmd.c_str() );
176 tr.Warning <<
"Deleting the file '" <<
work_dir_ <<
"/__RESULT' failed!" << endl;
179 tr.Debug <<
"obtained result: " << result << endl;
185 int const ret(system(command.c_str()));
187 tr.Warning <<
"Deleting work directory '" <<
work_dir_ <<
"' failed!" << endl;