23 #include "CollectiveVariable.h"
24 #include "Validator/ObjectRequirement.h"
25 #include "Drivers/DriverException.h"
75 std::vector<int> found(n, 0);
76 for(
size_t i = 0; i < n; ++i)
82 MPI_Allreduce(MPI_IN_PLACE, found.data(), n, MPI_INT, MPI_SUM, snapshot.
GetCommunicator());
83 unsigned ntot = std::accumulate(found.begin(), found.end(), 0, std::plus<int>());
86 "ParticleCoordinateCV: Expected to find " +
88 " atoms, but only found " +
100 std::vector<int> idx;
105 const auto& masses = snapshot.
GetMasses();
132 grad_[id][0] = (
dim_ == Dimension::x) ? masses[
id]/masstot : 0;
133 grad_[id][1] = (
dim_ == Dimension::y) ? masses[
id]/masstot : 0;
134 grad_[id][2] = (
dim_ == Dimension::z) ? masses[
id]/masstot : 0;
164 return val_ - Location;
173 reader.parse(JsonSchema::ParticleCoordinateCV, schema);
174 validator.
Parse(schema, path);
182 for(
auto&
id : json[
"atom_ids"])
183 atomids.push_back(
id.asInt());
185 auto indextype = json.get(
"dimension",
"x").asString();
189 index = Dimension::x;
190 else if(indextype ==
"y")
191 index = Dimension::y;
192 else if(indextype ==
"z")
193 index = Dimension::z;
195 throw BuildException({
"Could not obtain ParticleCoordinate dimension specified."});
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.
Class containing a snapshot of the current simulation in time.
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.
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.
Collective variable on a particle coordinate.
Dimension
Enum for dimension.
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.
double GetPeriodicValue(double Location) const override
Return value taking periodic boundary conditions into account.
Requirements on an object.
ParticleCoordinateCV(const Label &atomids, Dimension dim)
Constructor.
Label atomids_
IDs of atoms of interest.
Dimension dim_
Index of dimension.
Eigen::Vector3d Vector3
Three-dimensional vector.
double val_
Current value of CV.
double GetDifference(const double Location) const override
Return difference considering periodic boundaries.
Abstract class for a collective variable.
void Initialize(const Snapshot &snapshot) override
Initialize necessary variables.
void Evaluate(const Snapshot &snapshot) override
Evaluate the CV.
virtual void Validate(const Value &json, const std::string &path) override
Validate JSON value.