Rosetta 3.5
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
ResidueTorsionRestraints.cc
Go to the documentation of this file.
1 // -*- mode:c++;tab-width:2;indent-tabs-mode:t;show-trailing-whitespace:t;rm-trailing-spaces:t -*-
2 // vi: set ts=2 noet:
3 //
4 // (c) Copyright Rosetta Commons Member Institutions.
5 // (c) This file is part of the Rosetta software suite and is made available under license.
6 // (c) The Rosetta software is developed by the contributing members of the Rosetta Commons.
7 // (c) For more information, see http://www.rosettacommons.org. Questions about this can be
8 // (c) addressed to University of Washington UW TechTransfer, email: license@u.washington.edu.
9 
10 /// @file protocols/ligand_docking/ResidueTorsionRestraints.cc
11 ///
12 /// @brief
13 /// @author Ian W. Davis
14 
15 
18 #include <core/id/AtomID.hh>
19 #include <core/pose/Pose.hh>
24 
25 #include <basic/Tracer.hh>
26 
27 #include <numeric/conversions.hh>
28 
30 #include <utility/vector1.hh>
31 #include <boost/foreach.hpp>
32 
33 //Auto Headers
34 #define foreach BOOST_FOREACH
35 namespace protocols {
36 namespace ligand_docking {
37 
38 
39 static basic::Tracer TR("protocols.ligand_dock.ResidueTorsionRestraints", basic::t_debug);
40 
41 
43  core::pose::Pose & pose,
44  core::Size resid,
45  core::Real stddev_degrees
46 ):
47  resid_(resid),
48  stddev_degrees_(stddev_degrees),
49  my_constraints_(),
50  old_chi_(),
51  old_constraints_()
52 {
53  // my_constraints_ is empty to start with, so all existing constraints will be kept initially.
54  enable( pose );
55 }
56 
58  return resid_==other.resid_;
59 }
60 
61 ///@details Adds constraints to all rotatable torsions except proton chis.
62 /// Conserves all existing constraints except ones previously added by this object.
64 {
65  using namespace core::scoring::constraints;
69  using core::id::AtomID;
70 
71  // input stddev is in degrees, but dihedral constraints deal in radians
72  core::Real const stddev_radians = numeric::conversions::radians( stddev_degrees_ );
73 
74  std::set< core::scoring::constraints::ConstraintCOP > dont_care;
75  ConstraintSetOP new_constraints = without_my_constraints( pose.constraint_set(), dont_care );
76  // Over the lifetime of this object, its original Pose may be cloned, copied over,
77  // reverted to some previous version (think MC trials), etc.
78  // Thus, *any* of the constraints we've *ever* created may be in the Pose passed to enable/disable().
79  // So we need to keep record of all of them. Fortunately they're stored as strings, which are small.
80  //my_constraints_.clear();
81 
82  Residue const & rsd = pose.residue(resid_);
83  ResidueType const & rsd_type = pose.residue_type(resid_);
84  for(core::Size j = 1, j_end = rsd_type.nchi(); j <= j_end; ++j) {
85  core::Real const curr_chi_degrees = rsd.chi(j);
86  core::Real const curr_chi_radians = numeric::conversions::radians( curr_chi_degrees );
87  FuncOP restr_func = new CircularHarmonicFunc( curr_chi_radians, stddev_radians );
88  AtomIndices chi_idx = rsd_type.chi_atoms(j); // 1-based
90  AtomID(chi_idx[1], resid_),
91  AtomID(chi_idx[2], resid_),
92  AtomID(chi_idx[3], resid_),
93  AtomID(chi_idx[4], resid_),
94  restr_func
95  );
96  TR << "Constraint: " << curr_chi_degrees << " deg, " << constraint->atom(1) << " "
97  << constraint->atom(2) << " " << constraint->atom(3) << " " << constraint->atom(4) << std::endl;
98  // Is this still necessary (no) or advisable (maybe)? Constraint will be removed before packing...
99  if( rsd.atom_type(chi_idx[1]).is_hydrogen() || rsd.atom_type(chi_idx[4]).is_hydrogen() ) {
100  TR << "Constraint involves hydrogen atom; skipping it for PROTON_CHI." << std::endl;
101  } else {
102  new_constraints->add_constraint( constraint );
103  my_constraints_.insert( constraint->to_string() );
104  }
105  }
106 
107  pose.constraint_set( new_constraints );
108 }
109 
110 
114  std::set< core::scoring::constraints::ConstraintCOP > & removed_constraints
115 )
116 {
117  using namespace core::scoring::constraints;
118  ConstraintSetOP new_constraints = new ConstraintSet();
119 
120  // Cycle through all existing constraints, and keep all except the ones we added:
121  if( old_constraints.get() != NULL ) {
122  utility::vector1< ConstraintCOP > old_constr = old_constraints->get_all_constraints();
123  for( Size i = 1; i <= old_constr.size(); ++i ) {
124  if( my_constraints_.find( old_constr[i]->to_string() ) == my_constraints_.end() ) {
125  new_constraints->add_constraint( old_constr[i] );
126  TR << "Keeping old constraint " << old_constr[i]->to_string() << std::endl;
127  } else {
128  removed_constraints.insert( old_constr[i] );
129  TR << "Removing old constraint " << old_constr[i]->to_string() << std::endl;
130  }
131  }
132  }
133  return new_constraints;
134 }
135 
136 
138 {
139  using namespace core::scoring::constraints;
140  TR.Trace << "enable(), # constraints before: " << pose.constraint_set()->get_all_constraints().size() << std::endl;
141 
142  // Has our target residue changed conformation significantly?
143  utility::vector1< core::Real > new_chi = pose.residue(resid_).chi(); // need a copy, not a reference
144  bool resid_has_changed = (old_chi_.size() != new_chi.size());
145  if( !resid_has_changed ) {
146  for( core::Size i = 1; i <= old_chi_.size(); ++i ) {
147  if( std::abs( old_chi_[i] - new_chi[i] ) > 1e-1 ) resid_has_changed = true;
148  }
149  }
150 
151  TR.Trace << "Residue " << resid_ << " has changed conformation? " << resid_has_changed << std::endl;
152  if( !resid_has_changed ) {
153  // No: restore constraints exactly as they were
154  ConstraintSetOP new_constraints = pose.constraint_set()->clone(); // deep copy, constraints and their funcs are cloned too
156  new_constraints->add_constraint( constraint );
157  }
158  pose.constraint_set( new_constraints );
159  } else {
160  // Yes: generate new constraints for our DOFs
161  setup_constraints( pose );
162  }
163  old_constraints_.clear();
164  TR.Trace << "enable(), # constraints after: " << pose.constraint_set()->get_all_constraints().size() << std::endl;
165 }
166 
167 
169 {
170  using namespace core::scoring::constraints;
171  // Memorize initial conformation of our target residue
172  old_chi_ = pose.residue(resid_).chi(); // need a copy, not a reference
173  // Remove constraints
174  TR.Trace << "disable(), # constraints before: " << pose.constraint_set()->get_all_constraints().size() << std::endl;
176  pose.constraint_set( new_constraints );
177  TR.Trace << "disable(), # constraints after: " << pose.constraint_set()->get_all_constraints().size() << std::endl;
178 }
179 
180 
181 } // namespace ligand_docking
182 } // namespace protocols