Simpatico  v1.10
MultiHarmonicDihedral.h
1 #ifndef SIMP_MULTI_HARMONIC_DIHEDRAL_H
2 #define SIMP_MULTI_HARMONIC_DIHEDRAL_H
3 
4 /*
5 * Simpatico - Simulation Package for Polymeric and Molecular Liquids
6 *
7 * Copyright 2010 - 2017, The Regents of the University of Minnesota
8 * Distributed under the terms of the GNU General Public License.
9 */
10 
11 #include <util/param/ParamComposite.h> // base class
12 #include <util/containers/DArray.h> // member
13 #include <util/space/Vector.h> // inline function
14 #include <simp/interaction/dihedral/Torsion.h> // inline function
15 #include <simp/interaction/dihedral/TorsionForce.h> // inline function
16 #include <util/global.h>
17 
18 namespace Simp
19 {
20 
21  using namespace Util;
22 
37  {
38 
39  public:
40 
45 
50 
51  // Default C++ destructor.
52 
57 
63  void setNDihedralType(int nDihedralType);
64 
72  void readParameters(std::istream &in);
73 
81  void writeParam(std::ostream& out);
82 
88  virtual void loadParameters(Serializable::IArchive &ar);
89 
95  virtual void save(Serializable::OArchive &ar);
96 
104  void set(std::string name, int type, double value);
105 
120  double energy(const Vector& b1, const Vector& b2, const Vector& b3,
121  int type) const;
122 
135  void force(const Vector& b1, const Vector& b2, const Vector& b3,
136  Vector& f1, Vector& f2, Vector& f3, int type) const;
137 
145  double get(std::string name, int type) const;
146 
150  std::string className() const;
151 
152  private:
153 
154  struct Parameter
155  {
156 
157  public:
158 
159  // Coefficients in expansion V(phi) = \sum_m k_m cos(m phi)
160  double k0;
161  double k1;
162  double k2;
163  double k3;
164  double k4;
165 
166  // Coefficients in expansion V(phi) = \sum_m a_m cos^m(phi)
167  double a0;
168  double a1;
169  double a2;
170  double a3;
171  double a4;
172 
173  double g2;
174  double g3;
175  double g4;
176 
177  void init()
178  {
179  a0 = k0 - k2 + k4;
180  a1 = k1 - 3.0*k3;
181  a2 = 2.0*k2 - 8.0*k4;
182  a3 = 4.0*k3;
183  a4 = 8.0*k4;
184 
185  g2 = 2.0*a2;
186  g3 = 3.0*a3;
187  g4 = 4.0*a4;
188  }
189 
190  };
191 
194 
196  int nDihedralType_;
197 
198  };
199 
200  // Inline method definitions
201 
202  /*
203  * Return dihedral energy.
204  */
205  inline
206  double MultiHarmonicDihedral::energy(const Vector& b1, const Vector& b2,
207  const Vector& b3, int type) const
208  {
209  Torsion torsion;
210  bool status;
211  status = torsion.computeAngle(b1, b2, b3); // computes cosPhi
212  if (!status) {
213  double c = torsion.cosPhi;
214  const Parameter* p = &parameters_[type];
215  return (p->a0 + c*(p->a1 + c*(p->a2 + c*(p->a3 + c*p->a4))));
216  } else {
217  return 0.0;
218  }
219  }
220 
221  /*
222  * Compute and return vectors:
223  *
224  * f1 = d energy / d(b1)
225  * f2 = d energy / d(b2)
226  * f3 = d energy / d(b3)
227  *
228  * for use in MD and stress calculation.
229  */
230  inline
231  void MultiHarmonicDihedral::force(const Vector& b1, const Vector& b2,
232  const Vector& b3, Vector& f1, Vector& f2, Vector& f3, int type) const
233  {
234  TorsionForce torsion;
235  bool status;
236  status = torsion.computeDerivatives(b1, b2, b3);
237  if (!status) {
238  double c = torsion.cosPhi;
239  const Parameter* p = &parameters_[type];
240  double dEdC = p->a1 + c*(p->g2 + c*(p->g3 + c*p->g4));
241  f1.multiply(torsion.d1, dEdC);
242  f2.multiply(torsion.d2, dEdC);
243  f3.multiply(torsion.d3, dEdC);
244  } else {
245  f1.zero();
246  f2.zero();
247  f3.zero();
248  }
249  }
250 
251 }
252 #endif
Vector d1
Vector of derivatives d1[i] = d(cosPhi)/d(b1[i])
Definition: TorsionForce.h:52
Vector & zero()
Set all elements of a 3D vector to zero.
Definition: Vector.h:514
A Vector is a Cartesian vector.
Definition: Vector.h:75
bool computeDerivatives(const Vector &b1, const Vector &b2, const Vector &b3)
Compute cosPhi and derivatives.
Definition: TorsionForce.h:83
double cosPhi
Cosine of dihedral angle.
Definition: Torsion.h:42
Vector & multiply(const Vector &v, double s)
Multiply a vector v by a scalar s.
Definition: Vector.h:686
double energy(const Vector &b1, const Vector &b2, const Vector &b3, int type) const
Returns potential energy for one dihedral group.
void setNDihedralType(int nDihedralType)
Set the number of dihedral types.
File containing preprocessor macros for error handling.
Classes used by all simpatico molecular simulations.
void readParameters(std::istream &in)
Read dihedral interaction parameters from input stream.
Saving / output archive for binary ostream.
std::string className() const
Return name string "MultiHarmonicDihedral".
Utility classes for scientific computation.
Definition: accumulators.mod:1
A truncated Fourier series dihedral potential.
Computes derivatives of dihedral angle with respect to bond vectors.
Definition: TorsionForce.h:44
Vector d2
Vector of derivatives d2[i] = d(cosPhi)/d(b2[i])
Definition: TorsionForce.h:57
void force(const Vector &b1, const Vector &b2, const Vector &b3, Vector &f1, Vector &f2, Vector &f3, int type) const
Returns derivatives of energy with respect to bond vectors forming the dihedral group.
Vector d3
Vector of derivatives d3[i] = d(cosPhi)/d(b3[i])
Definition: TorsionForce.h:62
Dynamically allocatable contiguous array template.
Definition: DArray.h:31
Saving archive for binary istream.
virtual void loadParameters(Serializable::IArchive &ar)
Load internal state from an archive.
MultiHarmonicDihedral & operator=(const MultiHarmonicDihedral &other)
Assignment.
virtual void save(Serializable::OArchive &ar)
Save internal state to an archive.
bool computeAngle(const Vector &b1, const Vector &b2, const Vector &b3)
Compute cosPhi.
Definition: Torsion.h:75
Computes dihedral / torsion angle involving 3 bonds.
Definition: Torsion.h:34
void writeParam(std::ostream &out)
Write Fourier coefficients to output stream.
An object that can read multiple parameters from file.
MultiHarmonicDihedral()
Default constructor.