Simpatico  v1.10
System.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 // namespace McMd
9 #include "System.h"
10 #include "Simulation.h"
11 #include <mcMd/configIos/ConfigIo.h>
12 #include <mcMd/configIos/McConfigIo.h>
13 #include <mcMd/configIos/ConfigIoFactory.h>
14 #include <mcMd/trajectory/TrajectoryReader.h>
15 #include <mcMd/trajectory/TrajectoryReaderFactory.h>
16 #include <mcMd/species/SpeciesMutator.h>
17 
18 #ifndef SIMP_NOPAIR
19 #include <mcMd/potentials/pair/PairFactory.h>
20 #endif
21 #ifdef SIMP_BOND
22 #include <mcMd/potentials/bond/BondFactory.h>
23 #endif
24 #ifdef SIMP_ANGLE
25 #include <mcMd/potentials/angle/AngleFactory.h>
26 #endif
27 #ifdef SIMP_DIHEDRAL
28 #include <mcMd/potentials/dihedral/DihedralFactory.h>
29 #endif
30 #ifdef SIMP_COULOMB
31 #include <mcMd/potentials/coulomb/CoulombFactory.h>
32 #endif
33 #ifdef SIMP_EXTERNAL
34 #include <mcMd/potentials/external/ExternalFactory.h>
35 #endif
36 #ifdef SIMP_SPECIAL
37 #include <mcMd/potentials/special/SpecialFactory.h>
38 #endif
39 #ifdef MCMD_LINK
40 #include <mcMd/potentials/link/LinkFactory.h>
41 #include <mcMd/links/LinkMaster.h>
42 #endif
43 #ifdef SIMP_TETHER
44 #include <mcMd/potentials/tether/tetherFactory.h>
45 #include <mcMd/tethers/TetherMaster.h>
46 #endif
47 #ifdef MCMD_PERTURB
48 #include <mcMd/perturb/Perturbation.h>
49 #ifdef UTIL_MPI
50 #include <mcMd/perturb/ReplicaMove.h>
51 #endif // UTIL_MPI
52 #endif // MCMD_PERTURB
53 
54 // namespace Simp
55 #include <simp/species/Species.h>
56 #include <simp/ensembles/EnergyEnsemble.h>
57 #include <simp/ensembles/BoundaryEnsemble.h>
58 
59 // namespace Util
60 #include <util/misc/FileMaster.h>
61 #include <util/param/Factory.h>
62 #include <util/archives/Serializable_includes.h>
63 #include <util/archives/serialize.h>
64 
65 // C++ standard library
66 #include <fstream>
67 #include <string>
68 
69 namespace McMd
70 {
71 
72  using namespace Util;
73  using namespace Simp;
74 
75  /*
76  * Default constructor.
77  */
79  : moleculeSetsPtr_(0),
80  boundaryPtr_(0),
81  #ifdef MCMD_LINK
82  linkMasterPtr_(0),
83  #endif
84  #ifdef SIMP_TETHER
85  tetherMasterPtr_(0),
86  #endif
87  simulationPtr_(0),
88  energyEnsemblePtr_(0),
89  boundaryEnsemblePtr_(0),
90  #ifndef SIMP_NOPAIR
91  pairFactoryPtr_(0),
92  #endif
93  #ifdef SIMP_BOND
94  bondFactoryPtr_(0),
95  #endif
96  #ifdef SIMP_ANGLE
97  angleFactoryPtr_(0),
98  #endif
99  #ifdef SIMP_DIHEDRAL
100  dihedralFactoryPtr_(0),
101  #endif
102  #ifdef SIMP_COULOMB
103  coulombFactoryPtr_(0),
104  #endif
105  #ifdef SIMP_EXTERNAL
106  externalFactoryPtr_(0),
107  #endif
108  #ifdef SIMP_SPECIAL
109  specialFactoryPtr_(0),
110  #endif
111  #ifdef MCMD_LINK
112  linkFactoryPtr_(0),
113  #endif
114  #ifdef SIMP_TETHER
115  tetherFactoryPtr_(0),
116  #endif
117  configIoPtr_(0),
118  configIoFactoryPtr_(0),
119  trajectoryReaderFactoryPtr_(0),
120  fileMasterPtr_(0),
121  #ifdef MCMD_PERTURB
122  perturbationPtr_(0),
123  perturbationFactoryPtr_(0),
124  #ifdef UTIL_MPI
125  replicaMovePtr_(0),
126  hasReplicaMove_(false),
127  #endif // UTIL_MPI
128  #endif // MCMD_PERTURB
129  #ifndef SIMP_NOPAIR
130  pairStyle_(),
131  #endif
132  #ifdef SIMP_BOND
133  bondStyle_(),
134  #endif
135  #ifdef SIMP_ANGLE
136  angleStyle_(),
137  #endif
138  #ifdef SIMP_DIHEDRAL
139  dihedralStyle_(),
140  #endif
141  #ifdef SIMP_COULOMB
142  coulombStyle_(),
143  #endif
144  #ifdef SIMP_EXTERNAL
145  externalStyle_(),
146  #endif
147  #ifdef SIMP_SPECIAL
148  specialStyle_(),
149  #endif
150  #ifdef MCMD_LINK
151  linkStyle_(),
152  #endif
153  #ifdef SIMP_TETHER
154  tetherStyle_(),
155  #endif
156  id_(0),
157  isCopy_(false),
158  createdFileMaster_(false)
159  #ifdef MCMD_PERTURB
160  , expectPerturbationParam_(false)
161  , createdPerturbation_(false)
162  , createdPerturbationFactory_(false)
163  #ifdef UTIL_MPI
164  , createdReplicaMove_(false)
165  #endif // UTIL_MPI
166  #endif // MCMD_PERTURB
167  {
168  moleculeSetsPtr_ = new DArray<MoleculeSet>;
169  boundaryPtr_ = new Boundary;
170  energyEnsemblePtr_ = new EnergyEnsemble;
171  boundaryEnsemblePtr_ = new BoundaryEnsemble;
172  }
173 
174  /*
175  * Copy constructor.
176  */
177  System::System(const System& other)
178  : ParamComposite(other),
179  moleculeSetsPtr_(other.moleculeSetsPtr_),
180  boundaryPtr_(other.boundaryPtr_),
181  #ifdef MCMD_LINK
182  linkMasterPtr_(other.linkMasterPtr_),
183  #endif
184  #ifdef SIMP_TETHER
185  tetherMasterPtr_(other.tetherMasterPtr_),
186  #endif
187  simulationPtr_(other.simulationPtr_),
188  energyEnsemblePtr_(other.energyEnsemblePtr_),
189  boundaryEnsemblePtr_(other.boundaryEnsemblePtr_),
190  #ifndef SIMP_NOPAIR
191  pairFactoryPtr_(other.pairFactoryPtr_),
192  #endif
193  #ifdef SIMP_BOND
194  bondFactoryPtr_(other.bondFactoryPtr_),
195  #endif
196  #ifdef SIMP_ANGLE
197  angleFactoryPtr_(other.angleFactoryPtr_),
198  #endif
199  #ifdef SIMP_DIHEDRAL
200  dihedralFactoryPtr_(other.dihedralFactoryPtr_),
201  #endif
202  #ifdef SIMP_COULOMB
203  coulombFactoryPtr_(other.coulombFactoryPtr_),
204  #endif
205  #ifdef SIMP_EXTERNAL
206  externalFactoryPtr_(other.externalFactoryPtr_),
207  #endif
208  #ifdef SIMP_SPECIAL
209  specialFactoryPtr_(other.specialFactoryPtr_),
210  #endif
211  #ifdef MCMD_LINK
212  linkFactoryPtr_(other.linkFactoryPtr_),
213  #endif
214  #ifdef SIMP_TETHER
215  tetherFactoryPtr_(other.tetherFactoryPtr_),
216  #endif
217  configIoPtr_(other.configIoPtr_),
218  configIoFactoryPtr_(other.configIoFactoryPtr_),
219  trajectoryReaderFactoryPtr_(other.trajectoryReaderFactoryPtr_),
220  fileMasterPtr_(other.fileMasterPtr_),
221  #ifdef MCMD_PERTURB
222  perturbationPtr_(0),
223  perturbationFactoryPtr_(0),
224  #ifdef UTIL_MPI
225  replicaMovePtr_(0),
226  hasReplicaMove_(false),
227  #endif // ifdef UTIL_MPI
228  #endif // ifdef MCMD_PERTURB
229  #ifndef SIMP_NOPAIR
230  pairStyle_(other.pairStyle_),
231  #endif
232  #ifdef SIMP_BOND
233  bondStyle_(other.bondStyle_),
234  #endif
235  #ifdef SIMP_ANGLE
236  angleStyle_(other.angleStyle_),
237  #endif
238  #ifdef SIMP_DIHEDRAL
239  dihedralStyle_(other.dihedralStyle_),
240  #endif
241  #ifdef SIMP_COULOMB
242  coulombStyle_(other.coulombStyle_),
243  #endif
244  #ifdef SIMP_EXTERNAL
245  externalStyle_(other.externalStyle_),
246  #endif
247  #ifdef SIMP_SPECIAL
248  specialStyle_(other.specialStyle_),
249  #endif
250  #ifdef MCMD_LINK
251  linkStyle_(other.linkStyle_),
252  #endif
253  #ifdef SIMP_TETHER
254  tetherStyle_(other.tetherStyle_),
255  #endif
256  id_(other.id_),
257  isCopy_(true),
258  createdFileMaster_(false)
259  #ifdef MCMD_PERTURB
260  , expectPerturbationParam_(false)
261  , createdPerturbation_(false)
262  , createdPerturbationFactory_(false)
263  #ifdef UTIL_MPI
264  , createdReplicaMove_(false)
265  #endif // UTIL_MPI
266  #endif // MCMD_PERTURB
267  {}
268 
269  /*
270  * Destructor.
271  */
273  {
274  if (!isCopy()) {
275  if (moleculeSetsPtr_) {
276  delete moleculeSetsPtr_;
277  }
278  if (boundaryPtr_) {
279  delete boundaryPtr_;
280  }
281  #ifndef SIMP_NOPAIR
282  if (pairFactoryPtr_) {
283  delete pairFactoryPtr_;
284  }
285  #endif
286  #ifdef SIMP_BOND
287  if (bondFactoryPtr_) {
288  delete bondFactoryPtr_;
289  }
290  #endif
291  #ifdef SIMP_ANGLE
292  if (angleFactoryPtr_) {
293  delete angleFactoryPtr_;
294  }
295  #endif
296  #ifdef SIMP_DIHEDRAL
297  if (dihedralFactoryPtr_) {
298  delete dihedralFactoryPtr_;
299  }
300  #endif
301  #ifdef SIMP_COULOMB
302  if (coulombFactoryPtr_) {
303  delete coulombFactoryPtr_;
304  }
305  #endif
306  #ifdef SIMP_EXTERNAL
307  if (externalFactoryPtr_) {
308  delete externalFactoryPtr_;
309  }
310  #endif
311  #ifdef SIMP_SPECIAL
312  if (specialFactoryPtr_) {
313  delete specialFactoryPtr_;
314  }
315  #endif
316  #ifdef MCMD_LINK
317  if (linkFactoryPtr_) {
318  delete linkFactoryPtr_;
319  }
320  #endif
321  #ifdef SIMP_TETHER
322  if (tetherMasterPtr_) {
323  delete tetherMasterPtr_;
324  }
325  if (tetherFactoryPtr_) {
326  delete tetherFactoryPtr_;
327  }
328  #endif
329 
330  #ifdef MCMD_PERTURB
331  if (perturbationPtr_ && createdPerturbation_) {
332  delete perturbationPtr_;
333  }
334  if (perturbationFactoryPtr_ && createdPerturbationFactory_) {
335  delete perturbationFactoryPtr_;
336  }
337  #ifdef UTIL_MPI
338  if (replicaMovePtr_ && createdReplicaMove_) {
339  delete replicaMovePtr_;
340  }
341  #endif // UTIL_MPI
342  #endif // MCMD_PERTURB
343 
344  if (energyEnsemblePtr_) {
345  delete energyEnsemblePtr_;
346  }
347  if (boundaryEnsemblePtr_) {
348  delete boundaryEnsemblePtr_;
349  }
350  if (configIoPtr_) {
351  delete configIoPtr_;
352  }
353  if (configIoFactoryPtr_) {
354  delete configIoFactoryPtr_;
355  }
356  if (trajectoryReaderFactoryPtr_) {
357  delete trajectoryReaderFactoryPtr_;
358  }
359  if (fileMasterPtr_ && createdFileMaster_) {
360  delete fileMasterPtr_;
361  }
362  }
363  }
364 
365  /*
366  * Read parameters from file.
367  */
368  void System::readParameters(std::istream &in)
369  {
370 
371  // Only read parameters if this is not a copy.
372  if (!isCopy()) {
374  readFileMaster(in);
376  #ifdef MCMD_LINK
377  readLinkMaster(in);
378  #endif
379  #ifdef SIMP_TETHER
380  readTetherMaster(in);
381  #endif
382  readEnsembles(in);
383  }
384 
385  }
386 
387  /*
388  * Load internal state from an archive.
389  */
391  {
392  if (!isCopy()) {
394  loadFileMaster(ar);
396  #ifdef MCMD_LINK
397  loadLinkMaster(ar);
398  #endif
399  #ifdef SIMP_TETHER
400  loadTetherMaster(ar);
401  #endif
402  loadEnsembles(ar);
403  }
404  }
405 
406  /*
407  * Load parameters to an archive.
408  */
410  {
411  if (!isCopy()) {
412  saveFileMaster(ar);
414  #ifdef MCMD_LINK
415  saveLinkMaster(ar);
416  #endif
417  #ifdef SIMP_TETHER
418  saveTetherMaster(ar);
419  #endif
420  saveEnsembles(ar);
421  }
422  }
423 
427  void System::readFileMaster(std::istream &in)
428  {
429  // Create and read FileMaster if necessary
430  if (!fileMasterPtr_) {
431  fileMasterPtr_ = new FileMaster();
432  createdFileMaster_ = true;
433  readParamComposite(in, *fileMasterPtr_);
434  }
435  }
436 
437  /*
438  * If no FileMaster exists, create and load one.
439  *
440  * This is called by System::loadParameters(). Except during unit
441  * testing of System, a FileMaster will normally already exist when
442  * this is called, either because the FileMaster has been set to
443  * that of a parent Simulation by calling setFileMaster(), or
444  * because the System was constructed by copying another, for HMC.
445  */
447  {
448  if (!fileMasterPtr_) {
449  fileMasterPtr_ = new FileMaster();
450  createdFileMaster_ = true;
451  loadParamComposite(ar, *fileMasterPtr_);
452  }
453  }
454 
455  /*
456  * If createdFileMaster_, save to archive.
457  *
458  * A System normally creates its own FileMaster only in unit tests.
459  * In a simulation, the FileMaster is normally set to that of either
460  * a parent Simulation or that of another System from which this was
461  * copied.
462  */
464  {
465  if (createdFileMaster_) {
466  fileMasterPtr_->save(ar);
467  }
468  }
469 
470  /*
471  * Read potential style strings from parameter file.
472  */
473  void System::readPotentialStyles(std::istream &in)
474  {
475  UTIL_CHECK(!isCopy());
476  #ifndef SIMP_NOPAIR
477  read<std::string>(in, "pairStyle", pairStyle_);
478  #endif
479  #ifdef SIMP_BOND
480  if (simulation().nBondType() > 0) {
481  read<std::string>(in, "bondStyle", bondStyle_);
482  }
483  #endif
484  #ifdef SIMP_ANGLE
485  if (simulation().nAngleType() > 0) {
486  read<std::string>(in, "angleStyle", angleStyle_);
487  }
488  #endif
489  #ifdef SIMP_DIHEDRAL
490  if (simulation().nDihedralType() > 0) {
491  read<std::string>(in, "dihedralStyle", dihedralStyle_);
492  }
493  #endif
494  #ifdef SIMP_COULOMB
495  if (simulation().hasCoulomb() > 0) {
496  read<std::string>(in, "coulombStyle", coulombStyle_);
497  }
498  #endif
499  #ifdef SIMP_EXTERNAL
500  if (simulation().hasExternal()) {
501  read<std::string>(in, "externalStyle", externalStyle_);
502  }
503  #endif
504  #ifdef SIMP_SPECIAL
505  if (simulation().hasSpecial()) {
506  read<std::string>(in, "specialStyle", specialStyle_);
507  }
508  #endif
509  #ifdef MCMD_LINK
510  if (simulation().nLinkType() > 0) {
511  read<std::string>(in, "linkStyle", linkStyle_);
512  }
513  #endif
514  #ifdef SIMP_TETHER
515  if (simulation().hasTether()) {
516  read<std::string>(in, "tetherStyle", tetherStyle_);
517  }
518  #endif
519  }
520 
521  /*
522  * Load potential style strings.
523  */
525  {
526  UTIL_CHECK(!isCopy());
527  #ifndef SIMP_NOPAIR
528  loadParameter<std::string>(ar, "pairStyle", pairStyle_);
529  #endif
530  #ifdef SIMP_BOND
531  if (simulation().nBondType() > 0) {
532  loadParameter<std::string>(ar, "bondStyle", bondStyle_);
533  }
534  #endif
535  #ifdef SIMP_ANGLE
536  if (simulation().nAngleType() > 0) {
537  loadParameter<std::string>(ar, "angleStyle", angleStyle_);
538  }
539  #endif
540  #ifdef SIMP_DIHEDRAL
541  if (simulation().nDihedralType() > 0) {
542  loadParameter<std::string>(ar, "dihedralStyle", dihedralStyle_);
543  }
544  #endif
545  #ifdef SIMP_COULOMB
546  if (simulation().hasCoulomb() > 0) {
547  loadParameter<std::string>(ar, "coulombStyle", coulombStyle_);
548  }
549  #endif
550  #ifdef SIMP_EXTERNAL
551  if (simulation().hasExternal()) {
552  loadParameter<std::string>(ar, "externalStyle", externalStyle_);
553  }
554  #endif
555  #ifdef SIMP_SPECIAL
556  if (simulation().hasSpecial()) {
557  loadParameter<std::string>(ar, "specialStyle", specialStyle_);
558  }
559  #endif
560  #ifdef MCMD_LINK
561  if (simulation().nLinkType() > 0) {
562  loadParameter<std::string>(ar, "linkStyle", linkStyle_);
563  }
564  #endif
565  #ifdef SIMP_TETHER
566  if (simulation().hasTether()) {
567  loadParameter<std::string>(ar, "tetherStyle", tetherStyle_);
568  }
569  #endif
570  }
571 
572  /*
573  * Save potential style strings.
574  */
576  {
577  UTIL_CHECK(!isCopy());
578  #ifndef SIMP_NOPAIR
579  ar << pairStyle_;
580  #endif
581  #ifdef SIMP_BOND
582  if (simulation().nBondType() > 0) {
583  ar << bondStyle_;
584  }
585  #endif
586  #ifdef SIMP_ANGLE
587  if (simulation().nAngleType() > 0) {
588  ar << angleStyle_;
589  }
590  #endif
591  #ifdef SIMP_DIHEDRAL
592  if (simulation().nDihedralType() > 0) {
593  ar << dihedralStyle_;
594  }
595  #endif
596  #ifdef SIMP_COULOMB
597  if (simulation().hasCoulomb() > 0) {
598  ar << coulombStyle_;
599  }
600  #endif
601  #ifdef SIMP_EXTERNAL
602  if (simulation().hasExternal()) {
603  ar << externalStyle_;
604  }
605  #endif
606  #ifdef SIMP_SPECIAL
607  if (simulation().hasSpecial()) {
608  ar << specialStyle_;
609  }
610  #endif
611  #ifdef MCMD_LINK
612  if (simulation().nLinkType() > 0) {
613  ar << linkStyle_;
614  }
615  #endif
616  #ifdef SIMP_TETHER
617  if (simulation().hasTether()) {
618  ar << tetherStyle_;
619  }
620  #endif
621  }
622 
623  /*
624  * Create EnergyEnsemble and BoundaryEnsemble
625  */
626  void System::readEnsembles(std::istream &in)
627  {
628  UTIL_CHECK(!isCopy());
629  readParamComposite(in, *energyEnsemblePtr_);
630  readParamComposite(in, *boundaryEnsemblePtr_);
631  }
632 
633  /*
634  * Load EnergyEnsemble and BoundaryEnsemble.
635  */
637  {
638  UTIL_CHECK(!isCopy());
639  loadParamComposite(ar, *energyEnsemblePtr_);
640  loadParamComposite(ar, *boundaryEnsemblePtr_);
641  }
642 
643  /*
644  * Save EnergyEnsemble and BoundaryEnsemble.
645  */
647  {
648  UTIL_CHECK(!isCopy());
649  energyEnsemblePtr_->save(ar);
650  boundaryEnsemblePtr_->save(ar);
651  }
652 
653  #ifdef MCMD_LINK
654  void System::readLinkMaster(std::istream& in)
655  {
656  if (simulation().nLinkType() > 0) {
657  linkMasterPtr_ = new LinkMaster();
658  readParamComposite(in, *linkMasterPtr_);
659  }
660  }
661 
663  {
664  if (simulation().nLinkType() > 0) {
665  linkMasterPtr_ = new LinkMaster();
666  loadParamComposite(ar, *linkMasterPtr_);
667  }
668  }
669 
671  {
672  if (simulation().nLinkType() > 0) {
673  linkMasterPtr_->save(ar);
674  }
675  }
676  #endif
677 
678  #ifdef SIMP_TETHER
679  void System::readTetherMaster(std::istream &in)
680  {
681  if (simulation().hasTether()) {
682  tetherMasterPtr_ = new TetherMaster();
683  readParamComposite(in, *tetherMasterPtr_);
684  }
685  }
686 
687  void System::loadTetherMaster(Serializable::IArchive &ar)
688  {
689  if (simulation().hasTether()) {
690  tetherMasterPtr_ = new TetherMaster();
691  loadParamComposite(ar, *tetherMasterPtr_);
692  }
693  }
694 
695  void System::saveTetherMaster(Serializable::OArchive& ar)
696  {
697  if (simulation().hasTether() > 0) {
698  tetherMasterPtr_->save(ar);
699  }
700  }
701  #endif
702 
703  /*
704  * Load configuration from an archive.
705  */
707  {
708  ar >> boundary();
709 
710  int subType;
711  bool isMutable = false;
712  Molecule* molPtr;
713  Molecule::AtomIterator atomIter;
714  int iSpeciesIn, nMoleculeIn;
715  const int nSpecies = simulation().nSpecies();
716 
717  for (int iSpecies = 0; iSpecies < nSpecies; ++iSpecies) {
718  ar >> iSpeciesIn;
719  if (simulation().species(iSpecies).isMutable()) {
720  isMutable = true;
721  } else {
722  isMutable = false;
723  }
724  if (iSpeciesIn != iSpecies) {
725  UTIL_THROW("Error: iSpeciesIn != iSpecies");
726  }
727  ar >> nMoleculeIn;
728  for (int iMol = 0; iMol < nMoleculeIn; ++iMol) {
729  molPtr = &(simulation().getMolecule(iSpecies));
730  addMolecule(*molPtr);
731  if (molPtr != &molecule(iSpecies, iMol)) {
732  UTIL_THROW("Molecule index error");
733  }
734  if (isMutable) {
735  ar >> subType;
736  simulation().species(iSpecies).mutator().setMoleculeState(*molPtr, subType);
737  }
738  molPtr->begin(atomIter);
739  for ( ; atomIter.notEnd(); ++atomIter) {
740  ar >> atomIter->position();
741  ar >> atomIter->velocity();
742  #ifdef MCMD_SHIFT
743  ar >> atomIter->shift();
744  boundary().shift(atomIter->position(), atom.shift());
745  #else
746  boundary().shift(atomIter->position());
747  #endif
748  }
749  }
750  }
751  }
752 
753  /*
754  * Save configuration to an archive.
755  */
757  {
758  ar << boundary();
759 
760  int subType;
761  bool isMutable = false;
762  System::MoleculeIterator molIter;
763  Molecule::AtomIterator atomIter;
764  int nMoleculeOut;
765  const int nSpecies = simulation().nSpecies();
766 
767  for (int iSpecies = 0; iSpecies < nSpecies; ++iSpecies) {
768  ar << iSpecies;
769  if (simulation().species(iSpecies).isMutable()) {
770  isMutable = true;
771  } else {
772  isMutable = false;
773  }
774  nMoleculeOut = nMolecule(iSpecies);
775  ar << nMoleculeOut;
776  begin(iSpecies, molIter);
777  for ( ; molIter.notEnd(); ++molIter) {
778  if (isMutable) {
779  subType = simulation().species(iSpecies).mutator().moleculeStateId(*molIter);
780  ar << subType;
781  }
782  molIter->begin(atomIter);
783  for ( ; atomIter.notEnd(); ++atomIter) {
784  #ifdef MCMD_SHIFT
785  boundary().shift(atomIter->position(), atomIter->shift());
786  #else
787  boundary().shift(atomIter->position());
788  #endif
789  ar << atomIter->position();
790  ar << atomIter->velocity();
791  #ifdef MCMD_SHIFT
792  ar << atomIter->shift();
793  #endif
794  }
795  }
796  }
797  }
798 
799  /*
800  * Return a pointer to a new default ConfigIo.
801  */
803  { return new McConfigIo(*this); }
804 
805  /*
806  * Read configuration from a specific input stream.
807  */
808  void System::readConfig(std::istream &in)
809  {
810  if (!isEmpty()) removeAllMolecules();
811 
812  if (configIoPtr_ == 0) {
813  configIoPtr_ = newDefaultConfigIo();
814  }
815  configIoPtr_->read(in);
816 
817  #ifdef UTIL_DEBUG
818  isValid();
819  #endif
820  }
821 
822  /*
823  * Open, read, and close a configuration file.
824  */
825  void System::readConfig(std::string filename)
826  {
827  std::ifstream file;
828  fileMaster().openInputFile(filename, file);
829  readConfig(file);
830  file.close();
831  }
832 
833  /*
834  * Write configuration to specified output stream.
835  */
836  void System::writeConfig(std::ostream &out)
837  {
838  if (configIoPtr_ == 0) {
839  configIoPtr_ = newDefaultConfigIo();
840  }
841  configIoPtr_->write(out);
842  }
843 
844  /*
845  * Open, write, and close a configuration file.
846  */
847  void System::writeConfig(std::string filename)
848  {
849  std::ofstream file;
850  fileMaster().openOutputFile(filename, file);
851  writeConfig(file);
852  file.close();
853  }
854 
855  /*
856  * Set System integer Id.
857  *
858  * Should be set immediately after the System is instantiated. If the System
859  * is a member of the parent Simulation, setId() should be called in the
860  * Simulation constructor.
861  */
862  void System::setId(int id)
863  { id_ = id; }
864 
865  /*
866  * Set pointer to the parent Simulation.
867  *
868  * Should be set immediately after System instantiation. If this System
869  * is a member of the parent Simulation, setSimulation(*this) should be
870  * called in the Simulation constructor.
871  */
873  {
874  assert(!simulationPtr_);
875  simulationPtr_ = &simulation;
876  }
877 
878  /*
879  * Set pointer to a FileMaster.
880  */
882  {
883  assert(!fileMasterPtr_);
884  fileMasterPtr_ = &fileMaster;
885  }
886 
887  // ConfigIoIo Management
888 
889  /*
890  * Get the ConfigIo factory by reference.
891  */
893  {
894  if (!configIoFactoryPtr_) {
895  configIoFactoryPtr_ = newDefaultConfigIoFactory();
896  }
897  return *configIoFactoryPtr_;
898  }
899 
900  /*
901  * Return a pointer to a new ConfigIoFactory.
902  */
904  { return new ConfigIoFactory(*this); }
905 
906  /*
907  * Set the ConfigIo, identified by subclass name.
908  */
909  void System::setConfigIo(std::string& classname)
910  {
911  if (!configIoFactoryPtr_) {
912  configIoFactoryPtr_ = newDefaultConfigIoFactory();
913  }
914  ConfigIo* ptr = configIoFactoryPtr_->factory(classname);
915  if (!ptr) {
916  UTIL_THROW("Unrecognized ConfigIo subclass name");
917  }
918  if (configIoPtr_) {
919  delete configIoPtr_;
920  }
921  configIoPtr_ = ptr;
922  }
923 
924  // TrajectoryReader Management
925 
926  /*
927  * Get the TrajectoryReader factory by reference.
928  */
930  {
931  if (!trajectoryReaderFactoryPtr_) {
932  trajectoryReaderFactoryPtr_ = newDefaultTrajectoryReaderFactory();
933  }
934  return *trajectoryReaderFactoryPtr_;
935  }
936 
937  /*
938  * Return pointer to a new instance of default TrajectoryReader factory.
939  */
941  { return new TrajectoryReaderFactory(*this); }
942 
943  #ifdef MCMD_PERTURB
944  /*
945  * Set this system to expect a Perturbation in the param file.
946  * Also creates the perturbation factory.
947  */
949  {
950  // Precondition
951  if (hasPerturbation()) {
952  UTIL_THROW("A Perturbation is already set");
953  }
954 
955  // Create perturbation factory
956  perturbationFactoryPtr_ = newDefaultPerturbationFactory();
957  createdPerturbationFactory_ = true;
958 
959  expectPerturbationParam_ = true;
960  }
961 
962  /*
963  * If a perturbation is expected, read the polymorphic perturbation block.
964  *
965  * This function reads the array of perturbation parameters, and then
966  * modifies the appropriate system parameters accordingly. This function
967  * is not called by System::readParameters, but should be called by the
968  * readParameters function of subclasses (e.g., MdSystem and McSystem). It
969  * should be called after all of the potentials, ensmebles, and other
970  * physical parameters, which provide a set of baseline parameters that
971  * this function can then modify.
972  *
973  * The parameter value used for this system is determined by the rank
974  * of this System, which is a parameter of the Perturbation constructor.
975  * The rank must thus be known to the perturbation factory that creates
976  * an instance of a subclass of Perturbation. Subclasses of system must
977  * re-implement the virtual System::newDefaultPerturbationFactory()
978  * function to create an appropriate Factory object.
979  */
980  void System::readPerturbation(std::istream& in)
981  {
982  if (!hasPerturbation() && expectPerturbationParam_) {
983  #ifdef UTIL_MPI
985  #endif
986  std::string className;
987  bool isEnd;
988  UTIL_CHECK(perturbationFactoryPtr_)
989  perturbationPtr_ =
990  perturbationFactoryPtr_->readObject(in, *this, className, isEnd);
991  if (!perturbationPtr_) {
992  std::string msg = "Unrecognized Perturbation subclass name ";
993  msg += className;
994  UTIL_THROW(msg.c_str());
995  }
996  createdPerturbation_ = true;
997  }
998  }
999 
1000  /*
1001  * Load Perturbation, if any, or do nothing.
1002  */
1004  {
1005  UTIL_CHECK(!isCopy());
1006  bool savedPerturbation;
1007  ar >> savedPerturbation;
1008  if (savedPerturbation) {
1010  // Create the perturbationFactory
1012  UTIL_CHECK(perturbationFactoryPtr_);
1013  std::string className = "unknown";
1014  perturbationPtr_ =
1015  perturbationFactoryPtr_->loadObject(ar, *this, className);
1016  if (!perturbationPtr_) {
1017  std::string msg = "Unrecognized Perturbation subclass name ";
1018  msg += className;
1019  UTIL_THROW(msg.c_str());
1020  }
1021  createdPerturbation_ = true;
1022  }
1023  }
1024 
1025  /*
1026  * Save Perturbation, if any, or do nothing.
1027  */
1029  {
1030  UTIL_CHECK(!isCopy());
1031  bool savingPerturbation = hasPerturbation();
1032  ar << savingPerturbation;
1033  if (savingPerturbation) {
1034  std::string className = perturbationPtr_->className();
1035  ar << className;
1036  perturbationPtr_->save(ar);
1037  }
1038  }
1039 
1040  #ifdef UTIL_MPI
1041  /*
1042  * Read ReplicaMove, if any, or do nothing.
1043  */
1044  void System::readReplicaMove(std::istream& in)
1045  {
1046  if (hasPerturbation()) {
1047  read<bool>(in, "hasReplicaMove", hasReplicaMove_);
1048  if (hasReplicaMove_) {
1049  replicaMovePtr_ = new ReplicaMove(*this);
1050  readParamComposite(in, *replicaMovePtr_);
1051  }
1052  createdReplicaMove_ = true;
1053  } else {
1054  hasReplicaMove_ = false;
1055  }
1056  }
1057 
1058  /*
1059  * Load ReplicaMove, if any, or do nothing.
1060  */
1062  {
1063  if (hasPerturbation()) {
1064  loadParameter<bool>(ar, "hasReplicaMove", hasReplicaMove_);
1065  if (hasReplicaMove_) {
1066  replicaMovePtr_ = new ReplicaMove(*this);
1067  loadParamComposite(ar, *replicaMovePtr_);
1068  }
1069  createdReplicaMove_ = true;
1070  } else {
1071  hasReplicaMove_ = false;
1072  }
1073  }
1074 
1075  /*
1076  * Save ReplicaMove, if any, or do nothing.
1077  */
1079  {
1080  if (hasPerturbation()) {
1081  ar & hasReplicaMove_;
1082  if (hasReplicaMove_) {
1083  replicaMovePtr_->save(ar);
1084  }
1085  }
1086  }
1087  #endif // UTIL_MPI
1088  #endif // MCMD_PERTURB
1089 
1090  /*
1091  * Allocate and initialize a MoleculeSet for each Species.
1092  */
1094  {
1095  // Preconditions
1096  assert(simulationPtr_);
1097 
1098  // Allocate an array of nSpecies empty MoleculeSet objects.
1099  const int nSpecies = simulation().nSpecies();
1100  moleculeSetsPtr_->allocate(nSpecies);
1101 
1102  // Allocate and initialize the MoleculeSet for each species.
1103  for (int i=0; i < nSpecies; ++i) {
1104  simulation().allocateMoleculeSet((*moleculeSetsPtr_)[i], i);
1105  }
1106  }
1107 
1108  /*
1109  * Add a molecule to this System.
1110  */
1112  {
1113  assert(moleculeSetsPtr_);
1114 
1115  int speciesId = molecule.species().id();
1116  if ( speciesId >= moleculeSetsPtr_->capacity()) {
1117  UTIL_THROW("Error: speciesId >= moleculeSetsPtr_->capacity()");
1118  }
1119  (*moleculeSetsPtr_)[speciesId].append(molecule);
1120  molecule.setSystem(*this);
1121 
1122  // notify observers
1123  notifyMoleculeSetObservers();
1124  }
1125 
1126  /*
1127  * Remove a molecule from this System.
1128  */
1130  {
1131  assert(moleculeSetsPtr_);
1132 
1133  if ( &molecule.system() != this) {
1134  UTIL_THROW("Attempt to remove Molecule that is not in this System.");
1135  }
1136  int speciesId = molecule.species().id();
1137  (*moleculeSetsPtr_)[speciesId].remove(molecule);
1138  molecule.unsetSystem();
1139 
1140  // notify observers
1141  notifyMoleculeSetObservers();
1142  }
1143 
1144  /*
1145  * Is this System empty (i.e., devoid of Molecules) ?
1146  */
1147  bool System::isEmpty() const
1148  {
1149  if (!simulation().hasSpecies()) {
1150  return true;
1151  }
1152  for (int i = 0; i < simulation().nSpecies(); ++i) {
1153  if (nMolecule(i) != 0) return false;
1154  }
1155  return true;
1156  }
1157 
1158  /*
1159  * Return all molecules of all Species to their reservoirs.
1160  *
1161  * Ifdef MCMD_LINK, also clears the LinkMaster.
1162  */
1164  {
1165  Molecule* molPtr;
1166  int iSpecies, nMol;
1167  const int nSpecies = simulation().nSpecies();
1168  for (iSpecies = 0; iSpecies < nSpecies; ++iSpecies) {
1169  nMol = nMolecule(iSpecies);
1170  while (nMol > 0) {
1171  molPtr = &molecule(iSpecies, nMol - 1);
1172  removeMolecule(*molPtr);
1173  simulation().returnMolecule(*molPtr);
1174  nMol = nMolecule(iSpecies);
1175  }
1176  }
1177 
1178  #ifdef MCMD_LINK
1179  linkMaster().clear();
1180  #endif
1181 
1182  // notify observers
1183  notifyMoleculeSetObservers();
1184  }
1185 
1186  /*
1187  * Get the index of a molecule within its Species in this System.
1188  */
1190  {
1191  assert(moleculeSetsPtr_);
1192 
1193  int speciesId = molecule.species().id();
1194  return (*moleculeSetsPtr_)[speciesId].index(molecule);
1195  }
1196 
1197  /*
1198  * Get a randomly chosen molecule of a specified Species.
1199  */
1201  {
1202  int nMol, moleculeId;
1203  nMol = nMolecule(speciesId);
1204  if (nMol <= 0) {
1205  Log::file() << "Number of molecules in species " << speciesId
1206  << " = " << nMol << std::endl;
1207  UTIL_THROW("Number of molecules in species <= 0");
1208  }
1209  moleculeId = simulation().random().uniformInt(0, nMol);
1210  return molecule(speciesId, moleculeId);
1211  }
1212 
1213  /*
1214  * Return the total number of atoms in this System.
1215  */
1216  int System::nAtom() const
1217  {
1218  int sum = 0;
1219  for (int i = 0; i < simulation().nSpecies(); ++i) {
1220  sum += nMolecule(i)*simulation().species(i).nAtom();
1221  }
1222  return sum;
1223  }
1224 
1225  #ifndef SIMP_NOPAIR
1226  /*
1227  * Return the PairFactory by reference.
1228  */
1230  {
1231  if (!pairFactoryPtr_) {
1232  pairFactoryPtr_ = new PairFactory;
1233  }
1234  assert(pairFactoryPtr_);
1235  return *pairFactoryPtr_;
1236  }
1237 
1238  /*
1239  * Get the pair style string.
1240  */
1241  std::string System::pairStyle() const
1242  { return pairStyle_; }
1243  #endif
1244 
1245  #ifdef SIMP_BOND
1246  /*
1247  * Return the BondFactory by reference.
1248  */
1250  {
1251  if (!bondFactoryPtr_) {
1252  bondFactoryPtr_ = new BondFactory(*this);
1253  }
1254  assert(bondFactoryPtr_);
1255  return *bondFactoryPtr_;
1256  }
1257 
1258  /*
1259  * Get the bond style string.
1260  */
1261  std::string System::bondStyle() const
1262  { return bondStyle_; }
1263  #endif
1264 
1265  #ifdef SIMP_ANGLE
1266  /*
1267  * Return the AngleFactory by reference.
1268  */
1270  {
1271  if (angleFactoryPtr_ == 0) {
1272  angleFactoryPtr_ = new AngleFactory(*this);
1273  }
1274  assert(angleFactoryPtr_);
1275  return *angleFactoryPtr_;
1276  }
1277 
1278  /*
1279  * Get the angle style string.
1280  */
1281  std::string System::angleStyle() const
1282  { return angleStyle_; }
1283  #endif
1284 
1285  #ifdef SIMP_DIHEDRAL
1286  /*
1287  * Return the DihedralFactory by reference.
1288  */
1290  {
1291  if (dihedralFactoryPtr_ == 0) {
1292  dihedralFactoryPtr_ = new DihedralFactory(*this);
1293  }
1294  assert(dihedralFactoryPtr_);
1295  return *dihedralFactoryPtr_;
1296  }
1297 
1298  /*
1299  * Get the dihedral style string.
1300  */
1301  std::string System::dihedralStyle() const
1302  { return dihedralStyle_; }
1303  #endif
1304 
1305  #ifdef SIMP_COULOMB
1306  /*
1307  * Return the CoulombFactory by reference.
1308  */
1310  {
1311  if (coulombFactoryPtr_ == 0) {
1312  coulombFactoryPtr_ = new CoulombFactory(*this);
1313  }
1314  assert(coulombFactoryPtr_);
1315  return *coulombFactoryPtr_;
1316  }
1317 
1318  /*
1319  * Get the coulomb style string.
1320  */
1321  std::string System::coulombStyle() const
1322  { return coulombStyle_; }
1323  #endif
1324 
1325  #ifdef SIMP_EXTERNAL
1326  /*
1327  * Return the ExternalFactory by reference.
1328  */
1330  {
1331  if (externalFactoryPtr_ == 0) {
1332  externalFactoryPtr_ = new ExternalFactory(*this);
1333  }
1334  assert(externalFactoryPtr_);
1335  return *externalFactoryPtr_;
1336  }
1337 
1338  /*
1339  * Get the external style string.
1340  */
1341  std::string System::externalStyle() const
1342  { return externalStyle_; }
1343  #endif
1344 
1345  #ifdef SIMP_SPECIAL
1346  SpecialFactory& System::specialFactory()
1347  {
1348  if (specialFactoryPtr_ == 0) {
1349  specialFactoryPtr_ = new SpecialFactory;
1350  }
1351  assert(specialFactoryPtr_);
1352  return *specialFactoryPtr_;
1353  }
1354 
1355  /*
1356  * Get the special style string.
1357  */
1358  std::string System::specialStyle() const
1359  { return specialStyle_; }
1360  #endif
1361 
1362  #ifdef MCMD_LINK
1363  /*
1364  * Return the Link factory by reference.
1365  */
1367  {
1368  if (linkFactoryPtr_ == 0) {
1369  linkFactoryPtr_ = new LinkFactory(*this);
1370  }
1371  assert(linkFactoryPtr_);
1372  return *linkFactoryPtr_;
1373  }
1374 
1375  /*
1376  * Get the link style string.
1377  */
1378  std::string System::linkStyle() const
1379  { return linkStyle_; }
1380  #endif
1381 
1382  #ifdef SIMP_TETHER
1383  /*
1384  * Return the TetherFactory by reference.
1385  */
1386  TetherFactory& System::tetherFactory()
1387  {
1388  if (tetherFactoryPtr_ == 0) {
1389  tetherFactoryPtr_ = new TetherFactory;
1390  }
1391  assert(tetherFactoryPtr_);
1392  return *tetherFactoryPtr_;
1393  }
1394 
1395  /*
1396  * Get the tether style string.
1397  */
1398  std::string System::tetherStyle() const
1399  { return tetherStyle_; }
1400  #endif
1401 
1402  /*
1403  * Check validity of all data structures.
1404  */
1405  bool System::isValid() const
1406  {
1407  Molecule* molPtr;
1408  int iSpecies, iMolecule;
1409  if (!simulationPtr_) {
1410  UTIL_THROW("Null simulationPtr_");
1411  }
1412  if (!moleculeSetsPtr_) {
1413  UTIL_THROW("Null moleculeSetsPtr_");
1414  }
1415  for (iSpecies =0; iSpecies < simulationPtr_->nSpecies(); ++iSpecies) {
1416  (*moleculeSetsPtr_)[iSpecies].isValid();
1417  for (iMolecule = 0; iMolecule < nMolecule(iSpecies); ++iMolecule) {
1418  molPtr = &(*moleculeSetsPtr_)[iSpecies][iMolecule];
1419  if (&molPtr->system() != this) {
1420  UTIL_THROW("Error in pointer to System in a Molecule");
1421  }
1422  }
1423  }
1424 
1425  #ifdef MCMD_LINK
1426  if (simulation().nLinkType() > 0) {
1427  if (!linkMasterPtr_) {
1428  UTIL_THROW("Null linkMasterPtr_");
1429  }
1430  linkMasterPtr_->isValid();
1431  }
1432  #endif
1433 
1434  #ifdef SIMP_TETHER
1435  if (simulation().hasTether() > 0) {
1436  if (!tetherMasterPtr_) {
1437  UTIL_THROW("Null tetherMasterPtr_");
1438  }
1439  tetherMasterPtr_->isValid();
1440  }
1441  #endif
1442 
1443  return true;
1444  }
1445 
1446 }
void saveFileMaster(Serializable::OArchive &ar)
If necessary, save FileMaster to archive.
Definition: System.cpp:463
bool isEmpty() const
Is this an empty System (i.e., one with no molecules) ?
Definition: System.cpp:1147
virtual void save(Serializable::OArchive &ar)
Save internal state to an archive.
CoulombFactory & coulombFactory()
Get the associated Coulomb Factory by reference.
Definition: System.cpp:1309
Replica exchange Monte Carlo move using Gibbs sampling.
Definition: ReplicaMove.h:63
bool isCopy() const
Was this System instantiated with the copy constructor?
Definition: System.h:1122
FileMaster & fileMaster() const
Get the associated FileMaster by reference.
Definition: System.h:1113
void begin(int speciesId, MoleculeIterator &iterator)
Initialize an iterator for molecules of one species in this System.
Definition: System.h:1147
int nAtom() const
Get number of atoms per molecule for this Species.
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
Factory for subclasses of DihedralPotential.
void setExpectPerturbation()
Set to expect a Perturbation in the parameter file.
Definition: System.cpp:948
bool notEnd() const
Is the current pointer not at the end of the array?
Definition: ArrayIterator.h:83
void saveConfig(Serializable::OArchive &ar)
Save configuration.
Definition: System.cpp:756
virtual Factory< ConfigIo > * newDefaultConfigIoFactory()
Return a pointer to a new default ConfigIoFactory.
Definition: System.cpp:903
void loadPerturbation(Serializable::IArchive &ar)
Load the perturbation parameter block (if any)
Definition: System.cpp:1003
virtual ConfigIo * newDefaultConfigIo()
Return a pointer to a new default ConfigIo.
Definition: System.cpp:802
Factory for subclasses of MdBondPotential or McBondPotential.
Definition: LinkFactory.h:27
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
Statistical ensemble for changes in the periodic unit cell size.
void openOutputFile(const std::string &filename, std::ofstream &out, std::ios_base::openmode mode=std::ios_base::out) const
Open an output file.
Definition: FileMaster.cpp:290
void loadParamComposite(Serializable::IArchive &ar, ParamComposite &child, bool next=true)
Add and load a required child ParamComposite.
virtual void save(Serializable::OArchive &ar)
Save internal state to an archive.
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
virtual void write(std::ostream &out)=0
Write configuration (particle positions) to file.
Species & species() const
Get the molecular Species by reference.
Factory< AnglePotential > & angleFactory()
Get the associated AngleFactory by reference.
Definition: System.cpp:1269
Factory for subclasses MdPairPotential or McPairPotential.
void begin(AtomIterator &iterator)
Set an Molecule::AtomIterator to first Atom in this Molecule.
void setConfigIo(std::string &classname)
Create a new configuration file reader/writer.
Definition: System.cpp:909
A set of interacting Molecules enclosed by a Boundary.
Definition: System.h:115
void openInputFile(const std::string &filename, std::ifstream &in, std::ios_base::openmode mode=std::ios_base::in) const
Open an input file.
Definition: FileMaster.cpp:273
void allocateMoleculeSet(Util::ArraySet< Molecule > &set, int speciesId) const
Allocate and initialize a molecule set for one Species.
bool hasPerturbation() const
Does this system have an associated Perturbation?
Definition: System.h:1179
void readEnsembles(std::istream &in)
Read energy and boundary ensemble parameters.
Definition: System.cpp:626
int moleculeStateId(const Molecule &molecule) const
Get the state id for a specific molecule.
Classes used by all simpatico molecular simulations.
void setFileMaster(FileMaster &filemaster)
Set the FileMaster.
Definition: System.cpp:881
Molecule & getMolecule(int speciesId)
Get a new molecule from a reservoir of unused Molecule objects.
std::string linkStyle() const
Return link potential style string.
Definition: System.cpp:1378
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
void returnMolecule(Molecule &molecule)
Return a molecule to a reservoir of unused molecules.
void savePotentialStyles(Serializable::OArchive &ar)
Save potential style strings.
Definition: System.cpp:575
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 ~System()
Destructor.
Definition: System.cpp:272
void removeAllMolecules()
Remove all molecules from this System.
Definition: System.cpp:1163
Molecule & molecule(int speciesId, int moleculeId)
Get a specific Molecule in this System, by integer index.
Definition: System.h:1137
PairFactory & pairFactory()
Get the PairFactory by reference.
Definition: System.cpp:1229
A statistical ensemble for energy.
virtual void loadConfig(Serializable::IArchive &ar)
Load configuration.
Definition: System.cpp:706
int nBondType() const
Get the number of bond types.
std::string bondStyle() const
Return covalent bond style string.
Definition: System.cpp:1261
int nMolecule(int speciesId) const
Get the number of molecules of one Species in this System.
Definition: System.h:1128
int hasCoulomb() const
Does a Coulomb potential exist?
#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.
Molecule & randomMolecule(int speciesId)
Get a random Molecule of a specified species in this System.
Definition: System.cpp:1200
virtual void readParameters(std::istream &in)
Read parameter file.
Definition: System.cpp:368
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
void addMolecule(Molecule &molecule)
Add a Molecule to this System.
Definition: System.cpp:1111
void setId(int Id)
Set the integer Id for this System.
Definition: System.cpp:862
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
Factory< BondPotential > & bondFactory()
Get the associated Factory<BondPotential> by reference.
Definition: System.cpp:1249
OrthorhombicBoundary Boundary
Boundary is an alias for the periodic boundary condition class.
Definition: Boundary.h:21
bool notEnd() const
Is the current pointer not at the end of the PArray?
Utility classes for scientific computation.
Definition: accumulators.mod:1
void clear()
Clear LinkMaster.
Definition: LinkMaster.cpp:324
virtual void loadParameters(Serializable::IArchive &ar)
Load internal state from an archive.
Definition: System.cpp:390
void readLinkMaster(std::istream &in)
Read the LinkMaster parameters.
Definition: System.cpp:654
Default Factory for subclasses of TrajectoryReader.
long uniformInt(long range1, long range2)
Return random long int x uniformly distributed in range1 <= x < range2.
Definition: Random.h:224
void shift(Vector &r) const
Shift Cartesian Vector r to its primary image.
System()
Default constructor.
Definition: System.cpp:78
int nLinkType() const
Get the number of link types.
Forward iterator for an Array or a C array.
Definition: ArrayIterator.h:39
virtual void setMoleculeState(Molecule &molecule, int stateId)=0
Change the state of a specific molecule.
Forward iterator for a PArray.
Definition: ArraySet.h:19
int nAngleType() const
Get the number of angle types.
void savePerturbation(Serializable::OArchive &ar)
Save the perturbation parameter block (if any)
Definition: System.cpp:1028
Factory for CoulombPotential objects.
std::string externalStyle() const
Return external potential style string.
Definition: System.cpp:1341
virtual void save(Serializable::OArchive &ar)
Save internal state to file.
Definition: FileMaster.cpp:145
Manages all Link objects in a System.
Definition: LinkMaster.h:39
virtual void readConfig(std::istream &in)
Read system configuration from file.
Definition: System.cpp:808
Factory for subclasses MdExternalPotential or McExternalPotential.
int nDihedralType() const
Get the number of dihedral types.
virtual void save(Serializable::OArchive &ar)
Save internal state to an archive.
static std::ostream & file()
Get log ostream by reference.
Definition: Log.cpp:57
bool hasIoCommunicator() const
Does this object have an associated MPI communicator?
Definition: MpiFileIo.h:99
A FileMaster manages input and output files for a simulation.
Definition: FileMaster.h:142
Factory< ConfigIo > & configIoFactory()
Get the configuration file reader/writer factory by reference.
Definition: System.cpp:892
Dynamically allocatable contiguous array template.
Definition: DArray.h:31
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
int id() const
Get integer id of this Species.
Saving archive for binary istream.
Factory for BondPotential objects.
Single-processor Monte Carlo (MC) and molecular dynamics (MD).
int nSpecies() const
Get the number of Species in this Simulation.
void loadReplicaMove(Serializable::IArchive &ar)
Read the ReplicaMove parameter block (if any)
Definition: System.cpp:1061
Factory for specialized subclasses of SpecialPotential.
void unsetSystem()
Set the parent System pointer to null (no System).
virtual bool isValid() const
Return true if valid, or throw Exception.
Definition: System.cpp:1405
Default Factory for subclasses of ConfigIo.
#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
bool isValid() const
Return true if this LinkMaster is valid, or throw an Exception.
Definition: LinkMaster.cpp:245
int hasExternal() const
Does an external potential exist?
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 void save(Serializable::OArchive &ar)
Save internal state to an archive.
void readPerturbation(std::istream &in)
Read the perturbation parameter block (if any)
Definition: System.cpp:980
virtual void read(std::istream &in)=0
Read configuration (particle positions) from file.
virtual Data * factory(const std::string &className) const =0
Returns a pointer to a new instance of specified subclass.
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
A physical molecule (a set of covalently bonded Atoms).
void removeMolecule(Molecule &molecule)
Remove a specific molecule from this System.
Definition: System.cpp:1129
void setSystem(System &system)
Set the parent System.
Factory for subclasses of AnglePotential.
void saveParameters(Serializable::OArchive &ar)
Save internal state from an archive.
Definition: System.cpp:409
An object that can read multiple parameters from file.
Factory< DihedralPotential > & dihedralFactory()
Get the associated Dihedral Factory by reference.
Definition: System.cpp:1289
McMd::SpeciesMutator & mutator()
Return the species mutator object by reference.
ConfigIo for MC simulations (no atom velocities).
Definition: McConfigIo.h:29
void writeConfig(std::ostream &out)
Write system configuration to a specified ostream.
Definition: System.cpp:836
void loadEnsembles(Serializable::IArchive &ar)
Load energy and boundary ensembles from archive.
Definition: System.cpp:636
Species & species(int i)
Get a specific Species by reference.
System & system() const
Get the parent System.
void loadPotentialStyles(Serializable::IArchive &ar)
Load potential style strings from an archive.
Definition: System.cpp:524
std::string angleStyle() const
Return angle potential style string.
Definition: System.cpp:1281
void setSimulation(Simulation &simulation)
Set the parent Simulation.
Definition: System.cpp:872
virtual Factory< TrajectoryReader > * newDefaultTrajectoryReaderFactory()
Return a pointer to a new default TrajectoryReaderFactory.
Definition: System.cpp:940
Factory< TrajectoryReader > & trajectoryReaderFactory()
Get the trajectory reader/writer factory by reference.
Definition: System.cpp:929
int moleculeId(const Molecule &molecule) const
Get the index of a Molecule within its Species in this System.
Definition: System.cpp:1189
System configuration file reader and writer.
LinkMaster & linkMaster() const
Get the LinkMaster by reference.
Definition: System.h:1074
int id() const
Get integer index for this System.
Definition: System.h:1049
Random & random()
Get the random number generator by reference.
virtual Factory< Perturbation > * newDefaultPerturbationFactory()
Return a pointer to the default perturbation Factory.
Definition: System.h:678