1 #ifndef MCMD_DIHEDRAL_POTENTIAL_IMPL_H 2 #define MCMD_DIHEDRAL_POTENTIAL_IMPL_H 12 #include <mcMd/potentials/dihedral/DihedralPotential.h> 13 #include <mcMd/simulation/SystemInterface.h> 33 template <
class Interaction>
64 virtual void readParameters(std::istream& in);
124 void set(std::string name,
int type,
double value)
125 { interactionPtr_->set(name, type, value); }
134 double get(std::string name,
int type)
const 135 {
return interactionPtr_->get(name, type); }
140 virtual std::string interactionClassName()
const;
145 Interaction& interaction();
150 const Interaction& interaction()
const;
162 virtual double atomEnergy(
const Atom& atom)
const;
167 virtual void addForces();
172 virtual void computeEnergy();
177 virtual void computeStress();
183 Interaction* interactionPtr_;
190 template <
typename T>
191 void computeStressImpl(T& stress)
const;
197 #include <mcMd/simulation/System.h> 198 #include <mcMd/simulation/Simulation.h> 199 #include <mcMd/simulation/stress.h> 200 #include <mcMd/chemistry/getAtomGroups.h> 201 #include <simp/boundary/Boundary.h> 202 #include <util/space/Dimension.h> 203 #include <util/space/Vector.h> 204 #include <util/space/Tensor.h> 205 #include <util/accumulators/setToZero.h> 212 using namespace Util;
213 using namespace Simp;
218 template <
class Interaction>
224 { interactionPtr_ =
new Interaction(); }
229 template <
class Interaction>
241 template <
class Interaction>
248 template <
class Interaction>
253 bool nextIndent =
false;
262 template <
class Interaction>
269 bool nextIndent =
false;
278 template <
class Interaction>
290 template <
class Interaction>
293 {
return interaction().energy(R1, R2, R3, typeId); }
298 template <
class Interaction>
302 {
interaction().force(R1, R2, R3, F1, F2, F3, typeId); }
307 template <
class Interaction>
320 for (iDihedral = 0; iDihedral < dihedrals.
size(); ++iDihedral) {
321 dihedralPtr = dihedrals[iDihedral];
337 template <
class Interaction>
349 for (
begin(iSpec, molIter); molIter.
notEnd(); ++molIter) {
350 molIter->begin(dihedralIter);
351 for ( ; dihedralIter.
notEnd(); ++dihedralIter){
353 dihedralIter->atom(0).position(), dr1);
355 dihedralIter->atom(1).position(), dr2);
357 dihedralIter->atom(2).position(), dr3);
359 energy(dr1, dr2, dr3, dihedralIter->typeId());
372 template <
class Interaction>
375 Vector dr1, dr2, dr3, force1, force2, force3;
376 Atom *atom0Ptr, *atom1Ptr, *atom2Ptr, *atom3Ptr;
383 for (
begin(iSpec, molIter); molIter.
notEnd(); ++molIter) {
384 molIter->begin(dihedralIter);
385 for ( ; dihedralIter.
notEnd(); ++dihedralIter) {
387 atom0Ptr = &(dihedralIter->atom(0));
388 atom1Ptr = &(dihedralIter->atom(1));
389 atom2Ptr = &(dihedralIter->atom(2));
390 atom3Ptr = &(dihedralIter->atom(3));
399 force1, force2, force3, dihedralIter->typeId());
401 atom0Ptr->
force() += force1;
402 atom1Ptr->
force() -= force1;
403 atom1Ptr->
force() += force2;
404 atom2Ptr->
force() -= force2;
405 atom2Ptr->
force() += force3;
406 atom3Ptr->
force() -= force3;
421 template <
class Interaction>
422 template <
typename T>
426 Vector dr1, dr2, dr3, force1, force2, force3;
435 for (
begin(iSpec, molIter); molIter.
notEnd(); ++molIter) {
436 molIter->begin(dihedralIter);
437 for ( ; dihedralIter.
notEnd(); ++dihedralIter){
440 dihedralIter->atom(0).position(), dr1);
442 dihedralIter->atom(1).position(), dr2);
444 dihedralIter->atom(2).position(), dr3);
446 interaction().force(dr1, dr2, dr3, force1, force2, force3,
447 dihedralIter->typeId());
452 incrementPairStress(force1, dr1, stress);
453 incrementPairStress(force2, dr2, stress);
454 incrementPairStress(force3, dr3, stress);
461 normalizeStress(stress);
467 template <
class Interaction>
472 computeStressImpl(stress);
478 template <
class Interaction>
480 {
return *interactionPtr_; }
482 template <
class Interaction>
484 {
return *interactionPtr_; }
489 template <
class Interaction>
A Vector is a Cartesian vector.
virtual void readParameters(std::istream &in)
Read dihedral potential parameters.
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.
A set of interacting Molecules enclosed by a Boundary.
int typeId() const
Get the typeId for this covalent group.
Forward iterator for a PArray.
File containing preprocessor macros for error handling.
Classes used by all simpatico molecular simulations.
void getAtomDihedrals(const Atom &atom, AtomDihedralArray &groups)
Fill an array of pointers to Dihedrals that contain an Atom.
A Tensor represents a Cartesian tensor.
Interface for a Dihedral Potential.
Forward const iterator for an Array or a C array.
Saving / output archive for binary ostream.
virtual void save(Serializable::OArchive &ar)
Save internal state to an archive.
A fixed capacity (static) contiguous array with a variable logical size.
int nDihedral() const
Get number of dihedrals per molecule for this Species.
virtual ~DihedralPotentialImpl()
Destructor.
virtual void force(const Vector &R1, const Vector &R2, const Vector &R3, Vector &F1, Vector &F2, Vector &F3, int type) const
Returns derivatives of energy with respect to bond vectors forming the dihedral group.
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.
DihedralPotentialImpl(System &system)
Constructor.
bool notEnd() const
Is the current pointer not at the end of the PArray?
Utility classes for scientific computation.
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.
virtual double atomEnergy(const Atom &atom) const
Compute and return the dihedral energy for one Atom.
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 std::string interactionClassName() const
Return pair interaction class name (e.g., "CosineDihedral").
Interaction & interaction()
Return dihedral potential interaction by reference.
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 computeStress()
Compute and store the total dihedral pressure.
Boundary & boundary() const
Get the Boundary by reference.
Implementation template for an DihedralPotential.
virtual void addForces()
Add dihedral forces to all atomic forces.
const Vector & position() const
Get the position Vector by const reference.
bool notEnd() const
Is this not the end of the array?
virtual void computeEnergy()
Calculate and store dihedral energy for this System.
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.
double energy()
Return the energy contribution, compute if necessary.
virtual void loadParameters(Serializable::IArchive &ar)
Load internal state from an archive.