1 #ifndef MCMD_MD_EWALD_PAIR_POTENTIAL_IMPL_H 2 #define MCMD_MD_EWALD_PAIR_POTENTIAL_IMPL_H 4 #include <mcMd/potentials/pair/MdPairPotential.h> 5 #include <mcMd/potentials/pair/McPairPotentialImpl.h> 6 #include <mcMd/simulation/stress.h> 7 #include <mcMd/mdSimulation/MdSystem.h> 8 #include <mcMd/chemistry/AtomType.h> 9 #include <util/containers/Array.h> 10 #include <util/space/Tensor.h> 11 #include <util/misc/Setable.h> 14 #include <mcMd/potentials/coulomb/EwaldRSpaceAccumulator.h> 15 #include <simp/interaction/coulomb/EwaldInteraction.h> 47 template <
class Interaction>
72 virtual void readParameters(std::istream& in);
100 double energy(
double rsq,
int iAtomType,
int jAtomType)
const;
111 double forceOverR(
double rsq,
int iAtomType,
int jAtomType)
const;
116 virtual double maxPairCutoff()
const;
126 void set(std::string name,
int i,
int j,
double value)
127 { pairPtr_->set(name, i, j, value); }
136 double get(std::string name,
int i,
int j)
const 137 {
return pairPtr_->get(name, i, j); }
142 virtual std::string interactionClassName()
const;
149 virtual void addForces();
154 virtual void unsetEnergy();
159 virtual void computeEnergy();
164 virtual void unsetStress();
169 virtual void computeStress();
176 Interaction* pairPtr_;
192 {
return (*atomTypesPtr_)[i]; }
197 #include <mcMd/simulation/System.h> 198 #include <mcMd/simulation/Simulation.h> 199 #include <mcMd/mdSimulation/MdSystem.h> 200 #include <mcMd/simulation/stress.h> 201 #include <mcMd/neighbor/PairIterator.h> 202 #include <simp/boundary/Boundary.h> 203 #include <util/math/Constants.h> 204 #include <util/space/Dimension.h> 205 #include <util/space/Vector.h> 206 #include <util/accumulators/setToZero.h> 207 #include <mcMd/potentials/coulomb/MdCoulombPotential.h> 208 #include <mcMd/potentials/coulomb/MdEwaldPotential.h> 210 #include <mcMd/potentials/coulomb/MdSpmePotential.h> 217 using namespace Util;
218 using namespace Simp;
223 template <
class Interaction>
227 ewaldInteractionPtr_(0),
228 rSpaceAccumulatorPtr_(0),
229 atomTypesPtr_(&system.simulation().atomTypes()),
240 ewaldInteractionPtr_ = &ewaldPtr->ewaldInteraction();
241 rSpaceAccumulatorPtr_ = &ewaldPtr->rSpaceAccumulator();
248 ewaldInteractionPtr_ = &ewaldPtr->ewaldInteraction();
249 rSpaceAccumulatorPtr_ = &ewaldPtr->rSpaceAccumulator();
256 rSpaceAccumulatorPtr_->setPairPotential(*
this);
258 pairPtr_ =
new Interaction;
264 template <
class Interaction>
267 if (pairPtr_ && !isCopy_) {
270 ewaldInteractionPtr_ = 0;
271 rSpaceAccumulatorPtr_ = 0;
278 template <
class Interaction>
283 pairPtr_->setNAtomType(
simulation().nAtomType());
284 bool nextIndent =
false;
286 pairPtr_->readParameters(in);
305 template <
class Interaction>
311 pairPtr_->setNAtomType(
simulation().nAtomType());
312 bool nextIndent =
false;
314 pairPtr_->loadParameters(ar);
317 pairPtr_->maxPairCutoff())
325 template <
class Interaction>
338 template <
class Interaction>
double 340 int iAtomType,
int jAtomType)
342 {
return pairPtr_->energy(rsq, iAtomType, jAtomType); }
347 template <
class Interaction>
double 349 int iAtomType,
int jAtomType)
const 351 if (rsq < pairPtr_->cutoffSq(iAtomType, jAtomType)) {
352 return pairPtr_->forceOverR(rsq, iAtomType, jAtomType);
361 template <
class Interaction>
363 {
return pairPtr_->maxPairCutoff(); }
368 template <
class Interaction>
370 {
return pairPtr_->className(); }
375 template <
class Interaction>
397 iter.
getPair(atom0Ptr, atom1Ptr);
401 if (rsq < ewaldCutoffSq) {
402 type0 = atom0Ptr->
typeId();
403 type1 = atom1Ptr->
typeId();
404 qProduct = (*atomTypesPtr_)[type0].charge();
405 qProduct *= (*atomTypesPtr_)[type1].charge();
407 if (rsq < pairPtr_->cutoffSq(type0, type1)) {
408 forceOverR += pairPtr_->forceOverR(rsq, type0, type1);
411 atom0Ptr->
force() += force;
412 atom1Ptr->
force() -= force;
421 template <
class Interaction>
428 rSpaceAccumulatorPtr_->rSpaceEnergy_.
unset();
434 template <
class Interaction>
451 double pEnergy = 0.0;
452 double cEnergy = 0.0;
457 iter.
getPair(atom0Ptr, atom1Ptr);
461 if (rsq < ewaldCutoffSq) {
462 type0 = atom0Ptr->
typeId();
463 type1 = atom1Ptr->
typeId();
464 if (rsq < pairPtr_->cutoffSq(type0, type1)) {
465 pEnergy += pairPtr_->energy(rsq, atom0Ptr->
typeId(),
468 qProduct = (*atomTypesPtr_)[type0].charge();
469 qProduct *= (*atomTypesPtr_)[type1].charge();
470 cEnergy += ewaldInteractionPtr_->
rSpaceEnergy(rsq, qProduct);
475 energy_.
set(pEnergy);
476 rSpaceAccumulatorPtr_->rSpaceEnergy_.
set(cEnergy);
482 template <
class Interaction>
487 rSpaceAccumulatorPtr_->rSpaceStress_.unset();
493 template <
class Interaction>
524 iter.
getPair(atom0Ptr, atom1Ptr);
529 if (rsq < ewaldCutoffSq) {
530 type0 = atom0Ptr->
typeId();
531 type1 = atom1Ptr->
typeId();
534 if (rsq < pairPtr_->cutoffSq(type0, type1)) {
536 force *= pairPtr_->forceOverR(rsq, type0, type1);
537 incrementPairStress(force, dr, pStress);
541 qProduct = (*atomTypesPtr_)[type0].charge();
542 qProduct *= (*atomTypesPtr_)[type1].charge();
546 incrementPairStress(force, dr, cStress);
553 normalizeStress(pStress);
554 normalizeStress(cStress);
556 stress_.set(pStress);
557 rSpaceAccumulatorPtr_->rSpaceStress_.set(cStress);
void initialize(int atomIdEnd, double potentialCutoff)
Allocate memory and initialize.
Coulomb potential for an Md simulation.
A Vector is a Cartesian vector.
virtual void loadParameters(Serializable::IArchive &ar)
Load internal state from an archive.
double distanceSq(const Vector &r1, const Vector &r2) const
Return square distance between positions r1 and r2.
Implementation of a pair potential for a charged system.
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.
void loadParamComposite(Serializable::IArchive &ar, ParamComposite &child, bool next=true)
Add and load a required child ParamComposite.
Tensor & zero()
Set all elements of this tensor to zero.
double rSpaceForceOverR(double rSq, double qProduct) const
Return ratio of scalar pair interaction force to pair separation.
Array container class template.
virtual void computeStress()
Compute and store all short-range pair stress contributions.
File containing preprocessor macros for error handling.
double rSpaceCutoffSq() const
Get real space cutoff squared.
virtual void addForces()
Calculate non-bonded pair forces for all atoms in this System.
Classes used by all simpatico molecular simulations.
virtual std::string interactionClassName() const
Return pair interaction class name (e.g., "LJPair").
A Tensor represents a Cartesian tensor.
void getPair(Atom *&atom1Ptr, Atom *&atom2Ptr) const
Get pointers for current pair of Atoms.
virtual ~MdEwaldPairPotentialImpl()
Destructor.
virtual double forceOverR(double rsq, int iAtomType, int jAtomType) const
Return force / separation for a single pair.
Saving / output archive for binary ostream.
virtual double maxPairCutoff() const
Return maximum cutoff.
virtual void computeEnergy()
Compute and store all short-range pair energies.
#define UTIL_THROW(msg)
Macro for throwing an Exception, reporting function, file and line number.
double rSpaceEnergy(double rSq, double qProduct) const
Returns r-space interaction energy for a single pair of atoms.
Descriptor for a type of Atom.
int typeId() const
Get type index for this Atom.
std::string coulombStyle() const
Return coulomb potential style string.
Simulation & simulation() const
Get the parent Simulation by reference.
Implementation of r-space and k-space Ewald Coulomb interactions.
A point particle within a Molecule.
Utility classes for scientific computation.
virtual void readParameters(std::istream &in)
Read pair potential interaction and pair list blocks.
double rSpaceCutoff() const
Get real space cutoff.
Utility class to store r-space Coulomb energy and stress.
void unset()
Unset the value (mark as unknown).
virtual void save(Serializable::OArchive &ar)
Save internal state to an archive.
Iterator for pairs in a PairList.
Smooth Particle-Mesh Ewald Coulomb potential for MD simulations.
void begin(PairIterator &iterator) const
Initialize a PairIterator.
virtual void unsetEnergy()
Unset both energy accumulators.
PairList pairList_
Verlet neighbor pair list for nonbonded interactions.
An PairPotential for MD simulation.
bool isPairListCurrent()
Return true if PairList is current, false if obsolete.
Saving archive for binary istream.
Single-processor Monte Carlo (MC) and molecular dynamics (MD).
void buildPairList()
Build the internal PairList.
void addParamComposite(ParamComposite &child, bool next=true)
Add a child ParamComposite object to the format array.
Ewald Coulomb potential class for MD simulations.
#define UTIL_CHECK(condition)
Assertion macro suitable for serial or parallel production code.
Boundary & boundary() const
Get the Boundary by reference.
bool notEnd() const
Return true if not at end of PairList.
void readParamComposite(std::istream &in, ParamComposite &child, bool next=true)
Add and read a required child ParamComposite.
A System for Molecular Dynamics simulation.
const Vector & position() const
Get the position Vector by const reference.
virtual void unsetStress()
Unset both stress accumulators.
double energy()
Return the energy contribution, compute if necessary.
MdCoulombPotential & coulombPotential() const
Return CoulombPotential by reference.
virtual void save(Serializable::OArchive &ar)
Save internal state to an archive.