Simpatico  v1.10
CosineDihedral.h
1 #ifndef SIMP_COSINE_DIHEDRAL_H
2 #define SIMP_COSINE_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/global.h>
12 #include <util/space/Vector.h>
13 #include <util/param/ParamComposite.h> // base class
14 
15 #include "Torsion.h" // used in in-line function
16 #include "TorsionForce.h" // used in in-line function
17 
18 //#include <cmath>
19 
20 namespace Simp
21 {
22 
23  using namespace Util;
24 
39  {
40 
41  public:
42 
47 
51  CosineDihedral(const CosineDihedral& other);
52 
57 
58  // Default C++ destructor.
59 
65  void setNDihedralType(int nDihedralType);
66 
77  void readParameters(std::istream &in);
78 
84  virtual void loadParameters(Serializable::IArchive &ar);
85 
91  virtual void save(Serializable::OArchive &ar);
92 
100  void set(std::string name, int type, double value);
101 
116  double energy(const Vector& b1, const Vector& b2, const Vector& b3,
117  int type) const;
118 
131  void force(const Vector& b1, const Vector& b2, const Vector& b3,
132  Vector& f1, Vector& f2, Vector& f3, int type) const;
133 
141  double get(std::string name, int type) const;
142 
146  std::string className() const;
147 
148  private:
149 
151  static const int MaxNDihedralType = 8;
152 
153  double kappa_[MaxNDihedralType];
154  int nDihedralType_;
155 
156  };
157 
158  // Inline method definitions
159 
160  /*
161  * Return dihedral energy.
162  */
163  inline
164  double CosineDihedral::energy(const Vector& b1, const Vector& b2,
165  const Vector& b3, int type) const
166  {
167  Torsion torsion;
168  bool status;
169  status = torsion.computeAngle(b1, b2, b3); // computes cosPhi
170  if (!status) {
171  return (kappa_[type] * (1.0 + torsion.cosPhi));
172  } else {
173  return 0.0;
174  }
175  }
176 
177  /*
178  * Return:
179  * f1 = d energy / d(b1)
180  * f2 = d energy / d(b2)
181  * f3 = d energy / d(b3)
182  * for use in MD and stress calculation.
183  */
184  inline
185  void CosineDihedral::force(const Vector& b1, const Vector& b2,
186  const Vector& b3, Vector& f1, Vector& f2, Vector& f3, int type) const
187  {
188  TorsionForce torsion;
189  bool status; // Error code, 0 is normal, 1 is error
190  status = torsion.computeDerivatives(b1, b2, b3);
191 
192  if (!status) {
193  double dEdCosPhi = kappa_[type];
194  f1.multiply(torsion.d1, dEdCosPhi);
195  f2.multiply(torsion.d2, dEdCosPhi);
196  f3.multiply(torsion.d3, dEdCosPhi);
197  } else {
198  f1.zero();
199  f2.zero();
200  f3.zero();
201  }
202  }
203 
204 }
205 #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
std::string className() const
Return name string "CosineDihedral" for this evaluator class.
A Vector is a Cartesian vector.
Definition: Vector.h:75
void setNDihedralType(int nDihedralType)
Set the number of dihedral types.
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.
File containing preprocessor macros for error handling.
Classes used by all simpatico molecular simulations.
CosineDihedral()
Default constructor.
Saving / output archive for binary ostream.
CosineDihedral & operator=(const CosineDihedral &other)
Assignment.
Utility classes for scientific computation.
Definition: accumulators.mod:1
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
Vector d3
Vector of derivatives d3[i] = d(cosPhi)/d(b3[i])
Definition: TorsionForce.h:62
virtual void loadParameters(Serializable::IArchive &ar)
Load internal state from an archive.
Saving archive for binary istream.
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.
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
An object that can read multiple parameters from file.
A dihedral potential proportional to cos(phi).
void readParameters(std::istream &in)
Read dihedral interaction parameters from input stream.