Simpatico  v1.10
HarmonicBond.h
1 #ifndef SIMP_HARMONIC_BOND_H
2 #define SIMP_HARMONIC_BOND_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/param/ParamComposite.h> // base class
13 
14 #include <util/random/Random.h> // Util namespace
15 
16 #include <cmath>
17 
18 namespace Simp
19 {
20 
21  using namespace Util;
22 
23  //class Random;
24 
35  class HarmonicBond : public ParamComposite
36  {
37 
38  public:
39 
43  HarmonicBond();
44 
48  HarmonicBond(const HarmonicBond& other);
49 
53  HarmonicBond& operator = (const HarmonicBond& other);
54 
55  // Default C++ destructor.
56 
62  void setNBondType(int nBondType);
63 
75  void readParameters(std::istream &in);
76 
82  virtual void loadParameters(Serializable::IArchive &ar);
83 
89  virtual void save(Serializable::OArchive &ar);
90 
97  double energy(double rSq, int type) const;
98 
108  double forceOverR(double rSq, int type) const;
109 
123  double randomBondLength(Random *random, double beta, int type) const;
124 
132  void set(std::string name, int type, double value);
133 
140  double get(std::string name, int type) const;
141 
147  double kappa(int type) const;
148 
154  double length(int type) const;
155 
156  private:
157 
159  static const int MaxNBondType = 8;
160 
161  double kappa_[MaxNBondType];
162  double length_[MaxNBondType];
163  int nBondType_;
164 
165  };
166 
167  // Inline method definitions
168 
169  /*
170  * Return bond spring constant.
171  */
172  inline double HarmonicBond::kappa(int type) const
173  {
174  assert(type >= 0);
175  assert(type < nBondType_);
176  return kappa_[type];
177  }
178 
179  /*
180  * Return equilibrium bond length.
181  */
182  inline double HarmonicBond::length(int type) const
183  {
184  assert(type < nBondType_);
185  return length_[type];
186  }
187 
188  /*
189  * Return interaction energy for one bond
190  */
191  inline double HarmonicBond::energy(double rSq, int type) const
192  {
193  double dl = sqrt(rSq) - length_[type];
194  return 0.5*kappa_[type]*dl*dl;
195  }
196 
197  /*
198  * Return force / distance for one bond, for use in MD
199  */
200  inline
201  double HarmonicBond::forceOverR(double rSq, int type) const
202  {
203  double r = sqrt(rSq);
204  double dl = length_[type] - r;
205  return kappa_[type]*dl/r;
206  }
207 
208 }
209 #endif
double forceOverR(double rSq, int type) const
Returns force/distance for one bond, for use in MD.
Definition: HarmonicBond.h:201
File containing preprocessor macros for error handling.
Classes used by all simpatico molecular simulations.
double kappa(int type) const
Returns bond spring constant kappa.
Definition: HarmonicBond.h:172
Saving / output archive for binary ostream.
double energy(double rSq, int type) const
Returns potential energy for one bond.
Definition: HarmonicBond.h:191
double length(int type) const
Returns equilibrium bond length.
Definition: HarmonicBond.h:182
void setNBondType(int nBondType)
Set the number of bond types.
Utility classes for scientific computation.
Definition: accumulators.mod:1
HarmonicBond()
Default constructor.
HarmonicBond & operator=(const HarmonicBond &other)
Assignment.
virtual void save(Serializable::OArchive &ar)
Save internal state to an archive.
Saving archive for binary istream.
double randomBondLength(Random *random, double beta, int type) const
Return bond length chosen from equilibrium distribution.
A harmonic covalent bond potential.
Definition: HarmonicBond.h:35
Random number generator.
Definition: Random.h:46
An object that can read multiple parameters from file.
void readParameters(std::istream &in)
Read bond interaction parameters from input stream.
virtual void loadParameters(Serializable::IArchive &ar)
Load internal state from an archive.