Simpatico  v1.10
mcMd/analyzers/trajectory/LammpsDumpWriter.cpp
1 /*
2 * Simpatico - Simulation Package for Polymeric and Molecular Liquids
3 *
4 * Copyright 2010 - 2014, The Regents of the University of Minnesota
5 * Distributed under the terms of the GNU General Public License.
6 */
7 
8 #include "LammpsDumpWriter.h"
9 #include <util/misc/FileMaster.h>
10 #include <util/archives/Serializable_includes.h>
11 #include <util/misc/ioUtil.h>
12 
13 #include <sstream>
14 
15 namespace McMd
16 {
17 
18  using namespace Util;
19 
20  /*
21  * Constructor.
22  */
24  : SystemAnalyzer<System>(system),
25  nSample_(0),
26  isInitialized_(false)
27  { setClassName("LammpsDumpWriter"); }
28 
29  /*
30  * Read interval and outputFileName.
31  */
32  void LammpsDumpWriter::readParameters(std::istream& in)
33  {
34  readInterval(in);
36  isInitialized_ = true;
37  }
38 
39  /*
40  * Load state from an archive.
41  */
43  {
45  ar & nSample_;
46  isInitialized_ = true;
47  }
48 
49  /*
50  * Save state to archive.
51  */
53  { ar & *this; }
54 
55  /*
56  * Read interval and outputFileName.
57  */
59  {
60  nSample_ = 0;
61  std::string filename;
62  filename = outputFileName();
63  fileMaster().openOutputFile(filename, outputFile_);
64  }
65 
66  /*
67  * Dump configuration to file
68  */
69  void LammpsDumpWriter::sample(long iStep)
70  {
71  if (isAtInterval(iStep)) {
72  system().writeConfig(outputFile_);
73  ++nSample_;
74  }
75  }
76 
77  /*
78  * Read interval and outputFileName.
79  */
81  { outputFile_.close(); }
82 
83 }
virtual void save(Serializable::OArchive &ar)
Save state to archive.
virtual void readParameters(std::istream &in)
Read interval.
void openOutputFile(const std::string &filename, std::ofstream &out, std::ios_base::openmode mode=std::ios_base::out) const
Open an output file.
Definition: FileMaster.cpp:290
virtual void loadParameters(Serializable::IArchive &ar)
Load parameters from archive.
virtual void loadParameters(Serializable::IArchive &ar)
Load state from an archive.
A set of interacting Molecules enclosed by a Boundary.
Definition: System.h:115
System & system()
Return reference to parent system.
void readOutputFileName(std::istream &in)
Read outputFileName from file.
virtual void setup()
Clear nSample counter.
Saving / output archive for binary ostream.
void readInterval(std::istream &in)
Read interval from file, with error checking.
Utility classes for scientific computation.
Definition: accumulators.mod:1
Template for Analyzer associated with one System.
Saving archive for binary istream.
Single-processor Monte Carlo (MC) and molecular dynamics (MD).
void setClassName(const char *className)
Set class name string.
FileMaster & fileMaster()
Get the FileMaster by reference.
bool isAtInterval(long counter) const
Return true iff counter is a multiple of the interval.
const std::string & outputFileName() const
Return outputFileName string.
void writeConfig(std::ostream &out)
Write system configuration to a specified ostream.
Definition: System.cpp:836
virtual void sample(long iStep)
Write a frame/snapshot to file.