Simpatico  v1.10
McSimulation.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 <util/global.h>
9 
10 #include "McSimulation.h"
11 #include <mcMd/chemistry/Molecule.h>
12 #include <mcMd/chemistry/Atom.h>
13 #include <mcMd/analyzers/Analyzer.h>
14 #include <mcMd/trajectory/TrajectoryReader.h>
15 #include <mcMd/generators/Generator.h>
16 #include <mcMd/generators/generatorFactory.h>
17 #ifndef SIMP_NOPAIR
18 #include <mcMd/potentials/pair/McPairPotential.h>
19 #endif
20 #ifdef SIMP_BOND
21 #include <mcMd/potentials/bond/BondPotential.h>
22 #endif
23 #ifdef SIMP_ANGLE
24 #include <mcMd/potentials/angle/AnglePotential.h>
25 #endif
26 #ifdef SIMP_DIHEDRAL
27 #include <mcMd/potentials/dihedral/DihedralPotential.h>
28 #endif
29 #ifdef UTIL_MPI
30 #ifdef MCMD_PERTURB
31 #include <mcMd/perturb/ReplicaMove.h>
32 #endif
33 #endif
34 
35 #include <simp/species/Species.h>
36 
37 #include <util/param/Factory.h>
38 #include <util/archives/Serializable_includes.h>
39 #include <util/format/Dbl.h>
40 #include <util/format/Int.h>
41 #include <util/format/Str.h>
42 #include <util/misc/Log.h>
43 #include <util/misc/Timer.h>
44 #include <util/misc/ioUtil.h>
45 
46 #include <ctime>
47 #include <iomanip>
48 #include <sstream>
49 #include <string>
50 #include <unistd.h>
51 
52 namespace McMd
53 {
54 
55  using namespace Util;
56  using namespace Simp;
57 
58  #ifdef UTIL_MPI
59  /*
60  * Constructor.
61  */
62  McSimulation::McSimulation(MPI::Intracomm& communicator)
63  : Simulation(communicator),
64  system_(),
65  mcMoveManager_(*this),
66  mcAnalyzerManager_(*this),
67  mcCommandManager_(*this),
68  paramFilePtr_(0),
69  saveFileName_(),
70  saveInterval_(0),
71  isInitialized_(false),
72  isRestarting_(false)
73  {
74  setClassName("McSimulation");
75 
76  // Set connections between this McSimulation and child McSystem
77  system().setId(0);
78  system().setSimulation(*this);
80 
81  // Pass pointers to managers to Simulation base class.
82  setAnalyzerManager(&mcAnalyzerManager_);
83  setCommandManager(&mcCommandManager_);
84  }
85  #endif
86 
87  /*
88  * Constructor.
89  */
91  : Simulation(),
92  system_(),
93  mcMoveManager_(*this),
94  mcAnalyzerManager_(*this),
95  mcCommandManager_(*this),
96  paramFilePtr_(0),
97  saveFileName_(),
98  saveInterval_(0),
99  isInitialized_(false),
100  isRestarting_(false)
101  {
102  setClassName("McSimulation");
103 
104  // Set connections between this McSimulation and child McSystem
105  system().setId(0);
106  system().setSimulation(*this);
108 
109  // Pass pointers to managers to Simulation base class.
110  setAnalyzerManager(&mcAnalyzerManager_);
111  setCommandManager(&mcCommandManager_);
112  }
113 
114  /*
115  * Destructor.
116  */
118  {}
119 
120  /*
121  * Process command line options.
122  */
123  void McSimulation::setOptions(int argc, char **argv)
124  {
125  bool qflag = false; // query compile time options
126  bool eflag = false; // echo parameter file
127  bool rFlag = false; // read restart file
128  bool pFlag = false; // param file
129  bool cFlag = false; // command file
130  bool iFlag = false; // input prefix
131  bool oFlag = false; // output prefix
132  #ifdef MCMD_PERTURB
133  bool fflag = false; // free energy perturbation
134  #endif
135  char* rarg = 0;
136  char* pArg = 0;
137  char* cArg = 0;
138  char* iArg = 0;
139  char* oArg = 0;
140 
141  // Read and store all command line arguments
142  int c;
143  opterr = 0;
144  while ((c = getopt(argc, argv, "qer:p:c:i:o:f")) != -1) {
145  switch (c) {
146  case 'q':
147  qflag = true;
148  break;
149  case 'e':
150  eflag = true;
151  break;
152  case 'r':
153  rFlag = true;
154  rarg = optarg;
155  break;
156  case 'p': // parameter file
157  pFlag = true;
158  pArg = optarg;
159  break;
160  case 'c': // command file
161  cFlag = true;
162  cArg = optarg;
163  break;
164  case 'i': // input prefix
165  iFlag = true;
166  iArg = optarg;
167  break;
168  case 'o': // output prefix
169  oFlag = true;
170  oArg = optarg;
171  break;
172  #ifdef MCMD_PERTURB
173  case 'f':
174  fflag = true;
175  break;
176  #endif
177  case '?': {
178  char optChar = optopt;
179  Log::file() << "Unknown option -" << optChar << std::endl;
180  UTIL_THROW("Invalid command line option");
181  }
182  }
183  }
184 
185  // Apply all command line options
186 
187  #ifndef UTIL_MPI
188  if (qflag) {
190  }
191  #endif
192 
193  // Set flag to echo parameters as they are read.
194  if (eflag) {
196  }
197 
198  #ifdef MCMD_PERTURB
199  // Set to use a perturbation.
200  if (fflag) {
201 
202  if (rFlag) {
203  std::string msg("Error: Options -r and -f are incompatible. ");
204  msg += "Existence of a perturbation is specified in restart file.";
205  UTIL_THROW(msg.c_str());
206  }
207 
208  // Set to expect perturbation in the param file.
210 
211  #ifdef UTIL_MPI
212  Util::Log::file() << "Set to read parameters from a single file"
213  << std::endl;
215  #endif
216 
217  }
218  #endif
219 
220  // If option -p, set parameter file name
221  if (pFlag) {
222  if (rFlag) {
223  UTIL_THROW("Error: Options -r and -p are incompatible.");
224  }
225  fileMaster().setParamFileName(std::string(pArg));
226  }
227 
228  // If option -r, restart
229  if (rFlag) {
230  //Log::file() << "Reading restart file "
231  // << std::string(rarg) << std::endl;
232  isRestarting_ = true;
233  load(std::string(rarg));
234  }
235 
236  // The -c, -i, and -o options are applied after the -r option
237  // so that they override any paths set in the restart file.
238 
239  // If option -c, set command file name
240  if (cFlag) {
241  fileMaster().setCommandFileName(std::string(cArg));
242  }
243 
244  // If option -i, set path prefix for input files
245  if (iFlag) {
246  fileMaster().setInputPrefix(std::string(iArg));
247  }
248 
249  // If option -o, set path prefix for output files
250  if (oFlag) {
251  fileMaster().setOutputPrefix(std::string(oArg));
252  }
253 
254  }
255 
256  /*
257  * Read parameters from file.
258  */
259  void McSimulation::readParameters(std::istream &in)
260  {
261  if (isInitialized_) {
262  UTIL_THROW("Error: Called readParam when already initialized");
263  }
264 
265  // Record identity of parameter file
266  paramFilePtr_ = &in;
267 
268  // Read all species, analyzers, random number seed
270 
271  // Read the McSystem parameters: potential parameters, temperature etc.
272  readParamComposite(in, system());
273 
274  // Read Monte Carlo Moves
276 
277  // Read Analyzer and Command managers (optionally)
278  Analyzer::baseInterval = 0; // default value
281 
282  // Parameters for writing restart files (optionally)
283  saveInterval_ = 0; // default value
284  readOptional<int>(in, "saveInterval", saveInterval_);
285  if (saveInterval_ > 0) {
286  read<std::string>(in, "saveFileName", saveFileName_);
287  }
288 
289  isValid();
290  isInitialized_ = true;
291  }
292 
293  /*
294  * Read parameter block, including begin and end.
295  */
296  void McSimulation::readParam(std::istream& in)
297  {
298  if (isRestarting_) {
299  if (isInitialized_) {
300  return;
301  }
302  }
303  readBegin(in, className().c_str());
304  readParameters(in);
305  readEnd(in);
306  }
307 
308  /*
309  * Read default parameter file.
310  */
312  { readParam(fileMaster().paramFile()); }
313 
314  /*
315  * Load internal state from an archive.
316  */
318  {
319  if (isInitialized_) {
320  UTIL_THROW("Error: Called readParam when already initialized");
321  }
322  #ifdef UTIL_MPI
323  if (hasIoCommunicator()) {
324  UTIL_THROW("Error: Has a param communicator in loadParameters");
325  }
326  #endif
327 
329  loadParamComposite(ar, system());
333  loadParameter<int>(ar, "saveInterval", saveInterval_);
334  if (saveInterval_ > 0) {
335  loadParameter<std::string>(ar, "saveFileName", saveFileName_);
336  }
337 
338  system().loadConfig(ar);
339  ar >> iStep_;
340  isValid();
341  isInitialized_ = true;
342  }
343 
344  /*
345  * Save internal state to an archive.
346  */
348  {
349  Simulation::save(ar);
350  system().saveParameters(ar);
351  mcMoveManager().save(ar);
352  analyzerManager().save(ar);
353  commandManager().save(ar);
354  ar << saveInterval_;
355  if (saveInterval_ > 0) {
356  ar << saveFileName_;
357  }
358 
359  system().saveConfig(ar);
360  ar << iStep_;
361  }
362 
363  void McSimulation::load(const std::string& filename)
364  {
365  if (isInitialized_) {
366  UTIL_THROW("Error: Called load when already initialized");
367  }
368  if (!isRestarting_) {
369  UTIL_THROW("Error: Called load without restart option");
370  }
371 
372  // Load from archive
374  std::ios_base::openmode mode = std::ios_base::in | std::ios_base::binary;
375  fileMaster().openRestartIFile(filename, ar.file(), mode);
376  load(ar);
377  ar.file().close();
378 
379  #ifdef UTIL_MPI
380  #ifdef MCMD_PERTURB
381  if (system().hasPerturbation()) {
382  // Read one command file, after reading multiple restart files.
383  Util::Log::file() << "Set to use a single command file"
384  << std::endl;
386  }
387  #endif
388  #endif
389 
390  isInitialized_ = true;
391  }
392 
393  void McSimulation::save(const std::string& filename)
394  {
396  std::ios_base::openmode mode = std::ios_base::out | std::ios_base::binary;
397  fileMaster().openRestartOFile(filename, ar.file(), mode);
398  save(ar);
399  ar.file().close();
400  }
401 
402  /*
403  * Read and execute commands from a specified command file.
404  */
405  void McSimulation::readCommands(std::istream &in)
406  {
407  if (!isInitialized_) {
408  UTIL_THROW("McSimulation is not initialized");
409  }
410 
411  std::string command;
412  std::string filename;
413  std::ifstream inputFile;
414  std::ofstream outputFile;
415 
416  #ifndef UTIL_MPI
417  std::istream& inBuffer = in;
418  #else
419  std::stringstream inBuffer;
420  std::string line;
421  #endif
422 
423  bool readNext = true;
424  while (readNext) {
425 
426  // iffdef UTIL_MPI, read a line and copy to stringstream inBuffer
427  // ifndef UTIL_MPI, inBuffer is simply a reference to istream in.
428 
429  #ifdef UTIL_MPI
430  // Read a command line, and broadcast if necessary.
431  if (!hasIoCommunicator() || isIoProcessor()) {
432  getNextLine(in, line);
433  }
434  if (hasIoCommunicator()) {
435  bcast<std::string>(communicator(), line, 0);
436  }
437 
438  // Copy the command line to inBuffer.
439  inBuffer.clear();
440  for (unsigned i=0; i < line.size(); ++i) {
441  inBuffer.put(line[i]);
442  }
443  #endif
444 
445  inBuffer >> command;
446  Log::file() << command;
447 
448  if (isRestarting_) {
449 
450  if (command == "RESTART") {
451  int endStep;
452  inBuffer >> endStep;
453  Log::file() << " " << iStep_ << " to "
454  << endStep << std::endl;
455  simulate(endStep, isRestarting_);
456  isRestarting_ = false;
457  } else {
458  UTIL_THROW("Missing RESTART command");
459  }
460 
461  } else {
462 
463  if (command == "FINISH") {
464  Log::file() << std::endl;
465  readNext = false;
466  } else {
467  bool success;
468  success = commandManager().readCommand(command, inBuffer);
469  if (!success) {
470  Log::file() << "Error: Unknown command " << std::endl;
471  readNext = false;
472  }
473  }
474 
475  }
476  }
477  }
478 
479  /*
480  * Read and execute commands from the default command file.
481  */
483  {
484  if (fileMaster().commandFileName().empty()) {
485  UTIL_THROW("Empty command file name");
486  }
487  readCommands(fileMaster().commandFile());
488  }
489 
490  /*
491  * Read and execute a single command.
492  */
493  bool McSimulation::readCommand(std::string command, std::istream& in)
494  { return commandManager().readCommand(command, in); }
495 
496  /*
497  * Run this MC simulation.
498  */
499  void McSimulation::simulate(int endStep, bool isContinuation)
500  {
501  if (!isInitialized_) {
502  UTIL_THROW("McSimulation not initialized");
503  }
504 
505  // Setup before main loop
506  if (isContinuation) {
507  Log::file() << "Continuing from iStep = "
508  << iStep_ << std::endl;
509  } else {
510  iStep_ = 0;
512  }
513  int beginStep = iStep_;
514  int nStep = endStep - beginStep;
515  Log::file() << std::endl;
517 
518  // Main Monte Carlo loop
519  Timer timer;
520  timer.start();
521  for ( ; iStep_ < endStep; ++iStep_) {
522 
523  // Call analyzers
524  if (Analyzer::baseInterval != 0) {
525  if (iStep_ % Analyzer::baseInterval == 0) {
526  if (analyzerManager().size() > 0) {
530  }
531  }
532  }
533 
534  // Save restart file
535  if (saveInterval_ != 0) {
536  if (iStep_ % saveInterval_ == 0) {
537  save(saveFileName_);
538  }
539  }
540 
541  // Choose and attempt an McMove
543 
544  #ifdef UTIL_MPI
545  #ifdef MCMD_PERTURB
546  // Attempt replica move, if any.
547  if (system().hasPerturbation()) {
548  if (system().hasReplicaMove()) {
549  if (system().replicaMove().isAtInterval(iStep_)) {
551  bool success = system().replicaMove().move();
552  #ifndef SIMP_NOPAIR
553  if (success) {
555  }
556  #endif
557  }
558  }
559  }
560  #endif
561  #endif
562 
563  }
564  timer.stop();
565  double time = timer.time();
566 
567  // Final analyzers
568  assert(iStep_ == endStep);
569  if (Analyzer::baseInterval > 0) {
570  if (iStep_ % Analyzer::baseInterval == 0) {
571  if (analyzerManager().size() != 0) {
575  }
576  }
577  }
578 
579  // Final save to archive
580  if (saveInterval_ != 0) {
581  if (iStep_ % saveInterval_ == 0) {
582  save(saveFileName_);
583  }
584  }
585 
586  // Output results of all analyzers to output files
587  if (Analyzer::baseInterval > 0) {
589  }
590 
591  // Output results of move statistics to files
592  mcMoveManager().output();
593 
594  // Output time for the run
595  Log::file() << std::endl;
596  Log::file() << "endStep " << endStep << std::endl;
597  Log::file() << "nStep " << nStep << std::endl;
598  Log::file() << "run time " << time
599  << " sec" << std::endl;
600  double rStep = double(nStep);
601  Log::file() << "time / nStep " << time / rStep
602  << " sec" << std::endl;
603  Log::file() << std::endl;
604 
605  // Print McMove acceptance statistics
606  long attempt;
607  long accept;
608  using namespace std;
609  Log::file() << "Move Statistics:" << endl << endl;
610  Log::file() << setw(32) << left << "Move Name"
611  << setw(12) << right << "Attempted"
612  << setw(12) << right << "Accepted"
613  << setw(15) << right << "AcceptRate"
614  << endl;
615  int nMove = mcMoveManager().size();
616  for (int iMove = 0; iMove < nMove; ++iMove) {
617  attempt = mcMoveManager()[iMove].nAttempt();
618  accept = mcMoveManager()[iMove].nAccept();
619  Log::file() << setw(32) << left
620  << mcMoveManager().className(iMove)
621  << setw(12) << right << attempt
622  << setw(12) << accept
623  << setw(15) << fixed << setprecision(6)
624  << ( attempt == 0 ? 0.0 : double(accept)/double(attempt) )
625  << endl;
626  }
627  Log::file() << endl;
628 
629  #ifdef UTIL_MPI
630  #ifdef MCMD_PERTURB
631  // Print replica-exchange acceptance statistics
632  if (system().hasPerturbation()) {
633  if (system().hasReplicaMove()) {
634 
635  double ratio;
636  int nAttempt, nAccept;
637 
638  nAttempt = system().replicaMove().nAttempt();
639  nAccept = system().replicaMove().nAccept();
640  ratio = nAttempt == 0 ? 0.0 : double(nAccept)/double(nAttempt);
641  Log::file() << "Replica Exchange "
642  << Int(nAttempt) << Int(nAccept) << Dbl(ratio)
643  << std::endl;
644  }
645  }
646  #endif
647  #endif
648 
649  }
650 
651  /*
652  * Read and analyze a sequence of configuration files.
653  */
654  void
655  McSimulation::analyzeConfigs(int min, int max, std::string basename)
656  {
657  // Preconditions
658  UTIL_CHECK(min > 0);
659  UTIL_CHECK(max > min);
661  UTIL_CHECK(analyzerManager().size() > 0);
662 
663  Timer timer;
664  std::string filename;
665  std::stringstream indexString;
666  std::ifstream configFile;
667  int nConfig;
668  nConfig = max - min + 1;
669 
670  // Main loop
671  Log::file() << "begin main loop" << std::endl;
672  timer.start();
673  for (iStep_ = min; iStep_ <= max; ++iStep_) {
674 
675  indexString << iStep_;
676  filename = basename;
677  filename += indexString.str();
678  fileMaster().openInputFile(filename, configFile);
679 
680  // Clear the stringstream
681  indexString.str("");
682 
683  system().readConfig(configFile);
684  configFile.close();
685 
686  #ifndef SIMP_NOPAIR
687  // Build the system CellList
689  #endif
690 
691  #ifdef UTIL_DEBUG
692  isValid();
693  #endif
694 
695  // Initialize analyzers (taking in molecular information).
696  if (iStep_ == min) analyzerManager().setup();
697 
698  // Sample property values
699  analyzerManager().sample(iStep_);
700 
701  // Clear out the System for the next readConfig.
703 
704  }
705  timer.stop();
706  Log::file() << "end main loop" << std::endl;
707 
708  // Output results of all analyzers to output files
710 
711  // Output time
712  Log::file() << std::endl;
713  Log::file() << "nConfig " << nConfig << std::endl;
714  Log::file() << "run time " << timer.time()
715  << " sec" << std::endl;
716  Log::file() << "time / config " << timer.time()/double(nConfig)
717  << " sec" << std::endl;
718  Log::file() << std::endl;
719 
720  iStep_ = 0;
721  }
722 
723  /*
724  * Open, read and analyze a trajectory file
725  */
726  void McSimulation::analyzeTrajectory(int min, int max,
727  std::string classname,
728  std::string filename)
729  {
730  // Preconditions
731  if (min < 0) UTIL_THROW("min < 0");
732  if (max < 0) UTIL_THROW("max < 0");
733  if (max < min) UTIL_THROW("max < min!");
734 
735  // Construct TrajectoryReader
736  TrajectoryReader* trajectoryReaderPtr;
737  trajectoryReaderPtr = system().trajectoryReaderFactory().factory(classname);
738  if (!trajectoryReaderPtr) {
739  std::string message;
740  message = "Invalid TrajectoryReader class name " + classname;
741  UTIL_THROW(message.c_str());
742  }
743 
744  // Open trajectory file
745  Log::file() << "Reading " << filename << std::endl;
746  trajectoryReaderPtr->open(filename);
747 
748  // Main loop over trajectory frames
749  Timer timer;
750  Log::file() << "Begin main loop" << std::endl;
751  bool hasFrame = true;
752  timer.start();
753  for (iStep_ = 0; iStep_ <= max && hasFrame; ++iStep_) {
754  hasFrame = trajectoryReaderPtr->readFrame();
755  if (hasFrame) {
756  #ifndef SIMP_NOPAIR
757  // Build the system PairList
759  #endif
760  #ifdef UTIL_DEBUG
761  isValid();
762  #endif
763  // Initialize analyzers (taking in molecular information).
764  if (iStep_ == min) analyzerManager().setup();
765  // Sample property values only for iStep >= min
766  if (iStep_ >= min) analyzerManager().sample(iStep_);
767  }
768  }
769  timer.stop();
770  Log::file() << "end main loop" << std::endl;
771  int nFrames = iStep_ - min;
772 
773  trajectoryReaderPtr->close();
774  delete trajectoryReaderPtr;
775 
776  // Output results of all analyzers to output files
778 
779  // Output time
780  Log::file() << std::endl;
781  Log::file() << "# of frames " << nFrames << std::endl;
782  Log::file() << "run time " << timer.time()
783  << " sec" << std::endl;
784  Log::file() << "time / frame " << timer.time()/double(nFrames)
785  << " sec" << std::endl;
786  Log::file() << std::endl;
787  }
788 
789  /*
790  * Get the McMove factory.
791  */
793  { return mcMoveManager().factory(); }
794 
795  /*
796  * Check validity: return true if valid, or throw Exception.
797  */
799  {
801  system().isValid();
802 
803  if (&system().simulation() != this) {
804  UTIL_THROW("Invalid pointer to Simulation in System");
805  }
806 
807  return true;
808  }
809 
810 }
virtual void loadConfig(Serializable::IArchive &ar)
Load the system configuration from an archive.
Definition: McSystem.cpp:404
virtual ~McSimulation()
Destructor.
McSystem & system()
Get the McSystem by reference.
Definition: McSimulation.h:347
virtual bool move()
Generate, attempt, and accept or reject a Monte Carlo move.
Definition: McMove.cpp:77
virtual void save(Serializable::OArchive &ar)
Save a set of objects to an output archive.
Definition: Manager.h:448
void readCommands()
Read and execute commands from the default parameter file.
bool readCommand(std::string command, std::istream &in)
Read and execute a single command from an input stream.
int iStep_
Step index for main MC or MD loop.
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
void buildCellList()
Build the CellList with current configuration.
static long baseInterval
The interval for an Analyzer must be a multiple of baseInterval.
Signal & positionSignal()
Signal to indicate change in atomic positions.
Definition: McSystem.h:519
void outputOptions(std::ostream &out) const
Output a list of options enabled and disabled during compilation.
long nAccept()
Number of accepted swaps.
Definition: ReplicaMove.h:212
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 analyzeConfigs(int min, int max, std::string basename)
Read and analyze a sequence of configuration files.
void saveConfig(Serializable::OArchive &ar)
Save configuration.
Definition: System.cpp:756
Factory< Data > & factory()
Return a reference to the factory.
Definition: Manager.h:265
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 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.
STL namespace.
std::string className(int i) const
Get the subclass name for object number i.
Definition: Manager.h:473
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
Wrapper for a double precision number, for formatted ostream output.
Definition: Dbl.h:39
virtual bool isValid() const
Return true if Simulation is valid, or throw an Exception.
File containing preprocessor macros for error handling.
Classes used by all simpatico molecular simulations.
void setFileMaster(FileMaster &filemaster)
Set the FileMaster.
Definition: System.cpp:881
virtual void readConfig(std::istream &in)
Read system configuration from file.
Definition: McSystem.cpp:393
virtual void save(Serializable::OArchive &ar)
Save state to an archive.
virtual bool isValid() const
Return true if McSystem is valid, or throw Exception.
Definition: McSystem.cpp:721
virtual bool move()
Attempt, and accept or reject a replica exchange move.
The main object in a simulation, which coordinates others.
long nAttempt()
Number of swap attempts.
Definition: ReplicaMove.h:206
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
void output()
Output statistics for all moves.
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.
void output()
Call output method of each analyzer.
Factory< McMove > & mcMoveFactory()
Get the McMove factory by reference.
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
virtual void readParameters(std::istream &in)
Read body of parameter block from a specific file.
virtual void saveParameters(Serializable::OArchive &ar)
Save parameters to an archive, without configuration.
Definition: McSystem.cpp:331
void notify(const T &t)
Notify all observers.
Definition: Signal.cpp:22
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 save(Serializable::OArchive &ar)
Save internal state to an archive.
Wrapper for an int, for formatted ostream output.
Definition: Int.h:36
virtual void close()=0
Close the trajectory 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).
McPairPotential & pairPotential() const
Return the McPairPotential by reference.
Definition: McSystem.h:388
void readParamCompositeOptional(std::istream &in, ParamComposite &child, bool next=true)
Add and attempt to read an optional child ParamComposite.
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
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.
std::ifstream & file()
Get the underlying ifstream by reference.
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
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
virtual bool isValid() const
Return true if valid, or throw an Exception.
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.
virtual void loadParameters(Serializable::IArchive &ar)
Load parameters from an archive.
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.
McMoveManager & mcMoveManager()
Get the McMoveManager by reference.
Definition: McSimulation.h:360
int size() const
Get logical size.
Definition: Manager.h:494
bool readCommand(std::string name, std::istream &in)
Attempt to read a command line, execute if recognized.
void analyzeTrajectory(int min, int max, std::string classname, std::string filename)
Read and analyze a trajectory file.
std::ofstream & file()
Get the underlying ifstream by reference.
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 simulate(int endStep, bool isContinuation=false)
Run an MC simulation of specified length.
void setSimulation(Simulation &simulation)
Set the parent Simulation.
Definition: System.cpp:872
McSimulation()
Constructor.
void readParam()
Read parameters from the default parameter istream.
void load(const std::string &filename)
Read restart file to continue simulation.
Factory< TrajectoryReader > & trajectoryReaderFactory()
Get the trajectory reader/writer factory by reference.
Definition: System.cpp:929
virtual void save(Serializable::OArchive &ar)
Save internal state to an archive.
McMove & chooseMove()
Choose an McMove at random, using specified probabilities.
FileMaster & fileMaster()
Get the FileMaster object.
virtual void loadParameters(Serializable::IArchive &ar)
Load internal state from an archive.
ReplicaMove & replicaMove() const
Get the associated ReplicaMove by reference.
Definition: System.h:1201
void setOptions(int argc, char **argv)
Process command line options.