LCOV - code coverage report
Current view: top level - analysis - OutputPDBFile.cpp (source / functions) Hit Total Coverage
Test: plumed test coverage Lines: 29 30 96.7 %
Date: 2024-10-11 08:09:47 Functions: 6 8 75.0 %

          Line data    Source code
       1             : /* +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
       2             :    Copyright (c) 2015-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 "AnalysisBase.h"
      23             : #include "reference/ReferenceAtoms.h"
      24             : #include "reference/ReferenceArguments.h"
      25             : #include "core/ActionRegister.h"
      26             : #include "core/PlumedMain.h"
      27             : #include "core/ActionSet.h"
      28             : #include "core/Atoms.h"
      29             : #include "core/GenericMolInfo.h"
      30             : #include "tools/PDB.h"
      31             : 
      32             : namespace PLMD {
      33             : namespace analysis {
      34             : 
      35             : //+PLUMEDOC ANALYSIS OUTPUT_ANALYSIS_DATA_TO_PDB
      36             : /*
      37             : This can be used to output the data that has been stored in an Analysis object.
      38             : 
      39             : \par Examples
      40             : 
      41             : */
      42             : //+ENDPLUMEDOC
      43             : 
      44             : class OutputPDBFile : public AnalysisBase {
      45             : private:
      46             :   PDB mypdb;
      47             :   std::string fmt;
      48             :   std::string filename;
      49             : public:
      50             :   static void registerKeywords( Keywords& keys );
      51             :   explicit OutputPDBFile( const ActionOptions& );
      52           0 :   void performTask( const unsigned&, const unsigned&, MultiValue& ) const override { plumed_error(); }
      53             :   void performAnalysis() override;
      54             : };
      55             : 
      56       10431 : PLUMED_REGISTER_ACTION(OutputPDBFile,"OUTPUT_ANALYSIS_DATA_TO_PDB")
      57             : 
      58           7 : void OutputPDBFile::registerKeywords( Keywords& keys ) {
      59           7 :   AnalysisBase::registerKeywords( keys );
      60          14 :   keys.add("compulsory","FILE","the name of the file to output to");
      61          14 :   keys.add("optional","FMT","the format to use in the output file");
      62          14 :   keys.add("compulsory","STRIDE","0","the frequency with which to perform the required analysis and to output the data.  The default value of 0 tells plumed to use all the data");
      63           7 : }
      64             : 
      65           6 : OutputPDBFile::OutputPDBFile( const ActionOptions& ao ):
      66             :   Action(ao),
      67             :   AnalysisBase(ao),
      68           6 :   fmt("%f")
      69             : {
      70             :   // Get setup the pdb
      71           6 :   mypdb.setAtomNumbers( my_input_data->getAtomIndexes() );
      72           6 :   mypdb.setArgumentNames( my_input_data->getArgumentNames() );
      73             : 
      74             :   // Find a moldata object
      75           6 :   auto* moldat=plumed.getActionSet().selectLatest<GenericMolInfo*>(this);
      76          12 :   if( ! moldat ) warning("PDB output files do not have atom types unless you use MOLDATA");
      77             : 
      78          18 :   parse("FILE",filename); parse("FMT",fmt);
      79          12 :   if( !getRestart() ) { OFile ofile; ofile.link(*this); ofile.setBackupString("analysis"); ofile.backupAllFiles(filename); }
      80           6 :   log.printf("  printing data to file named %s \n",filename.c_str() );
      81           6 : }
      82             : 
      83           8 : void OutputPDBFile::performAnalysis() {
      84             :   // Find a moldata object
      85           8 :   auto* mymoldat=plumed.getActionSet().selectLatest<GenericMolInfo*>(this);
      86             :   // Output the embedding in plumed pdb format
      87          16 :   OFile afile; afile.link(*this); afile.setBackupString("analysis"); std::size_t psign=fmt.find("%");
      88          16 :   afile.open( filename ); std::string descr="REMARK WEIGHT=%-" + fmt.substr(psign+1) + "\n";
      89         426 :   for(unsigned j=0; j<getNumberOfDataPoints(); ++j) {
      90         418 :     afile.printf("DESCRIPTION: analysis data from calculation done by %s at time %f \n",getLabel().c_str(),getTime() );
      91         836 :     if( dissimilaritiesWereSet() ) afile.printf("REMARK %s \n", getDissimilarityInstruction().c_str() );
      92         418 :     afile.printf(descr.c_str(),getWeight(j) ); getStoredData(j,false).transferDataToPDB( mypdb );
      93         418 :     if( plumed.getAtoms().usingNaturalUnits() ) mypdb.print( 1.0, mymoldat, afile, fmt );
      94          18 :     else mypdb.print( plumed.getAtoms().getUnits().getLength()/0.1, mymoldat, afile, fmt );
      95             :   }
      96           8 :   afile.close();
      97           8 : }
      98             : 
      99             : }
     100             : }

Generated by: LCOV version 1.15