15 #include <protocols/moves/Mover.hh>
16 #include <protocols/moves/MonteCarlo.hh>
17 #include <protocols/simple_moves/PackRotamersMover.hh>
18 #include <protocols/simple_moves/CoupledMover.hh>
19 #include <protocols/simple_moves/MinPackMover.hh>
20 #include <protocols/viewer/viewers.hh>
21 #include <protocols/canonical_sampling/PDBTrajectoryRecorder.hh>
22 #include <protocols/jd2/util.hh>
23 #include <protocols/jd2/JobDistributor.hh>
24 #include <protocols/jd2/Job.hh>
25 #include <protocols/jd2/InnerJob.hh>
26 #include <protocols/toolbox/IGEdgeReweighters.hh>
27 #include <core/scoring/ScoreFunction.hh>
28 #include <core/scoring/ScoreFunctionFactory.hh>
29 #include <core/scoring/Energies.hh>
30 #include <core/scoring/methods/EnergyMethodOptions.hh>
31 #include <core/scoring/hbonds/HBondOptions.hh>
32 #include <core/scoring/EnergyGraph.hh>
33 #include <core/scoring/constraints/util.hh>
34 #include <core/import_pose/import_pose.hh>
35 #include <core/pack/task/TaskFactory.hh>
36 #include <core/pack/task/PackerTask.hh>
37 #include <core/pack/task/operation/TaskOperations.hh>
38 #include <core/pack/task/residue_selector/ClashBasedRepackShellSelector.hh>
39 #include <core/pose/Pose.hh>
40 #include <core/pose/PDBInfo.hh>
41 #include <core/chemical/ResidueType.hh>
42 #include <core/chemical/AtomType.hh>
43 #include <core/conformation/Conformation.hh>
44 #include <core/kinematics/FoldTree.hh>
55 #include <basic/options/keys/constraints.OptionKeys.gen.hh>
56 #include <basic/options/keys/in.OptionKeys.gen.hh>
57 #include <basic/options/keys/out.OptionKeys.gen.hh>
58 #include <basic/options/keys/backrub.OptionKeys.gen.hh>
59 #include <basic/options/keys/packing.OptionKeys.gen.hh>
90 main(
int argc,
char * argv [] )
95 OPT(in::ignore_unrecognized_res);
97 OPT(packing::resfile);
99 OPT(constraints::cst_fa_weight);
100 OPT(constraints::cst_fa_file);
102 NEW_OPT(coupled_moves::ntrials,
"number of Monte Carlo trials to run", 1000);
103 NEW_OPT(coupled_moves::mc_kt,
"value of kT for Monte Carlo", 0.6);
104 NEW_OPT(coupled_moves::boltzmann_kt,
"value of kT for Boltzmann weighted moves", 0.6);
105 NEW_OPT(coupled_moves::mm_bend_weight,
"weight of mm_bend bond angle energy term", 1.0);
106 NEW_OPT(coupled_moves::trajectory,
"record a trajectory",
false);
107 NEW_OPT(coupled_moves::trajectory_gz,
"gzip the trajectory",
false);
108 NEW_OPT(coupled_moves::trajectory_stride,
"write out a trajectory frame every N steps", 100);
109 NEW_OPT(coupled_moves::trajectory_file,
"name of trajectory file",
"traj.pdb");
110 NEW_OPT(coupled_moves::output_fasta,
"name of FASTA output file",
"sequences.fasta");
111 NEW_OPT(coupled_moves::output_stats,
"name of stats output file",
"sequences.stats");
112 NEW_OPT(coupled_moves::ligand_mode,
"if true, model protein ligand interaction",
false);
113 NEW_OPT(coupled_moves::initial_repack,
"start simulation with repack and design step",
true);
115 NEW_OPT(coupled_moves::save_sequences,
"save all unique sequences",
true);
116 NEW_OPT(coupled_moves::save_structures,
"save structures for all unique sequences",
false);
117 NEW_OPT(coupled_moves::ligand_prob,
"probability of making a ligand move", 0.1);
118 NEW_OPT(coupled_moves::fix_backbone,
"do not make any backbone moves",
false);
119 NEW_OPT(coupled_moves::uniform_backrub,
"select backrub rotation angle from uniform distribution",
false);
120 NEW_OPT(coupled_moves::bias_sampling,
"if true, bias rotamer selection based on energy",
true);
121 NEW_OPT(coupled_moves::bump_check,
"if true, use bump check in generating rotamers",
true);
122 NEW_OPT(coupled_moves::ligand_weight,
"weight for residue - ligand interactions", 1.0);
123 NEW_OPT(coupled_moves::output_prefix,
"prefix for output files",
"");
128 protocols::viewer::viewer_main(
my_main );
131 std::cout <<
"caught exception " << e.
msg() << std::endl;
144 std::string
get_name()
const {
return "CoupledMovesProtocol"; }
146 virtual protocols::moves::MoverOP
clone()
const {
155 core::pose::PoseOP pose,
166 score_fxn_(core::scoring::ScoreFunctionOP( new core::scoring::ScoreFunction() )),
167 main_task_factory_(core::
pack::
task::TaskFactoryOP( new core::
pack::
task::TaskFactory() ))
171 using namespace basic::options::OptionKeys;
174 using namespace core::pack::task::operation;
176 main_task_factory_->push_back( TaskOperationCOP(
new operation::InitializeFromCommandline ) );
180 operation::RestrictToRepackingOP rtrop(
new operation::RestrictToRepacking );
188 score_fxn_ = core::scoring::get_score_function();
189 score_fxn_->set_weight(core::scoring::mm_bend,
option[ coupled_moves::mm_bend_weight ]);
190 core::scoring::constraints::add_fa_constraints_from_cmdline_to_scorefxn(*
score_fxn_);
191 core::scoring::methods::EnergyMethodOptions energymethodoptions(
score_fxn_->energy_method_options());
192 energymethodoptions.hbond_options().decompose_bb_hb_into_pair_energies(
true);
193 energymethodoptions.bond_angle_central_atoms_to_score(
option[ backrub::pivot_atoms ]);
194 score_fxn_->set_energy_method_options(energymethodoptions);
203 core::pose::PoseOP
pose,
207 core::scoring::EnergyMap
weights = pose->energies().weights();
208 core::scoring::EnergyGraph
const & energy_graph( pose->energies().energy_graph() );
209 core::scoring::EnergyMap ligand_two_body_energies;
211 for (
core::Size i = 1; i <= pose->total_residue(); i++ ) {
212 for ( core::graph::Graph::EdgeListConstIter
213 iru = energy_graph.get_node(i)->const_edge_list_begin(),
214 irue = energy_graph.get_node(i)->const_edge_list_end();
215 iru != irue; ++iru ) {
216 const core::scoring::EnergyEdge * edge( static_cast< const core::scoring::EnergyEdge *> (*iru) );
217 core::Size const j( edge->get_first_node_ind() );
218 core::Size const k( edge->get_second_node_ind() );
219 if ( j == ligand_resnum || k == ligand_resnum ) {
220 ligand_two_body_energies += edge->fill_energy_map();
225 core::Real ligand_score_bonus = ligand_two_body_energies.dot(weights) * (ligand_weight - 1.0);
227 return ligand_score_bonus;
232 using namespace basic::options::OptionKeys;
234 TR <<
"Initial Score:" << std::endl;
240 protocols::viewer::add_monte_carlo_viewer(mc,
"CoupledMoves", 600, 600);
244 std::string output_tag(protocols::jd2::current_output_name());
245 output_tag +=
option[coupled_moves::output_prefix];
251 core::scoring::constraints::add_fa_constraints_from_cmdline_to_pose(*pose_copy);
253 core::pack::task::PackerTaskOP
task(
main_task_factory_->create_task_and_apply_taskoperations( *pose_copy ) );
259 core::pack::task::residue_selector::ClashBasedRepackShellSelectorOP rs(
new core::pack::task::residue_selector::ClashBasedRepackShellSelector(
task,
score_fxn_) );
262 for (
core::Size i = 1; i <= to_repack.size(); ++i ) {
263 if (
task->residue_task(i).has_behavior(
"AUTO") ) {
264 if ( to_repack[i] ) {
265 task->nonconst_residue_task(i).restrict_to_repacking();
267 task->nonconst_residue_task(i).prevent_repacking();
272 for (
core::Size i = 1; i <= to_repack.size(); ++i ) {
273 if (
task->design_residue(i) ) {
274 design_positions.push_back(i);
275 move_positions.push_back(i);
276 }
else if (
task->pack_residue(i) ) {
277 move_positions.push_back(i);
284 core::Size ligand_resnum = pose_copy->total_residue();
286 protocols::simple_moves::CoupledMoverOP coupled_mover;
288 if (
option[coupled_moves::ligand_mode] ) {
289 coupled_mover = protocols::simple_moves::CoupledMoverOP(
new protocols::simple_moves::CoupledMover(pose_copy,
score_fxn_,
task, ligand_resnum));
290 coupled_mover->set_ligand_resnum( ligand_resnum );
291 coupled_mover->set_ligand_weight( ligand_weight );
292 core::pack::task::IGEdgeReweighterOP reweight_ligand(
new protocols::toolbox::IGLigandDesignEdgeUpweighter( ligand_weight ) );
293 task->set_IGEdgeReweights()->add_reweighter( reweight_ligand );
295 coupled_mover = protocols::simple_moves::CoupledMoverOP(
new protocols::simple_moves::CoupledMover(pose_copy,
score_fxn_,
task) );
298 coupled_mover->set_fix_backbone(
option[coupled_moves::fix_backbone] );
299 coupled_mover->set_bias_sampling(
option[coupled_moves::bias_sampling] );
300 coupled_mover->set_temperature(
option[coupled_moves::boltzmann_kt] );
301 coupled_mover->set_bump_check(
option[coupled_moves::bump_check] );
302 coupled_mover->set_uniform_backrub(
option[coupled_moves::uniform_backrub] );
304 protocols::simple_moves::PackRotamersMoverOP
pack(
new protocols::simple_moves::PackRotamersMover(
score_fxn_,
task, 1 ) );
305 protocols::simple_moves::MinPackMoverOP minpack(
new protocols::simple_moves::MinPackMover(
score_fxn_,
task ));
307 if (
option[coupled_moves::initial_repack] ) {
309 minpack->apply(*pose_copy);
311 pack->apply(*pose_copy);
316 mc.reset(*pose_copy);
318 protocols::canonical_sampling::PDBTrajectoryRecorder trajectory;
319 if (
option[ coupled_moves::trajectory ] ) {
320 trajectory.file_name(output_tag +
"_traj.pdb" + (
option[ coupled_moves::trajectory_gz ] ?
".gz" :
""));
321 trajectory.stride(
option[ coupled_moves::trajectory_stride ]);
322 trajectory.reset(mc);
325 TR <<
"Design Positions: ";
326 for (
core::Size i = 1; i <= design_positions.size(); i++ ) {
327 TR << pose_copy->pdb_info()->number(design_positions[i]) <<
" ";
330 std::string initial_sequence =
"";
332 initial_sequence += pose_copy->residue(design_positions[
index]).name1();
334 TR <<
"Starting Sequence: " << initial_sequence << std::endl;
336 TR <<
"Starting Score:" << std::endl;
340 TR <<
"Running " <<
option[ coupled_moves::ntrials ] <<
" trials..." << std::endl;
342 std::map<std::string,core::Real> unique_sequences;
343 std::map<std::string,core::pose::Pose> unique_structures;
344 std::map<std::string,core::scoring::EnergyMap> unique_scores;
350 (*score_fxn_)(*pose_copy);
351 core::Real current_score = pose_copy->energies().total_energy();
353 if (
option[coupled_moves::ligand_mode] ) {
355 current_score += ligand_score_bonus;
356 mc.set_last_accepted_pose(*pose_copy, current_score);
362 std::string move_type;
364 if ( move_prob <
option[coupled_moves::ligand_prob] ) {
365 resnum = ligand_resnum;
366 move_type =
"LIGAND";
368 move_type =
"RESIDUE";
371 coupled_mover->set_resnum(resnum);
372 coupled_mover->apply(*pose_copy);
374 (*score_fxn_)(*pose_copy);
375 current_score = pose_copy->energies().total_energy();
378 if (
option[coupled_moves::ligand_mode] ) {
382 current_score += ligand_score_bonus;
384 bool accepted = mc.boltzmann(current_score, move_type);
387 if ( current_score < lowest_score ) {
388 mc.set_lowest_score_pose(*pose_copy, current_score);
390 mc.set_last_accepted_pose(*pose_copy, current_score);
393 sequence += pose_copy->residue(design_positions[
index]).name1();
395 TR << i <<
" " << sequence <<
" " << current_score << std::endl;
396 if (
option[coupled_moves::save_sequences] ) {
397 if ( unique_sequences.find(sequence) == unique_sequences.end() ) {
398 unique_sequences.insert(std::make_pair(sequence,current_score));
399 unique_scores.insert(std::make_pair(sequence,pose_copy->energies().total_energies()));
400 if (
option[coupled_moves::save_structures] ) {
401 unique_structures.insert(std::make_pair(sequence,*pose_copy));
404 if ( unique_sequences[sequence] > current_score ) {
405 unique_sequences[
sequence] = current_score;
406 unique_scores[
sequence] = pose_copy->energies().total_energies();
407 if (
option[coupled_moves::save_structures] ) {
408 unique_structures[
sequence] = *pose_copy;
414 (*pose_copy) = mc.last_accepted_pose();
417 if (
option[ coupled_moves::trajectory ] ) trajectory.update_after_boltzmann(mc);
425 TR <<
"Last Score:" << std::endl;
429 if (
option[out::pdb_gz] ) {
430 pose_copy->dump_pdb(output_tag +
"_last.pdb.gz");
432 pose_copy->dump_scored_pdb(output_tag +
"_last.pdb", *
score_fxn_);
435 *pose_copy = mc.lowest_score_pose();
437 TR <<
"Low Score:" << std::endl;
441 if (
option[out::pdb_gz] ) {
442 pose_copy->dump_pdb(output_tag +
"_low.pdb.gz");
444 pose_copy->dump_scored_pdb(output_tag +
"_low.pdb", *
score_fxn_);
447 pose = mc.lowest_score_pose();
449 if (
option[coupled_moves::save_sequences] ) {
450 std::ofstream out_fasta( (output_tag +
".fasta").c_str() );
452 for ( std::map<std::string,core::Real>::iterator it = unique_sequences.begin(),
end = unique_sequences.end(); it !=
end; ++it ) {
453 out_fasta <<
">Sequence" << count <<
" " << it->second << std::endl;
454 out_fasta << it->first << std::endl;
459 std::ofstream out_stats( (output_tag +
".stats").c_str() );
461 for ( std::map<std::string,core::Real>::iterator it = unique_sequences.begin(),
end = unique_sequences.end(); it !=
end; ++it ) {
462 out_stats <<
"Sequence" << count <<
"\t" << it->second <<
"\tsequence:\t" << it->first <<
"\t" << unique_scores[it->first].weighted_string_of(
score_fxn_->weights()) << std::endl;
467 if (
option[coupled_moves::save_structures] ) {
468 for ( std::map<std::string,core::pose::Pose>::iterator it = unique_structures.begin(),
end = unique_structures.end(); it !=
end; ++it ) {
469 if (
option[out::pdb_gz] ) {
470 it->second.dump_pdb(output_tag +
"_" + it->first +
"_low.pdb.gz");
472 it->second.dump_scored_pdb(output_tag +
"_" + it->first +
"_low.pdb", *
score_fxn_);
487 protocols::jd2::JobDistributor::get_instance()->go( coupled_moves );
static THREAD_LOCAL basic::Tracer TR("apps.coupled_moves")
virtual std::string const msg() const
utility::pointer::shared_ptr< CoupledMovesProtocol > CoupledMovesProtocolOP
virtual protocols::moves::MoverOP fresh_instance() const
basic::options::BooleanOptionKey const min_pack("min_pack")
void init(int argc, char *argv[])
Command line init() version.
BooleanOptionKey const user("options:user")
int main(int argc, char *argv[])
utility::keys::lookup::end< KeyType > const end
Conversions between degrees and radians.
core::scoring::ScoreFunctionOP score_fxn_
Random number generator system.
int random_range(int low, int high)
Return a number uniformly drawn from the inclusive range between low and high. Threadsafe since each ...
core::pack::task::TaskFactoryOP main_task_factory_
virtual void apply(core::pose::Pose &pose)
Fstring::size_type index(Fstring const &s, Fstring const &ss)
First Index Position of a Substring in an Fstring.
basic::options::IntegerOptionKey const nstruct("nstruct")
rule< Scanner, options_closure::context_t > options
list resnum
if line_edit[13:14]=='P': #Nucleic acid? Skip.
#define NEW_OPT(akey, help, adef)
ocstream cout(std::cout)
Wrapper around std::cout.
Class for handling user debug/warnings/errors. Use instance of this class instead of 'std::cout' for ...
double uniform()
Generate a random number between 0 and 1. Threadsafe since each thread uses its own random generator...
#define OPT_1GRP_KEY(type, grp, key)
xyzVector and xyzMatrix functions
core::Real compute_ligand_score_bonus(core::pose::PoseOP pose, core::Size ligand_resnum, core::Real ligand_weight)
Fast (x,y,z)-coordinate numeric vector.
std::string get_name() const
virtual protocols::moves::MoverOP clone() const
rule< Scanner, option_closure::context_t > option