37 #include <basic/Tracer.hh>
38 #include <basic/basic.hh>
39 #include <basic/prof.hh>
42 #include <numeric/angle.functions.hh>
44 #include <numeric/conversions.hh>
45 #include <numeric/random/random.hh>
48 #include <utility/string_util.hh>
49 #include <utility/tag/Tag.hh>
50 #include <utility/exit.hh>
55 #include <utility/fixedsizearray1.hh>
58 #include <utility/vector0.hh>
59 #include <utility/excn/Exceptions.hh>
60 #include <utility/vector1.hh>
63 using namespace core::pose;
65 static numeric::random::RandomGenerator
RG(38627225);
66 static basic::Tracer
TR(
"protocols.simple_moves.sidechain_moves.SidechainMover");
69 namespace simple_moves {
70 namespace sidechain_moves {
73 SidechainMoverCreator::keyname()
const {
74 return SidechainMoverCreator::mover_name();
78 SidechainMoverCreator::create_mover()
const {
83 SidechainMoverCreator::mover_name() {
87 SidechainMover::SidechainMover():
88 rotamer_library_( core::pack::dunbrack::RotamerLibrary::get_instance() ),
92 prob_random_pert_to_current_(0.0),
93 accept_according_to_dunbrack_(true),
94 sample_rotwells_unif_(false),
95 change_chi_without_replacing_residue_(false),
97 last_proposal_density_ratio_(1),
98 task_initialized_(false),
99 scratch_( new core::pack::dunbrack::RotamerLibraryScratchSpace ),
101 sampling_temperature_(0.56)
107 rotamer_library_(rotamer_library),
110 prob_withinrot_(0.0),
111 prob_random_pert_to_current_(0.0),
112 accept_according_to_dunbrack_(true),
113 sample_rotwells_unif_(false),
114 change_chi_without_replacing_residue_(false),
116 last_proposal_density_ratio_(1),
117 task_initialized_(false),
118 scratch_( new core::pack::dunbrack::RotamerLibraryScratchSpace ),
120 sampling_temperature_(0.56)
127 protocols::canonical_sampling::ThermodynamicMover(mover),
128 rotamer_library_(mover.rotamer_library_),
129 packed_residues_(mover.packed_residues_),
130 residue_packed_(mover.residue_packed_),
131 prob_uniform_(mover.prob_uniform_),
132 prob_withinrot_(mover.prob_withinrot_),
133 prob_random_pert_to_current_(mover.prob_random_pert_to_current_),
134 preserve_detailed_balance_(mover.preserve_detailed_balance_),
135 accept_according_to_dunbrack_(mover.accept_according_to_dunbrack_),
136 sample_rotwells_unif_(mover.sample_rotwells_unif_),
137 change_chi_without_replacing_residue_(mover.change_chi_without_replacing_residue_),
138 next_resnum_(mover.next_resnum_),
139 last_chi_angles_(mover.last_chi_angles_),
140 last_nchi_(mover.last_nchi_),
141 last_mutation_(mover.last_mutation_),
142 last_uniform_(mover.last_uniform_),
143 last_withinrot_(mover.last_withinrot_),
144 last_pertrot_(mover.last_pertrot_),
145 last_proposal_density_ratio_(mover.last_proposal_density_ratio_),
146 task_initialized_(mover.task_initialized_),
148 sampling_temperature_(0.56)
175 if ( tag->hasOption(
"task_operations") ) {
179 StringVec
const t_o_keys( utility::string_split( t_o_val,
',' ) );
180 for ( StringVec::const_iterator t_o_key( t_o_keys.begin() ),
end( t_o_keys.end() );
181 t_o_key !=
end; ++t_o_key ) {
182 if ( data.
has(
"task_operations", *t_o_key ) ) {
185 throw utility::excn::EXCN_RosettaScriptsOption(
"TaskOperation " + *t_o_key +
" not found in protocols::moves::DataMap.");
218 utility_exit_with_message(
"Cannot create task because no task factory is set");
242 numeric::random::RandomGenerator Rand,
247 new_chi.resize( old_chi.size() );
249 for(
unsigned int chi_i = 1; chi_i <= old_chi.size(); chi_i++){
250 rand = Rand.uniform();
256 new_chi[ chi_i ] = basic::periodic_range( ( (2.0*rand-1.0)*max_deviation + old_chi[ chi_i ]) , 360.0 );
262 numeric::random::RandomGenerator & Rand,
275 if ( new_chi_angle_score > prev_chi_angle_score) {
279 Real const probability = std::exp(boltz_factor);
280 if ( rand >= probability ) {
292 using numeric::conversions::degrees;
293 using numeric::conversions::radians;
311 Size const restypenum(
RG.random_range(1, residue_types.size()));
313 for (
Size i = 1; i < restypenum; ++i) ++iter;
314 residue_type = *iter;
326 if (
TR.visible( basic::t_debug )) {
327 TR.Debug << input_residue->name() <<
" " << resnum <<
" -> " << residue_type->name() << std::endl;
330 if (residue_type->aa() != (input_residue->type()).aa())
last_mutation_ =
true;
336 dynamic_cast< core::pack::dunbrack::SingleResidueDunbrackLibrary const * >(residue_rotamer_library.get())
346 if ( move_type_prob >
prob_uniform_ && residue_dunbrack_library) {
348 core::Real const phi( residue_dunbrack_library->get_phi_from_rsd( *input_residue ) );
349 core::Real const psi( residue_dunbrack_library->get_psi_from_rsd( *input_residue ) );
368 residue_dunbrack_library->get_all_rotamer_samples(
phi,
psi)
376 residue_dunbrack_library->get_all_rotamer_samples(
phi,
psi)
381 if (
TR.visible( basic::t_debug )) {
382 TR.Debug <<
"making a uniform jump " << std::endl;
399 if (
TR.visible( basic::t_debug )) {
400 TR.Debug <<
"residue angles were previously: ";
402 for (
Size i = 1; i <= input_residue->nchi(); ++i) {
403 TR.Debug <<
" " << input_residue->chi( i );;
405 TR.Debug << std::endl;
409 for (
Size i = 1; i <= input_residue->nchi(); ++i) {
413 if (
TR.visible( basic::t_debug )) {
414 TR.Debug <<
"Set residue chi angles to:";
415 for (
Size i = 1; i <= input_residue->nchi(); ++i) {
417 TR.Debug <<
" " << input_residue->chi( i );
419 TR.Debug << std::endl;
425 if (residue_type() != & previous_residue->type() ) {
426 if (
TR.visible( basic::t_debug )) {
427 TR.Debug <<
"previous residue " << previous_residue->type().name() <<
" doesn't match new res-name " << residue_type->name() << std::endl;
432 pose_->conformation(),
433 residue_task.preserve_c_beta());
434 if (
TR.visible( basic::t_debug )) {
435 TR.Debug <<
"type of new residue created " << new_residue->type().name() << std::endl;
437 for(
Size ii = 1; ii <= residue_type->nchi(); ii++ ){
438 if (
TR.visible( basic::t_debug )) {
441 new_residue->set_chi( ii, numeric::principal_angle_degrees(
last_chi_angles_[ ii ] ));
442 if (
TR.visible( basic::t_debug )) {
443 TR.Debug <<
" input residue chi is now: " << input_residue->chi( ii ) << std::endl;
448 new_residue = input_residue;
454 for (
Size ii = 1; ii <= residue_type->nchi(); ++ii ) {
462 proposal_density_forward =
proposal_density(*input_residue, resnum, previous_residue_type, previous_chi_angles);
465 if (
TR.visible( basic::t_debug )) {
482 if (
TR.visible( basic::t_debug )) {
483 TR.Debug <<
"making a rot-well jump " << std::endl;
492 for (rotnum=rotamer_sample_data.size(); rotnum>0; rotnum--)
494 rot_prob_list[rotnum] = rotamer_sample_data[rotnum].probability();
497 sum_prob+=rot_prob_list[rotnum];
500 runtime_assert(sum_prob>0.0);
501 for (rotnum=rotamer_sample_data.size(); rotnum>0; rotnum--){rot_prob_list[rotnum]/=sum_prob;}
505 while ( random_prob > 0 ) {
507 random_prob -= (1.0/rotamer_sample_data.size());
511 random_prob -= rot_prob_list[++rotnum];
516 if ( rotnum == rotamer_sample_data.size() )
break;
529 if (
TR.visible( basic::t_debug )) {
530 TR.Debug <<
"making a perterb-rot (ek) " << std::endl;
541 perturb_chi(
RG, max_deviation, previous_chi_angles, new_chi_angles );
549 while( !
dunbrack_accept(
RG, *input_residue, previous_chi_angles, new_chi_angles ) );
551 TR <<
"ERROR: you cannot specify accept_according_to_dunbrack_ and preserve_detailed_balance_ both as true!" << std::endl;
552 TR <<
"Recommend rerunning with 'random perturb current' frequency set to zero." << std::endl;
569 if (
TR.visible( basic::t_debug )) {
570 TR.Debug <<
"making a within-rot-well jump " << std::endl;
574 for (
core::Size ii = 1; ii <= rotamer_sample_data.size(); ++ii) {
575 core::Real candidate_rot_prob( rotamer_sample_data[ii].chi_probability(previous_chi_angles) );
576 if (candidate_rot_prob > max_rot_prob) {
578 max_rot_prob = candidate_rot_prob;
603 using numeric::conversions::degrees;
604 using numeric::conversions::radians;
606 PROF_START( basic::APPLY_SC_MOVE );
621 if (
TR.visible( basic::t_debug )) {
622 TR.Debug <<
"old residue chi is : ";
623 for (
Size i = 1; i <= newresidue->nchi(); ++i)
TR.Debug <<
" " << newresidue->chi(i);
624 TR.Debug << std::endl;
628 if (
TR.visible( basic::t_debug )) {
629 TR.Debug <<
"new residue chi is : ";
630 for (
Size i = 1; i <= pose.
residue(resnum).
type().
nchi(); ++i)
TR.Debug <<
" " << newresidue->chi(i);
631 TR.Debug << std::endl;
640 pose.
set_chi(i, resnum, final->chi(i));
644 if (
TR.visible( basic::t_debug )) {
645 TR.Debug <<
"pose replaced " << resnum <<
" " << pose.
residue(resnum).
type().
name() <<
" has phi-psi " << pose.
phi(resnum) <<
" " << pose.
psi(resnum) <<
" and chi: ";
648 TR.Debug << std::endl;
650 PROF_STOP( basic::APPLY_SC_MOVE );
655 return "SidechainMover";
675 dynamic_cast< core::pack::dunbrack::SingleResidueDunbrackLibrary const * >(residue_rotamer_library.get())
678 if (residue_dunbrack_library) {
680 core::Real const phi( residue_dunbrack_library->get_phi_from_rsd( proposed_residue ) );
681 core::Real const psi( residue_dunbrack_library->get_psi_from_rsd( proposed_residue ) );
684 residue_dunbrack_library->get_all_rotamer_samples(
phi,
psi)
691 while( itr_i <= rotamer_sample_data.size() &&
692 rotamer_sample_data[ itr_i ].probability() > probability_threshold){
693 most_probable_rotamers.push_back( rotamer_sample_data[ itr_i ] );
696 rotamer_sample_data = most_probable_rotamers;
706 for (
core::Size ii = 1; ii <= rotamer_sample_data.size(); ++ii) {
708 core::Real const proposed_rot_prob( rotamer_sample_data[ii].chi_probability(proposed_chi_angles) );
711 rot_density += ( 1.0 / rotamer_sample_data.size() ) * proposed_rot_prob;
714 rot_density += exp(log(rotamer_sample_data[ii].probability()) + log(proposed_rot_prob));
717 if (calc_withinrot) {
719 core::Real const initial_rot_prob( rotamer_sample_data[ii].chi_probability(initial_chi_angles) );
721 if (initial_rot_prob > max_initial_rot_prob) {
722 max_initial_rot_prob = initial_rot_prob;
723 max_proposed_rot_prob = proposed_rot_prob;
730 density += rot_density;
732 if (calc_withinrot) {
734 core::Real const withinrot_density( prob_withinrot_ * max_proposed_rot_prob );
736 density += withinrot_density;
745 uniform_density *= 1.0/360.0;
748 if (residue_dunbrack_library) uniform_density *=
prob_uniform_;
750 density += uniform_density;
757 density *= 1.0/residue_task.allowed_residue_types().size();
794 if (residue_type.nchi() > chi.size()) chi.resize(residue_type.nchi());
795 for (
Size chinum = 1; chinum <= residue_type.nchi(); ++chinum) {
796 chi[chinum] = pose.
chi(chinum, resnum);
801 conformation::ResidueFactory::create_residue(residue_type, pose.
residue(resnum), pose.
conformation(),
802 residue_task.preserve_c_beta())
807 for (
Size chinum = 1; chinum <= residue_type.nchi(); ++chinum) {
808 pose.
set_chi(chinum, resnum, chi[chinum]);
851 for (
Size i = 1; i <=
task_->total_residue(); ++i) {
856 for (ResidueLevelTask::ResidueTypeCOPListConstIter iter(residue_task.allowed_residue_types_begin());
857 iter != residue_task.allowed_residue_types_end(); ++iter) {
918 bool preserve_detailed_balance
932 bool const change_chi_without_replacing_residue
951 Real static const pi(numeric::NumericTraits<Real>::pi());
961 bool all_names_match =
true;
967 iter != residueleveltask.allowed_residue_types_end(); ++iter) {
970 all_names_match =
false;
975 if (!all_names_match)
break;
1054 std::stringstream
mt;