All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
DRMSD.cpp
Go to the documentation of this file.
1 /* +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
2  Copyright (c) 2013 The plumed team
3  (see the PEOPLE file at the root of the distribution for a list of names)
4 
5  See http://www.plumed-code.org for more information.
6 
7  This file is part of plumed, version 2.0.
8 
9  plumed is free software: you can redistribute it and/or modify
10  it under the terms of the GNU Lesser General Public License as published by
11  the Free Software Foundation, either version 3 of the License, or
12  (at your option) any later version.
13 
14  plumed is distributed in the hope that it will be useful,
15  but WITHOUT ANY WARRANTY; without even the implied warranty of
16  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17  GNU Lesser General Public License for more details.
18 
19  You should have received a copy of the GNU Lesser General Public License
20  along with plumed. If not, see <http://www.gnu.org/licenses/>.
21 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ */
22 #include "Colvar.h"
23 #include "core/PlumedMain.h"
24 #include "ActionRegister.h"
25 #include "tools/PDB.h"
26 #include "tools/DRMSD.h"
27 #include "core/Atoms.h"
28 
29 using namespace std;
30 
31 namespace PLMD{
32 namespace colvar{
33 
34 //+PLUMEDOC COLVAR DRMSD
35 /*
36 Calculate the distance RMSD with respect to a reference structure.
37 
38 To calculate the root-mean-square deviation between the atoms in two configurations
39 you must first superimpose the two structures in some ways. Obviously, it is the internal vibrational
40 motions of the structure - i.e. not the translations and rotations - that are interesting. However,
41 aligning two structures by removing the translational and rotational motions is not easy. Furthermore,
42 in some cases there can be alignment issues caused by so-called frame-fitting problems. It is thus
43 often cheaper and easier to calculate the distances between all the pairs of atoms. The distance
44 between the two structures, \f$\mathbf{X}^a\f$ and \f$\mathbf{X}^b\f$ can then be measured as:
45 
46 \f[
47 d(\mathbf{X}^A, \mathbf{X}^B) = \frac{1}{N(N-1)} \sum_{i \ne j} [ d(\mathbf{x}_i^a,\mathbf{x}_j^a) - d(\mathbf{x}_i^b,\mathbf{x}_j^b) ]^2
48 \f]
49 
50 where \f$N\f$ is the number of atoms and \f$d(\mathbf{x}_i,\mathbf{x}_j)\f$ represents the distance between
51 atoms \f$i\f$ and \f$j\f$. Clearly, this representation of the configuration is invariant to translation and rotation.
52 However, it can become expensive to calculate when the number of atoms is large. This can be resolved
53 within the DRMSD colvar by setting LOWER_CUTOFF and UPPER_CUTOFF. These keywords ensure that only
54 pairs of atoms that are within a certain range are incorporated into the above sum.
55 
56 In PDB files the atomic coordinates and box lengths should be in Angstroms unless
57 you are working with natural units. If you are working with natural units then the coordinates
58 should be in your natural length unit. For more details on the PDB file format visit http://www.wwpdb.org/docs.html
59 
60 \par Examples
61 
62 The following tells plumed to calculate the distance RMSD between
63 the positions of the atoms in the reference file and their instantaneous
64 position. Only pairs of atoms whose distance in the reference structure is within
65 0.1 and 0.8 nm are considered.
66 
67 \verbatim
68 DRMSD REFERENCE=file.pdb LOWER_CUTOFF=0.1 UPPER_CUTOFF=0.8
69 \endverbatim
70 
71 ...
72 
73 */
74 //+ENDPLUMEDOC
75 
76 
77 class DRMSD : public Colvar {
78 
79  vector<Vector> derivs_;
81  bool pbc_;
82 
83 public:
84  DRMSD(const ActionOptions&);
85  virtual void calculate();
86  static void registerKeywords(Keywords& keys);
87 };
88 
89 PLUMED_REGISTER_ACTION(DRMSD,"DRMSD")
90 
91 void DRMSD::registerKeywords(Keywords& keys){
92  Colvar::registerKeywords(keys);
93  keys.add("compulsory","REFERENCE","a file in pdb format containing the reference structure and the atoms involved in the CV.");
94  keys.add("compulsory","LOWER_CUTOFF","only pairs of atoms further than LOWER_CUTOFF are considered in the calculation.");
95  keys.add("compulsory","UPPER_CUTOFF","only pairs of atoms closer than UPPER_CUTOFF are considered in the calculation.");
96 }
97 
98 DRMSD::DRMSD(const ActionOptions&ao):
99 PLUMED_COLVAR_INIT(ao), pbc_(true)
100 {
101  string reference;
102  parse("REFERENCE",reference);
103  double lcutoff;
104  parse("LOWER_CUTOFF",lcutoff);
105  double ucutoff;
106  parse("UPPER_CUTOFF",ucutoff);
107  bool nopbc(false);
108  parseFlag("NOPBC",nopbc);
109  pbc_=!nopbc;
110 
111  checkRead();
112 
114 
115  // read everything in ang and transform to nm if we are not in natural units
116  PDB pdb;
117  if( !pdb.read(reference,plumed.getAtoms().usingNaturalUnits(),0.1/atoms.getUnits().getLength()) )
118  error("missing input file " + reference );
119 
120  // store target_ distance
121  drmsd_.setFromPDB(pdb, lcutoff, ucutoff);
122 
124  derivs_.resize(getNumberOfAtoms());
125 
126  log.printf(" reference from file %s\n",reference.c_str());
127  log.printf(" which contains %d atoms\n",getNumberOfAtoms());
128 
129 }
130 
131 // calculator
133 
134 // set derivatives to zero
135  for(unsigned i=0;i<derivs_.size();++i) {derivs_[i].zero();}
136 
137  double drmsd;
138  Tensor virial;
139 
140  if(pbc_){drmsd=drmsd_.calculate(getPositions(),getPbc(),derivs_,virial);}
141  else{ drmsd=drmsd_.calculate(getPositions(), derivs_,virial);}
142 
143  setValue(drmsd);
144 
145  for(unsigned i=0;i<derivs_.size();++i) {setAtomsDerivatives(i,derivs_[i]);}
146 
147  setBoxDerivatives(virial);
148 
149  }
150 
151 }
152 }
bool read(const std::string &file, bool naturalUnits, double scale)
Read the pdb from a file, scaling positions by a factor scale.
Definition: PDB.cpp:144
void parseFlag(const std::string &key, bool &t)
Parse one keyword as boolean flag.
Definition: Action.cpp:104
void setNotPeriodic()
Set your default value to have no periodicity.
Log & log
Reference to the log stream.
Definition: Action.h:93
Class implementing fixed size matrices of doubles.
Definition: Tensor.h:70
void setAtomsDerivatives(int, const Vector &)
Definition: Colvar.h:97
Provides the keyword DRMSD
Definition: DRMSD.cpp:77
void error(const std::string &msg) const
Crash calculation and print documentation.
Definition: Action.cpp:195
const std::vector< Vector > & getPositions() const
Get the array of all positions.
void checkRead()
Check if Action was properly read.
Definition: Action.cpp:161
STL namespace.
void addValueWithDerivatives()
Add a value with the name label that has derivatives.
void requestAtoms(const std::vector< AtomNumber > &a)
Definition: Colvar.cpp:44
#define PLUMED_COLVAR_INIT(ao)
Definition: Colvar.h:29
const Pbc & getPbc() const
Get reference to Pbc.
void setBoxDerivatives(const Tensor &)
Definition: Colvar.h:102
double calculate(const std::vector< Vector > &positions, std::vector< Vector > &derivatives, Tensor &virial) const
Compute drmsd ( no pbc )
Definition: DRMSD.cpp:51
void parse(const std::string &key, T &t)
Parse one keyword as generic type.
Definition: Action.h:273
This class holds the keywords and their documentation.
Definition: Keywords.h:36
This class is used to bring the relevant information to the Action constructor.
Definition: Action.h:41
virtual void calculate()
Calculate an Action.
Definition: DRMSD.cpp:132
int printf(const char *fmt,...)
Formatted output with explicit format - a la printf.
Definition: OFile.cpp:82
This is the abstract base class to use for implementing new collective variables, within it there is ...
Definition: Colvar.h:39
void setValue(const double &d)
Set the default value (the one without name)
A class that implements DRMSD calculations.
Definition: DRMSD.h:37
Minimalistic pdb parser.
Definition: PDB.h:38
PLMD::DRMSD drmsd_
Definition: DRMSD.cpp:80
void setFromPDB(const PDB &, double lbound=0.0, double ubound=std::numeric_limits< double >::max())
set reference, align and displace from input pdb structure
Definition: DRMSD.cpp:30
const Units & getUnits()
Definition: Atoms.h:181
const double & getLength() const
Get length units as double.
Definition: Units.h:95
Main plumed object.
Definition: Plumed.h:201
const std::vector< AtomNumber > & getAtomNumbers() const
Access to the indexes.
Definition: PDB.cpp:47
unsigned getNumberOfAtoms() const
Get number of available atoms.
vector< Vector > derivs_
Definition: DRMSD.cpp:79