Simpatico  v1.10
HarmonicAngle.h
1 #ifndef SIMP_HARMONIC_ANGLE_H
2 #define SIMP_HARMONIC_ANGLE_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 <simp/interaction/angle/BendForce.h> // used in inline function
13 #include <util/global.h>
14 #include <cmath>
15 
16 namespace Util {class Random;}
17 
18 namespace Simp
19 {
20 
21  using namespace Util;
22 
35  {
36 
37  public:
38 
42  HarmonicAngle();
43 
47  HarmonicAngle(const HarmonicAngle& other);
48 
53 
54  // Default C++ destructor.
55 
61  void setNAngleType(int nAngleType);
62 
74  void readParameters(std::istream &in);
75 
81  virtual void loadParameters(Serializable::IArchive &ar);
82 
88  virtual void save(Serializable::OArchive &ar);
89 
97  void set(std::string name, int type, double value);
98 
105  double energy(double cosTheta, int type) const;
106 
118  void force(const Vector& b1, const Vector& b2,
119  Vector& F1, Vector& F2, int type) const;
120 
135  double randomAngle(Random *random, double beta, int type) const;
136 
151  double randomCosineAngle(Random *random, double beta, int type) const;
152 
160  double get(std::string name, int type) const;
161 
165  std::string className() const;
166 
167  private:
168 
170  static const int MaxNAngleType = 4;
171 
172  double kappa_[MaxNAngleType];
173  double theta0_[MaxNAngleType];
174  int nAngleType_;
175 
176  };
177 
178  // Inline method definitions
179 
180  /*
181  * Return angle energy.
182  */
183  inline double HarmonicAngle::energy(double cosTheta, int type) const
184  {
185  double dTheta = std::acos(cosTheta) - theta0_[type];
186  return 0.5*kappa_[type]*dTheta*dTheta;
187  }
188 
189  /*
190  * Return:
191  * F1 = d energy / d(b1)
192  * F2 = d energy / d(b2)
193  * for use in MD and stress calculation.
194  */
195  inline
196  void HarmonicAngle::force(const Vector& b1, const Vector& b2,
197  Vector& F1, Vector& F2, int type) const
198  {
199  BendForce bend;
200  bend.computeDerivatives(b1, b2);
201  double s = bend.sinTheta();
202  if (s > 1.0E-10) {
203  double factor = kappa_[type]*(theta0_[type] - bend.theta())/s;
204  F1.multiply(bend.d1, factor);
205  F2.multiply(bend.d2, factor);
206  } else {
207  F1.zero();
208  F2.zero();
209  }
210  }
211 
212 }
213 
214 #endif
Vector d2
Vector of derivatives d2[i] = d(cosTheta)/d(b2[i])
Definition: BendForce.h:46
Vector & zero()
Set all elements of a 3D vector to zero.
Definition: Vector.h:514
A BendForce computes derivatives of the angle between two vectors.
Definition: BendForce.h:33
A Vector is a Cartesian vector.
Definition: Vector.h:75
Vector d1
Vector of derivatives d1[i] = d(cosTheta)/d(b1[i])
Definition: BendForce.h:41
Vector & multiply(const Vector &v, double s)
Multiply a vector v by a scalar s.
Definition: Vector.h:686
void readParameters(std::istream &in)
Read angle interaction parameters from input stream.
HarmonicAngle & operator=(const HarmonicAngle &other)
Assignment.
double randomCosineAngle(Random *random, double beta, int type) const
Return bond angle cosine chosen from equilibrium distribution.
File containing preprocessor macros for error handling.
Classes used by all simpatico molecular simulations.
A angle potential that is harmonic in the angle.
Definition: HarmonicAngle.h:34
HarmonicAngle()
Default constructor.
virtual void loadParameters(Serializable::IArchive &ar)
Load internal state from an archive.
Saving / output archive for binary ostream.
void computeDerivatives(const Vector &b1, const Vector &b2)
Compute cosTheta and its derivatives d1 and d2.
Definition: BendForce.h:64
double energy(double cosTheta, int type) const
Returns potential energy for one angle.
Utility classes for scientific computation.
Definition: accumulators.mod:1
double randomAngle(Random *random, double beta, int type) const
Return bond angle chosen from equilibrium distribution.
double sinTheta() const
Return value of sin(theta) for precomputed cos(theta).
Definition: Bend.h:80
Saving archive for binary istream.
virtual void save(Serializable::OArchive &ar)
Save internal state to an archive.
void force(const Vector &b1, const Vector &b2, Vector &F1, Vector &F2, int type) const
Compute angle forces.
std::string className() const
Return name string "HarmonicAngle" for this evaluator class.
void setNAngleType(int nAngleType)
Set the number of angle types.
Random number generator.
Definition: Random.h:46
An object that can read multiple parameters from file.
double theta() const
Return value of theta in radians for precomputed cos(theta).
Definition: Bend.h:87