9 #include "McSimulation.h" 10 #include <mcMd/simulation/stress.h> 11 #include <mcMd/generators/Generator.h> 12 #include <mcMd/generators/generatorFactory.h> 14 #include <mcMd/potentials/pair/McPairPotential.h> 15 #include <mcMd/potentials/pair/PairFactory.h> 18 #include <mcMd/potentials/bond/BondPotential.h> 21 #include <mcMd/potentials/angle/AnglePotential.h> 24 #include <mcMd/potentials/dihedral/DihedralPotential.h> 27 #include <mcMd/potentials/external/ExternalPotential.h> 30 #include <mcMd/links/LinkMaster.h> 33 #include <mcMd/tethers/TetherMaster.h> 34 #include <mcMd/potentials/tether/TetherPotential.h> 37 #include <mcMd/perturb/mcSystem/McPerturbationFactory.h> 40 #include <simp/species/Species.h> 41 #include <simp/ensembles/BoundaryEnsemble.h> 42 #include <simp/ensembles/EnergyEnsemble.h> 44 #include <util/param/Factory.h> 45 #include <util/space/Vector.h> 46 #include <util/space/Tensor.h> 47 #include <util/space/Dimension.h> 48 #include <util/archives/Serializable_includes.h> 49 #include <util/accumulators/setToZero.h> 68 , pairPotentialPtr_(0)
71 , bondPotentialPtr_(0)
74 , anglePotentialPtr_(0)
77 , dihedralPotentialPtr_(0)
80 , externalPotentialPtr_(0)
83 , linkPotentialPtr_(0)
86 , tetherPotentialPtr_(0)
104 if (pairPotentialPtr_)
delete pairPotentialPtr_;
107 if (bondPotentialPtr_)
delete bondPotentialPtr_;
110 if (anglePotentialPtr_)
delete anglePotentialPtr_;
113 if (dihedralPotentialPtr_)
delete dihedralPotentialPtr_;
116 if (externalPotentialPtr_)
delete externalPotentialPtr_;
119 if (linkPotentialPtr_)
delete linkPotentialPtr_;
122 if (tetherPotentialPtr_)
delete tetherPotentialPtr_;
139 assert(pairPotentialPtr_ == 0);
141 if (pairPotentialPtr_ == 0) {
142 UTIL_THROW(
"Failed attempt to create McPairPotential");
148 assert(bondPotentialPtr_ == 0);
151 if (bondPotentialPtr_ == 0) {
152 UTIL_THROW(
"Failed attempt to create BondPotential");
159 assert(anglePotentialPtr_ == 0);
162 if (anglePotentialPtr_ == 0) {
163 UTIL_THROW(
"Failed attempt to create AnglePotential");
170 assert(dihedralPotentialPtr_ == 0);
173 if (dihedralPotentialPtr_ == 0) {
174 UTIL_THROW(
"Failed attempt to create DihedralPotential");
181 assert(externalPotentialPtr_ == 0);
183 externalPotentialPtr_ =
185 if (externalPotentialPtr_ == 0) {
186 UTIL_THROW(
"Failed attempt to create ExternalPotential");
193 assert(linkPotentialPtr_ == 0);
197 if (linkPotentialPtr_ == 0) {
198 UTIL_THROW(
"Failed attempt to create BondPotential for links");
206 readTetherMaster(in);
207 tetherPotentialPtr_ = tetherFactory().factory(tetherStyle(), *
this);
208 if (tetherPotentialPtr_ == 0) {
209 UTIL_THROW(
"Failed attempt to create TetherPotential");
241 if (pairPotentialPtr_ == 0) {
242 UTIL_THROW(
"Failed attempt to create McPairPotential");
248 assert(bondPotentialPtr_ == 0);
251 if (bondPotentialPtr_ == 0) {
252 UTIL_THROW(
"Failed attempt to create BondPotential");
259 assert(anglePotentialPtr_ == 0);
262 if (anglePotentialPtr_ == 0) {
263 UTIL_THROW(
"Failed attempt to create AnglePotential");
270 assert(dihedralPotentialPtr_ == 0);
273 if (dihedralPotentialPtr_ == 0) {
274 UTIL_THROW(
"Failed attempt to create DihedralPotential");
281 assert(externalPotentialPtr_ == 0);
283 externalPotentialPtr_ =
285 if (externalPotentialPtr_ == 0) {
286 UTIL_THROW(
"Failed attempt to create ExternalPotential");
293 assert(linkPotentialPtr_ == 0);
297 if (linkPotentialPtr_ == 0) {
298 UTIL_THROW(
"Failed attempt to create BondPotential for links");
306 loadTetherMaster(ar);
307 tetherPotentialPtr_ = tetherFactory().factory(tetherStyle(), *
this);
308 if (tetherPotentialPtr_ == 0) {
309 UTIL_THROW(
"Failed attempt to create TetherPotential");
354 assert(externalPotentialPtr_ == 0);
356 assert(externalPotentialPtr_);
357 externalPotentialPtr_->
save(ar);
363 assert(linkPotentialPtr_);
364 linkPotentialPtr_->
save(ar);
369 saveTetherMaster(ar);
370 assert(tetherPotentialPtr_);
371 tetherPotentialPtr_->save(ar);
428 bool success =
false;
429 for (
int iSpecies = 0; iSpecies < nSpecies; ++iSpecies) {
430 if (capacities[iSpecies] > 0) {
433 success = ptr->
generate(capacities[iSpecies],
434 diameters, cellList);
437 Log::file() <<
"Failed to complete species " 491 if (tetherPotentialPtr_) {
492 if (tetherMaster().isTethered(atom)) {
493 energy += tetherPotential().atomEnergy(atom);
535 if (tetherPotentialPtr_) {
536 energy += tetherPotential().energy();
575 template <
typename T>
576 void McSystem::computeVirialStressImpl(T& stress)
const 583 stress += pairStress;
589 stress += bondStress;
596 stress += angleStress;
603 stress += dihedralStress;
610 stress += linkStress;
619 void McSystem::computeVirialStress<double>(
double& stress)
const 620 { computeVirialStressImpl(stress); }
626 void McSystem::computeVirialStress<Util::Vector>(
Util::Vector& stress)
const 627 { computeVirialStressImpl(stress); }
633 void McSystem::computeVirialStress<Util::Tensor>(
Util::Tensor& stress)
const 634 { computeVirialStressImpl(stress); }
640 void McSystem::computeStress<double>(
double& stress)
const 646 stress += rho*temperature;
654 void McSystem::computeStress<Util::Vector>(
Util::Vector& stress)
const 661 stress[i] += rho*temperature;
670 void McSystem::computeStress<Util::Tensor>(
Util::Tensor& stress)
const 677 stress(i, i) += rho*temperature;
virtual void loadConfig(Serializable::IArchive &ar)
Load the system configuration from an archive.
void saveFileMaster(Serializable::OArchive &ar)
If necessary, save FileMaster to archive.
static void setupCellList(int atomCapacity, Boundary &boundary, const Array< double > &diameters, CellList &cellList)
Allocate any required memory for the cell list.
const int Dimension
Dimensionality of space.
A Vector is a Cartesian vector.
double potentialEnergy() const
Return total potential energy of this System.
bool isCopy() const
Was this System instantiated with the copy constructor?
virtual double energy(double rsq, int iAtomType, int jAtomType) const =0
Return pair energy for a single pair.
void buildCellList()
Build the CellList with current configuration.
virtual double atomEnergy(const Atom &atom) const =0
Calculate the external energy for one Atom.
bool isValid(int nAtom=-1) const
Return true if valid, or throw Exception.
Signal & positionSignal()
Signal to indicate change in atomic positions.
void loadFileMaster(Serializable::IArchive &ar)
Load FileMaster data from archive, if necessary.
int nAtom() const
Return the total number of atoms in this System.
const CellList & cellList() const
Get the cellList by const reference.
BondPotential & bondPotential() const
Return the BondPotential by reference.
bool hasDihedralPotential() const
Does a dihedral potential exist?.
double volume() const
Return unit cell volume.
void loadPerturbation(Serializable::IArchive &ar)
Load the perturbation parameter block (if any)
void unsetVirialStress()
Unset precomputed virial stress components.
bool hasLinkPotential() const
Does a link potential exist?.
double atomPotentialEnergy(const Atom &atom) const
Calculate the total potential energy for one Atom.
void loadParamComposite(Serializable::IArchive &ar, ParamComposite &child, bool next=true)
Add and load a required child ParamComposite.
virtual double atomEnergy(const Atom &atom) const =0
Calculate the covalent bond energy for one Atom.
void saveLinkMaster(Serializable::OArchive &ar)
Save the LinkMaster.
void readReplicaMove(std::istream &in)
Read the ReplicaMove parameter block (if any)
EnergyEnsemble & energyEnsemble() const
Get the EnergyEnsemble by reference.
bool hasAnglePotential() const
Does angle potential exist?.
Factory< AnglePotential > & angleFactory()
Get the associated AngleFactory by reference.
virtual void loadParameters(Serializable::IArchive &ar)
Load parameters from an archive, without configuration.
A set of interacting Molecules enclosed by a Boundary.
void addObserver(Observer &observer, void(Observer::*methodPtr)(const T &))
Register an observer.
bool hasPerturbation() const
Does this system have an associated Perturbation?
File containing preprocessor macros for error handling.
void readEnsembles(std::istream &in)
Read energy and boundary ensemble parameters.
virtual void generateMolecules(Array< int > const &capacities, Array< double > const &diameters)
Generate molecules for all species.
Classes used by all simpatico molecular simulations.
virtual void readConfig(std::istream &in)
Read system configuration from file.
Generator * generatorFactory(Species &species, McSystem &system)
Instantiates generator for on species in an McSystem.
A Tensor represents a Cartesian tensor.
virtual bool isValid() const
Return true if McSystem is valid, or throw Exception.
std::string linkStyle() const
Return link potential style string.
void allocateMoleculeSets()
Allocate and initialize molecule sets for all species.
std::string dihedralStyle() const
Return dihedral potential style string.
void savePotentialStyles(Serializable::OArchive &ar)
Save potential style strings.
Saving / output archive for binary ostream.
virtual double energy(const Vector &R1, const Vector &R2, const Vector &R3, int type) const =0
Returns potential energy for one dihedral.
PairFactory & pairFactory()
Get the PairFactory by reference.
virtual void loadConfig(Serializable::IArchive &ar)
Load configuration.
virtual double energy(const Vector &position, int i) const =0
Returns external potential energy of a single particle.
std::string bondStyle() const
Return covalent bond style string.
#define UTIL_THROW(msg)
Macro for throwing an Exception, reporting function, file and line number.
Factory< BondPotential > & linkFactory()
Get the associated Link factory by reference.
Simulation & simulation() const
Get the parent Simulation by reference.
bool hasBondPotential() const
Does a bond potential exist?.
virtual double atomEnergy(const Atom &atom) const
Calculate the covalent angle energy for one Atom.
virtual McPairPotential * mcFactory(const std::string &subclass, System &system) const
Return a pointer to a new McPairPotential, if possible.
virtual void unsetEnergy()
Mark the energy as unknown.
ExternalPotential & externalPotential() const
Return ExternalPotential by reference.
virtual void save(Serializable::OArchive &ar)
Saves all parameters to an archive.
virtual void saveParameters(Serializable::OArchive &ar)
Save parameters to an archive, without configuration.
void unsetPotentialEnergies()
Unset potential precomputed potential energy components.
void setToZero(int &value)
Set an int variable to zero.
Factory< BondPotential > & bondFactory()
Get the associated Factory<BondPotential> by reference.
bool expectPerturbation() const
Return true if we expect a perturbation.
A point particle within a Molecule.
Utility classes for scientific computation.
void readLinkMaster(std::istream &in)
Read the LinkMaster parameters.
Generates initial configurations for molecules of one species.
virtual ~McSystem()
Destructor.
Default Factory for subclasses of Perturbation.
void savePerturbation(Serializable::OArchive &ar)
Save the perturbation parameter block (if any)
void computeVirialStress(T &stress) const
Compute total virial stress (excludes kinetic contribution).
std::string externalStyle() const
Return external potential style string.
McPairPotential & pairPotential() const
Return the McPairPotential by reference.
virtual double energy(double cosTheta, int type) const =0
Returns potential energy for one angle.
A cell list for Atom objects in a periodic system boundary.
virtual double energy(double rSq, int type) const =0
Returns potential energy for one bond.
virtual void readConfig(std::istream &in)
Read system configuration from file.
static std::ostream & file()
Get log ostream by reference.
std::string pairStyle() const
Return nonbonded pair style string.
void loadLinkMaster(Serializable::IArchive &ar)
Load the LinkMaster.
void saveEnsembles(Serializable::OArchive &ar)
Save energy and boundary ensembles.
Boundary & boundary() const
Get the Boundary by reference.
BondPotential & linkPotential() const
Return the McLinkPotential 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.
bool hasExternalPotential() const
Does an external potential exist?.
void loadReplicaMove(Serializable::IArchive &ar)
Read the ReplicaMove parameter block (if any)
virtual bool isValid() const
Return true if valid, or throw Exception.
#define UTIL_CHECK(condition)
Assertion macro suitable for serial or parallel production code.
void saveReplicaMove(Serializable::OArchive &ar)
Save the ReplicaMove parameter block (if any)
void setClassName(const char *className)
Set class name string.
void readParamComposite(std::istream &in, ParamComposite &child, bool next=true)
Add and read a required child ParamComposite.
Factory< ExternalPotential > & externalFactory()
Get the associated ExternalPotential factory by reference.
void readPerturbation(std::istream &in)
Read the perturbation parameter block (if any)
AnglePotential & anglePotential() const
Return AnglePotential by reference.
virtual Data * factory(const std::string &className) const =0
Returns a pointer to a new instance of specified subclass.
virtual bool generate(int nMolecule, Array< double > const &diameters, CellList &cellList)
Generate nMolecule molecules of the associated Species.
void readFileMaster(std::istream &in)
Read FileMaster parameters, if none yet exists.
void readPotentialStyles(std::istream &in)
Read potential style parameter strings.
double temperature() const
Return the temperature.
virtual void readParameters(std::istream &in)
Read parameters from input file.
Factory< DihedralPotential > & dihedralFactory()
Get the associated Dihedral Factory by reference.
void loadEnsembles(Serializable::IArchive &ar)
Load energy and boundary ensembles from archive.
virtual void unsetStress()
Mark the stress as unknown.
void loadPotentialStyles(Serializable::IArchive &ar)
Load potential style strings from an archive.
virtual void computeStress()
Compute and store the stress tensor.
std::string angleStyle() const
Return angle potential style string.
virtual double atomEnergy(const Atom &atom) const
Compute and return the dihedral potential energy for one Atom.
virtual Factory< Perturbation > * newDefaultPerturbationFactory()
Return a pointer to a new McPerturbationFactory.
virtual double atomEnergy(const Atom &atom) const =0
Calculate the nonbonded pair energy for one Atom.
DihedralPotential & dihedralPotential() const
Return the DihedralPotential by reference.