Simpatico  v1.10
McNVTChemicalPotential.h
1 #ifndef MCMD_MC_NVT_CHEMICAL_POTENTIAL_H
2 #define MCMD_MC_NVT_CHEMICAL_POTENTIAL_H
3 
4 /*
5 * Simpatico - Simulation Package for Polymeric and Molecular Liquids
6 *
7 * Copyright 2010 - 2017, The Regents of the University of Minnesota
8 * Distributed under the terms of the GNU General Public License.
9 */
10 
11 #include <mcMd/analyzers/SystemAnalyzer.h> // base class template
12 #include <mcMd/mcSimulation/McSystem.h> // base template parameter
13 #include <simp/ensembles/EnergyEnsemble.h> // inline function
14 #include <util/accumulators/Average.h> // member
15 #include <util/accumulators/Distribution.h> // member
16 #include <util/random/Random.h> // member
17 #include <util/archives/Serializable.h> // typedef
18 
19 #include <cstdio>
20 
21 namespace McMd
22 {
23 
24  using namespace Util;
25  using namespace Simp;
26 
27  class Atom;
28 
38  class McNVTChemicalPotential : public SystemAnalyzer<McSystem>
39  {
40 
41  public:
42 
47 
51  virtual void readParameters(std::istream& in);
52 
56  virtual void setup();
57 
61  virtual void sample(long iStep);
62 
66  virtual void output();
67 
73  virtual void save(Serializable::OArchive& ar);
74 
80  virtual void load(Serializable::IArchive& ar);
81 
88  template <class Archive>
89  void serialize(Archive& ar, const unsigned int version);
90 
91  private:
92 
94  McSystem& system();
95 
97  Simulation& simulation();
98 
100  Boundary& boundary();
101 
103  EnergyEnsemble& energyEnsemble();
104 
106  Random& random();
107 
114  double boltzmann(double energy);
115 
138  void addEndAtom(Molecule* molPtr, int atomId, double &rosenbluth,
139  double &energy);
140 
150  void uniformCone(const double length, const double angle,
151  const Vector n, Vector &p);
152 
154  static const int MaxTrial_ = 200;
155 
157  McSystem *systemPtr_;
158 
160  Simulation *simulationPtr_;
161 
163  Boundary *boundaryPtr_;
164 
166  EnergyEnsemble *energyEnsemblePtr_;
167 
169  Random *randomPtr_;
170 
172  std::ofstream outputFile_;
173 
175  Average accumulator_;
176 
178  std::ofstream EoutputFile_;
179 
181  Distribution Eaccumulator_;
182 
184  double Emin_;
185 
187  double Emax_;
188 
190  double EnBin_;
191 
193  std::ofstream EcoutputFile_;
194 
196  Distribution Ecaccumulator_;
197 
199  double Ecmin_;
200 
202  double Ecmax_;
203 
205  double EcnBin_;
206 
208  std::ofstream EmoutputFile_;
209 
211  Distribution Emaccumulator_;
212 
214  double Emmin_;
215 
217  double Emmax_;
218 
220  double EmnBin_;
221 
223  std::ofstream BRoutputFile_;
224 
226  Distribution BRaccumulator_;
227 
229  double BRmin_;
230 
232  double BRmax_;
233 
235  double BRnBin_;
236 
238  int nTrial_;
239 
241  int speciesId_;
242 
244  int nMoleculeTrial_;
245 
247  int nSamplePerBlock_;
248 
250  bool isInitialized_;
251 
253  // friend class CbEndBaseTest;
254 
255  };
256 
257  // Inline methods
258 
259  /*
260  * Get parent McSystem.
261  */
262  inline McSystem& McNVTChemicalPotential::system()
263  { return *systemPtr_; }
264 
265  /*
266  * Get Simulation object of parent McSystem.
267  */
268  inline Simulation& McNVTChemicalPotential::simulation()
269  { return *simulationPtr_; }
270 
271  /*
272  * Get Boundary object of parent McSystem.
273  */
274  inline Boundary& McNVTChemicalPotential::boundary()
275  { return *boundaryPtr_; }
276 
277  /*
278  * Get EnergyEnsemble object of parent McSystem.
279  */
280  inline EnergyEnsemble& McNVTChemicalPotential::energyEnsemble()
281  { return *energyEnsemblePtr_; }
282 
283  /*
284  * Get random object of parent McSystem.
285  */
286  inline Random& McNVTChemicalPotential::random()
287  { return *randomPtr_; }
288 
289  /*
290  * Boltzmann weight associated with an energy difference.
291  */
292  inline double McNVTChemicalPotential::boltzmann(double energy)
293  { return exp(-energyEnsemblePtr_->beta()*energy); }
294 
295  /*
296  * Serialize to/from an archive.
297  */
298  template <class Archive>
300  const unsigned int version)
301  {
302  if (!isInitialized_) {
303  UTIL_THROW("Error: Object not initialized.");
304  }
305 
306  ar & accumulator_;
307  ar & nSamplePerBlock_;
308  }
309 
310 }
311 #endif
A System for use in a Markov chain Monte Carlo simulation.
Definition: McSystem.h:52
A Vector is a Cartesian vector.
Definition: Vector.h:75
Calculates the average and variance of a sampled property.
Definition: Average.h:43
An orthorhombic periodic unit cell.
Classes used by all simpatico molecular simulations.
void serialize(Archive &ar, PairSelector &selector, const unsigned int version)
Serialize a PairSelector.
Definition: PairSelector.h:167
The main object in a simulation, which coordinates others.
McNVTChemicalPotential uses configuration bias algorithm to calculate the chemical potential of a lin...
Saving / output archive for binary ostream.
A statistical ensemble for energy.
#define UTIL_THROW(msg)
Macro for throwing an Exception, reporting function, file and line number.
Definition: global.h:51
Utility classes for scientific computation.
Definition: accumulators.mod:1
void serialize(Archive &ar, const unsigned int version)
Serialize to/from an archive.
Template for Analyzer associated with one System.
Saving archive for binary istream.
Single-processor Monte Carlo (MC) and molecular dynamics (MD).
Random number generator.
Definition: Random.h:46
A distribution (or histogram) of values for a real variable.
Definition: Distribution.h:23
A physical molecule (a set of covalently bonded Atoms).