8 #include "CfbReptateMove.h" 9 #include <mcMd/mcSimulation/McSystem.h> 11 #include <mcMd/simulation/Simulation.h> 12 #include <mcMd/chemistry/Molecule.h> 13 #include <mcMd/chemistry/Atom.h> 14 #include <mcMd/chemistry/Bond.h> 16 #include <simp/species/Linear.h> 18 #include <simp/boundary/Boundary.h> 19 #include <util/space/Vector.h> 38 maskPolicy_(MaskBonded),
55 readOptional<bool>(in,
"hasAutoCorr", hasAutoCorr_);
57 read<int>(in,
"autoCorrCapacity", autoCorrCapacity_);
58 read<std::string>(in,
"outputFileName", outputFileName_);
63 int nBond = speciesPtr->
nBond();
64 bondTypeId_ = speciesPtr->speciesBond(0).typeId();
65 for (
int i = 1; i < nBond; ++i) {
66 if (bondTypeId_ != speciesPtr->speciesBond(i).typeId()) {
77 int nAtom = speciesPtr->nAtom();
85 for (
int i = 0; i < nAtom - 1; ++i) {
86 lType = speciesPtr->atomTypeId(i);
87 uType = speciesPtr->atomTypeId(i+1);
89 junctions_[nJunction_] = i;
90 lTypes_[nJunction_] = lType;
91 uTypes_[nJunction_] = uType;
99 accumulators_.allocate(moleculeCapacity);
100 for (
int i = 0; i < moleculeCapacity; i++) {
101 accumulators_[i].setParam(autoCorrCapacity_);
117 loadParameter<bool>(ar,
"hasAutoCorr", hasAutoCorr_);
119 loadParameter<int>(ar,
"autoCorrCapacity", autoCorrCapacity_);
120 loadParameter<std::string>(ar,
"outputFileName", outputFileName_);
132 int nBond = speciesPtr->
nBond();
133 for (
int i = 0; i < nBond; ++i) {
135 UTIL_THROW(
"Inconsistent or unequal bond type ids");
139 if (maskPolicy_ !=
simulation().maskedPairPolicy()) {
140 UTIL_THROW(
"Inconsistent values of maskPolicy_");
154 ar & autoCorrCapacity_;
155 ar & outputFileName_;
172 double rosen_r, rosen_f, ratio;
173 double energy_r, energy_f;
177 int nAtom, sign, headId, tailId, oldType, i;
184 nAtom = molPtr->
nAtom();
188 if (
random().uniform(0.0, 1.0) > 0.5) {
199 tailPtr = &(molPtr->
atom(tailId));
201 oldType = tailPtr->
typeId();
204 deleteAtom(*molPtr, tailId, -sign, rosen_r, energy_r);
211 atomPtr = &(molPtr->
atom(headId));
214 if (maskPolicy_ == MaskBonded) {
217 addAtom(*molPtr, *tailPtr, *atomPtr, headId, sign, rosen_f, energy_f);
221 if (nJunction_ > 0) {
222 jFactor = junctionFactor(molPtr, sign);
229 ratio = jFactor * rosen_f / rosen_r;
235 if (maskPolicy_ == MaskBonded) {
236 atomPtr = tailPtr + sign;
246 atomPtr = tailPtr + sign;
254 for (i = 1; i < nAtom - 1; ++i) {
255 atomPtr->
position() = (atomPtr+sign)->position();
261 assert(atomPtr == &molPtr->
atom(headId));
273 int molId = molPtr->
id();
274 double rsign = (double) sign;
275 accumulators_[molId].sample(rsign);
296 double CfbReptateMove::junctionFactor(
Molecule* molPtr,
int sign)
298 double oldEnergy, newEnergy, factor;
307 for (i = 0; i < nJunction_; ++i) {
310 hAtomPtr = &(molPtr->
atom(j+1));
313 hAtomPtr = &(molPtr->
atom(j));
323 if (
system().hasExternalPotential()) {
335 if (
system().hasExternalPotential()) {
340 factor *=
boltzmann(newEnergy - oldEnergy);
345 for (i = 0; i < nJunction_; ++i) {
348 hAtomPtr = &(molPtr->
atom(j+1));
351 hAtomPtr = &(molPtr->
atom(j));
358 #else //ifdef SIMP_NOPAIR 370 autoCorrAvg.
allocate(autoCorrCapacity_);
373 for (
int i = 0; i < autoCorrCapacity_; i++) {
377 if (accumulators_[j].nSample() > i) {
379 autoCorrAvg[i] += accumulators_[j].autoCorrelation(i);
382 autoCorrAvg[i] /= nAvg;
386 std::ofstream outputFile;
387 std::string fileName = outputFileName_;
390 for (
int i = 0; i < autoCorrCapacity_; i++) {
391 outputFile <<
Int(i);
392 write<double>(outputFile, autoCorrAvg[i]);
393 outputFile << std::endl;
400 acSum = 0.5*autoCorrAvg[0];
401 for (
int i = 1; i < autoCorrCapacity_; i++) {
402 acSum += autoCorrAvg[i];
406 fileName = outputFileName_;
409 outputFile <<
"autoCorrSum " << acSum << std::endl;
A System for use in a Markov chain Monte Carlo simulation.
A Vector is a Cartesian vector.
void addAtom(Molecule &molecule, Atom &atom0, Atom &atom1, int atomId, int sign, double &rosenbluth, double &energy)
Configuration bias algorithm for adding an atom to a Linear molecule.
virtual double atomEnergy(const Atom &atom) const =0
Calculate the external energy for one Atom.
FileMaster & fileMaster() const
Get the associated FileMaster by reference.
void incrementNAttempt()
Increment the number of attempted moves.
Include this file to include all MC potential energy classes at once.
virtual void save(Serializable::OArchive &ar)
Save internal state to an archive.
CfbReptateMove(McSystem &system)
Constructor.
void addAtom(Atom &atom)
Add an Atom to the CellList.
void openOutputFile(const std::string &filename, std::ofstream &out, std::ios_base::openmode mode=std::ios_base::out) const
Open an output file.
Mask & mask()
Get the associated Mask by reference.
virtual void loadParameters(Serializable::IArchive &ar)
Load internal state from an archive.
MaskPolicy maskedPairPolicy() const
Return the value of the mask policy (MaskNone or MaskBonded).
virtual void save(Serializable::OArchive &ar)
Save speciesId and nTrial.
File containing preprocessor macros for error handling.
Classes used by all simpatico molecular simulations.
int id() const
Get the index for this Molecule (unique in species).
virtual void readParameters(std::istream &in)
Read and validate speciesId and nTrial.
Base class for configuration bias (CFB) end regrowth moves.
virtual void output()
Output statistics about accepted reptation steps.
Saving / output archive for binary ostream.
double boltzmann(double energy)
Boltzmann weight associated with an energy difference.
const SpeciesBond & speciesBond(int iBond) const
Get a specific SpeciesBond object, by local bond index.
int nMolecule(int speciesId) const
Get the number of molecules of one Species in this System.
#define UTIL_THROW(msg)
Macro for throwing an Exception, reporting function, file and line number.
McSystem & system()
Get parent McSystem.
Molecule & randomMolecule(int speciesId)
Get a random Molecule of a specified species in this System.
void incrementNAccept()
Increment the number of accepted moves.
int typeId() const
Get type index for this Atom.
ExternalPotential & externalPotential() const
Return ExternalPotential by reference.
A point particle within a Molecule.
void clear()
Clear the mask set (remove all atoms).
Utility classes for scientific computation.
int typeId() const
Get the type id for this covalent group.
Wrapper for an int, for formatted ostream output.
int speciesId() const
Get speciesId.
Random & random()
Get Random number generator of parent Simulation.
virtual void loadParameters(Serializable::IArchive &ar)
Load and validate speciesId and nTrial.
McPairPotential & pairPotential() const
Return the McPairPotential by reference.
void deleteAtom(Molecule &molecule, int atomId, int sign, double &rosenbluth, double &energy)
CFB algorithm for deleting an end atom from a Linear molecule.
void setTypeId(int typeId)
Set the atomic type index.
Saving archive for binary istream.
virtual void save(Serializable::OArchive &ar)
Save internal state to an archive.
Single-processor Monte Carlo (MC) and molecular dynamics (MD).
void readProbability(std::istream &in)
Read the probability from file.
void setClassName(const char *className)
Set class name string.
const Atom & atom(int localId) const
Get a specific Atom in this Molecule.
int capacity() const
Maximum allowed number of molecules for this Species.
bool metropolis(double ratio)
Metropolis algorithm for whether to accept a MC move.
void allocate(int capacity)
Allocate the underlying C array.
Simulation & simulation()
Get parent Simulation object.
A physical molecule (a set of covalently bonded Atoms).
const Vector & position() const
Get the position Vector by const reference.
virtual void loadParameters(Serializable::IArchive &ar)
Load internal state from an archive.
A Species represents a set of chemically similar molecules.
int nBond() const
Get number of bonds per molecule for this Species.
Species & species(int i)
Get a specific Species by reference.
virtual bool move()
Generate and accept or reject configuration bias move.
void deleteAtom(Atom &atom)
Remove an Atom from the CellList.
void updateAtomCell(Atom &atom)
Update the cell list to reflect a new position.
int nAtom() const
Get the number of Atoms in this Molecule.
virtual double atomEnergy(const Atom &atom) const =0
Calculate the nonbonded pair energy for one Atom.
void append(const Atom &atom)
Add an Atom to the masked set.
virtual void readParameters(std::istream &in)
Read species to which displacement is applied.