LCOV - code coverage report
Current view: top level - colvar - RMSDShortcut.cpp (source / functions) Hit Total Coverage
Test: plumed test coverage Lines: 53 53 100.0 %
Date: 2024-10-18 14:00:25 Functions: 2 3 66.7 %

          Line data    Source code
       1             : /* +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
       2             :    Copyright (c) 2011-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 "core/ActionShortcut.h"
      23             : #include "core/ActionRegister.h"
      24             : #include "core/ActionWithArguments.h"
      25             : #include "tools/PDB.h"
      26             : #include "core/PlumedMain.h"
      27             : 
      28             : namespace PLMD {
      29             : namespace colvar {
      30             : 
      31             : class RMSDShortcut : public ActionShortcut {
      32             : public:
      33             :   static void registerKeywords(Keywords& keys);
      34             :   explicit RMSDShortcut(const ActionOptions&);
      35             : };
      36             : 
      37             : PLUMED_REGISTER_ACTION(RMSDShortcut,"RMSD")
      38             : 
      39         118 : void RMSDShortcut::registerKeywords(Keywords& keys) {
      40         118 :   ActionShortcut::registerKeywords( keys );
      41         236 :   keys.add("compulsory","REFERENCE","a file in pdb format containing the reference structure and the atoms involved in the CV");
      42         236 :   keys.add("compulsory","TYPE","SIMPLE","the manner in which RMSD alignment is performed.  Should be OPTIMAL or SIMPLE.");
      43         236 :   keys.addFlag("SQUARED",false," This should be setted if you want MSD instead of RMSD ");
      44         236 :   keys.addFlag("NOPBC",false,"ignore the periodic boundary conditions when calculating distances");
      45         236 :   keys.addFlag("NUMERICAL_DERIVATIVES", false, "calculate the derivatives for these quantities numerically");
      46         236 :   keys.addFlag("DISPLACEMENT",false,"Calculate the vector of displacements instead of the length of this vector");
      47         236 :   keys.add("compulsory","NUMBER","0","if there are multiple structures in the pdb file you can specify that you want the RMSD from a specific structure by specifying its place in the file here. If NUMBER=0 then the RMSD from all structures are computed");
      48         118 :   keys.setValueDescription("the RMSD distance between the instaneous structure and the reference structure/s that were input");
      49         236 :   keys.addActionNameSuffix("_SCALAR"); keys.addActionNameSuffix("_VECTOR");
      50         236 :   keys.needsAction("PDB2CONSTANT"); keys.needsAction("WHOLEMOLECULES");
      51         236 :   keys.needsAction("POSITION"); keys.needsAction("CONCATENATE");
      52         118 : }
      53             : 
      54         104 : RMSDShortcut::RMSDShortcut(const ActionOptions& ao):
      55             :   Action(ao),
      56         104 :   ActionShortcut(ao)
      57             : {
      58         208 :   bool disp; parseFlag("DISPLACEMENT",disp);
      59         106 :   std::string reference; parse("REFERENCE",reference);
      60             :   // Read the reference pdb file
      61         106 :   PDB pdb; if( !pdb.read(reference,plumed.usingNaturalUnits(),0.1/plumed.getUnits().getLength()) ) plumed_merror("missing file " + reference );
      62         103 :   unsigned frame; parse("NUMBER",frame); unsigned nf=1;
      63         103 :   if( frame==0 ) {
      64          94 :     FILE* fp=std::fopen(reference.c_str(),"r"); bool do_read=true; nf=0;
      65         561 :     while ( do_read ) {
      66         495 :       PDB mypdb; do_read=mypdb.readFromFilepointer(fp,plumed.usingNaturalUnits(),0.1/plumed.getUnits().getLength());
      67         495 :       if( !do_read && nf>0 ) break ;
      68         467 :       nf++;
      69         495 :     }
      70             :   }
      71         103 :   bool nopbc; parseFlag("NOPBC",nopbc);
      72             :   // Now create the RMSD object
      73         103 :   std::string rmsd_line = getShortcutLabel() + ": ";
      74         103 :   if( nf==1 && !disp ) {
      75         162 :     rmsd_line += "RMSD_SCALAR REFERENCE=" + reference; if(nopbc) rmsd_line += " NOPBC";
      76             :   } else {
      77          22 :     std::string ffnum; Tools::convert( frame, ffnum );
      78          44 :     readInputLine( getShortcutLabel() + "_ref: PDB2CONSTANT REFERENCE=" + reference + " NUMBER=" + ffnum );
      79          22 :     std::vector<AtomNumber> anum( pdb.getAtomNumbers() );
      80          22 :     if( !nopbc ) {
      81          20 :       std::string num; Tools::convert( anum[0].serial(), num ); std::string wm_line = "WHOLEMOLECULES ENTITY0=" + num;
      82         196 :       for(unsigned i=1; i<anum.size(); ++i) { Tools::convert( anum[i].serial(), num ); wm_line += "," + num; }
      83          20 :       readInputLine( wm_line );
      84             :     }
      85          22 :     std::string num; Tools::convert( anum[0].serial(), num ); std::string pos_line = getShortcutLabel() + "_cpos: POSITION NOPBC ATOMS=" + num;
      86         210 :     for(unsigned i=1; i<anum.size(); ++i) { Tools::convert( anum[i].serial(), num ); pos_line += "," + num; }
      87          22 :     readInputLine( pos_line );
      88             :     // Concatenate the three positions together
      89          44 :     readInputLine( getShortcutLabel() + "_pos: CONCATENATE ARG=" + getShortcutLabel() + "_cpos.x," + getShortcutLabel() + "_cpos.y," + getShortcutLabel() + "_cpos.z");
      90          44 :     rmsd_line += "RMSD_VECTOR ARG=" + getShortcutLabel() + "_pos," + getShortcutLabel() + "_ref";
      91          22 :     if( disp ) rmsd_line += " DISPLACEMENT";
      92             :     // Now align
      93          22 :     std::vector<double> align( pdb.getOccupancy() ); Tools::convert( align[0], num ); rmsd_line += " ALIGN=" + num;
      94         210 :     for(unsigned i=1; i<align.size(); ++i) { Tools::convert( align[i], num ); rmsd_line += "," + num; }
      95             :     // And displace
      96          22 :     std::vector<double> displace( pdb.getBeta() ); Tools::convert( displace[0], num ); rmsd_line += " DISPLACE=" + num;
      97         210 :     for(unsigned i=1; i<displace.size(); ++i) { Tools::convert( displace[i], num ); rmsd_line += "," + num; }
      98             :   }
      99             :   // And create the RMSD object
     100         103 :   bool numder; parseFlag("NUMERICAL_DERIVATIVES",numder);
     101         103 :   if(numder && nf==1 && !disp ) rmsd_line += " NUMERICAL_DERIVATIVES"; else if( numder ) error("can only use NUMERICAL_DERIVATIVES flag when RMSD is calculating a single scalar value");
     102         207 :   bool squared; parseFlag("SQUARED",squared); if(squared) rmsd_line += " SQUARED";
     103         310 :   std::string tt; parse("TYPE",tt); readInputLine( rmsd_line + " TYPE=" + tt );
     104         210 : }
     105             : 
     106             : }
     107             : }

Generated by: LCOV version 1.16