Simpatico  v1.10
AtomDisplaceMove.cpp
1 /*
2 * Simpatico - Simulation Package for Polymeric and Molecular Liquids
3 *
4 * Copyright 2010 - 2017, The Regents of the University of Minnesota
5 * Distributed under the terms of the GNU General Public License.
6 */
7 
8 #include "AtomDisplaceMove.h"
9 #include <mcMd/mcSimulation/McSystem.h>
10 #ifndef SIMP_NOPAIR
11 #include <mcMd/potentials/pair/McPairPotential.h>
12 #endif
13 #include <mcMd/chemistry/Molecule.h>
14 #include <mcMd/chemistry/Atom.h>
15 #include <simp/boundary/Boundary.h>
16 #include <util/space/Vector.h>
17 #include <util/space/Dimension.h>
18 #include <util/global.h>
19 
20 namespace McMd
21 {
22 
23  using namespace Util;
24  using namespace Simp;
25 
26  /*
27  * Constructor
28  */
30  : SystemMove(system),
31  delta_(0.0),
32  speciesId_(-1)
33  { setClassName("AtomDisplaceMove"); }
34 
35  /*
36  * Read speciesId and delta.
37  */
38  void AtomDisplaceMove::readParameters(std::istream& in)
39  {
40  readProbability(in);
41  read<int>(in, "speciesId", speciesId_);
42  read<double>(in, "delta", delta_);
43  }
44 
45  /*
46  * Load internal state from an archive.
47  */
49  {
51  loadParameter<int>(ar, "speciesId", speciesId_);
52  loadParameter<double>(ar, "delta", delta_);
53  }
54 
55  /*
56  * Save internal state to an archive.
57  */
59  {
60  McMove::save(ar);
61  ar << speciesId_;
62  ar << delta_;
63  }
64 
65  /*
66  * Generate, attempt and accept or reject a move.
67  */
69  {
70  Vector oldPos;
71  double newEnergy, oldEnergy;
72  Molecule* molPtr;
73  Atom* atomPtr;
74  int iAtom;
75 
77 
78  // Choose a molecule and atom at random
79  molPtr = &(system().randomMolecule(speciesId_));
80  iAtom = random().uniformInt(0, molPtr->nAtom());
81  atomPtr = &molPtr->atom(iAtom);
82 
83  // Calculate current pair energy and store old position
84  oldPos = atomPtr->position();
85  oldEnergy = system().atomPotentialEnergy(*atomPtr);
86 
87  for (int j = 0; j < Dimension; ++j) {
88  atomPtr->position()[j] += random().uniform(-delta_, delta_);
89  }
90  boundary().shift(atomPtr->position());
91  newEnergy = system().atomPotentialEnergy(*atomPtr);
92 
93  // Decide whether to accept forward move
94  bool accept = random().metropolis(boltzmann(newEnergy - oldEnergy));
95 
96  if (accept) {
97  #ifndef SIMP_NOPAIR
98  system().pairPotential().updateAtomCell(*atomPtr);
99  #endif
101  } else {
102  atomPtr->position() = oldPos;
103  }
104 
105  return accept;
106  }
107 
108 }
const int Dimension
Dimensionality of space.
Definition: Dimension.h:19
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
void incrementNAttempt()
Increment the number of attempted moves.
Definition: McMove.h:191
virtual void save(Serializable::OArchive &ar)
Save internal state to an archive.
Definition: McMove.cpp:58
double atomPotentialEnergy(const Atom &atom) const
Calculate the total potential energy for one Atom.
Definition: McSystem.cpp:459
virtual void loadParameters(Serializable::IArchive &ar)
Load internal state from an archive.
Definition: McMove.cpp:48
virtual void save(Serializable::OArchive &ar)
Save internal state to an archive.
File containing preprocessor macros for error handling.
Classes used by all simpatico molecular simulations.
double uniform()
Return a random floating point number x, uniformly distributed in the range 0 <= x < 1...
Definition: Random.h:203
Saving / output archive for binary ostream.
double boltzmann(double energy)
Boltzmann weight associated with an energy difference.
Definition: SystemMove.h:100
McSystem & system()
Get parent McSystem.
Definition: SystemMove.h:82
Molecule & randomMolecule(int speciesId)
Get a random Molecule of a specified species in this System.
Definition: System.cpp:1200
void incrementNAccept()
Increment the number of accepted moves.
Definition: McMove.h:197
AtomDisplaceMove(McSystem &system)
Constructor.
A point particle within a Molecule.
Utility classes for scientific computation.
Definition: accumulators.mod:1
An McMove that acts on one McSystem.
Definition: SystemMove.h:28
long uniformInt(long range1, long range2)
Return random long int x uniformly distributed in range1 <= x < range2.
Definition: Random.h:224
void shift(Vector &r) const
Shift Cartesian Vector r to its primary image.
Random & random()
Get Random number generator of parent Simulation.
Definition: McMove.h:209
McPairPotential & pairPotential() const
Return the McPairPotential by reference.
Definition: McSystem.h:388
virtual void readParameters(std::istream &in)
Read species to which displacement is applied.
Saving archive for binary istream.
virtual bool move()
Generate, attempt and accept or reject a move.
Single-processor Monte Carlo (MC) and molecular dynamics (MD).
void readProbability(std::istream &in)
Read the probability from file.
Definition: McMove.cpp:42
void setClassName(const char *className)
Set class name string.
const Atom & atom(int localId) const
Get a specific Atom in this Molecule.
bool metropolis(double ratio)
Metropolis algorithm for whether to accept a MC move.
Definition: Random.h:260
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.
void updateAtomCell(Atom &atom)
Update the cell list to reflect a new position.
int nAtom() const
Get the number of Atoms in this Molecule.
Boundary & boundary()
Get Boundary object of parent McSystem.
Definition: SystemMove.h:88