23 #include "CollectiveVariable.h" 
   24 #include "Validator/ObjectRequirement.h" 
   25 #include "Drivers/DriverException.h" 
   42         std::vector<Label>     groups_; 
 
   43         std::vector<double>     massg_; 
 
   47         std::vector<Vector3>        r_; 
 
   56         groups_(groups), p_(p), N_( groups_.size())
 
   57         { massg_.resize( groups_.size(),0.0 ); }
 
   66             double massi; 
Label listi;
 
   67             for (
size_t i = 0; i < N_; ++i) {
 
   84             if (p_ > groups_.size())
 
   85                 throw std::invalid_argument(
 
   86                     "RouseModeCV: Expected to find p to be less than " + 
 
   87                     to_string(groups_.size()) +
" but found p = " + 
 
   91             for (
size_t j = 0; j < groups_.size(); ++j) {
 
   92                 auto nj = groups_[j].size();
 
   94                 std::vector<int> found(nj,0);
 
   95                 for (
size_t i = 0; i <nj; ++i) {
 
  100                 MPI_Allreduce(MPI_IN_PLACE, found.data(), nj, MPI_INT, MPI_SUM, snapshot.
GetCommunicator());
 
  101                 unsigned njtot = std::accumulate(found.begin(), found.end(), 0, std::plus<int>());
 
  104                     throw std::invalid_argument(
 
  105                         "RouseModeCV: Expected to find " + 
 
  107                         " atoms in group " + to_string(j) +
", but only found " + 
 
  108                         to_string(njtot) + 
"." 
  125             const auto& masses = snapshot.
GetMasses();   
 
  128             double ppi_n = p_ * M_PI / N_;  
 
  135             std::vector<Vector3>     rcom; 
 
  136             for (
size_t i = 0; i < N_; ++i) {
 
  147             for (
size_t i = 1; i< N_; ++i) {
 
  149                 r_[i] = r_[i-1] + dri;  
 
  157             for (
size_t i = 0; i<N_; ++i) {
 
  158                 xp_ += r_[i]*cos ( ppi_n * (i+0.5) );
 
  161             if ( p_ != 0 ) xp_ *= sqrt(2.0) ;
 
  171             if ( p_ != 0) gradpcon *= sqrt(2.0);         
 
  172             for (
size_t i = 0; i < N_; ++i) {
 
  182                 double cosval = cos(ppi_n*(i+0.5)) / massg_[i]; 
 
  183                 for (
auto& 
id : idi) {
 
  184                     grad_[id] +=  gradpcon* cosval * masses[id];
 
  190         static RouseModeCV* Build(
const Json::Value& json, 
const std::string& path)
 
  196             reader.parse(JsonSchema::RouseModeCV, schema);
 
  197             validator.
Parse(schema, path);
 
  204             std::vector<Label> groups;
 
  205             for (
auto& group : json[
"groups"]) 
 
  207                 groups.push_back({});
 
  208                 for(
auto& 
id : group) 
 
  209                     groups.back().push_back(
id.asInt());
 
  212             auto mode = json.get(
"mode",0).asInt();
 
std::vector< int > Label
List of integers. 
bool HasErrors()
Check if errors have occured. 
unsigned GetNumAtoms() const 
Get number of atoms in this snapshot. 
void Evaluate(const Snapshot &snapshot) override
Evaluate the CV. 
double TotalMass(const Label &indices) const 
Compute the total mass of a group of particles based on index. 
Collective variable is a Rouse mode for a polymer chain comprised of N particle groups. 
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. 
RouseModeCV(const std::vector< Label > &groups, int p)
Basic Constructor for Rouse Mode CV. 
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. 
Requirements on an object. 
void Initialize(const Snapshot &snapshot) override
Initialize necessary variables. 
void setMasses(const std::vector< Label > &groups, const Snapshot &snapshot)
Helper function to determine masses of each group. 
Eigen::Vector3d Vector3
Three-dimensional vector. 
void ApplyMinimumImage(Vector3 *v) const 
Apply minimum image to a vector. 
double val_
Current value of CV. 
Abstract class for a collective variable. 
virtual void Validate(const Value &json, const std::string &path) override
Validate JSON value.