9 #include <util/random/Random.h> 10 #include <util/mpi/MpiLoader.h> 24 for (
int i = 0; i < MaxNBondType; ++i) {
32 energyCutoff_[i] = 0.0;
40 : nBondType_(other.nBondType_)
42 for (
int i = 0; i < nBondType_; ++i) {
43 kappa_[i] = other.kappa_[i];
44 r0_[i] = other.r0_[i];
45 r0Sq_[i] = other.r0Sq_[i];
46 r0SqInv_[i] = other.r0SqInv_[i];
47 ce_[i] = other.ce_[i];
48 rlSq_[i] = other.rlSq_[i];
49 rl_[i] = other.rl_[i];
50 energyCutoff_[i] = other.energyCutoff_[i];
59 nBondType_ = other.nBondType_;
60 forceCutoff_ = other.forceCutoff_;
61 for (
int i = 0; i < nBondType_; ++i) {
62 kappa_[i] = other.kappa_[i];
63 r0_[i] = other.r0_[i];
64 r0Sq_[i] = other.r0Sq_[i];
65 r0SqInv_[i] = other.r0SqInv_[i];
66 ce_[i] = other.ce_[i];
67 rlSq_[i] = other.rlSq_[i];
68 rl_[i] = other.rl_[i];
69 energyCutoff_[i] = other.energyCutoff_[i];
80 nBondType_ = nBondType;
92 readCArray<double>(in,
"kappa", kappa_, nBondType_);
93 readCArray<double>(in,
"r0", r0_, nBondType_);
94 read<double>(in,
"forceCutoff", forceCutoff_);
97 for (
int i = 0; i < nBondType_; ++i) {
98 r0Sq_[i] = r0_[i]*r0_[i];
99 r0SqInv_[i] = 1.0/r0Sq_[i];
100 ce_[i] = -0.5*r0Sq_[i]*kappa_[i];
101 y = 0.5*kappa_[i]*r0_[i]/forceCutoff_;
102 rl_[i] = r0_[i]*(sqrt(1.0 + y*y) - y);
103 rlSq_[i] = rl_[i]*rl_[i];
104 g = 1.0 - rlSq_[i]*r0SqInv_[i];
105 energyCutoff_[i] = ce_[i]*log(g);
115 loadCArray<double> (ar,
"kappa", kappa_, nBondType_);
116 loadCArray<double>(ar,
"r0", r0_, nBondType_);
117 loadParameter<double>(ar,
"forceCutoff", forceCutoff_);
120 loader.load(r0Sq_, nBondType_);
121 loader.load(r0SqInv_, nBondType_);
122 loader.load(ce_, nBondType_);
123 loader.load(rl_, nBondType_);
124 loader.load(rlSq_, nBondType_);
125 loader.load(energyCutoff_, nBondType_);
127 ar.unpack(r0Sq_, nBondType_);
128 ar.unpack(r0SqInv_, nBondType_);
129 ar.unpack(ce_, nBondType_);
130 ar.unpack(rl_, nBondType_);
131 ar.unpack(rlSq_, nBondType_);
132 ar.unpack(energyCutoff_, nBondType_);
142 ar.
pack(kappa_, nBondType_);
143 ar.
pack(r0_, nBondType_);
145 ar.
pack(r0Sq_, nBondType_);
146 ar.
pack(r0SqInv_, nBondType_);
147 ar.
pack(ce_, nBondType_);
148 ar.
pack(rl_, nBondType_);
149 ar.
pack(rlSq_, nBondType_);
150 ar.
pack(energyCutoff_, nBondType_);
167 Random *random,
double beta,
int type)
const 170 double x, y, z, sigSq, rSq, eHarm, eFene, ratio;
171 sigSq = 1.0/(beta*kappa_[type]);
178 rSq = sqrt(x*x + y*y + z*z)*sigSq;
179 if (rSq >= r0Sq_[type])
continue;
180 eHarm = 0.5*kappa_[type]*rSq;
181 eFene =
energy(rSq, type);
182 ratio = exp(-beta*(eFene - eHarm));
183 if (random->
uniform(0.0,1.0) < ratio) {
194 if (name ==
"kappa") {
195 kappa_[type] = value;
202 r0Sq_[type] = r0_[type]*r0_[type];
203 r0SqInv_[type] = 1.0/r0Sq_[type];
204 ce_[type] = -0.5*r0Sq_[type]*kappa_[type];
205 double y = 0.5*kappa_[type]*r0_[type]/forceCutoff_;
206 rl_[type] = r0_[type]*(sqrt(1.0 + y*y) - y);
207 rlSq_[type] = rl_[type]*rl_[type];
208 double g = 1.0 - rlSq_[type]*r0SqInv_[type];
209 energyCutoff_[type] = ce_[type]*log(g);
218 if (name ==
"kappa") {
219 value = kappa_[type];
void readParameters(std::istream &in)
Read bond interaction parameters from input stream.
double energy(double rSq, int type) const
Returns potential energy for one bond.
A finitely-extensible nonlinear element (FENE) bond potential.
Classes used by all simpatico molecular simulations.
void setNBondType(int nBondType)
Set the number of bond types.
double uniform()
Return a random floating point number x, uniformly distributed in the range 0 <= x < 1...
Saving / output archive for binary ostream.
#define UTIL_THROW(msg)
Macro for throwing an Exception, reporting function, file and line number.
void pack(const T &data)
Pack one object of type T.
Utility classes for scientific computation.
double randomBondLength(Random *random, double beta, int type) const
Return bond length chosen from equilibrium distribution.
void set(std::string name, int type, double value)
Modify a parameter, identified by a string.
double gaussian(void)
Return a Gaussian random number with zero average and unit variance.
virtual void save(Serializable::OArchive &ar)
Save internal state to an archive.
virtual void loadParameters(Serializable::IArchive &ar)
Load internal state from an archive.
double get(std::string name, int type) const
Get a parameter value, identified by a string.
Saving archive for binary istream.
Provides methods for MPI-aware loading of data from input archive.
FeneBond()
Default constructor.
#define UTIL_CHECK(condition)
Assertion macro suitable for serial or parallel production code.
void setClassName(const char *className)
Set class name string.
FeneBond & operator=(const FeneBond &other)
Assignment.