Simpatico  v1.10
McSystem.cpp
1 /*
2 * Simpatico - Simulation Package for Polymeric and Molecular Liquids
3 *
4 * Copyright 2010 - 2017, The Regents of the University of Minnesota
5 * Distributed under the terms of the GNU General Public License.
6 */
7 
8 #include "McSystem.h"
9 #include "McSimulation.h"
10 #include <mcMd/simulation/stress.h>
11 #include <mcMd/generators/Generator.h>
12 #include <mcMd/generators/generatorFactory.h>
13 #ifndef SIMP_NOPAIR
14 #include <mcMd/potentials/pair/McPairPotential.h>
15 #include <mcMd/potentials/pair/PairFactory.h>
16 #endif
17 #ifdef SIMP_BOND
18 #include <mcMd/potentials/bond/BondPotential.h>
19 #endif
20 #ifdef SIMP_ANGLE
21 #include <mcMd/potentials/angle/AnglePotential.h>
22 #endif
23 #ifdef SIMP_DIHEDRAL
24 #include <mcMd/potentials/dihedral/DihedralPotential.h>
25 #endif
26 #ifdef SIMP_EXTERNAL
27 #include <mcMd/potentials/external/ExternalPotential.h>
28 #endif
29 #ifdef MCMD_LINK
30 #include <mcMd/links/LinkMaster.h>
31 #endif
32 #ifdef SIMP_TETHER
33 #include <mcMd/tethers/TetherMaster.h>
34 #include <mcMd/potentials/tether/TetherPotential.h>
35 #endif
36 #ifdef MCMD_PERTURB
37 #include <mcMd/perturb/mcSystem/McPerturbationFactory.h>
38 #endif
39 
40 #include <simp/species/Species.h>
41 #include <simp/ensembles/BoundaryEnsemble.h>
42 #include <simp/ensembles/EnergyEnsemble.h>
43 
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>
50 
51 #include <util/global.h>
52 
53 #include <fstream>
54 
55 namespace McMd
56 {
57 
58  using namespace Util;
59  using namespace Simp;
60 
61  /*
62  * Constructor.
63  */
65  :
66  System()
67  #ifndef SIMP_NOPAIR
68  , pairPotentialPtr_(0)
69  #endif
70  #ifdef SIMP_BOND
71  , bondPotentialPtr_(0)
72  #endif
73  #ifdef SIMP_ANGLE
74  , anglePotentialPtr_(0)
75  #endif
76  #ifdef SIMP_DIHEDRAL
77  , dihedralPotentialPtr_(0)
78  #endif
79  #ifdef SIMP_EXTERNAL
80  , externalPotentialPtr_(0)
81  #endif
82  #ifdef MCMD_LINK
83  , linkPotentialPtr_(0)
84  #endif
85  #ifdef SIMP_TETHER
86  , tetherPotentialPtr_(0)
87  #endif
88  {
89  UTIL_CHECK(!isCopy());
90  setClassName("McSystem");
91 
92  // Actions taken when particles are moved
95  }
96 
97 
98  /*
99  * Destructor.
100  */
102  {
103  #ifndef SIMP_NOPAIR
104  if (pairPotentialPtr_) delete pairPotentialPtr_;
105  #endif
106  #ifdef SIMP_BOND
107  if (bondPotentialPtr_) delete bondPotentialPtr_;
108  #endif
109  #ifdef SIMP_ANGLE
110  if (anglePotentialPtr_) delete anglePotentialPtr_;
111  #endif
112  #ifdef SIMP_DIHEDRAL
113  if (dihedralPotentialPtr_) delete dihedralPotentialPtr_;
114  #endif
115  #ifdef SIMP_EXTERNAL
116  if (externalPotentialPtr_) delete externalPotentialPtr_;
117  #endif
118  #ifdef MCMD_LINK
119  if (linkPotentialPtr_) delete linkPotentialPtr_;
120  #endif
121  #ifdef SIMP_TETHER
122  if (tetherPotentialPtr_) delete tetherPotentialPtr_;
123  #endif
124  }
125 
126  // -------------------------------------------------------------
127  // Initialization and Parameter I/O
128 
129  /*
130  * Read parameters from file.
131  */
132  void McSystem::readParameters(std::istream &in)
133  {
135  readFileMaster(in);
137 
138  #ifndef SIMP_NOPAIR
139  assert(pairPotentialPtr_ == 0);
140  pairPotentialPtr_ = pairFactory().mcFactory(pairStyle(), *this);
141  if (pairPotentialPtr_ == 0) {
142  UTIL_THROW("Failed attempt to create McPairPotential");
143  }
144  readParamComposite(in, *pairPotentialPtr_);
145  #endif
146 
147  #ifdef SIMP_BOND
148  assert(bondPotentialPtr_ == 0);
149  if (simulation().nBondType() > 0) {
150  bondPotentialPtr_ = bondFactory().factory(bondStyle());
151  if (bondPotentialPtr_ == 0) {
152  UTIL_THROW("Failed attempt to create BondPotential");
153  }
154  readParamComposite(in, *bondPotentialPtr_);
155  }
156  #endif
157 
158  #ifdef SIMP_ANGLE
159  assert(anglePotentialPtr_ == 0);
160  if (simulation().nAngleType() > 0) {
161  anglePotentialPtr_ = angleFactory().factory(angleStyle());
162  if (anglePotentialPtr_ == 0) {
163  UTIL_THROW("Failed attempt to create AnglePotential");
164  }
165  readParamComposite(in, *anglePotentialPtr_);
166  }
167  #endif
168 
169  #ifdef SIMP_DIHEDRAL
170  assert(dihedralPotentialPtr_ == 0);
171  if (simulation().nDihedralType() > 0) {
172  dihedralPotentialPtr_ = dihedralFactory().factory(dihedralStyle());
173  if (dihedralPotentialPtr_ == 0) {
174  UTIL_THROW("Failed attempt to create DihedralPotential");
175  }
176  readParamComposite(in, *dihedralPotentialPtr_);
177  }
178  #endif
179 
180  #ifdef SIMP_EXTERNAL
181  assert(externalPotentialPtr_ == 0);
182  if (simulation().hasExternal()) {
183  externalPotentialPtr_ =
185  if (externalPotentialPtr_ == 0) {
186  UTIL_THROW("Failed attempt to create ExternalPotential");
187  }
188  readParamComposite(in, *externalPotentialPtr_);
189  }
190  #endif
191 
192  #ifdef MCMD_LINK
193  assert(linkPotentialPtr_ == 0);
194  if (simulation().nLinkType() > 0) {
195  readLinkMaster(in);
196  linkPotentialPtr_ = linkFactory().factory(linkStyle());
197  if (linkPotentialPtr_ == 0) {
198  UTIL_THROW("Failed attempt to create BondPotential for links");
199  }
200  readParamComposite(in, *linkPotentialPtr_);
201  }
202  #endif
203 
204  #ifdef SIMP_TETHER
205  if (simulation().hasTether()) {
206  readTetherMaster(in);
207  tetherPotentialPtr_ = tetherFactory().factory(tetherStyle(), *this);
208  if (tetherPotentialPtr_ == 0) {
209  UTIL_THROW("Failed attempt to create TetherPotential");
210  }
211  readParamComposite(in, *tetherPotentialPtr_);
212  }
213  #endif
214 
215  // Read EnergyEnsemble and BoundaryEnsemble
216  readEnsembles(in);
217 
218  #ifdef MCMD_PERTURB
219  if (expectPerturbation()) {
220  readPerturbation(in);
221  #ifdef UTIL_MPI
222  if (hasPerturbation()) {
223  readReplicaMove(in);
224  }
225  #endif
226  }
227  #endif
228  }
229 
230  /*
231  * Load parameters from an archive.
232  */
234  {
236  loadFileMaster(ar);
238 
239  #ifndef SIMP_NOPAIR
240  pairPotentialPtr_ = pairFactory().mcFactory(pairStyle(), *this);
241  if (pairPotentialPtr_ == 0) {
242  UTIL_THROW("Failed attempt to create McPairPotential");
243  }
244  loadParamComposite(ar, *pairPotentialPtr_);
245  #endif
246 
247  #ifdef SIMP_BOND
248  assert(bondPotentialPtr_ == 0);
249  if (simulation().nBondType() > 0) {
250  bondPotentialPtr_ = bondFactory().factory(bondStyle());
251  if (bondPotentialPtr_ == 0) {
252  UTIL_THROW("Failed attempt to create BondPotential");
253  }
254  loadParamComposite(ar, *bondPotentialPtr_);
255  }
256  #endif
257 
258  #ifdef SIMP_ANGLE
259  assert(anglePotentialPtr_ == 0);
260  if (simulation().nAngleType() > 0) {
261  anglePotentialPtr_ = angleFactory().factory(angleStyle());
262  if (anglePotentialPtr_ == 0) {
263  UTIL_THROW("Failed attempt to create AnglePotential");
264  }
265  loadParamComposite(ar, *anglePotentialPtr_);
266  }
267  #endif
268 
269  #ifdef SIMP_DIHEDRAL
270  assert(dihedralPotentialPtr_ == 0);
271  if (simulation().nDihedralType() > 0) {
272  dihedralPotentialPtr_ = dihedralFactory().factory(dihedralStyle());
273  if (dihedralPotentialPtr_ == 0) {
274  UTIL_THROW("Failed attempt to create DihedralPotential");
275  }
276  loadParamComposite(ar, *dihedralPotentialPtr_);
277  }
278  #endif
279 
280  #ifdef SIMP_EXTERNAL
281  assert(externalPotentialPtr_ == 0);
282  if (simulation().hasExternal()) {
283  externalPotentialPtr_ =
285  if (externalPotentialPtr_ == 0) {
286  UTIL_THROW("Failed attempt to create ExternalPotential");
287  }
288  loadParamComposite(ar, *externalPotentialPtr_);
289  }
290  #endif
291 
292  #ifdef MCMD_LINK
293  assert(linkPotentialPtr_ == 0);
294  if (simulation().nLinkType() > 0) {
295  loadLinkMaster(ar);
296  linkPotentialPtr_ = linkFactory().factory(linkStyle());
297  if (linkPotentialPtr_ == 0) {
298  UTIL_THROW("Failed attempt to create BondPotential for links");
299  }
300  loadParamComposite(ar, *linkPotentialPtr_);
301  }
302  #endif
303 
304  #ifdef SIMP_TETHER
305  if (simulation().hasTether()) {
306  loadTetherMaster(ar);
307  tetherPotentialPtr_ = tetherFactory().factory(tetherStyle(), *this);
308  if (tetherPotentialPtr_ == 0) {
309  UTIL_THROW("Failed attempt to create TetherPotential");
310  }
311  loadParamComposite(ar, *tetherPotentialPtr_);
312  }
313  #endif
314 
315  loadEnsembles(ar);
316 
317  #ifdef MCMD_PERTURB
318  loadPerturbation(ar);
319  #ifdef UTIL_MPI
320  if (hasPerturbation()) {
321  loadReplicaMove(ar);
322  }
323  #endif
324  #endif
325 
326  }
327 
328  /*
329  * Save parameters.
330  */
332  {
333  saveFileMaster(ar);
335  #ifndef SIMP_NOPAIR
336  pairPotential().save(ar);
337  #endif
338  #ifdef SIMP_BOND
339  if (simulation().nBondType() > 0) {
340  bondPotential().save(ar);
341  }
342  #endif
343  #ifdef SIMP_ANGLE
344  if (simulation().nAngleType() > 0) {
345  anglePotential().save(ar);
346  }
347  #endif
348  #ifdef SIMP_DIHEDRAL
349  if (simulation().nDihedralType() > 0) {
350  dihedralPotential().save(ar);
351  }
352  #endif
353  #ifdef SIMP_EXTERNAL
354  assert(externalPotentialPtr_ == 0);
355  if (simulation().hasExternal() > 0) {
356  assert(externalPotentialPtr_);
357  externalPotentialPtr_->save(ar);
358  }
359  #endif
360  #ifdef MCMD_LINK
361  if (simulation().nLinkType() > 0) {
362  saveLinkMaster(ar);
363  assert(linkPotentialPtr_);
364  linkPotentialPtr_->save(ar);
365  }
366  #endif
367  #ifdef SIMP_TETHER
368  if (simulation().hasExternal() > 0) {
369  saveTetherMaster(ar);
370  assert(tetherPotentialPtr_);
371  tetherPotentialPtr_->save(ar);
372  }
373  #endif
374 
375  saveEnsembles(ar);
376 
377  #ifdef MCMD_PERTURB
378  savePerturbation(ar);
379  #ifdef UTIL_MPI
380  if (hasPerturbation()) {
381  saveReplicaMove(ar);
382  }
383  #endif
384  #endif
385  }
386 
387  // -------------------------------------------------------------
388  // Configuration I/o
389 
390  /*
391  * Read configuration from a specific input stream.
392  */
393  void McSystem::readConfig(std::istream &in)
394  {
395  System::readConfig(in);
396  #ifndef SIMP_NOPAIR
398  #endif
399  }
400 
401  /*
402  * Load a System configuration from an archive.
403  */
405  {
406  System::loadConfig(ar);
407  #ifndef SIMP_NOPAIR
409  #endif
410  }
411 
412  /*
413  * Generate molecules for all species.
414  */
416  Array<int> const & capacities,
417  Array<double> const & diameters)
418  {
419 
420  // Setup a local cell list
421  CellList cellList;
422  Generator::setupCellList(simulation().atomCapacity(),
423  boundary(), diameters, cellList);
424 
425  // Generate molecules for each species
426  Generator* ptr = 0;
427  int nSpecies = simulation().nSpecies();
428  bool success = false;
429  for (int iSpecies = 0; iSpecies < nSpecies; ++iSpecies) {
430  if (capacities[iSpecies] > 0) {
431  ptr = generatorFactory(simulation().species(iSpecies), *this);
432  UTIL_CHECK(ptr);
433  success = ptr->generate(capacities[iSpecies],
434  diameters, cellList);
435  delete ptr;
436  if (!success) {
437  Log::file() << "Failed to complete species "
438  << iSpecies << "\n";
439  }
440  UTIL_CHECK(success);
441  }
442  }
443 
444  #ifndef SIMP_NOPAIR
446  #endif
447 
448  #ifdef UTIL_DEBUG
449  isValid();
450  #endif
451  }
452 
453  // -------------------------------------------------------------
454  // Energy Evaluators (including all components)
455 
456  /*
457  * Return total potential energy for one Atom.
458  */
459  double McSystem::atomPotentialEnergy(const Atom &atom) const
460  {
461  double energy = 0.0;
462  #ifndef SIMP_NOPAIR
463  energy += pairPotential().atomEnergy(atom);
464  #endif
465  #ifdef SIMP_BOND
466  if (hasBondPotential()) {
467  energy += bondPotential().atomEnergy(atom);
468  }
469  #endif
470  #ifdef SIMP_ANGLE
471  if (hasAnglePotential()) {
472  energy += anglePotential().atomEnergy(atom);
473  }
474  #endif
475  #ifdef SIMP_DIHEDRAL
476  if (hasDihedralPotential()) {
477  energy += dihedralPotential().atomEnergy(atom);
478  }
479  #endif
480  #ifdef SIMP_EXTERNAL
481  if (hasExternalPotential()) {
482  energy += externalPotential().atomEnergy(atom);
483  }
484  #endif
485  #ifdef MCMD_LINK
486  if (hasLinkPotential()) {
487  energy += linkPotential().atomEnergy(atom);
488  }
489  #endif
490  #ifdef SIMP_TETHER
491  if (tetherPotentialPtr_) {
492  if (tetherMaster().isTethered(atom)) {
493  energy += tetherPotential().atomEnergy(atom);
494  }
495  }
496  #endif
497  return energy;
498  }
499 
500  /*
501  * Return total potential energy for this McSystem.
502  */
504  {
505  double energy = 0.0;
506  #ifndef SIMP_NOPAIR
507  energy += pairPotential().energy();
508  #endif
509  #ifdef SIMP_BOND
510  if (hasBondPotential()) {
511  energy += bondPotential().energy();
512  }
513  #endif
514  #ifdef SIMP_ANGLE
515  if (hasAnglePotential()) {
516  energy += anglePotential().energy();
517  }
518  #endif
519  #ifdef SIMP_DIHEDRAL
520  if (hasDihedralPotential()) {
521  energy += dihedralPotential().energy();
522  }
523  #endif
524  #ifdef SIMP_EXTERNAL
525  if (hasExternalPotential()) {
526  energy += externalPotential().energy();
527  }
528  #endif
529  #ifdef MCMD_LINK
530  if (hasLinkPotential()) {
531  energy += linkPotential().energy();
532  }
533  #endif
534  #ifdef SIMP_TETHER
535  if (tetherPotentialPtr_) {
536  energy += tetherPotential().energy();
537  }
538  #endif
539  return energy;
540  }
541 
542  /*
543  * Unset all precomputed potential energy components.
544  */
546  {
547  #ifndef SIMP_NOPAIR
549  #endif
550  #ifdef SIMP_BOND
551  if (hasBondPotential()) {
553  }
554  #endif
555  #ifdef SIMP_ANGLE
556  if (hasAnglePotential()) {
558  }
559  #endif
560  #ifdef SIMP_DIHEDRAL
561  if (hasDihedralPotential()) {
563  }
564  #endif
565  #ifdef SIMP_EXTERNAL
566  if (hasExternalPotential()) {
568  }
569  #endif
570  }
571 
572  // -------------------------------------------------------------
573  // Pressure/Stress Evaluators (including all components)
574 
575  template <typename T>
576  void McSystem::computeVirialStressImpl(T& stress) const
577  {
578  setToZero(stress);
579 
580  #ifndef SIMP_NOPAIR
581  T pairStress;
582  pairPotential().computeStress(pairStress);
583  stress += pairStress;
584  #endif
585  #ifdef SIMP_BOND
586  if (hasBondPotential()) {
587  T bondStress;
588  bondPotential().computeStress(bondStress);
589  stress += bondStress;
590  }
591  #endif
592  #ifdef SIMP_ANGLE
593  if (hasAnglePotential()) {
594  T angleStress;
595  anglePotential().computeStress(angleStress);
596  stress += angleStress;
597  }
598  #endif
599  #ifdef SIMP_DIHEDRAL
600  if (hasDihedralPotential()) {
601  T dihedralStress;
602  dihedralPotential().computeStress(dihedralStress);
603  stress += dihedralStress;
604  }
605  #endif
606  #ifdef MCMD_LINK
607  if (hasLinkPotential()) {
608  T linkStress;
609  linkPotential().computeStress(linkStress);
610  stress += linkStress;
611  }
612  #endif
613  }
614 
615  /*
616  * Compute virial pressure (isotropic)
617  */
618  template <>
619  void McSystem::computeVirialStress<double>(double& stress) const
620  { computeVirialStressImpl(stress); }
621 
622  /*
623  * Compute virial stress (diagonal components)
624  */
625  template <>
626  void McSystem::computeVirialStress<Util::Vector>(Util::Vector& stress) const
627  { computeVirialStressImpl(stress); }
628 
629  /*
630  * Compute virial stress (full tensor).
631  */
632  template <>
633  void McSystem::computeVirialStress<Util::Tensor>(Util::Tensor& stress) const
634  { computeVirialStressImpl(stress); }
635 
636  /*
637  * Compute total pressure (isotropic)
638  */
639  template <>
640  void McSystem::computeStress<double>(double& stress) const
641  {
642  computeVirialStress(stress);
643  if (energyEnsemble().isIsothermal()) {
644  double rho = nAtom()/boundary().volume();
645  double temperature = energyEnsemble().temperature();
646  stress += rho*temperature;
647  }
648  }
649 
650  /*
651  * Compute total stress (diagonal components)
652  */
653  template <>
654  void McSystem::computeStress<Util::Vector>(Util::Vector& stress) const
655  {
656  computeVirialStress(stress);
657  if (energyEnsemble().isIsothermal()) {
658  double rho = nAtom()/boundary().volume();
659  double temperature = energyEnsemble().temperature();
660  for (int i = 0; i < Dimension; ++i) {
661  stress[i] += rho*temperature;
662  }
663  }
664  }
665 
666  /*
667  * Compute total stress (full tensor)
668  */
669  template <>
670  void McSystem::computeStress<Util::Tensor>(Util::Tensor& stress) const
671  {
672  computeVirialStress(stress);
673  if (energyEnsemble().isIsothermal()) {
674  double rho = nAtom()/boundary().volume();
675  double temperature = energyEnsemble().temperature();
676  for (int i = 0; i < Dimension; ++i) {
677  stress(i, i) += rho*temperature;
678  }
679  }
680  }
681 
682  /*
683  * Unset all precomputed virial stress components.
684  */
686  {
687  #ifndef SIMP_NOPAIR
689  #endif
690  #ifdef SIMP_BOND
691  if (hasBondPotential()) {
693  }
694  #endif
695  #ifdef SIMP_ANGLE
696  if (hasAnglePotential()) {
698  }
699  #endif
700  #ifdef SIMP_DIHEDRAL
701  if (hasDihedralPotential()) {
703  }
704  #endif
705  }
706 
707  // -------------------------------------------------------------
708  // Miscellaneous
709 
710  #ifdef MCMD_PERTURB
711  /*
712  * Return a pointer to a new default McPerturbationFactory.
713  */
715  { return new McPerturbationFactory(*this); }
716  #endif
717 
718  /*
719  * Return true if this McSystem is valid, or an throw Exception.
720  */
721  bool McSystem::isValid() const
722  {
723  System::isValid();
724  #ifndef SIMP_NOPAIR
725  UTIL_CHECK(pairPotentialPtr_);
727  #endif
728  return true;
729  }
730 
731 }
virtual void loadConfig(Serializable::IArchive &ar)
Load the system configuration from an archive.
Definition: McSystem.cpp:404
void saveFileMaster(Serializable::OArchive &ar)
If necessary, save FileMaster to archive.
Definition: System.cpp:463
static void setupCellList(int atomCapacity, Boundary &boundary, const Array< double > &diameters, CellList &cellList)
Allocate any required memory for the cell list.
Definition: Generator.cpp:131
const int Dimension
Dimensionality of space.
Definition: Dimension.h:19
A Vector is a Cartesian vector.
Definition: Vector.h:75
double potentialEnergy() const
Return total potential energy of this System.
Definition: McSystem.cpp:503
bool isCopy() const
Was this System instantiated with the copy constructor?
Definition: System.h:1122
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.
Definition: McSystem.h:519
void loadFileMaster(Serializable::IArchive &ar)
Load FileMaster data from archive, if necessary.
Definition: System.cpp:446
int nAtom() const
Return the total number of atoms in this System.
Definition: System.cpp:1216
const CellList & cellList() const
Get the cellList by const reference.
BondPotential & bondPotential() const
Return the BondPotential by reference.
Definition: McSystem.h:405
bool hasDihedralPotential() const
Does a dihedral potential exist?.
Definition: McSystem.h:433
double volume() const
Return unit cell volume.
void loadPerturbation(Serializable::IArchive &ar)
Load the perturbation parameter block (if any)
Definition: System.cpp:1003
void unsetVirialStress()
Unset precomputed virial stress components.
Definition: McSystem.cpp:685
bool hasLinkPotential() const
Does a link potential exist?.
Definition: McSystem.h:484
double atomPotentialEnergy(const Atom &atom) const
Calculate the total potential energy for one Atom.
Definition: McSystem.cpp:459
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.
Definition: System.cpp:670
void readReplicaMove(std::istream &in)
Read the ReplicaMove parameter block (if any)
Definition: System.cpp:1044
EnergyEnsemble & energyEnsemble() const
Get the EnergyEnsemble by reference.
Definition: System.h:1095
bool hasAnglePotential() const
Does angle potential exist?.
Definition: McSystem.h:416
Factory< AnglePotential > & angleFactory()
Get the associated AngleFactory by reference.
Definition: System.cpp:1269
virtual void loadParameters(Serializable::IArchive &ar)
Load parameters from an archive, without configuration.
Definition: McSystem.cpp:233
A set of interacting Molecules enclosed by a Boundary.
Definition: System.h:115
void addObserver(Observer &observer, void(Observer::*methodPtr)(const T &))
Register an observer.
Definition: Signal.h:111
bool hasPerturbation() const
Does this system have an associated Perturbation?
Definition: System.h:1179
File containing preprocessor macros for error handling.
void readEnsembles(std::istream &in)
Read energy and boundary ensemble parameters.
Definition: System.cpp:626
virtual void generateMolecules(Array< int > const &capacities, Array< double > const &diameters)
Generate molecules for all species.
Definition: McSystem.cpp:415
Classes used by all simpatico molecular simulations.
virtual void readConfig(std::istream &in)
Read system configuration from file.
Definition: McSystem.cpp:393
Generator * generatorFactory(Species &species, McSystem &system)
Instantiates generator for on species in an McSystem.
A Tensor represents a Cartesian tensor.
Definition: Tensor.h:32
virtual bool isValid() const
Return true if McSystem is valid, or throw Exception.
Definition: McSystem.cpp:721
std::string linkStyle() const
Return link potential style string.
Definition: System.cpp:1378
void allocateMoleculeSets()
Allocate and initialize molecule sets for all species.
Definition: System.cpp:1093
std::string dihedralStyle() const
Return dihedral potential style string.
Definition: System.cpp:1301
void savePotentialStyles(Serializable::OArchive &ar)
Save potential style strings.
Definition: System.cpp:575
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.
Definition: System.cpp:1229
virtual void loadConfig(Serializable::IArchive &ar)
Load configuration.
Definition: System.cpp:706
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.
Definition: System.cpp:1261
#define UTIL_THROW(msg)
Macro for throwing an Exception, reporting function, file and line number.
Definition: global.h:51
Factory< BondPotential > & linkFactory()
Get the associated Link factory by reference.
Definition: System.cpp:1366
Simulation & simulation() const
Get the parent Simulation by reference.
Definition: System.h:1055
bool hasBondPotential() const
Does a bond potential exist?.
Definition: McSystem.h:399
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.
Definition: McSystem.h:473
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.
Definition: McSystem.cpp:331
void unsetPotentialEnergies()
Unset potential precomputed potential energy components.
Definition: McSystem.cpp:545
void setToZero(int &value)
Set an int variable to zero.
Definition: setToZero.h:25
Factory< BondPotential > & bondFactory()
Get the associated Factory<BondPotential> by reference.
Definition: System.cpp:1249
bool expectPerturbation() const
Return true if we expect a perturbation.
Definition: System.h:1167
A point particle within a Molecule.
Utility classes for scientific computation.
Definition: accumulators.mod:1
void readLinkMaster(std::istream &in)
Read the LinkMaster parameters.
Definition: System.cpp:654
Generates initial configurations for molecules of one species.
Definition: Generator.h:38
virtual ~McSystem()
Destructor.
Definition: McSystem.cpp:101
Default Factory for subclasses of Perturbation.
void savePerturbation(Serializable::OArchive &ar)
Save the perturbation parameter block (if any)
Definition: System.cpp:1028
void computeVirialStress(T &stress) const
Compute total virial stress (excludes kinetic contribution).
std::string externalStyle() const
Return external potential style string.
Definition: System.cpp:1341
McPairPotential & pairPotential() const
Return the McPairPotential by reference.
Definition: McSystem.h:388
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.
Definition: System.cpp:808
static std::ostream & file()
Get log ostream by reference.
Definition: Log.cpp:57
McSystem()
Constructor.
Definition: McSystem.cpp:64
std::string pairStyle() const
Return nonbonded pair style string.
Definition: System.cpp:1241
void loadLinkMaster(Serializable::IArchive &ar)
Load the LinkMaster.
Definition: System.cpp:662
void saveEnsembles(Serializable::OArchive &ar)
Save energy and boundary ensembles.
Definition: System.cpp:646
Boundary & boundary() const
Get the Boundary by reference.
Definition: System.h:1064
BondPotential & linkPotential() const
Return the McLinkPotential by reference.
Definition: McSystem.h:493
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?.
Definition: McSystem.h:467
void loadReplicaMove(Serializable::IArchive &ar)
Read the ReplicaMove parameter block (if any)
Definition: System.cpp:1061
virtual bool isValid() const
Return true if valid, or throw Exception.
Definition: System.cpp:1405
#define UTIL_CHECK(condition)
Assertion macro suitable for serial or parallel production code.
Definition: global.h:68
void saveReplicaMove(Serializable::OArchive &ar)
Save the ReplicaMove parameter block (if any)
Definition: System.cpp:1078
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.
Definition: System.cpp:1329
void readPerturbation(std::istream &in)
Read the perturbation parameter block (if any)
Definition: System.cpp:980
AnglePotential & anglePotential() const
Return AnglePotential by reference.
Definition: McSystem.h:422
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.
Definition: Generator.cpp:87
void readFileMaster(std::istream &in)
Read FileMaster parameters, if none yet exists.
Definition: System.cpp:427
void readPotentialStyles(std::istream &in)
Read potential style parameter strings.
Definition: System.cpp:473
double temperature() const
Return the temperature.
virtual void readParameters(std::istream &in)
Read parameters from input file.
Definition: McSystem.cpp:132
Factory< DihedralPotential > & dihedralFactory()
Get the associated Dihedral Factory by reference.
Definition: System.cpp:1289
void loadEnsembles(Serializable::IArchive &ar)
Load energy and boundary ensembles from archive.
Definition: System.cpp:636
virtual void unsetStress()
Mark the stress as unknown.
void loadPotentialStyles(Serializable::IArchive &ar)
Load potential style strings from an archive.
Definition: System.cpp:524
virtual void computeStress()
Compute and store the stress tensor.
std::string angleStyle() const
Return angle potential style string.
Definition: System.cpp:1281
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.
Definition: McSystem.cpp:714
virtual double atomEnergy(const Atom &atom) const =0
Calculate the nonbonded pair energy for one Atom.
DihedralPotential & dihedralPotential() const
Return the DihedralPotential by reference.
Definition: McSystem.h:439