Simpatico  v1.10
FeneBond.h
1 #ifndef SIMP_FENE_BOND_H
2 #define SIMP_FENE_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 #include <util/random/Random.h> // Util namespace
14 
15 #include <cmath>
16 #include <sstream>
17 
18 namespace Simp
19 {
20 
21  using namespace Util;
22 
39  class FeneBond : public ParamComposite
40  {
41 
42  public:
43 
47  FeneBond();
48 
52  FeneBond(const FeneBond& other);
53 
57  FeneBond& operator = (const FeneBond& other);
58 
59  // Default destructor.
60 
66  void setNBondType(int nBondType);
67 
80  void readParameters(std::istream &in);
81 
87  virtual void loadParameters(Serializable::IArchive &ar);
88 
94  virtual void save(Serializable::OArchive &ar);
95 
103  void set(std::string name, int type, double value);
104 
111  double energy(double rSq, int type) const;
112 
122  double forceOverR(double rSq, int type) const;
123 
137  double randomBondLength(Random *random, double beta, int type) const;
138 
145  double get(std::string name, int type) const;
146 
147  private:
148 
150  static const int MaxNBondType = 2;
151 
153  double kappa_[MaxNBondType];
154 
156  double r0_[MaxNBondType];
157 
159  double r0Sq_[MaxNBondType];
160 
162  double r0SqInv_[MaxNBondType];
163 
165  double ce_[MaxNBondType];
166 
168  double rlSq_[MaxNBondType];
169 
171  double rl_[MaxNBondType];
172 
174  double energyCutoff_[MaxNBondType];
175 
177  // double a_[MaxNBondType];
178 
180  double forceCutoff_;
181 
183  int nBondType_;
184 
185  };
186 
187  // Inline method definitions
188 
189  /*
190  * Return interaction energy for one bond
191  */
192  inline double FeneBond::energy(double rSq, int type) const
193  {
194  if (rSq < rlSq_[type]){
195  double g = 1.0 - rSq*r0SqInv_[type];
196  return ce_[type]*log(g);
197  } else {
198  //double b = rl_[type]*kappa_[type]/a_[type];
199  return energyCutoff_[type] + forceCutoff_*(sqrt(rSq) - rl_[type]);
200  }
201  }
202 
203  /*
204  * Return force / distance for one bond, for use in MD
205  */
206  inline
207  double FeneBond::forceOverR(double rSq, int type) const
208  {
209  if (rSq < rlSq_[type]){
210  double g = 1.0 - rSq*r0SqInv_[type];
211  return -kappa_[type]/g;
212  } else {
213  if (rSq > r0Sq_[type]) {
214  std::cout << "Warning: Long FENE bond: Rsq = " << rSq << std::endl;
215  }
216  //return -rl_[type]*kappa_[type]/(a_[type]*sqrt(rSq));
217  return -forceCutoff_/sqrt(rSq);
218  }
219  }
220 
221 }
222 #endif
void readParameters(std::istream &in)
Read bond interaction parameters from input stream.
Definition: FeneBond.cpp:86
double energy(double rSq, int type) const
Returns potential energy for one bond.
Definition: FeneBond.h:192
A finitely-extensible nonlinear element (FENE) bond potential.
Definition: FeneBond.h:39
File containing preprocessor macros for error handling.
Classes used by all simpatico molecular simulations.
void setNBondType(int nBondType)
Set the number of bond types.
Definition: FeneBond.cpp:77
Saving / output archive for binary ostream.
Utility classes for scientific computation.
Definition: accumulators.mod:1
double randomBondLength(Random *random, double beta, int type) const
Return bond length chosen from equilibrium distribution.
Definition: FeneBond.cpp:166
virtual void save(Serializable::OArchive &ar)
Save internal state to an archive.
Definition: FeneBond.cpp:139
virtual void loadParameters(Serializable::IArchive &ar)
Load internal state from an archive.
Definition: FeneBond.cpp:112
double forceOverR(double rSq, int type) const
Returns force/distance for one bond, for use in MD.
Definition: FeneBond.h:207
Saving archive for binary istream.
FeneBond()
Default constructor.
Definition: FeneBond.cpp:20
Random number generator.
Definition: Random.h:46
FeneBond & operator=(const FeneBond &other)
Assignment.
Definition: FeneBond.cpp:57
An object that can read multiple parameters from file.