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;
172 Json::CharReaderBuilder rbuilder;
173 Json::CharReader* reader = rbuilder.newCharReader();
175 reader->parse(JsonSchema::ParticleCoordinateCV.c_str(),
176 JsonSchema::ParticleCoordinateCV.c_str() + JsonSchema::ParticleCoordinateCV.size(),
178 validator.
Parse(schema, path);
186 for(
auto&
id : json[
"atom_ids"])
187 atomids.push_back(
id.asInt());
189 auto indextype = json.get(
"dimension",
"x").asString();
193 index = Dimension::x;
194 else if(indextype ==
"y")
195 index = Dimension::y;
196 else if(indextype ==
"z")
197 index = Dimension::z;
199 throw BuildException({
"Could not obtain ParticleCoordinate dimension specified."});
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.
bool HasErrors()
Check if errors have occured.
Exception to be thrown when building the Driver fails.
Abstract class for a collective variable.
std::vector< Vector3 > grad_
Gradient vector dCv/dxi.
double val_
Current value of CV.
Collective variable on a particle coordinate.
void Initialize(const Snapshot &snapshot) override
Initialize necessary variables.
double GetDifference(const double Location) const override
Return difference considering periodic boundaries.
Dimension dim_
Index of dimension.
double GetPeriodicValue(double Location) const override
Return value taking periodic boundary conditions into account.
ParticleCoordinateCV(const Label &atomids, Dimension dim)
Constructor.
static ParticleCoordinateCV * Build(const Json::Value &json, const std::string &path)
Set up collective variable.
Label atomids_
IDs of atoms of interest.
void Evaluate(const Snapshot &snapshot) override
Evaluate the CV.
Class containing a snapshot of the current simulation in time.
unsigned GetNumAtoms() const
Get number of atoms in this snapshot.
void GetLocalIndices(const Label &ids, Label *indices) const
const mxx::comm & GetCommunicator() const
Get communicator for walker.
int GetLocalIndex(int id) const
Gets the local atom index corresponding to an atom ID.
double TotalMass(const Label &indices) const
Compute the total mass of a group of particles based on index.
const std::vector< double > & GetMasses() const
Const access to the particle masses.
Vector3 CenterOfMass(const Label &indices, bool mass_weight=true) const
Compute center of mass of a group of atoms based on index.
Eigen::Vector3d Vector3
Three-dimensional vector.
Dimension
Enum for dimension.
std::vector< int > Label
List of integers.