8 #include "CfbReptationMove.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> 17 #include <simp/boundary/Boundary.h> 19 #include <util/space/Vector.h> 39 maskPolicy_(MaskBonded),
43 acceptedStepsAccumulators_()
55 read<int>(in,
"speciesId", speciesId_);
56 read<int>(in,
"nTrial",
nTrial_);
67 UTIL_THROW(
"Species is not a subclass of Linear");
74 int nBond = speciesPtr->
nBond();
75 for (
int i = 1; i < nBond; ++i) {
87 int nAtom = speciesPtr->
nAtom();
95 for (
int i = 0; i < nAtom - 1; ++i) {
99 junctions_[nJunction_] = i;
100 lTypes_[nJunction_] = lType;
101 uTypes_[nJunction_] = uType;
108 read<int>(in,
"hasAutoCorr", hasAutoCorr_);
112 read<int>(in,
"autoCorrCapacity", autoCorrCapacity_);
113 read<std::string>(in,
"autoCorrName", outputFileName_);
117 acceptedStepsAccumulators_.allocate(moleculeCapacity);
118 for (
int i = 0; i < moleculeCapacity; i++)
120 acceptedStepsAccumulators_[i].setParam(autoCorrCapacity_);
133 loadParameter<int>(ar,
"speciesId", speciesId_);
134 loadParameter<int>(ar,
"nTrial",
nTrial_);
139 if (nTrial_ <=0 || nTrial_ >
MaxTrial_) {
145 UTIL_THROW(
"Species is not a subclass of Linear");
147 int nBond = speciesPtr->
nBond();
148 for (
int i = 0; i < nBond; ++i) {
150 UTIL_THROW(
"Inconsistent or unequal bond type ids");
154 if (maskPolicy_ !=
simulation().maskedPairPolicy()) {
155 UTIL_THROW(
"Inconsistent values of maskPolicy_");
164 loadParameter<int>(ar,
"hasAutoCorr", hasAutoCorr_);
166 loadParameter<int>(ar,
"autoCorrCapacity", autoCorrCapacity_);
167 loadParameter<std::string>(ar,
"autoCorrName", outputFileName_);
168 ar & acceptedStepsAccumulators_;
188 ar & autoCorrCapacity_;
189 ar & outputFileName_;
190 ar & acceptedStepsAccumulators_;
200 double rosen_r, rosen_f, ratio;
201 double energy_r, energy_f;
205 int length, sign, headId, tailId, oldType, i;
212 length = molPtr->
nAtom();
215 if (
random().uniform(0.0, 1.0) > 0.5) {
226 tailPtr = &(molPtr->
atom(tailId));
228 oldType = tailPtr->
typeId();
231 atomPtr = tailPtr + sign;
232 deleteEndAtom(tailPtr, atomPtr, bondTypeId_, rosen_r, energy_r);
239 atomPtr = &(molPtr->
atom(headId));
242 if (maskPolicy_ == MaskBonded) {
245 addEndAtom(tailPtr, atomPtr, bondTypeId_, rosen_f, energy_f);
248 double jFactor = 1.0;
249 if (nJunction_ > 0) {
250 jFactor = junctionFactor(molPtr, sign);
255 ratio = jFactor * rosen_f / rosen_r;
261 if (maskPolicy_ == MaskBonded) {
262 atomPtr = tailPtr + sign;
272 atomPtr = tailPtr + sign;
281 for (i=1; i < length - 1; ++i) {
283 atomPtr->
position() = (atomPtr+sign)->position();
303 acceptedStepsAccumulators_[molPtr->
id()].sample((
double) sign);
324 double CfbReptationMove::junctionFactor(
Molecule* molPtr,
int sign)
327 double oldEnergy, newEnergy, factor;
337 for (i = 0; i < nJunction_; ++i) {
340 hAtomPtr = &(molPtr->
atom(j+1));
343 hAtomPtr = &(molPtr->
atom(j));
352 if (
system().hasExternalPotential()) {
363 if (
system().hasExternalPotential()) {
369 factor *=
boltzmann(newEnergy - oldEnergy);
375 for (i = 0; i < nJunction_; ++i) {
378 hAtomPtr = &(molPtr->
atom(j+1));
381 hAtomPtr = &(molPtr->
atom(j));
388 #else //ifdef SIMP_NOPAIR 401 autoCorrAvg.
allocate(autoCorrCapacity_);
405 for (
int i = 0; i < autoCorrCapacity_; i++) {
410 if (acceptedStepsAccumulators_[j].nSample() > i)
413 autoCorrAvg[i] += acceptedStepsAccumulators_[j].
417 autoCorrAvg[i] /= nAvg;
420 std::ofstream outputFile;
426 for (
int i = 0; i < autoCorrCapacity_; i++)
428 outputFile <<
Int(i);
429 write<double>(outputFile, autoCorrAvg[i]);
430 outputFile << std::endl;
438 acSum = 0.5*autoCorrAvg[0];
439 for (
int i = 1; i < autoCorrCapacity_; i++)
440 acSum += autoCorrAvg[i];
445 outputFile <<
"autoCorrSum " << acSum << std::endl;
static const int MaxTrial_
Maximum allowed number of trial positions for a regrown atom.
A System for use in a Markov chain Monte Carlo simulation.
A Vector is a Cartesian vector.
virtual double atomEnergy(const Atom &atom) const =0
Calculate the external energy for one Atom.
void addEndAtom(Atom *endPtr, Atom *pvtPtr, int bondType, double &rosenbluth, double &energy)
Configuration bias algorithm for adding an atom to a chain end.
FileMaster & fileMaster() const
Get the associated FileMaster by reference.
void incrementNAttempt()
Increment the number of attempted moves.
int nAtom() const
Get number of atoms per molecule for this Species.
Include this file to include all MC potential energy classes at once.
virtual void output()
Output statistics about accepted reptation steps.
virtual void loadParameters(Serializable::IArchive &ar)
Load internal state from an archive.
virtual void save(Serializable::OArchive &ar)
Save internal state to an archive.
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 readParameters(std::istream &in)
Read species to which displacement is applied.
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 save(Serializable::OArchive &ar)
Save internal state to an archive.
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.
CfbReptationMove(McSystem &system)
Constructor.
int typeId() const
Get the type id for this covalent group.
Wrapper for an int, for formatted ostream output.
int atomTypeId(int iAtom) const
Get atom type index for a specific atom, by local atom index.
virtual bool move()
Generate and accept or reject configuration bias move.
Random & random()
Get Random number generator of parent Simulation.
McPairPotential & pairPotential() const
Return the McPairPotential by reference.
void deleteEndAtom(Atom *endPtr, Atom *pvtPtr, int bondType, double &rosenbluth, double &energy)
CFB algorithm for deleting an end atom from a flexible chain.
void setTypeId(int typeId)
Set the atomic type index.
Saving archive for binary istream.
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.
int nTrial_
Actual number of trial positions for each regrown atom.
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.
Base class for configuration bias (CFB) end regrowth moves.
int nBond() const
Get number of bonds per molecule for this Species.
Species & species(int i)
Get a specific Species by reference.
void deleteAtom(Atom &atom)
Remove an Atom from the CellList.
void updateAtomCell(Atom &atom)
Update the cell list to reflect a new position.
A Species of linear polymers (abstract).
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.