Rosetta 3.5
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
CartesianBondedEnergy.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 core/scoring/methods/CartesianBondedEnergy.hh
11 /// @brief
12 /// @author Frank DiMaio
13 /// @author Andrew Leaver-Fay optimized the code a bit
14 
15 #ifndef INCLUDED_core_scoring_methods_CartesianBondedEnergy_hh
16 #define INCLUDED_core_scoring_methods_CartesianBondedEnergy_hh
17 
18 // Unit headers
21 
22 // Package headers
27 
28 // Project headers
29 #include <core/pose/Pose.fwd.hh>
31 #include <core/types.hh>
32 
33 // boost
34 #include <boost/unordered_map.hpp>
35 #include <boost/tuple/tuple.hpp>
36 
37 // C++ headers
38 #include <iostream>
39 #include <map>
40 
41 #include <utility/pointer/ReferenceCount.hh>
42 #include <utility/fixedsizearray1.hh>
43 #include <utility/vector1.hh>
44 
45 //#include <map>
46 
47 
48 typedef boost::tuples::tuple< std::string, std::string, std::string, std::string, std::string > atm_name_quad;
49 typedef boost::tuples::tuple< std::string, std::string, std::string, std::string > atm_name_triple;
50 typedef boost::tuples::tuple< std::string, std::string, std::string > atm_name_pair;
51 typedef boost::tuples::tuple< std::string, std::string > atm_name_single;
52 
53 namespace boost {
54 namespace tuples {
55 
56 std::size_t hash_value(atm_name_quad const& e);
57 std::size_t hash_value(atm_name_triple const& e);
58 std::size_t hash_value(atm_name_pair const& e);
59 std::size_t hash_value(atm_name_single const& e);
60 bool operator==(atm_name_quad const& a,atm_name_quad const& b);
61 bool operator==(atm_name_triple const& a,atm_name_triple const& b);
62 bool operator==(atm_name_pair const& a,atm_name_pair const& b);
63 bool operator==(atm_name_single const& a,atm_name_single const& b);
64 
65 }
66 }
67 
68 namespace core {
69 namespace scoring {
70 namespace methods {
71 
72 
74 public:
75  typedef utility::fixedsizearray1< Size, 2 > Size2;
76  typedef utility::fixedsizearray1< Size, 3 > Size3;
77  typedef utility::fixedsizearray1< Size, 4 > Size4;
78  typedef std::pair< Size2, CartBondedParametersCOP > length_parameter;
79  typedef std::pair< Size3, CartBondedParametersCOP > angle_parameter;
80  typedef std::pair< Size4, CartBondedParametersCOP > torsion_parameter;
81 
82 public:
85 
94 
95  void bb_N_index( Size index );
96  void bb_CA_index( Size index );
97  void bb_C_index( Size index );
98  void bb_O_index( Size index );
99  void bb_H_index( Size index );
100 
104 
107  return length_params_;
108  }
109 
112  return angle_params_;
113  }
114 
117  return torsion_params_;
118  }
119 
120  /// @brief Exactly the same as proper torsion parameters, but parceled out
121  /// into their own section so that debugging information can be given for
122  /// these torsions in particular.
126  }
127 
128  /// @brief just the list of length parameters that are dependent on phi and psi; used for calculating dE/dphi and dE/dpsi
131  return bbdep_length_params_;
132  }
133 
134  /// @brief just the list of angle parameters that are dependent on phi and psi; used for calculating dE/dphi and dE/dpsi
137  return bbdep_angle_params_;
138  }
139 
143  }
144 
148  }
149 
150  Size bb_N_index() const { return bb_N_index_; }
151  Size bb_CA_index() const { return bb_CA_index_; }
152  Size bb_C_index() const { return bb_C_index_; }
153  Size bb_O_index() const { return bb_O_index_; }
154  Size bb_H_index() const { return bb_H_index_; }
155 
159  }
160 
164  }
165 
169  }
170 
171 private:
178 
179  /// For amino acids only: if they have a lower connection,
180  /// then what are the angle parameters for Cprev-at1-at2 for all
181  /// atoms at2 bonded to lower-connect-atom at1?
183 
184  /// For amino acids only: if they have an upper connection,
185  /// then what are the angle parameters for Nnext-at1-at2 for all
186  /// atoms at2 bonded to upper-connect-atom at1?
188 
189 
195 
199 
200 };
201 
202 ////////////////////
203 //fpd
204 // Database stores all ideal parameters
206 public:
207  IdealParametersDatabase(Real k_len, Real k_ang, Real k_tors, Real k_tors_prot, Real k_tors_improper);
208 
209  void init(Real k_len, Real k_ang, Real k_tors, Real k_tors_prot, Real k_tors_improper);
210 
213  core::chemical::ResidueType const & rsd_type,
214  std::string const & atm1_name,
215  std::string const & atm2_name,
216  std::string const & atm3_name,
217  std::string const & atm4_name
218  );
219 
220  // needs both names (for keying off databases) and indices (for building those not found from ideal)
222  lookup_angle(
223  core::chemical::ResidueType const & rsd_type,
224  bool pre_proline,
225  std::string const & atm1_name,
226  std::string const & atm2_name,
227  std::string const & atm3_name,
228  int atm1idx,
229  int atm2idx,
230  int atm3idx
231  );
232 
233  // needs both names (for keying off databases) and indices (for building those not found from ideal)
236  core::chemical::ResidueType const & rsd_type,
237  bool pre_proline,
238  std::string const & atm1_name,
239  std::string const & atm2_name,
240  int atm1idx,
241  int atm2idx
242  );
243 
244  // old-style interface to database
245  void
247  int atm1, int atm2, int atm3, int atm4, Real &Kphi, Real &phi0, Real &phi_step );
248 
249  // old-style interface to database
250  void
252  int atm1, int atm2, int atm3, Real &Ktheta, Real &d0);
253 
254  // old-style interface to database
255  void
256  lookup_length_legacy( core::pose::Pose const & pose, core::conformation::Residue const & res, int atm1, int atm2, Real &Kd, Real &d0 );
257 
260 
261  /// @brief Return a list of all the bond lengths, bond angles, and bond torsions
262  /// for a single residue type. This list is constructed lazily as required.
263  /// (This may cause thread safety issues!).
266  core::chemical::ResidueType const & restype,
267  bool prepro
268  );
269 
270 private:
271  // helper functions: find the ideal values by constructing from Rosetta's params file
272  void
274  core::chemical::ResidueType const & restype,
275  int atm1,
276  int atm2,
277  int atm3,
278  Real &Ktheta,
279  Real &theta0
280  );
281 
282  void
284  core::chemical::ResidueType const & restype,
285  int atm1,
286  int atm2,
287  Real &Kd,
288  Real &d0
289  );
290 
291  // another helper function: read backbone dependent db files
292  void
295  boost::unordered_map< atm_name_single, CartBondedParametersOP > &bondlengths,
296  boost::unordered_map< atm_name_pair, CartBondedParametersOP > &bondangles,
297  std::string res );
298 
299  void
301  core::chemical::ResidueType const & restype,
302  bool prepro
303  );
304 
305 private:
306 
307  // defaults (they should be rarely used as everything should be in the DB now)
309 
310  // backbone-independent parameters (keyed on atom names)
311  boost::unordered_map< atm_name_quad, CartBondedParametersOP > torsions_indep_;
312  boost::unordered_map< atm_name_triple, CartBondedParametersOP > bondangles_indep_;
313  boost::unordered_map< atm_name_pair, CartBondedParametersOP > bondlengths_indep_;
314 
315  // backbone-dependent parameter sets
316  boost::unordered_map< atm_name_pair, CartBondedParametersOP >
318  boost::unordered_map< atm_name_single, CartBondedParametersOP >
320 
321  // options
323 
324  // per residue-type data
325  std::map< chemical::ResidueType const *, ResidueCartBondedParametersOP > prepro_restype_data_;
326  std::map< chemical::ResidueType const *, ResidueCartBondedParametersOP > nonprepro_restype_data_;
327 
328 };
329 
330 
331 
332 
333 ///////////////////
334 ///
335 /// the energy method
337 public:
339 
340 public:
342 
344 
346 
347  /// clone
348  virtual
350  clone() const;
351 
352  virtual void
353  setup_for_scoring( pose::Pose & pose, ScoreFunction const & ) const;
354 
355  virtual
356  bool
358  pose::Pose const & pose,
359  Size res1,
360  Size res2
361  ) const;
362 
363  ///
364  virtual void
366  conformation::Residue const & rsd1,
367  conformation::Residue const & rsd2,
368  pose::Pose const & pose,
369  ScoreFunction const &,
370  EnergyMap & emap
371  ) const;
372 
373  void
375  conformation::Residue const &,
376  pose::Pose const &,
377  ScoreFunction const &,
378  EnergyMap &
379  ) const;
380 
381 
382  void
384  conformation::Residue const & rsd1,
385  conformation::Residue const & rsd2,
388  ResPairMinimizationData const & min_data,
389  pose::Pose const &,
390  EnergyMap const & weights,
391  utility::vector1< DerivVectorPair > & r1_atom_derivs,
392  utility::vector1< DerivVectorPair > & r2_atom_derivs
393  ) const;
394 
395  // dof (bbdep) derivatives
396  virtual
397  Real
399  conformation::Residue const & rsd,
400  ResSingleMinimizationData const & min_data,
401  id::DOF_ID const & dof_id,
402  id::TorsionID const & torsion_id,
403  pose::Pose const & pose,
404  ScoreFunction const & sfxn,
405  EnergyMap const & weights
406  ) const;
407 
408  virtual
409  bool
410  defines_intrares_energy( EnergyMap const & /*weights*/ ) const { return false; }
411 
412  virtual
413  bool
414  defines_intrares_dof_derivatives( pose::Pose const & ) const { return true; }
415 
416  //fpd use the new minimizer interface
417  virtual
418  bool
419  minimize_in_whole_structure_context( pose::Pose const & ) const { return false; }
420 
421  virtual
422  Distance
424 
425  virtual
427 
429  long_range_type() const;
430 
431 private:
432 
433  //////////////////////////////
434  /// Score evaluation methods
435  //////////////////////////////
436 
437  /// @brief here, rsd1.seqpos() < rsd2.seqpos()
438  void
440  conformation::Residue const & rsd1,
441  conformation::Residue const & rsd2,
442  pose::Pose const & pose,
443  ScoreFunction const & sf,
444  EnergyMap & emap
445  ) const;
446 
447  /// Methods for intra-residue energies
448 
449  //@brief because of separate pre-proline distributions
450  // this function must be called from residue_pair_energy
451  // rather than defined in intrares energy
452  void
454  conformation::Residue const & rsd,
455  ResidueCartBondedParameters const & rsdparams,
456  Real phi,
457  Real psi,
458  pose::Pose const & pose,
459  EnergyMap & emap
460  ) const;
461 
462  /// @brief helper function to handle intrares improper torsions
463  void
465  conformation::Residue const & rsd,
466  ResidueCartBondedParameters const & resparams,
467  pose::Pose const & pose,
468  EnergyMap & emap
469  ) const;
470 
471 
472  /// @brief helper function to handle intrares bond torsions
473  void
475  conformation::Residue const & rsd,
476  ResidueCartBondedParameters const & resparams,
477  Real const phi,
478  Real const psi,
479  pose::Pose const & pose,
480  EnergyMap & emap
481  ) const;
482 
483  /// @brief helper function to handle intrares bond angles
484  void
486  conformation::Residue const & rsd,
487  ResidueCartBondedParameters const & resparams,
488  Real const phi,
489  Real const psi,
490  pose::Pose const & pose,
491  EnergyMap & emap
492  ) const;
493 
494  /// @brief helper function to handle intrares bond lengths
495  void
497  conformation::Residue const & rsd,
498  ResidueCartBondedParameters const & resparams,
499  Real const phi,
500  Real const psi,
501  pose::Pose const & pose,
502  EnergyMap & emap
503  ) const;
504 
505  /// Methods for inter-residue energies
506 
507  /// @brief Evaluate all the inter-residue components
508  void
510  conformation::Residue const & rsd1,
511  conformation::Residue const & rsd2,
512  ResidueCartBondedParameters const & rsd1params,
513  ResidueCartBondedParameters const & rsd2params,
514  Real phi1,
515  Real psi1,
516  Real phi2,
517  Real psi2,
518  pose::Pose const & pose,
519  EnergyMap & emap
520  ) const;
521 
522  /// @brief Evaluate all inter
523  void
525  conformation::Residue const & rsd1,
526  conformation::Residue const & rsd2,
527  ResidueCartBondedParameters const & rsd1params,
528  ResidueCartBondedParameters const & rsd2params,
529  Real phi1,
530  Real psi1,
531  pose::Pose const & pose,
532  EnergyMap & emap
533  ) const;
534 
535  void
537  conformation::Residue const & rsd1,
538  conformation::Residue const & rsd2,
539  ResidueCartBondedParameters const & rsd1params,
540  ResidueCartBondedParameters const & rsd2params,
541  Real phi2,
542  Real psi2,
543  pose::Pose const & pose,
544  EnergyMap & emap
545  ) const;
546 
547  void
549  conformation::Residue const & rsd1,
550  conformation::Residue const & rsd2,
551  ResidueCartBondedParameters const & rsd1params,
552  ResidueCartBondedParameters const & rsd2params,
553  Real phi2,
554  Real psi2,
555  pose::Pose const & pose,
556  EnergyMap & emap
557  ) const;
558 
559 
560  void
562  conformation::Residue const & rsd1,
563  conformation::Residue const & rsd2,
564  ResidueCartBondedParameters const & rsd1params,
565  ResidueCartBondedParameters const & rsd2params,
566  pose::Pose const & pose,
567  EnergyMap & emap
568  ) const;
569 
570  /////////////////////////////////
571  /// Derivative evaluation methods
572  /////////////////////////////////
573 
574  // single-residue derivatives
575 
576  /// @brief evaluate all intra-residue derivatives
577  void
579  conformation::Residue const & rsd,
580  ResidueCartBondedParameters const & resparams,
581  Real phi,
582  Real psi,
583  EnergyMap const & weights,
585  ) const;
586 
587  /// @brief evaluate intra-residue (proper) torsion derivatives
588  void
590  conformation::Residue const & rsd,
591  ResidueCartBondedParameters const & resparams,
592  Real const phi,
593  Real const psi,
594  EnergyMap const & weights,
596  ) const;
597 
598  /// @brief evaluate intra-residue angle derivatives
599  void
601  conformation::Residue const & rsd,
602  ResidueCartBondedParameters const & resparams,
603  Real const phi,
604  Real const psi,
605  EnergyMap const & weights,
607  ) const;
608 
609  /// @brief evaluate intra-residue bond-length derivatives
610  void
612  conformation::Residue const & rsd,
613  ResidueCartBondedParameters const & resparams,
614  Real const phi,
615  Real const psi,
616  EnergyMap const & weights,
618  ) const;
619 
620 
621  /// @brief evaluate intra-residue improper torsion derivatives
622  void
624  conformation::Residue const & rsd,
625  ResidueCartBondedParameters const & resparams,
626  EnergyMap const & weights,
628  ) const;
629 
630  // residue-pair derivatives
631 
632  /// @brief evaluate inter-residue angle derivatives where
633  /// two of the atoms defining the angle are from rsd1
634  void
636  conformation::Residue const & rsd1,
637  conformation::Residue const & rsd2,
638  ResidueCartBondedParameters const & rsd1params,
639  ResidueCartBondedParameters const & rsd2params,
640  Real phi1,
641  Real psi1,
642  EnergyMap const & weights,
643  utility::vector1< DerivVectorPair > & r1_atom_derivs,
644  utility::vector1< DerivVectorPair > & r2_atom_derivs
645  ) const;
646 
647  /// @brief evaluate inter-residue angle derivatives where
648  /// two of the atoms defining the angle are from rsd2
649  void
651  conformation::Residue const & rsd1,
652  conformation::Residue const & rsd2,
653  ResidueCartBondedParameters const & rsd1params,
654  ResidueCartBondedParameters const & rsd2params,
655  Real phi2,
656  Real psi2,
657  EnergyMap const & weights,
658  utility::vector1< DerivVectorPair > & r1_atom_derivs,
659  utility::vector1< DerivVectorPair > & r2_atom_derivs
660  ) const;
661 
662  /// @brief evaluate inter-residue bond-length derivatives
663  void
665  conformation::Residue const & rsd1,
666  conformation::Residue const & rsd2,
667  ResidueCartBondedParameters const & rsd1params,
668  ResidueCartBondedParameters const & rsd2params,
669  Real phi2,
670  Real psi2,
671  EnergyMap const & weights,
672  utility::vector1< DerivVectorPair > & r1_atom_derivs,
673  utility::vector1< DerivVectorPair > & r2_atom_derivs
674  ) const;
675 
676  /// @brief evaluate inter-residue improper torsion derivatives
677  void
679  conformation::Residue const & rsd1,
680  conformation::Residue const & rsd2,
681  ResidueCartBondedParameters const & res1params,
682  ResidueCartBondedParameters const & res2params,
683  EnergyMap const & weights,
684  utility::vector1< DerivVectorPair > & r1_atom_derivs,
685  utility::vector1< DerivVectorPair > & r2_atom_derivs
686  ) const;
687 
688  ////////////////////////////////////////////////////////////////////
689  /// Common to evaluating the score for torsions, angles, and lengths
690  ////////////////////////////////////////////////////////////////////
691 
692 
693  /// @brief Evaluate either the harmonic or linearized-harmonic energy
694  /// given by either:
695  /// score = 0.5 * K * (val-val0)^2
696  /// or
697  /// score = 0.5 * K * (val-val0)^2 if abs(val-val0) < 1
698  /// = 0.5 * K * abs(val-val0) otherwise
699  Real eval_score( Real val, Real K, Real val0 ) const;
700 
701  /// @breif Evaluate the derivative for a
702 
703 private:
704 
705  // the ideal parameter database
707 
708  // option
710 
711  virtual
712  core::Size version() const;
713 
714 
715 };
716 
717 } // namespace methods
718 } // namespace scoring
719 } // namespace core
720 
721 
722 #endif // INCLUDED_core_scoring_methods_CartesianBondedEnergy_HH