Chemical Data Processing Library C++ API - Version 1.2.0
ElasticPotentialFunctions.hpp
Go to the documentation of this file.
1 /*
2  * ElasticPotentialFunctions.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_ELASTICPOTENTIALFUNCTIONS_HPP
30 #define CDPL_FORCEFIELD_ELASTICPOTENTIALFUNCTIONS_HPP
31 
35 #include "CDPL/Util/BitSet.hpp"
36 
37 
38 namespace CDPL
39 {
40 
41  namespace ForceField
42  {
43 
44  /*
45  * \since 1.1
46  */
47  template <typename ValueType, typename Iter, typename CoordsArray>
48  ValueType calcElasticPotentialEnergy(Iter beg, const Iter& end, const CoordsArray& coords);
49 
50  /*
51  * \since 1.1
52  */
53  template <typename ValueType, typename CoordsArray>
54  ValueType calcElasticPotentialEnergy(const ElasticPotential& pot, const CoordsArray& coords);
55 
73  template <typename ValueType, typename CoordsVec>
74  ValueType calcElasticPotentialEnergy(const CoordsVec& atom1_pos, const CoordsVec& atom2_pos,
75  const ValueType& force_const, const ValueType& ref_length);
76 
77  /*
78  * \since 1.1
79  */
80  template <typename ValueType, typename Iter, typename CoordsArray, typename GradVector>
81  ValueType calcElasticPotentialGradient(Iter beg, const Iter& end, const CoordsArray& coords, GradVector& grad);
82 
83  /*
84  * \since 1.1
85  */
86  template <typename ValueType, typename CoordsArray, typename GradVector>
87  ValueType calcElasticPotentialGradient(const ElasticPotential& pot, const CoordsArray& coords, GradVector& grad);
88 
121  template <typename ValueType, typename CoordsVec, typename GradVec>
122  ValueType calcElasticPotentialGradient(const CoordsVec& atom1_pos, const CoordsVec& atom2_pos, GradVec& atom1_grad, GradVec& atom2_grad,
123  const ValueType& force_const, const ValueType& ref_length);
124  } // namespace ForceField
125 } // namespace CDPL
126 
127 
128 // Implementation
129 // \cond DOC_IMPL_DETAILS
130 
131 template <typename ValueType, typename Iter, typename CoordsArray>
132 ValueType CDPL::ForceField::calcElasticPotentialEnergy(Iter beg, const Iter& end, const CoordsArray& coords)
133 {
134  return Detail::accumInteractionEnergies<ValueType>(beg, end, coords,
135  static_cast<ValueType (*)(const ElasticPotential&, const CoordsArray&)>(
136  &calcElasticPotentialEnergy<ValueType, CoordsArray>));
137 }
138 
139 template <typename ValueType, typename CoordsArray>
140 ValueType CDPL::ForceField::calcElasticPotentialEnergy(const ElasticPotential& pot, const CoordsArray& coords)
141 {
142  return calcElasticPotentialEnergy<ValueType>(coords[pot.getAtom1Index()], coords[pot.getAtom2Index()],
143  pot.getForceConstant(), pot.getReferenceLength());
144 }
145 
146 template <typename ValueType, typename CoordsVec>
147 ValueType CDPL::ForceField::calcElasticPotentialEnergy(const CoordsVec& atom1_pos, const CoordsVec& atom2_pos,
148  const ValueType& force_const, const ValueType& ref_length)
149 {
150  ValueType dr_ij = calcDistance<ValueType>(atom1_pos, atom2_pos) - ref_length;
151  ValueType e = force_const * dr_ij * dr_ij;
152 
153  return e;
154 }
155 
156 
157 template <typename ValueType, typename Iter, typename CoordsArray, typename GradVector>
158 ValueType CDPL::ForceField::calcElasticPotentialGradient(Iter beg, const Iter& end, const CoordsArray& coords, GradVector& grad)
159 {
160  return Detail::calcInteractionGradient<ValueType>(beg, end, coords, grad,
161  static_cast<ValueType (*)(const ElasticPotential&, const CoordsArray&, GradVector&)>(
162  &calcElasticPotentialGradient<ValueType, CoordsArray, GradVector>));
163 }
164 
165 template <typename ValueType, typename CoordsArray, typename GradVector>
166 ValueType CDPL::ForceField::calcElasticPotentialGradient(const ElasticPotential& pot, const CoordsArray& coords, GradVector& grad)
167 {
168  return calcElasticPotentialGradient<ValueType>(coords[pot.getAtom1Index()], coords[pot.getAtom2Index()], grad[pot.getAtom1Index()],
169  grad[pot.getAtom2Index()], pot.getForceConstant(), pot.getReferenceLength());
170 }
171 
172 template <typename ValueType, typename CoordsVec, typename GradVec>
173 ValueType CDPL::ForceField::calcElasticPotentialGradient(const CoordsVec& atom1_pos, const CoordsVec& atom2_pos, GradVec& atom1_grad, GradVec& atom2_grad,
174  const ValueType& force_const, const ValueType& ref_length)
175 {
176  ValueType dist_atom1_grad[3];
177  ValueType dist_atom2_grad[3];
178 
179  ValueType dr_ij = calcDistanceDerivatives<ValueType>(atom1_pos, atom2_pos, dist_atom1_grad, dist_atom2_grad) - ref_length;
180  ValueType grad_fact = ValueType(2) * force_const * dr_ij;
181 
182  Detail::scaleAddVector(dist_atom1_grad, grad_fact, atom1_grad);
183  Detail::scaleAddVector(dist_atom2_grad, grad_fact, atom2_grad);
184 
185  ValueType e = force_const * dr_ij * dr_ij;
186 
187  return e;
188 }
189 
190 // \endcond
191 
192 #endif // CDPL_FORCEFIELD_ELASTICPOTENTIALENERGYFUNCTIONS_HPP
Definition of the type CDPL::Util::BitSet.
Definition of the class CDPL::ForceField::ElasticPotential.
Definition of the preprocessor macro CDPL_FORCEFIELD_API.
Utility functions used in the calculation of force field energies and gradients.
Definition: ElasticPotential.hpp:45
ValueType calcElasticPotentialEnergy(Iter beg, const Iter &end, const CoordsArray &coords)
ValueType calcElasticPotentialGradient(Iter beg, const Iter &end, const CoordsArray &coords, GradVector &grad)
The namespace of the Chemical Data Processing Library.