SSAGES  0.8.3
Software Suite for Advanced General Ensemble Simulations
ElasticBand.cpp
1 
21 #include "ElasticBand.h"
22 #include "CVs/CVManager.h"
23 #include "Snapshot.h"
24 #include <math.h>
25 #include <iostream>
26 
27 namespace SSAGES
28 {
29  // Post-integration hook.
30  void ElasticBand::PostIntegration(Snapshot* snapshot, const CVManager& cvmanager)
31  {
32  auto& forces = snapshot->GetForces();
33  auto cvs = cvmanager.GetCVs(cvmask_);
34 
35  // Apply umbrella to cvs
36  for(size_t i = 0; i < cvs.size(); ++i)
37  {
38  // Get current CV and gradient.
39  auto& cv = cvs[i];
40  auto& grad = cv->GetGradient();
41 
42  // Compute dV/dCV.
43  auto diff = cv->GetDifference(centers_[i]);
44  auto D = cvspring_[i] * diff;
45 
46  // Update forces.
47  for(size_t j = 0; j < forces.size(); ++j)
48  for(int k = 0; k < forces[j].size(); ++k)
49  forces[j][k] -= D*grad[j][k];
50 
51  // If not equilibrating and has evolved enough steps,
52  // generate the gradient
54  {
55  newcenters_[i] += diff;
56  nsampled_++;
57  }
58  }
59 
60  // Restart iteration and zero gradients when moving onto
61  // next elastic band iteration
63  {
64  StringUpdate();
65  CheckEnd(cvs);
66  UpdateWorldString(cvs);
67  PrintString(cvs);
68 
69  iterator_ = 0;
70 
71  for(size_t ii = 0; ii < newcenters_.size(); ii++)
72  newcenters_[ii] = 0;
73 
74  nsampled_ = 0;
75  iteration_++;
76  }
77 
78  iterator_++;
79  }
80 
82  {
83  double dot=0, norm=0;
84  std::vector<double> lcv0, ucv0, tngt;
85  lcv0.resize(centers_.size(), 0);
86  ucv0.resize(centers_.size(), 0);
87 
88  GatherNeighbors(&lcv0, &ucv0);
89 
90  tngt.resize(centers_.size());
91 
92  for(size_t ii = 0; ii<centers_.size(); ii++)
93  {
94  tngt[ii] = ucv0[ii] - lcv0[ii];
95  norm+=tngt[ii]*tngt[ii];
96  }
97 
98  norm=sqrt(norm);
99 
100  for(size_t ii = 0; ii < centers_.size(); ii++) {
101  tngt[ii] /= norm;
102  newcenters_[ii] /= ((double) nsampled_);
103  dot+=newcenters_[ii]*tngt[ii];
104  }
105 
106  // Evolution of the images and reparametrirized of the string
107  for(size_t ii = 0; ii < centers_.size(); ii++)
108  {
109  if((mpiid_ != 0) && (mpiid_ != world_.size()-1))
110  {
111  newcenters_[ii] -= dot*tngt[ii];
112  centers_[ii] = centers_[ii] + tau_ *
113  (newcenters_[ii] + stringspring_ * (ucv0[ii] + lcv0[ii] - 2 * centers_[ii]));
114  }
115  else
116  {
117  centers_[ii] = centers_[ii] + tau_ * newcenters_[ii];
118  }
119  }
120  }
121 }
std::vector< CollectiveVariable * > GetCVs(const std::vector< unsigned int > &mask=std::vector< unsigned int >()) const
Get CV iterator.
Definition: CVManager.h:80
Collective variable manager.
Definition: CVManager.h:40
unsigned int nsampled_
Number samples actually sampled.
Definition: ElasticBand.h:49
void StringUpdate() override
Updates the nudged elastic band string.
Definition: ElasticBand.cpp:81
const std::vector< Vector3 > & GetForces() const
Access the per-particle forces.
Definition: Snapshot.h:362
Class containing a snapshot of the current simulation in time.
Definition: Snapshot.h:43
void GatherNeighbors(std::vector< double > *lcv0, std::vector< double > *ucv0)
Gather neighbors over MPI.
std::vector< double > centers_
CV starting location values.
Definition: StringMethod.h:43
std::vector< double > newcenters_
CV starting location values.
Definition: StringMethod.h:46
mxx::comm world_
Global MPI communicator.
Definition: Method.h:46
bool CheckEnd(const CVList &CV)
Check if method reached one of the exit criteria.
double tau_
Time step of string change.
Definition: ElasticBand.h:52
int mpiid_
The node this belongs to.
Definition: StringMethod.h:55
void UpdateWorldString(const CVList &cvs)
Update the world string over MPI.
void PrintString(const CVList &CV)
Prints the CV positions to file.
unsigned int iterator_
The local method iterator.
Definition: StringMethod.h:70
std::vector< unsigned int > cvmask_
Mask which identifies which CVs to act on.
Definition: Method.h:50
unsigned int iteration_
The global method iteration.
Definition: StringMethod.h:73
std::vector< double > cvspring_
Vector of spring constants.
Definition: StringMethod.h:67
void PostIntegration(Snapshot *snapshot, const class CVManager &cvmanager) override
Post-integration hook.
Definition: ElasticBand.cpp:30
unsigned int equilibrate_
Definition: ElasticBand.h:39
unsigned int evolution_
Definition: ElasticBand.h:43
unsigned int nsamples_
Block iterations.
Definition: ElasticBand.h:46
double stringspring_
String spring constant.
Definition: ElasticBand.h:55