23 #include "CollectiveVariable.h"
24 #include "Validator/ObjectRequirement.h"
25 #include "Drivers/DriverException.h"
28 #include "Utility/ReadBackbone.h"
51 std::vector< std::vector<std::string> >
atomids_;
77 AlphaRMSDCV(std::vector<int> resids, std::string refpdb,
double unitconv) :
81 throw std::invalid_argument(
"AlphaRMSDCV: Input must designate range of residues with 2 residue numbers.");
86 if(resids[0] >= resids[1]){
87 throw std::invalid_argument(
"AlphaRMSDCV: Input must list lower residue index first: please reverse residue range.");
88 }
else if(resids[1] - resids[0] < 5) {
89 throw std::invalid_argument(
"AlphaRMSDCV: Residue range must span at least 6 residues for alpha helix calculation.");
92 std::cout <<
"AlphaRMSDCV: Calculating alpha helix character from residue " << resids[0] <<
" to " << resids[1] <<
"." << std::endl;
94 for(
int i = resids[0]; i <= resids[1]; i++){
110 using std::to_string;
111 std::vector<int> found;
113 size_t nfound = found.size();
114 MPI_Allreduce(MPI_IN_PLACE, &nfound, 1, MPI_INT, MPI_SUM, snapshot.
GetCommunicator());
115 if(nfound !=
resids_.size() * 5)
117 "AlphaRMSDCV: Expected to find " +
118 to_string(
resids_.size() * 5) +
119 " atoms, but only found " +
120 to_string(nfound) +
"."
125 std::vector<Vector3> refalpha;
160 for(
size_t k = 0; k < 29; k++){
161 for(
size_t h = k + 1; h < 30; h++){
162 refdists_[29 * k + h] = (refalpha[k] - refalpha[h]).norm();
177 double rmsd, dist_norm, dxgrouprmsd;
180 std::vector<Vector3> refxyz;
181 std::vector< std::vector< Vector3 > > deriv(30, std::vector<Vector3>(30,
Vector3{0,0,0}));
185 unsigned int resgroups =
resids_.size() - 5;
188 for(
size_t i = 0; i < resgroups; i++){
194 std::fill(refxyz.begin(), refxyz.end(),
Vector3{0,0,0});
195 refxyz.resize(30,
Vector3{0,0,0});
196 for(
size_t j = 0; j < 30; j++){
198 if(localidx != -1) refxyz[j] = pos[localidx];
201 MPI_Allreduce(MPI_IN_PLACE, refxyz.data(), 90, MPI_DOUBLE, MPI_SUM, comm);
204 for(
size_t j = 0; j < 29; j++){
205 for(
size_t k = j + 1; k < 30; k++){
206 dist_xyz = refxyz[j] - refxyz[k];
207 dist_norm = dist_xyz.norm() -
refdists_[29 * j + k];
208 rmsd += dist_norm * dist_norm;
209 deriv[j][k] = dist_xyz * dist_norm / dist_xyz.norm();
213 rmsd = pow(rmsd / 435, 0.5) / 0.1;
214 val_ += (1 - pow(rmsd, 8.0)) / (1 - pow(rmsd, 12.0));
216 dxgrouprmsd = pow(rmsd, 11.0) + pow(rmsd, 7.0);
217 dxgrouprmsd /= pow(rmsd, 8.0) + pow(rmsd, 4.0) + 1;
218 dxgrouprmsd /= pow(rmsd, 8.0) + pow(rmsd, 4.0) + 1;
219 dxgrouprmsd *= -40. / 435;
221 for(
size_t j = 0; j < 29; j++){
222 for(
size_t k = j + 1; k < 30; k++){
224 if(localidx != -1)
grad_[localidx] += dxgrouprmsd * deriv[j][k];
226 if(localidx != -1)
grad_[localidx] += dxgrouprmsd * deriv[j][k];
237 Json::CharReaderBuilder rbuilder;
238 Json::CharReader* reader = rbuilder.newCharReader();
240 reader->parse(JsonSchema::AlphaRMSDCV.c_str(),
241 JsonSchema::AlphaRMSDCV.c_str() + JsonSchema::AlphaRMSDCV.size(),
243 validator.
Parse(schema, path);
250 std::vector<int> resids;
251 for(
auto& s : json[
"residue_ids"])
252 resids.push_back(s.asInt());
253 auto reference = json[
"reference"].asString();
255 double unitconv = json.get(
"length_unit", 1).asDouble();
257 return new AlphaRMSDCV(resids, reference, unitconv);
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.
Collective variable to measure alpha helix secondary structure.
std::vector< int > ids_only_
Atom IDs only, for secondary structure calculation: backbone atoms of resids_.
std::vector< std::vector< std::string > > atomids_
Atom IDs for secondary structure calculation: backbone of resids_.
std::string refpdb_
Name of pdb reference for system.
void Evaluate(const Snapshot &snapshot) override
Evaluate the CV.
std::vector< int > resids_
Residue IDs for secondary structure calculation.
AlphaRMSDCV(std::vector< int > resids, std::string refpdb, double unitconv)
Constructor.
double unitconv_
Length unit conversion: convert 1 nm to your internal MD units (ex. if using angstroms use 10)
std::vector< double > refdists_
Pairwise distance between backbone atoms for reference structure.
static AlphaRMSDCV * Build(const Json::Value &json, const std::string &path)
Set up collective variable.
void Initialize(const Snapshot &snapshot) override
Initialize necessary variables.
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.
static std::vector< std::vector< std::string > > GetPdbBackbone(std::string refpdb, std::vector< int > resids)
Read protein backbone atoms from reference PDB file.
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.
const std::vector< Vector3 > & GetPositions() const
Access the particle positions.
Eigen::Vector3d Vector3
Three-dimensional vector.