SSAGES  0.9.3
Software Suite for Advanced General Ensemble Simulations
Classes | Public Member Functions | Static Public Member Functions | Protected Member Functions | Protected Attributes | List of all members
SSAGES::ForwardFlux Class Referenceabstract

ForwardFlux sampling method. More...

#include <ForwardFlux.h>

Inheritance diagram for SSAGES::ForwardFlux:
Inheritance graph
[legend]

Classes

class  FFSConfigID
 Nested class to store different FFS Config IDs. More...
 

Public Member Functions

 ForwardFlux (const MPI_Comm &world, const MPI_Comm &comm, double ninterfaces, std::vector< double > interfaces, unsigned int N0Target, std::vector< unsigned int > M, bool initialFluxFlag, bool saveTrajectories, unsigned int currentInterface, std::string output_directory, unsigned int frequency)
 Constructor. More...
 
void PreSimulation (Snapshot *snapshot, const class CVManager &cvmanager) override
 Method call prior to simulation initiation. More...
 
virtual void PostIntegration (Snapshot *snapshot, const class CVManager &cvmanager) override=0
 Method call post integration. More...
 
void PostSimulation (Snapshot *snapshot, const class CVManager &cvmanager) override
 Method call post simulation. More...
 
- Public Member Functions inherited from SSAGES::Method
 Method (unsigned int frequency, const MPI_Comm &world, const MPI_Comm &comm)
 Constructor. More...
 
void SetCVMask (const std::vector< unsigned int > &mask)
 Sets the collective variable mask. More...
 
virtual ~Method ()
 Destructor.
 
- Public Member Functions inherited from SSAGES::EventListener
 EventListener (unsigned int frequency)
 Constructor. More...
 
unsigned int GetFrequency () const
 Get frequency of event listener. More...
 
virtual ~EventListener ()
 Destructor.
 

Static Public Member Functions

static ForwardFluxBuild (const Json::Value &json, const MPI_Comm &world, const MPI_Comm &comm, const std::string &path)
 Build a derived method from JSON node. More...
 
- Static Public Member Functions inherited from SSAGES::Method
static MethodBuildMethod (const Json::Value &json, const MPI_Comm &world, const MPI_Comm &comm, const std::string &path)
 Build a derived method from JSON node. More...
 
- Static Public Member Functions inherited from SSAGES::EventListener
static unsigned int GetWalkerID (const MPI_Comm &world, const MPI_Comm &comm)
 Get walker ID number of specified communicator. More...
 
static unsigned int GetNumWalkers (const MPI_Comm &world, const MPI_Comm &comm)
 Get total number of walkers in the simulation. More...
 
static bool IsMasterRank (const MPI_Comm &comm)
 Check if current processor is master. More...
 

Protected Member Functions

void CheckInitialStructure (const CVList &)
 Function that checks the initial structure that user provides.
 
void WriteInitialFlux ()
 Function to compute and write the initial flux.
 
void AddNewIDsToQueue ()
 
bool HasReturnedToA (double current)
 Function checks if configuration has returned to A. More...
 
int HasCrossedInterface (double current, double prev, unsigned int i)
 Function checks if configuration has crossed interface specified since the last check. More...
 
void WriteFFSConfiguration (Snapshot *snapshot, FFSConfigID &ffsconfig, bool wassuccess)
 Write a file corresponding to FFSConfigID from current snapshot. More...
 
void ReadFFSConfiguration (Snapshot *snapshot, FFSConfigID &ffsconfig, bool wassuccess)
 Read a file corresponding to a FFSConfigID into current snapshot. More...
 
void ComputeInitialFlux (Snapshot *, const CVList &)
 Compute Initial Flux.
 
virtual void CheckForInterfaceCrossings (Snapshot *, const class CVManager &)=0
 Function that checks if interfaces have been crossed (different for each FFS flavor)
 
virtual void InitializeQueue (Snapshot *, const CVList &)=0
 Initialize the Queue.
 
void ComputeTransitionProbabilities ()
 Compute the probability of going from each lambda_i to lambda_{i+1}. More...
 
void PrintQueue ()
 Print the queue, useful for debugging.
 
void PopQueueMPI (Snapshot *, const CVList &, unsigned)
 Pop the queue, do MPI so that all procs maintain the same queue.
 
void FluxBruteForce (Snapshot *, const CVList &)
 Compute the flux via brute force. More...
 
void ReconstructTrajectories (Snapshot *)
 When simulation is finished, parse through the trajectories that reached B, and reconstruct the complete trajectory from where it started at A (lambda0)
 
void ComputeCommittorProbability (Snapshot *)
 When simulation is finished, recursively parse through the trajectories that reached B or failed back to A and calculate the Commitor Probability of that state going to B (_pB)
 
void AppendTrajectoryFile (Snapshot *, std::ofstream &)
 
void OpenTrajectoryFile (std::ofstream &)
 Take the current config in snapshot and append it to the provided ofstream.
 

Protected Attributes

double _ninterfaces
 
std::vector< double > _interfaces
 FFS Interfaces.
 
bool _interfaces_increase
 Interfaces must monotonically increase (or decrease), this determines whether going to the 'next' interface will be higher values of CV, or lower ones.
 
double _cvvalue_previous
 Previous cv position, used to determine if you've crossed an interface since last time.
 
double _cvvalue
 current cv position
 
double _rate
 rate constant
 
std::vector< FFSConfigIDLambda0ConfigLibrary
 Data structure that holds a Library N0 configurations at lambda0.
 
double _N0TotalSimTime
 Total Simulation Time spent in accumulating \ _N0.
 
unsigned int _N0Target
 Number of configurations to store at lambda0, target.
 
double _fluxA0
 Flux of trajectories out of state A. Denoted PhiA0 over h_A in Allen2009.
 
std::vector< unsigned int > _M
 
std::vector< unsigned int > _A
 Number of attempts from interface i.
 
std::vector< double > _P
 Flag to determine wheter fluxA0 should be calculated, seems not using this. More...
 
std::vector< unsigned int > _S
 
std::vector< unsigned int > _N
 
bool _pop_tried_but_empty_queue
 
bool _initialFluxFlag
 if 1, compute initial flux
 
bool initializeQueueFlag
 if 1, initialize the Queue
 
FFSConfigID myFFSConfigID
 The current FFSConfigID of this MPI process.
 
bool _saveTrajectories
 should the FFS trajectories be saved
 
unsigned int _nfailure_total
 
std::vector< std::vector< double > > _pB
 
unsigned int _current_interface
 Current Interface.
 
std::deque< FFSConfigIDFFSConfigIDQueue
 
std::string _output_directory
 Directory of FFS output.
 
std::ofstream _trajectory_file
 file to which the current trajectory is written to
 
std::default_random_engine _generator
 random number generator
 
unsigned int iteration_
 Method iteration counter/.
 
- Protected Attributes inherited from SSAGES::Method
mxx::comm world_
 Global MPI communicator.
 
mxx::comm comm_
 Local MPI communicator.
 
std::vector< unsigned int > cvmask_
 Mask which identifies which CVs to act on.
 

Detailed Description

ForwardFlux sampling method.

The notation used here is drawn largely from Allen, Valeriani and Rein ten Wolde. J. Phys.: Condens. Matter (2009) 21:463102. We recommend referring to this review if the reader is unfamiliar with the method, or our variable naming conventions.

Definition at line 38 of file ForwardFlux.h.

Constructor & Destructor Documentation

◆ ForwardFlux()

SSAGES::ForwardFlux::ForwardFlux ( const MPI_Comm &  world,
const MPI_Comm &  comm,
double  ninterfaces,
std::vector< double >  interfaces,
unsigned int  N0Target,
std::vector< unsigned int >  M,
bool  initialFluxFlag,
bool  saveTrajectories,
unsigned int  currentInterface,
std::string  output_directory,
unsigned int  frequency 
)
inline

Constructor.

Parameters
worldMPI global communicator.
commMPI local communicator.
ninterfacesNumber of interfaces.
interfacesVector of interfaces.
N0TargetRequired number of initial configurations.
MVector of trials.
initialFluxFlagFlag for first step of this method.
saveTrajectoriesFlag to save flux trajectories.
currentInterfaceThe number of the current interface.
output_directoryDirectory to which trajectories are saved.
frequencyFrequency with which this method is invoked.

Create instance of Forward Flux

Definition at line 284 of file ForwardFlux.h.

289  :
290  Method(frequency, world, comm), _ninterfaces(ninterfaces), _interfaces(interfaces), _N0Target(N0Target),
291  _M(M), _initialFluxFlag(initialFluxFlag), _saveTrajectories(saveTrajectories), _current_interface(currentInterface),
292  _output_directory(output_directory), _generator(1), iteration_(0)
293  {
294  //_output_directory = "FFSoutput";
295  mkdir(_output_directory.c_str(),S_IRWXU); //how to make directory?
296 
297  //_current_interface = 0;
298  _N0TotalSimTime = 0;
299 
300  if (!_initialFluxFlag)
301  initializeQueueFlag = true;
302 
303  _A.resize(_ninterfaces);
304  _P.resize(_ninterfaces);
305  _S.resize(_ninterfaces);
306  _N.resize(_ninterfaces);
307 
308  //_N[_current_interface] = _N0Target;
309  /*_M.resize(_ninterfaces);
310 
311  //code for setting up simple simulation and debugging
312  _ninterfaces = 5;
313  int i;
314  _interfaces.resize(_ninterfaces);
315  _interfaces[0]=-1.0;
316  _interfaces[1]=-0.95;
317  _interfaces[2]=-0.8;
318  _interfaces[3]= 0;
319  _interfaces[4]= 1.0;
320 
321  _saveTrajectories = true;
322 
323  _initialFluxFlag = true;
324 
325  for(i=0;i<_ninterfaces;i++) _M[i] = 50;
326 
327  _N0Target = 100;*/
328  //_N0Target = 100;
329  _nfailure_total = 0;
330 
331 
332  //check if interfaces monotonically increase or decrease
333  bool errflag = false;
334  if (_interfaces[0]< _interfaces[1]) _interfaces_increase = true;
335  else if (_interfaces[0] > _interfaces[1]) _interfaces_increase = false;
336  else errflag = true;
337  for (unsigned int i=0;i<_ninterfaces-1;i++)
338  {
339  if((_interfaces_increase) && (_interfaces[i] >= _interfaces[i+1]))
340  errflag = true;
341  else if ((!_interfaces_increase) && (_interfaces[i] <= _interfaces[i+1]))
342  errflag = true;
343  }
344  if (errflag)
345  {
346  std::cerr << "Error! The interfaces are poorly defined. They must be monotonically increasing or decreasing and cannot equal one another! Please fix this.\n";
347  for (auto interface : _interfaces)
348  std::cerr << interface << " ";
349  std::cerr << "\n";
350  MPI_Abort(world_, EXIT_FAILURE);
351  }
352 
353  // This is to generate an artificial Lambda0ConfigLibrary, Hadi's code does this for real
354  // THIS SHOULD BE SOMEWHERE ELSE!!!
356  std::normal_distribution<double> distribution(0,1);
357  for (unsigned int i = 0; i < _N0Target ; i++)
358  {
359  Lambda0ConfigLibrary[i].l = 0;
360  Lambda0ConfigLibrary[i].n = i;
361  Lambda0ConfigLibrary[i].a = 0;
362  Lambda0ConfigLibrary[i].lprev = 0;
363  Lambda0ConfigLibrary[i].nprev = i;
364  Lambda0ConfigLibrary[i].aprev = 0;
365  //FFSConfigID ffsconfig = Lambda0ConfigLibrary[i];
366  }
367  /*// Write the dump file out
368  std::ofstream file;
369  std::string filename = _output_directory + "/l" + std::to_string(ffsconfig.l) + "-n" + std::to_string(ffsconfig.n) + ".dat";
370  file.open(filename.c_str());
371 
372  //first line gives ID of where it came from
373  file << ffsconfig.lprev << " " << ffsconfig.nprev << " " << ffsconfig.aprev << "\n";
374  //write position and velocity
375  file << "1 -1 0 0 " << distribution(_generator) << " " << distribution(_generator) << " 0\n";
376 
377  }
378  */
380  }
std::vector< FFSConfigID > Lambda0ConfigLibrary
Data structure that holds a Library N0 configurations at lambda0.
Definition: ForwardFlux.h:96
bool _pop_tried_but_empty_queue
Definition: ForwardFlux.h:132
std::string _output_directory
Directory of FFS output.
Definition: ForwardFlux.h:166
unsigned int _nfailure_total
Definition: ForwardFlux.h:149
std::vector< double > _interfaces
FFS Interfaces.
Definition: ForwardFlux.h:81
unsigned int iteration_
Method iteration counter/.
Definition: ForwardFlux.h:175
std::vector< unsigned int > _M
Definition: ForwardFlux.h:109
bool _saveTrajectories
should the FFS trajectories be saved
Definition: ForwardFlux.h:144
bool _interfaces_increase
Interfaces must monotonically increase (or decrease), this determines whether going to the 'next' int...
Definition: ForwardFlux.h:84
bool _initialFluxFlag
if 1, compute initial flux
Definition: ForwardFlux.h:135
std::vector< unsigned int > _N
Definition: ForwardFlux.h:127
std::vector< unsigned int > _S
Definition: ForwardFlux.h:122
std::vector< double > _P
Flag to determine wheter fluxA0 should be calculated, seems not using this.
Definition: ForwardFlux.h:118
bool initializeQueueFlag
if 1, initialize the Queue
Definition: ForwardFlux.h:138
double _N0TotalSimTime
Total Simulation Time spent in accumulating \ _N0.
Definition: ForwardFlux.h:99
std::default_random_engine _generator
random number generator
Definition: ForwardFlux.h:172
unsigned int _current_interface
Current Interface.
Definition: ForwardFlux.h:156
unsigned int _N0Target
Number of configurations to store at lambda0, target.
Definition: ForwardFlux.h:102
std::vector< unsigned int > _A
Number of attempts from interface i.
Definition: ForwardFlux.h:112
mxx::comm world_
Global MPI communicator.
Definition: Method.h:46
Method(unsigned int frequency, const MPI_Comm &world, const MPI_Comm &comm)
Constructor.
Definition: Method.h:61

References _A, _initialFluxFlag, _interfaces, _interfaces_increase, _N, _N0Target, _N0TotalSimTime, _nfailure_total, _ninterfaces, _output_directory, _P, _pop_tried_but_empty_queue, _S, initializeQueueFlag, Lambda0ConfigLibrary, and SSAGES::Method::world_.

Member Function Documentation

◆ AddNewIDsToQueue()

void SSAGES::ForwardFlux::AddNewIDsToQueue ( )
protected

Function that adds new FFS configurations to the Queue Different FFS flavors can have differences in this method

◆ AppendTrajectoryFile()

void SSAGES::ForwardFlux::AppendTrajectoryFile ( Snapshot snapshot,
std::ofstream &  file 
)
protected

Take the current config in snapshot and append it to the provided ofstream Current format is xyz style (including vx,vy,vz)

Definition at line 279 of file ForwardFlux.cpp.

280  {
281  const auto& positions = snapshot->GetPositions();
282  const auto& velocities = snapshot->GetVelocities();
283  const auto& atomID = snapshot->GetAtomIDs();
284 
285  //first line gives number of atoms
286  file << atomID.size() << "\n\n";
287 
288  // Then write positions and velocities
289  for(size_t i = 0; i< atomID.size(); i++)
290  {
291  file<<atomID[i]<<" ";
292  file<<positions[i][0]<<" "<<positions[i][1]<<" "<<positions[i][2]<<" ";
293  file<<velocities[i][0]<<" "<<velocities[i][1]<<" "<<velocities[i][2]<<std::endl;
294  }
295  }

References SSAGES::Snapshot::GetAtomIDs(), SSAGES::Snapshot::GetPositions(), and SSAGES::Snapshot::GetVelocities().

Referenced by SSAGES::DirectForwardFlux::CheckForInterfaceCrossings().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ Build()

ForwardFlux * SSAGES::ForwardFlux::Build ( const Json::Value &  json,
const MPI_Comm &  world,
const MPI_Comm &  comm,
const std::string &  path 
)
static

Build a derived method from JSON node.

Parameters
jsonJSON Value containing all input information.
worldMPI global communicator.
commMPI local communicator.
pathPath for JSON path specification.
Returns
Pointer to the Method built. nullptr if an unknown error occurred.

This function builds a registered method from a JSON node. The difference between this function and "Build" is that this automatically determines the appropriate derived type based on the JSON node information.

Note
Object lifetime is the caller's responsibility.

Definition at line 628 of file ForwardFlux.cpp.

632  {
633  ObjectRequirement validator;
634  Value schema;
635  CharReaderBuilder rbuilder;
636  CharReader* reader = rbuilder.newCharReader();
637 
638  reader->parse(JsonSchema::ForwardFluxMethod.c_str(),
639  JsonSchema::ForwardFluxMethod.c_str() + JsonSchema::ForwardFluxMethod.size(),
640  &schema, nullptr);
641  validator.Parse(schema, path);
642 
643  // Validate inputs.
644  validator.Validate(json, path);
645  if(validator.HasErrors())
646  throw BuildException(validator.GetErrors());
647 
648  double ninterfaces = json.get("nInterfaces", 2).asDouble();
649  std::vector<double> interfaces;
650  for(auto& s : json["interfaces"])
651  interfaces.push_back(s.asDouble());
652 
653  std::vector<unsigned int> M;
654  for(auto& s : json["trials"])
655  M.push_back(s.asInt());
656 
657  if ((ninterfaces != interfaces.size()) || (ninterfaces != M.size()))
658  throw BuildException({"The size of \"interfaces\" and \"trials\" must be equal to \"nInterfaces\". See documentation for more information"});
659 
660  auto N0Target = json.get("N0Target", 1).asInt();
661  auto initialFluxFlag = json.get("computeInitialFlux", true).asBool();
662  auto saveTrajectories = json.get("saveTrajectories", true).asBool();
663  auto currentInterface = json.get("currentInterface", 0).asInt();
664  auto freq = json.get("frequency", 1).asInt();
665  auto flavor = json.get("flavor", "none").asString();
666  auto output_directory = json.get("outputDirectoryName", "FFSoutput").asString();
667 
668  // TODO: Implement multiple processes per walker
669  if(mxx::comm(comm).size() > 1)
670  {
671  throw BuildException({"Forward Flux currently only works with 1 process per walker."});
672  }
673 
674  if(flavor == "DirectForwardFlux")
675  {
676  return new DirectForwardFlux(world, comm, ninterfaces, interfaces, N0Target, M, initialFluxFlag, saveTrajectories, currentInterface, output_directory, freq);
677  }
678  else
679  {
680  throw BuildException({"Unknown flavor of forward flux. The options are \"DirectForwardFlux\""});
681  }
682  }
Requirements on an object.
virtual void Parse(Value json, const std::string &path) override
Parse JSON value to generate Requirement(s).
virtual void Validate(const Value &json, const std::string &path) override
Validate JSON value.
std::vector< std::string > GetErrors()
Get list of error messages.
Definition: Requirement.h:92
bool HasErrors()
Check if errors have occured.
Definition: Requirement.h:86

References Json::Requirement::GetErrors(), Json::Requirement::HasErrors(), Json::ObjectRequirement::Parse(), and Json::ObjectRequirement::Validate().

Here is the call graph for this function:

◆ ComputeTransitionProbabilities()

void SSAGES::ForwardFlux::ComputeTransitionProbabilities ( )
protected

Compute the probability of going from each lambda_i to lambda_{i+1}.

Using number of successes and number of trials This will need to be different for each FFS flavor

Definition at line 214 of file ForwardFlux.cpp.

215  {
216  double Ptotal = 1;
217  for (unsigned int i = 0; i < _ninterfaces -1; i++)
218  Ptotal *= _P[i];
219 
220  _rate = Ptotal*_fluxA0;
221 
222  //write file
223  std::ofstream file;
224  std::string filename = _output_directory + "/rate.dat";
225  file.open(filename.c_str());
226  if (!file) {std::cerr << "Error! Unable to write " << filename << "\n"; exit(1);}
227  file << _rate << "\n";
228  file.close();
229  }
double _rate
rate constant
Definition: ForwardFlux.h:93
double _fluxA0
Flux of trajectories out of state A. Denoted PhiA0 over h_A in Allen2009.
Definition: ForwardFlux.h:105

◆ FluxBruteForce()

void SSAGES::ForwardFlux::FluxBruteForce ( Snapshot ,
const CVList  
)
protected

Compute the flux via brute force.

Eventually this should be a new class that inherits from ForwardFlux, but for the time being I'll just hard code it This function takes the configurations at lambda0 and run them until they reach B (lambdaN) or return to A

◆ HasCrossedInterface()

int SSAGES::ForwardFlux::HasCrossedInterface ( double  current,
double  prev,
unsigned int  i 
)
protected

Function checks if configuration has crossed interface specified since the last check.

Simple function, given current and previous CV position, checks if interface i has been crossed. If crossed in positive direction, return +1, if crossed in negative direction return -1, if nothing crossed return 0.

Parameters
currentCurrent value of CV.
prevPrevious value of CV.
iIndex of interface to check for crossing.
Returns
Ternary value for direction of crossing (positive, negative, or none).

Definition at line 79 of file ForwardFlux.cpp.

80  {
81  double interface_location = _interfaces[i];
83  {
84  if ((prev <= interface_location) && (current >= interface_location))
85  return 1;
86  else if ((prev >= interface_location) && (current <= interface_location))
87  return -1;
88  else
89  return 0;
90  }
91  else
92  {
93  if ((prev >= interface_location) && (current <= interface_location))
94  return 1;
95  else if ((prev <= interface_location) && (current >= interface_location))
96  return -1;
97  else
98  return 0;
99  }
100  }

Referenced by SSAGES::DirectForwardFlux::CheckForInterfaceCrossings().

Here is the caller graph for this function:

◆ HasReturnedToA()

bool SSAGES::ForwardFlux::HasReturnedToA ( double  current)
protected

Function checks if configuration has returned to A.

Parameters
currentCurrent value of CV.
Returns
Boolean if the trajectory returned to state A

Definition at line 102 of file ForwardFlux.cpp.

103  {
104  double interface_location = _interfaces[0];
106  {
107  if (current < interface_location) return true;
108  else return false;
109  }
110  else
111  {
112  if (current > interface_location) return true;
113  else return false;
114  }
115  }

Referenced by SSAGES::DirectForwardFlux::CheckForInterfaceCrossings().

Here is the caller graph for this function:

◆ PostIntegration()

virtual void SSAGES::ForwardFlux::PostIntegration ( Snapshot snapshot,
const class CVManager cvmanager 
)
overridepure virtual

Method call post integration.

Parameters
snapshotPointer to the simulation snapshot.
cvmanagerCollective variable manager.

This function will be called after each integration step.

Implements SSAGES::Method.

Implemented in SSAGES::DirectForwardFlux.

◆ PostSimulation()

void SSAGES::ForwardFlux::PostSimulation ( Snapshot snapshot,
const class CVManager cvmanager 
)
overridevirtual

Method call post simulation.

Parameters
snapshotPointer to the simulation snapshot.
cvmanagerCollective variable manager.

This function will be called after the end of the simulation run.

Implements SSAGES::Method.

Definition at line 48 of file ForwardFlux.cpp.

49  {
50  std::cout << "Post simulation\n";
51 
54 
56  ReconstructTrajectories(snapshot);
57 
58  MPI_Abort(world_, EXIT_FAILURE); //more elegant solution?
59  }
void ComputeTransitionProbabilities()
Compute the probability of going from each lambda_i to lambda_{i+1}.
void ComputeCommittorProbability(Snapshot *)
When simulation is finished, recursively parse through the trajectories that reached B or failed back...
void ReconstructTrajectories(Snapshot *)
When simulation is finished, parse through the trajectories that reached B, and reconstruct the compl...

Referenced by SSAGES::DirectForwardFlux::CheckForInterfaceCrossings().

Here is the caller graph for this function:

◆ PreSimulation()

void SSAGES::ForwardFlux::PreSimulation ( Snapshot snapshot,
const class CVManager cvmanager 
)
overridevirtual

Method call prior to simulation initiation.

Parameters
snapshotPointer to the simulation snapshot.
cvmanagerCollective variable manager.

This function will be called before the simulation is started.

Implements SSAGES::Method.

Definition at line 39 of file ForwardFlux.cpp.

40  {
41  auto cvs = cvmanager.GetCVs(cvmask_);
42  if(cvs.size() > 1)
43  throw BuildException({"Forwardflux currently only works with one cv."});
44 
45  std::cout << "\nWARNING! MAKE SURE LAMMPS GIVES A DIFFERENT RANDOM SEED TO EACH PROCESSOR, OTHERWISE EACH FFS TRAJ WILL BE IDENTICAL!\n";
46  }
std::vector< unsigned int > cvmask_
Mask which identifies which CVs to act on.
Definition: Method.h:50

References SSAGES::CVManager::GetCVs().

Here is the call graph for this function:

◆ ReadFFSConfiguration()

void SSAGES::ForwardFlux::ReadFFSConfiguration ( Snapshot snapshot,
FFSConfigID ffsconfig,
bool  wassuccess 
)
protected

Read a file corresponding to a FFSConfigID into current snapshot.

Parameters
snapshotCurrent snaphshot of the system
ffsconfigID of the current FFS configuration
wassuccessIf the last attempt was a success

Definition at line 297 of file ForwardFlux.cpp.

298  {
299  auto& positions = snapshot->GetPositions();
300  auto& velocities = snapshot->GetVelocities();
301  auto& atomID = snapshot->GetAtomIDs();
302  auto& forces = snapshot->GetForces();
303  //auto& ID = snapshot->GetSnapshotID();
304 
305  std::ifstream file;
306  std::string filename;
307  if (wassuccess)
308  filename = _output_directory + "/l"+ std::to_string(ffsconfig.l) +"-n"+ std::to_string(ffsconfig.n) + ".dat";
309  else
310  filename = _output_directory + "/fail-l"+ std::to_string(ffsconfig.l) +"-n"+ std::to_string(ffsconfig.n) + ".dat";
311 
312  std::string line;
313  file.open(filename);
314  if(!file)
315  {
316  std::cerr << "Error! Unable to read " << filename << "\n";
317  MPI_Abort(world_, EXIT_FAILURE);
318  }
319 
320  unsigned int line_count = 0;
321  while(!std::getline(file,line).eof())
322  {
323  int atomindex = -1;
324 
325  //parse line into tokens
326  std::string buf; // Have a buffer string
327  std::stringstream ss(line); // Insert the string into a stream
328  std::vector<std::string> tokens; // Create vector to hold our words
329  while (ss >> buf)
330  tokens.push_back(buf);
331 
332  // first line contains the previous ffsconfig information
333  if ((line_count == 0) && (tokens.size() == 3))
334  {
335  ffsconfig.lprev = std::stoi(tokens[0]);
336  ffsconfig.nprev = std::stoi(tokens[1]);
337  ffsconfig.aprev = std::stoi(tokens[2]);
338  }
339  // all other lines contain config information
340  else if ((line_count != 0) && (tokens.size() == 7))
341  {
342  //FIXME: try using snapshot->GetLocalIndex()
343 
344  //copied from Ben's previous implementation
345  for(size_t i=0; i < atomID.size(); i++)
346  {
347  if(atomID[i] == std::stoi(tokens[0]))
348  atomindex = i;
349  }
350 
351  if(atomindex < 0)
352  {
353  std::cout<<"error, could not locate atomID "<<tokens[0]<<" from dumpfile"<<std::endl;
354  MPI_Abort(world_, EXIT_FAILURE);
355  }
356 
357  positions[atomindex][0] = std::stod(tokens[1]);
358  positions[atomindex][1] = std::stod(tokens[2]);
359  positions[atomindex][2] = std::stod(tokens[3]);
360  velocities[atomindex][0] = std::stod(tokens[4]);
361  velocities[atomindex][1] = std::stod(tokens[5]);
362  velocities[atomindex][2] = std::stod(tokens[6]);
363 
364  for(auto& force : forces)
365  force.setZero();
366  }
367  // else throw error
368  else
369  {
370  std::cout<<"ERROR: incorrect line format in "<< filename <<" on line" << line_count << ":\n";
371  std::cout<<line<<std::endl;
372  MPI_Abort(world_, EXIT_FAILURE);
373  }
374  line_count++;
375  }
376  file.close();
377  }

References SSAGES::ForwardFlux::FFSConfigID::aprev, SSAGES::Snapshot::GetAtomIDs(), SSAGES::Snapshot::GetForces(), SSAGES::Snapshot::GetPositions(), SSAGES::Snapshot::GetVelocities(), SSAGES::ForwardFlux::FFSConfigID::l, SSAGES::ForwardFlux::FFSConfigID::lprev, SSAGES::ForwardFlux::FFSConfigID::n, and SSAGES::ForwardFlux::FFSConfigID::nprev.

Here is the call graph for this function:

◆ WriteFFSConfiguration()

void SSAGES::ForwardFlux::WriteFFSConfiguration ( Snapshot snapshot,
FFSConfigID ffsconfig,
bool  wassuccess 
)
protected

Write a file corresponding to FFSConfigID from current snapshot.

Parameters
snapshotCurrent snaphshot of the system
ffsconfigID of the current FFS configuration
wassuccessIf the last attempt was a success

Definition at line 231 of file ForwardFlux.cpp.

232  {
233  const auto& positions = snapshot->GetPositions();
234  const auto& velocities = snapshot->GetVelocities();
235  const auto& atomID = snapshot->GetAtomIDs();
236  //unsigned natoms = snapshot->GetNumAtoms();
237  //const auto& dumpfilename = snapshot->GetSnapshotID();
238 
239  // Write the dump file out
240  std::ofstream file;
241  std::string filename;
242  if (wassuccess)
243  filename = _output_directory + "/l" + std::to_string(ffsconfig.l) + "-n" + std::to_string(ffsconfig.n) + ".dat";
244  else
245  filename = _output_directory + "/fail-l" + std::to_string(ffsconfig.l) + "-n" + std::to_string(ffsconfig.n) + ".dat";
246 
247  file.open(filename.c_str());
248  if(!file)
249  {
250  std::cerr << "Error! Unable to write " << filename << "\n";
251  MPI_Abort(world_, EXIT_FAILURE);
252  }
253 
254  //first line gives ID of where it came from
255  file << ffsconfig.lprev << " " << ffsconfig.nprev << " " << ffsconfig.aprev << "\n";
256 
257  // Then write positions and velocities
258  for(size_t i = 0; i< atomID.size(); i++)
259  //for(size_t i = 0; i< natoms; i++)
260  {
261  file<<atomID[i]<<" ";
262  file<<positions[i][0]<<" "<<positions[i][1]<<" "<<positions[i][2]<<" ";
263  file<<velocities[i][0]<<" "<<velocities[i][1]<<" "<<velocities[i][2]<<std::endl;
264  }
265  }

References SSAGES::ForwardFlux::FFSConfigID::aprev, SSAGES::Snapshot::GetAtomIDs(), SSAGES::Snapshot::GetPositions(), SSAGES::Snapshot::GetVelocities(), SSAGES::ForwardFlux::FFSConfigID::l, SSAGES::ForwardFlux::FFSConfigID::lprev, SSAGES::ForwardFlux::FFSConfigID::n, and SSAGES::ForwardFlux::FFSConfigID::nprev.

Referenced by SSAGES::DirectForwardFlux::CheckForInterfaceCrossings().

Here is the call graph for this function:
Here is the caller graph for this function:

Member Data Documentation

◆ _M

std::vector<unsigned int> SSAGES::ForwardFlux::_M
protected

Number of trials to attemt from each interface Note _M[0] sets the number of 'branches' for RBFFS and BGFFS?

Definition at line 109 of file ForwardFlux.h.

Referenced by SSAGES::DirectForwardFlux::CheckForInterfaceCrossings(), and SSAGES::DirectForwardFlux::InitializeQueue().

◆ _N

std::vector<unsigned int> SSAGES::ForwardFlux::_N
protected

Current number of configurations currently stored at interface i This is somewhat redundant since _N[i] == _S[i-1], but for clarity N[0] - current number of configurations collected at lambda0 (first interface)

Definition at line 127 of file ForwardFlux.h.

Referenced by SSAGES::DirectForwardFlux::CheckForInterfaceCrossings(), ForwardFlux(), and SSAGES::DirectForwardFlux::InitializeQueue().

◆ _nfailure_total

unsigned int SSAGES::ForwardFlux::_nfailure_total
protected

Counts the total number of failures eventually if I prune, will want this to be a vector, where it stores the number of failures at each interface however in the absence of pruning, a traj can only fail at lambda0, so this is just a scalar

Definition at line 149 of file ForwardFlux.h.

Referenced by SSAGES::DirectForwardFlux::CheckForInterfaceCrossings(), and ForwardFlux().

◆ _ninterfaces

double SSAGES::ForwardFlux::_ninterfaces
protected

Number of FFS interfaces note that _ninterfaces = n+1 where n is lambda_n the interface defining B

Definition at line 78 of file ForwardFlux.h.

Referenced by SSAGES::DirectForwardFlux::CheckForInterfaceCrossings(), and ForwardFlux().

◆ _P

std::vector<double> SSAGES::ForwardFlux::_P
protected

Flag to determine wheter fluxA0 should be calculated, seems not using this.

Probability of going from lambda_{i} to lambda_{i+1}

Definition at line 118 of file ForwardFlux.h.

Referenced by SSAGES::DirectForwardFlux::CheckForInterfaceCrossings(), and ForwardFlux().

◆ _pB

std::vector<std::vector<double> > SSAGES::ForwardFlux::_pB
protected

commitor probability. The probability of a given configuration reaching B

Definition at line 153 of file ForwardFlux.h.

◆ _pop_tried_but_empty_queue

bool SSAGES::ForwardFlux::_pop_tried_but_empty_queue
protected

Keep track of jobs that have suceeded or failed but couldn't get reassigned a new task and must wait for the queue to get more jobs This could happen in DFFS once a job has finished but M[i] hasn't been reached (waiting on other jobs) If this is the case I call it a 'zombie job', since the job is running, but isnt doing anything useful. Its just burning cpu cycles waiting for the queue to repopulate

Definition at line 132 of file ForwardFlux.h.

Referenced by SSAGES::DirectForwardFlux::CheckForInterfaceCrossings(), and ForwardFlux().

◆ _S

std::vector<unsigned int> SSAGES::ForwardFlux::_S
protected

Number of successes from lambda_{i} to lambda_{i+1} (might need to be 2d vector if multiple branches are used (with RBFFS)

Definition at line 122 of file ForwardFlux.h.

Referenced by SSAGES::DirectForwardFlux::CheckForInterfaceCrossings(), and ForwardFlux().

◆ FFSConfigIDQueue

std::deque<FFSConfigID> SSAGES::ForwardFlux::FFSConfigIDQueue
protected

Queue When a given processor reaches an interface, it pulls a config from this Queue to figure out what it should do next This object should be syncronized between all FFS walkers (is walker the correct terminology here?) technically this is a double-ended queue, this was mostly for debugging to allow element access of the queue (which std::queue doesn't allow). I use it like a queue though.

Definition at line 163 of file ForwardFlux.h.

Referenced by SSAGES::DirectForwardFlux::CheckForInterfaceCrossings(), and SSAGES::DirectForwardFlux::InitializeQueue().


The documentation for this class was generated from the following files: