Line data Source code
1 : /* +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
2 : Copyright (c) 2016-2019 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.org for more information.
6 :
7 : This file is part of plumed, version 2.
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 :
23 : /*
24 : This vast majority of the source code in this file was writting by
25 : Sandro Bottaro with some help from Giovanni Bussi
26 : */
27 :
28 : #include "Colvar.h"
29 : #include "core/PlumedMain.h"
30 : #include "ActionRegister.h"
31 : #include "tools/PDB.h"
32 : #include "tools/ERMSD.h"
33 : #include "core/Atoms.h"
34 : #include <iostream>
35 :
36 : using namespace std;
37 :
38 : namespace PLMD {
39 : namespace colvar {
40 :
41 :
42 : //+PLUMEDOC COLVAR ERMSD
43 : /*
44 : Calculate eRMSD with respect to a reference structure.
45 :
46 : eRMSD is a metric developed for measuring distances between three-dimensional RNA structures.
47 : The standard RMSD measure is highly inaccurate when measuring distances among three-dimensional
48 : structures of nucleic acids.
49 : It is not unusual, for example, that two RNA structures with low RMSD (i.e. less than 0.4nm) display a completely different network of base-base interactions.
50 :
51 : eRMSD measures the distance between structures by considering only the relative positions and orientations of nucleobases. The eRMSD can be considered as a vectorial version of contact maps and it is calculated as follows:
52 :
53 : 1. Set up a local reference system in the center of the six-membered ring of each nucleobase in a molecule.
54 : The xy plane lies on the plane of the nucleobase, and it is oriented such that the Watson-Crick interaction is always at \f$ \theta \approx 60^{\circ} \f$.
55 :
56 : 2. Calculate all pairwise distance vectors \f$ \vec{r}_{i,j} \f$ among base centers.
57 :
58 : 3. Rescale distance vectors as \f$ \tilde{\vec{r}}_{i,j} = (r_x/a,r_y/a,r_z/b) \f$, where a=b=5 \AA, c= 3 \AA. This rescaling has the effect of weghting more deviations on the z-axis with respect to the x/y directions.
59 :
60 : 4. Calculate the G vectors
61 :
62 : \f[
63 : \vec{G}(\tilde{\vec{r}}) = (\sin(\gamma \tilde{r}) \tilde{r}_x/\tilde{r},\sin(\gamma \tilde{r}) \tilde{r}_y/\tilde{r},\sin(\gamma \tilde{r}) \tilde{r}_z/\tilde{r}, 1+\cos(\gamma \tilde{r})) \times
64 : \frac{\Theta(\tilde{r}_{cutoff}-\tilde{r})}{\gamma}
65 : \f]
66 :
67 : Here, \f$ \gamma = \pi/\tilde{r}_{cutoff}\f$ and \f$ \Theta \f$ is the Heaviside step function. The default cutoff is set to 2.4.
68 :
69 : 5. The eRMSD between two structures \f$ \alpha \f$ and \f$ \beta \f$ reads
70 :
71 : \f[
72 : eRMSD = \sqrt{\frac{1}{N} \sum_{j,k} \vert \vec{G}(\tilde{\vec{r}}_{jk}^{\alpha}) - \vec{G}(\tilde{\vec{r}}_{jk}^{\beta}) \vert^2 }
73 : \f]
74 :
75 : Using the default cutoff, two structures with eRMSD of 0.7 or lower can be considered as significantly similar. A full description of the eRMSD can be found in \cite bott14
76 :
77 : ERMSD is computed using the position of three atoms on the 6-membered ring of each involved nucleobase. The atoms should be:
78 : - C2,C4,C6 for pyrimdines
79 : - C2,C6,C4 for purines
80 :
81 : The different order for purines and pyrimidines is fundamental and allows you to compute ERMSD between structures with different
82 : sequences as well! Notice that the simplest way to avoid mistakes in choosing these atoms is to use the `@lcs-#` strings
83 : as shown in the examples (see also \ref MOLINFO).
84 :
85 : \warning Notice that the ERMSD implemented here is not integrated with the other metrics in plumed. As a consequence, it is not (yet) possible
86 : to e.g. build path collective variables using ERMSD
87 :
88 : \warning Notice that ERMSD expect a single molecule and makes coordinate whole before anything else. As such, results might be unexpected
89 : for a multi molecular system.
90 :
91 : \par Examples
92 :
93 : Calculate the eRMSD from reference structure reference.pdb using the default cutoff (2.4). The list of residues involved in the calculation has to be specified. In this example, the eRMSD is calculated
94 : considering residues 1,2,3,4,5,6.
95 :
96 : \plumedfile
97 : MOLINFO STRUCTURE=reference.pdb
98 : eRMSD1: ERMSD REFERENCE=reference.pdb ATOMS=@lcs-1,@lcs-2,@lcs-3,@lcs-4,@lcs-5,@lcs-6
99 : \endplumedfile
100 :
101 : */
102 : //+ENDPLUMEDOC
103 :
104 :
105 12 : class ERMSD : public Colvar {
106 :
107 :
108 : vector<Vector> derivs;
109 : PLMD::ERMSD ermsd;
110 : bool pbc;
111 :
112 : public:
113 : explicit ERMSD(const ActionOptions&);
114 : virtual void calculate();
115 : static void registerKeywords(Keywords& keys);
116 : };
117 :
118 6456 : PLUMED_REGISTER_ACTION(ERMSD,"ERMSD")
119 :
120 5 : void ERMSD::registerKeywords(Keywords& keys) {
121 5 : Colvar::registerKeywords(keys);
122 :
123 20 : keys.add("compulsory","REFERENCE","a file in pdb format containing the reference structure and the atoms involved in the CV.");
124 25 : keys.add("compulsory","CUTOFF","2.4","only pairs of atoms closer than CUTOFF are considered in the calculation.");
125 20 : keys.add("atoms","ATOMS","the list of atoms (use lcs)");
126 20 : keys.add("optional","PAIRS","List of pairs considered. All pairs are considered if this value is not specified.");
127 :
128 5 : }
129 :
130 4 : ERMSD::ERMSD(const ActionOptions&ao):
131 12 : PLUMED_COLVAR_INIT(ao), pbc(true)
132 : {
133 : string reference;
134 8 : parse("REFERENCE",reference);
135 4 : double cutoff=2.4;
136 8 : parse("CUTOFF",cutoff);
137 :
138 :
139 4 : bool nopbc(false);
140 8 : parseFlag("NOPBC",nopbc);
141 4 : pbc=!nopbc;
142 :
143 : vector<AtomNumber> atoms_;
144 8 : parseAtomList("ATOMS",atoms_);
145 :
146 : vector<unsigned> pairs_;
147 8 : parseVector("PAIRS",pairs_);
148 4 : checkRead();
149 :
150 4 : addValueWithDerivatives(); setNotPeriodic();
151 :
152 4 : if(atoms_.size()<6) error("at least six atoms should be specified");
153 4 : if(atoms_.size()%3!=0) error("Atoms are not multiple of 3");
154 4 : if(pairs_.size()%2!=0) error("pairs are not multiple of 2");
155 :
156 :
157 : //checkRead();
158 : //log.printf(" of atoms");
159 : //for(unsigned i=0;i<atoms.size();++i) log.printf(" %d",atoms[i].serial());
160 : //requestAtoms(atoms);
161 :
162 : // read everything in ang and transform to nm if we are not in natural units
163 8 : PDB pdb;
164 8 : if( !pdb.read(reference,plumed.getAtoms().usingNaturalUnits(),0.1/atoms.getUnits().getLength()) )
165 0 : error("missing input file " + reference );
166 : // store target_ distance
167 : vector <Vector> reference_positions;
168 4 : unsigned natoms = atoms_.size();
169 4 : log.printf("Read %u atoms\n",natoms);
170 :
171 4 : reference_positions.resize(natoms);
172 1708 : for(unsigned i=0; i<natoms; i++) {
173 1704 : reference_positions[i] = pdb.getPosition(atoms_[i]);
174 : //log.printf("%f %f %f \n",reference_positions[i][0],reference_positions[i][1],reference_positions[i][2]);
175 : }
176 :
177 : // shift to count from zero
178 80 : for(unsigned i=0; i<pairs_.size(); ++i) pairs_[i]--;
179 :
180 4 : ermsd.setReference(reference_positions,pairs_,cutoff/atoms.getUnits().getLength());
181 :
182 4 : requestAtoms(atoms_);
183 4 : derivs.resize(natoms);
184 :
185 8 : log.printf(" reference from file %s\n",reference.c_str());
186 4 : log.printf(" which contains %u atoms\n",natoms);
187 :
188 4 : log<<" Bibliography "
189 12 : <<plumed.cite("Bottaro, Di Palma, and Bussi, Nucleic Acids Res. 42, 13306 (2014)")
190 16 : <<plumed.cite("Bottaro, Banas, Sponer, and Bussi, J. Phys. Chem. Lett. 7, 4032 (2016)")<<"\n";
191 :
192 4 : }
193 :
194 : // calculator
195 222 : void ERMSD::calculate() {
196 : // set derivatives to zero
197 142302 : for(unsigned i=0; i<derivs.size(); ++i) {derivs[i].zero();}
198 : double ermsdist;
199 222 : Tensor virial;
200 : // This is a trick to avoid explicit virial calculation
201 : // 1. we make the molecule whole
202 222 : makeWhole();
203 : // 2. we ignore pbcs
204 222 : Pbc fake_pbc;
205 : // Notice that this might have problems when having 2 RNA molecules (hybridization).
206 :
207 444 : ermsdist=ermsd.calculate(getPositions(),fake_pbc,derivs,virial);
208 222 : const double scale=atoms.getUnits().getLength();
209 222 : setValue(ermsdist*scale);
210 :
211 189588 : for(unsigned i=0; i<derivs.size(); ++i) {setAtomsDerivatives(i,derivs[i]*scale);}
212 :
213 222 : setBoxDerivativesNoPbc();
214 :
215 : //setBoxDerivatives(virial);
216 :
217 222 : }
218 :
219 : }
220 4839 : }
|