Simpatico  v1.10
System.h
1 #ifndef MCMD_SYSTEM_H
2 #define MCMD_SYSTEM_H
3 
4 /*
5 * Simpatico - Simulation Package for Polymeric and Molecular Liquids
6 *
7 * Copyright 2010 - 2017, The Regents of the University of Minnesota
8 * Distributed under the terms of the GNU General Public License.
9 */
10 
11 #include <util/global.h>
12 
13 #include <util/param/ParamComposite.h> // base class
14 
15 #include <simp/boundary/Boundary.h> // member (typedef)
16 #include <mcMd/chemistry/Molecule.h> // member template parameter
17 
18 #include <util/containers/DArray.h> // member template
19 #include <util/containers/ArraySet.h> // member template
20 #include <util/containers/PArrayIterator.h> // inline function begin()
21 
22 #include <iostream>
23 #include <string>
24 #include <set>
25 
26 class SystemTest;
27 
28 namespace Util {
29  template <typename T> class Factory;
30  class FileMaster;
31 }
32 
33 namespace Simp {
34  class EnergyEnsemble;
35  class BoundaryEnsemble;
36 }
37 
38 namespace McMd
39 {
40 
41  using namespace Util;
42  using namespace Simp;
43 
50  {
51  public:
52 
53  virtual ~MoleculeSetObserver(){};
54 
55  virtual void notifyMoleculeSetChanged() = 0;
56  };
57 
58  class Simulation;
59  class ConfigIo;
60  class TrajectoryReader;
61  class PairFactory;
62  #ifdef SIMP_BOND
63  class BondPotential;
64  #endif
65  #ifdef SIMP_ANGLE
66  class AnglePotential;
67  #endif
68  #ifdef SIMP_DIHEDRAL
69  class DihedralPotential;
70  #endif
71  #ifdef SIMP_COULOMB
72  class CoulombFactory;
73  #endif
74  #ifdef SIMP_EXTERNAL
75  class ExternalPotential;
76  #endif
77  #ifdef SIMP_SPECIAL
78  class SpecialFactory;
79  #endif
80  #ifdef MCMD_LINK
81  class LinkPotential;
82  class LinkMaster;
83  #endif
84  #ifdef SIMP_TETHER
85  class TetherFactory;
86  class TetherMaster;
87  #endif
88  #ifdef MCMD_PERTURB
89  class Perturbation;
90  #ifdef UTIL_MPI
91  class ReplicaMove;
92  #endif
93  #endif
94 
115  class System : public ParamComposite
116  {
117 
118  public:
119 
120  // Typedefs
121 
124 
127 
130 
131  // Methods
132 
136  System();
137 
154  System(const System& other);
155 
157  virtual ~System();
158 
160 
161 
169  void setId(int Id);
170 
176  void setSimulation(Simulation& simulation);
177 
186  void setFileMaster(FileMaster& filemaster);
187 
197  virtual void readParameters(std::istream& in);
198 
204  virtual void loadParameters(Serializable::IArchive &ar);
205 
211  void saveParameters(Serializable::OArchive &ar);
212 
214 
216 
220  Factory<ConfigIo>& configIoFactory();
221 
233  void setConfigIo(std::string& classname);
234 
254  virtual void readConfig(std::istream& in);
255 
265  void readConfig(std::string filename);
266 
276  void writeConfig(std::ostream& out);
277 
287  void writeConfig(std::string filename);
288 
294  virtual void loadConfig(Serializable::IArchive& ar);
295 
301  void saveConfig(Serializable::OArchive& ar);
302 
304 
306 
310  Factory<TrajectoryReader>& trajectoryReaderFactory();
311 
313 
315 
327  void addMolecule(Molecule& molecule);
328 
340  void removeMolecule(Molecule& molecule);
341 
348  void removeAllMolecules();
349 
355  void subscribeMoleculeSetChange(MoleculeSetObserver& observer);
356 
362  void unsubscribeMoleculeSetChange(MoleculeSetObserver& observer);
363 
365 
367 
374  int nMolecule(int speciesId) const;
375 
379  int nAtom() const;
380 
384  bool isEmpty() const;
385 
401  int moleculeId(const Molecule& molecule) const;
402 
415  Molecule& molecule(int speciesId, int moleculeId);
416 
423  Molecule& randomMolecule(int speciesId);
424 
431  void begin(int speciesId, MoleculeIterator& iterator);
432 
439  void begin(int speciesId, ConstMoleculeIterator& iterator) const;
440 
442 
444 
445  #ifndef SIMP_NOPAIR
446 
449  PairFactory& pairFactory();
450 
454  std::string pairStyle() const;
455  #endif
456 
457  #ifdef SIMP_BOND
458 
461  Factory<BondPotential>& bondFactory();
462 
466  std::string bondStyle() const;
467  #endif
468 
469  #ifdef SIMP_ANGLE
470 
473  Factory<AnglePotential>& angleFactory();
474 
478  std::string angleStyle() const;
479  #endif
480 
481  #ifdef SIMP_DIHEDRAL
482 
485  Factory<DihedralPotential>& dihedralFactory();
486 
490  std::string dihedralStyle() const;
491  #endif
492 
493  #ifdef SIMP_COULOMB
494 
497  CoulombFactory& coulombFactory();
498 
502  std::string coulombStyle() const;
503  #endif
504 
505  #ifdef SIMP_EXTERNAL
506 
509  Factory<ExternalPotential>& externalFactory();
510 
514  std::string externalStyle() const;
515  #endif
516 
517  #ifdef SIMP_SPECIAL
518 
521  SpecialFactory& specialFactory();
522 
526  std::string specialStyle() const;
527  #endif
528 
529  #ifdef MCMD_LINK
530 
533  Factory<BondPotential>& linkFactory();
534 
538  std::string linkStyle() const;
539 
543  LinkMaster& linkMaster() const;
544  #endif
545 
546  #ifdef SIMP_TETHER
547 
550  TetherFactory& tetherFactory();
551 
555  std::string tetherStyle() const;
556 
560  TetherMaster& tetherMaster() const;
561  #endif
562 
564  #ifdef MCMD_PERTURB
565 
567 
571  Factory<Perturbation>& perturbationFactory();
572 
576  void setExpectPerturbation();
577 
581  bool expectPerturbation() const;
582 
586  bool hasPerturbation() const;
587 
591  Perturbation& perturbation() const;
592 
593  #ifdef UTIL_MPI
594 
597  bool hasReplicaMove() const;
598 
602  ReplicaMove& replicaMove() const;
603  #endif // UTIL_MPI
604 
606  #endif // MCMD_PERTURB
607 
609 
613  int id() const;
614 
618  Simulation& simulation() const;
619 
623  Boundary& boundary() const;
624 
628  EnergyEnsemble& energyEnsemble() const;
629 
633  BoundaryEnsemble& boundaryEnsemble() const;
634 
638  FileMaster& fileMaster() const;
639 
643  bool isCopy() const;
644 
648  virtual bool isValid() const;
649 
651 
652  protected:
653 
657  Boundary& maxBoundary() const;
658 
662  virtual ConfigIo* newDefaultConfigIo();
663 
667  virtual Factory<ConfigIo>* newDefaultConfigIoFactory();
668 
672  virtual Factory<TrajectoryReader>* newDefaultTrajectoryReaderFactory();
673 
674  #ifdef MCMD_PERTURB
675 
679  { return 0; }
680 
686  void readPerturbation(std::istream& in);
687 
693  void loadPerturbation(Serializable::IArchive& ar);
694 
700  void savePerturbation(Serializable::OArchive& ar);
701 
702  #ifdef UTIL_MPI
703 
708  void readReplicaMove(std::istream& in);
709 
715  void loadReplicaMove(Serializable::IArchive& ar);
716 
722  void saveReplicaMove(Serializable::OArchive& ar);
723  #endif // UTIL_MPI
724  #endif // MCMD_PERTURB
725 
738  void allocateMoleculeSets();
739 
751  void readFileMaster(std::istream& in);
752 
758  void loadFileMaster(Serializable::IArchive& ar);
759 
765  void saveFileMaster(Serializable::OArchive& ar);
766 
772  void readPotentialStyles(std::istream& in);
773 
779  void loadPotentialStyles(Serializable::IArchive& ar);
780 
786  void savePotentialStyles(Serializable::OArchive& ar);
787 
793  void readEnsembles(std::istream& in);
794 
800  void loadEnsembles(Serializable::IArchive& ar);
801 
807  void saveEnsembles(Serializable::OArchive& ar);
808 
809  #ifdef MCMD_LINK
810 
815  void readLinkMaster(std::istream& in);
816 
822  void loadLinkMaster(Serializable::IArchive& ar);
823 
829  void saveLinkMaster(Serializable::OArchive& ar);
830  #endif
831 
832  #ifdef SIMP_TETHER
833 
838  void readTetherMaster(std::istream& in);
839 
845  void loadTetherMaster(Serializable::IArchive& ar);
846 
852  void saveTetherMaster(Serializable::OArchive& ar);
853  #endif // SIMP_TETHER
854 
855  private:
856 
863  DArray<MoleculeSet>* moleculeSetsPtr_;
864 
866  Boundary* boundaryPtr_;
867 
868  #ifdef MCMD_LINK
869  LinkMaster* linkMasterPtr_;
871  #endif
872 
873  #ifdef SIMP_TETHER
874  TetherMaster* tetherMasterPtr_;
876  #endif
877 
879  Simulation* simulationPtr_;
880 
882  EnergyEnsemble* energyEnsemblePtr_;
883 
885  BoundaryEnsemble* boundaryEnsemblePtr_;
886 
887  #ifndef SIMP_NOPAIR
888  PairFactory* pairFactoryPtr_;
890  #endif
891 
892  #ifdef SIMP_BOND
893  Factory<BondPotential>* bondFactoryPtr_;
895  #endif
896 
897  #ifdef SIMP_ANGLE
898  Factory<AnglePotential>* angleFactoryPtr_;
900  #endif
901 
902  #ifdef SIMP_DIHEDRAL
903  Factory<DihedralPotential>* dihedralFactoryPtr_;
905  #endif
906 
907  #ifdef SIMP_COULOMB
908  CoulombFactory* coulombFactoryPtr_;
910  #endif
911 
912  #ifdef SIMP_EXTERNAL
913  Factory<ExternalPotential>* externalFactoryPtr_;
915  #endif
916 
917  #ifdef SIMP_SPECIAL
918  SpecialFactory* specialFactoryPtr_;
920  #endif
921 
922  #ifdef MCMD_LINK
923  Factory<BondPotential>* linkFactoryPtr_;
925  #endif
926 
927  #ifdef SIMP_TETHER
928  TetherFactory* tetherFactoryPtr_;
930  #endif
931 
933  ConfigIo* configIoPtr_;
934 
936  Factory<ConfigIo>* configIoFactoryPtr_;
937 
939  Factory<TrajectoryReader>* trajectoryReaderFactoryPtr_;
940 
942  FileMaster* fileMasterPtr_;
943 
944  #ifdef MCMD_PERTURB
945  Perturbation* perturbationPtr_;
947 
949  Factory<Perturbation>* perturbationFactoryPtr_;
950 
951  #ifdef UTIL_MPI
952  ReplicaMove* replicaMovePtr_;
954 
956  bool hasReplicaMove_;
957 
958  #endif // UTIL_MPI
959  #endif // MCMD_PERTURB
960  #ifndef SIMP_NOPAIR
961  std::string pairStyle_;
963  #endif
964 
965  #ifdef SIMP_BOND
966  std::string bondStyle_;
968  #endif
969 
970  #ifdef SIMP_ANGLE
971  std::string angleStyle_;
973  #endif
974 
975  #ifdef SIMP_DIHEDRAL
976  std::string dihedralStyle_;
978  #endif
979 
980  #ifdef SIMP_COULOMB
981  std::string coulombStyle_;
983  #endif
984 
985  #ifdef SIMP_EXTERNAL
986  std::string externalStyle_;
988  #endif
989 
990  #ifdef SIMP_SPECIAL
991  std::string specialStyle_;
993  #endif
994 
995  #ifdef MCMD_LINK
996  std::string linkStyle_;
998  #endif
999 
1000  #ifdef SIMP_TETHER
1001  std::string tetherStyle_;
1003  #endif
1004 
1006  int id_;
1007 
1009  bool isCopy_;
1010 
1012  bool createdFileMaster_;
1013 
1014  #ifdef MCMD_PERTURB
1015  bool expectPerturbationParam_;
1017 
1019  bool createdPerturbation_;
1020 
1022  bool createdPerturbationFactory_;
1023 
1024  #ifdef UTIL_MPI
1025  bool createdReplicaMove_;
1027  #endif // ifdef UTIL_MPI
1028  #endif // ifdef MCMD_PERTURB
1029 
1031  std::set<MoleculeSetObserver*> observers_;
1032 
1034  void notifyMoleculeSetObservers() const;
1035 
1036  //friends:
1037 
1038  friend class SystemInterface;
1039  friend class ::SystemTest;
1040 
1041  };
1042 
1043 
1044  // Inline functions
1045 
1046  /*
1047  * Get integer Id for this System.
1048  */
1049  inline int System::id() const
1050  { return id_; }
1051 
1052  /*
1053  * Get the parent Simulation by reference.
1054  */
1055  inline Simulation& System::simulation() const
1056  {
1057  assert(simulationPtr_);
1058  return *simulationPtr_;
1059  }
1060 
1061  /*
1062  * Get the Boundary by reference.
1063  */
1064  inline Boundary& System::boundary() const
1065  {
1066  assert(boundaryPtr_);
1067  return *boundaryPtr_;
1068  }
1069 
1070  #ifdef MCMD_LINK
1071  /*
1072  * Get the LinkMaster by reference.
1073  */
1074  inline LinkMaster& System::linkMaster() const
1075  {
1076  assert(linkMasterPtr_);
1077  return *linkMasterPtr_;
1078  }
1079  #endif
1080 
1081  #ifdef SIMP_TETHER
1082  /*
1083  * Get the TetherMaster by reference.
1084  */
1085  inline TetherMaster& System::tetherMaster() const
1086  {
1087  assert(tetherMasterPtr_);
1088  return *tetherMasterPtr_;
1089  }
1090  #endif
1091 
1092  /*
1093  * Get the EnergyEnsemble by reference.
1094  */
1095  inline EnergyEnsemble& System::energyEnsemble() const
1096  {
1097  assert(energyEnsemblePtr_);
1098  return *energyEnsemblePtr_;
1099  }
1100 
1101  /*
1102  * Get the BoundaryEnsemble by reference.
1103  */
1104  inline BoundaryEnsemble& System::boundaryEnsemble() const
1105  {
1106  assert(boundaryEnsemblePtr_);
1107  return *boundaryEnsemblePtr_;
1108  }
1109 
1110  /*
1111  * Get the FileMaster by reference.
1112  */
1113  inline FileMaster& System::fileMaster() const
1114  {
1115  assert(fileMasterPtr_);
1116  return *fileMasterPtr_;
1117  }
1118 
1119  /*
1120  * Was this System instantiated with the copy constructor?
1121  */
1122  inline bool System::isCopy() const
1123  { return isCopy_; }
1124 
1125  /*
1126  * Get the number of molecules of a specific Species in this System.
1127  */
1128  inline int System::nMolecule(int speciesId) const
1129  {
1130  assert(moleculeSetsPtr_);
1131  return (*moleculeSetsPtr_)[speciesId].size();
1132  }
1133 
1134  /*
1135  * Get a specific molecule of a specific Species.
1136  */
1137  inline Molecule& System::molecule(int speciesId, int moleculeId)
1138  {
1139  assert(moleculeSetsPtr_);
1140  return (*moleculeSetsPtr_)[speciesId][moleculeId];
1141  }
1142 
1143  /*
1144  * Initialize a MoleculeIterator for molecules of one Species.
1145  */
1146  inline
1147  void System::begin(int speciesId, MoleculeIterator& iterator)
1148  {
1149  assert(moleculeSetsPtr_);
1150  (*moleculeSetsPtr_)[speciesId].begin(iterator);
1151  }
1152 
1153  /*
1154  * Initialize a MoleculeIterator for molecules of one Species.
1155  */
1156  inline
1157  void System::begin(int speciesId, ConstMoleculeIterator& iterator) const
1158  {
1159  assert(moleculeSetsPtr_);
1160  (*moleculeSetsPtr_)[speciesId].begin(iterator);
1161  }
1162 
1163  #ifdef MCMD_PERTURB
1164 
1167  inline bool System::expectPerturbation() const
1168  { return expectPerturbationParam_; }
1169 
1173  inline Factory<Perturbation>& System::perturbationFactory()
1174  { return *perturbationFactoryPtr_; }
1175 
1176  /*
1177  * Does this system have an associated Perturbation?
1178  */
1179  inline bool System::hasPerturbation() const
1180  { return perturbationPtr_; }
1181 
1182  /*
1183  * Get the Perturbation by reference.
1184  */
1185  inline Perturbation& System::perturbation() const
1186  {
1187  assert(perturbationPtr_);
1188  return *perturbationPtr_;
1189  }
1190 
1191  #ifdef UTIL_MPI
1192  /*
1193  * Does this system have an associated ReplicaMove?
1194  */
1195  inline bool System::hasReplicaMove() const
1196  { return replicaMovePtr_; }
1197 
1198  /*
1199  * Get the ReplicaMove by reference.
1200  */
1201  inline ReplicaMove& System::replicaMove() const
1202  {
1203  assert(replicaMovePtr_);
1204  return *replicaMovePtr_;
1205  }
1206  #endif // UTIL_MPI
1207  #endif // MCMD_PERTURB
1208 
1209  /*
1210  * Subscribe to moleculeSet change signal.
1211  */
1212  inline void System::subscribeMoleculeSetChange(MoleculeSetObserver& observer)
1213  { observers_.insert(&observer); }
1214 
1215  /*
1216  * Unsubscribe from moleculeSet change signal.
1217  */
1218  inline void System::unsubscribeMoleculeSetChange(MoleculeSetObserver& observer)
1219  { observers_.erase(&observer); }
1220 
1221  /*
1222  * Notifiy all observers
1223  */
1224  inline void System::notifyMoleculeSetObservers() const
1225  {
1226  std::set<MoleculeSetObserver*>::iterator itr;
1227 
1228  for ( itr = observers_.begin();
1229  itr != observers_.end(); itr++ )
1230  (*itr)->notifyMoleculeSetChanged();
1231  }
1232 
1233 }
1234 #endif
PArrayIterator< Molecule > MoleculeIterator
Iterator for a MoleculeSet.
Definition: System.h:126
Replica exchange Monte Carlo move using Gibbs sampling.
Definition: ReplicaMove.h:63
Interface for a Angle Interaction.
Observer interface.
Definition: System.h:49
An interface to a System.
An orthorhombic periodic unit cell.
ArraySet< Molecule > MoleculeSet
A set of molecules of one Species in a System.
Definition: System.h:123
Statistical ensemble for changes in the periodic unit cell size.
Factory for subclasses MdPairPotential or McPairPotential.
A set of interacting Molecules enclosed by a Boundary.
Definition: System.h:115
Forward iterator for a PArray.
File containing preprocessor macros for error handling.
Classes used by all simpatico molecular simulations.
The main object in a simulation, which coordinates others.
Interface for a Dihedral Potential.
Saving / output archive for binary ostream.
A statistical ensemble for energy.
Abstract External Potential class.
A container for pointers to a subset of elements of an associated array.
Definition: ArraySet.h:46
Utility classes for scientific computation.
Definition: accumulators.mod:1
Trajectory file reader (base class).
Forward iterator for a PArray.
Definition: ArraySet.h:19
Model of parameter dependence in a free energy perturbation theory.
Definition: Perturbation.h:39
Factory for CoulombPotential objects.
Manages all Link objects in a System.
Definition: LinkMaster.h:39
A FileMaster manages input and output files for a simulation.
Definition: FileMaster.h:142
Dynamically allocatable contiguous array template.
Definition: DArray.h:31
Saving archive for binary istream.
ConstPArrayIterator< Molecule > ConstMoleculeIterator
Const Iterator for a MoleculeSet.
Definition: System.h:129
Single-processor Monte Carlo (MC) and molecular dynamics (MD).
Factory for specialized subclasses of SpecialPotential.
Abstract Bond Potential class.
A physical molecule (a set of covalently bonded Atoms).
An object that can read multiple parameters from file.
System configuration file reader and writer.
virtual Factory< Perturbation > * newDefaultPerturbationFactory()
Return a pointer to the default perturbation Factory.
Definition: System.h:678