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> 16 #include <mcMd/potentials/bond/BondPotential.h> 19 #include <mcMd/potentials/angle/AnglePotential.h> 22 #include <mcMd/potentials/dihedral/DihedralPotential.h> 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> 50 mdAnalyzerManager_(*this),
51 mdCommandManager_(*this),
54 isInitialized_(false),
82 mdAnalyzerManager_(*this),
83 mdCommandManager_(*this),
86 isInitialized_(false),
113 if (mdAnalyzerManagerPtr_) {
114 delete mdAnalyzerManagerPtr_;
116 if (mdCommandManagerPtr_) {
117 delete mdCommandManagerPtr_;
146 while ((c = getopt(argc, argv,
"qer:p:c:i:o:f")) != -1) {
180 char optChar = optopt;
181 std::cout <<
"Unknown option -" << optChar << std::endl;
206 std::string msg(
"Error: Options -r and -f are incompatible.");
207 msg +=
"Existence of a perturbation is specified in restart file.";
226 UTIL_THROW(
"Cannot have both parameter and restart files");
235 isRestarting_ =
true;
236 load(std::string(rarg));
264 if (isInitialized_) {
265 UTIL_THROW(
"Error: Called readParam when already initialized");
277 readOptional<int>(in,
"saveInterval", saveInterval_);
278 if (saveInterval_ > 0) {
279 read<std::string>(in,
"saveFileName", saveFileName_);
283 isInitialized_ =
true;
300 if (isInitialized_) {
314 if (isInitialized_) {
315 UTIL_THROW(
"Error: Called loadParameters when already initialized");
322 loadParameter<int>(ar,
"saveInterval", saveInterval_);
323 if (saveInterval_ > 0) {
324 loadParameter<std::string>(ar,
"saveFileName", saveFileName_);
331 isInitialized_ =
true;
344 if (saveInterval_ > 0) {
358 std::istream& inBuffer = in;
360 std::stringstream inBuffer;
364 bool readNext =
true;
375 for (
unsigned i=0; i < line.size(); ++i) {
376 inBuffer.put(line[i]);
387 if (command ==
"RESTART") {
391 << endStep << std::endl;
393 isRestarting_ =
false;
400 if (command ==
"FINISH") {
407 Log::file() <<
"Error: Unknown command " << std::endl;
441 if (isContinuation) {
442 Log::file() <<
"Continuing simulation from iStep = " 448 if (
system().hasCoulombPotential()) {
457 int nStep = endStep - beginStep;
479 if (saveInterval_ > 0) {
480 if (
iStep_ % saveInterval_ == 0) {
489 double time = timer.
time();
490 double rstep = double(nStep);
501 if (saveInterval_ > 0) {
502 if (
iStep_ % saveInterval_ == 0) {
512 Log::file() <<
"Time Statistics" << std::endl;
513 Log::file() <<
"endStep " << endStep << std::endl;
514 Log::file() <<
"nStep " << nStep << std::endl;
516 << time <<
" sec" << std::endl;
518 << time / rstep <<
" sec" << std::endl;
520 << time / (rstep*double(
system().nAtom()))
521 <<
" sec" << std::endl;
526 Log::file() <<
"PairList Statistics" << std::endl;
538 << rstep/double(buildCounter)
558 std::string filename;
559 std::stringstream indexString;
560 std::ifstream configFile;
562 nConfig = max - min + 1;
565 Log::file() <<
"begin main loop" << std::endl;
571 filename += indexString.str();
600 Log::file()<<
"end main loop" << std::endl;
607 Log::file() <<
"nConfig " << nConfig << std::endl;
609 <<
" sec" << std::endl;
610 Log::file() <<
"time / config " << timer.
time()/double(nConfig)
611 <<
" sec" << std::endl;
620 std::string classname,
621 std::string filename)
633 if (!trajectoryReaderPtr) {
635 message =
"Invalid TrajectoryReader class name " + classname;
640 Log::file() <<
"Reading " << filename << std::endl;
641 trajectoryReaderPtr->
open(filename);
645 Log::file() <<
"Begin main loop" << std::endl;
646 bool hasFrame =
true;
649 hasFrame = trajectoryReaderPtr->
readFrame();
665 Log::file() <<
"end main loop" << std::endl;
666 int nFrames =
iStep_ - min;
668 trajectoryReaderPtr->
close();
669 delete trajectoryReaderPtr;
676 Log::file() <<
"# of frames " << nFrames << std::endl;
678 <<
" sec" << std::endl;
679 Log::file() <<
"time / frame " << timer.
time()/double(nFrames)
680 <<
" sec" << std::endl;
690 if (isInitialized_) {
691 UTIL_THROW(
"Error: Called load when already initialized");
696 std::ios_base::openmode mode = std::ios_base::in | std::ios_base::binary;
701 isInitialized_ =
true;
702 isRestarting_ =
true;
711 std::ios_base::openmode mode = std::ios_base::out | std::ios_base::binary;
726 UTIL_THROW(
"Invalid pointer to Simulation in System");
virtual void save(Serializable::OArchive &ar)
Save a set of objects to an output archive.
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.
static long baseInterval
The interval for an Analyzer must be a multiple of baseInterval.
void calculateForces()
Compute all forces in this System.
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.
virtual void save(Serializable::OArchive &ar)
Save internal state to an archive.
void saveConfig(Serializable::OArchive &ar)
Save configuration.
MdSimulation()
Constructor.
Manager for Analyzer objects in an MdSimulation.
void shiftAtoms()
Shift all atoms into primary cell.
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.
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.
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.
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.
virtual void setup()
Initialize internal state, if any.
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.
void removeAllMolecules()
Remove all molecules from this System.
MdPairPotential & pairPotential() const
Return MdPairPotential by reference.
double time()
Get the accumulated time, in seconds.
#define UTIL_THROW(msg)
Macro for throwing an Exception, reporting function, file and line number.
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.
void output()
Call output method of each analyzer.
void stop()
Stop the clock, increment time.
void setId(int Id)
Set the integer Id for this System.
Utility classes for scientific computation.
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 ?
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.
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.
bool hasIoCommunicator() const
Does this object have an associated MPI communicator?
virtual bool isValid() const
Return true if this MdSimulation valid, or throw an Exception.
void setOutputPrefix(const std::string &outputPrefix)
Set the output file prefix string.
Saving archive for binary istream.
virtual bool isValid() const
Return true if valid, or throw Exception.
std::ifstream & file()
Get the underlying ifstream by reference.
virtual void loadConfig(Serializable::IArchive &ar)
Load the MdSystem configuration from an archive.
Single-processor Monte Carlo (MC) and molecular dynamics (MD).
void setInputPrefix(const std::string &inputPrefix)
Set the input file prefix string.
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.
void setClassName(const char *className)
Set class name string.
void setParamFileName(const std::string ¶mFileName)
Set the parameter file name.
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.
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.
void start()
Start the clock.
void sample(long iStep)
Call sample method of each Analyzer.
void setSimulation(Simulation &simulation)
Set the parent Simulation.
virtual void saveParameters(Serializable::OArchive &ar)
Save parameters to an archive, without configuration.
Factory< TrajectoryReader > & trajectoryReaderFactory()
Get the trajectory reader/writer factory by reference.
MdCoulombPotential & coulombPotential() const
Return CoulombPotential by reference.
FileMaster & fileMaster()
Get the FileMaster object.
virtual void loadParameters(Serializable::IArchive &ar)
Load internal state from an archive.