LCOV - code coverage report
Current view: top level - colvar - ERMSD.cpp (source / functions) Hit Total Coverage
Test: plumed test coverage Lines: 51 52 98.1 %
Date: 2024-10-18 13:59:31 Functions: 3 4 75.0 %

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

Generated by: LCOV version 1.16