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_;
74 AlphaRMSDCV(std::vector<int> resids, std::string refpdb,
double unitconv) :
78 throw std::invalid_argument(
"AlphaRMSDCV: Input must designate range of residues with 2 residue numbers.");
83 if(resids[0] >= resids[1]){
84 throw std::invalid_argument(
"AlphaRMSDCV: Input must list lower residue index first: please reverse residue range.");
85 }
else if(resids[1] - resids[0] < 5) {
86 throw std::invalid_argument(
"AlphaRMSDCV: Residue range must span at least 6 residues for alpha helix calculation.");
89 std::cout <<
"AlphaRMSDCV: Calculating alpha helix character from residue " << resids[0] <<
" to " << resids[1] <<
"." << std::endl;
91 for(
unsigned int i = resids[0]; i <= resids[1]; i++){
147 std::vector<int> groupidx;
148 std::vector<int> double_atomids(
atomids_[0].size());
149 std::transform(
atomids_[0].begin(),
atomids_[0].end(), double_atomids.begin(), [](std::string val) {
return std::stod(val);});
152 double rmsd, dist_norm, dxgrouprmsd;
154 std::vector<Vector3> refxyz;
155 std::vector< std::vector< Vector3 > > deriv(30, std::vector<Vector3>(30,
Vector3{0,0,0}));
161 unsigned int resgroups =
resids_.size() - 5;
164 for(
size_t i = 0; i < resgroups; i++){
170 std::fill(refxyz.begin(), refxyz.end(),
Vector3{0,0,0});
171 refxyz.resize(30,
Vector3{0,0,0});
172 for(
size_t j = 0; j < 30; j++){
173 refxyz[j] = pos[groupidx[5 * i + j]];
177 for(
size_t j = 0; j < 29; j++){
178 for(
size_t k = j + 1; k < 30; k++){
179 dist_xyz = refxyz[j] - refxyz[k];
181 dist_norm = dist_xyz.norm() - dist_ref.norm();
182 rmsd += dist_norm * dist_norm;
183 deriv[j][k] = dist_xyz * dist_norm / dist_xyz.norm();
187 rmsd = pow(rmsd / 435, 0.5) / 0.1;
188 val_ += (1 - pow(rmsd, 8.0)) / (1 - pow(rmsd, 12.0));
190 dxgrouprmsd = pow(rmsd, 11.0) + pow(rmsd, 7.0);
191 dxgrouprmsd /= pow(rmsd, 8.0) + pow(rmsd, 4.0) + 1;
192 dxgrouprmsd /= pow(rmsd, 8.0) + pow(rmsd, 4.0) + 1;
193 dxgrouprmsd *= -40. / 435;
195 for(
size_t j = 0; j < 29; j++){
196 for(
size_t k = j + 1; k < 30; k++){
197 grad_[groupidx[5 * i + j]] += dxgrouprmsd * deriv[j][k];
198 grad_[groupidx[5 * i + k]] -= dxgrouprmsd * deriv[j][k];
211 reader.parse(JsonSchema::AlphaRMSDCV, schema);
212 validator.
Parse(schema, path);
219 std::vector<int> resids;
220 for(
auto& s : json[
"residue_ids"])
221 resids.push_back(s.asInt());
222 auto reference = json[
"reference"].asString();
224 double unitconv = json.get(
"length_unit", 1).asDouble();
226 return new AlphaRMSDCV(resids, reference, unitconv);
std::vector< std::vector< std::string > > atomids_
Atom IDs for secondary structure calculation: backbone of resids_.
bool HasErrors()
Check if errors have occured.
unsigned GetNumAtoms() const
Get number of atoms in this snapshot.
double unitconv_
Length unit conversion: convert 1 nm to your internal MD units (ex. if using angstroms use 10) ...
std::vector< int > resids_
Residue IDs for secondary structure calculation.
Class containing a snapshot of the current simulation in time.
Collective variable to measure alpha helix secondary structure.
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.
std::string refpdb_
Name of pdb reference for system.
std::vector< std::string > GetErrors()
Get list of error messages.
std::vector< Vector3 > refalpha_
Coordinates for reference structure.
Requirements on an object.
AlphaRMSDCV(std::vector< int > resids, std::string refpdb, double unitconv)
Constructor.
void Evaluate(const Snapshot &snapshot) override
Evaluate the CV.
void Initialize(const Snapshot &snapshot) override
Initialize necessary variables.
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.
const std::vector< Vector3 > & GetPositions() const
Access the particle positions.
static AlphaRMSDCV * 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.