Simpatico  v1.10
McCommandManager.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 "McCommandManager.h"
9 #include "McSimulation.h"
10 #include "mc_potentials.h"
11 #include <mcMd/commands/McCommandFactory.h>
12 
13 #include <util/format/Str.h>
14 #include <util/format/Dbl.h>
15 
16 namespace McMd
17 {
18 
19  using namespace Util;
20 
21  // Constructor.
23  : CommandManager(),
24  simulationPtr_(&simulation),
25  systemPtr_(&simulation.system())
26  {
27  // Note: No setClassname("MdCommandManager");
28  // This class retains name CommandManager set by base class.
29  }
30 
31  // Constructor.
34  : CommandManager(),
35  simulationPtr_(&simulation),
36  systemPtr_(&system)
37  {}
38 
39  // Destructor.
41  {}
42 
45  { return new McCommandFactory(*simulationPtr_, *systemPtr_); }
46 
47  // Attempt to read one standard (built-in) command.
48  bool
49  McCommandManager::readStandardCommand(std::string name, std::istream& in)
50  {
51  std::string filename;
52  bool success = true;
53 
54  if (name == "SET_CONFIG_IO") {
55  std::string classname;
56  in >> classname;
57  Log::file() << Str(classname, 15) << std::endl;
58  system().setConfigIo(classname);
59  } else
60  if (name == "READ_CONFIG") {
61  in >> filename;
62  Log::file() << Str(filename, 15) << std::endl;
63  system().readConfig(filename);
64  } else
65  if (name == "SIMULATE") {
66  int endStep;
67  in >> endStep;
68  Log::file() << " " << endStep << std::endl;
69  bool isContinuation = false;
70  simulation().simulate(endStep, isContinuation);
71  } else
72  if (name == "CONTINUE") {
73  if (simulation().iStep() == 0) {
74  UTIL_THROW("Attempt to continue when iStep() == 0");
75  }
76  int endStep;
77  in >> endStep;
78  Log::file() << Int(endStep, 15) << std::endl;
79  bool isContinuation = true;
80  simulation().simulate(endStep, isContinuation);
81  } else
82  if (name == "ANALYZE_CONFIGS") {
83  int min, max;
84  in >> min >> max >> filename;
85  Log::file() << " " << min << " " << max
86  << " " << filename << std::endl;
87  simulation().analyzeConfigs(min, max, filename);
88  } else
89  if (name == "ANALYZE_TRAJECTORY") {
90  std::string classname;
91  std::string filename;
92  int min, max;
93  in >> min >> max >> classname >> filename;
94  Log::file() << " " << Str(classname,15)
95  << " " << Str(filename, 15)
96  << std::endl;
97  simulation().analyzeTrajectory(min, max, classname, filename);
98  } else
99  if (name == "WRITE_CONFIG") {
100  in >> filename;
101  Log::file() << Str(filename, 15) << std::endl;
102  system().writeConfig(filename);
103  } else
104  if (name == "WRITE_PARAM") {
105  in >> filename;
106  Log::file() << " " << filename << std::endl;
107  simulation().writeParam(filename);
108  } else
109  if (name == "GENERATE_MOLECULES") {
110  DArray<double> diameters;
111  DArray<int> capacities;
112  int nAtomType = simulation().nAtomType();
113  int nSpecies = simulation().nSpecies();
114  diameters.allocate(nAtomType);
115  capacities.allocate(nSpecies);
116 
117  // Parse name
118  in >> system().boundary();
119  Log::file() << "\n Boundary: " << system().boundary();
120  Label capacityLabel("Capacities:");
121  in >> capacityLabel;
122  Log::file() << "\n Capacities: ";
123  for (int iSpecies = 0; iSpecies < nSpecies; ++iSpecies) {
124  in >> capacities[iSpecies];
125  Log::file() << " " << capacities[iSpecies];
126  }
127  Label diameterLabel("Diameters:");
128  in >> diameterLabel;
129  Log::file() << "\n Diameters: ";
130  for (int iType=0; iType < nAtomType; iType++) {
131  in >> diameters[iType];
132  Log::file() << " " << diameters[iType];
133  }
134  Log::file() << std::endl;
135 
136  system().generateMolecules(capacities, diameters);
137 
138  } else
139  if (name == "DEFORM_CELL") {
140 
141  // Read in configuration from file
142  in >> filename;
143  Log::file() << Str(filename, 15) << std::endl;
144  system().readConfig(filename);
145 
146  int nSpecies = simulation().nSpecies();
147  System::MoleculeIterator molIter;
148  Molecule::AtomIterator atomIter;
149  for (int iSpec=0; iSpec < nSpecies; ++iSpec) {
150  system().begin(iSpec, molIter);
151  for ( ; molIter.notEnd(); ++molIter) {
152  molIter->begin(atomIter);
153  for ( ; atomIter.notEnd(); ++atomIter) {
154  Vector cartPosition, genPosition;
155  cartPosition = atomIter->position();
156  system().boundary().transformCartToGen(cartPosition, genPosition);
157  atomIter->position() = genPosition;
158  }
159  }
160  }
161 
162  // Read in new boundary
163  in >> system().boundary();
164  Log::file() << " " << system().boundary();
165  Log::file() << std::endl;
166 
167  for (int iSpec=0; iSpec < nSpecies; ++iSpec) {
168  system().begin(iSpec, molIter);
169  for ( ; molIter.notEnd(); ++molIter) {
170  molIter->begin(atomIter);
171  for ( ; atomIter.notEnd(); ++atomIter) {
172  Vector cartPosition, genPosition;
173  genPosition = atomIter->position();
174  system().boundary().transformGenToCart(genPosition, cartPosition);
175  atomIter->position() = cartPosition;
176  }
177  }
178  }
179 
180  // Write out configuration to file
181  in >> filename;
182  Log::file() << Str(filename, 15) << std::endl;
183  system().writeConfig(filename);
184 
185  #ifndef SIMP_NOPAIR
186  // Generate cell list
188  #endif
189 
190  } else
191  #ifndef UTIL_MPI
192  #ifndef SIMP_NOPAIR
193  if (name == "SET_PAIR") {
194  std::string paramName;
195  int typeId1, typeId2;
196  double value;
197  in >> paramName >> typeId1 >> typeId2 >> value;
198  Log::file() << " " << paramName
199  << " " << typeId1 << " " << typeId2
200  << " " << value << std::endl;
202  .set(paramName, typeId1, typeId2, value);
203  } else
204  #endif
205  #ifdef SIMP_BOND
206  if (name == "SET_BOND") {
207  std::string paramName;
208  int typeId;
209  double value;
210  in >> paramName >> typeId >> value;
211  Log::file() << " " << paramName << " " << typeId
212  << " " << value << std::endl;
213  system().bondPotential().set(paramName, typeId, value);
214  } else
215  #endif
216  #ifdef SIMP_ANGLE
217  if (name == "SET_ANGLE") {
218  std::string paramName;
219  int typeId;
220  double value;
221  in >> paramName >> typeId >> value;
222  Log::file() << " " << paramName << " " << typeId
223  << " " << value << std::endl;
224  system().anglePotential().set(paramName, typeId, value);
225  } else
226  #endif
227  #ifdef SIMP_DIHEDRAL
228  if (name == "SET_DIHEDRAL") {
229  std::string paramName;
230  int typeId;
231  double value;
232  in >> paramName >> typeId >> value;
233  Log::file() << " " << paramName << " " << typeId
234  << " " << value << std::endl;
235  system().dihedralPotential().set(paramName, typeId, value);
236  } else
237  #endif // ifdef SIMP_DIHEDRAL
238  #endif // ifndef UTIL_MPI
239  {
240  // Command name not recognized
241  success = false;
242  }
243  return success;
244  }
245 
246 }
Manager for Command objects in an MdSimulation.
A System for use in a Markov chain Monte Carlo simulation.
Definition: McSystem.h:52
McSimulation & simulation() const
Get parent McSimulation by reference.
A Vector is a Cartesian vector.
Definition: Vector.h:75
virtual void set(std::string name, int i, int j, double value)=0
Modify a parameter, identified by a string.
void buildCellList()
Build the CellList with current configuration.
virtual Util::Factory< Command > * newDefaultFactory() const
Create and return pointer to a new McCommandFactory object.
void begin(int speciesId, MoleculeIterator &iterator)
Initialize an iterator for molecules of one species in this System.
Definition: System.h:1147
Include this file to include all MC potential energy classes at once.
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
void analyzeConfigs(int min, int max, std::string basename)
Read and analyze a sequence of configuration files.
virtual bool readStandardCommand(std::string command, std::istream &in)
Attempt to read one of the standard commands.
void setConfigIo(std::string &classname)
Create a new configuration file reader/writer.
Definition: System.cpp:909
virtual void generateMolecules(Array< int > const &capacities, Array< double > const &diameters)
Generate molecules for all species.
Definition: McSystem.cpp:415
virtual void readConfig(std::istream &in)
Read system configuration from file.
Definition: McSystem.cpp:393
A Monte-Carlo simulation of one McSystem.
Definition: McSimulation.h:32
#define UTIL_THROW(msg)
Macro for throwing an Exception, reporting function, file and line number.
Definition: global.h:51
bool notEnd() const
Is the current pointer not at the end of the PArray?
Utility classes for scientific computation.
Definition: accumulators.mod:1
virtual void set(std::string name, int type, double value)=0
Modify an interaction parameter, identified by a string.
Wrapper for an int, for formatted ostream output.
Definition: Int.h:36
Forward iterator for an Array or a C array.
Definition: ArrayIterator.h:39
Forward iterator for a PArray.
Definition: ArraySet.h:19
void transformGenToCart(const Vector &Rg, Vector &Rc) const
Transform Vector of generalized coordinates to Cartesian Vector.
CommandFactory for an McSimulation.
virtual ~McCommandManager()
Destructor.
McCommandManager(McSimulation &simulation)
Constructor.
McPairPotential & pairPotential() const
Return the McPairPotential by reference.
Definition: McSystem.h:388
virtual void set(std::string name, int type, double value)=0
Modify an interaction parameter, identified by a string.
A label string in a file format.
Definition: Label.h:36
static std::ostream & file()
Get log ostream by reference.
Definition: Log.cpp:57
Boundary & boundary() const
Get the Boundary by reference.
Definition: System.h:1064
Single-processor Monte Carlo (MC) and molecular dynamics (MD).
int nSpecies() const
Get the number of Species in this Simulation.
virtual void set(std::string name, int type, double value)=0
Modify an interaction parameter, identified by a string.
Wrapper for a std::string, for formatted ostream output.
Definition: Str.h:36
McSystem & system() const
Get associated McSystem by reference.
AnglePotential & anglePotential() const
Return AnglePotential by reference.
Definition: McSystem.h:422
void allocate(int capacity)
Allocate the underlying C array.
Definition: DArray.h:191
void analyzeTrajectory(int min, int max, std::string classname, std::string filename)
Read and analyze a trajectory file.
int nAtomType() const
Get the number of atom types.
void writeConfig(std::ostream &out)
Write system configuration to a specified ostream.
Definition: System.cpp:836
void simulate(int endStep, bool isContinuation=false)
Run an MC simulation of specified length.
void writeParam(std::string filename)
Open output, write and close an output parameter file.
void transformCartToGen(const Vector &Rc, Vector &Rg) const
Transform Cartesian Vector to scaled / generalized coordinates.
DihedralPotential & dihedralPotential() const
Return the DihedralPotential by reference.
Definition: McSystem.h:439