Simpatico  v1.10
MdSystem.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 <util/global.h>
9 #include "MdSystem.h"
10 #include "MdSimulation.h"
11 #include <mcMd/configIos/MdConfigIo.h>
12 #include <mcMd/mcSimulation/McSystem.h>
13 #include <mcMd/neighbor/PairIterator.h>
14 #include <mcMd/neighbor/CellList.h>
15 #include <mcMd/mdIntegrators/MdIntegratorFactory.h>
16 #include <mcMd/generators/Generator.h>
17 #include <mcMd/generators/generatorFactory.h>
18 #include <mcMd/potentials/pair/MdPairPotential.h>
19 #include <mcMd/potentials/pair/PairFactory.h>
20 #include <mcMd/simulation/stress.h>
21 
22 #ifdef SIMP_BOND
23 #include <mcMd/potentials/bond/BondPotential.h>
24 #include <mcMd/potentials/bond/BondFactory.h>
25 #endif
26 #ifdef SIMP_ANGLE
27 #include <mcMd/potentials/angle/AnglePotential.h>
28 #include <mcMd/potentials/angle/AngleFactory.h>
29 #endif
30 #ifdef SIMP_DIHEDRAL
31 #include <mcMd/potentials/dihedral/DihedralPotential.h>
32 #endif
33 #ifdef SIMP_COULOMB
34 #include <mcMd/potentials/coulomb/MdCoulombPotential.h>
35 #include <mcMd/potentials/coulomb/CoulombFactory.h>
36 #endif
37 #ifdef SIMP_EXTERNAL
38 #include <mcMd/potentials/external/ExternalPotential.h>
39 #endif
40 #ifdef SIMP_SPECIAL
41 #include <mcMd/potentials/special/SpecialPotential.h>
42 #include <mcMd/potentials/special/SpecialFactory.h>
43 #endif
44 #ifdef MCMD_LINK
45 #include <mcMd/links/LinkMaster.h>
46 #endif
47 #ifdef SIMP_TETHER
48 #include <mcMd/potentials/tether/TetherPotential.h>
49 #include <mcMd/tethers/TetherMaster.h>
50 #endif
51 
52 #include <simp/ensembles/BoundaryEnsemble.h>
53 #include <simp/ensembles/EnergyEnsemble.h>
54 
55 #include <util/param/Factory.h>
56 #include <util/space/Vector.h>
57 #include <util/space/Dimension.h>
58 
59 #include <util/space/Tensor.h>
60 #include <util/accumulators/setToZero.h>
61 
62 #include <fstream>
63 
64 namespace McMd
65 {
66 
67  using namespace Util;
68  using namespace Simp;
69 
70  /*
71  * Default constructor.
72  */
74  : System(),
75  #ifndef SIMP_NOPAIR
76  pairPotentialPtr_(0),
77  #endif
78  #ifdef SIMP_BOND
79  bondPotentialPtr_(0),
80  #endif
81  #ifdef SIMP_ANGLE
82  anglePotentialPtr_(0),
83  #endif
84  #ifdef SIMP_DIHEDRAL
85  dihedralPotentialPtr_(0),
86  #endif
87  #ifdef SIMP_COULOMB
88  coulombPotentialPtr_(0),
89  #endif
90  #ifdef SIMP_EXTERNAL
91  externalPotentialPtr_(0),
92  #endif
93  #ifdef SIMP_SPECIAL
94  specialPotentialPtr_(0),
95  #endif
96  #ifdef MCMD_LINK
97  linkPotentialPtr_(0),
98  #endif
99  #ifdef SIMP_TETHER
100  tetherPotentialPtr_(0),
101  #endif
102  mdIntegratorPtr_(0),
103  mdIntegratorFactoryPtr_(0),
104  createdMdIntegratorFactory_(false)
105  {
106  setClassName("MdSystem");
107 
108  // Set actions taken when particles are moved
111  }
112 
113  /*
114  * Constructor, copy of an McSystem.
115  */
117  : System(system),
118  #ifndef SIMP_NOPAIR
119  pairPotentialPtr_(0),
120  #endif
121  #ifdef SIMP_BOND
122  bondPotentialPtr_(0),
123  #endif
124  #ifdef SIMP_ANGLE
125  anglePotentialPtr_(0),
126  #endif
127  #ifdef SIMP_DIHEDRAL
128  dihedralPotentialPtr_(0),
129  #endif
130  #ifdef SIMP_COULOMB
131  coulombPotentialPtr_(0),
132  #endif
133  #ifdef SIMP_EXTERNAL
134  externalPotentialPtr_(0),
135  #endif
136  #ifdef SIMP_SPECIAL
137  specialPotentialPtr_(0),
138  #endif
139  #ifdef MCMD_LINK
140  linkPotentialPtr_(0),
141  #endif
142  #ifdef SIMP_TETHER
143  tetherPotentialPtr_(0),
144  #endif
145  mdIntegratorPtr_(0),
146  mdIntegratorFactoryPtr_(0),
147  createdMdIntegratorFactory_(false)
148  {
149  setClassName("MdSystem");
150 
151  #ifndef SIMP_NOPAIR
152  /*
153  * Create an MdPairPotential that is a clone of the McPairPotential
154  * of the parent McSystem. The resulting MdPairPotential is an
155  * instance of MdPairPotentialImpl<Interaction> that has a pointer
156  * to the pair Interaction object owned by the parent McSystem,
157  * which it uses to compute pair forces and energies.
158  */
159  assert(pairPotentialPtr_ == 0);
160  pairPotentialPtr_ = pairFactory().mdFactory(system.pairPotential());
161  if (pairPotentialPtr_ == 0) {
162  UTIL_THROW("Failed attempt to clone McPairPotential");
163  }
164  #endif
165 
166  // Set pointers to non-pair potentials to point to the same potential
167  // objects as those used by the parent McSystem.
168 
169  #ifdef SIMP_BOND
170  assert(bondPotentialPtr_ == 0);
171  if (system.hasBondPotential()) {
172  bondPotentialPtr_ = &system.bondPotential();
173  }
174  #endif
175  #ifdef SIMP_ANGLE
176  assert(anglePotentialPtr_ == 0);
177  if (system.hasAnglePotential()) {
178  anglePotentialPtr_ = &system.anglePotential();
179  }
180  #endif
181  #ifdef SIMP_DIHEDRAL
182  assert(dihedralPotentialPtr_ == 0);
183  if (system.hasDihedralPotential()) {
184  dihedralPotentialPtr_ = &system.dihedralPotential();
185  }
186  #endif
187  #ifdef SIMP_COULOMB
188  #if 0
189  assert(coulombPotentialPtr_ == 0);
190  if (system.hasCoulombPotential()) {
191  coulombPotentialPtr_ = &system.coulombPotential();
192  }
193  #endif
194  #endif
195  #ifdef SIMP_EXTERNAL
196  if (system.hasExternalPotential()) {
197  externalPotentialPtr_ = &system.externalPotential();
198  }
199  #endif
200  // #ifdef SIMP_SPECIAL
201  // if (system.hasSpecialPotential()) {
202  // specialPotentialPtr_ = &system.specialPotential();
203  // }
204  // #endif
205  #ifdef MCMD_LINK
206  if (system.hasLinkPotential()) {
207  linkPotentialPtr_ = &system.linkPotential();
208  }
209  #endif
210  #ifdef SIMP_TETHER
211  if (system.hasTetherPotential()) {
212  tetherPotentialPtr_ = &system.tetherPotential();
213  }
214  #endif
215 
216  // Register actions taken when particles are moved
219  }
220 
221  /*
222  * Destructor.
223  */
225  {
226  #ifndef SIMP_NOPAIR
227  if (pairPotentialPtr_) delete pairPotentialPtr_;
228  #endif
229  #ifdef SIMP_BOND
230  if (!isCopy() && bondPotentialPtr_) delete bondPotentialPtr_;
231  #endif
232  #ifdef SIMP_ANGLE
233  if (!isCopy() && anglePotentialPtr_) delete anglePotentialPtr_;
234  #endif
235  #ifdef SIMP_DIHEDRAL
236  if (!isCopy() && dihedralPotentialPtr_) delete dihedralPotentialPtr_;
237  #endif
238  #ifdef SIMP_COULOMB
239  if (!isCopy() && coulombPotentialPtr_) delete coulombPotentialPtr_;
240  #endif
241  #ifdef SIMP_EXTERNAL
242  if (!isCopy() && externalPotentialPtr_) delete externalPotentialPtr_;
243  #endif
244  #ifdef SIMP_SPECIAL
245  if (!isCopy() && specialPotentialPtr_) delete specialPotentialPtr_;
246  #endif
247  #ifdef MCMD_LINK
248  if (!isCopy() && linkPotentialPtr_) delete linkPotentialPtr_;
249  #endif
250  #ifdef SIMP_TETHER
251  if (!isCopy() && tetherPotentialPtr_) delete tetherPotentialPtr_;
252  #endif
253 
254  if (mdIntegratorFactoryPtr_ && createdMdIntegratorFactory_) {
255  delete mdIntegratorFactoryPtr_;
256  }
257  if (mdIntegratorPtr_) {
258  delete mdIntegratorPtr_;
259  }
260  }
261 
262  /*
263  * Get the MdIntegrator factory
264  */
266  {
267  if (mdIntegratorFactoryPtr_ == 0) {
268  mdIntegratorFactoryPtr_ = new MdIntegratorFactory(*this);
269  createdMdIntegratorFactory_ = true;
270  }
271  return *mdIntegratorFactoryPtr_;
272  }
273 
274  /*
275  * Read parameter and configuration files, initialize system.
276  */
277  void MdSystem::readParameters(std::istream &in)
278  {
279 
280  if (!isCopy()) {
282  readFileMaster(in);
284  }
285 
286  #ifdef SIMP_COULOMB
287  if (!isCopy()) {
288  assert(coulombPotentialPtr_ == 0);
289  if (simulation().hasCoulomb()) {
290  coulombPotentialPtr_ =
292  if (coulombPotentialPtr_ == 0) {
293  UTIL_THROW("Failed attempt to create CoulombPotential");
294  }
295  readParamComposite(in, *coulombPotentialPtr_);
296  }
297  }
298  #endif
299 
300  #ifndef SIMP_NOPAIR
301  if (!isCopy()) {
302  assert(pairPotentialPtr_ == 0);
303  pairPotentialPtr_ = pairFactory().mdFactory(pairStyle(), *this);
304  if (pairPotentialPtr_ == 0) {
305  UTIL_THROW("Failed attempt to create PairPotential");
306  }
307  }
308  readParamComposite(in, *pairPotentialPtr_);
309  #endif
310 
311  if (!isCopy()) {
312 
313  #ifdef SIMP_BOND
314  assert(bondPotentialPtr_ == 0);
315  if (simulation().nBondType() > 0) {
316  bondPotentialPtr_ = bondFactory().factory(bondStyle());
317  if (bondPotentialPtr_ == 0) {
318  UTIL_THROW("Failed attempt to create bondPotential");
319  }
320  readParamComposite(in, *bondPotentialPtr_);
321  }
322  #endif
323 
324  #ifdef SIMP_ANGLE
325  assert(anglePotentialPtr_ == 0);
326  if (simulation().nAngleType() > 0) {
327  anglePotentialPtr_ =
329  if (anglePotentialPtr_ == 0) {
330  UTIL_THROW("Failed attempt to create anglePotential");
331  }
332  readParamComposite(in, *anglePotentialPtr_);
333  }
334  #endif
335 
336  #ifdef SIMP_DIHEDRAL
337  assert(dihedralPotentialPtr_ == 0);
338  if (simulation().nDihedralType() > 0) {
339  dihedralPotentialPtr_ =
341  if (dihedralPotentialPtr_ == 0) {
342  UTIL_THROW("Failed attempt to create dihedralPotential");
343  }
344  readParamComposite(in, *dihedralPotentialPtr_);
345  }
346  #endif
347 
348  #ifdef SIMP_EXTERNAL
349  assert(externalPotentialPtr_ == 0);
350  if (simulation().hasExternal() > 0) {
351  externalPotentialPtr_ =
353  if (externalPotentialPtr_ == 0) {
354  UTIL_THROW("Failed attempt to create externalPotential");
355  }
356  readParamComposite(in, *externalPotentialPtr_);
357  }
358  #endif
359 
360  #ifdef SIMP_SPECIAL
361  assert(specialPotentialPtr_ == 0);
362  if (simulation().hasSpecial() > 0) {
363  specialPotentialPtr_ =
364  specialFactory().mdFactory(specialStyle(), *this);
365  if (specialPotentialPtr_ == 0) {
366  UTIL_THROW("Failed attempt to create specialPotential");
367  }
368  readParamComposite(in, *specialPotentialPtr_);
369  }
370  #endif
371 
372  #ifdef MCMD_LINK
373  assert(linkPotentialPtr_ == 0);
374  if (simulation().nLinkType() > 0) {
375  readLinkMaster(in);
376  linkPotentialPtr_ = linkFactory().factory(linkStyle());
377  if (linkPotentialPtr_ == 0) {
378  UTIL_THROW("Failed attempt to create linkPotential");
379  }
380  readParamComposite(in, *linkPotentialPtr_);
381  }
382  #endif
383 
384  #ifdef SIMP_TETHER
385  if (simulation().hasTether() > 0) {
386  readTetherMaster(in);
387  tetherPotentialPtr_ =
388  tetherFactory().factory(tetherStyle(), *this);
389  if (tetherPotentialPtr_ == 0) {
390  UTIL_THROW("Failed attempt to create tetherPotential");
391  }
392  readParamComposite(in, *tetherPotentialPtr_);
393  }
394  #endif
395 
396  // Read EnergyEnsemble and BoundaryEnsemble
397  readEnsembles(in);
398  }
399 
400  // Check for MdIntegratorFactory, create default if necessary.
401  if (mdIntegratorFactoryPtr_ == 0) {
402  mdIntegratorFactoryPtr_ = new MdIntegratorFactory(*this);
403  createdMdIntegratorFactory_ = true;
404  }
405  assert(mdIntegratorFactoryPtr_);
406  assert(mdIntegratorPtr_ == 0);
407 
408  // Read polymorphic MdIntegrator
409  std::string className;
410  bool isEnd;
411  mdIntegratorPtr_ =
412  mdIntegratorFactoryPtr_->readObject(in, *this, className, isEnd);
413  if (!mdIntegratorPtr_) {
414  std::string msg("Unknown MdIntegrator subclass name: ");
415  msg += className;
416  UTIL_THROW(msg.c_str());
417  }
418 
419  #ifdef MCMD_PERTURB
420  if (!isCopy()) {
421  // Read Perturbation object for free energy perturbation, if any.
422  readPerturbation(in);
423  }
424  #endif
425  }
426 
427  /*
428  * Load parameter and configuration files, initialize system.
429  */
431  {
432  if (!isCopy()) {
434  loadFileMaster(ar);
436  }
437 
438  #ifdef SIMP_COULOMB
439  if (!isCopy()) {
440  assert(coulombPotentialPtr_ == 0);
441  if (simulation().hasCoulomb() > 0) {
442  coulombPotentialPtr_ =
444  if (coulombPotentialPtr_ == 0) {
445  UTIL_THROW("Failed attempt to create CoulombPotential");
446  }
447  loadParamComposite(ar, *coulombPotentialPtr_);
448  }
449  }
450  #endif
451 
452  #ifndef SIMP_NOPAIR
453  if (!isCopy()) {
454  assert(pairPotentialPtr_ == 0);
455  pairPotentialPtr_ = pairFactory().mdFactory(pairStyle(), *this);
456  if (pairPotentialPtr_ == 0) {
457  UTIL_THROW("Failed attempt to create PairPotential");
458  }
459  }
460  loadParamComposite(ar, *pairPotentialPtr_);
461  #endif
462 
463  if (!isCopy()) {
464 
465  #ifdef SIMP_BOND
466  assert(bondPotentialPtr_ == 0);
467  if (simulation().nBondType() > 0) {
468  bondPotentialPtr_ = bondFactory().factory(bondStyle());
469  if (bondPotentialPtr_ == 0) {
470  UTIL_THROW("Failed attempt to create bondPotential");
471  }
472  loadParamComposite(ar, *bondPotentialPtr_);
473  }
474  #endif
475 
476  #ifdef SIMP_ANGLE
477  assert(anglePotentialPtr_ == 0);
478  if (simulation().nAngleType() > 0) {
479  anglePotentialPtr_ =
481  if (anglePotentialPtr_ == 0) {
482  UTIL_THROW("Failed attempt to create anglePotential");
483  }
484  loadParamComposite(ar, *anglePotentialPtr_);
485  }
486  #endif
487 
488  #ifdef SIMP_DIHEDRAL
489  assert(dihedralPotentialPtr_ == 0);
490  if (simulation().nDihedralType() > 0) {
491  dihedralPotentialPtr_ =
493  if (dihedralPotentialPtr_ == 0) {
494  UTIL_THROW("Failed attempt to create dihedralPotential");
495  }
496  loadParamComposite(ar, *dihedralPotentialPtr_);
497  }
498  #endif
499 
500  #ifdef SIMP_EXTERNAL
501  assert(externalPotentialPtr_ == 0);
502  if (simulation().hasExternal() > 0) {
503  externalPotentialPtr_ =
505  if (externalPotentialPtr_ == 0) {
506  UTIL_THROW("Failed attempt to create externalPotential");
507  }
508  loadParamComposite(ar, *externalPotentialPtr_);
509  }
510  #endif
511 
512  #ifdef SIMP_SPECIAL
513  assert(specialPotentialPtr_ == 0);
514  if (simulation().hasSpecial() > 0) {
515  specialPotentialPtr_ =
516  specialFactory().mdFactory(specialStyle(), *this);
517  if (specialPotentialPtr_ == 0) {
518  UTIL_THROW("Failed attempt to create specialPotential");
519  }
520  loadParamComposite(ar, *specialPotentialPtr_);
521  }
522  #endif
523 
524  #ifdef MCMD_LINK
525  assert(linkPotentialPtr_ == 0);
526  if (simulation().nLinkType() > 0) {
527  loadLinkMaster(ar);
528  linkPotentialPtr_ = linkFactory().factory(linkStyle());
529  if (linkPotentialPtr_ == 0) {
530  UTIL_THROW("Failed attempt to create linkPotential");
531  }
532  loadParamComposite(ar, *linkPotentialPtr_);
533  }
534  #endif
535 
536  #ifdef SIMP_TETHER
537  assert(tetherPotentialPtr_ == 0);
538  if (simulation().hasTether() > 0) {
539  loadTetherMaster(ar);
540  tetherPotentialPtr_ =
541  tetherFactory().factory(tetherStyle(), *this);
542  if (tetherPotentialPtr_ == 0) {
543  UTIL_THROW("Failed attempt to create tetherPotential");
544  }
545  loadParamComposite(ar, *tetherPotentialPtr_);
546  }
547  #endif
548 
549  // Read EnergyEnsemble and BoundaryEnsemble
550  loadEnsembles(ar);
551  }
552 
553  // Check for MdIntegratorFactory, create default if necessary.
554  if (mdIntegratorFactoryPtr_ == 0) {
555  mdIntegratorFactoryPtr_ = new MdIntegratorFactory(*this);
556  createdMdIntegratorFactory_ = true;
557  }
558  assert(mdIntegratorFactoryPtr_);
559  assert(mdIntegratorPtr_ == 0);
560 
561  // Read polymorphic MdIntegrator
562  std::string className;
563  mdIntegratorPtr_ =
564  mdIntegratorFactoryPtr_->loadObject(ar, *this, className);
565  if (!mdIntegratorPtr_) {
566  std::string msg("Unknown MdIntegrator subclass name: ");
567  msg += className;
568  UTIL_THROW(msg.c_str());
569  }
570 
571  #ifdef MCMD_PERTURB
572  if (!isCopy()) {
573  // Read Perturbation object if any
574  loadPerturbation(ar);
575  }
576  #endif
577  }
578 
579  /*
580  * Save state, excluding configuration.
581  */
583  {
584  if (!isCopy()) {
585  saveFileMaster(ar);
587  }
588 
589  #ifdef SIMP_COULOMB
590  if (!isCopy()) {
591  if (simulation().hasCoulomb()) {
592  coulombPotentialPtr_->save(ar);
593  }
594  }
595  #endif
596 
597  #ifndef SIMP_NOPAIR
598  pairPotential().save(ar);
599  #endif
600 
601  if (!isCopy()) {
602  #ifdef SIMP_BOND
603  if (simulation().nBondType() > 0) {
604  bondPotential().save(ar);
605  }
606  #endif
607  #ifdef SIMP_ANGLE
608  if (simulation().nAngleType() > 0) {
609  anglePotential().save(ar);
610  }
611  #endif
612  #ifdef SIMP_DIHEDRAL
613  if (simulation().nDihedralType() > 0) {
614  dihedralPotential().save(ar);
615  }
616  #endif
617  #ifdef MCMD_LINK
618  if (simulation().nLinkType() > 0) {
619  saveLinkMaster(ar);
620  linkPotential().save(ar);
621  }
622  #endif
623  #ifdef SIMP_EXTERNAL
624  if (simulation().hasExternal()) {
625  externalPotential().save(ar);
626  }
627  #endif
628  #ifdef SIMP_SPECIAL
629  if (simulation().hasSpecial()) {
630  specialPotential().save(ar);
631  }
632  #endif
633  #ifdef SIMP_TETHER
634  if (simulation().hasTether()) {
635  saveTetherMaster(ar);
636  tetherPotentialPtr_->save(ar);
637  }
638  #endif
639  saveEnsembles(ar);
640  }
641  std::string className = mdIntegratorPtr_->className();
642  ar & className;
643  mdIntegratorPtr_->save(ar);
644 
645  #ifdef MCMD_PERTURB
646  if (!isCopy()) {
647  savePerturbation(ar);
648  }
649  #endif
650  }
651 
652  /*
653  * Read configuration from a specific input stream.
654  */
655  void MdSystem::readConfig(std::istream &in)
656  {
657  System::readConfig(in);
658 
659  #ifndef SIMP_NOPAIR
662  #endif
663  #ifdef SIMP_COULOMB
664  if (hasCoulombPotential()) {
666  Log::file() << "Initial coulombPotential nWave = "
667  << coulombPotential().nWave() << std::endl;
668  }
669  #endif
670  calculateForces();
671  }
672 
673  /*
674  * Load a System configuration from an archive.
675  */
677  {
678  System::loadConfig(ar);
679  #ifndef SIMP_NOPAIR
682  #endif
683  #ifdef SIMP_COULOMB
684  if (hasCoulombPotential()) {
686  }
687  #endif
688  calculateForces();
689  }
690 
691 
692  /*
693  * Generate molecules for all species.
694  */
696  Array<int> const & capacities,
697  Array<double> const & diameters)
698  {
699 
700  // Setup a local cell list
701  CellList cellList;
702  Generator::setupCellList(simulation().atomCapacity(),
703  boundary(), diameters, cellList);
704 
705  // Generate molecules for each species
706  Generator* ptr = 0;
707  int nSpecies = simulation().nSpecies();
708  bool success = false;
709  for (int iSpecies = 0; iSpecies < nSpecies; ++iSpecies) {
710  if (capacities[iSpecies] > 0) {
711  ptr = generatorFactory(simulation().species(iSpecies), *this);
712  UTIL_CHECK(ptr);
713  success = ptr->generate(capacities[iSpecies],
714  diameters, cellList);
715  delete ptr;
716  if (!success) {
717  Log::file() << "Failed to complete species "
718  << iSpecies << "\n";
719  }
720  UTIL_CHECK(success);
721  }
722  }
723 
724  #ifndef SIMP_NOPAIR
727  #endif
728  #ifdef UTIL_DEBUG
729  isValid();
730  #endif
731 
732  #ifdef SIMP_COULOMB
733  if (hasCoulombPotential()) {
735  }
736  #endif
737  calculateForces();
738  }
739 
740  /*
741  * Shift all atoms into primary unit cell.
742  */
744  {
745  MoleculeIterator molIter;
746  Molecule::AtomIterator atomIter;
747  for (int iSpec=0; iSpec < simulation().nSpecies(); ++iSpec) {
748  for (begin(iSpec, molIter); molIter.notEnd(); ++molIter) {
749  molIter->begin(atomIter);
750  for ( ; atomIter.notEnd(); ++atomIter) {
751  #ifdef MCMD_SHIFT
752  boundary().shift(atomIter->position(), atomIter->shift());
753  #else
754  boundary().shift(atomIter->position());
755  #endif
756  }
757  }
758  }
759  }
760 
761  /*
762  * Set force vectors to zero for all atoms in this System.
763  */
765  {
766  MoleculeIterator molIter;
767  Molecule::AtomIterator atomIter;
768  for (int iSpec=0; iSpec < simulation().nSpecies(); ++iSpec) {
769  for (begin(iSpec, molIter); molIter.notEnd(); ++molIter) {
770  for (molIter->begin(atomIter); atomIter.notEnd(); ++atomIter) {
771  atomIter->force().zero();
772  }
773  }
774  }
775  }
776 
777  /*
778  * Set velocity vectors to zero for all atoms in this System.
779  */
781  {
782  MoleculeIterator molIter;
783  Molecule::AtomIterator atomIter;
784  for (int iSpec=0; iSpec < simulation().nSpecies(); ++iSpec) {
785  for (begin(iSpec, molIter); molIter.notEnd(); ++molIter) {
786  for (molIter->begin(atomIter); atomIter.notEnd(); ++atomIter) {
787  atomIter->velocity().zero();
788  }
789  }
790  }
791 
792  }
793 
794  /*
795  * Set velocities to Boltzmannian random values, for all atoms in System.
796  */
797  void MdSystem::setBoltzmannVelocities(double temperature)
798  {
799  Simulation& sim = simulation();
800  Random &random = sim.random();
801  double scale;
802  double mass;
803  MoleculeIterator molIter;
804  int nSpec = sim.nSpecies();
805  int iSpec, j;
806 
807  Molecule::AtomIterator atomIter;
808  for (iSpec = 0; iSpec < nSpec; ++iSpec) {
809  for (begin(iSpec, molIter); molIter.notEnd(); ++molIter) {
810  for (molIter->begin(atomIter); atomIter.notEnd(); ++atomIter) {
811  mass = sim.atomType(atomIter->typeId()).mass();
812  scale = sqrt(temperature/mass);
813  for (j = 0; j < Dimension; ++j) {
814  atomIter->velocity()[j] = scale*random.gaussian();
815  }
816  }
817  }
818  }
819 
820  }
821 
822  /*
823  * Subtract average velocity from all atomic velocities.
824  */
826  {
827  Vector average(0.0);
828  MoleculeIterator molIter;
829  Molecule::AtomIterator atomIter;
830  int nSpec = simulation().nSpecies();
831  int nAtom = 0;
832  int iSpec;
833 
834  for (iSpec = 0; iSpec < nSpec; ++iSpec) {
835  for (begin(iSpec, molIter); molIter.notEnd(); ++molIter) {
836  for (molIter->begin(atomIter); atomIter.notEnd(); ++atomIter) {
837  average += atomIter->velocity();
838  ++nAtom;
839  }
840  }
841  }
842  average /= double(nAtom);
843  for (iSpec = 0; iSpec < nSpec; ++iSpec) {
844  for (begin(iSpec, molIter); molIter.notEnd(); ++molIter) {
845  for (molIter->begin(atomIter); atomIter.notEnd(); ++atomIter) {
846  atomIter->velocity() -= average;
847  }
848  }
849  }
850 
851  return average;
852  }
853 
854  /*
855  * Calculate all forces.
856  */
858  {
859  setZeroForces();
860  #ifndef SIMP_NOPAIR
861  // This method builds pair list if needed, and shifts atoms if
862  // it builds the pair list.
864  #endif
865  #ifdef SIMP_BOND
866  if (hasBondPotential()) {
868  }
869  #endif
870  #ifdef SIMP_ANGLE
871  if (hasAnglePotential()) {
873  }
874  #endif
875  #ifdef SIMP_DIHEDRAL
876  if (hasDihedralPotential()) {
878  }
879  #endif
880  #ifdef SIMP_COULOMB
881  if (hasCoulombPotential()) {
883  }
884  #endif
885  #ifdef SIMP_EXTERNAL
886  if (hasExternalPotential()) {
888  }
889  #endif
890  #ifdef SIMP_SPECIAL
891  if (hasSpecialPotential()) {
892  specialPotential().addForces();
893  }
894  #endif
895  #ifdef MCMD_LINK
896  if (hasLinkPotential()) {
898  }
899  #endif
900  #ifdef SIMP_TETHER
901  if (tetherPotentialPtr_) {
902  tetherPotential().addForces();
903  }
904  #endif
905  }
906 
907  /*
908  * Calculate and return total potential energy.
909  */
911  {
912  double energy = 0.0;
913  #ifndef SIMP_NOPAIR
914  // In charged system, this only returns non-Coulombic pair energy.
915  energy += pairPotential().energy();
916  #endif
917  #ifdef SIMP_BOND
918  if (hasBondPotential()) {
919  energy += bondPotential().energy();
920  }
921  #endif
922  #ifdef SIMP_ANGLE
923  if (hasAnglePotential()) {
924  energy += anglePotential().energy();
925  }
926  #endif
927  #ifdef SIMP_DIHEDRAL
928  if (hasDihedralPotential()) {
929  energy += dihedralPotential().energy();
930  }
931  #endif
932  #ifdef SIMP_COULOMB
933  if (hasCoulombPotential()) {
934  energy += coulombPotential().energy();
935  }
936  #endif
937  #ifdef SIMP_EXTERNAL
938  if (hasExternalPotential()) {
939  energy += externalPotential().energy();
940  }
941  #endif
942  #ifdef SIMP_SPECIAL
943  if (hasSpecialPotential()) {
944  energy += specialPotential().energy();
945  }
946  #endif
947  #ifdef MCMD_LINK
948  if (hasLinkPotential()) {
949  energy += linkPotential().energy();
950  }
951  #endif
952  #ifdef SIMP_TETHER
953  if (tetherPotentialPtr_) {
954  energy += tetherPotential().energy();
955  }
956  #endif
957  return energy;
958  }
959 
960  /*
961  * Unset precomputed potential energy components.
962  */
964  {
965  #ifndef SIMP_NOPAIR
967  #endif
968  #ifdef SIMP_BOND
969  if (hasBondPotential()) {
971  }
972  #endif
973  #ifdef SIMP_ANGLE
974  if (hasAnglePotential()) {
976  }
977  #endif
978  #ifdef SIMP_DIHEDRAL
979  if (hasDihedralPotential()) {
981  }
982  #endif
983  #ifdef SIMP_COULOMB
984  if (hasCoulombPotential()) {
986  }
987  #endif
988  #ifdef SIMP_EXTERNAL
989  if (hasExternalPotential()) {
991  }
992  #endif
993  #ifdef SIMP_SPECIAL
994  if (hasSpecialPotential()) {
995  specialPotential().unsetEnergy();
996  }
997  #endif
998  }
999 
1000  /*
1001  * Return total kinetic energy.
1002  */
1004  {
1005  const Simulation& sim = simulation();
1006  double KE, mass;
1007  ConstMoleculeIterator molIter;
1008  Molecule::ConstAtomIterator atomIter;
1009  int iSpec, typeId;
1010 
1011  KE = 0.0;
1012  for (iSpec=0; iSpec < sim.nSpecies(); ++iSpec) {
1013  for (begin(iSpec, molIter); molIter.notEnd(); ++molIter) {
1014  for (molIter->begin(atomIter); atomIter.notEnd(); ++atomIter) {
1015  typeId = atomIter->typeId();
1016  mass = sim.atomType(typeId).mass();
1017  KE += atomIter->velocity().square()*mass;
1018  }
1019  }
1020  }
1021 
1022  return 0.5*KE;
1023  }
1024 
1025  // Kinetic Stress
1026 
1027  /*
1028  * Compute the kinetic (velocity) stress.
1029  */
1030  template <typename T>
1031  void MdSystem::computeKineticStressImpl(T& stress) const
1032  {
1033  Vector p;
1034  double mass;
1035  ConstMoleculeIterator molIter;
1036  Molecule::ConstAtomIterator atomIter;
1037  const Vector* vPtr;
1038  const Simulation& sim = simulation();
1039 
1040  setToZero(stress);
1041  for (int iSpec=0; iSpec < sim.nSpecies(); ++iSpec) {
1042  for (begin(iSpec, molIter); molIter.notEnd(); ++molIter) {
1043  for (molIter->begin(atomIter); atomIter.notEnd(); ++atomIter) {
1044  vPtr = &atomIter->velocity();
1045  mass = sim.atomType(atomIter->typeId()).mass();
1046  p.multiply(*vPtr, mass);
1047  incrementPairStress(*vPtr, p, stress);
1048  }
1049  }
1050  }
1051  stress /= boundary().volume();
1052  normalizeStress(stress);
1053  }
1054 
1055  template <>
1056  void MdSystem::computeKineticStress<double>(double& stress) const
1057  { computeKineticStressImpl(stress); }
1058 
1059  template <>
1060  void MdSystem::computeKineticStress<Util::Vector>(Util::Vector& stress) const
1061  { computeKineticStressImpl(stress); }
1062 
1063  template <>
1064  void MdSystem::computeKineticStress<Util::Tensor>(Util::Tensor& stress) const
1065  { computeKineticStressImpl(stress); }
1066 
1067  // Virial Stress
1068 
1069  template <typename T>
1070  void MdSystem::computeVirialStressImpl(T& stress) const
1071  {
1072  setToZero(stress);
1073  T dStress;
1074 
1075  #ifndef SIMP_NOPAIR
1076  pairPotential().computeStress(dStress);
1077  stress += dStress;
1078  #endif
1079  #ifdef SIMP_BOND
1080  if (hasBondPotential()) {
1081  bondPotential().computeStress(dStress);
1082  stress += dStress;
1083  }
1084  #endif
1085  #ifdef SIMP_ANGLE
1086  if (hasAnglePotential()) {
1087  anglePotential().computeStress(dStress);
1088  stress += dStress;
1089  }
1090  #endif
1091  #ifdef SIMP_DIHEDRAL
1092  if (hasDihedralPotential()) {
1093  dihedralPotential().computeStress(dStress);
1094  stress += dStress;
1095  }
1096  #endif
1097  #ifdef SIMP_COULOMB
1098  if (hasCoulombPotential()) {
1099  coulombPotential().computeStress(dStress);
1100  stress += dStress;
1101  }
1102  #endif
1103  #ifdef SIMP_SPECIAL
1104  if (hasSpecialPotential()) {
1105  if (specialPotential().createsStress()) {
1106  specialPotential().computeStress(dStress);
1107  stress += dStress;
1108  }
1109  }
1110  #endif
1111  #ifdef MCMD_LINK
1112  if (hasLinkPotential()) {
1113  linkPotential().computeStress(dStress);
1114  stress += dStress;
1115  }
1116  #endif
1117 
1118  }
1119 
1120  template <>
1121  void MdSystem::computeVirialStress<double>(double& stress) const
1122  { computeVirialStressImpl(stress); }
1123 
1124  template <>
1125  void MdSystem::computeVirialStress<Util::Vector>(Util::Vector& stress)
1126  const
1127  { computeVirialStressImpl(stress); }
1128 
1129  template <>
1130  void MdSystem::computeVirialStress<Util::Tensor>(Util::Tensor& stress)
1131  const
1132  { computeVirialStressImpl(stress); }
1133 
1134  // Total Stress
1135 
1136  template <>
1137  void MdSystem::computeStress<double>(double& stress) const
1138  {
1139  computeVirialStress(stress);
1140 
1141  double kineticStress;
1142  computeKineticStress(kineticStress);
1143  stress += kineticStress;
1144  }
1145 
1146  template <>
1147  void MdSystem::computeStress<Util::Vector>(Util::Vector& stress) const
1148  {
1149  Util::Vector kineticStress;
1150  computeKineticStress(kineticStress);
1151 
1152  computeVirialStress(stress);
1153  stress += kineticStress;
1154 
1155  }
1156 
1157  template <>
1158  void MdSystem::computeStress<Util::Tensor>(Util::Tensor& stress) const
1159  {
1160  computeVirialStress(stress);
1161 
1162  Util::Tensor kineticStress;
1163  computeKineticStress(kineticStress);
1164  stress += kineticStress;
1165  }
1166 
1167  /*
1168  * Unset precomputed virial stress components.
1169  */
1171  {
1172  #ifndef SIMP_NOPAIR
1174  #endif
1175  #ifdef SIMP_BOND
1176  if (hasBondPotential()) {
1178  }
1179  #endif
1180  #ifdef SIMP_ANGLE
1181  if (hasAnglePotential()) {
1183  }
1184  #endif
1185  #ifdef SIMP_DIHEDRAL
1186  if (hasDihedralPotential()) {
1188  }
1189  #endif
1190  #ifdef SIMP_COULOMB
1191  if (hasCoulombPotential()) {
1193  }
1194  #endif
1195  #ifdef SIMP_SPECIAL
1196  if (hasSpecialPotential()) {
1197  if (specialPotential().createsStress()) {
1198  specialPotential().unsetStress();
1199  }
1200  }
1201  #endif
1202 
1203  }
1204 
1205  // Miscellaneous member functions
1206 
1207  /*
1208  * Return true if this MdSystem is valid, or an throw Exception.
1209  */
1210  bool MdSystem::isValid() const
1211  {
1212  System::isValid();
1213  #ifndef SIMP_NOPAIR
1215  #endif
1216  return true;
1217  }
1218 
1219  /*
1220  * Return a pointer to a new default ConfigIo.
1221  */
1223  { return new MdConfigIo(*this); }
1224 
1225 }
virtual void loadParameters(Serializable::IArchive &ar)
Load parameters from an archive, without configuration.
Definition: MdSystem.cpp:430
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
void computeKineticStress(T &stress) const
Compute kinetic stress mvv, arising from velocities.
const int Dimension
Dimensionality of space.
Definition: Dimension.h:19
A System for use in a Markov chain Monte Carlo simulation.
Definition: McSystem.h:52
A Vector is a Cartesian vector.
Definition: Vector.h:75
CoulombFactory & coulombFactory()
Get the associated Coulomb Factory by reference.
Definition: System.cpp:1309
DihedralPotential & dihedralPotential() const
Return DihedralPotential by reference.
Definition: MdSystem.h:571
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.
MdCoulombPotential * factory(const std::string &subclass) const
Return a pointer to a new CoulombPotential, if possible.
void calculateForces()
Compute all forces in this System.
Definition: MdSystem.cpp:857
bool hasLinkPotential() const
Does a link potential exist?.
Definition: MdSystem.h:633
void begin(int speciesId, MoleculeIterator &iterator)
Initialize an iterator for molecules of one species in this System.
Definition: System.h:1147
Factory< MdIntegrator > & mdIntegratorFactory()
Return the MdIntegrator Factory by reference.
Definition: MdSystem.cpp:265
void generateMolecules(Array< int > const &capacities, Array< double > const &diameters)
Generate molecules for all species.
Definition: MdSystem.cpp:695
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
bool isValid() const
Return true if valid, or throw Exception.
bool notEnd() const
Is the current pointer not at the end of the array?
Definition: ArrayIterator.h:83
BondPotential & bondPotential() const
Return the BondPotential by reference.
Definition: McSystem.h:405
bool hasDihedralPotential() const
Does a dihedral potential exist?.
Definition: McSystem.h:433
Signal & positionSignal()
Signal to indicate change in atomic positions.
Definition: MdSystem.h:669
double volume() const
Return unit cell volume.
void loadPerturbation(Serializable::IArchive &ar)
Load the perturbation parameter block (if any)
Definition: System.cpp:1003
Vector & multiply(const Vector &v, double s)
Multiply a vector v by a scalar s.
Definition: Vector.h:686
Vector removeDriftVelocity()
Subtract average velocity from all atomic velocities.
Definition: MdSystem.cpp:825
void shiftAtoms()
Shift all atoms into primary cell.
Definition: MdSystem.cpp:743
bool hasLinkPotential() const
Does a link potential exist?.
Definition: McSystem.h:484
Data * readObject(std::istream &in, ParamComposite &parent, std::string &className, bool &isEnd)
Read a class name, instantiate an object, and read its parameters.
Definition: Factory.h:214
void loadParamComposite(Serializable::IArchive &ar, ParamComposite &child, bool next=true)
Add and load a required child ParamComposite.
void saveLinkMaster(Serializable::OArchive &ar)
Save the LinkMaster.
Definition: System.cpp:670
bool hasAnglePotential() const
Does angle potential exist?.
Definition: McSystem.h:416
Factory< AnglePotential > & angleFactory()
Get the associated AngleFactory by reference.
Definition: System.cpp:1269
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
Forward iterator for a PArray.
virtual void computeStress()=0
Compute kspace part of Coulomb stress.
MdSystem()
Default constructor.
Definition: MdSystem.cpp:73
File containing preprocessor macros for error handling.
void readEnsembles(std::istream &in)
Read energy and boundary ensemble parameters.
Definition: System.cpp:626
void unsetVirialStress()
Unset precomputed virial stress components.
Definition: MdSystem.cpp:1170
double potentialEnergy()
Compute and return total potential energy.
Definition: MdSystem.cpp:910
Classes used by all simpatico molecular simulations.
Generator * generatorFactory(Species &species, McSystem &system)
Instantiates generator for on species in an McSystem.
bool hasBondPotential() const
Does a bond potential exist?.
Definition: MdSystem.h:531
A Tensor represents a Cartesian tensor.
Definition: Tensor.h:32
ExternalPotential & externalPotential() const
Return ExternalPotential by reference.
Definition: MdSystem.h:605
virtual void unsetEnergy()
Unset k-space energy.
virtual void addForces()=0
Add dihedral potential forces to all atomic forces.
std::string linkStyle() const
Return link potential style string.
Definition: System.cpp:1378
virtual void addForces()=0
Add external force of an Atom to the total force acting on it.
The main object in a simulation, which coordinates others.
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
bool hasExternalPotential() const
Does an external potential exist?.
Definition: MdSystem.h:599
void savePotentialStyles(Serializable::OArchive &ar)
Save potential style strings.
Definition: System.cpp:575
Forward const iterator for an Array or a C array.
Data * loadObject(Serializable::IArchive &ar, ParamComposite &parent, std::string &className)
Load a class name, instantiate an object, and load the object.
Definition: Factory.h:303
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.
MdPairPotential & pairPotential() const
Return MdPairPotential by reference.
Definition: MdSystem.h:520
PairFactory & pairFactory()
Get the PairFactory by reference.
Definition: System.cpp:1229
Default Factory for subclasses of MdIntegrator.
virtual void loadConfig(Serializable::IArchive &ar)
Load configuration.
Definition: System.cpp:706
const AtomType & atomType(int i) const
Get a single AtomType object by const reference.
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
std::string className() const
Get class name string.
Factory< BondPotential > & linkFactory()
Get the associated Link factory by reference.
Definition: System.cpp:1366
const PairList & pairList() const
Return a const reference to the internal PairList.
Simulation & simulation() const
Get the parent Simulation by reference.
Definition: System.h:1055
virtual void addForces()=0
Add angle forces to all atomic forces.
bool hasBondPotential() const
Does a bond potential exist?.
Definition: McSystem.h:399
virtual void unsetEnergy()
Mark the energy as unknown.
ExternalPotential & externalPotential() const
Return ExternalPotential by reference.
Definition: McSystem.h:473
void computeVirialStress(T &stress) const
Compute total virial stress, from all forces.
virtual void save(Serializable::OArchive &ar)
Saves all parameters to an archive.
std::string coulombStyle() const
Return coulomb potential style string.
Definition: System.cpp:1321
BondPotential & linkPotential() const
Return link potential by reference.
Definition: MdSystem.h:639
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 notEnd() const
Is the current pointer not at the end of the PArray?
Utility classes for scientific computation.
Definition: accumulators.mod:1
void setBoltzmannVelocities(double temperature)
Set all velocities to Boltzmann distributed random values.
Definition: MdSystem.cpp:797
bool hasAnglePotential() const
Does angle potential exist?.
Definition: MdSystem.h:548
AnglePotential & anglePotential() const
Return AnglePotential by reference.
Definition: MdSystem.h:554
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
CoulombPotential & coulombPotential() const
Return CoulombPotential by reference.
Definition: McSystem.h:456
double gaussian(void)
Return a Gaussian random number with zero average and unit variance.
Definition: Random.cpp:92
virtual void makeWaves()=0
Generate wavevectors and influence function for this boundary.
void shift(Vector &r) const
Shift Cartesian Vector r to its primary image.
virtual void addForces()=0
Add bond forces to all atomic forces.
bool hasCoulombPotential() const
Does a Coulomb potential exist?.
Definition: MdSystem.h:582
Forward iterator for an Array or a C array.
Definition: ArrayIterator.h:39
double kineticEnergy() const
Compute and return total kinetic energy.
Definition: MdSystem.cpp:1003
Forward iterator for a PArray.
Definition: ArraySet.h:19
void savePerturbation(Serializable::OArchive &ar)
Save the perturbation parameter block (if any)
Definition: System.cpp:1028
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
void unsetPotentialEnergy()
Unset all precomputed potential energy components.
Definition: MdSystem.cpp:963
virtual double energy(double cosTheta, int type) const =0
Returns potential energy for one angle.
virtual MdPairPotential * mdFactory(const std::string &subclass, System &system) const
Return a pointer to a new McPairPotential, if possible.
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
bool notEnd() const
Is the current pointer not at the end of the array?
bool hasDihedralPotential() const
Does a dihedral potential exist?.
Definition: MdSystem.h:565
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
virtual void addForces()=0
Add k-space Coulomb forces to forces on all atoms.
Boundary & boundary() const
Get the Boundary by reference.
Definition: System.h:1064
virtual ConfigIo * newDefaultConfigIo()
Return a pointer to a new MdConfigIo object.
Definition: MdSystem.cpp:1222
virtual int nWave() const =0
Current number of wavevectors.
BondPotential & linkPotential() const
Return the McLinkPotential by reference.
Definition: McSystem.h:493
Saving archive for binary istream.
virtual bool isValid() const
Return true if valid, or throw Exception.
Definition: MdSystem.cpp:1210
bool hasCoulombPotential() const
Does a Coulomb potential exist?.
Definition: McSystem.h:450
double mass() const
Get the mass.
virtual void loadConfig(Serializable::IArchive &ar)
Load the MdSystem configuration from an archive.
Definition: MdSystem.cpp:676
Single-processor Monte Carlo (MC) and molecular dynamics (MD).
int nSpecies() const
Get the number of Species in this Simulation.
void buildPairList()
Build the internal PairList.
bool hasExternalPotential() const
Does an external potential exist?.
Definition: McSystem.h:467
void clearPairListStatistics()
Clear all statistical accumulators stored in PairList.
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 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
virtual ~MdSystem()
Destructor.
Definition: MdSystem.cpp:224
void readPerturbation(std::istream &in)
Read the perturbation parameter block (if any)
Definition: System.cpp:980
Random number generator.
Definition: Random.h:46
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
virtual void unsetStress()
Unset k-space stress.
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
virtual void readConfig(std::istream &in)
Read system configuration from file.
Definition: MdSystem.cpp:655
ConfigIo for MD simulations (includes velocities).
Definition: MdConfigIo.h:29
bool notEnd() const
Is this not the end of the array?
Factory< DihedralPotential > & dihedralFactory()
Get the associated Dihedral Factory by reference.
Definition: System.cpp:1289
double energy()
Get total Coulomb energy.
void loadEnsembles(Serializable::IArchive &ar)
Load energy and boundary ensembles from archive.
Definition: System.cpp:636
virtual void readParameters(std::istream &in)
Read parameters from input file.
Definition: MdSystem.cpp:277
void setZeroForces()
Set all atomic forces to zero.
Definition: MdSystem.cpp:764
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
void setZeroVelocities()
Set all atomic velocities to zero.
Definition: MdSystem.cpp:780
virtual void saveParameters(Serializable::OArchive &ar)
Save parameters to an archive, without configuration.
Definition: MdSystem.cpp:582
virtual void addForces()=0
Calculate non-bonded pair forces for all atoms in this System.
System configuration file reader and writer.
BondPotential & bondPotential() const
Return BondPotential by reference.
Definition: MdSystem.h:537
MdCoulombPotential & coulombPotential() const
Return CoulombPotential by reference.
Definition: MdSystem.h:588
Random & random()
Get the random number generator by reference.
DihedralPotential & dihedralPotential() const
Return the DihedralPotential by reference.
Definition: McSystem.h:439