23 #include "CollectiveVariable.h"
24 #include "Validator/ObjectRequirement.h"
25 #include "Drivers/DriverException.h"
28 #include "Utility/ReadBackbone.h"
52 std::vector< std::vector<std::string> >
atomids_;
83 throw std::invalid_argument(
"ParallelBetaRMSDCV: Input must designate range of residues with 2 residue numbers.");
88 if(resids[0] >= resids[1]){
89 throw std::invalid_argument(
"ParallelBetaRMSDCV: Input must list lower residue index first: please reverse residue range.");
90 }
else if(resids[1] - resids[0] < 5) {
91 throw std::invalid_argument(
"ParallelBetaRMSDCV: Residue range must span at least 6 residues for secondary structure calculation.");
94 std::cout <<
"ParallelBetaRMSDCV: Calculating parallel beta sheet character from residue " << resids[0] <<
" to " << resids[1] <<
"." << std::endl;
96 for(
unsigned int i = resids[0]; i <= resids[1]; i++){
151 std::vector<int> groupidx;
152 std::vector<int> double_atomids(
atomids_[0].size());
153 std::transform(
atomids_[0].begin(),
atomids_[0].end(), double_atomids.begin(), [](std::string val) {
return std::stod(val);});
156 unsigned int resgroups =
resids_.size() - 2;
157 double rmsd, dist_norm, dxgrouprmsd;
159 std::vector<Vector3> refxyz;
160 std::vector< std::vector< Vector3 > > deriv(30, std::vector<Vector3>(30,
Vector3{0,0,0}));
166 for(
size_t i = 0; i < resgroups - 3; i++){
167 for(
size_t j = i + 3; j < resgroups; j++){
171 std::fill(refxyz.begin(), refxyz.end(),
Vector3{0,0,0});
172 refxyz.resize(30,
Vector3{0,0,0});
173 for(
size_t k = 0; k < 15; k++){
174 refxyz[k] = pos[groupidx[5 * i + k]];
176 for(
size_t k = 0; k < 15; k++){
177 refxyz[k + 15] = pos[groupidx[5 * j + k]];
181 for(
size_t k = 0; k < 29; k++){
182 for(
size_t h = k + 1; h < 30; h++){
183 dist_xyz = refxyz[k] - refxyz[h];
185 dist_norm = dist_xyz.norm() - dist_ref.norm();
186 rmsd += dist_norm * dist_norm;
187 deriv[k][h] = dist_xyz * dist_norm / dist_xyz.norm();
191 rmsd = pow(rmsd / 435, 0.5) / 0.1;
192 val_ += (1 - pow(rmsd, 8.0)) / (1 - pow(rmsd, 12.0));
194 dxgrouprmsd = pow(rmsd, 11.0) + pow(rmsd, 7.0);
195 dxgrouprmsd /= pow(rmsd, 8.0) + pow(rmsd, 4.0) + 1;
196 dxgrouprmsd /= pow(rmsd, 8.0) + pow(rmsd, 4.0) + 1;
197 dxgrouprmsd *= -40. / 435;
199 for(
size_t k = 0; k < 15; k++){
200 for(
size_t h = k + 1; h < 15; h++){
201 grad_[groupidx[5 * i + k]] += dxgrouprmsd * deriv[k][h];
202 grad_[groupidx[5 * i + h]] -= dxgrouprmsd * deriv[k][h];
204 for(
size_t h = 0; h < 15; h++){
205 grad_[groupidx[5 * i + k]] += dxgrouprmsd * deriv[k][h+15];
206 grad_[groupidx[5 * j + h]] -= dxgrouprmsd * deriv[k][h+15];
209 for(
size_t k = 0; k < 14; k++){
210 for(
size_t h = k + 1; h < 15; h++){
211 grad_[groupidx[5 * j + k]] += dxgrouprmsd * deriv[k+15][h+15];
212 grad_[groupidx[5 * j + h]] -= dxgrouprmsd * deriv[k+15][h+15];
227 reader.parse(JsonSchema::ParallelBetaRMSDCV, schema);
228 validator.
Parse(schema, path);
235 std::vector<int> resids;
236 for(
auto& s : json[
"residue_ids"])
237 resids.push_back(s.asInt());
238 auto reference = json[
"reference"].asString();
240 double unitconv = json.get(
"length_unit", 1).asDouble();
242 int mode = json.get(
"mode", 0).asInt();
double unitconv_
Length unit conversion: convert 1 nm to your internal MD units (ex. if using angstroms use 10) ...
void Evaluate(const Snapshot &snapshot) override
Evaluate the CV.
bool HasErrors()
Check if errors have occured.
unsigned GetNumAtoms() const
Get number of atoms in this snapshot.
std::string refpdb_
Name of pdb reference for system.
Class containing a snapshot of the current simulation in time.
std::vector< int > resids_
Residue IDs for secondary structure calculation.
virtual void Parse(Value json, const std::string &path) override
Parse JSON value to generate Requirement(s).
std::vector< Vector3 > grad_
Gradient vector dCv/dxi.
void GetLocalIndices(const Label &ids, Label *indices) const
Exception to be thrown when building the Driver fails.
Collective variable to measure parallel beta sheet secondary structure.
std::vector< std::string > GetErrors()
Get list of error messages.
ParallelBetaRMSDCV(std::vector< int > resids, std::string refpdb, double unitconv, int mode)
Constructor.
Requirements on an object.
int mode_
Specify whether to calculate beta sheet character in intra or inter mode: 0 for either, 1 for inter, 2 for intra.
std::vector< Vector3 > refalpha_
Coordinates for reference structure.
std::vector< std::vector< std::string > > atomids_
Atom IDs for secondary structure calculation: backbone of resids_.
Eigen::Vector3d Vector3
Three-dimensional vector.
double val_
Current value of CV.
Abstract class for a collective variable.
static std::vector< std::vector< std::string > > GetPdbBackbone(std::string refpdb, std::vector< int > resids)
Read protein backbone atoms from reference PDB file.
void Initialize(const Snapshot &snapshot) override
Initialize necessary variables.
const std::vector< Vector3 > & GetPositions() const
Access the particle positions.
static ParallelBetaRMSDCV * Build(const Json::Value &json, const std::string &path)
Set up collective variable.
virtual void Validate(const Value &json, const std::string &path) override
Validate JSON value.