1 #ifndef MCMD_BOND_POTENTIAL_IMPL_H 2 #define MCMD_BOND_POTENTIAL_IMPL_H 12 #include <mcMd/potentials/bond/BondPotential.h> 13 #include <mcMd/simulation/SystemInterface.h> 33 template <
class Interaction>
61 virtual void readParameters(std::istream& in);
83 virtual double energy(
double rsq,
int bondTypeId)
const;
88 virtual double forceOverR(
double rsq,
int bondTypeId)
const;
94 double randomBondLength(
Random* random,
double beta,
int bondTypeId)
104 void set(std::string name,
int type,
double value)
105 { interactionPtr_->set(name, type, value); }
113 double get(std::string name,
int type)
const 114 {
return interactionPtr_->get(name, type); }
119 virtual std::string interactionClassName()
const;
131 double atomEnergy(
const Atom& atom)
const;
141 virtual void computeEnergy();
146 virtual void computeStress();
153 Interaction& interaction();
158 const Interaction& interaction()
const;
162 Interaction* interactionPtr_;
169 template <
typename T>
170 void computeStressImpl(T& stress)
const;
176 #include <mcMd/simulation/System.h> 177 #include <mcMd/simulation/Simulation.h> 178 #include <mcMd/simulation/stress.h> 179 #include <mcMd/chemistry/getAtomGroups.h> 180 #include <simp/boundary/Boundary.h> 181 #include <util/space/Dimension.h> 182 #include <util/space/Vector.h> 183 #include <util/space/Tensor.h> 184 #include <util/accumulators/setToZero.h> 191 using namespace Util;
192 using namespace Simp;
197 template <
class Interaction>
203 { interactionPtr_ =
new Interaction(); }
208 template <
class Interaction>
220 template <
class Interaction>
224 delete interactionPtr_;
232 template <
class Interaction>
238 bool nextIndent =
false;
247 template <
class Interaction>
254 bool nextIndent =
false;
263 template <
class Interaction>
275 template <
class Interaction>
283 template <
class Interaction>
286 {
return interaction().forceOverR(rsq, iBondType); }
291 template <
class Interaction>
double 294 {
return interaction().randomBondLength(random, beta, bondTypeId); }
299 template <
class Interaction>
310 nBond = bonds.
size();
311 for (iBond = 0; iBond < nBond; ++iBond) {
312 bondPtr = bonds[iBond];
324 template <
class Interaction>
334 for (
begin(iSpec, molIter); molIter.
notEnd(); ++molIter) {
335 for (molIter->begin(bondIter); bondIter.
notEnd(); ++bondIter) {
337 distanceSq( bondIter->atom(0).position(),
338 bondIter->atom(1).position());
339 energy +=
interaction().energy(rsq, bondIter->typeId());
352 template <
class Interaction>
359 Atom *atom0Ptr, *atom1Ptr;
365 for (
begin(iSpec, molIter); molIter.
notEnd(); ++molIter) {
366 for (molIter->begin(bondIter); bondIter.
notEnd(); ++bondIter) {
367 atom0Ptr = &(bondIter->atom(0));
368 atom1Ptr = &(bondIter->atom(1));
371 force *=
interaction().forceOverR(rsq, bondIter->typeId());
372 atom0Ptr->
force() += force;
373 atom1Ptr->
force() -= force;
388 template <
class Interaction>
389 template <
typename T>
395 const Atom* atom0Ptr;
396 const Atom* atom1Ptr;
405 for (
begin(iSpec, molIter); molIter.
notEnd(); ++molIter) {
406 molIter->begin(bondIter);
407 for ( ; bondIter.
notEnd(); ++bondIter) {
408 atom0Ptr = &(bondIter->atom(0));
409 atom1Ptr = &(bondIter->atom(1));
415 incrementPairStress(force, dr, stress);
422 normalizeStress(stress);
428 template <
class Interaction>
432 computeStressImpl(stress);
438 template <
class Interaction>
440 {
return *interactionPtr_; }
442 template <
class Interaction>
445 {
return *interactionPtr_; }
450 template <
class Interaction>
virtual double randomBondLength(Random *random, double beta, int bondTypeId) const
Return force / separation for a single pair.
A Vector is a Cartesian vector.
An interface to a System.
double distanceSq(const Vector &r1, const Vector &r2) const
Return square distance between positions r1 and r2.
bool notEnd() const
Is the current pointer not at the end of the array?
Vector & force()
Get atomic force Vector by reference.
double volume() const
Return unit cell volume.
void set(const T &value)
Set the value and mark as set.
double atomEnergy(const Atom &atom) const
Calculate the bond energy for one Atom.
void addForces()
Add the bond forces for all atoms.
Implementation template for a BondPotential.
A set of interacting Molecules enclosed by a Boundary.
int typeId() const
Get the typeId for this covalent group.
virtual void computeEnergy()
Calculate and store pair energy for this System.
Forward iterator for a PArray.
File containing preprocessor macros for error handling.
Classes used by all simpatico molecular simulations.
A Tensor represents a Cartesian tensor.
Forward const iterator for an Array or a C array.
Saving / output archive for binary ostream.
A fixed capacity (static) contiguous array with a variable logical size.
virtual std::string interactionClassName() const
Return pair interaction class name (e.g., "HarmonicBond").
BondPotentialImpl(System &system)
Constructor.
Simulation & simulation() const
Get the parent Simulation by reference.
void setToZero(int &value)
Set an int variable to zero.
A point particle within a Molecule.
bool notEnd() const
Is the current pointer not at the end of the PArray?
Utility classes for scientific computation.
virtual double forceOverR(double rsq, int bondTypeId) const
Return force / separation for a single pair.
Forward iterator for an Array or a C array.
virtual void save(Serializable::OArchive &ar)
Save internal state to an archive.
Forward iterator for a PArray.
Atom & atom(int i)
Get a specific Atom in the Group by reference.
virtual void readParameters(std::istream &in)
Read potential energy.
bool notEnd() const
Is the current pointer not at the end of the array?
void begin(int speciesId, System::MoleculeIterator &iterator)
Initialize an iterator for molecules of one species in this SystemInterface.
virtual void loadParameters(Serializable::IArchive &ar)
Load internal state from an archive.
Saving archive for binary istream.
Single-processor Monte Carlo (MC) and molecular dynamics (MD).
int nSpecies() const
Get the number of Species in this Simulation.
void addParamComposite(ParamComposite &child, bool next=true)
Add a child ParamComposite object to the format array.
A sequence of NAtom covalently interacting atoms.
Boundary & boundary() const
Get the Boundary by reference.
Abstract Bond Potential class.
Interaction & interaction()
Return bond interaction by reference.
const Vector & position() const
Get the position Vector by const reference.
bool notEnd() const
Is this not the end of the array?
int nBond() const
Get number of bonds per molecule for this Species.
Species & species(int i)
Get a specific Species by reference.
int size() const
Return logical size of this array (i.e., number of elements).
virtual ~BondPotentialImpl()
Destructor.
System & system() const
Get the parent System by reference.
void getAtomBonds(const Atom &atom, AtomBondArray &groups)
Fill an array of pointers to Bonds that contain an Atom.
double energy()
Return the energy contribution, compute if necessary.
virtual void computeStress()
Compute and store the total nonbonded pressure.