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_;
80 AntiBetaRMSDCV(std::vector<int> resids, std::string refpdb,
double unitconv,
int mode) :
84 throw std::invalid_argument(
"AntiBetaRMSDCV: Input must designate range of residues with 2 residue numbers.");
89 if(resids[0] >= resids[1]){
90 throw std::invalid_argument(
"AntiBetaRMSDCV: Input must list lower residue index first: please reverse residue range.");
91 }
else if(resids[1] - resids[0] < 5){
92 throw std::invalid_argument(
"AntiBetaRMSDCV: Residue range must span at least 6 residues for secondary structure calculation.");
95 std::cout <<
"AntiBetaRMSDCV: Calculating antiparallel beta sheet character from residue " << resids[0] <<
" to " << resids[1] <<
"." << std::endl;
97 for(
int i = resids[0]; i <= resids[1]; i++){
113 using std::to_string;
114 std::vector<int> found;
116 size_t nfound = found.size();
117 MPI_Allreduce(MPI_IN_PLACE, &nfound, 1, MPI_INT, MPI_SUM, snapshot.
GetCommunicator());
118 if(nfound !=
resids_.size() * 5)
120 "AntiBetaRMSDCV: Expected to find " +
121 to_string(
resids_.size() * 5) +
122 " atoms, but only found " +
123 to_string(nfound) +
"."
128 std::vector<Vector3> refalpha;
163 for(
size_t k = 0; k < 29; k++){
164 for(
size_t h = k + 1; h < 30; h++){
165 refdists_[29 * k + h] = (refalpha[k] - refalpha[h]).norm();
180 unsigned int resgroups =
resids_.size() - 2;
181 double rmsd, dist_norm, dxgrouprmsd;
184 std::vector<Vector3> refxyz;
185 std::vector< std::vector< Vector3 > > deriv(30, std::vector<Vector3>(30,
Vector3{0,0,0}));
190 for(
size_t i = 0; i < resgroups - 3; i++){
191 for(
size_t j = i + 3; j < resgroups; j++){
195 std::fill(refxyz.begin(), refxyz.end(),
Vector3{0,0,0});
196 refxyz.resize(30,
Vector3{0,0,0});
198 for(
size_t k = 0; k < 15; k++){
200 if(localidx != -1) refxyz[k] = pos[localidx];
203 for(
size_t k = 0; k < 15; k++){
205 if(localidx != -1) refxyz[k + 15] = pos[localidx];
208 MPI_Allreduce(MPI_IN_PLACE, refxyz.data(), 90, MPI_DOUBLE, MPI_SUM, comm);
211 for(
size_t k = 0; k < 29; k++){
212 for(
size_t h = k + 1; h < 30; h++){
213 dist_xyz = refxyz[k] - refxyz[h];
214 dist_norm = dist_xyz.norm() -
refdists_[29 * k + h];
215 rmsd += dist_norm * dist_norm;
216 deriv[k][h] = dist_xyz * dist_norm / dist_xyz.norm();
220 rmsd = pow(rmsd / 435, 0.5) / 0.1;
221 val_ += (1 - pow(rmsd, 8.0)) / (1 - pow(rmsd, 12.0));
223 dxgrouprmsd = pow(rmsd, 11.0) + pow(rmsd, 7.0);
224 dxgrouprmsd /= pow(rmsd, 8.0) + pow(rmsd, 4.0) + 1;
225 dxgrouprmsd /= pow(rmsd, 8.0) + pow(rmsd, 4.0) + 1;
226 dxgrouprmsd *= -40. / 435;
228 for(
size_t k = 0; k < 15; k++){
229 for(
size_t h = k + 1; h < 15; h++){
231 if(localidx != -1)
grad_[localidx] += dxgrouprmsd * deriv[k][h];
233 if (localidx != -1)
grad_[localidx] += dxgrouprmsd * deriv[k][h];
235 for(
size_t h = 0; h < 15; h++){
237 if(localidx != -1)
grad_[localidx] += dxgrouprmsd * deriv[k][h + 15];
239 if(localidx != -1)
grad_[localidx] += dxgrouprmsd * deriv[k][h + 15];
242 for(
size_t k = 0; k < 14; k++){
243 for(
size_t h = k + 1; h < 15; h++){
245 if(localidx != -1)
grad_[localidx] += dxgrouprmsd * deriv[k + 15][h + 15];
247 if(localidx != -1)
grad_[localidx] += dxgrouprmsd * deriv[k + 15][h + 15];
260 Json::CharReaderBuilder rbuilder;
261 Json::CharReader* reader = rbuilder.newCharReader();
263 reader->parse(JsonSchema::AntiBetaRMSDCV.c_str(),
264 JsonSchema::AntiBetaRMSDCV.c_str() + JsonSchema::AntiBetaRMSDCV.size(),
266 validator.
Parse(schema, path);
273 std::vector<int> resids;
274 for(
auto& s : json[
"residue_ids"])
275 resids.push_back(s.asInt());
276 auto reference = json[
"reference"].asString();
278 double unitconv = json.get(
"length_unit", 1).asDouble();
280 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.
Collective variable to measure antiparallel beta secondary structure.
std::vector< double > refdists_
Pairwise distance between backbone atoms for reference structure.
std::vector< int > resids_
Residue IDs for secondary structure calculation.
int mode_
Specify whether to calculate beta sheet character in intra or inter mode: 0 for either,...
static AntiBetaRMSDCV * Build(const Json::Value &json, const std::string &path)
Set up collective variable.
void Initialize(const Snapshot &snapshot) override
Initialize necessary variables.
double unitconv_
Length unit conversion: convert 1 nm to your internal MD units (ex. if using angstroms use 10)
std::string refpdb_
Name of pdb reference for system.
std::vector< std::vector< std::string > > atomids_
Atom IDs and chain IDs for secondary structure calculation: backbone of resids_.
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_.
AntiBetaRMSDCV(std::vector< int > resids, std::string refpdb, double unitconv, int mode)
Constructor.
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.