Chemical Data Processing Library C++ API - Version 1.1.1
MMFF94GradientCalculator.hpp
Go to the documentation of this file.
1 /*
2  * MMFF94GradientCalculator.hpp
3  *
4  * This file is part of the Chemical Data Processing Toolkit
5  *
6  * Copyright (C) 2003 Thomas Seidel <thomas.seidel@univie.ac.at>
7  *
8  * This library is free software; you can redistribute it and/or
9  * modify it under the terms of the GNU Lesser General Public
10  * License as published by the Free Software Foundation; either
11  * version 2 of the License, or (at your option) any later version.
12  *
13  * This library is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16  * Lesser General Public License for more details.
17  *
18  * You should have received a copy of the GNU Lesser General Public License
19  * along with this library; see the file COPYING. If not, write to
20  * the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
21  * Boston, MA 02111-1307, USA.
22  */
23 
29 #ifndef CDPL_FORCEFIELD_MMFF94GRADIENTCALCULATOR_HPP
30 #define CDPL_FORCEFIELD_MMFF94GRADIENTCALCULATOR_HPP
31 
32 #include <cstddef>
33 
39 #include "CDPL/Util/BitSet.hpp"
40 
41 
42 namespace CDPL
43 {
44 
45  namespace ForceField
46  {
47 
48  template <typename ValueType>
50  {
51 
52  public:
54 
55  MMFF94GradientCalculator(const MMFF94InteractionData& ia_data, std::size_t num_atoms);
56 
57  void setEnabledInteractionTypes(unsigned int types);
58 
59  unsigned int getEnabledInteractionTypes() const;
60 
61  void setup(const MMFF94InteractionData& ia_data, std::size_t num_atoms);
62 
63  template <typename CoordsArray>
64  const ValueType& operator()(const CoordsArray& coords);
65 
66  template <typename CoordsArray, typename GradVector>
67  const ValueType& operator()(const CoordsArray& coords, GradVector& grad);
68 
69  const ValueType& getTotalEnergy() const;
70 
71  const ValueType& getBondStretchingEnergy() const;
72 
73  const ValueType& getAngleBendingEnergy() const;
74 
75  const ValueType& getStretchBendEnergy() const;
76 
77  const ValueType& getOutOfPlaneBendingEnergy() const;
78 
79  const ValueType& getTorsionEnergy() const;
80 
81  const ValueType& getElectrostaticEnergy() const;
82 
83  const ValueType& getVanDerWaalsEnergy() const;
84 
86 
87  void setFixedAtomMask(const Util::BitSet& mask);
88 
90 
91  private:
92  const MMFF94InteractionData* interactionData;
93  std::size_t numAtoms;
94  ValueType totalEnergy;
95  ValueType bondStretchingEnergy;
96  ValueType angleBendingEnergy;
97  ValueType stretchBendEnergy;
98  ValueType outOfPlaneEnergy;
99  ValueType torsionEnergy;
100  ValueType electrostaticEnergy;
101  ValueType vanDerWaalsEnergy;
102  unsigned int interactionTypes;
103  Util::BitSet fixedAtomMask;
104  };
105  } // namespace ForceField
106 } // namespace CDPL
107 
108 
109 // Implementation
110 // \cond DOC_IMPL_DETAILS
111 
112 template <typename ValueType>
114  interactionData(0), numAtoms(0), totalEnergy(), bondStretchingEnergy(), angleBendingEnergy(),
115  stretchBendEnergy(), outOfPlaneEnergy(), torsionEnergy(), electrostaticEnergy(),
116  vanDerWaalsEnergy(), interactionTypes(InteractionType::ALL)
117 {}
118 
119 template <typename ValueType>
120 CDPL::ForceField::MMFF94GradientCalculator<ValueType>::MMFF94GradientCalculator(const MMFF94InteractionData& ia_data, std::size_t num_atoms):
121  interactionData(&ia_data), numAtoms(num_atoms), totalEnergy(), bondStretchingEnergy(), angleBendingEnergy(),
122  stretchBendEnergy(), outOfPlaneEnergy(), torsionEnergy(), electrostaticEnergy(),
123  vanDerWaalsEnergy(), interactionTypes(InteractionType::ALL)
124 {}
125 
126 template <typename ValueType>
128 {
129  interactionTypes = types;
130 }
131 
132 template <typename ValueType>
134 {
135  return interactionTypes;
136 }
137 
138 template <typename ValueType>
139 void CDPL::ForceField::MMFF94GradientCalculator<ValueType>::setup(const MMFF94InteractionData& ia_data, std::size_t num_atoms)
140 {
141  interactionData = &ia_data;
142  numAtoms = num_atoms;
143 }
144 
145 template <typename ValueType>
146 template <typename CoordsArray>
147 const ValueType& CDPL::ForceField::MMFF94GradientCalculator<ValueType>::operator()(const CoordsArray& coords)
148 {
149  if (!interactionData) {
150  totalEnergy = ValueType();
151  bondStretchingEnergy = ValueType();
152  angleBendingEnergy = ValueType();
153  stretchBendEnergy = ValueType();
154  outOfPlaneEnergy = ValueType();
155  torsionEnergy = ValueType();
156  electrostaticEnergy = ValueType();
157  vanDerWaalsEnergy = ValueType();
158 
159  return totalEnergy;
160  }
161 
162  totalEnergy = ValueType();
163 
164  if (interactionTypes & InteractionType::BOND_STRETCHING) {
165  bondStretchingEnergy = calcMMFF94BondStretchingEnergy<ValueType>(interactionData->getBondStretchingInteractions().getElementsBegin(),
166  interactionData->getBondStretchingInteractions().getElementsEnd(),
167  coords);
168  totalEnergy += bondStretchingEnergy;
169 
170  } else
171  bondStretchingEnergy = ValueType();
172 
173 
174  if (interactionTypes & InteractionType::ANGLE_BENDING) {
175  angleBendingEnergy = calcMMFF94AngleBendingEnergy<ValueType>(interactionData->getAngleBendingInteractions().getElementsBegin(),
176  interactionData->getAngleBendingInteractions().getElementsEnd(),
177  coords);
178  totalEnergy += angleBendingEnergy;
179 
180  } else
181  angleBendingEnergy = ValueType();
182 
183  if (interactionTypes & InteractionType::STRETCH_BEND) {
184  stretchBendEnergy = calcMMFF94StretchBendEnergy<ValueType>(interactionData->getStretchBendInteractions().getElementsBegin(),
185  interactionData->getStretchBendInteractions().getElementsEnd(),
186  coords);
187  totalEnergy += stretchBendEnergy;
188 
189  } else
190  stretchBendEnergy = ValueType();
191 
192  if (interactionTypes & InteractionType::OUT_OF_PLANE_BENDING) {
193  outOfPlaneEnergy = calcMMFF94OutOfPlaneBendingEnergy<ValueType>(interactionData->getOutOfPlaneBendingInteractions().getElementsBegin(),
194  interactionData->getOutOfPlaneBendingInteractions().getElementsEnd(),
195  coords);
196  totalEnergy += outOfPlaneEnergy;
197 
198  } else
199  outOfPlaneEnergy = ValueType();
200 
201  if (interactionTypes & InteractionType::TORSION) {
202  torsionEnergy = calcMMFF94TorsionEnergy<ValueType>(interactionData->getTorsionInteractions().getElementsBegin(),
203  interactionData->getTorsionInteractions().getElementsEnd(),
204  coords);
205  totalEnergy += torsionEnergy;
206 
207  } else
208  torsionEnergy = ValueType();
209 
210  if (interactionTypes & InteractionType::ELECTROSTATIC) {
211  electrostaticEnergy = calcMMFF94ElectrostaticEnergy<ValueType>(interactionData->getElectrostaticInteractions().getElementsBegin(),
212  interactionData->getElectrostaticInteractions().getElementsEnd(),
213  coords);
214  totalEnergy += electrostaticEnergy;
215 
216  } else
217  electrostaticEnergy = ValueType();
218 
219  if (interactionTypes & InteractionType::VAN_DER_WAALS) {
220  vanDerWaalsEnergy = calcMMFF94VanDerWaalsEnergy<ValueType>(interactionData->getVanDerWaalsInteractions().getElementsBegin(),
221  interactionData->getVanDerWaalsInteractions().getElementsEnd(),
222  coords);
223  totalEnergy += vanDerWaalsEnergy;
224 
225  } else
226  vanDerWaalsEnergy = ValueType();
227 
228  return totalEnergy;
229 }
230 
231 template <typename ValueType>
232 template <typename CoordsArray, typename GradVector>
233 const ValueType& CDPL::ForceField::MMFF94GradientCalculator<ValueType>::operator()(const CoordsArray& coords, GradVector& grad)
234 {
236 
237  if (!interactionData) {
238  totalEnergy = ValueType();
239  bondStretchingEnergy = ValueType();
240  angleBendingEnergy = ValueType();
241  stretchBendEnergy = ValueType();
242  outOfPlaneEnergy = ValueType();
243  torsionEnergy = ValueType();
244  electrostaticEnergy = ValueType();
245  vanDerWaalsEnergy = ValueType();
246 
247  return totalEnergy;
248  }
249 
250  totalEnergy = ValueType();
251 
252  if (interactionTypes & InteractionType::BOND_STRETCHING) {
253  bondStretchingEnergy = calcMMFF94BondStretchingGradient<ValueType>(interactionData->getBondStretchingInteractions().getElementsBegin(),
254  interactionData->getBondStretchingInteractions().getElementsEnd(),
255  coords, grad);
256  totalEnergy += bondStretchingEnergy;
257 
258  } else
259  bondStretchingEnergy = ValueType();
260 
261  if (interactionTypes & InteractionType::ANGLE_BENDING) {
262  angleBendingEnergy = calcMMFF94AngleBendingGradient<ValueType>(interactionData->getAngleBendingInteractions().getElementsBegin(),
263  interactionData->getAngleBendingInteractions().getElementsEnd(),
264  coords, grad);
265  totalEnergy += angleBendingEnergy;
266 
267  } else
268  angleBendingEnergy = ValueType();
269 
270  if (interactionTypes & InteractionType::STRETCH_BEND) {
271  stretchBendEnergy = calcMMFF94StretchBendGradient<ValueType>(interactionData->getStretchBendInteractions().getElementsBegin(),
272  interactionData->getStretchBendInteractions().getElementsEnd(),
273  coords, grad);
274  totalEnergy += stretchBendEnergy;
275 
276  } else
277  stretchBendEnergy = ValueType();
278 
279  if (interactionTypes & InteractionType::OUT_OF_PLANE_BENDING) {
280  outOfPlaneEnergy = calcMMFF94OutOfPlaneBendingGradient<ValueType>(interactionData->getOutOfPlaneBendingInteractions().getElementsBegin(),
281  interactionData->getOutOfPlaneBendingInteractions().getElementsEnd(),
282  coords, grad);
283  totalEnergy += outOfPlaneEnergy;
284 
285  } else
286  outOfPlaneEnergy = ValueType();
287 
288  if (interactionTypes & InteractionType::TORSION) {
289  torsionEnergy = calcMMFF94TorsionGradient<ValueType>(interactionData->getTorsionInteractions().getElementsBegin(),
290  interactionData->getTorsionInteractions().getElementsEnd(),
291  coords, grad);
292  totalEnergy += torsionEnergy;
293 
294  } else
295  torsionEnergy = ValueType();
296 
297  if (interactionTypes & InteractionType::ELECTROSTATIC) {
298  electrostaticEnergy = calcMMFF94ElectrostaticGradient<ValueType>(interactionData->getElectrostaticInteractions().getElementsBegin(),
299  interactionData->getElectrostaticInteractions().getElementsEnd(),
300  coords, grad);
301  totalEnergy += electrostaticEnergy;
302 
303  } else
304  electrostaticEnergy = ValueType();
305 
306  if (interactionTypes & InteractionType::VAN_DER_WAALS) {
307  vanDerWaalsEnergy = calcMMFF94VanDerWaalsGradient<ValueType>(interactionData->getVanDerWaalsInteractions().getElementsBegin(),
308  interactionData->getVanDerWaalsInteractions().getElementsEnd(),
309  coords, grad);
310  totalEnergy += vanDerWaalsEnergy;
311 
312  } else
313  vanDerWaalsEnergy = ValueType();
314 
315  if (!fixedAtomMask.empty())
316  for (Util::BitSet::size_type i = fixedAtomMask.find_first(); i != Util::BitSet::npos; i = fixedAtomMask.find_next(i))
317  grad[i].clear(ValueType());
318 
319  return totalEnergy;
320 }
321 
322 template <typename ValueType>
324 {
325  return totalEnergy;
326 }
327 
328 template <typename ValueType>
330 {
331  return bondStretchingEnergy;
332 }
333 
334 template <typename ValueType>
336 {
337  return angleBendingEnergy;
338 }
339 
340 template <typename ValueType>
342 {
343  return stretchBendEnergy;
344 }
345 
346 template <typename ValueType>
348 {
349  return outOfPlaneEnergy;
350 }
351 
352 template <typename ValueType>
354 {
355  return torsionEnergy;
356 }
357 
358 template <typename ValueType>
360 {
361  return electrostaticEnergy;
362 }
363 
364 template <typename ValueType>
366 {
367  return vanDerWaalsEnergy;
368 }
369 
370 template <typename ValueType>
372 {
373  return fixedAtomMask;
374 }
375 
376 template <typename ValueType>
378 {
379  fixedAtomMask = mask;
380 }
381 
382 template <typename ValueType>
384 {
385  fixedAtomMask.clear();
386 }
387 
388 // \endcond
389 
390 #endif // CDPL_FORCEFIELD_MMFF94GRADIENTCALCULATOR_HPP
CDPL::ForceField::MMFF94GradientCalculator::getTotalEnergy
const ValueType & getTotalEnergy() const
CDPL::ForceField::MMFF94InteractionData
Definition: MMFF94InteractionData.hpp:51
CDPL::ForceField::InteractionType::TORSION
const unsigned int TORSION
Definition: InteractionType.hpp:50
MMFF94EnergyFunctions.hpp
Functions for the calculation of MMFF94 interaction energies.
CDPL::Chem::ReactionRole::ALL
const unsigned int ALL
Specifies reactants, agents and products of a reaction.
Definition: ReactionRole.hpp:74
CDPL::ForceField::MMFF94GradientCalculator::setFixedAtomMask
void setFixedAtomMask(const Util::BitSet &mask)
CDPL::Util::BitSet
boost::dynamic_bitset BitSet
A dynamic bitset class.
Definition: BitSet.hpp:46
MMFF94GradientFunctions.hpp
Functions for the calculation of MMFF94 interaction energy gradients.
CDPL::ForceField::MMFF94GradientCalculator::resetFixedAtomMask
void resetFixedAtomMask()
CDPL::ForceField::InteractionType::BOND_STRETCHING
const unsigned int BOND_STRETCHING
Definition: InteractionType.hpp:46
CDPL::ForceField::MMFF94GradientCalculator::operator()
const ValueType & operator()(const CoordsArray &coords)
BitSet.hpp
Definition of the type CDPL::Util::BitSet.
CDPL::ForceField::InteractionType::ANGLE_BENDING
const unsigned int ANGLE_BENDING
Definition: InteractionType.hpp:47
CDPL::ForceField::MMFF94GradientCalculator::operator()
const ValueType & operator()(const CoordsArray &coords, GradVector &grad)
CDPL::ForceField::MMFF94GradientCalculator::getElectrostaticEnergy
const ValueType & getElectrostaticEnergy() const
CDPL::ForceField::MMFF94GradientCalculator::getTorsionEnergy
const ValueType & getTorsionEnergy() const
CDPL::ForceField::MMFF94GradientCalculator::getAngleBendingEnergy
const ValueType & getAngleBendingEnergy() const
CDPL::ForceField::MMFF94GradientCalculator::getOutOfPlaneBendingEnergy
const ValueType & getOutOfPlaneBendingEnergy() const
CDPL::ForceField::GradientVectorTraits::clear
static void clear(VectorType &g, std::size_t num_elem)
Definition: GradientVectorTraits.hpp:51
CDPL::ForceField::InteractionType::VAN_DER_WAALS
const unsigned int VAN_DER_WAALS
Definition: InteractionType.hpp:51
CDPL::ForceField::MMFF94GradientCalculator::getBondStretchingEnergy
const ValueType & getBondStretchingEnergy() const
CDPL::ForceField::MMFF94GradientCalculator::getEnabledInteractionTypes
unsigned int getEnabledInteractionTypes() const
CDPL::ForceField::InteractionType::ELECTROSTATIC
const unsigned int ELECTROSTATIC
Definition: InteractionType.hpp:52
CDPL::ForceField::MMFF94GradientCalculator::getFixedAtomMask
const Util::BitSet & getFixedAtomMask() const
CDPL
The namespace of the Chemical Data Processing Library.
CDPL::ForceField::MMFF94GradientCalculator::getStretchBendEnergy
const ValueType & getStretchBendEnergy() const
CDPL::ForceField::InteractionType::STRETCH_BEND
const unsigned int STRETCH_BEND
Definition: InteractionType.hpp:48
CDPL::ForceField::MMFF94GradientCalculator::setEnabledInteractionTypes
void setEnabledInteractionTypes(unsigned int types)
InteractionType.hpp
Definition of constants in namespace CDPL::ForceField::InteractionType.
CDPL::ForceField::MMFF94GradientCalculator::MMFF94GradientCalculator
MMFF94GradientCalculator(const MMFF94InteractionData &ia_data, std::size_t num_atoms)
GradientVectorTraits.hpp
Definition of the class CDPL::ForceField::GradientVectorTraits.
CDPL::ForceField::MMFF94GradientCalculator
Definition: MMFF94GradientCalculator.hpp:50
CDPL::ForceField::MMFF94GradientCalculator::setup
void setup(const MMFF94InteractionData &ia_data, std::size_t num_atoms)
CDPL::ForceField::MMFF94GradientCalculator::MMFF94GradientCalculator
MMFF94GradientCalculator()
CDPL::ForceField::InteractionType::OUT_OF_PLANE_BENDING
const unsigned int OUT_OF_PLANE_BENDING
Definition: InteractionType.hpp:49
CDPL::ForceField::MMFF94GradientCalculator::getVanDerWaalsEnergy
const ValueType & getVanDerWaalsEnergy() const
MMFF94InteractionData.hpp
Definition of the class CDPL::ForceField::MMFF94InteractionData.