23 #include "CollectiveVariable.h"
24 #include "Validator/ObjectRequirement.h"
25 #include "Drivers/DriverException.h"
89 std::vector<int> found1(n1, 0), found2(n2, 0);
90 for(
size_t i = 0; i < n1; ++i)
96 for(
size_t i = 0; i < n2; ++i)
102 MPI_Allreduce(MPI_IN_PLACE, found1.data(), n1, MPI_INT, MPI_SUM, snapshot.
GetCommunicator());
103 MPI_Allreduce(MPI_IN_PLACE, found2.data(), n2, MPI_INT, MPI_SUM, snapshot.
GetCommunicator());
105 unsigned ntot1 = std::accumulate(found1.begin(), found1.end(), 0, std::plus<int>());
106 unsigned ntot2 = std::accumulate(found2.begin(), found2.end(), 0, std::plus<int>());
109 "ParticleSeparationCV: Expected to find " +
111 " atoms in particle 1, but only found " +
112 to_string(ntot1) +
"."
117 "ParticleSeparationCV: Expected to find " +
119 " atoms in particle 2, but only found " +
120 to_string(ntot2) +
"."
131 std::vector<int> idx1, idx2;
137 const auto& masses = snapshot.
GetMasses();
172 reader.parse(JsonSchema::ParticleSeparationCV, schema);
173 validator.
Parse(schema, path);
180 std::vector<int> group1, group2;
182 for(
auto& s : json[
"group1"])
183 group1.push_back(s.asInt());
185 for(
auto& s : json[
"group2"])
186 group2.push_back(s.asInt());
189 if(json.isMember(
"dimension"))
191 auto fixx = json[
"dimension"][0].asBool();
192 auto fixy = json[
"dimension"][1].asBool();
193 auto fixz = json[
"dimension"][2].asBool();
std::vector< int > Label
List of integers.
bool HasErrors()
Check if errors have occured.
unsigned GetNumAtoms() const
Get number of atoms in this snapshot.
double TotalMass(const Label &indices) const
Compute the total mass of a group of particles based on index.
ParticleSeparationCV(const Label &group1, const Label &group2, bool fixx, bool fixy, bool fixz)
Constructor.
Class containing a snapshot of the current simulation in time.
void Initialize(const Snapshot &snapshot) override
Initialize necessary variables.
Label group2_
Atom ID's of group 2.
virtual void Parse(Value json, const std::string &path) override
Parse JSON value to generate Requirement(s).
int GetLocalIndex(int id) const
Gets the local atom index corresponding to an atom ID.
Collective variable on the distance between two particles' centers of mass.
std::vector< Vector3 > grad_
Gradient vector dCv/dxi.
const mxx::comm & GetCommunicator() const
Get communicator for walker.
void GetLocalIndices(const Label &ids, Label *indices) const
Exception to be thrown when building the Driver fails.
std::vector< std::string > GetErrors()
Get list of error messages.
Vector3 CenterOfMass(const Label &indices) const
const std::vector< double > & GetMasses() const
Const access to the particle masses.
ParticleSeparationCV(const Label &group1, const Label &group2)
Constructor.
Requirements on an object.
Eigen::Vector3d Vector3
Three-dimensional vector.
Bool3 dim_
Each dimension determines if it is applied by the CV.
void ApplyMinimumImage(Vector3 *v) const
Apply minimum image to a vector.
double val_
Current value of CV.
Abstract class for a collective variable.
Matrix3 boxgrad_
Gradient w.r.t box vectors dCv/dHij.
void Evaluate(const Snapshot &snapshot) override
Evaluate the CV.
Label group1_
Atom ID's of group 1.
virtual void Validate(const Value &json, const std::string &path) override
Validate JSON value.
Eigen::Matrix< bool, 3, 1 > Bool3
Three-dimensional boolean.