Rosetta 3.5
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
ConstraintSet.hh
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
11 /// @brief
12 
13 
14 #ifndef INCLUDED_core_scoring_constraints_ConstraintSet_hh
15 #define INCLUDED_core_scoring_constraints_ConstraintSet_hh
16 
17 // Unit headers
19 #include <core/scoring/constraints/Func.hh> /// cant get to compile w/ Func.fwd.hh
20 
21 
22 // Package headers
30 
31 // Project headers
32 #include <core/types.hh>
35 #include <core/pose/Pose.fwd.hh>
36 #include <core/id/AtomID.fwd.hh>
37 #include <core/id/DOF_ID.fwd.hh>
38 // AUTO-REMOVED #include <core/id/TorsionID.fwd.hh>
41 #include <core/conformation/signals/LengthEvent.fwd.hh> //for observing conformation length changes
43 // Utility Headers
44 #include <utility/pointer/ReferenceCount.hh>
45 
46 //Utility Headers
47 
48 // C++ Headers
49 #include <map>
50 
51 #include <utility/vector1.hh>
52 
53 
54 namespace core {
55 namespace scoring {
56 namespace constraints {
57 
58 ////////////////////////////////////////////////////////////////////////////////////////
59 ////////////////////////////////////////////////////////////////////////////////////////
60 /// silly helper class, a wrapper for std::map so we can hold in owning_ptr
61 ////////////////////////////////////////////////////////////////////////////////////////
62 ////////////////////////////////////////////////////////////////////////////////////////
63 
65 public:
66  ///@brief Automatically generated virtual destructor for class deriving directly from ReferenceCount
67  virtual ~ResidueConstraints();
68  typedef std::map< Size, ConstraintsOP > Map;
69  typedef Map::const_iterator const_iterator;
70  typedef Map::iterator iterator;
71 
72 public:
74  begin() const
75  {
76  return map_.begin();
77  }
78 
80  end() const
81  {
82  return map_.end();
83  }
84 
86  find( Size const seqpos ) const
87  {
88  return map_.find( seqpos );
89  }
90 
91  iterator
92  find( Size const seqpos )
93  {
94  return map_.find( seqpos );
95  }
96 
97  void
98  erase( Size const seqpos )
99  {
100  map_.erase( seqpos );
101  }
102 
103  bool
104  has( Size const seqpos )
105  {
106  return ( map_.find( seqpos ) != map_.end() );
107  }
108 
109  void
110  insert( Size const seqpos, ConstraintsOP cst )
111  {
112  map_.insert( std::make_pair( seqpos, cst ) );
113  }
114 
115  Size
116  size() const
117  {
118  return map_.size();
119  }
120 
121  void
123  {
124  map_.clear();
125  }
126 
127 private:
129 };
130 
131 
132 
133 ////////////////////////////////////////////////////////////////////////////////////////
134 ////////////////////////////////////////////////////////////////////////////////////////
135 // ConstraintSet
136 ////////////////////////////////////////////////////////////////////////////////////////
137 ////////////////////////////////////////////////////////////////////////////////////////
138 
140 public:
143 
145  typedef pose::Pose Pose;
146 
149 
150  // typedef utility::vector1< DOF_ConstraintOP > DOF_Constraints;
151 
152 public:
153  ConstraintSet();
154  ConstraintSet( ConstraintSet const & other );
156  ConstraintSet const & other,
157  core::Size start_residue,
158  core::Size end_residue
159  );
160  /// @brief Destructor so far only detaches from conformation
162 
163  virtual ConstraintSetOP clone() const;
164 
165  /// @brief Copies the data from this ConstraintSet into a new object and
166  /// returns its OP; atoms are mapped to atoms with the same name in dest pose
167  /// ( e.g. for switch from centroid to fullatom ) if a sequence_mapping is
168  /// present it is used to map residue numbers .. NULL = identity mapping to
169  /// the new object. This will really clone all constraints since they have to
170  /// change their atom-numbers and residue-numbers
171  virtual ConstraintSetOP
173  pose::Pose const& src,
174  pose::Pose const& dest,
175  id::SequenceMappingCOP smap = NULL
176  ) const;
177 
178  /// @brief like remapped_clone, but constraints also steal_def from src-pose
179  /// use, e.g., to get a new set of CoordinateConstraints for given xyz
180  /// coordinates in src-pose
182  pose::Pose const& src,
183  pose::Pose const& dest,
184  id::SequenceMappingCOP smap = NULL
185  ) const;
186 
187 
188  /// @brief remaps the constraints in this particular constraint set according
189  /// to brief the passed in sequence mapping --- redundant with
190  /// remapped_clone!!!
191  void
193  id::SequenceMapping const & smap
194  );
195 
196  /// @brief Cache the ConstraintsCOP for a particular residue
197  /// in the res_data_cache, under the "cst_res_data" element of
198  /// the data-cache's CachableDataOP array. Derived ConstraintSet
199  /// classes should decide HERE whether any constraints should be evaluated
200  /// for this residue, since, once a ConstraintsOP is added
201  /// to the minimization graph, the derived class looses the chance to
202  /// veto the evaluation of that constraint.
203  virtual
204  void
206  conformation::Residue const & rsd,
207  pose::Pose const & pose,
208  ScoreFunction const & sfxn,
209  kinematics::MinimizerMapBase const & minmap,
210  ResSingleMinimizationData & res_data_cache
211  ) const;
212 
213 
214  /// @brief Cache the ConstraintsCOP for a particular residue pair
215  /// in the respair_data_cache, under the "cst_respair_data" element of
216  /// the data-cache's CachableDataOP array. Derived ConstraintSet
217  /// classes should decide HERE whether any constraints should be evaluated
218  /// between this pair of residues, since, once a ConstraintsOP is added
219  /// to the minimization graph, the derived class looses the chance to
220  /// veto the evaluation of that constraint.
221  virtual
222  void
224  conformation::Residue const & rsd1,
225  conformation::Residue const & rsd2,
226  pose::Pose const & pose,
227  ScoreFunction const & sfxn,
228  kinematics::MinimizerMapBase const & minmap,
229  ResSingleMinimizationData const & res1_data_cache,
230  ResSingleMinimizationData const & res2_data_cache,
231  ResPairMinimizationData & respair_data_cache
232  ) const;
233 
234 
235  virtual void
236  setup_for_scoring( pose::Pose & pose, ScoreFunction const & scfxn ) const;
237 
238  virtual void
239  setup_for_derivatives( pose::Pose & pose, ScoreFunction const & scfxn ) const;
240 
241  ///
242  virtual
243  void
245  Residue const & rsd1,
246  Residue const & rsd2,
247  Pose const & pose,
248  ScoreFunction const & scorefxn,
249  EnergyMap & emap
250  ) const;
251 
252  /// @brief Switching over to a pairwise decomposable eval-atom-deriv system for
253  /// RTMin means deprecating the old "evaluate an atom's derivative wrt the entire structure"
254  /// This function is preserved (for now) for use by the RNA_TorsionEnergy
255  virtual
256  void
258  id::AtomID const & atom_id,
259  pose::Pose const & pose,
260  ScoreFunction const &,
261  EnergyMap const & weights,
262  Vector & F1,
263  Vector & F2
264  ) const;
265 
266  /// @brief evaluate the derivatives for an atom that contains 3- or higher-body
267  /// constraints. Such derivatives cannot be evalauated in an extra-posal context
268  /// (e.g. such as in RTMin).
269  virtual
270  void
272  id::AtomID const & atom_id,
273  pose::Pose const & pose,
274  ScoreFunction const &,
275  EnergyMap const & weights,
276  Vector & F1,
277  Vector & F2
278  ) const;
279 
280  /// uses the dof constraints
281  /*
282  Real
283  eval_dof_derivative(
284  id::DOF_ID const & id,
285  id::TorsionID const & tor,
286  pose::Pose const & pose,
287  ScoreFunction const & scorefxn,
288  EnergyMap const & weights
289  ) const;*/
290 
291 
292  ///
293  virtual bool
294  residue_pair_constraint_exists( int const pos1, int const pos2 ) const
295  {
296  return ( residue_pair_constraints_.size() >= Size(pos1) &&
297  residue_pair_constraints_[ pos1 ] &&
298  residue_pair_constraints_[ pos1 ]->has( pos2 ) );
299  }
300 
301  ///
302  virtual bool
304  return ( (residue_pair_constraints_.size() >= pos ) &&
306  );
307  }
308 
309  ///
310  virtual void
312  conformation::Residue const & rsd,
313  pose::Pose const & pose,
314  ScoreFunction const & sfxn,
315  EnergyMap & emap
316  ) const;
317 
318  ///
319  void
321  conformation::Residue const & rsd,
322  EnergyMap & emap
323  ) const;
324 
325  /// Does *NOT* zero the emap values, just adds the additional contribution to the
326  /// existing emap energies (so can be called inside finalize_total_energies)
327  virtual void
329  Pose const & pose,
330  ScoreFunction const & sfxn,
331  EnergyMap & emap
332  ) const;
333 
334  ///
335  void
337 
338  void
339  add_constraints( ConstraintCOPs cst_list );
340 
341  /// @brief Returns true if the constraint was successfully found and removed.
342  /// if object comparison is set to true, the constraint to be removed is found
343  /// through the Constraint::== operator and not through pointer comparison
344  bool
346  ConstraintCOP cst,
347  bool object_comparison );
348 
349  // @brief returns true if all the constraints in the list were successfully
350  // found and removed.
351  bool
353  ConstraintCOPs cst_list,
354  bool object_comparison );
355 
356  /// @brief Note -- still hacky. Will not be included in packing, just scoring
357  /// and minimization
358  void
360  DOF_ID const & id,
361  FuncOP func,
362  ScoreType const & t = dof_constraint
363  );
364 
365  /// @brief Returns all constraints in the set as a flat list, regardless of
366  /// type.
368  get_all_constraints() const;
369 
371  residue_pair_constraints_begin( Size resid ) const;
372 
374  residue_pair_constraints_end( Size resid ) const;
375 
376  void
378 
379  void
382  );
383 
384  void
386 
387  void
389 
390  Size
391  revision_id() const;
392 
393  // output statements, useful for debugging
394  virtual void
395  show( std::ostream& out ) const;
396 
397  // output statements, useful for debugging
398  virtual void
399  show_definition( std::ostream& out, core::pose::Pose const& ) const;
400 
401  // this is the worst function name ever. This might as well be print_string.
402  virtual void
403  show_numbers( std::ostream& out ) const;
404 
405  virtual Size
407  std::ostream & out,
408  pose::Pose &,
409  Size verbose_level,
410  Real threshold = 1
411  ) const;
412 
413  bool
415  return residue_pair_constraints_.size() > 0;
416  }
417 
418  bool
420  return intra_residue_constraints_.size() > 0;
421  }
422 
423  bool
425  return dof_constraints_.size() > 0;
426  }
427 
428  bool
430  return non_residue_pair_constraints_.size() > 0;
431  }
432 
433  bool
434  has_constraints() const {
439  }
440 
441  void
442  clear();
443 
444  bool
445  is_empty() const;
446 
447 protected:
448 
449 
450  virtual
451  void
453  id::AtomID const & atom_id,
454  pose::Pose const & pose,
455  ScoreFunction const &,
456  EnergyMap const & weights,
457  Vector & F1,
458  Vector & F2
459  ) const;
460 
461  void
463 
464 private:
465  void
467  Size const pos1,
468  Size const pos2,
469  ConstraintCOP cst
470  );
471 
472  /// @brief Returns true iff the constraint was successfully found and removed.
473  bool
475  Size const pos1,
476  Size const pos2,
477  ConstraintCOP cst,
478  bool object_comparison
479  );
480 
481 protected:
482  ResiduePairConstraints const &
483  residue_pair_constraints() const;
484 
487  }
488 
489 private:
490 
491  /// constraints are added symmetrically
493 
495 
497 
498  // do not put anything in this -- used to return iterators to empty containers
500 
501  // vector of DOF constraints
503 
504  // a constraint set's "state identifier" for rapidly determining if any constraints
505  // have changed since the last time the constraint energies were evaluated
507  mutable bool revision_id_current_;
508 
510 };
511 
512 std::ostream & operator << (std::ostream & os, ConstraintSet const & set);
513 
514 } // constraints
515 } // scoring
516 } // core
517 
518 #endif