19 #include <utility/string_util.hh>
22 #include <basic/Tracer.hh>
24 #include <utility/vector1.hh>
86 #include <utility/excn/Exceptions.hh>
87 #include <utility/file/file_sys_util.hh>
89 #include <numeric/random/random.hh>
90 #include <numeric/xyzVector.hh>
91 #include <numeric/xyz.functions.hh>
92 #include <numeric/model_quality/rms.hh>
98 #include <utility/tag/Tag.hh>
101 namespace protocols {
102 namespace seeded_abinitio {
104 using namespace core;
105 using namespace scoring::constraints;
106 using namespace protocols::moves;
108 static basic::Tracer
TR(
"protocols.seeded_abinitio.PlaceFragments" );
111 PlaceFragmentsCreator::keyname()
const
113 return PlaceFragmentsCreator::mover_name();
117 PlaceFragmentsCreator::create_mover()
const {
118 return new PlaceFragments;
122 PlaceFragmentsCreator::mover_name()
124 return "PlaceFragments";
130 protocols::moves::
Mover( PlaceFragmentsCreator::mover_name() )
140 using namespace core::fragment;
146 Size position = (*i)->start();
159 Size seq_start = numeric::random::random_range( 0,
ss_.size() -
fsize_ );
163 for(
Size i = seq_start ; i <
ss_.size(); ++ i )
166 std::cout <<
"picking fragments for secondary structure "<< ss_sub << std::endl;
195 R.xx() = R.yy() = R.zz() = 1;
196 R.xy() = R.yx() = R.zx() = R.zy() = R.yz() = R.xz() = 0;
210 frame.
apply( toget, pose_copy );
213 core::Size aln_start = numeric::random::random_range(frag.start(), len-aln_len+frag.start() );
217 ObjexxFCL::FArray2D< core::Real > final_coords( 3, 4*aln_len );
218 ObjexxFCL::FArray2D< core::Real > init_coords( 3, 4*aln_len );
220 for (
int ii=0; ii<(
int)aln_len; ++ii) {
226 preT += x_1+x_2+x_3+x_4;
232 postT += y_1+y_2+y_3+y_4;
234 for (
int j=0; j<3; ++j) {
235 init_coords(j+1,4*ii+1) = x_1[j];
236 init_coords(j+1,4*ii+2) = x_2[j];
237 init_coords(j+1,4*ii+3) = x_3[j];
238 init_coords(j+1,4*ii+4) = x_4[j];
239 final_coords(j+1,4*ii+1) = y_1[j];
240 final_coords(j+1,4*ii+2) = y_2[j];
241 final_coords(j+1,4*ii+3) = y_3[j];
242 final_coords(j+1,4*ii+4) = y_4[j];
247 for (
int i=1; i<=(
int)4*len; ++i) {
248 for (
int j=0; j<3; ++j ) {
249 init_coords(j+1,i) -= preT[j];
250 final_coords(j+1,i) -= postT[j];
256 ObjexxFCL::FArray1D< numeric::Real > ww( 4*len, 1.0 );
257 ObjexxFCL::FArray2D< numeric::Real > uu( 3, 3, 0.0 );
260 numeric::model_quality::findUU( init_coords, final_coords, ww, 4*len, uu, ctx );
261 R.xx( uu(1,1) ); R.xy( uu(2,1) ); R.xz( uu(3,1) );
262 R.yx( uu(1,2) ); R.yy( uu(2,2) ); R.yz( uu(3,2) );
263 R.zx( uu(1,3) ); R.zy( uu(2,3) ); R.zz( uu(3,3) );
269 for (
int i=frag.start(); i<=frag.stop(); ++i) {
272 pose.
set_xyz( tgt, postT + (R*(pose_copy.
xyz( src )-preT)) );
288 bool nterm = (start == seq_start );
295 ObjexxFCL::FArray1D< numeric::Real > ww( 2*4*aln_len, 1.0 );
296 ObjexxFCL::FArray2D< numeric::Real > uu( 3, 3, 0.0 );
299 for (
int tries = 0; tries<100; ++tries) {
306 ObjexxFCL::FArray2D< core::Real > init_coords( 3, 2*4*aln_len );
307 for (
int ii=-aln_len; ii<aln_len; ++ii) {
308 int i = (ii>=0) ? (nterm?len-ii-1:ii) : (cterm?-ii-1:len+ii);
314 com1 += x_1+x_2+x_3+x_4;
316 for (
int j=0; j<3; ++j) {
317 init_coords(j+1,4*(ii+aln_len)+1) = x_1[j];
318 init_coords(j+1,4*(ii+aln_len)+2) = x_2[j];
319 init_coords(j+1,4*(ii+aln_len)+3) = x_3[j];
320 init_coords(j+1,4*(ii+aln_len)+4) = x_4[j];
323 com1 /= 2.0*4.0*aln_len;
324 for (
int ii=0; ii<2*4*aln_len; ++ii) {
325 for (
int j=0; j<3; ++j ) init_coords(j+1,ii+1) -= com1[j];
329 frame.
apply( toget, pose_copy );
332 ObjexxFCL::FArray2D< core::Real > final_coords( 3, 2*4*aln_len );
333 for (
int ii=-aln_len; ii<aln_len; ++ii) {
334 int i = (ii>=0) ? (nterm?len-ii-1:ii) : (cterm?-ii-1:len+ii);
339 com2 += x_1+x_2+x_3+x_4;
340 for (
int j=0; j<3; ++j) {
341 final_coords(j+1,4*(ii+aln_len)+1) = x_1[j];
342 final_coords(j+1,4*(ii+aln_len)+2) = x_2[j];
343 final_coords(j+1,4*(ii+aln_len)+3) = x_3[j];
344 final_coords(j+1,4*(ii+aln_len)+4) = x_4[j];
347 com2 /= 2.0*4.0*aln_len;
348 for (
int ii=0; ii<2*4*aln_len; ++ii) {
349 for (
int j=0; j<3; ++j ) final_coords(j+1,ii+1) -= com2[j];
357 numeric::model_quality::findUU( final_coords, init_coords, ww, 2*4*aln_len, uu, ctx );
358 numeric::model_quality::calc_rms_fast( rms, final_coords, init_coords, ww, 2*4*aln_len, ctx );
360 std::cout <<
"try " << tries <<
" rms " << rms << std::endl;
362 if (rms < 0.5)
break;
363 if (tries >= 20 && rms < 1)
break;
364 if (tries >= 40 && rms < 2)
break;
365 if (tries >= 60 && rms < 3)
break;
368 R.xx( uu(1,1) ); R.xy( uu(2,1) ); R.xz( uu(3,1) );
369 R.yx( uu(1,2) ); R.yy( uu(2,2) ); R.yz( uu(3,2) );
370 R.zx( uu(1,3) ); R.zy( uu(2,3) ); R.zz( uu(3,3) );
374 for (
Size i = 0; i < len; ++i ) {
377 pose.
set_xyz(
id, R * ( pose_copy.
xyz(
id) - com2) + com1 );
392 res.push_back( resnum);
393 TR<<
"parsed: "<<key<<std::endl;
414 Size stub = parsed_residues[1];
415 std::cout <<
"stub: " << stub <<std::endl;
423 Size insert_start = pose.chain_begin( num_chains );
425 runtime_assert( insert_start <= insert_stop );
431 std::cout <<
"start frags = fragments->min_pos:"<< insert_frags_pos <<
433 "\nfragset for positions = nr_frames " <<
fragments_->nr_frames() << std::endl;
437 std::cout <<
"position after iterator: " << position << std::endl;
449 int in_position = stub_pos;
452 core::Size insert_pos = max_pos - numeric::random::random_range(fsize_/2 -1, fsize_/2);
453 std::cout <<
"insert position before apply frags : " << insert_pos << std::endl;
456 insert_pos = std::min( insert_pos, insert_stop - fsize_-1);
457 insert_pos = std::max( (
int)insert_pos, (
int)insert_start);
460 for (boost::unordered_map<core::Size, core::fragment::Frame>::iterator iter =
library_.begin() ; iter !=
library_.end() ; ++iter){
461 std::cout <<
" frame " << (*iter).first <<
" len: " <<
library_[insert_pos].length() << std::endl;
465 apply_frag (pose,
library_[insert_pos]);
466 std::cout <<
"applying fragments on position: " << insert_pos << std::endl;
473 return PlaceFragmentsCreator::mover_name();
486 using namespace filters;
488 if( tag->hasOption (
"fragments" )){
489 string fragments_file = tag->getOption<
string>(
"fragments");
497 if( tag->!hasOption(
"secstr") || !hasOption(
"fragments") )
498 throw utility::excn::EXCN_RosettaScriptsOption(
"either need to specify secondary structure or supply fragements!!");
507 if( tag->hasOption(
"stubs") )
513 foreach(
TagPtr const btag, branch_tags ){
515 if( btag->getName() ==
"Seeds" ) {
519 std::pair <std::string,std::string> seedpair;
520 seedpair.first = beginS;
521 TR.Debug <<
"parsing seeds: " << beginS <<
" " <<endS <<std::endl;
522 seedpair.second = endS;
523 seed_vector_.push_back( seedpair );
526 throw utility::excn::EXCN_RosettaScriptsOption(
"need to either specify a stub residue or a seed/segment");
532 Movers_map::const_iterator find_mover( movers.find( mover_name ) );
534 protocols::moves::Movers_map::const_iterator mover_it( movers.find( mover_name ) );
535 if( mover_it == movers.end() )
536 throw utility::excn::EXCN_RosettaScriptsOption(
"mover "+ mover_name+
" not found" );
537 mover_ = mover_it->second ;
540 Filters_map::const_iterator find_filter( filters.find( filter_name ));
541 if( find_filter == filters.end() ) {
542 TR<<
"WARNING WARNING!!! filter not found in map. skipping: \n"<<tag<<
"defaulting to truefilter "<<std::endl;
548 filter_ = find_filter->second->clone();
550 TR <<
"with mover \"" << mover_name <<
"\" and filter \"" << filter_name << std::endl ;