1 /* +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 2 Copyright (c) 2011-2021 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 #ifndef __PLUMED_tools_PDB_h 23 #define __PLUMED_tools_PDB_h 24 25 #include "AtomNumber.h" 26 #include "Vector.h" 27 #include <vector> 28 #include <string> 29 #include <map> 30 #include "Tensor.h" 31 32 33 namespace PLMD { 34 35 class GenericMolInfo; 36 class OFile; 37 class Log; 38 39 /// Minimalistic pdb parser. 40 /// Contain positions, atomic indexes, occupancy and beta. 41 /// We should also add other info (e.g. residue name etc). 42 class PDB { 43 std::vector<unsigned> block_ends; 44 std::vector<std::string> atomsymb, chain; 45 std::vector<unsigned> residue; 46 std::vector<Vector> positions; 47 std::vector<double> occupancy; 48 std::vector<double> beta; 49 std::vector<AtomNumber> numbers; 50 std::map<AtomNumber,unsigned> number2index; 51 std::vector<std::string> residuenames; 52 std::string mtype; 53 std::vector<std::string> flags; 54 std::vector<std::string> argnames; 55 std::map<std::string,double> arg_data; 56 Vector BoxXYZ,BoxABG; 57 Tensor Box; 58 public: 59 /// Read the pdb from a file, scaling positions by a factor scale 60 bool read(const std::string&file,bool naturalUnits,double scale); 61 /// Read from a file pointer 62 bool readFromFilepointer(FILE *fp,bool naturalUnits,double scale); 63 /// Access to the position array 64 const std::vector<Vector> & getPositions()const; 65 /// Access to the occupancy array 66 const std::vector<double> & getOccupancy()const; 67 /// Access to the beta array 68 const std::vector<double> & getBeta()const; 69 /// Access to the indexes 70 const std::vector<AtomNumber> & getAtomNumbers()const; 71 /// 72 std::vector<std::string> getArgumentNames()const; 73 /// Add data to argnames map 74 void addRemark( std::vector<std::string>& v1 ); 75 /// Returns the number of atoms 76 unsigned size()const; 77 /// Get the names of all the chains in the pdb file 78 void getChainNames( std::vector<std::string>& chains ) const; 79 /// Get the residues in each of the chains 80 void getResidueRange( const std::string& chainname, unsigned& res_start, unsigned& res_end, std::string& errmsg ) const; 81 /// Get the atoms in each of the chains 82 void getAtomRange( const std::string& chainname, AtomNumber& a_start, AtomNumber& a_end, std::string& errmsg ) const; 83 /// Get the chain ID that a particular residue is a part of 84 std::string getChainID(const unsigned& resnumber) const; 85 ///use the log to dump information 86 friend Log& operator<<(Log& ostr, const PDB& pdb); 87 /// return the name of a specific atom 88 std::string getAtomName(AtomNumber a) const; 89 /// return the residue number for a specific atom 90 unsigned getResidueNumber(AtomNumber a) const; 91 /// return the residue name for a specific atom 92 std::string getResidueName(AtomNumber a) const; 93 /// get the name of the resnum'th residue 94 std::string getResidueName(const unsigned& resnum ) const; 95 /// get the name of the resnum'th residue of chain 96 /// Chain=="*" matches any chain and makes it equivalent to getResidueName 97 std::string getResidueName(const unsigned& resnum,const std::string& chain ) const; 98 /// Check if any of the residues are named name 99 bool checkForResidue( const std::string& name ) const ; 100 /// Check if any of the atoms are named atom 101 bool checkForAtom( const std::string& name ) const ; 102 /// Check if specific atom exists 103 bool checkForAtom( AtomNumber a ) const ; 104 /// Return the atom named aname from residue number resnum 105 AtomNumber getNamedAtomFromResidue( const std::string& aname, const unsigned& resnum ) const; 106 /// Return the atom named aname from residue number resnum and chain. 107 /// Chain=="*" matches any chain and makes it equivalent to getNamedAtomFromResidue. 108 AtomNumber getNamedAtomFromResidueAndChain( const std::string& aname, const unsigned& resnum, const std::string& chain ) const; 109 /// Check if the properties that are required are in this pdb this is used in PLMD::mapping::Mapping 110 // bool hasRequiredProperties( const std::vector<std::string>& inproperties ); 111 /// This is used in PLMD::analysis::AnalysisWithDataCollection to add the sizes of the domains for PLMD::MultiRMSD 112 void addBlockEnd( const unsigned& end ); 113 /// This is used in PLMD::analysis::AnalysisWithDataCollection to add the numbers of the atoms 114 void setAtomNumbers( const std::vector<AtomNumber>& atoms ); 115 /// This is used in PLMD::analysis::AnalysisWithDataCollection to set the atom positions 116 void setAtomPositions( const std::vector<Vector>& pos ); 117 /// Set the argument names that you would like to use 118 void setArgumentNames( const std::vector<std::string>& argument_names ); 119 /// This is used in PLMD::analysis::AnalysisWithDataCollection to set the argument values 120 void setArgumentValue( const std::string& argname, const double& val ); 121 /// Get the value of one of the arguments in the PDB file 122 bool getArgumentValue( const std::string& name, double& value ) const ; 123 /// Access to the atoms of a residue 124 std::vector<AtomNumber> getAtomsInResidue(const unsigned& resnum,const std::string& chainid)const; 125 /// Access to the atoms of a chain 126 std::vector<AtomNumber> getAtomsInChain(const std::string& chainid)const; 127 /// Get the extents of the blocks containing the atoms 128 const std::vector<unsigned> & getAtomBlockEnds() const ; 129 /// Get the number of blocks of atoms in the pdb 130 unsigned getNumberOfAtomBlocks() const ; 131 /// Set the position array 132 void setPositions(const std::vector<Vector> &v); 133 /// Access to the position array 134 Vector getPosition(AtomNumber a)const; 135 /// Print out a PDB object 136 void print( const double& lunits, GenericMolInfo* mymoldat, OFile& ofile, const std::string& fmt ); 137 /// Does the PDB have this flag 138 bool hasFlag( const std::string& fname ) const ; 139 /// Get the metric type 140 std::string getMtype() const ; 141 /// Returns box axis lengths 142 const Vector & getBoxAxs()const; 143 /// Returns box axis angles 144 const Vector & getBoxAng()const; 145 /// Returns box axis vectors 146 const Tensor & getBoxVec()const; 147 }; 148 149 } 150 #endif 151