LCOV - code coverage report
Current view: top level - reference - SimpleRMSD.cpp (source / functions) Hit Total Coverage
Test: plumed test coverage Lines: 30 35 85.7 %
Date: 2020-11-18 11:20:57 Functions: 13 15 86.7 %

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

Generated by: LCOV version 1.13