Xmipp  v3.23.11-Nereus
pdb.h
Go to the documentation of this file.
1 /***************************************************************************
2  *
3  * Authors: Carlos Oscar Sanchez Sorzano (coss@cnb.csic.es)
4  *
5  * Unidad de Bioinformatica of Centro Nacional de Biotecnologia , CSIC
6  *
7  * This program is free software; you can redistribute it and/or modify
8  * it under the terms of the GNU General Public License as published by
9  * the Free Software Foundation; either version 2 of the License, or
10  * (at your option) any later version.
11  *
12  * This program is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15  * GNU General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License
18  * along with this program; if not, write to the Free Software
19  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
20  * 02111-1307 USA
21  *
22  * All comments concerning this program package may be sent to the
23  * e-mail address 'xmipp@cnb.csic.es'
24  ***************************************************************************/
25 /*****************************************************************************/
26 /* INTERACTION WITH PDBs */
27 /*****************************************************************************/
28 
29 #ifndef _XMIPP_PDB_HH
30 #define _XMIPP_PDB_HH
31 
32 #include <vector>
33 #include "cif++.hpp"
34 #include "core/xmipp_error.h"
35 
36 template<typename T>
37 class Matrix1D;
38 template<typename T>
39 class Matrix2D;
40 template<typename T>
41 class MultidimArray;
42 class FileName;
43 class Projection;
44 class Histogram1D;
45 
52 int atomCharge(const std::string &atom);
53 
60 double atomRadius(const std::string &atom);
61 
67 double atomCovalentRadius(const std::string &atom);
68 
74 void computePDBgeometry(const std::string &fnPDB,
76  Matrix1D<double> &limit0, Matrix1D<double> &limitF,
77  const std::string &intensityColumn);
78 
84 void applyGeometryToPDBFile(const std::string &fn_in, const std::string &fn_out,
85  const Matrix2D<double> &A, bool centerPDB=true,
86  const std::string &intensityColumn="occupancy");
87 
91 struct pdbInfo
92 {
93  std::vector<double> x;
94  std::vector<double> y;
95  std::vector<double> z;
96  std::vector<double> b;
97  std::vector<std::string> chain;
98  std::vector<int> residue;
99  std::vector<double> atomCovRad;
100 };
101 
106 void analyzePDBAtoms(const FileName &fn_pdb, const std::string &typeOfAtom, int &numberOfAtoms, pdbInfo &at_pos);
107 
108 
110 class Atom
111 {
112 public:
114  char atomType;
115 
117  double x;
118 
120  double y;
121 
123  double z;
124 };
125 
128 {
129 public:
131  std::vector<Atom> atomList;
132 
133  // Whole data block
134  cif::datablock dataBlock;
135 
137  void addAtom(const Atom &atom)
138  {
139  atomList.push_back(atom);
140  }
141 
143  const Atom& getAtom(int i) const
144  {
145  return atomList[i];
146  }
147 
149  size_t getNumberOfAtoms() const
150  {
151  return atomList.size();
152  }
153 
161  void read(const FileName &fnPDB);
162 
164  void shift(double x, double y, double z);
165 
170  void produceSideInfo();
171 };
172 
174 class RichAtom
175 {
176 public:
178  std::string record;
179 
181  int serial;
182 
184  double x;
185 
187  double y;
188 
190  double z;
191 
193  std::string name;
194 
196  std::string altloc;
197 
199  std::string resname;
200 
202  char chainid;
203 
205  int resseq;
206 
208  std::string icode;
209 
211  double occupancy;
212 
214  double bfactor;
215 
217  std::string atomType;
218 
220  std::string charge;
221 
222  /* PDB Specific values */
224  std::string segment;
225 
226  /* CIF Specific values */
227  // Alternative id
228  std::string altId;
229 
230  // Sequence id
231  int seqId;
232 
233  // Author sequence id
235 
236  // Author chain name
237  std::string authCompId;
238 
239  // Author chain location
240  std::string authAsymId;
241 
242  // Author atom name
243  std::string authAtomId;
244 
245  // PDB model number
246  int pdbNum;
247 };
248 
251 {
252 public:
254  std::vector<std::string> remarks;
255 
257  std::vector<RichAtom> atomList;
258  std::vector<double> intensities;
259 
260  // Whole data block
261  cif::datablock dataBlock;
262 
264  void addAtom(const RichAtom &atom)
265  {
266  atomList.push_back(atom);
267  }
268 
270  size_t getNumberOfAtoms() const
271  {
272  return atomList.size();
273  }
274 
285  void read(const FileName &fnPDB, const bool pseudoatoms = false, const double threshold = 0.0);
286 
297  void write(const FileName &fnPDB, const bool renumber = false);
298 
299 };
300 
311 void atomDescriptors(const std::string &atom, Matrix1D<double> &descriptors);
312 
316 double electronFormFactorFourier(double f,
317  const Matrix1D<double> &descriptors);
318 
323 double electronFormFactorRealSpace(double r,
324  const Matrix1D<double> &descriptors);
325 
331 void atomRadialProfile(int M, double T, const std::string &atom,
332  Matrix1D<double> &profile);
333 
337 void atomProjectionRadialProfile(int M,
338  const Matrix1D<double> &profileCoefficients,
339  Matrix1D<double> &projectionProfile);
340 
343 {
344 public:
345  // Vector of radial volume profiles
346  std::vector< MultidimArray<double> > volumeProfileCoefficients;
347  // Vector of radial projection profiles
348  std::vector< MultidimArray<double> > projectionProfileCoefficients;
349  // Vector of atom radii
350  std::vector<double> radii;
351  // Downsampling factor
352  int M;
353  // Fine sampling rate
354  double highTs;
355 
359  void setup(int m, double hights, bool computeProjection=false);
360 
362  void addAtom(const std::string &atomType, bool computeProjection=false);
363 
365  int getAtomIndex(char atom) const
366  {
367  int idx=-1;
368  switch (atom)
369  {
370  case 'H':
371  idx=0;
372  break;
373  case 'C':
374  idx=1;
375  break;
376  case 'N':
377  idx=2;
378  break;
379  case 'O':
380  idx=3;
381  break;
382  case 'P':
383  idx=4;
384  break;
385  case 'S':
386  idx=5;
387  break;
388  case 'E': // Iron Fe
389  idx=6;
390  break;
391  case 'K':
392  idx=7;
393  break;
394  case 'F':
395  idx=8;
396  break;
397  case 'G': // Magnesium Mg
398  idx=9;
399  break;
400  case 'L': // Chlorine Cl
401  idx=10;
402  break;
403  case 'A': // Calcium Ca
404  idx=11;
405  break;
406  default:
407  REPORT_ERROR(ERR_VALUE_INCORRECT,(std::string)
408  "AtomInterpolator::getAtomIndex: Atom "+atom+" unknown");
409  }
410  return idx;
411  }
412 
414  double atomRadius(char atom) const
415  {
416  return radii[getAtomIndex(atom)];
417  }
418 
421  double volumeAtDistance(char atom, double r) const;
422 
425  double projectionAtDistance(char atom, double r) const;
426 };
427 
430 void projectPDB(const PDBPhantom &phantomPDB,
431  const AtomInterpolator &interpolator, Projection &proj,
432  int Ydim, int Xdim, double rot, double tilt, double psi);
433 
438 void distanceHistogramPDB(const PDBPhantom &phantomPDB, size_t Nnearest, double maxDistance, int Nbins, Histogram1D &hist);
440 #endif
441 
442 const char*
443 hy36encode(unsigned width, int value, char* result);
444 
445 const char*
446 hy36decode(unsigned width, const char* s, unsigned s_size, int* result);
447 
448 void
449 hy36encodeSafe(unsigned width, int value, char* result);
450 
451 void
452 hy36decodeSafe(unsigned width, const char* s, unsigned s_size, int* result);
double z
Position Z.
Definition: pdb.h:123
void atomProjectionRadialProfile(int M, const Matrix1D< double > &profileCoefficients, Matrix1D< double > &projectionProfile)
double electronFormFactorRealSpace(double r, const Matrix1D< double > &descriptors)
Definition: pdb.cpp:1087
void applyGeometryToPDBFile(const std::string &fn_in, const std::string &fn_out, const Matrix2D< double > &A, bool centerPDB=true, const std::string &intensityColumn="occupancy")
Definition: pdb.cpp:294
std::vector< MultidimArray< double > > projectionProfileCoefficients
Definition: pdb.h:348
void projectPDB(const PDBPhantom &phantomPDB, const AtomInterpolator &interpolator, Projection &proj, int Ydim, int Xdim, double rot, double tilt, double psi)
Definition: pdb.cpp:1603
std::string segment
segment name
Definition: pdb.h:224
void atomRadialProfile(int M, double T, const std::string &atom, Matrix1D< double > &profile)
void write(std::ostream &os, const datablock &db)
Definition: cif2pdb.cpp:3747
#define REPORT_ERROR(nerr, ErrormMsg)
Definition: xmipp_error.h:211
std::vector< double > z
Definition: pdb.h:95
int seqId
Definition: pdb.h:231
std::string charge
2-char charge with sign 2nd (e.g. 1- or 2+)
Definition: pdb.h:220
std::string record
Record Type ("ATOM " or "HETATM")
Definition: pdb.h:178
std::vector< double > intensities
Definition: pdb.h:258
char chainid
ChainId.
Definition: pdb.h:202
int serial
atom serial number
Definition: pdb.h:181
Definition: pdb.h:91
double x
Position X.
Definition: pdb.h:117
std::vector< std::string > chain
Definition: pdb.h:97
void addAtom(const Atom &atom)
Add Atom.
Definition: pdb.h:137
Definition: pdb.h:174
char atomType
Type.
Definition: pdb.h:114
std::string resname
Residue name.
Definition: pdb.h:199
std::string authCompId
Definition: pdb.h:237
std::string atomType
atom element type
Definition: pdb.h:217
#define i
int atomCharge(const std::string &atom)
Definition: pdb.cpp:122
void centerOfMass(Matrix1D< double > &center, void *mask=NULL, size_t n=0)
void threshold(double *phi, unsigned long nvox, double limit)
Definition: lib_vwk.cpp:524
const char * hy36encode(unsigned width, int value, char *result)
Definition: pdb.cpp:1824
int resseq
Residue sequence.
Definition: pdb.h:205
Definition: mask.h:36
const Atom & getAtom(int i) const
Get Atom at position i.
Definition: pdb.h:143
double y
Position Y.
Definition: pdb.h:187
size_t getNumberOfAtoms() const
Get number of atoms.
Definition: pdb.h:149
void distanceHistogramPDB(const PDBPhantom &phantomPDB, size_t Nnearest, double maxDistance, int Nbins, Histogram1D &hist)
Definition: pdb.cpp:1627
std::vector< double > x
Definition: pdb.h:93
double * f
double occupancy
Occupancy.
Definition: pdb.h:211
std::string altId
Definition: pdb.h:228
int pdbNum
Definition: pdb.h:246
void computePDBgeometry(const std::string &fnPDB, Matrix1D< double > &centerOfMass, Matrix1D< double > &limit0, Matrix1D< double > &limitF, const std::string &intensityColumn)
Definition: pdb.cpp:238
const char * hy36decode(unsigned width, const char *s, unsigned s_size, int *result)
Definition: pdb.cpp:1892
double bfactor
Bfactor.
Definition: pdb.h:214
std::vector< MultidimArray< double > > volumeProfileCoefficients
Definition: pdb.h:346
std::vector< double > b
Definition: pdb.h:96
int getAtomIndex(char atom) const
Get atom index.
Definition: pdb.h:365
std::vector< double > y
Definition: pdb.h:94
double electronFormFactorFourier(double f, const Matrix1D< double > &descriptors)
Definition: pdb.cpp:1059
void atomDescriptors(const std::string &atom, Matrix1D< double > &descriptors)
Definition: pdb.cpp:883
double x
Position X.
Definition: pdb.h:184
std::vector< int > residue
Definition: pdb.h:98
Definition: pdb.h:110
cif::datablock dataBlock
Definition: pdb.h:134
std::string authAsymId
Definition: pdb.h:240
int m
int authSeqId
Definition: pdb.h:234
std::vector< RichAtom > atomList
List of atoms.
Definition: pdb.h:257
double atomRadius(const std::string &atom)
Definition: pdb.cpp:168
std::string name
Name.
Definition: pdb.h:193
std::vector< std::string > remarks
List of remarks.
Definition: pdb.h:254
size_t getNumberOfAtoms() const
Get number of atoms.
Definition: pdb.h:270
Definition: ctf.h:38
double y
Position Y.
Definition: pdb.h:120
double psi(const double x)
std::vector< Atom > atomList
List of atoms.
Definition: pdb.h:131
void analyzePDBAtoms(const FileName &fn_pdb, const std::string &typeOfAtom, int &numberOfAtoms, pdbInfo &at_pos)
Definition: pdb.cpp:64
void hy36encodeSafe(unsigned width, int value, char *result)
Definition: pdb.cpp:1977
double highTs
Definition: pdb.h:354
double atomRadius(char atom) const
Definition: pdb.h:414
std::vector< double > radii
Definition: pdb.h:350
std::vector< double > atomCovRad
Definition: pdb.h:99
double atomCovalentRadius(const std::string &atom)
Definition: pdb.cpp:214
void addAtom(const RichAtom &atom)
Add Atom.
Definition: pdb.h:264
file read(std::istream &is)
Definition: pdb2cif.cpp:6200
std::string icode
Icode.
Definition: pdb.h:208
Incorrect value received.
Definition: xmipp_error.h:195
std::string authAtomId
Definition: pdb.h:243
void hy36decodeSafe(unsigned width, const char *s, unsigned s_size, int *result)
Definition: pdb.cpp:1968
double z
Position Z.
Definition: pdb.h:190
std::string altloc
Alternate location.
Definition: pdb.h:196
cif::datablock dataBlock
Definition: pdb.h:261