All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
RMSD.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/RMSD.h"
27 #include "core/Atoms.h"
28 
29 
30 using namespace std;
31 
32 namespace PLMD{
33 namespace colvar{
34 
35 class RMSD : public Colvar {
36 
38 
39  bool squared;
40 
41  vector<Vector> derivs;
42 
43 public:
44  RMSD(const ActionOptions&);
45  virtual void calculate();
46  static void registerKeywords(Keywords& keys);
47 };
48 
49 
50 using namespace std;
51 
52 //+PLUMEDOC COLVAR RMSD
53 /*
54 Calculate the RMSD with respect to a reference structure.
55 
56 To calculate the root-mean-square deviation between the atoms in two configurations
57 you must first superimpose the two structures in some ways. Obviously, it is the internal vibrational
58 motions of the structure - i.e. not the translations and rotations - that are interesting. It is
59 possible to align two structures (i.e. remove the translational and rotational motions of the
60 system).
61 In general the aim of this colvar is to calculate something like:
62 
63 \f[
64 d(X,X_r) = \vert X-X' \vert
65 \f]
66 
67 where \f$ X \f$ is the molecular dynamics snapshot and
68 \f$ X' \f$ is a reference structure you provide as input.
69 Here the symbols \f$ \vert \dots \vert \f$ represent some sort of norm of choice that is selected through the OPTIMAL switch (see below for examples).
70 
71 Here we discuss the switch we implemented so far.
72 
73  - If you use TYPE=SIMPLE you just calculate the root mean square deviation after reset of the geometric center
74  that reads:
75  \f[
76  d(X,X_r) = \sqrt{ \sum_i \sum_\alpha^{x,y,z} \frac{w_i}{\sum_j w_j}( X_{i,\alpha}-com_\alpha(X)-{X'}_{i,\alpha}+com_\alpha(X') )^2 }
77  \f]
78  with
79  \f[
80  com_\alpha(X)= \sum_i \frac{w'_{i}}{\sum_j w'_j}X_{i,\alpha}
81  \f]
82  and
83  \f[
84  com_\alpha(X')= \sum_i \frac{w'_{i}}{\sum_j w'_j}X'_{i,\alpha}
85  \f]
86  where \f$ com_\alpha(X) \f$ and \f$ com_\alpha(X') \f$ are the center of mass
87  whenever the weights $w'$ are assigned proportional to the atomic masses, otherwise are the geometric centers of the
88  running MD snapshot and the reference frame respectively whenever they are all set to one.
89  Note that two set of weights exist: \f$ w' \f$ and \f$ w \f$. The first is used to calculate the center of mass (so it determines the \e alignment)
90  and the second is used to calculate the actual \e displacement.
91  These are assigned in the reference (that you set with e.g.: REFERENCE=whatever.pdb)
92  frame which is, for this case, a simple pdb file containing the atoms
93  on which you want to calculate the distance.
94  Note that in this pdb you need to set correctly the index of the atom STARTING FROM 1 (i.e. +1 shift respect
95  to VMD numbering) so that the program knows which atom needs to be compared with.
96  The OCCUPANCY column (the first after the coordinates) set the \f$ w' \f$ used for the center of mass calculation and the BETA column (the second
97  after the Cartesian coordinates) set the \f$ w \f$ which is responsible of the calculation of the displacement.
98  Users can also use fractional values for beta and the occupancy values. We recommend you only do this when you really know what you are doing however as the results can be rather strange.
99  In PDB files the atomic coordinates and box lengths should be in Angstroms unless
100  you are working with natural units. If you are working with natural units then the coordinates
101  should be in your natural length unit. For more details on the PDB file format visit http://www.wwpdb.org/docs.html
102  .
103  - If you use TYPE=OPTIMAL you just the root mean square deviation after reset of the geometric center
104  and performing an optimal alignment that reads:
105  \f[
106  d(X,X_r) = \sqrt{ \sum_i \sum_\alpha^{x,y,z} \frac{w_i}{\sum_j w_j}[ X_{i,\alpha}-com_\alpha(X)- \sum_\beta M(X,X',w')_{\alpha,\beta}({X'}_{i,\beta}-com_\beta(X')) ]^2 }
107  \f]
108  where \f$ M(X,X',w') \f$ is the optimal alignment matrix which is calculated through the Kearsley \cite kearsley algorithm and the set of
109  weights used for the alignment of the center of mass is also used to perform the optimal alignment.
110  Note that the flexibility of setting only certain atoms to calculate the center of mass and optimal alignment which may be different from the one used in the \e displacemnt calculation is useful whenever for example you want to calculate the motion of a ligand in a protein cavity and you want to clearly use the protein as reference system.
111  When this form of RMSD is used to calculate the secondary structure variables (\ref ALPHARMSD, \ref ANTIBETARMSD and \ref PARABETARMSD) all the atoms in the segment are assumed to be part of both the alignment and displacement sets.
112 
113 \par Examples
114 
115 The following tells plumed to calculate the RMSD distance between
116 the positions of the atoms in the reference file and their instantaneous
117 position. The Kearseley algorithm is used so this is done optimally.
118 
119 \verbatim
120 RMSD REFERENCE=file.pdb TYPE=OPTIMAL
121 \endverbatim
122 
123 ...
124 
125 */
126 //+ENDPLUMEDOC
127 
128 PLUMED_REGISTER_ACTION(RMSD,"RMSD")
129 
130 void RMSD::registerKeywords(Keywords& keys){
131  Colvar::registerKeywords(keys);
132  keys.add("compulsory","REFERENCE","a file in pdb format containing the reference structure and the atoms involved in the CV.");
133  keys.add("compulsory","TYPE","SIMPLE","the manner in which RMSD alignment is performed. Should be OPTIMAL or SIMPLE.");
134  keys.addFlag("SQUARED",false," This should be setted if you want MSD instead of RMSD ");
135 }
136 
137 RMSD::RMSD(const ActionOptions&ao):
138 PLUMED_COLVAR_INIT(ao),rmsd(log),squared(false)
139 {
140  string reference;
141  parse("REFERENCE",reference);
142  string type;
143  type.assign("SIMPLE");
144  parse("TYPE",type);
145  parseFlag("SQUARED",squared);
146 
147  checkRead();
148 
149 
151  PDB pdb;
152 
153  // read everything in ang and transform to nm if we are not in natural units
154  if( !pdb.read(reference,plumed.getAtoms().usingNaturalUnits(),0.1/atoms.getUnits().getLength()) )
155  error("missing input file " + reference );
156 
157  rmsd.set(pdb,type);
158 
160 
161  derivs.resize(getNumberOfAtoms());
162  log.printf(" reference from file %s\n",reference.c_str());
163  log.printf(" which contains %d atoms\n",getNumberOfAtoms());
164  log.printf(" method for alignment : %s \n",rmsd.getMethod().c_str() );
165  if(squared)log.printf(" chosen to use SQUARED option for MSD instead of RMSD\n");
166 
167 }
168 
169 
170 // calculator
173  setValue(r);
174  for(unsigned i=0;i<derivs.size();i++) setAtomsDerivatives(i,derivs[i]);
175  Tensor virial;
177 }
178 
179 }
180 }
181 
182 
183 
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
vector< Vector > derivs
Definition: RMSD.cpp:41
void setAtomsDerivatives(int, const Vector &)
Definition: Colvar.h:97
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.
A class that implements RMSD calculations This is a class that implements the various infrastructure ...
Definition: RMSD.h:62
double calculate(const std::vector< Vector > &positions, std::vector< Vector > &derivatives, bool squared=false)
Compute rmsd.
Definition: RMSD.cpp:131
void requestAtoms(const std::vector< AtomNumber > &a)
Definition: Colvar.cpp:44
#define PLUMED_COLVAR_INIT(ao)
Definition: Colvar.h:29
virtual void calculate()
Calculate an Action.
Definition: RMSD.cpp:171
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
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)
PLMD::RMSD rmsd
Definition: RMSD.cpp:37
void set(const PDB &, std::string mytype)
set reference, align and displace from input pdb structure
Definition: RMSD.cpp:65
Minimalistic pdb parser.
Definition: PDB.h:38
void setBoxDerivativesNoPbc()
Set box derivatives automatically.
Definition: Colvar.h:107
const Units & getUnits()
Definition: Atoms.h:181
const double & getLength() const
Get length units as double.
Definition: Units.h:95
Provides the keyword RMSD
Definition: RMSD.cpp:35
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.
std::string getMethod()
Definition: RMSD.cpp:102