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_;
89 throw std::invalid_argument(
"ParallelBetaRMSDCV: Input must designate range of residues with 2 residue numbers.");
94 if(resids[0] >= resids[1]){
95 throw std::invalid_argument(
"ParallelBetaRMSDCV: Input must list lower residue index first: please reverse residue range.");
96 }
else if(resids[1] - resids[0] < 5) {
97 throw std::invalid_argument(
"ParallelBetaRMSDCV: Residue range must span at least 6 residues for secondary structure calculation.");
100 std::cout <<
"ParallelBetaRMSDCV: Calculating parallel beta sheet character from residue " << resids[0] <<
" to " << resids[1] <<
"." << std::endl;
102 for(
int i = resids[0]; i <= resids[1]; i++){
118 using std::to_string;
119 std::vector<int> found;
121 size_t nfound = found.size();
122 MPI_Allreduce(MPI_IN_PLACE, &nfound, 1, MPI_INT, MPI_SUM, snapshot.
GetCommunicator());
123 if(nfound !=
resids_.size() * 5)
125 "ParallelBetaRMSDCV: Expected to find " +
126 to_string(
resids_.size() * 5) +
127 " atoms, but only found " +
128 to_string(nfound) +
"."
133 std::vector<Vector3> refalpha;
168 for(
size_t k = 0; k < 29; k++){
169 for(
size_t h = k + 1; h < 30; h++){
170 refdists_[29 * k + h] = (refalpha[k] - refalpha[h]).norm();
185 unsigned int resgroups =
resids_.size() - 2;
186 double rmsd, dist_norm, dxgrouprmsd;
189 std::vector<Vector3> refxyz;
190 std::vector< std::vector< Vector3 > > deriv(30, std::vector<Vector3>(30,
Vector3{0,0,0}));
195 for(
size_t i = 0; i < resgroups - 3; i++){
196 for(
size_t j = i + 3; j < resgroups; j++){
200 std::fill(refxyz.begin(), refxyz.end(),
Vector3{0,0,0});
201 refxyz.resize(30,
Vector3{0,0,0});
203 for(
size_t k = 0; k < 15; k++){
205 if(localidx != -1) refxyz[k] = pos[localidx];
207 for(
size_t k = 0; k < 15; k++){
209 if(localidx != -1) refxyz[k + 15] = pos[localidx];
212 MPI_Allreduce(MPI_IN_PLACE, refxyz.data(), 90, MPI_DOUBLE, MPI_SUM, comm);
215 for(
size_t k = 0; k < 29; k++){
216 for(
size_t h = k + 1; h < 30; h++){
217 dist_xyz = refxyz[k] - refxyz[h];
218 dist_norm = dist_xyz.norm() -
refdists_[29 * k + h];
219 rmsd += dist_norm * dist_norm;
220 deriv[k][h] = dist_xyz * dist_norm / dist_xyz.norm();
224 rmsd = pow(rmsd / 435, 0.5) / 0.1;
225 val_ += (1 - pow(rmsd, 8.0)) / (1 - pow(rmsd, 12.0));
227 dxgrouprmsd = pow(rmsd, 11.0) + pow(rmsd, 7.0);
228 dxgrouprmsd /= pow(rmsd, 8.0) + pow(rmsd, 4.0) + 1;
229 dxgrouprmsd /= pow(rmsd, 8.0) + pow(rmsd, 4.0) + 1;
230 dxgrouprmsd *= -40. / 435;
232 for(
size_t k = 0; k < 15; k++){
233 for(
size_t h = k + 1; h < 15; h++){
235 if(localidx != -1)
grad_[localidx] += dxgrouprmsd * deriv[k][h];
237 if(localidx != -1)
grad_[localidx] += dxgrouprmsd * deriv[k][h];
239 for(
size_t h = 0; h < 15; h++){
241 if(localidx != -1)
grad_[localidx] += dxgrouprmsd * deriv[k][h + 15];
243 if(localidx != -1)
grad_[localidx] += dxgrouprmsd * deriv[k][h + 15];
246 for(
size_t k = 0; k < 14; k++){
247 for(
size_t h = k + 1; h < 15; h++){
249 if(localidx != -1)
grad_[localidx] += dxgrouprmsd * deriv[k + 15][h + 15];
251 if(localidx != -1)
grad_[localidx] += dxgrouprmsd * deriv[k + 15][h + 15];
264 Json::CharReaderBuilder rbuilder;
265 Json::CharReader* reader = rbuilder.newCharReader();
267 reader->parse(JsonSchema::ParallelBetaRMSDCV.c_str(),
268 JsonSchema::ParallelBetaRMSDCV.c_str() + JsonSchema::ParallelBetaRMSDCV.size(),
270 validator.
Parse(schema, path);
277 std::vector<int> resids;
278 for(
auto& s : json[
"residue_ids"])
279 resids.push_back(s.asInt());
280 auto reference = json[
"reference"].asString();
282 double unitconv = json.get(
"length_unit", 1).asDouble();
284 int mode = json.get(
"mode", 0).asInt();
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 to measure parallel beta sheet secondary structure.
std::vector< std::vector< std::string > > atomids_
Atom IDs for secondary structure calculation: backbone of resids_.
ParallelBetaRMSDCV(std::vector< int > resids, std::string refpdb, double unitconv, int mode)
Constructor.
int mode_
Specify whether to calculate beta sheet character in intra or inter mode: 0 for either,...
void Initialize(const Snapshot &snapshot) override
Initialize necessary variables.
std::vector< double > refdists_
Pairwise distance between backbone atoms for reference structure.
void Evaluate(const Snapshot &snapshot) override
Evaluate the CV.
std::vector< int > ids_only_
Atom IDs only, for secondary structure calculation: backbone atoms of resids_.
std::string refpdb_
Name of pdb reference for system.
double unitconv_
Length unit conversion: convert 1 nm to your internal MD units (ex. if using angstroms use 10)
std::vector< Vector3 > refalpha_
Coordinates for reference structure.
static ParallelBetaRMSDCV * Build(const Json::Value &json, const std::string &path)
Set up collective variable.
std::vector< int > resids_
Residue IDs for secondary structure calculation.
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.