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