Simpatico  v1.10
SSChainDist.cpp
1 #ifndef SS_CHAIN_DIST_CPP
2 #define SS_CHAIN_DIST_CPP
3 
4 /*
5 * Simpatico - Simulation Package for Polymeric and Molecular Liquids
6 *
7 * Copyright 2010 - 2014, The Regents of the University of Minnesota
8 * Distributed under the terms of the GNU General Public License.
9 */
10 
11 #include "SSChainDist.h"
12 #include <mcMd/simulation/Simulation.h>
13 #include <mcMd/links/LinkMaster.h>
14 #include <mcMd/chemistry/Molecule.h>
15 #include <mcMd/chemistry/Atom.h>
16 #include <simp/species/Species.h>
17 #include <simp/boundary/Boundary.h>
18 #include <util/misc/FileMaster.h>
19 
20 #include <util/global.h>
21 
22 namespace McMd
23 {
24 
25  using namespace Util;
26  using namespace Simp;
27 
30  : SystemAnalyzer<System>(system)
31  { setClassName("SSChainDist"); }
32 
38 
39  void SSChainDist::readParameters(std::istream& in)
40  {
41  readInterval(in);
43  readParamComposite(in, accumulator_);
44  }
45 
46 
49  { accumulator_.clear(); }
50 
52  void SSChainDist::sample(long iStep)
53  {
54  if (isAtInterval(iStep)) {
55  Link link;
56  int nLinks0, idLink;
57  int iAtom0, iAtom1;
58 
59  // Go through all the links.
60  nLinks0 = system().linkMaster().nLink();
61  for (idLink=0; idLink < nLinks0; idLink++) {
62  link = system().linkMaster().link(idLink);
63  iAtom0 = link.atom0().indexInMolecule();
64  iAtom1 = link.atom1().indexInMolecule();
65  accumulator_.sample((double)iAtom0);
66  accumulator_.sample((double)iAtom1);
67  }
68 
69  }
70  }
71 
72 
75  {
76 
77  // Echo parameters to a log file
78  fileMaster().openOutputFile(outputFileName(".prm"), outputFile_);
79  writeParam(outputFile_);
80  outputFile_.close();
81 
82  // Output statistical analysis to separate data file
83  fileMaster().openOutputFile(outputFileName(".dat"), outputFile_);
84  accumulator_.output(outputFile_);
85  outputFile_.close();
86 
87  }
88 
89 }
90 #endif
int nLink() const
Get the total number of active Links.
Definition: LinkMaster.h:261
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 setup()
Clear accumulator.
Definition: SSChainDist.cpp:48
A set of interacting Molecules enclosed by a Boundary.
Definition: System.h:115
System & system()
Return reference to parent system.
File containing preprocessor macros for error handling.
Classes used by all simpatico molecular simulations.
void readOutputFileName(std::istream &in)
Read outputFileName from file.
void sample(long iStep)
Add atoms attached to links to SSChainDist histogram.
Definition: SSChainDist.cpp:52
virtual void writeParam(std::ostream &out)
Write all parameters to an output stream.
void readInterval(std::istream &in)
Read interval from file, with error checking.
SSChainDist(System &system)
Constructor.
Definition: SSChainDist.cpp:29
Utility classes for scientific computation.
Definition: accumulators.mod:1
void sample(double value)
Sample a value.
virtual void readParameters(std::istream &in)
Read parameters from file.
Definition: SSChainDist.cpp:39
Template for Analyzer associated with one System.
void output(std::ostream &out)
Output the distribution to file.
virtual void clear()
Clear (i.e., zero) previously allocated histogram.
Single-processor Monte Carlo (MC) and molecular dynamics (MD).
virtual void output()
Output results to output file.
Definition: SSChainDist.cpp:74
void setClassName(const char *className)
Set class name string.
int indexInMolecule() const
Get local index for this Atom within the parent molecule;.
void readParamComposite(std::istream &in, ParamComposite &child, bool next=true)
Add and read a required child ParamComposite.
Link & link(int id) const
Return an active link by an internal set index.
Definition: LinkMaster.h:255
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.
LinkMaster & linkMaster() const
Get the LinkMaster by reference.
Definition: System.h:1074