Simpatico  v1.10
mcMd/analyzers/trajectory/TrajectoryWriter.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  */
23  LammpsDumpWriter::LammpsDumpWriter(System& system)
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);
35  readOutputFileName(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 readParameters(std::istream &in)
Read parameters and initialize.
virtual void sample(long iStep)
Write frame to file.
Saving / output archive for binary ostream.
virtual void save(Serializable::OArchive &ar)
Saves all parameters to an archive.
Utility classes for scientific computation.
Definition: accumulators.mod:1
virtual void setup()
Open the trajectory file.
virtual void loadParameters(Serializable::IArchive &ar)
Load state from archive, without adding Begin and End lines.
Saving archive for binary istream.
Single-processor Monte Carlo (MC) and molecular dynamics (MD).
virtual void output()
Close ouput file.