LCOV - code coverage report
Current view: top level - reference - SimpleRMSD.cpp (source / functions) Hit Total Coverage
Test: plumed test coverage Lines: 36 42 85.7 %
Date: 2026-03-30 13:16:06 Functions: 9 11 81.8 %

          Line data    Source code
       1             : /* +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
       2             :    Copyright (c) 2013-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             : #include "RMSDBase.h"
      23             : #include "MetricRegister.h"
      24             : #include "tools/RMSD.h"
      25             : 
      26             : namespace PLMD {
      27             : 
      28             : class SimpleRMSD : public RMSDBase {
      29             : private:
      30             :   RMSD myrmsd;
      31             : public:
      32             :   explicit SimpleRMSD( const ReferenceConfigurationOptions& ro );
      33             :   void read( const PDB& ) override;
      34             :   double calc( const std::vector<Vector>& pos, ReferenceValuePack& myder, const bool& squared ) const override;
      35           4 :   bool pcaIsEnabledForThisReference() override {
      36           4 :     return true;
      37             :   }
      38          68 :   void setupPCAStorage( ReferenceValuePack& mypack ) override {
      39             :     mypack.switchOnPCAOption();
      40          68 :     mypack.getAtomsDisplacementVector().resize( getNumberOfAtoms() );
      41          68 :   }
      42             :   void extractAtomicDisplacement( const std::vector<Vector>& pos, std::vector<Vector>& direction ) const override;
      43             :   double projectAtomicDisplacementOnVector( const bool& normalized, const std::vector<Vector>& vecs, ReferenceValuePack& mypack ) const override;
      44             : };
      45             : 
      46       13855 : PLUMED_REGISTER_METRIC(SimpleRMSD,"SIMPLE")
      47             : 
      48          35 : SimpleRMSD::SimpleRMSD( const ReferenceConfigurationOptions& ro ):
      49             :   ReferenceConfiguration( ro ),
      50          35 :   RMSDBase( ro ) {
      51          35 : }
      52             : 
      53          31 : void SimpleRMSD::read( const PDB& pdb ) {
      54          31 :   readReference( pdb );
      55          31 : }
      56             : 
      57         172 : double SimpleRMSD::calc( const std::vector<Vector>& pos, ReferenceValuePack& myder, const bool& squared ) const {
      58         172 :   if( myder.getAtomsDisplacementVector().size()!=pos.size() ) {
      59          38 :     myder.getAtomsDisplacementVector().resize( pos.size() );
      60             :   }
      61         172 :   double d=myrmsd.simpleAlignment( getAlign(), getDisplace(), pos, getReferencePositions(), myder.getAtomVector(), myder.getAtomsDisplacementVector(), squared );
      62         172 :   myder.clear();
      63        3997 :   for(unsigned i=0; i<pos.size(); ++i) {
      64        3825 :     myder.setAtomDerivatives( i, myder.getAtomVector()[i] );
      65             :   }
      66         172 :   if( !myder.updateComplete() ) {
      67         172 :     myder.updateDynamicLists();
      68             :   }
      69         172 :   return d;
      70             : }
      71             : 
      72           0 : void SimpleRMSD::extractAtomicDisplacement( const std::vector<Vector>& pos, std::vector<Vector>& direction ) const {
      73           0 :   std::vector<Vector> tder( getNumberOfAtoms() );
      74           0 :   myrmsd.simpleAlignment( getAlign(), getDisplace(), pos, getReferencePositions(), tder, direction, true );
      75           0 :   for(unsigned i=0; i<pos.size(); ++i) {
      76           0 :     direction[i] = getDisplace()[i]*direction[i];
      77             :   }
      78           0 : }
      79             : 
      80          88 : double SimpleRMSD::projectAtomicDisplacementOnVector( const bool& normalized, const std::vector<Vector>& vecs, ReferenceValuePack& mypack ) const {
      81             :   plumed_dbg_assert( mypack.calcUsingPCAOption() );
      82          88 :   Vector comder;
      83          88 :   comder.zero();
      84         550 :   for(unsigned j=0; j<vecs.size(); ++j) {
      85        1848 :     for(unsigned k=0; k<3; ++k) {
      86        1386 :       comder[k] += getAlign()[j]*vecs[j][k];
      87             :     }
      88             :   }
      89             : 
      90             :   double proj=0;
      91          88 :   mypack.clear();
      92         550 :   for(unsigned j=0; j<vecs.size(); ++j) {
      93        1848 :     for(unsigned k=0; k<3; ++k) {
      94        1386 :       proj += vecs[j][k]*mypack.getAtomsDisplacementVector()[j][k];
      95             :     }
      96         462 :     mypack.setAtomDerivatives( j, vecs[j] - comder );
      97             :   }
      98          88 :   if( !mypack.updateComplete() ) {
      99          88 :     mypack.updateDynamicLists();
     100             :   }
     101          88 :   return proj;
     102             : }
     103             : 
     104             : }

Generated by: LCOV version 1.16