4 #ifndef MCMD_MC_PAIR_EXTERNAL_PERTURBATION_H 5 #define MCMD_MC_PAIR_EXTERNAL_PERTURBATION_H 15 #include <mcMd/perturb/LinearPerturbation.h> 16 #include <mcMd/neighbor/CellList.h> 17 #include <mcMd/simulation/Simulation.h> 18 #include <mcMd/mcSimulation/McSystem.h> 19 #include <mcMd/potentials/pair/McPairPotentialImpl.h> 20 #include <mcMd/potentials/external/ExternalPotentialImpl.h> 21 #include <mcMd/chemistry/Atom.h> 22 #include <simp/ensembles/EnergyEnsemble.h> 23 #include <util/containers/DMatrix.h> 24 #include <util/containers/DArray.h> 25 #include <util/containers/Pair.h> 48 template <
class PairInteraction,
class ExternalInteraction >
73 virtual void readParameters(std::istream& in);
79 virtual void setParameter();
87 virtual double parameter(
int i)
const;
93 virtual double derivative(
int i)
const;
95 PairInteraction& pairInteraction()
const;
97 ExternalInteraction& externalInteraction()
const;
105 mutable PairInteraction* pairInteractionPtr_;
108 mutable ExternalInteraction* externalInteractionPtr_;
123 template <
class PairInteraction,
class ExternalInteraction >
126 pairInteractionPtr_(0),
127 externalInteractionPtr_(0)
133 template <
class PairInteraction,
class ExternalInteraction >
140 template <
class PairInteraction,
class ExternalInteraction >
149 template <
class PairInteraction,
class ExternalInteraction >
152 if (pairInteractionPtr_ == 0) {
157 UTIL_THROW(
"Failed dynamic cast of McPairPotential");
161 return *pairInteractionPtr_;
166 template <
class PairInteraction,
class ExternalInteraction >
169 if (externalInteractionPtr_ == 0) {
174 UTIL_THROW(
"Failed dynamic cast of ExternalPotential");
178 return *externalInteractionPtr_;
185 template <
class PairInteraction,
class ExternalInteraction >
188 pairInteraction().setEpsilon(0, 1,
parameter_[0]);
189 externalInteraction().setExternalParameter(
parameter_[1]);
196 template <
class PairInteraction,
class ExternalInteraction >
199 if (i >= nParameters_) {
200 UTIL_THROW(
"perturbation parameter index is out of bounds");
204 param = pairInteraction().epsilon(0, 1);
206 param = externalInteraction().externalParameter();
215 template <
class PairInteraction,
class ExternalInteraction >
219 if (i >= nParameters_) {
220 UTIL_THROW(
"perturbation parameter index is out of bounds");
225 UTIL_THROW(
"Pair perturbation parameter is not set correctly");
227 double pairEnergy, rsq;
228 Atom *jAtomPtr, *kAtomPtr;
229 int nNeighbor, nInCell;
230 int ic, nc, j, k, jId, kId, jType, kType;
234 for (ic = 0; ic < nc; ++ic) {
238 nNeighbor = neighbors_.
size();
241 for (j = 0; j < nInCell; ++j) {
242 jAtomPtr = neighbors_[j];
243 jId = jAtomPtr->
id();
244 jType = jAtomPtr->
typeId();
247 for (k = 0; k < nNeighbor; ++k) {
248 kAtomPtr = neighbors_[k];
249 kId = kAtomPtr->
id();
250 kType = kAtomPtr->
typeId();
253 if (kId > jId && jType != kType) {
260 pairEnergy += pairInteraction().
277 UTIL_THROW(
"Non isothermal ensemble for McPairPerturbation.");
281 }
else if ( i == 1 ) {
283 UTIL_THROW(
"External perturbation parameter is not set correctly");
285 double externalEnergy;
289 externalEnergy = 0.0;
293 for (molIter->begin(atomIter); atomIter.
notEnd(); ++atomIter) {
316 #endif // #ifndef SIMP_NOPAIR 317 #endif // #ifdef SIMP_EXTERNAL 318 #endif // ifdef MCMD_PERTURB DArray< double > parameter_
Value of the perturbation parameter for the associated System.
A System for use in a Markov chain Monte Carlo simulation.
void begin(int speciesId, MoleculeIterator &iterator)
Initialize an iterator for molecules of one species in this System.
bool notEnd() const
Is the current pointer not at the end of the array?
const CellList & cellList() const
Get the cellList by const reference.
A Perturbation that is a linear function of a parameter.
A PairPotential for MC simulations (abstract).
EnergyEnsemble & energyEnsemble() const
Get the EnergyEnsemble by reference.
Mask & mask()
Get the associated Mask by reference.
File containing preprocessor macros for error handling.
Classes used by all simpatico molecular simulations.
virtual double energy(const Vector &position, int i) const =0
Returns external potential energy of a single particle.
bool isMasked(const Atom &atom) const
True if the atom is in the masked set for the target Atom.
double beta() const
Return the inverse temperature.
#define UTIL_THROW(msg)
Macro for throwing an Exception, reporting function, file and line number.
Simulation & simulation() const
Get the parent Simulation by reference.
Implementation template for an McPairPotential.
Abstract External Potential class.
int typeId() const
Get type index for this Atom.
void getCellNeighbors(int ic, NeighborArray &neighbors, int &nInCell) const
Fill an array with pointers to atoms in a cell and neighboring cells.
ExternalPotential & externalPotential() const
Return ExternalPotential by reference.
bool isIsothermal() const
Is this an Isothermal ensemble?
Interaction & interaction()
Return external interaction by reference.
A point particle within a Molecule.
bool notEnd() const
Is the current pointer not at the end of the PArray?
Utility classes for scientific computation.
int getNParameters() const
Gets the number of parameters per system.
int id() const
Get global index for this Atom within the Simulation.
Interaction & interaction()
Return reference to underlying pair interaction.
A Perturbation in the pair interaction epsilon(0,1) for any pair potential supporting setEpsilon() an...
int totCells() const
Get total number of cells in this CellList.
Forward iterator for an Array or a C array.
McSystem & system() const
Get the associated System by reference.
Forward iterator for a PArray.
virtual double parameter(int i) const
Return the perturbation parameter for this System.
virtual double derivative(int i) const
Return (0-1 pair energy) / ( kT *epsilon(0,1) ) if i is 0 or (external potential energy)/ ( kT *exter...
McPairPotential & pairPotential() const
Return the McPairPotential by reference.
Boundary & boundary() const
Get the Boundary by reference.
Template implementation of ExternalPotential.
Single-processor Monte Carlo (MC) and molecular dynamics (MD).
virtual void setParameter()
Set pair interaction parameter epsilon(0,1) and external parameter for this System.
int nSpecies() const
Get the number of Species in this Simulation.
void setClassName(const char *className)
Set class name string.
const Vector & position() const
Get the position Vector by const reference.
virtual void readParameters(std::istream &in)
Read parameter epsilon(0, 1) and external parameter from file.
int size() const
Return logical size of this array (i.e., number of elements).
McPairExternalPerturbation(McSystem &system, int size, int rank)
Constructor.
void readParameters(std::istream &in)
Read perturbation parameter(s) from file.