SSAGES  0.9.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] += D;
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, lnorm = 0, unorm = 0;
84  std::vector<double> lcv0, ucv0, tngt, ltngt, utngt;
85  lcv0.resize(centers_.size(), 0);
86  ucv0.resize(centers_.size(), 0);
87 
88  GatherNeighbors(&lcv0, &ucv0);
89 
90  tngt.resize(centers_.size());
91  ltngt.resize(centers_.size());
92  utngt.resize(centers_.size());
93 
94  for(size_t ii = 0; ii < centers_.size(); ii++)
95  {
96  utngt[ii] = ucv0[ii] - centers_[ii];
97  ltngt[ii] = centers_[ii] - lcv0[ii];
98 
99  unorm += utngt[ii]*utngt[ii];
100  lnorm += ltngt[ii]*ltngt[ii];
101  }
102 
103  unorm = sqrt(unorm);
104  lnorm = sqrt(lnorm);
105 
106  for(size_t ii = 0; ii<centers_.size(); ii++)
107  {
108  tngt[ii] = ltngt[ii]/lnorm + utngt[ii]/unorm;
109  norm += tngt[ii]*tngt[ii];
110  }
111 
112  norm=sqrt(norm);
113 
114  for(size_t ii = 0; ii < centers_.size(); ii++) {
115  tngt[ii] /= norm;
116  newcenters_[ii] /= ((double) nsampled_);
117  dot += newcenters_[ii]*tngt[ii];
118  }
119 
120  // Evolution of the images within the band
121  // Endpoints evolve due to gradient alone.
122  for(size_t ii = 0; ii < centers_.size(); ii++)
123  {
124  if((mpiid_ != 0) && (mpiid_ != world_.size()-1))
125  {
126  //subtract out tangent from "real" force
127  newcenters_[ii] -= dot*tngt[ii];
128 
129  //centers evolve according to perpendicular "real" force and parallel "spring" force; reuses tngt def.
130  centers_[ii] += tau_ * (newcenters_[ii] + stringspring_ * (unorm - lnorm) * tngt[ii]);
131  }
132  else
133  {
134  centers_[ii] += tau_ * newcenters_[ii];
135  }
136  }
137  }
138 }
Collective variable manager.
Definition: CVManager.h:43
CVList GetCVs(const std::vector< unsigned int > &mask=std::vector< unsigned int >()) const
Get CV iterator.
Definition: CVManager.h:81
void StringUpdate() override
Updates the nudged elastic band string.
Definition: ElasticBand.cpp:81
unsigned int equilibrate_
Definition: ElasticBand.h:39
unsigned int nsampled_
Number samples actually sampled.
Definition: ElasticBand.h:49
double stringspring_
String spring constant.
Definition: ElasticBand.h:55
double tau_
Time step of string change.
Definition: ElasticBand.h:52
void PostIntegration(Snapshot *snapshot, const class CVManager &cvmanager) override
Post-integration hook.
Definition: ElasticBand.cpp:30
unsigned int evolution_
Definition: ElasticBand.h:43
unsigned int nsamples_
Block iterations.
Definition: ElasticBand.h:46
std::vector< unsigned int > cvmask_
Mask which identifies which CVs to act on.
Definition: Method.h:50
mxx::comm world_
Global MPI communicator.
Definition: Method.h:46
Class containing a snapshot of the current simulation in time.
Definition: Snapshot.h:48
const std::vector< Vector3 > & GetForces() const
Access the per-particle forces.
Definition: Snapshot.h:351
int mpiid_
The node this belongs to.
Definition: StringMethod.h:55
std::vector< double > cvspring_
Vector of spring constants.
Definition: StringMethod.h:67
void UpdateWorldString(const CVList &cvs)
Update the world string over MPI.
std::vector< double > centers_
CV starting location values.
Definition: StringMethod.h:43
bool CheckEnd(const CVList &CV)
Check if method reached one of the exit criteria.
unsigned int iteration_
The global method iteration.
Definition: StringMethod.h:73
void PrintString(const CVList &CV)
Prints the CV positions to file.
void GatherNeighbors(std::vector< double > *lcv0, std::vector< double > *ucv0)
Gather neighbors over MPI.
unsigned int iterator_
The local method iterator.
Definition: StringMethod.h:70
std::vector< double > newcenters_
CV starting location values.
Definition: StringMethod.h:46