Rosetta 3.5
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
ligand_functions.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/ligand_functions.cc
11 ///
12 /// @brief
13 /// @author Ian W. Davis
14 
15 
17 
19 #include <core/id/AtomID.hh>
20 #include <basic/options/option.hh>
21 #include <basic/options/keys/packing.OptionKeys.gen.hh>
27 #include <basic/Tracer.hh>
28 
30 
31 #include <numeric/angle.functions.hh>
32 #include <numeric/conversions.hh>
33 
34 #include <core/pose/Pose.hh>
35 #include <utility/vector1.hh>
36 
37 
38 namespace protocols {
39 namespace ligand_docking {
40 
41 static basic::Tracer TR("protocols.ligand_docking.ligand_functions");
42 
43 /// @brief Helper function.
46  core::Size rsd_no,
47  core::Size chino,
48  core::chemical::ResidueType const & rsd_type,
49  utility::vector1< std::pair< core::Real, core::Real > > const & mean_sd_degrees
50 )
51 {
52  using namespace core;
53  using namespace core::scoring::constraints;
55  using core::id::AtomID;
56 
57  TR << "Torsion constraint for Rsd " << rsd_no << " chi " << chino << " =";
58  ConstraintCOPs csts;
59  for(Size j = 1; j <= mean_sd_degrees.size(); ++j) {
60  TR << " " << mean_sd_degrees[j].first;
61  TR << " std dev " << mean_sd_degrees[j].second;
62  // input is in degrees, but dihedral constraints deal in radians
63  Real const chi_radians = numeric::conversions::radians( mean_sd_degrees[j].first );
64  Real const stddev_radians = numeric::conversions::radians( mean_sd_degrees[j].second );
65  FuncOP restr_func = new CircularHarmonicFunc( chi_radians, stddev_radians );
66  AtomIndices chi_idx = rsd_type.chi_atoms(chino);
67  ConstraintCOP constraint = new DihedralConstraint(
68  AtomID(chi_idx[1], rsd_no),
69  AtomID(chi_idx[2], rsd_no),
70  AtomID(chi_idx[3], rsd_no),
71  AtomID(chi_idx[4], rsd_no),
72  restr_func
73  );
74  csts.push_back( constraint );
75  }
76  TR << std::endl;
77  ConstraintOP cst = new AmbiguousConstraint( csts );
78  return cst;
79 }
80 
81 
84  core::Size rsd_no,
85  core::Size chino,
87  core::Real stddev_degrees
88 )
89 {
90  using namespace core;
91  chemical::ResidueType const & rsd_type = rsds[1]->type();
92 
93  Real const tol_d = stddev_degrees / 10.0; // within this range, considered to be the same minimum
95  for(Size i = 1; i <= rsds.size(); ++i) {
96  //runtime_assert( rsds[i].type().name() == rsdtype.name() );
97  Real const chi_d = rsds[i]->chi(chino);
98  bool found = false;
99  for(Size j = 1; j <= minima_d.size(); ++j) {
100  Real const min = minima_d[j].first;
101  if(std::abs(min - numeric::nearest_angle_degrees(chi_d, min)) < tol_d) {
102  found = true;
103  break;
104  }
105  }
106  if( !found ) {
107  minima_d.push_back( std::make_pair(chi_d, stddev_degrees) );
108  }
109  }
110 
111  return torsion_constraints_from_mean_sd(rsd_no, chino, rsd_type, minima_d);
112 }
113 
114 
117  core::Size rsd_no,
118  core::Size chino,
119  core::chemical::ResidueType const & rsdtype
120 )
121 {
122  return torsion_constraints_from_mean_sd( rsd_no, chino, rsdtype, rsdtype.chi_rotamers(chino) );
123 }
124 
125 
126 void
128  core::pose::Pose & pose,
129  core::Size rsd_no,
130  core::Real stddev_degrees,
132  bool const constrain_all_torsions_equally
133 )
134 {
135  using namespace core;
136  using namespace basic::options;
138 
139  ResidueType const & rsdtype = pose.residue_type(rsd_no);
140  for(Size i = 1; i <= rsdtype.nchi(); ++i) {
141  bool has_diversity(false);
142  if( rsdtype.chi_rotamers(i).size() == 0 ) {
144  rotamers_for_trials(pose, rsd_no, rotamers);
145  if( rotamers.empty() || option[ OptionKeys::packing::use_input_sc ]() ) {
146  rotamers.push_back( pose.residue(rsd_no).clone() );
147  if ( (rotamers.size()==1) && constrain_all_torsions_equally) has_diversity=true;
148  }
149  for (Size j=2;j<=rotamers.size();++j) {
150  Real const chi_d1 = rotamers[j]->chi(i);
151  Real const chi_d2 = rotamers[j-1]->chi(i);
152  if (std::abs(chi_d2 - chi_d1)> stddev_degrees ){
153  // TR<<"Debug: found diversity for CHI " << i << "values "<< chi_d2 << " and " << chi_d1 << std::endl;
154  has_diversity=true;
155  break;
156  }
157  }
158  if (has_diversity || constrain_all_torsions_equally) csts_out.push_back( torsion_constraints_from_rotamers(rsd_no, i, rotamers, stddev_degrees) );
159  else csts_out.push_back( torsion_constraints_from_rotamers(rsd_no, i, rotamers, 0.1/*make sure non-diverse torsions are highly constrained*/) );
160  } else {
161  csts_out.push_back( torsion_constraints_from_chi_rotamers(rsd_no, i, rsdtype) );
162  }
163  }
164 }
165 
166 
167 void
169  core::pose::Pose & pose,
170  core::Real stddev_degrees,
171  bool constrain_all_torsions_equally
172 )
173 {
174  using namespace core;
175  using namespace core::scoring::constraints;
176  ConstraintSetOP new_constraint_set = pose.constraint_set()->clone();
177  for(Size rsdno = 1; rsdno <= pose.total_residue(); ++rsdno) {
178  if( pose.residue_type(rsdno).is_polymer() ) continue;
180  get_ligand_torsion_constraints(pose, rsdno, stddev_degrees, csts, constrain_all_torsions_equally);
181  for(Size cstno = 1; cstno <= csts.size(); ++cstno) {
182  //csts[cstno]->show(TR);
183  new_constraint_set->add_constraint( csts[cstno] );
184  }
185  }
186  pose.constraint_set( new_constraint_set );
187 }
188 
191  core::pose::Pose const & pose
192 )
193 {
195  for( core::Size i =1; i <= pose.total_residue(); ++i){
196  if( pose.residue_type(i).is_ligand() ) to_return.push_back( i );
197  }
198  return to_return;
199 }
200 
201 
202 } // namespace ligand_docking
203 } // namespace protocols