SSAGES  0.8.5
Software Suite for Advanced General Ensemble Simulations
StringMethod.h
1 
22 #pragma once
23 
24 #include <numeric>
25 
26 #include "Method.h"
27 #include <fstream>
28 
29 namespace SSAGES
30 {
32 
38  class StringMethod : public Method
39  {
40  protected:
41 
43  std::vector<double> centers_;
44 
46  std::vector<double> newcenters_;
47 
49 
52  std::vector<std::vector<double> > worldstring_;
53 
55  int mpiid_;
56 
58  std::vector<double> tol_;
59 
61  int numnodes_;
62 
64  unsigned int maxiterator_;
65 
67  std::vector<double> cvspring_;
68 
70  unsigned int iterator_;
71 
73  unsigned int iteration_;
74 
76  std::ofstream stringout_;
77 
80 
82  int recneigh_;
83 
85  std::vector<std::vector<double>> prev_positions_;
86 
88  std::vector<std::vector<double>> prev_velocities_;
89 
91  std::vector<std::vector<int>> prev_IDs_;
92 
94  virtual void StringUpdate() = 0;
95 
97 
102  double distance(const std::vector<double>& x, const std::vector<double>& y) const
103  {
104  double distance = 0;
105  for (size_t i = 0; i < x.size(); i++)
106  distance += pow((x[i] - y[i]),2);
107 
108  return sqrt(distance);
109  }
110 
112 
115  void PrintString(const CVList& CV);
116 
118 
122  void GatherNeighbors(std::vector<double> *lcv0, std::vector<double> *ucv0);
123 
125 
128  void StringReparam(double alpha_star);
129 
131 
134  void UpdateWorldString(const CVList& cvs);
135 
137 
140  bool TolCheck() const
141  {
142  if(tol_.size() == 0)
143  return false;
144 
145  for(size_t i = 0; i < centers_.size(); i++)
146  {
147  if(fabs(centers_[i] - worldstring_[mpiid_][i]) > tol_[i])
148  {
149  return false;
150  }
151  }
152 
153  return true;
154  }
155 
157 
164  bool CheckEnd(const CVList& CV);
165 
166  public:
168 
176  StringMethod(const MPI_Comm& world,
177  const MPI_Comm& comm,
178  const std::vector<double>& centers,
179  unsigned int maxiterations,
180  const std::vector<double> cvspring,
181  unsigned int frequency) :
182  Method(frequency, world, comm), centers_(centers),
183  maxiterator_(maxiterations),
184  cvspring_(cvspring), iterator_(1), iteration_(0)
185  {
186  newcenters_.resize(centers_.size(), 0);
187  }
188 
190  void PreSimulation(Snapshot* snapshot, const class CVManager& cvmanager) override;
191 
193  virtual void PostIntegration(Snapshot* snapshot, const class CVManager& cvmanager) override = 0;
194 
196  void PostSimulation(Snapshot* snapshot, const class CVManager& cvmanager) override;
197 
199 
205  void SetTolerance(std::vector<double> tol)
206  {
207  for(auto& t : tol)
208  tol_.push_back(t);
209  }
210 
212  void SetSendRecvNeighbors();
213 
215  static StringMethod* Build(const Json::Value& json,
216  const MPI_Comm& world,
217  const MPI_Comm& comm,
218  const std::string& path);
219 
221  virtual ~StringMethod() {}
222  };
223 }
224 
int sendneigh_
Neighbor to send info to.
Definition: StringMethod.h:79
double distance(const std::vector< double > &x, const std::vector< double > &y) const
Helper function for calculating distances.
Definition: StringMethod.h:102
StringMethod(const MPI_Comm &world, const MPI_Comm &comm, const std::vector< double > &centers, unsigned int maxiterations, const std::vector< double > cvspring, unsigned int frequency)
Constructor.
Definition: StringMethod.h:176
Collective variable manager.
Definition: CVManager.h:42
bool TolCheck() const
Check whether tolerance criteria have been met.
Definition: StringMethod.h:140
std::vector< CollectiveVariable * > CVList
List of Collective Variables.
Definition: types.h:51
void SetSendRecvNeighbors()
Communicate neighbor lists over MPI.
String base class for FTS, Swarm, and elastic band.
Definition: StringMethod.h:38
void PostSimulation(Snapshot *snapshot, const class CVManager &cvmanager) override
Method call post simulation.
std::vector< std::vector< double > > prev_velocities_
Store velocities for starting trajectories.
Definition: StringMethod.h:88
std::vector< double > tol_
Tolerance criteria for determining when to stop string (default 0 if no tolerance criteria) ...
Definition: StringMethod.h:58
std::ofstream stringout_
Output stream for string data.
Definition: StringMethod.h:76
Class containing a snapshot of the current simulation in time.
Definition: Snapshot.h:47
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
Interface for Method implementations.
Definition: Method.h:43
bool CheckEnd(const CVList &CV)
Check if method reached one of the exit criteria.
int numnodes_
Number of nodes on a string.
Definition: StringMethod.h:61
unsigned int maxiterator_
Maximum cap on number of string method iterations performed.
Definition: StringMethod.h:64
int recneigh_
Neighbor to gain info from.
Definition: StringMethod.h:82
std::vector< std::vector< int > > prev_IDs_
Store atom IDs for starting trajectories.
Definition: StringMethod.h:91
int mpiid_
The node this belongs to.
Definition: StringMethod.h:55
void UpdateWorldString(const CVList &cvs)
Update the world string over MPI.
void StringReparam(double alpha_star)
Reparameterize the string.
void PrintString(const CVList &CV)
Prints the CV positions to file.
static StringMethod * Build(const Json::Value &json, const MPI_Comm &world, const MPI_Comm &comm, const std::string &path)
Build a derived method from JSON node.
virtual void PostIntegration(Snapshot *snapshot, const class CVManager &cvmanager) override=0
Method call post integration.
unsigned int iterator_
The local method iterator.
Definition: StringMethod.h:70
std::vector< std::vector< double > > worldstring_
The world&#39;s strings centers for each CV.
Definition: StringMethod.h:52
void SetTolerance(std::vector< double > tol)
Set the tolerance for quitting method.
Definition: StringMethod.h:205
unsigned int iteration_
The global method iteration.
Definition: StringMethod.h:73
std::vector< double > cvspring_
Vector of spring constants.
Definition: StringMethod.h:67
virtual void StringUpdate()=0
Updates the position of the string.
void PreSimulation(Snapshot *snapshot, const class CVManager &cvmanager) override
Method call prior to simulation initiation.
virtual ~StringMethod()
Destructor.
Definition: StringMethod.h:221
std::vector< std::vector< double > > prev_positions_
Store positions for starting trajectories.
Definition: StringMethod.h:85