21 #include <basic/Tracer.hh>
23 #include <numeric/random/random.hh>
26 #include <utility/vector1.hh>
27 #include <ObjexxFCL/string.functions.hh>
28 #include <utility/io/izstream.hh>
36 #include <basic/options/option.hh>
37 #include <basic/options/keys/out.OptionKeys.gen.hh>
38 #include <basic/options/keys/parser.OptionKeys.gen.hh>
39 #include <basic/options/keys/in.OptionKeys.gen.hh>
41 #include <numeric/xyz.functions.hh>
46 using namespace core::scoring;
48 static basic::Tracer
TR(
"protocols.protein_interface_design.read_patchdock" );
49 static numeric::random::RandomGenerator
RG( 15031972 );
60 namespace protein_interface_design {
62 PatchdockReader::PatchdockReader(){
65 PatchdockReader::~PatchdockReader() {}
68 PatchdockReader::clear_internals()
70 patchdock_fname_ =
"";
71 patchdock_entry_num_ = 0;
72 saved_input_tag_ =
"";
73 saved_native_tag_ =
"";
74 saved_input_pose_ = saved_native_pose_ = NULL;
75 saved_transformations_.clear();
80 PatchdockReader::number_of_patchdock_entries()
82 core::Size const saved_patchdock_entry_num( patchdock_entry_num_ );
83 patchdock_entry_num_ = 1;
84 read_patchdock_entry();
85 patchdock_entry_num_ = saved_patchdock_entry_num;
86 return( saved_transformations_.size() );
92 PatchdockReader::read_patchdock_entry()
94 runtime_assert( patchdock_entry_num_ );
95 if( saved_transformations_.size() )
96 return( saved_transformations_[ patchdock_entry_num_ ] );
98 utility::io::izstream data( patchdock_fname_ );
100 utility_exit_with_message(
"Cannot open patchdock file: " + patchdock_fname_ );
103 bool entries_found(
false );
104 while ( getline( data, line ) ) {
108 t.alpha =
t.beta =
t.gamma = 0;
109 t.translation.zero() ;
111 istringstream line_stream( line );
113 line_stream >> first_field;
115 if( first_field ==
"#" ) { entries_found =
true;
continue; }
116 if( !entries_found )
continue;
117 core::Size const wheres_pipe( line.find_first_of(
"|" ) );
118 if( wheres_pipe == string::npos )
break;;
119 core::Size const transformation_begin( line.find_last_of(
"||" ) + 2 );
120 std::istringstream transData( line.substr( transformation_begin, 10000) );
122 transData >>
t.alpha >>
t.beta >>
t.gamma >> x >> y >> z;
123 if( transData.fail() ) {
124 TR<<
"Error parsing transformation data in line\n"<<line<<std::endl;
125 runtime_assert( !transData.fail() );
127 t.translation.assign( x, y, z );
128 saved_transformations_.push_back(
t );
130 return( saved_transformations_[ patchdock_entry_num_ ] );
150 rotation.xx( cg * cb ); rotation.xy( -sb*sa*cg - sg * ca ); rotation.xz( -sb*ca*cg + sg * sa );
151 rotation.yx( sg * cb ); rotation.yy( -sb*sa*sg + ca*cg ); rotation.yz( -sb*ca*sg - sa*cg );
152 rotation.zx( sb ); rotation.zy( cb*sa ); rotation.zz( cb*ca );
156 for(
core::Size residue=chain_begin; residue<=chain_end; ++residue ) {
161 for(
core::Size atom=atom_begin; atom<=atom_end; ++atom ) {
164 localX = pose.
xyz(
id );
165 localRX = rotation * localX;
171 for(
core::Size residue=chain_begin; residue<=chain_end; ++residue ) {
175 for(
core::Size atom=atom_begin; atom<=atom_end; ++atom ) {
183 using basic::options::option;
184 using namespace basic::options::OptionKeys;
185 if ( option[ in::detect_disulf ].user() ?
186 option[ in::detect_disulf ]() :
200 read_poses( input_pose, dummy_pose, input_tag, dummy_tag );
206 using namespace basic::options;
207 using namespace basic::options::OptionKeys;
209 patchdock_entry_num_ = 0;
210 patchdock_fname_ =
"";
211 bool const patchdock( option[ parser::patchdock ].user() );
213 patchdock_fname_ = option[ parser::patchdock ]();
214 if( patchdock_fname_ ==
"" ) {
215 core::Size const filename_end( input_tag.find_first_of(
"." ) );
217 patchdock_fname_ = input_tag.substr( 0, filename_end ) +
".patchdock";
219 TR<<
"Reading from patchdock file name: "<<patchdock_fname_<<std::endl;
220 bool const patchdock_random_entry( option[ parser::patchdock_random_entry ].user() );
221 core::Size const number_of_entries = number_of_patchdock_entries();
222 if( number_of_entries == 0 )
223 utility_exit_with_message_status(
"No patchdock entries found. Aborting", 0 );
224 if( patchdock_random_entry ) {
227 runtime_assert( entry_num_extrema.size() == 2 );
228 runtime_assert( entry_num_extrema[ 1 ] <= entry_num_extrema[ 2 ] );
229 runtime_assert( entry_num_extrema[ 1 ] > 0 );
231 TR<<number_of_entries<<
" entries in patchdock file "<<patchdock_fname_<<std::endl;
232 entry_num_extrema[ 2 ] = std::min( entry_num_extrema[ 2 ], number_of_entries );
233 TR<<
"sampling a number between "<<entry_num_extrema[ 1 ]<<
" and "<<entry_num_extrema[ 2 ]<<std::endl;
235 patchdock_entry_num_ = (
core::Size ) floor(
RG.uniform() * ( entry_num_extrema[ 2 ] - entry_num_extrema[ 1 ] ) ) + entry_num_extrema[ 1 ];
236 runtime_assert( patchdock_entry_num_ <= entry_num_extrema[ 2 ] );
237 runtime_assert( patchdock_entry_num_ >= entry_num_extrema[ 1 ] );
238 std::stringstream ss;
239 ss <<
"." << patchdock_entry_num_;
240 option[ out::user_tag ].value( ss.str() );
243 core::Size const entrynum_begin( input_tag.find_first_of(
"." ) );
244 core::Size const entrynum_end( input_tag.find_last_of(
"." ) );
245 std::stringstream ss( input_tag.substr( entrynum_begin+1, entrynum_end - entrynum_begin ) );
246 ss >> patchdock_entry_num_;
247 if( patchdock_entry_num_ > number_of_entries ){
248 TR<<
"number of patchdock entries exceeded. You've asked for entry "<< patchdock_entry_num_<<
" but only "<<number_of_entries<<
" entries were found"<<std::endl;
249 utility_exit_with_message_status(
"aborting.", 0 );
251 if( input_tag == native_tag ){
252 input_tag.replace( entrynum_begin, entrynum_end - entrynum_begin + 1,
"." );
253 native_tag.replace( entrynum_begin, entrynum_end - entrynum_begin + 1,
"." );
266 using namespace basic::options;
267 using namespace basic::options::OptionKeys;
269 if( saved_input_tag_ == input_tag && saved_native_tag_ == native_tag )
271 input_pose = *saved_input_pose_;
272 native_pose = *saved_native_pose_;
273 TR<<
"Skipped reading pose from disk"<<std::endl;
277 saved_input_tag_ = input_tag;
278 saved_native_tag_ = native_tag;
279 TR<<
"Reading pose from disk"<<std::endl;
280 if ( option[ in::file::centroid_input ].user() ) {
290 if( option[ in::file::fold_tree ].user() ){
291 std::string const fold_tree_fname( option[ in::file::fold_tree ]() );
292 utility::io::izstream data( fold_tree_fname );
294 TR <<
"Cannot open file: " << fold_tree_fname << std::endl;
295 runtime_assert( data );
298 bool ft_found(
false );
299 while( getline( data, line ) ){
300 if( line.substr(0,10) ==
"FOLD_TREE " ){
301 std::istringstream line_stream( line );
307 TR<<
"Using user-defined fold-tree:\n"<<input_pose.
fold_tree()<<std::endl;
311 runtime_assert( ft_found );
318 read_patchdock( input_tag, native_tag );
320 if( !patchdock_entry_num_ )
return;
321 TR<<
"Reading patchdock entry "<<patchdock_entry_num_<<
" from file: "<<patchdock_fname_<<std::endl;