Simpatico  v1.10
McEnergyPerturbation.cpp
1 #ifdef MCMD_PERTURB
2 /*
3 * Simpatico - Simulation Package for Polymeric and Molecular Liquids
4 *
5 * Copyright 2010 - 2017, The Regents of the University of Minnesota
6 * Distributed under the terms of the GNU General Public License.
7 */
8 
9 #include "McEnergyPerturbation.h"
10 #include <mcMd/mcSimulation/McSystem.h>
11 #include <simp/ensembles/EnergyEnsemble.h>
12 
13 namespace McMd
14 {
15 
16  using namespace Util;
17  using namespace Simp;
18 
19  /*
20  * Constructor.
21  */
23  int size, int rank)
24  : LinearPerturbation<McSystem>(system, size, rank)
25  {}
26 
27  /*
28  * Read beta = 1/kT from file
29  */
30  void McEnergyPerturbation::readParameters(std::istream& in)
31  {
33  nParameters_ = Perturbation::getNParameters();
34  }
35 
36  /*
37  * Set inverse temperature.
38  *
39  * \param parameter inverse temperature beta.
40  */
43 
44  /*
45  * Get inverse temperature of the parent system.
46  */
47  double McEnergyPerturbation::parameter(int i) const
48  {
49  if (i > nParameters_) {
50  UTIL_THROW("perturbation parameter index is out of bounds");
51  }
52  double T = system().energyEnsemble().temperature();
53  return (1.0/T);
54  }
55 
56  /*
57  * Return the system energy.
58  */
60  {
61  if (i > nParameters_) {
62  UTIL_THROW("perturbation parameter index is out of bounds");
63  }
64  return system().potentialEnergy();
65  }
66 
67 }
68 
69 #endif // ifdef MCMD_PERTURB
DArray< double > parameter_
Value of the perturbation parameter for the associated System.
Definition: Perturbation.h:172
A System for use in a Markov chain Monte Carlo simulation.
Definition: McSystem.h:52
virtual void readParameters(std::istream &in)
Read beta parameter (inverse temperature) from file.
double potentialEnergy() const
Return total potential energy of this System.
Definition: McSystem.cpp:503
McEnergyPerturbation(McSystem &system, int size, int rank)
Constructor.
A Perturbation that is a linear function of a parameter.
EnergyEnsemble & energyEnsemble() const
Get the EnergyEnsemble by reference.
Definition: System.h:1095
Classes used by all simpatico molecular simulations.
virtual double parameter(int i) const
Get inverse temperature of the parent system.
#define UTIL_THROW(msg)
Macro for throwing an Exception, reporting function, file and line number.
Definition: global.h:51
virtual double derivative(int i) const
Get derivative of the Boltzmann weight with respect to the perturbation parameter.
Utility classes for scientific computation.
Definition: accumulators.mod:1
int getNParameters() const
Gets the number of parameters per system.
McSystem & system() const
Get the associated System by reference.
void setTemperature(double temperature)
Set the temperature.
Single-processor Monte Carlo (MC) and molecular dynamics (MD).
double temperature() const
Return the temperature.
void readParameters(std::istream &in)
Read perturbation parameter(s) from file.
virtual void setParameter()
Set inverse temperature of the parent system.