23 #include "CollectiveVariable.h"
24 #include "Validator/ObjectRequirement.h"
25 #include "Drivers/DriverException.h"
94 std::vector<int> found(n, 0);
95 for(
size_t i = 0; i < n; ++i)
101 MPI_Allreduce(MPI_IN_PLACE, found.data(), n, MPI_INT, MPI_SUM, snapshot.
GetCommunicator());
102 unsigned ntot = std::accumulate(found.begin(), found.end(), 0, std::plus<int>());
105 "ParticlePositionCV: Expected to find " +
107 " atoms, but only found " +
108 to_string(ntot) +
"."
119 std::vector<int> idx;
124 const auto& masses = snapshot.
GetMasses();
152 Json::CharReaderBuilder rbuilder;
153 Json::CharReader* reader = rbuilder.newCharReader();
155 reader->parse(JsonSchema::ParticlePositionCV.c_str(),
156 JsonSchema::ParticlePositionCV.c_str() + JsonSchema::ParticlePositionCV.size(),
158 validator.
Parse(schema, path);
166 for(
auto&
id : json[
"atom_ids"])
167 atomids.push_back(
id.asInt());
170 position[0] = json[
"position"][0].asDouble();
171 position[1] = json[
"position"][1].asDouble();
172 position[2] = json[
"position"][2].asDouble();
176 if(json.isMember(
"dimension"))
178 auto dimx = json[
"dimension"][0].asBool();
179 auto dimy = json[
"dimension"][1].asBool();
180 auto dimz = json[
"dimension"][2].asBool();
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 an particle position.
Label atomids_
Vector of atom ids of interest.
void Initialize(const Snapshot &snapshot) override
Initialize necessary variables.
Bool3 dim_
Each dimension determines if a constraint is applied by the CV.
ParticlePositionCV(const Label &atomids, const Vector3 &position)
Constructor.
ParticlePositionCV(const Label &atomids, const Vector3 &position, bool dimx, bool dimy, bool dimz)
Constructor.
void Evaluate(const Snapshot &snapshot) override
Evaluate the CV.
static ParticlePositionCV * Build(const Json::Value &json, const std::string &path)
Set up collective variable.
Vector3 point_
Target point in space.
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.
void ApplyMinimumImage(Vector3 *v) const
Apply minimum image to a vector.
Eigen::Vector3d Vector3
Three-dimensional vector.
Eigen::Matrix< bool, 3, 1 > Bool3
Three-dimensional boolean.
std::vector< int > Label
List of integers.