LCOV - code coverage report
Current view: top level - mapping - GeometricPathShortcut.cpp (source / functions) Hit Total Coverage
Test: plumed test coverage Lines: 38 41 92.7 %
Date: 2025-04-08 21:11:17 Functions: 2 3 66.7 %

          Line data    Source code
       1             : /* +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
       2             :    Copyright (c) 2013-2018 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 "Path.h"
      23             : #include "tools/PDB.h"
      24             : #include "core/ActionRegister.h"
      25             : 
      26             : //+PLUMEDOC COLVAR GPATH
      27             : /*
      28             : Distance along and from a path calculated using geometric formulas
      29             : 
      30             : 
      31             : \par Examples
      32             : 
      33             : */
      34             : //+ENDPLUMEDOC
      35             : 
      36             : namespace PLMD {
      37             : namespace mapping {
      38             : 
      39             : class GeometricPathShortcut : public ActionShortcut {
      40             : public:
      41             :   static void registerKeywords(Keywords& keys);
      42             :   explicit GeometricPathShortcut(const ActionOptions&);
      43             : };
      44             : 
      45             : PLUMED_REGISTER_ACTION(GeometricPathShortcut,"GPATH")
      46             : 
      47           8 : void GeometricPathShortcut::registerKeywords( Keywords& keys ) {
      48           8 :   ActionShortcut::registerKeywords( keys );
      49           8 :   Path::registerInputFileKeywords( keys );
      50           8 :   keys.add("optional","PROPERTY","read in path coordinates by finding option with this label in remark of pdb frames");
      51          16 :   keys.addOutputComponent("s","default","scalar","the position on the path");
      52          16 :   keys.addOutputComponent("z","default","scalar","the distance from the path");
      53           8 :   keys.needsAction("DISPLACEMENT");
      54           8 :   keys.needsAction("GEOMETRIC_PATH");
      55           8 :   keys.needsAction("PDB2CONSTANT");
      56           8 :   keys.needsAction("CONSTANT");
      57           8 : }
      58             : 
      59           2 : GeometricPathShortcut::GeometricPathShortcut( const ActionOptions& ao ):
      60             :   Action(ao),
      61           2 :   ActionShortcut(ao) {
      62             :   std::string mtype, reference_data;
      63             :   std::vector<std::string> argnames;
      64           2 :   parseVector("ARG",argnames);
      65           4 :   parse("TYPE", mtype);
      66             :   // Create list of reference configurations that PLUMED will use
      67             :   std::string reference;
      68           4 :   parse("REFERENCE",reference);
      69           2 :   FILE* fp=std::fopen(reference.c_str(),"r");
      70           2 :   PDB mypdb;
      71           2 :   if(!fp) {
      72           0 :     error("could not open reference file " + reference );
      73             :   }
      74           2 :   bool do_read=mypdb.readFromFilepointer(fp,false,0.1);
      75           2 :   if( !do_read ) {
      76           0 :     error("missing file " + reference );
      77             :   }
      78           2 :   Path::readInputFrames( reference, mtype, argnames, true, this, reference_data );
      79             :   // Now get coordinates on spath
      80             :   std::vector<std::string> pnames;
      81           2 :   parseVector("PROPERTY",pnames);
      82           2 :   Path::readPropertyInformation( pnames, getShortcutLabel(), reference, this );
      83             :   // Create action that computes the geometric path variablesa
      84           2 :   std::string propstr = getShortcutLabel() + "_ind";
      85           2 :   if( pnames.size()>0 ) {
      86           0 :     propstr = pnames[0] + "_ref";
      87             :   }
      88           2 :   if( argnames.size()>0 ) {
      89           2 :     readInputLine( getShortcutLabel() + ": GEOMETRIC_PATH ARG=" + getShortcutLabel() + "_data " + " PROPERTY=" + propstr + " REFERENCE=" + reference_data + " METRIC={DIFFERENCE}");
      90             :   } else {
      91             :     std::string num, align_str, displace_str;
      92           1 :     Tools::convert( mypdb.getOccupancy()[0], align_str );
      93           1 :     Tools::convert( mypdb.getBeta()[0], displace_str );
      94          13 :     for(unsigned j=1; j<mypdb.getAtomNumbers().size(); ++j ) {
      95          12 :       Tools::convert( mypdb.getOccupancy()[j], num );
      96          12 :       align_str += "," + num;
      97          12 :       Tools::convert( mypdb.getBeta()[0], num );
      98          24 :       displace_str += "," + num;
      99             :     }
     100           2 :     std::string metric = "RMSD_VECTOR DISPLACEMENT TYPE=" + mtype + " ALIGN=" + align_str + " DISPLACE=" + displace_str;
     101           2 :     readInputLine( getShortcutLabel() + ": GEOMETRIC_PATH ARG=" + getShortcutLabel() + "_data.disp " + " PROPERTY=" +  propstr + " REFERENCE=" + reference_data + " METRIC={" + metric + "} METRIC_COMPONENT=disp");
     102             :   }
     103           6 : }
     104             : 
     105             : 
     106             : }
     107             : }
     108             : 
     109             : 

Generated by: LCOV version 1.16