Line data Source code
1 : /* +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 2 : Copyright (c) 2015-2020 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/SetupMolInfo.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 18 : 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 : OutputPDBFile( const ActionOptions& ); 52 0 : void performTask( const unsigned&, const unsigned&, MultiValue& ) const { plumed_error(); } 53 : void performAnalysis(); 54 : }; 55 : 56 7368 : PLUMED_REGISTER_ACTION(OutputPDBFile,"OUTPUT_ANALYSIS_DATA_TO_PDB") 57 : 58 7 : void OutputPDBFile::registerKeywords( Keywords& keys ) { 59 7 : AnalysisBase::registerKeywords( keys ); 60 28 : keys.add("compulsory","FILE","the name of the file to output to"); 61 28 : keys.add("optional","FMT","the format to use in the output file"); 62 35 : 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 12 : std::vector<SetupMolInfo*> moldat=plumed.getActionSet().select<SetupMolInfo*>(); 76 12 : if( moldat.empty() ) 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 12 : 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 16 : std::vector<SetupMolInfo*> moldat=plumed.getActionSet().select<SetupMolInfo*>(); 86 8 : if( moldat.size()>1 ) error("you should only have one MOLINFO action in your input file"); 87 8 : SetupMolInfo* mymoldat=NULL; if( moldat.size()==1 ) mymoldat=moldat[0]; 88 : // Output the embedding in plumed pdb format 89 24 : OFile afile; afile.link(*this); afile.setBackupString("analysis"); std::size_t psign=fmt.find("%"); 90 32 : afile.open( filename.c_str() ); std::string descr="REMARK WEIGHT=%-" + fmt.substr(psign+1) + "\n"; 91 426 : for(unsigned j=0; j<getNumberOfDataPoints(); ++j) { 92 836 : afile.printf("DESCRIPTION: analysis data from calculation done by %s at time %f \n",getLabel().c_str(),getTime() ); 93 1254 : if( dissimilaritiesWereSet() ) afile.printf("REMARK %s \n", getDissimilarityInstruction().c_str() ); 94 836 : afile.printf(descr.c_str(),getWeight(j) ); getStoredData(j,false).transferDataToPDB( mypdb ); 95 818 : if( plumed.getAtoms().usingNaturalUnits() ) mypdb.print( 1.0, mymoldat, afile, fmt ); 96 36 : else mypdb.print( plumed.getAtoms().getUnits().getLength()/0.1, mymoldat, afile, fmt ); 97 : } 98 8 : afile.close(); 99 8 : } 100 : 101 : } 102 5517 : }