10 #include "CfbLinear.h" 11 #include <mcMd/mcSimulation/McSystem.h> 13 #include <mcMd/simulation/Simulation.h> 14 #include <mcMd/chemistry/Molecule.h> 15 #include <mcMd/chemistry/Atom.h> 17 #include <simp/species/Species.h> 18 #include <simp/species/Linear.h> 19 #include <simp/boundary/Boundary.h> 21 #include <util/space/Vector.h> 38 UTIL_THROW(
"CfbLinear requires that bonds be enabled");
51 void CfbLinear::processParameters()
64 UTIL_THROW(
"Species is not Linear in CfbLinear");
73 UTIL_THROW(
"CfbLinear does not (yet) work with dihedrals");
82 UTIL_THROW(
"Invalid parameter value, nTrial <= 0");
84 if (nTrial_ > MaxTrial_) {
85 UTIL_THROW(
"Invalid parameter value, nTrial > MaxTrial_");
94 read<int>(in,
"speciesId", speciesId_);
95 read<int>(in,
"nTrial", nTrial_);
104 loadParameter<int>(ar,
"speciesId", speciesId_);
105 loadParameter<int>(ar,
"nTrial", nTrial_);
123 int sign,
double &rosenbluth,
double &energy)
127 assert(sign == 1 || sign == -1);
128 int shift = (sign == 1) ? 1 : 0;
129 Atom& atom0 = molecule.
atom(atomId);
130 Atom& atom1 = molecule.
atom(atomId - sign);
137 double r1, bondEnergy;
138 int bondTypeId = molecule.
bond(atomId - shift).
typeId();
156 bool hasAngle =
false;
158 int atom2Id = atomId - 2*sign;
161 hasAngle = (atom2Id >= 0);
164 hasAngle = (atom2Id < molecule.
nAtom());
167 Atom& atom2 = molecule.
atom(atom2Id);
174 double cosTheta = u1.
dot(u2);
175 angleTypeId = molecule.
bond(atomId - 2*shift).
typeId();
177 energy += anglePotentialPtr->
energy(cosTheta, angleTypeId);
186 assert(externalPotentialPtr);
187 energy += externalPotentialPtr->
atomEnergy(atom0);
196 energy += bondEnergy;
200 for (
int iTrial = 0; iTrial < nTrial_ - 1; ++iTrial) {
218 assert(anglePotentialPtr);
219 double cosTheta = u1.
dot(u2);
220 trialEnergy += anglePotentialPtr->
energy(cosTheta, angleTypeId);
226 assert(externalPotentialPtr);
227 trialEnergy += externalPotentialPtr->
atomEnergy(atom0);
241 int sign,
double &rosenbluth,
double &energy)
245 assert(sign == 1 || sign == -1);
246 int shift = (sign == 1) ? 1 : 0;
254 int bondTypeId, iTrial;
255 bondTypeId = molecule.
bond(atomId - shift).
typeId();
268 bool hasAngle =
false;
270 int atom2Id = atomId - 2*sign;
273 hasAngle = (atom2Id >= 0);
276 hasAngle = (atom2Id < molecule.
nAtom());
279 Atom* atom2Ptr = &atom1 - sign;
287 angleTypeId = molecule.
bond(atomId - 2*shift).
typeId();
296 assert(externalPotentialPtr);
302 Vector trialPos[MaxTrial_];
303 double trialProb[MaxTrial_], trialEnergy[MaxTrial_];
305 for (iTrial = 0; iTrial < nTrial_; ++iTrial) {
311 trialPos[iTrial].
subtract(pos1, v1);
313 pos0 = trialPos[iTrial];
317 trialEnergy[iTrial] = pairPotential.
atomEnergy(atom0);
319 trialEnergy[iTrial] = 0.0;
324 assert(anglePotentialPtr);
325 double cosTheta = u1.
dot(u2);
326 trialEnergy[iTrial] +=
327 anglePotentialPtr->
energy(cosTheta, angleTypeId);
333 assert(externalPotentialPtr);
334 trialEnergy[iTrial] +=
340 trialProb[iTrial] =
boltzmann(trialEnergy[iTrial]);
341 rosenbluth += trialProb[iTrial];
345 for (iTrial = 0; iTrial < nTrial_; ++iTrial) {
346 trialProb[iTrial] = trialProb[iTrial]/rosenbluth;
353 energy = trialEnergy[iTrial];
357 pos0 = trialPos[iTrial];
Bond & bond(int localId)
Get a specific Bond in this Molecule by non-const reference.
A System for use in a Markov chain Monte Carlo simulation.
A Vector is a Cartesian vector.
void addAtom(Molecule &molecule, Atom &atom0, Atom &atom1, int atomId, int sign, double &rosenbluth, double &energy)
Configuration bias algorithm for adding an atom to a Linear molecule.
virtual double atomEnergy(const Atom &atom) const =0
Calculate the external energy for one Atom.
Interface for a Angle Interaction.
double distanceSq(const Vector &r1, const Vector &r2) const
Return square distance between positions r1 and r2.
Include this file to include all MC potential energy classes at once.
BondPotential & bondPotential() const
Return the BondPotential by reference.
bool hasDihedralPotential() const
Does a dihedral potential exist?.
double dot(const Vector &v) const
Return dot product of this vector and vector v.
A PairPotential for MC simulations (abstract).
bool hasAnglePotential() const
Does angle potential exist?.
Species & species() const
Get the molecular Species by reference.
int typeId() const
Get the typeId for this covalent group.
virtual void save(Serializable::OArchive &ar)
Save speciesId and nTrial.
File containing preprocessor macros for error handling.
Classes used by all simpatico molecular simulations.
long drawFrom(double probability[], long size)
Choose one of several outcomes with a specified set of probabilities.
virtual void readParameters(std::istream &in)
Read and validate speciesId and nTrial.
Saving / output archive for binary ostream.
double boltzmann(double energy)
Boltzmann weight associated with an energy difference.
int nDihedral() const
Get number of dihedrals per molecule for this Species.
double beta() const
Return the inverse temperature.
#define UTIL_THROW(msg)
Macro for throwing an Exception, reporting function, file and line number.
McSystem & system()
Get parent McSystem.
Abstract External Potential class.
int typeId() const
Get type index for this Atom.
ExternalPotential & externalPotential() const
Return ExternalPotential by reference.
A point particle within a Molecule.
Utility classes for scientific computation.
An McMove that acts on one McSystem.
void shift(Vector &r) const
Shift Cartesian Vector r to its primary image.
int atomTypeId(int iAtom) const
Get atom type index for a specific atom, by local atom index.
Random & random()
Get Random number generator of parent Simulation.
virtual void loadParameters(Serializable::IArchive &ar)
Load and validate speciesId and nTrial.
McPairPotential & pairPotential() const
Return the McPairPotential by reference.
virtual double energy(double cosTheta, int type) const =0
Returns potential energy for one angle.
virtual double energy(double rSq, int type) const =0
Returns potential energy for one bond.
virtual ~CfbLinear()
Destructor.
void deleteAtom(Molecule &molecule, int atomId, int sign, double &rosenbluth, double &energy)
CFB algorithm for deleting an end atom from a Linear molecule.
Saving archive for binary istream.
Single-processor Monte Carlo (MC) and molecular dynamics (MD).
bool hasExternalPotential() const
Does an external potential exist?.
Vector & subtract(const Vector &v1, const Vector &v2)
Subtract vector v2 from v1.
const Atom & atom(int localId) const
Get a specific Atom in this Molecule.
AnglePotential & anglePotential() const
Return AnglePotential by reference.
CfbLinear(McSystem &system)
Constructor.
Simulation & simulation()
Get parent Simulation object.
A physical molecule (a set of covalently bonded Atoms).
const Vector & position() const
Get the position Vector by const reference.
virtual double randomBondLength(Util::Random *random, double beta, int type) const =0
Return bond length chosen from equilibrium distribution.
A Species represents a set of chemically similar molecules.
int nAngle() const
Get number of angles per molecule for this Species.
Species & species(int i)
Get a specific Species by reference.
A Species of linear polymers (abstract).
EnergyEnsemble & energyEnsemble()
Get EnergyEnsemble object of parent McSystem.
int nAtom() const
Get the number of Atoms in this Molecule.
virtual double atomEnergy(const Atom &atom) const =0
Calculate the nonbonded pair energy for one Atom.
void unitVector(Vector &v)
Generate unit vector with uniform probability over the unit sphere.
Boundary & boundary()
Get Boundary object of parent McSystem.