Simpatico  v1.10
McEnergyOutput.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 "McEnergyOutput.h"
9 #include <mcMd/mcSimulation/mc_potentials.h> // include all MC potentials
10 #include <util/misc/FileMaster.h>
11 #include <util/format/Dbl.h>
12 
13 namespace McMd
14 {
15 
16  using namespace Util;
17 
18  /*
19  * Constructor.
20  */
22  SystemAnalyzer<McSystem>(system)
23  { setClassName("McEnergyOutput"); }
24 
25  /*
26  * Read file name and open output file.
27  */
28  void McEnergyOutput::readParameters(std::istream& in)
29  {
30  readInterval(in);
32  fileMaster().openOutputFile(outputFileName(".dat"), outputFile_);
33  }
34 
35  /*
36  * Load state from an archive, and open output file.
37  */
39  {
41  fileMaster().openOutputFile(outputFileName(".dat"), outputFile_);
42  }
43 
44  /*
45  * Save state to an archive.
46  */
48  { ar & *this; }
49 
50  /*
51  * Evaluate energy and output to outputFile_.
52  */
53  void McEnergyOutput::sample(long iStep)
54  {
55  if (isAtInterval(iStep)) {
56  double energy = 0.0;
57  #ifndef SIMP_NOPAIR
58  double pair = system().pairPotential().energy();
59  outputFile_ << Dbl(pair);
60  energy += pair;
61  #endif
62  #ifdef SIMP_BOND
63  double bond = system().bondPotential().energy();
64  outputFile_ << Dbl(bond);
65  energy += bond;
66  #endif
67  #ifdef SIMP_ANGLE
68  if (system().hasAnglePotential()) {
69  double angle = system().anglePotential().energy();
70  outputFile_ << Dbl(angle);
71  energy += angle;
72  }
73  #endif
74  #ifdef SIMP_DIHEDRAL
75  if (system().hasDihedralPotential()) {
76  double dihedral = system().dihedralPotential().energy();
77  outputFile_ << Dbl(dihedral);
78  energy += dihedral;
79  }
80  #endif
81  #ifdef MCMD_LINK
82  if (system().hasLinkPotential()) {
83  double link = system().linkPotential().energy();
84  outputFile_ << Dbl(link);
85  energy += link;
86  }
87  #endif
88  #ifdef SIMP_EXTERNAL
89  if (system().hasExternalPotential()) {
90  double external = system().externalPotential().energy();
91  outputFile_ << Dbl(external);
92  energy += external;
93  }
94  #endif
95  #ifdef SIMP_TETHER
96  double tether = system().tetherPotential().energy();
97  outputFile_ << Dbl(tether);
98  energy += tether;
99  #endif
100  outputFile_ << Dbl(energy) << std::endl;
101  }
102  }
103 
104  /*
105  * Summary
106  */
108  {
109  // Close *.dat file
110  outputFile_.close();
111 
112  // Open and write summary file
113  fileMaster().openOutputFile(outputFileName(".prm"), outputFile_);
114  writeParam(outputFile_);
115  outputFile_ << std::endl;
116  outputFile_ << std::endl;
117 
118  outputFile_ << "File format:" << std::endl;
119  #ifndef SIMP_NOPAIR
120  outputFile_ << "[pair] ";
121  #endif
122  #ifdef SIMP_BOND
123  outputFile_ << "[bond] ";
124  #endif
125  #ifdef SIMP_ANGLE
126  if (system().hasAnglePotential()) {
127  outputFile_ << "[angle] ";
128  }
129  #endif
130  #ifdef SIMP_DIHEDRAL
131  if (system().hasDihedralPotential()) {
132  outputFile_ << "[dihedral] ";
133  }
134  #endif
135  #ifdef MCMD_LINK
136  if (system().hasLinkPotential()) {
137  outputFile_ << "[link] ";
138  }
139  #endif
140  #ifdef SIMP_EXTERNAL
141  if (system().hasExternalPotential()) {
142  outputFile_ << "[external] ";
143  }
144  #endif
145  #ifdef SIMP_TETHER
146  outputFile_ << "[tether] ";
147  #endif
148  outputFile_ << "[potential] ";
149  outputFile_ << std::endl;
150 
151  outputFile_.close();
152  }
153 
154 }
A System for use in a Markov chain Monte Carlo simulation.
Definition: McSystem.h:52
virtual double energy(double rsq, int iAtomType, int jAtomType) const =0
Return pair energy for a single pair.
Include this file to include all MC potential energy classes at once.
BondPotential & bondPotential() const
Return the BondPotential by reference.
Definition: McSystem.h:405
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.
McSystem & system()
Return reference to parent system.
Wrapper for a double precision number, for formatted ostream output.
Definition: Dbl.h:39
void readOutputFileName(std::istream &in)
Read outputFileName from file.
virtual void readParameters(std::istream &in)
Read output file and nStepPerSample.
Saving / output archive for binary ostream.
virtual double energy(const Vector &R1, const Vector &R2, const Vector &R3, int type) const =0
Returns potential energy for one dihedral.
virtual double energy(const Vector &position, int i) const =0
Returns external potential energy of a single particle.
virtual void writeParam(std::ostream &out)
Write all parameters to an output stream.
ExternalPotential & externalPotential() const
Return ExternalPotential by reference.
Definition: McSystem.h:473
void readInterval(std::istream &in)
Read interval from file, with error checking.
Utility classes for scientific computation.
Definition: accumulators.mod:1
virtual void save(Serializable::OArchive &ar)
Save state to an archive.
Template for Analyzer associated with one System.
McPairPotential & pairPotential() const
Return the McPairPotential by reference.
Definition: McSystem.h:388
virtual double energy(double cosTheta, int type) const =0
Returns potential energy for one angle.
McEnergyOutput(McSystem &system)
Constructor.
virtual double energy(double rSq, int type) const =0
Returns potential energy for one bond.
virtual void output()
Output final summary and file format.
BondPotential & linkPotential() const
Return the McLinkPotential by reference.
Definition: McSystem.h:493
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.
AnglePotential & anglePotential() const
Return AnglePotential by reference.
Definition: McSystem.h:422
const std::string & outputFileName() const
Return outputFileName string.
virtual void loadParameters(Serializable::IArchive &ar)
Load state from an archive.
void sample(long iStep)
Evaluate energy and print.
DihedralPotential & dihedralPotential() const
Return the DihedralPotential by reference.
Definition: McSystem.h:439