Simpatico  v1.10
MdCommandManager.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 "MdCommandManager.h"
9 #include "MdSimulation.h"
10 #include "md_potentials.h"
11 #include <mcMd/commands/MdCommandFactory.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 command 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 
43  // Return pointer to a new CommandFactory.
45  { return new MdCommandFactory(simulation(), system()); }
46 
47  // Attempt to read one standard (built-in) command.
48  bool
49  MdCommandManager::readStandardCommand(std::string name, std::istream& in)
50  {
51  std::string filename;
52  bool success = true;
53 
54  if (name == "READ_CONFIG") {
55  in >> filename;
56  Log::file() << Str(filename, 15) << std::endl;
57  system().readConfig(filename);
58  } else
59  if (name == "THERMALIZE") {
60  double temperature;
61  in >> temperature;
62  Log::file() << Dbl(temperature, 15, 6) << std::endl;
63  system().setBoltzmannVelocities(temperature);
65  } else
66  if (name == "SIMULATE") {
67  int endStep;
68  in >> endStep;
69  Log::file() << Int(endStep, 15) << std::endl;
70  bool isContinuation = false;
71  simulation().simulate(endStep, isContinuation);
72  } else
73  if (name == "CONTINUE") {
74  if (simulation().iStep() == 0) {
75  UTIL_THROW("Attempt to continue simulation when iStep_ == 0");
76  }
77  int endStep;
78  in >> endStep;
79  Log::file() << Int(endStep, 15) << std::endl;
80  bool isContinuation = true;
81  simulation().simulate(endStep, isContinuation);
82  } else
83  if (name == "ANALYZE_CONFIGS") {
84  int min, max;
85  in >> min >> max >> filename;
86  Log::file() << Int(min, 15) << Int(max, 15)
87  << Str(filename, 20) << std::endl;
88  simulation().analyzeConfigs(min, max, filename);
89  } else
90  if (name == "WRITE_CONFIG") {
91  in >> filename;
92  Log::file() << Str(filename, 15) << std::endl;
93  system().writeConfig(filename);
94  } else
95  if (name == "WRITE_PARAM") {
96  in >> filename;
97  Log::file() << Str(filename, 15) << std::endl;
98  simulation().writeParam(filename);
99  } else
100  if (name == "SET_CONFIG_IO") {
101  std::string classname;
102  in >> classname;
103  Log::file() << Str(classname, 15) << std::endl;
104  system().setConfigIo(classname);
105  } else
106  if (name == "ANALYZE_TRAJECTORY") {
107  std::string classname;
108  std::string filename;
109  int min, max;
110  in >> min >> max >> classname >> filename;
111  Log::file() << " " << Str(classname,15)
112  << " " << Str(filename, 15)
113  << std::endl;
114  simulation().analyzeTrajectory(min, max, classname, filename);
115  } else
116  if (name == "GENERATE_MOLECULES") {
117  DArray<double> diameters;
118  DArray<int> capacities;
119  int nAtomType = simulation().nAtomType();
120  int nSpecies = simulation().nSpecies();
121  diameters.allocate(nAtomType);
122  capacities.allocate(nSpecies);
123 
124  // Parse name
125  in >> system().boundary();
126  Log::file() << " " << system().boundary();
127  Label capacityLabel("Capacities:");
128  in >> capacityLabel;
129  for (int iSpecies = 0; iSpecies < nSpecies; ++iSpecies) {
130  in >> capacities[iSpecies];
131  Log::file() << " " << capacities[iSpecies];
132  }
133  Label diameterLabel("Diameters:");
134  in >> diameterLabel;
135  for (int iType=0; iType < nAtomType; iType++) {
136  in >> diameters[iType];
137  Log::file() << " " << diameters[iType];
138  }
139  Log::file() << std::endl;
140 
141  system().generateMolecules(capacities, diameters);
142  } else
143  #ifndef UTIL_MPI
144  #ifndef SIMP_NOPAIR
145  if (name == "SET_PAIR") {
146  std::string paramName;
147  int typeId1, typeId2;
148  double value;
149  in >> paramName >> typeId1 >> typeId2 >> value;
150  Log::file() << " " << paramName
151  << " " << typeId1 << " " << typeId2
152  << " " << value << std::endl;
154  .set(paramName, typeId1, typeId2, value);
155  } else
156  #endif
157  #ifdef SIMP_BOND
158  if (name == "SET_BOND") {
159  std::string paramName;
160  int typeId;
161  double value;
162  in >> paramName >> typeId >> value;
163  Log::file() << " " << paramName << " " << typeId
164  << " " << value << std::endl;
165  system().bondPotential().set(paramName, typeId, value);
166  } else
167  #endif
168  #ifdef SIMP_ANGLE
169  if (name == "SET_ANGLE") {
170  std::string paramName;
171  int typeId;
172  double value;
173  in >> paramName >> typeId >> value;
174  Log::file() << " " << paramName << " " << typeId
175  << " " << value << std::endl;
176  system().anglePotential().set(paramName, typeId, value);
177  } else
178  #endif
179  #ifdef SIMP_DIHEDRAL
180  if (name == "SET_DIHEDRAL") {
181  std::string paramName;
182  int typeId;
183  double value;
184  in >> paramName >> typeId >> value;
185  Log::file() << " " << paramName << " " << typeId
186  << " " << value << std::endl;
187  system().dihedralPotential().set(paramName, typeId, value);
188  } else
189  #endif
190  #endif // ifndef UTIL_MPI
191  {
192  // Failed to match command name
193  success = false;
194  }
195  return success;
196  }
197 
198 }
Include this file to include all MD potentials at once.
Manager for Command objects in an MdSimulation.
DihedralPotential & dihedralPotential() const
Return DihedralPotential by reference.
Definition: MdSystem.h:571
virtual void set(std::string name, int i, int j, double value)=0
Modify a parameter, identified by a string.
void generateMolecules(Array< int > const &capacities, Array< double > const &diameters)
Generate molecules for all species.
Definition: MdSystem.cpp:695
Vector removeDriftVelocity()
Subtract average velocity from all atomic velocities.
Definition: MdSystem.cpp:825
void simulate(int endStep, bool isContinuation=false)
Run an MD simulation of specified length.
void analyzeConfigs(int min, int max, std::string basename)
Read and analyze a sequence of configuration files.
void setConfigIo(std::string &classname)
Create a new configuration file reader/writer.
Definition: System.cpp:909
Wrapper for a double precision number, for formatted ostream output.
Definition: Dbl.h:39
virtual bool readStandardCommand(std::string command, std::istream &in)
Attempt to read one of the standard built-in commands.
void analyzeTrajectory(int min, int max, std::string classname, std::string filename)
Read and analyze a trajectory file.
MdPairPotential & pairPotential() const
Return MdPairPotential by reference.
Definition: MdSystem.h:520
#define UTIL_THROW(msg)
Macro for throwing an Exception, reporting function, file and line number.
Definition: global.h:51
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
virtual void set(std::string name, int type, double value)=0
Modify an interaction parameter, identified by a string.
virtual Util::Factory< Command > * newDefaultFactory() const
Create and return pointer to a new MdCommandFactory object.
AnglePotential & anglePotential() const
Return AnglePotential by reference.
Definition: MdSystem.h:554
Wrapper for an int, for formatted ostream output.
Definition: Int.h:36
MdSimulation & simulation() const
Get parent MdSimulation by reference.
virtual ~MdCommandManager()
Destructor.
CommandFactory for an MdSimulation.
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.
MdCommandManager(MdSimulation &simulation)
Constructor.
MdSystem & system() const
Get associated MdSystem by reference.
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
A System for Molecular Dynamics simulation.
Definition: MdSystem.h:68
void allocate(int capacity)
Allocate the underlying C array.
Definition: DArray.h:191
virtual void readConfig(std::istream &in)
Read system configuration from file.
Definition: MdSystem.cpp:655
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
BondPotential & bondPotential() const
Return BondPotential by reference.
Definition: MdSystem.h:537
A molecular dynamics simulation of a single MdSystem.
Definition: MdSimulation.h:26
void writeParam(std::string filename)
Open output, write and close an output parameter file.