Simpatico  v1.10
MdMove.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 "MdMove.h"
9 #include <mcMd/mcSimulation/McSystem.h>
10 #include <mcMd/mdSimulation/MdSystem.h>
11 #include <mcMd/mdIntegrators/MdIntegrator.h>
12 #ifndef SIMP_NOPAIR
13 #include <mcMd/potentials/pair/MdPairPotential.h>
14 #include <mcMd/potentials/pair/McPairPotential.h>
15 #endif
16 
17 namespace McMd
18 {
19 
20  using namespace Util;
21 
22  /*
23  * Constructor
24  */
26  SystemMove(system),
27  mdSystemPtr_(0),
28  nStep_(0)
29  {
30  setClassName("MdMove");
31  mdSystemPtr_ = new MdSystem(system);
32  }
33 
34  /*
35  * Destructor.
36  */
38  {
39  if (mdSystemPtr_) {
40  delete mdSystemPtr_;
41  }
42  }
43 
44  /*
45  * Read parameter maxDisp
46  */
47  void MdMove::readParameters(std::istream& in)
48  {
49  readProbability(in);
50  read<int>(in, "nStep", nStep_);
51  readParamComposite(in, *mdSystemPtr_);
52  }
53 
54  /*
55  * Load internal state from an archive.
56  */
58  {
60  loadParameter<int>(ar, "nStep", nStep_);
61  loadParamComposite(ar, *mdSystemPtr_);
62  }
63 
64  /*
65  * Save internal state to an archive.
66  */
68  {
69  McMove::save(ar);
70  ar << nStep_;
71  mdSystemPtr_->saveParameters(ar);
72  }
73 
74  /*
75  * Generate, attempt and accept or reject a Hybrid MD/MC move.
76  */
77  bool MdMove::move()
78  {
80 
81  // Initialize MdSystem
82  #ifndef SIMP_NOPAIR
83  mdSystemPtr_->pairPotential().buildPairList();
84  #endif
85  mdSystemPtr_->calculateForces();
86  mdSystemPtr_->setBoltzmannVelocities(energyEnsemble().temperature());
87 
88  // Run a short MD simulation
89  for (int iStep = 0; iStep < nStep_; ++iStep) {
90  mdSystemPtr_->mdIntegrator().step();
91  }
92 
93  #ifndef SIMP_NOPAIR
94  // Rebuild the McSystem cellList using the new positions.
96  #endif
97 
98  // Accept all moves
100  return true;
101  }
102 
103 }
A System for use in a Markov chain Monte Carlo simulation.
Definition: McSystem.h:52
void buildCellList()
Build the CellList with current configuration.
void calculateForces()
Compute all forces in this System.
Definition: MdSystem.cpp:857
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
void loadParamComposite(Serializable::IArchive &ar, ParamComposite &child, bool next=true)
Add and load a required child ParamComposite.
MdIntegrator & mdIntegrator()
Return the MdIntegrator by reference.
Definition: MdSystem.h:660
bool move()
Generate, attempt and accept or reject a move.
Definition: MdMove.cpp:77
virtual void loadParameters(Serializable::IArchive &ar)
Load internal state from an archive.
Definition: McMove.cpp:48
~MdMove()
Destructor.
Definition: MdMove.cpp:37
virtual void save(Serializable::OArchive &ar)
Save internal state to an archive.
Definition: MdMove.cpp:67
Saving / output archive for binary ostream.
MdPairPotential & pairPotential() const
Return MdPairPotential by reference.
Definition: MdSystem.h:520
virtual void readParameters(std::istream &in)
Read nStep, dt, skin, maxNPair from file.
Definition: MdMove.cpp:47
McSystem & system()
Get parent McSystem.
Definition: SystemMove.h:82
void incrementNAccept()
Increment the number of accepted moves.
Definition: McMove.h:197
Utility classes for scientific computation.
Definition: accumulators.mod:1
void setBoltzmannVelocities(double temperature)
Set all velocities to Boltzmann distributed random values.
Definition: MdSystem.cpp:797
An McMove that acts on one McSystem.
Definition: SystemMove.h:28
MdMove(McSystem &system)
Constructor.
Definition: MdMove.cpp:25
McPairPotential & pairPotential() const
Return the McPairPotential by reference.
Definition: McSystem.h:388
Saving archive for binary istream.
Single-processor Monte Carlo (MC) and molecular dynamics (MD).
void buildPairList()
Build the internal PairList.
void readProbability(std::istream &in)
Read the probability from file.
Definition: McMove.cpp:42
void setClassName(const char *className)
Set class name string.
void readParamComposite(std::istream &in, ParamComposite &child, bool next=true)
Add and read a required child ParamComposite.
A System for Molecular Dynamics simulation.
Definition: MdSystem.h:68
virtual void step()=0
Take a complete MD integration step.
EnergyEnsemble & energyEnsemble()
Get EnergyEnsemble object of parent McSystem.
Definition: SystemMove.h:94
virtual void saveParameters(Serializable::OArchive &ar)
Save parameters to an archive, without configuration.
Definition: MdSystem.cpp:582
virtual void loadParameters(Serializable::IArchive &ar)
Load internal state from an archive.
Definition: MdMove.cpp:57