Simpatico  v1.10
MdSimulation.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 <mcMd/mdSimulation/MdSimulation.h>
9 #include <mcMd/mdIntegrators/MdIntegrator.h>
10 #include <mcMd/generators/Generator.h>
11 #include <mcMd/generators/generatorFactory.h>
12 #include <mcMd/analyzers/Analyzer.h>
13 #include <mcMd/trajectory/TrajectoryReader.h>
14 #include <mcMd/potentials/pair/MdPairPotential.h>
15 #ifdef SIMP_BOND
16 #include <mcMd/potentials/bond/BondPotential.h>
17 #endif
18 #ifdef SIMP_ANGLE
19 #include <mcMd/potentials/angle/AnglePotential.h>
20 #endif
21 #ifdef SIMP_DIHEDRAL
22 #include <mcMd/potentials/dihedral/DihedralPotential.h>
23 #endif
24 #include <simp/species/Species.h>
25 #include <util/format/Int.h>
26 #include <util/format/Dbl.h>
27 #include <util/format/Str.h>
28 #include <util/misc/Log.h>
29 #include <util/archives/Serializable_includes.h>
30 #include <util/misc/ioUtil.h>
31 #include <util/misc/Timer.h>
32 
33 #include <sstream>
34 #include <iostream>
35 #include <unistd.h>
36 
37 namespace McMd
38 {
39 
40  using namespace Util;
41  using namespace Simp;
42 
43  #ifdef UTIL_MPI
44  /*
45  * Constructor.
46  */
47  MdSimulation::MdSimulation(MPI::Intracomm& communicator)
48  : Simulation(communicator),
49  system_(),
50  mdAnalyzerManager_(*this),
51  mdCommandManager_(*this),
52  saveFileName_(),
53  saveInterval_(0),
54  isInitialized_(false),
55  isRestarting_(false)
56  {
57  setClassName("MdSimulation");
58  system_.setId(0);
59  system_.setSimulation(*this);
60  system_.setFileMaster(fileMaster());
61 
62  #if 0
63  // Instantiate Manager objects
64  mdAnalyzerManagerPtr_ = new MdAnalyzerManager(*this);
65  UTIL_CHECK(mdAnalyzerManagerPtr_);
66  mdCommandManagerPtr_ = new MdCommandManager(*this);
67  UTIL_CHECK(mdCommandManagerPtr_);
68  #endif
69 
70  // Pass pointers to managers to Simulation base class
71  setAnalyzerManager(&mdAnalyzerManager_);
72  setCommandManager(&mdCommandManager_);
73  }
74  #endif
75 
76  /*
77  * Constructor.
78  */
80  : Simulation(),
81  system_(),
82  mdAnalyzerManager_(*this),
83  mdCommandManager_(*this),
84  saveFileName_(),
85  saveInterval_(0),
86  isInitialized_(false),
87  isRestarting_(false)
88  {
89  setClassName("MdSimulation");
90  system_.setId(0);
91  system_.setSimulation(*this);
92  system_.setFileMaster(fileMaster());
93 
94  #if 0
95  // Instantiate Manager objects
96  mdAnalyzerManagerPtr_ = new MdAnalyzerManager(*this);
97  UTIL_CHECK(mdAnalyzerManagerPtr_);
98  mdCommandManagerPtr_ = new MdCommandManager(*this);
99  UTIL_CHECK(mdCommandManagerPtr_);
100  #endif
101 
102  // Pass pointers to managers to Simulation base class
103  setAnalyzerManager(&mdAnalyzerManager_);
104  setCommandManager(&mdCommandManager_);
105  }
106 
107  /*
108  * Destructor.
109  */
111  {
112  #if 0
113  if (mdAnalyzerManagerPtr_) {
114  delete mdAnalyzerManagerPtr_;
115  }
116  if (mdCommandManagerPtr_) {
117  delete mdCommandManagerPtr_;
118  }
119  #endif
120  }
121 
122  /*
123  * Process command line options.
124  */
125  void MdSimulation::setOptions(int argc, char **argv)
126  {
127  bool qflag = false; // query compile time options
128  bool eflag = false; // echo parameter file
129  bool rFlag = false; // restart file
130  bool pFlag = false; // param file
131  bool cFlag = false; // command file
132  bool iFlag = false; // input prefix
133  bool oFlag = false; // output prefix
134  #ifdef MCMD_PERTURB
135  bool fflag = false; // free energy perturbation
136  #endif
137  char* rarg = 0;
138  char* pArg = 0;
139  char* cArg = 0;
140  char* iArg = 0;
141  char* oArg = 0;
142 
143  // Read and store all program arguments
144  int c;
145  opterr = 0;
146  while ((c = getopt(argc, argv, "qer:p:c:i:o:f")) != -1) {
147  switch (c) {
148  case 'q':
149  qflag = true;
150  break;
151  case 'e':
152  eflag = true;
153  break;
154  case 'r':
155  rFlag = true;
156  rarg = optarg;
157  break;
158  case 'p': // parameter file
159  pFlag = true;
160  pArg = optarg;
161  break;
162  case 'c': // command file
163  cFlag = true;
164  cArg = optarg;
165  break;
166  case 'i': // input prefix
167  iFlag = true;
168  iArg = optarg;
169  break;
170  case 'o': // output prefix
171  oFlag = true;
172  oArg = optarg;
173  break;
174  #ifdef MCMD_PERTURB
175  case 'f':
176  fflag = true;
177  break;
178  #endif
179  case '?': {
180  char optChar = optopt;
181  std::cout << "Unknown option -" << optChar << std::endl;
182  UTIL_THROW("Invalid command line option");
183  }
184  }
185  }
186 
187  // Apply requested options
188 
189  #ifndef UTIL_MPI
190  if (qflag) {
191  // Output list of enabled/disabled compile-time options.
193  }
194  #endif
195 
196  // Set flag to echo parameters as they are read.
197  if (eflag) {
199  }
200 
201  #ifdef MCMD_PERTURB
202  // Set to use a perturbation.
203  if (fflag) {
204 
205  if (rFlag) {
206  std::string msg("Error: Options -r and -f are incompatible.");
207  msg += "Existence of a perturbation is specified in restart file.";
208  UTIL_THROW(msg.c_str());
209  }
210 
211  // Set to expect perturbation in the param file.
213 
214  #ifdef UTIL_MPI
215  Util::Log::file() << "Set to read parameters from a single file"
216  << std::endl;
218  #endif
219 
220  }
221  #endif
222 
223  // If option -p, set parameter file name
224  if (pFlag) {
225  if (rFlag) {
226  UTIL_THROW("Cannot have both parameter and restart files");
227  }
228  fileMaster().setParamFileName(std::string(pArg));
229  }
230 
231  // If option -r, restart
232  if (rFlag) {
233  // Log::file() << "Reading restart file "
234  // << std::string(rarg) << std::endl;
235  isRestarting_ = true;
236  load(std::string(rarg));
237  }
238 
239  // The -c, -i, and -o options are applied after the -r option
240  // so that they override any paths set in the restart file.
241 
242  // If option -c, set command file name
243  if (cFlag) {
244  fileMaster().setCommandFileName(std::string(cArg));
245  }
246 
247  // If option -i, set path prefix for input files
248  if (iFlag) {
249  fileMaster().setInputPrefix(std::string(iArg));
250  }
251 
252  // If option -o, set path prefix for output files
253  if (oFlag) {
254  fileMaster().setOutputPrefix(std::string(oArg));
255  }
256 
257  }
258 
259  /*
260  * Read parameters from file.
261  */
262  void MdSimulation::readParameters(std::istream &in)
263  {
264  if (isInitialized_) {
265  UTIL_THROW("Error: Called readParam when already initialized");
266  }
267 
269 
270  readParamComposite(in, system_);
274 
275  // Parameters for writing restart files
276  saveInterval_ = 0;
277  readOptional<int>(in, "saveInterval", saveInterval_);
278  if (saveInterval_ > 0) {
279  read<std::string>(in, "saveFileName", saveFileName_);
280  }
281 
282  isValid();
283  isInitialized_ = true;
284  }
285 
286  /*
287  * Read default parameter file.
288  */
290  {
291  readParam(fileMaster().paramFile());
292  }
293 
294  /*
295  * Read parameter block, including begin and end.
296  */
297  void MdSimulation::readParam(std::istream &in)
298  {
299  if (isRestarting_) {
300  if (isInitialized_) {
301  return;
302  }
303  }
304  readBegin(in, className().c_str());
305  readParameters(in);
306  readEnd(in);
307  }
308 
309  /*
310  * Load parameters from an archive.
311  */
313  {
314  if (isInitialized_) {
315  UTIL_THROW("Error: Called loadParameters when already initialized");
316  }
317 
319  loadParamComposite(ar, system_);
322  loadParameter<int>(ar, "saveInterval", saveInterval_);
323  if (saveInterval_ > 0) {
324  loadParameter<std::string>(ar, "saveFileName", saveFileName_);
325  }
326 
327  system_.loadConfig(ar);
328  ar & iStep_;
329 
330  isValid();
331  isInitialized_ = true;
332  }
333 
334  /*
335  * Save parameters to an archive.
336  */
338  {
339  Simulation::save(ar);
340  system_.saveParameters(ar);
341  analyzerManager().save(ar);
342  commandManager().save(ar);
343  ar << saveInterval_;
344  if (saveInterval_ > 0) {
345  ar << saveFileName_;
346  }
347  system_.saveConfig(ar);
348  ar & iStep_;
349  }
350 
351  /*
352  * Read and implement commands in an input script.
353  */
354  void MdSimulation::readCommands(std::istream &in)
355  {
356  std::string command;
357  #ifndef UTIL_MPI
358  std::istream& inBuffer = in;
359  #else
360  std::stringstream inBuffer;
361  std::string line;
362  #endif
363 
364  bool readNext = true;
365  while (readNext) {
366 
367  #ifdef UTIL_MPI
368  if (!hasIoCommunicator() || isIoProcessor()) {
369  getNextLine(in, line);
370  }
371  if (hasIoCommunicator()) {
372  bcast<std::string>(communicator(), line, 0);
373  }
374  inBuffer.clear();
375  for (unsigned i=0; i < line.size(); ++i) {
376  inBuffer.put(line[i]);
377  }
378  #endif
379 
380  inBuffer >> command;
381  Log::file().setf(std::ios_base::left);
382  Log::file().width(15);
383  Log::file() << command;
384 
385  if (isRestarting_) {
386 
387  if (command == "RESTART") {
388  int endStep;
389  inBuffer >> endStep;
390  Log::file() << " " << iStep_ << " to "
391  << endStep << std::endl;
392  simulate(endStep, isRestarting_);
393  isRestarting_ = false;
394  } else {
395  UTIL_THROW("Missing RESTART command");
396  }
397 
398  } else {
399 
400  if (command == "FINISH") {
401  Log::file() << std::endl;
402  readNext = false;
403  } else {
404  bool success;
405  success = commandManager().readCommand(command, inBuffer);
406  if (!success) {
407  Log::file() << "Error: Unknown command " << std::endl;
408  readNext = false;
409  }
410  }
411 
412  }
413  }
414  }
415 
416  /*
417  * Read and implement commands from the default command file.
418  */
420  {
421  if (fileMaster().commandFileName().empty()) {
422  UTIL_THROW("Empty command file name");
423  }
424  readCommands(fileMaster().commandFile());
425  }
426 
427  /*
428  * Read and execute a single command.
429  */
430  bool
431  MdSimulation::readCommand(std::string command, std::istream& in)
432  { return commandManager().readCommand(command, in); }
433 
434  /*
435  * Run a simulation.
436  */
437  void MdSimulation::simulate(int endStep, bool isContinuation)
438  {
439  Timer timer;
440 
441  if (isContinuation) {
442  Log::file() << "Continuing simulation from iStep = "
443  << iStep_ << std::endl;
444  } else {
445  iStep_ = 0;
446  system().shiftAtoms();
447  #ifdef UTIL_COULOMB
448  if (system().hasCoulombPotential()) {
450  }
451  #endif
454  system_.mdIntegrator().setup();
455  }
456  int beginStep = iStep_;
457  int nStep = endStep - beginStep;
458 
459  #ifdef SIMP_NOPAIR
460  // When the pair potential is disabled, require that
461  // Analyzer::baseInterval > 0 to guarantee periodic
462  // shifting of atomic positions into primary cell.
464  #endif
465 
466  // Main loop
467  Log::file() << std::endl;
468  timer.start();
469  for ( ; iStep_ < endStep; ++iStep_) {
470 
471  // Sample scheduled analyzers
472  if (Analyzer::baseInterval > 0) {
473  if (iStep_ % Analyzer::baseInterval == 0) {
474  system().shiftAtoms();
476  }
477  }
478 
479  if (saveInterval_ > 0) {
480  if (iStep_ % saveInterval_ == 0) {
481  save(saveFileName_);
482  }
483  }
484 
485  // Take one MD step with the MdIntegrator
486  system_.mdIntegrator().step();
487  }
488  timer.stop();
489  double time = timer.time();
490  double rstep = double(nStep);
491 
492  // Shift final atomic positions
493  system().shiftAtoms();
494 
495  // Final analyzers and restart
496  if (Analyzer::baseInterval > 0) {
497  if (iStep_ % Analyzer::baseInterval == 0) {
499  }
500  }
501  if (saveInterval_ > 0) {
502  if (iStep_ % saveInterval_ == 0) {
503  save(saveFileName_);
504  }
505  }
506 
507  // Final analyzer output
509 
510  // Output timing results
511  Log::file() << std::endl;
512  Log::file() << "Time Statistics" << std::endl;
513  Log::file() << "endStep " << endStep << std::endl;
514  Log::file() << "nStep " << nStep << std::endl;
515  Log::file() << "run time "
516  << time << " sec" << std::endl;
517  Log::file() << "time / nStep "
518  << time / rstep << " sec" << std::endl;
519  Log::file() << "time / (nStep*nAtom) "
520  << time / (rstep*double(system().nAtom()))
521  << " sec" << std::endl;
522  Log::file() << std::endl;
523  Log::file() << std::endl;
524 
525  #ifndef SIMP_NOPAIR
526  Log::file() << "PairList Statistics" << std::endl;
527  Log::file() << "maxNPair "
529  << std::endl;
530  Log::file() << "maxNAtom "
532  << std::endl;
533  int buildCounter = system().pairPotential().pairList().buildCounter();
534  Log::file() << "buildCounter "
535  << buildCounter
536  << std::endl;
537  Log::file() << "steps / build "
538  << rstep/double(buildCounter)
539  << std::endl;
540  Log::file() << std::endl;
541  #endif
542 
543  }
544 
545  /*
546  * Read and analyze a sequence of configuration files.
547  */
548  void
549  MdSimulation::analyzeConfigs(int min, int max, std::string basename)
550  {
551  // Preconditions
552  UTIL_CHECK(min >= 0);
553  UTIL_CHECK(max > min);
555  UTIL_CHECK(analyzerManager().size() > 0);
556 
557  Timer timer;
558  std::string filename;
559  std::stringstream indexString;
560  std::ifstream configFile;
561  int nConfig;
562  nConfig = max - min + 1;
563 
564  // Main loop
565  Log::file() << "begin main loop" << std::endl;
566  timer.start();
567  for (iStep_ = min; iStep_ <= max; ++iStep_) {
568 
569  indexString << iStep_;
570  filename = basename;
571  filename += indexString.str();
572  fileMaster().openInputFile(filename, configFile);
573 
574  // Clear the stringstream
575  indexString.str("");
576 
577  system().readConfig(configFile);
578  configFile.close();
579 
580  #ifndef SIMP_NOPAIR
581  // Build the system CellList
583  #endif
584 
585  #ifndef NDEBUG
586  isValid();
587  #endif
588 
589  // Initialize analyzers (taking in molecular information).
590  if (iStep_ == min) analyzerManager().setup();
591 
592  // Sample property values
593  analyzerManager().sample(iStep_);
594 
595  // Clear out the System for the next readConfig.
597 
598  }
599  timer.stop();
600  Log::file()<< "end main loop" << std::endl;
601 
602  // Output results of all analyzers to output files
604 
605  // Output time
606  Log::file() << std::endl;
607  Log::file() << "nConfig " << nConfig << std::endl;
608  Log::file() << "run time " << timer.time()
609  << " sec" << std::endl;
610  Log::file() << "time / config " << timer.time()/double(nConfig)
611  << " sec" << std::endl;
612  Log::file() << std::endl;
613 
614  }
615 
616  /*
617  * Open, read and analyze a trajectory file
618  */
619  void MdSimulation::analyzeTrajectory(int min, int max,
620  std::string classname,
621  std::string filename)
622  {
623  // Preconditions
624  UTIL_CHECK(min >= 0);
625  UTIL_CHECK(max > min);
627  UTIL_CHECK(analyzerManager().size() > 0);
628 
629  // Construct TrajectoryReader
630  TrajectoryReader* trajectoryReaderPtr;
631  trajectoryReaderPtr
632  = system().trajectoryReaderFactory().factory(classname);
633  if (!trajectoryReaderPtr) {
634  std::string message;
635  message = "Invalid TrajectoryReader class name " + classname;
636  UTIL_THROW(message.c_str());
637  }
638 
639  // Open trajectory file
640  Log::file() << "Reading " << filename << std::endl;
641  trajectoryReaderPtr->open(filename);
642 
643  // Main loop over trajectory frames
644  Timer timer;
645  Log::file() << "Begin main loop" << std::endl;
646  bool hasFrame = true;
647  timer.start();
648  for (iStep_ = 0; iStep_ <= max && hasFrame; ++iStep_) {
649  hasFrame = trajectoryReaderPtr->readFrame();
650  if (hasFrame) {
651  #ifndef SIMP_NOPAIR
652  // Build the system PairList
654  #endif
655  #ifdef UTIL_DEBUG
656  isValid();
657  #endif
658  // Initialize analyzers (taking in molecular information).
659  if (iStep_ == min) analyzerManager().setup();
660  // Sample property values only for iStep >= min
661  if (iStep_ >= min) analyzerManager().sample(iStep_);
662  }
663  }
664  timer.stop();
665  Log::file() << "end main loop" << std::endl;
666  int nFrames = iStep_ - min;
667 
668  trajectoryReaderPtr->close();
669  delete trajectoryReaderPtr;
670 
671  // Output results of all analyzers to output files
673 
674  // Output time
675  Log::file() << std::endl;
676  Log::file() << "# of frames " << nFrames << std::endl;
677  Log::file() << "run time " << timer.time()
678  << " sec" << std::endl;
679  Log::file() << "time / frame " << timer.time()/double(nFrames)
680  << " sec" << std::endl;
681  Log::file() << std::endl;
682  }
683 
687  void MdSimulation::load(const std::string& filename)
688  {
689  // Precondition
690  if (isInitialized_) {
691  UTIL_THROW("Error: Called load when already initialized");
692  }
693 
694  // Load state from archive
696  std::ios_base::openmode mode = std::ios_base::in | std::ios_base::binary;
697  fileMaster().openRestartIFile(filename, ar.file(), mode);
698  load(ar);
699  ar.file().close();
700 
701  isInitialized_ = true;
702  isRestarting_ = true;
703  }
704 
705  /*
706  * Write a restart file with specified filename, if at interval.
707  */
708  void MdSimulation::save(const std::string& filename)
709  {
711  std::ios_base::openmode mode = std::ios_base::out | std::ios_base::binary;
712  fileMaster().openRestartOFile(filename, ar.file(), mode);
713  save(ar);
714  ar.file().close();
715  }
716 
717  /*
718  * Return true if this MdSimulation is valid, or throw an Exception.
719  */
721  {
723  system_.isValid();
724 
725  if (&system_.simulation() != this) {
726  UTIL_THROW("Invalid pointer to Simulation in System");
727  }
728 
729  return true;
730  }
731 
732 }
virtual void save(Serializable::OArchive &ar)
Save a set of objects to an output archive.
Definition: Manager.h:448
void load(const std::string &filename)
Read a restart file.
int iStep_
Step index for main MC or MD loop.
int buildCounter() const
Return number of times the PairList has been built thus far.
virtual void readParameters(std::istream &in)
Read parameter file block and initialize simulation.
void setCommandFileName(const std::string &commandFileName)
Set the command file name.
Definition: FileMaster.cpp:112
static long baseInterval
The interval for an Analyzer must be a multiple of baseInterval.
void calculateForces()
Compute all forces in this System.
Definition: MdSystem.cpp:857
virtual void loadParameters(Serializable::IArchive &ar)
Load parameter file section of archive.
void outputOptions(std::ostream &out) const
Output a list of options enabled and disabled during compilation.
bool readCommand(std::string command, std::istream &in)
Read and execute a single command from an input stream.
void setExpectPerturbation()
Set to expect a Perturbation in the parameter file.
Definition: System.cpp:948
virtual void save(Serializable::OArchive &ar)
Save internal state to an archive.
void saveConfig(Serializable::OArchive &ar)
Save configuration.
Definition: System.cpp:756
MdSimulation()
Constructor.
Manager for Analyzer objects in an MdSimulation.
void shiftAtoms()
Shift all atoms into primary cell.
Definition: MdSystem.cpp:743
AnalyzerManager & analyzerManager()
Get the associated AnalyzerManager by reference.
void openRestartIFile(const std::string &name, std::ifstream &in, std::ios_base::openmode mode=std::ios_base::in) const
Open an input restart dump file for reading.
Definition: FileMaster.cpp:242
void simulate(int endStep, bool isContinuation=false)
Run an MD simulation of specified length.
void loadParamComposite(Serializable::IArchive &ar, ParamComposite &child, bool next=true)
Add and load a required child ParamComposite.
static void setEcho(bool echo=true)
Enable or disable echoing for all subclasses of ParamComponent.
MdIntegrator & mdIntegrator()
Return the MdIntegrator by reference.
Definition: MdSystem.h:660
void analyzeConfigs(int min, int max, std::string basename)
Read and analyze a sequence of configuration files.
End & readEnd(std::istream &in)
Add and read the closing bracket.
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
virtual ~MdSimulation()
Destructor.
virtual bool isValid() const
Return true if Simulation is valid, or throw an Exception.
Classes used by all simpatico molecular simulations.
void setFileMaster(FileMaster &filemaster)
Set the FileMaster.
Definition: System.cpp:881
virtual void setup()
Initialize internal state, if any.
Definition: MdIntegrator.h:53
virtual void save(Serializable::OArchive &ar)
Save state to an archive.
The main object in a simulation, which coordinates others.
void analyzeTrajectory(int min, int max, std::string classname, std::string filename)
Read and analyze a trajectory file.
Saving / output archive for binary ostream.
bool getNextLine(std::istream &in, std::string &line)
Read the next non-empty line into a string, strip trailing whitespace.
Definition: ioUtil.cpp:79
void removeAllMolecules()
Remove all molecules from this System.
Definition: System.cpp:1163
MdPairPotential & pairPotential() const
Return MdPairPotential by reference.
Definition: MdSystem.h:520
double time()
Get the accumulated time, in seconds.
Definition: Timer.h:110
#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.
CommandManager & commandManager()
Get the associated CommandManager by reference.
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
void output()
Call output method of each analyzer.
void stop()
Stop the clock, increment time.
Definition: Timer.h:89
void setId(int Id)
Set the integer Id for this System.
Definition: System.cpp:862
Utility classes for scientific computation.
Definition: accumulators.mod:1
void setAnalyzerManager(AnalyzerManager *ptr)
Set the associated AnalyzerManager.
void setCommandManager(CommandManager *ptr)
Set the associated CommandManager.
virtual void open(std::string filename)=0
Open trajectory file and read header, if any.
virtual void close()=0
Close the trajectory file.
virtual void makeWaves()=0
Generate wavevectors and influence function for this boundary.
void readCommands()
Read and execute commands from a default command file.
bool isIoProcessor() const
Can this processor do file I/O ?
Definition: MpiFileIo.h:92
MPI::Intracomm & communicator()
Get the MPI communicator by reference.
Trajectory file reader (base class).
virtual void readParameters(std::istream &in)
Read parameters from stream, without begin and end lines.
Command interpreter and Command Manager for an MdSimulation.
const MdSystem & system() const
Get the MdSystem being simulated by const reference.
Definition: MdSimulation.h:318
void readParamCompositeOptional(std::istream &in, ParamComposite &child, bool next=true)
Add and attempt to read an optional child ParamComposite.
void readParam()
Read parameters from the default parameter istream.
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
virtual bool isValid() const
Return true if this MdSimulation valid, or throw an Exception.
Wall clock timer.
Definition: Timer.h:30
void setOutputPrefix(const std::string &outputPrefix)
Set the output file prefix string.
Definition: FileMaster.cpp:100
Saving archive for binary istream.
virtual bool isValid() const
Return true if valid, or throw Exception.
Definition: MdSystem.cpp:1210
std::ifstream & file()
Get the underlying ifstream by reference.
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).
void setInputPrefix(const std::string &inputPrefix)
Set the input file prefix string.
Definition: FileMaster.cpp:94
void buildPairList()
Build the internal PairList.
void save(const std::string &filename)
Write a restart file.
virtual bool readFrame()=0
Read a single frame.
#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 setParamFileName(const std::string &paramFileName)
Set the parameter file name.
Definition: FileMaster.cpp:106
void readParamComposite(std::istream &in, ParamComposite &child, bool next=true)
Add and read a required child ParamComposite.
Begin & readBegin(std::istream &in, const char *label, bool isRequired=true)
Add and read a class label and opening bracket.
int maxNPair() const
Get the maximum number of pairs encountered thus far.
void setIoCommunicator()
Set MPI job to read one parameter file and one command file.
void setup()
Call initialize method of each Analyzer.
virtual Data * factory(const std::string &className) const =0
Returns a pointer to a new instance of specified subclass.
bool readCommand(std::string name, std::istream &in)
Attempt to read a command line, execute if recognized.
virtual void readConfig(std::istream &in)
Read system configuration from file.
Definition: MdSystem.cpp:655
int maxNAtom() const
Get the maximum number of atoms encountered thus far.
std::ofstream & file()
Get the underlying ifstream by reference.
virtual void step()=0
Take a complete MD integration step.
void setOptions(int argc, char **argv)
Process command line options.
void openRestartOFile(const std::string &name, std::ofstream &out, std::ios_base::openmode mode=std::ios_base::out) const
Open an output restart file for writing.
Definition: FileMaster.cpp:257
void start()
Start the clock.
Definition: Timer.h:78
void sample(long iStep)
Call sample method of each Analyzer.
void setSimulation(Simulation &simulation)
Set the parent Simulation.
Definition: System.cpp:872
virtual void saveParameters(Serializable::OArchive &ar)
Save parameters to an archive, without configuration.
Definition: MdSystem.cpp:582
Factory< TrajectoryReader > & trajectoryReaderFactory()
Get the trajectory reader/writer factory by reference.
Definition: System.cpp:929
MdCoulombPotential & coulombPotential() const
Return CoulombPotential by reference.
Definition: MdSystem.h:588
FileMaster & fileMaster()
Get the FileMaster object.
virtual void loadParameters(Serializable::IArchive &ar)
Load internal state from an archive.