Rosetta 3.5
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
DistancePairConstraint.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 src/core/scoring/DistancePairConstraint.cc
11 /// @brief Restrain a pair of residues to take the same AtomPair constraint of another pair
12 /// @author Frank DiMaio, Fabio Parmeggiani
13 
17 
18 #include <core/pose/Pose.hh>
19 #include <core/pose/util.hh>
21 #include <basic/Tracer.hh>
22 
23 #include <numeric/xyz.functions.hh>
24 #include <numeric/trig.functions.hh>
25 #include <numeric/deriv/distance_deriv.hh>
26 
27 #include <utility/exit.hh>
28 
29 #include <core/id/NamedAtomID.hh>
33 #include <utility/vector1.hh>
34 
35 namespace core {
36 namespace scoring {
37 namespace constraints {
38 
39 static basic::Tracer TR("core.io.constraints");
40 
41 
42 /////////////////////////////////////////////////////////////////////////////
43 
46  core::id::SequenceMapping const & seqmap
47 ) const {
48  if ( seqmap[atomA1_.rsd()] != 0 && seqmap[atomA2_.rsd()] != 0
49  && seqmap[atomB1_.rsd()] != 0 && seqmap[atomB2_.rsd()] != 0 ) {
50  AtomID remap_a1( atomA1_.atomno(), seqmap[atomA1_.rsd()] ),
51  remap_a2( atomA2_.atomno(), seqmap[atomA2_.rsd()] );
52  AtomID remap_b1( atomB1_.atomno(), seqmap[atomB1_.rsd()] ),
53  remap_b2( atomB2_.atomno(), seqmap[atomB2_.rsd()] );
54  return ConstraintOP(
56  remap_a1, remap_a2,
57  remap_b1, remap_b2,
58  this->func_ ) );
59  } else {
60  return NULL;
61  }
62 }
63 
64 
65 /// @brief Copies the data from this Constraint into a new object and returns an OP
66 /// atoms are mapped to atoms with the same name in dest pose ( e.g. for switch from centroid to fullatom )
67 /// if a sequence_mapping is present it is used to map residue numbers .. NULL = identity mapping
68 /// to the new object. Intended to be implemented by derived classes.
74  if ( smap ) {
75  atomA1.rsd() = (*smap)[ atomA1_.rsd() ];
76  atomA2.rsd() = (*smap)[ atomA2_.rsd() ];
77  atomB1.rsd() = (*smap)[ atomB1_.rsd() ];
78  atomB2.rsd() = (*smap)[ atomB2_.rsd() ];
79  }
80 
81  //get AtomIDs for target pose
86  if ( id1.valid() && id2.valid() && id3.valid() && id4.valid() ) {
87  return new DistancePairConstraint( id1, id2, id3, id4, func_, score_type() );
88  } else {
89  return NULL;
90  }
91 }
92 
93 
94 id::AtomID const &
96  switch( n ) {
97  case 1: return atomA1_;
98  case 2: return atomA2_;
99  case 3: return atomB1_;
100  case 4: return atomB2_;
101  default:
102  utility_exit_with_message( "DistancePairConstraint::atom() bad argument" );
103  }
104  return atomA1_;
105 }
106 
107 
108 
109 ////////////////////////////////////////////////////////////////////////////////////////////////////
110 ///@details one line definition "DistancePair atom1 res1 atom2 res2 atom3 res3 atom4 res4 function_type function_definition"
111 void
113  std::istream & in,
114  pose::Pose const & pose,
115  FuncFactory const & func_factory
116 ) {
117  Size res1, res2, res3, res4;
118  std::string tempres1, tempres2, tempres3, tempres4;
119  std::string name1, name2, name3, name4;
120  std::string func_type;
122 
123  in
124  >> name1 >> tempres1
125  >> name2 >> tempres2
126  >> name3 >> tempres3
127  >> name4 >> tempres4
128  >> func_type;
129 
130  ConstraintIO::parse_residue( pose, tempres1, res1 );
131  ConstraintIO::parse_residue( pose, tempres2, res2 );
132  ConstraintIO::parse_residue( pose, tempres3, res3 );
133  ConstraintIO::parse_residue( pose, tempres4, res4 );
134 
135  TR.Debug << "read: " << name1 << " " << name2 << " "
136  << res1 << " " << res2 << " func: " << func_type
137  << std::endl;
138  if ( res1 > pose.total_residue() || res2 > pose.total_residue()
139  || res3 > pose.total_residue() || res4 > pose.total_residue() ) {
140  TR.Warning << "ignored constraint (no such atom in pose!)"
141  << name1 << " " << name2 << " "
142  << res1 << " " << res2 << " func: " << func_type
143  << std::endl;
144  in.setstate( std::ios_base::failbit );
145  return;
146  }
147 
152 
153 
154 
155  if ( atomA1_.atomno() == 0 || atomA2_.atomno() == 0
156  || atomB1_.atomno() == 0 || atomB2_.atomno() == 0 ) {
157  TR.Warning << "Error reading atoms: read in atom names("
158  << name1 << "," << name2 << "," << name3 << "," << name4 << "), "
159  << "and found AtomIDs (" << atomA1_ << "," << atomA2_ << " -- "
160  << atomB1_ << "," << atomB2_ << ")" << std::endl;
161  in.setstate( std::ios_base::failbit );
162  return;
163  }
164 
165  func_ = func_factory.new_func( func_type );
166  func_->read_data( in );
167 
168  while( in.good() && (in.get() != '\n') ) {}
169 
170  if ( TR.Debug.visible() ) {
171  func_->show_definition( std::cout );
172  std::cout << std::endl;
173  }
174 }
175 
176 /////////////////////////////////////////////////////////////////////////////
177 
178 Real
180  conformation::Conformation const & conformation
181 ) const {
182  return score(
183  conformation.xyz( atomA1_ ), conformation.xyz( atomA2_ ),
184  conformation.xyz( atomB1_ ), conformation.xyz( atomB2_ ));
185 }
186 
187 void
189  XYZ_Func const & xyz,
190  EnergyMap const &,
191  EnergyMap & emap
192 ) const {
193  emap[ this->score_type() ] += score(
194  xyz( atomA1_ ), xyz( atomA2_ ),
195  xyz( atomB1_ ), xyz( atomB2_ )
196  );
197 }
198 
199 
200 Real
202  Vector const & p1, Vector const & p2, Vector const & p3, Vector const & p4
203 ) const {
204  core::Real dis1 = p1.distance(p2) ;
205  core::Real dis2 = p3.distance(p4) ;
206  core::Real difference = dis2 - dis1 ;
207 
208  TR.Debug << "difference of " << difference << " Angstroms" << std::endl;
209  return func(difference);
210 }
211 
212 
213 void
215  AtomID const & /* atom */,
216  XYZ_Func const & xyz,
217  Vector & F1,
218  Vector & F2,
219  EnergyMap const & weights
220 ) const {
221  using namespace numeric::deriv;
222 
223  Vector f1(0.0) ,f2(0.0);
224 
225  Real dist(0.0), dist0(0.0);
226 
227  numeric::deriv::distance_f1_f2_deriv( xyz( atomA1_ ), xyz( atomA2_ ), dist0, f1, f2 );
228  numeric::deriv::distance_f1_f2_deriv( xyz( atomB1_ ), xyz( atomB2_ ), dist, f1, f2 );
229 
230  core::Real difference = dist - dist0;
231  Real const dE_dist( dfunc( difference ) );
232 
233  F1 += dE_dist * weights[ this->score_type() ] * f1;
234  F2 += dE_dist * weights[ this->score_type() ] * f2;
235 }
236 
237 
238 bool
240  if( !dynamic_cast< DistancePairConstraint const * > ( &other_cst ) ) return false;
241 
242  DistancePairConstraint const & other( static_cast< DistancePairConstraint const & > (other_cst) );
243 
244  if( atomA1_ != other.atomA1_ ) return false;
245  if( atomA2_ != other.atomA2_ ) return false;
246  if( atomB1_ != other.atomB1_ ) return false;
247  if( atomB2_ != other.atomB2_ ) return false;
248  if( func_ != other.func_ ) return false;
249  if( this->score_type() != other.score_type() ) return false;
250 
251  return true;
252 }
253 
254 
255 void DistancePairConstraint::show( std::ostream & out ) const {
256  out << "DistancePairConstraint";
257  for ( Size i = 1; i <= natoms(); ++i ) {
258  AtomID const & id = atom(i);
259  out << ' ' << id.rsd() << ' ' << id.atomno();
260  }
261  out << ' ';
262  func_->show_definition(out);
263 }
264 
265 
267  std::ostream& out,
268  pose::Pose const& pose,
269  Size verbose_level,
270  Real threshold
271 ) const {
272  if ( verbose_level > 80 ) {
273  out << "DistancePair ("
274  << pose.residue_type(atomA1_.rsd() ).atom_name( atomA1_.atomno() ) << ":"
275  << atomA1_.atomno() << "," << atomA1_.rsd() << "-"
276  << pose.residue_type(atomA2_.rsd() ).atom_name( atomA2_.atomno() ) << ":"
277  << atomA2_.atomno() << "," << atomA2_.rsd() << " === "
278  << pose.residue_type(atomB1_.rsd() ).atom_name( atomB1_.atomno() ) << ":"
279  << atomB1_.atomno() << "," << atomB1_.rsd() << "-"
280  << pose.residue_type(atomB2_.rsd() ).atom_name( atomB2_.atomno() ) << ":"
281  << atomB2_.atomno() << "," << atomB2_.rsd() << "-";
282  }
283  return func_->show_violations( out, 0.0, verbose_level, threshold );
284 }
285 
286 
287 Real
288 DistancePairConstraint::func( Real const theta ) const {
289  return func_->func( theta );
290 }
291 
292 Real
293 DistancePairConstraint::dfunc( Real const theta ) const {
294  return func_->dfunc( theta );
295 }
296 
297 } // constraints
298 } // scoring
299 } // core