Line data Source code
1 : /* +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
2 : Copyright (c) 2011-2019 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 :
31 :
32 : namespace PLMD {
33 :
34 : class Log;
35 :
36 : /// Minimalistic pdb parser.
37 : /// Contain positions, atomic indexes, occupancy and beta.
38 : /// We should also add other info (e.g. residue name etc).
39 9770 : class PDB {
40 : std::vector<unsigned> block_ends;
41 : std::vector<std::string> atomsymb, chain;
42 : std::vector<unsigned> residue;
43 : std::vector<Vector> positions;
44 : std::vector<double> occupancy;
45 : std::vector<double> beta;
46 : std::vector<std::string> remark;
47 : std::vector<AtomNumber> numbers;
48 : std::map<AtomNumber,unsigned> number2index;
49 : std::vector<std::string> residuenames;
50 : public:
51 : /// Read the pdb from a file, scaling positions by a factor scale
52 : bool read(const std::string&file,bool naturalUnits,double scale);
53 : /// Read from a file pointer
54 : bool readFromFilepointer(FILE *fp,bool naturalUnits,double scale);
55 : /// Access to the position array
56 : const std::vector<Vector> & getPositions()const;
57 : /// Access to the occupancy array
58 : const std::vector<double> & getOccupancy()const;
59 : /// Access to the beta array
60 : const std::vector<double> & getBeta()const;
61 : /// This is used to set the keyword ARG - this is so we
62 : /// we can use a1.* in the input for reference configurations
63 : void setArgKeyword( const std::string& new_args );
64 : /// Add information to the remark
65 : void addRemark( const std::vector<std::string>& v1 );
66 : /// Access to the lines of REMARK
67 : const std::vector<std::string> & getRemark()const;
68 : /// Access to the indexes
69 : const std::vector<AtomNumber> & getAtomNumbers()const;
70 : /// Returns the number of atoms
71 : unsigned size()const;
72 : /// Get the names of all the chains in the pdb file
73 : void getChainNames( std::vector<std::string>& chains ) const;
74 : /// Get the residues in each of the chains
75 : void getResidueRange( const std::string& chainname, unsigned& res_start, unsigned& res_end, std::string& errmsg ) const;
76 : /// Get the atoms in each of the chains
77 : void getAtomRange( const std::string& chainname, AtomNumber& a_start, AtomNumber& a_end, std::string& errmsg ) const;
78 : /// Get the chain ID that a particular residue is a part of
79 : std::string getChainID(const unsigned& resnumber) const;
80 : ///use the log to dump information
81 : friend Log& operator<<(Log& ostr, const PDB& pdb);
82 : /// return the name of a specific atom
83 : std::string getAtomName(AtomNumber a) const;
84 : /// return the residue number for a specific atom
85 : unsigned getResidueNumber(AtomNumber a) const;
86 : /// return the residue name for a specific atom
87 : std::string getResidueName(AtomNumber a) const;
88 : /// get the name of the resnum'th residue
89 : std::string getResidueName(const unsigned& resnum ) const;
90 : /// get the name of the resnum'th residue of chain
91 : /// Chain=="*" matches any chain and makes it equivalent to getResidueName
92 : std::string getResidueName(const unsigned& resnum,const std::string& chain ) const;
93 : /// Check if any of the residues are named name
94 : bool checkForResidue( const std::string& name ) const ;
95 : /// Check if any of the atoms are named atom
96 : bool checkForAtom( const std::string& name ) const ;
97 : /// Return the atom named aname from residue number resnum
98 : AtomNumber getNamedAtomFromResidue( const std::string& aname, const unsigned& resnum ) const;
99 : /// Return the atom named aname from residue number resnum and chain.
100 : /// Chain=="*" matches any chain and makes it equivalent to getNamedAtomFromResidue.
101 : AtomNumber getNamedAtomFromResidueAndChain( const std::string& aname, const unsigned& resnum, const std::string& chain ) const;
102 : /// Access to the atoms of a residue
103 : std::vector<AtomNumber> getAtomsInResidue(const unsigned& resnum,const std::string& chainid)const;
104 : /// Access to the atoms of a chain
105 : std::vector<AtomNumber> getAtomsInChain(const std::string& chainid)const;
106 : /// Get the extents of the blocks containing the atoms
107 : const std::vector<unsigned> & getAtomBlockEnds() const ;
108 : /// Get the number of blocks of atoms in the pdb
109 : unsigned getNumberOfAtomBlocks() const ;
110 : /// Set the position array
111 : void setPositions(const std::vector<Vector> &v);
112 : /// Access to the position array
113 : Vector getPosition(AtomNumber a)const;
114 : };
115 :
116 : }
117 : #endif
|