Simpatico  v1.10
CompositeBond.h
1 #ifndef SIMP_COMPOSITE_BOND_H
2 #define SIMP_COMPOSITE_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/param/ParamComposite.h>
12 #include <util/param/Begin.h>
13 #include <util/param/End.h>
14 #include <util/global.h>
15 
16 #include <math.h>
17 
18 namespace Util
19 { class Random; }
20 
21 namespace Simp
22 {
23 
24  using namespace Util;
25 
37  template <class BareBond, class BarePair>
38  class CompositeBond : public ParamComposite
39  {
40 
41  public:
42 
46  CompositeBond();
47 
48  // Mutators
49 
55  void setNBondType(int nBondType);
56 
64  void readParameters(std::istream &in);
65 
73  void set(std::string name, int type, double value);
74 
75  // Accessors
76 
84  double energy(double rsq, int type) const;
85 
97  double forceOverR(double rsq, int bondTypeId) const;
98 
106  double randomBondLength(Random* randomPtr, double beta, int type)
107  const;
108 
116  double get(std::string name, int type) const;
117 
118  private:
119 
120  // Bare bond potential object.
121  BareBond bond_;
122 
123  // Bare pair potential object.
124  BarePair pair_;
125 
130 
131  };
132 
133 
134  /*
135  * Constructor.
136  */
137  template <class BareBond, class BarePair>
139  : bond_(),
140  pair_()
141  {
142  std::string name("CompositeBond");
143  name += "<";
144  name += bond_.className();
145  name += ",";
146  name += pair_.className();
147  name += ">";
148  setClassName(name.c_str());
149  }
150 
151 
152  /*
153  * Copy constructor.
154  */
155  template <class BareBond, class BarePair>
157  : bond_(other.bond_),
158  pair_(other.pair_)
159  {}
160 
161  /*
162  * Read potential parameters from file.
163  */
164  template <class BareBond, class BarePair>
166  {
167 
168  readParamComposite(in, bond_);
169  readParamComposite(in, pair_);
170 
171  #if 0
172  std::string label;
173  Begin* beginPtr = 0;
174  End* endPtr = 0;
175  // Read bare bond potential
176  beginPtr = &addBegin(bond_.className().c_str());
177  beginPtr->setIndent(*this);
178  beginPtr->readParameters(in);
179  readParamComposite(in, bond_);
180  endPtr = &addEnd();
181  endPtr->setIndent(*this);
182  endPtr->readParameters(in);
183 
184  // Read bare pair potential
185  beginPtr = &addBegin(pair_.className().c_str());
186  beginPtr->setIndent(*this);
187  beginPtr->readParameters(in);
188  readParamComposite(in, pair_);
189  endPtr = &addEnd();
190  endPtr->setIndent(*this);
191  endPtr->readParameters(in);
192  #endif
193 
194  }
195 
196  /*
197  * Set nAtomType
198  */
199  template <class BareBond, class BarePair>
201  {
202  bond_.setNBondType(nBondType);
203  pair_.setNAtomType(1);
204  }
205 
206  /*
207  * Calculate interaction energy for a bond.
208  */
209  template <class BareBond, class BarePair>
210  inline double
212  const
213  {
214  double total = bond_.energy(rsq, type);
215  total += pair_.energy(rsq, 0, 0);
216  return total;
217  }
218 
219  /*
220  * Compute force/distance for a bond.
221  */
222  template <class BareBond, class BarePair>
223  inline double
225  const
226  {
227  double total = bond_.forceOverR(rsq, type);
228  total += pair_.forceOverR(rsq, 0, 0);
229  return total;
230  }
231 
232  /*
233  * Modify a parameter, identified by a string.
234  */
235  template <class BareBond, class BarePair>
237  ::set(std::string name, int type, double value)
238  {
239  UTIL_THROW("Unrecognized parameter name");
240  }
241 
242  /*
243  * Get a parameter value, identified by a string.
244  */
245  template <class BareBond, class BarePair>
247  get(std::string name, int type) const
248  {
249  UTIL_THROW("Unrecognized parameter name");
250  return 0.0;
251  }
252 
253  /*
254  * Throws exception if called.
255  */
256  template <class BareBond, class BarePair>
258  ::randomBondLength(Random* randomPtr, double beta, int type) const
259  {
260  UTIL_THROW("Unimplemented function");
261  return 0.0; // To avoid compiler warnings.
262  }
263 
264 }
265 #endif
End bracket of a ParamComposite parameter block.
Definition: End.h:24
double energy(double rsq, int type) const
Returns interaction energy for a single pair of particles.
double forceOverR(double rsq, int bondTypeId) const
Returns ratio of bond force to atom separation.
File containing preprocessor macros for error handling.
Classes used by all simpatico molecular simulations.
void setNBondType(int nBondType)
Set nAtomType value.
Composite bond potential.
Definition: CompositeBond.h:38
CompositeBond()
Constructor.
End & addEnd()
Add a closing bracket.
#define UTIL_THROW(msg)
Macro for throwing an Exception, reporting function, file and line number.
Definition: global.h:51
Utility classes for scientific computation.
Definition: accumulators.mod:1
Begin & addBegin(const char *label)
Add a Begin object representing a class name and bracket.
void readParameters(std::istream &in)
Read epsilon and sigma, initialize other variables.
void setIndent(const ParamComponent &parent, bool next=true)
Set indent level.
double get(std::string name, int type) const
Get a parameter value, identified by a string.
void setClassName(const char *className)
Set class name string.
void readParamComposite(std::istream &in, ParamComposite &child, bool next=true)
Add and read a required child ParamComposite.
Random number generator.
Definition: Random.h:46
An object that can read multiple parameters from file.
Beginning line of a composite parameter block.
Definition: Begin.h:24
double randomBondLength(Random *randomPtr, double beta, int type) const
Throws exception if called.