IMP logo
IMP Reference Guide  2.18.0
The Integrative Modeling Platform
CHARMMParameters.h
Go to the documentation of this file.
1 /**
2  * \file IMP/atom/CHARMMParameters.h
3  * \brief access to CHARMM force field parameters
4  *
5  * Copyright 2007-2022 IMP Inventors. All rights reserved.
6  *
7  */
8 
9 #ifndef IMPATOM_CHARMM_PARAMETERS_H
10 #define IMPATOM_CHARMM_PARAMETERS_H
11 
12 #include "internal/charmm_helpers.h"
13 #include "ForceFieldParameters.h"
14 #include "charmm_topology.h"
15 #include "atom_macros.h"
16 #include <IMP/file.h>
17 
18 #include <string>
19 // swig is being dumb
20 #ifdef SWIG
21 IMPKERNEL_BEGIN_NAMESPACE
22 class VersionInfo;
23 IMPKERNEL_END_NAMESPACE
24 #endif
25 
26 IMPATOM_BEGIN_NAMESPACE
27 
28 //! The parameters for a CHARMM bond or angle.
30  double force_constant;
31  double ideal;
34  out << "force constant: " << force_constant << "; ideal value: " << ideal;
35  });
36 
37 private:
38  friend class boost::serialization::access;
39 
40  template<class Archive> void serialize(Archive &ar, const unsigned int) {
41  ar & force_constant & ideal;
42  }
43 };
44 
46 
47 //! The parameters for a CHARMM dihedral or improper.
49  double force_constant;
50  int multiplicity;
51  double ideal;
54  out << "force constant: " << force_constant
55  << "; multiplicity: " << multiplicity << "; ideal value: " << ideal;
56  });
57 
58 private:
59  friend class boost::serialization::access;
60 
61  template<class Archive> void serialize(Archive &ar, const unsigned int) {
62  ar & force_constant & multiplicity & ideal;
63  }
64 };
65 
67 
68 class CHARMMTopology;
69 
70 //! CHARMM force field parameters.
71 /** This class reads in topology and parameter files in CHARMM format and
72  stores the information.
73 
74  It does not actually evaluate the force field itself - there are other
75  classes that use the parameters provided by this class to do that. For
76  example, the LennardJonesPairScore or CoulombPairScore evaluate the
77  nonbond terms of the CHARMM force field, while
78  CHARMMStereochemistryRestraint (or BondSingletonScore, AngleSingletonScore,
79  DihedralSingletonScore and ImproperSingletonScore) cover the bond terms.
80 
81  Typically, the create_topology() method is used to create a new
82  CHARMMTopology object for a given Hierarchy; that object can then be
83  used to assign atomic radii, bonds, etc.
84  */
85 class IMPATOMEXPORT CHARMMParameters : public ForceFieldParameters {
86  std::map<std::string, Element> atom_type_to_element_;
87  std::map<ResidueType, Pointer<CHARMMIdealResidueTopology> >
88  residue_topologies_;
89  std::map<std::string, Pointer<CHARMMPatch> > patches_;
90  std::map<internal::CHARMMBondNames, CHARMMBondParameters> bond_parameters_;
91  std::map<internal::CHARMMAngleNames, CHARMMBondParameters> angle_parameters_;
92 
93  typedef Vector<std::pair<internal::CHARMMDihedralNames,
95  DihedralParameters dihedral_parameters_;
96  DihedralParameters improper_parameters_;
97 
98  DihedralParameters::const_iterator find_dihedral(
99  DihedralParameters::const_iterator begin,
100  DihedralParameters::const_iterator end,
101  const internal::CHARMMDihedralNames &dihedral,
102  bool allow_wildcards) const;
103 
104  public:
105  //! Construction with CHARMM topology (and optionally parameters) file.
106  /** For addition of atom types, the topology file alone is enough;
107  for adding bonds and radii, both files are needed.
108 
109  Atom and residue naming in the topology file differs slightly between
110  CHARMM and PDB. If translate_names_to_pdb is set to true, some simple
111  translations are done to map CHARMM-style names to PDB-style for
112  standard amino acids and some other commonly-used residues and patches.
113  (This translation has already been done for the topology files included
114  with IMP and MODELLER, so it is only needed for topology files taken
115  from CHARMM itself or other sources.) The modifications are as follows:
116  - CHARMM HSD (unprotonated histidine) is mapped to PDB HIS.
117  - CD1 and CD2 atoms in LEU are swapped.
118  - OT1 and OT2 in CTER are mapped to O and OXT.
119  - CHARMM hydrogen names are mapped to PDB equivalents.
120  - CHARMM NTER, GLYP and CTER residues are modified slightly to avoid
121  removing the HN, HN and O atoms respectively, and adding excess bonds
122  to these atoms.
123  */
124  CHARMMParameters(TextInput topology_file_name,
125  TextInput par_file_name = TextInput(),
126  bool translate_names_to_pdb = false);
127 
128  /** \name Residue topology
129 
130  The class stores the topology of each residue type as defined in the
131  topology file, as a set of CHARMMIdealResidueTopology objects.
132  */
133  /**@{*/
134  void add_residue_topology(CHARMMIdealResidueTopology *res) {
135  res->set_was_used(true);
136  residue_topologies_.insert(
137  std::make_pair(ResidueType(res->get_type()), res));
138  }
139 
140  CHARMMIdealResidueTopology *get_residue_topology(ResidueType type) const {
141  std::map<ResidueType,
142  Pointer<CHARMMIdealResidueTopology> >::const_iterator it =
143  residue_topologies_.find(type);
144  if (it != residue_topologies_.end()) {
145  return it->second;
146  } else {
147  IMP_THROW("Residue " << type << " does not exist", ValueException);
148  }
149  }
150 
151  /** \name Patches
152 
153  The class stores patches as defined in the topology file, as a set of
154  CHARMMPatch objects.
155  */
156  /**@{*/
157  void add_patch(CHARMMPatch *patch) {
158  patch->set_was_used(true);
159  patches_.insert(std::make_pair(patch->get_type(), patch));
160  }
161 #if 0
162  // return of non const ref values is not allowed
163  CHARMMPatch &get_patch(std::string name) {
164  std::map<std::string, CHARMMPatch>::iterator it = patches_.find(name);
165  if (it != patches_.end()) {
166  return it->second;
167  } else {
168  IMP_THROW("Patch " << name << " does not exist", ValueException);
169  }
170  }
171 #endif
172 
173  CHARMMPatch *get_patch(std::string name) const {
174  std::map<std::string, Pointer<CHARMMPatch> >::const_iterator it =
175  patches_.find(name);
176  if (it != patches_.end()) {
177  return it->second;
178  } else {
179  IMP_THROW("Patch " << name << " does not exist", ValueException);
180  }
181  }
182  /**@}*/
183 
184  //! Create topology that corresponds to the primary sequence of the Hierarchy.
185  /** Residues are placed in different segments if they are deemed to be
186  "disconnected", i.e. they have different Chains as parents, they are
187  in different Fragments and the fragments are not consecutive (the last
188  residue index of the first Fragment and the first index of the second
189  Fragment are not consecutive), or their ancestors are different
190  (e.g. one Residue lives in a Chain and another does not have a Chain
191  parent) */
192  CHARMMTopology *create_topology(Hierarchy hierarchy) const;
193 
194  //! Get bond parameters for the bond between the two given CHARMM atom types.
195  /** The atom types may match in any order.
196  \throws IndexException if no parameters are present.
197  */
198  const CHARMMBondParameters &get_bond_parameters(std::string type1,
199  std::string type2) const {
200  internal::CHARMMBondNames types = internal::CHARMMBondNames(type1, type2);
201  if (bond_parameters_.find(types) != bond_parameters_.end()) {
202  return bond_parameters_.find(types)->second;
203  } else {
204  IMP_THROW("No CHARMM parameters found for bond " << type1 << "-" << type2,
206  }
207  }
208 
209  //! Get parameters for the angle between the three given CHARMM atom types.
210  /** The atom types may match in either forward or reverse order.
211  \throws IndexException if no parameters are present.
212  */
213  const CHARMMBondParameters &get_angle_parameters(std::string type1,
214  std::string type2,
215  std::string type3) const {
216  internal::CHARMMAngleNames types =
217  internal::CHARMMAngleNames(type1, type2, type3);
218  if (angle_parameters_.find(types) != angle_parameters_.end()) {
219  return angle_parameters_.find(types)->second;
220  } else {
221  IMP_THROW("No CHARMM parameters found for angle " << type1 << "-" << type2
222  << "-" << type3,
224  }
225  }
226 
227  //! Get parameters for the dihedral between the four given CHARMM atom types.
228  /** The atom types may match in either forward or reverse order. When
229  looking for a match in the library, wildcards are considered; an atom
230  type of X in the library will match any atom type. The most specific
231  match from the library is returned.
232 
233  Multiple sets of parameters can be specified for the same combination
234  of atom types in the library, in which case all of them are returned.
235 
236  \throws IndexException if no parameters are present.
237  */
239  std::string type1, std::string type2, std::string type3,
240  std::string type4) const {
242  internal::CHARMMDihedralNames types =
243  internal::CHARMMDihedralNames(type1, type2, type3, type4);
244  // Look for matches without wildcards
245  DihedralParameters::const_iterator match = find_dihedral(
246  dihedral_parameters_.begin(), dihedral_parameters_.end(), types, false);
247  if (match != dihedral_parameters_.end()) {
248  param.push_back(match->second);
249  while ((match = find_dihedral(match + 1, dihedral_parameters_.end(),
250  match->first, false)) !=
251  dihedral_parameters_.end()) {
252  param.push_back(match->second);
253  }
254  } else {
255  // If no matches, try again with wildcards
256  match = find_dihedral(
257  dihedral_parameters_.begin(), dihedral_parameters_.end(), types, true);
258  if (match != dihedral_parameters_.end()) {
259  param.push_back(match->second);
260  while ((match = find_dihedral(match + 1, dihedral_parameters_.end(),
261  match->first, true)) !=
262  dihedral_parameters_.end()) {
263  param.push_back(match->second);
264  }
265  }
266  }
267 
268  if (param.size() == 0) {
269  IMP_THROW("No CHARMM parameters found for dihedral "
270  << type1 << "-" << type2 << "-" << type3 << "-" << type4,
272  } else {
273  return param;
274  }
275  }
276 
277  //! Get parameters for the improper between the four given CHARMM atom types.
278  /** The atom types may match in either forward or reverse order. When
279  looking for a match in the library, wildcards are considered; an atom
280  type of X in the library will match any atom type. The most specific
281  match from the library is returned.
282 
283  \throws IndexException if no parameters are present.
284  */
286  std::string type1, std::string type2, std::string type3,
287  std::string type4) const {
288  internal::CHARMMDihedralNames types =
289  internal::CHARMMDihedralNames(type1, type2, type3, type4);
290  // Return just the first match; wildcards are OK
291  DihedralParameters::const_iterator it = find_dihedral(
292  improper_parameters_.begin(), improper_parameters_.end(), types, true);
293  if (it != improper_parameters_.end()) {
294  return it->second;
295  } else {
296  IMP_THROW("No CHARMM parameters found for improper "
297  << type1 << "-" << type2 << "-" << type3 << "-" << type4,
299  }
300  }
301 
302  //! Auto-generate Angle particles from the passed list of Bond particles.
303  /** The angles consist of all unique pairs of bonds which share an
304  endpoint. If no parameters are found for an angle, it is simply
305  created without those parameters.
306 
307  The list of newly-created Angle particles can be passed to a
308  StereochemistryPairFilter to exclude 1-3 interactions from the
309  nonbonded list, or to an AngleSingletonScore to score each angle.
310 
311  \return a list of the newly-created Angle particles.
312 
313  \see CHARMMTopology::add_bonds().
314  */
315  Particles create_angles(Particles bonds) const;
316 
317  //! Auto-generate Dihedral particles from the passed list of Bond particles.
318  /** The dihedrals consist of all unique triples of bonds which form
319  dihedrals. If no parameters are found for a dihedral, it is simply
320  created without those parameters; if multiple sets of parameters are
321  found, multiple copies of the dihedral are created, each with one set
322  of parameters.
323 
324  The list of newly-created Dihedral particles can be passed to a
325  StereochemistryPairFilter to exclude 1-4 interactions from the
326  nonbonded list, or to a DihedralSingletonScore to score each dihedral.
327 
328  If dihedrals are explicitly listed in the CHARMM topology file, they
329  can be created if desired by calling CHARMMTopology::add_dihedrals()
330  rather than this function.
331 
332  \return a list of the newly-created Dihedral particles.
333 
334  \see CHARMMTopology::add_bonds().
335  */
336  Particles create_dihedrals(Particles bonds) const;
337 
339 
340  private:
341  virtual String get_force_field_atom_type(Atom atom) const override;
342 
343  void read_parameter_file(TextInput input_file);
344  // read topology file
345  void read_topology_file(TextInput input_file,
346  bool translate_names_to_pdb);
347 
348  void add_angle(Particle *p1, Particle *p2,
349  Particle *p3, Particles &ps) const;
350  void add_dihedral(Particle *p1, Particle *p2,
351  Particle *p3, Particle *p4,
352  Particles &ps) const;
353 
354  ResidueType parse_residue_line(const String &line,
355  bool translate_names_to_pdb);
356  void parse_atom_line(const String &line, ResidueType curr_res_type,
357  CHARMMResidueTopologyBase *residue,
358  bool translate_names_to_pdb);
359  void parse_bond_line(const String &line, ResidueType curr_res_type,
360  CHARMMResidueTopologyBase *residue,
361  bool translate_names_to_pdb);
362 
363  void parse_nonbonded_parameters_line(String line);
364  void parse_bonds_parameters_line(String line);
365  void parse_angles_parameters_line(String line);
366  void parse_dihedrals_parameters_line(String line, DihedralParameters &param);
367  WarningContext warn_context_;
368 };
369 
371 
372 /** The default CHARMM parameters support normal amino acid
373  and nucleic acid residues and the atoms found in them.
374  To use CHARMM with heterogens or non-standard residues,
375  a different CHARMM parameters file must be used.
376 
377  No hydrogen parameters are read.
378 
379  \see get_all_atom_CHARMM_parameters();
380 */
382 
383 /** The default CHARMM parameters support normal amino acid
384  and nucleic acid residues and the atoms found in them.
385  To use CHARMM with heterogens or non-standard residues,
386  a different CHARMM parameters file must be used.
387 
388  \see get_heavy_atom_CHARMM_parameters()
389 */
391 
392 IMPATOM_END_NAMESPACE
393 
394 #endif /* IMPATOM_CHARMM_PARAMETERS_H */
The ideal topology of a single residue.
CHARMMParameters * get_heavy_atom_CHARMM_parameters()
Storage and access to force field.
#define IMP_SHOWABLE_INLINE(Name, how_to_show)
Declare the methods needed by an object that can be printed.
The parameters for a CHARMM bond or angle.
#define IMP_OBJECT_METHODS(Name)
Define the basic things needed by any Object.
Definition: object_macros.h:25
The parameters for a CHARMM dihedral or improper.
force field base class
Handling of file input/output.
const CHARMMBondParameters & get_angle_parameters(std::string type1, std::string type2, std::string type3) const
Get parameters for the angle between the three given CHARMM atom types.
A more IMP-like version of the std::vector.
Definition: Vector.h:42
const CHARMMBondParameters & get_bond_parameters(std::string type1, std::string type2) const
Get bond parameters for the bond between the two given CHARMM atom types.
Warnings with the same key within the context are only output once.
A smart pointer to a reference counted object.
Definition: Pointer.h:87
CHARMM force field parameters.
Classes for handling CHARMM-style topology.
const CHARMMDihedralParameters & get_improper_parameters(std::string type1, std::string type2, std::string type3, std::string type4) const
Get parameters for the improper between the four given CHARMM atom types.
#define IMP_VALUES(Name, PluralName)
Define the type for storing sets of values.
Definition: value_macros.h:23
The standard decorator for manipulating molecular structures.
Base class for all CHARMM residue-based topology.
A decorator for a particle representing an atom.
Definition: atom/Atom.h:238
The type for a residue.
An exception for a request for an invalid member of a container.
Definition: exception.h:156
A CHARMM patch residue.
#define IMP_OBJECTS(Name, PluralName)
Define the types for storing lists of object pointers.
Definition: object_macros.h:44
#define IMP_THROW(message, exception_name)
Throw an exception with a message.
Definition: check_macros.h:50
Macros for maintaining molecular hierarchies.
Class to handle individual particles of a Model object.
Definition: Particle.h:41
CHARMMDihedralParametersList get_dihedral_parameters(std::string type1, std::string type2, std::string type3, std::string type4) const
Get parameters for the dihedral between the four given CHARMM atom types.
The topology of a complete CHARMM model.
CHARMMParameters * get_all_atom_CHARMM_parameters()
An exception for an invalid value being passed to IMP.
Definition: exception.h:136
std::string String
Basic string value.
Definition: types.h:43
void set_was_used(bool tf) const