1 #ifndef MCMD_ANGLE_POTENTIAL_IMPL_H 2 #define MCMD_ANGLE_POTENTIAL_IMPL_H 11 #include <mcMd/potentials/angle/AnglePotential.h> 12 #include <mcMd/simulation/SystemInterface.h> 33 template <
class Interaction>
63 virtual void readParameters(std::istream& in);
88 double energy(
double cosTheta,
int type)
const;
111 double randomAngle(
Random* random,
double beta,
int type)
122 double randomCosineAngle(
Random *random,
double beta,
int type)
const;
131 void set(std::string name,
int type,
double value)
132 { interactionPtr_->set(name, type, value); }
141 double get(std::string name,
int type)
const 142 {
return interactionPtr_->get(name, type); }
147 virtual std::string interactionClassName()
const;
152 Interaction& interaction();
157 const Interaction& interaction()
const;
169 virtual double atomEnergy(
const Atom& atom)
const;
174 virtual void addForces();
179 virtual void computeEnergy();
184 virtual void computeStress();
190 Interaction* interactionPtr_;
197 template <
typename T>
198 void computeStressImpl(T& stress)
const;
204 #include <mcMd/simulation/System.h> 205 #include <mcMd/simulation/Simulation.h> 206 #include <mcMd/simulation/stress.h> 207 #include <mcMd/chemistry/getAtomGroups.h> 208 #include <simp/boundary/Boundary.h> 209 #include <util/space/Dimension.h> 210 #include <util/space/Vector.h> 211 #include <util/space/Tensor.h> 212 #include <util/accumulators/setToZero.h> 219 using namespace Util;
220 using namespace Simp;
225 template <
class Interaction>
231 { interactionPtr_ =
new Interaction(); }
236 template <
class Interaction>
248 template <
class Interaction>
251 if (interactionPtr_ && !isCopy_) {
252 delete interactionPtr_;
260 template <
class Interaction>
265 bool nextIndent =
false;
274 template <
class Interaction>
281 bool nextIndent =
false;
290 template <
class Interaction>
302 template <
class Interaction>
310 template <
class Interaction>
318 template <
class Interaction>
320 double beta,
int type)
const 321 {
return interaction().randomAngle(random, beta, type); }
326 template <
class Interaction>
328 double beta,
int type)
const 329 {
return interaction().randomCosineAngle(random, beta, type); }
334 template <
class Interaction>
338 const Angle* anglePtr;
342 double rsq1, rsq2, cosTheta;
346 for (iAngle = 0; iAngle < angles.
size(); ++iAngle) {
347 anglePtr = angles[iAngle];
352 cosTheta = dr1.
dot(dr2) / sqrt(rsq1 * rsq2);
362 template <
class Interaction>
367 double rsq1, rsq2, cosTheta;
374 for (
begin(iSpec, molIter); molIter.
notEnd(); ++molIter) {
375 for (molIter->begin(angleIter); angleIter.
notEnd(); ++angleIter){
377 angleIter->atom(0).position(), dr1);
379 angleIter->atom(1).position(), dr2);
380 cosTheta = dr1.
dot(dr2) / sqrt(rsq1 * rsq2);
381 energy +=
interaction().energy(cosTheta, angleIter->typeId());
394 template <
class Interaction>
397 Vector dr1, dr2, force1, force2;
400 Atom *atom0Ptr, *atom1Ptr, *atom2Ptr;
405 for (
begin(iSpec, molIter); molIter.
notEnd(); ++molIter) {
406 for (molIter->begin(angleIter); angleIter.
notEnd(); ++angleIter){
407 atom0Ptr = &(angleIter->atom(0));
408 atom1Ptr = &(angleIter->atom(1));
409 atom2Ptr = &(angleIter->atom(2));
415 angleIter->typeId());
416 atom0Ptr->
force() += force1;
417 atom1Ptr->
force() -= force1;
418 atom1Ptr->
force() += force2;
419 atom2Ptr->
force() -= force2;
434 template <
class Interaction>
435 template <
typename T>
438 Vector dr1, dr2, force1, force2;
439 const Atom *atom0Ptr, *atom1Ptr, *atom2Ptr;
448 for (
begin(iSpec, molIter); molIter.
notEnd(); ++molIter) {
449 for (molIter->begin(angleIter); angleIter.
notEnd(); ++angleIter){
450 atom0Ptr = &(angleIter->atom(0));
451 atom1Ptr = &(angleIter->atom(1));
452 atom2Ptr = &(angleIter->atom(2));
461 force1, force2, angleIter->typeId());
465 incrementPairStress(force1, dr1, stress);
466 incrementPairStress(force2, dr2, stress);
473 normalizeStress(stress);
479 template <
class Interaction>
483 computeStressImpl(stress);
489 template <
class Interaction>
491 {
return *interactionPtr_; }
493 template <
class Interaction>
495 {
return *interactionPtr_; }
500 template <
class Interaction>
virtual ~AnglePotentialImpl()
Destructor.
virtual void readParameters(std::istream &in)
Read angle potential parameters.
A Vector is a Cartesian vector.
Interface for a Angle Interaction.
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?
virtual void loadParameters(Serializable::IArchive &ar)
Load internal state from an archive.
Vector & force()
Get atomic force Vector by reference.
double volume() const
Return unit cell volume.
double dot(const Vector &v) const
Return dot product of this vector and vector v.
void set(const T &value)
Set the value and mark as set.
A set of interacting Molecules enclosed by a Boundary.
int typeId() const
Get the typeId for this covalent group.
virtual double randomAngle(Random *random, double beta, int type) const
Returns a random bond Angle.
Forward iterator for a PArray.
File containing preprocessor macros for error handling.
Classes used by all simpatico molecular simulations.
virtual double atomEnergy(const Atom &atom) const
Calculate the angle energy for one Atom.
A Tensor represents a Cartesian tensor.
Forward const iterator for an Array or a C array.
virtual std::string interactionClassName() const
Return pair interaction class name (e.g., "CosineAngle").
Saving / output archive for binary ostream.
void force(const Vector &R1, const Vector &R2, Vector &F1, Vector &F2, int type) const
Returns forces along two bonds at the angle, for use in MD and stress calculation.
A fixed capacity (static) contiguous array with a variable logical size.
void getAtomAngles(const Atom &atom, AtomAngleArray &groups)
Fill an array of pointers to Angles that contain an Atom.
virtual double randomCosineAngle(Random *random, double beta, int type) const
Returns Cosine a random bond Angle.
Implementation template for an AnglePotential.
virtual void computeStress()
Compute and store the total angle pressure.
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.
AnglePotentialImpl(System &system)
Constructor.
Forward iterator for an Array or a C array.
Forward iterator for a PArray.
Atom & atom(int i)
Get a specific Atom in the Group by reference.
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.
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.
virtual void computeEnergy()
Calculate and store total angle energy.
Boundary & boundary() const
Get the Boundary 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 nAngle() const
Get number of angles 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).
System & system() const
Get the parent System by reference.
Interaction & interaction()
Return angle interaction by reference.
virtual void save(Serializable::OArchive &ar)
Save internal state to an archive.
virtual void addForces()
Calculate the angle energy for one Atom.
double energy()
Return the energy contribution, compute if necessary.