SSAGES  0.9.3
Software Suite for Advanced General Ensemble Simulations
Method.cpp
1 
20 #include "Method.h"
21 #include "ABF.h"
22 #include "ANN.h"
23 #include "CFF.h"
24 #include "Umbrella.h"
25 #include "BasisFunc.h"
26 #include "ForwardFlux.h"
27 #include "Meta.h"
28 #include "StringMethod.h"
29 #include "schema.h"
30 #include "json/json.h"
31 #include "Drivers/DriverException.h"
32 #include "Validator/ObjectRequirement.h"
33 #include "CVs/CVManager.h"
34 #include <stdexcept>
35 
36 using namespace Json;
37 
38 namespace SSAGES
39 {
40  Method* Method::BuildMethod(const Value& json,
41  const MPI_Comm& world,
42  const MPI_Comm& comm,
43  const std::string& path)
44  {
45  ObjectRequirement validator;
46  Value schema;
47  CharReaderBuilder rbuilder;
48  CharReader* reader = rbuilder.newCharReader();
49 
50  reader->parse(JsonSchema::Method.c_str(),
51  JsonSchema::Method.c_str() + JsonSchema::Method.size(),
52  &schema, nullptr);
53  validator.Parse(schema, path);
54  validator.Validate(json, path);
55  if(validator.HasErrors())
56  throw BuildException(validator.GetErrors());
57 
58  Method* method = nullptr;
59 
60  if(json["type"] == "ABF")
61  method = ABF::Build(json, world, comm, path);
62  else if(json["type"] == "ANN")
63  method = ANN::Build(json, world, comm, path);
64  else if(json["type"] == "BFSMethod")
65  method = BFS::Build(json, world, comm, path);
66  else if(json["type"] == "CFF")
67  method = CFF::Build(json, world, comm, path);
68  else if(json["type"] == "ForwardFlux")
69  method = ForwardFlux::Build(json, world, comm, path);
70  else if(json["type"] == "Metadynamics")
71  method = Meta::Build(json, world, comm, path);
72  else if(json["type"] == "Umbrella")
73  method = Umbrella::Build(json, world, comm, path);
74  else if(json["type"] == "String")
75  method = StringMethod::Build(json, world, comm, path);
76  else
77  throw std::invalid_argument(path + ": Unknown method type specified.");
78 
79  // Load cv mask.
80  std::vector<unsigned int> cvmask;
81  for(auto& cv : json["cvs"])
82  {
83  cvmask.push_back(CVManager::LookupCV(cv, path));
84  }
85 
86  method->SetCVMask(cvmask);
87  return method;
88  }
89 }
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
Exception to be thrown when building the Driver fails.
Interface for Method implementations.
Definition: Method.h:44
void SetCVMask(const std::vector< unsigned int > &mask)
Sets the collective variable mask.
Definition: Method.h:99