p3d.parser module

From p3d
Jump to: navigation, search

A parser was built into p3d in order to facilitate the selection of atoms of interest. All operations are done under the hood and the parser methods do not have to be accessible to the general user in order to enjoy its beauty :)

pdb.query(Query string,atom,Query-string,atom-list)

Syntax

Keywords understood by the query method can be divided into:

  • hash-keywords
chain atype or atom type resid or residue resname model
oxygen nitrogen alpha protein non-protein
non-aa-resname aa-resname bkb or backbone
  • logical operators
not and xor or minus
  • arithmetic operators
is or = or == is not or != = < <=
> >=
  • functions
within <float> of <atom(s)> first residue of chain <Chain> last residue of chain <Chain>

NOTE

  • chain identifiers are case sensitive
  • arithmetic operators work only with residue ids. They will be extended to other values in later releases.

Examples

Shown are some examples of how the keywords can be used together. The query string can include variables if they are converted to string type. It is however necessary to seperate them by commas. Additional user defined sets or lists of atoms can be included.

Selection of Amino acids

>>> atoms = pdb.query(' resname ALA ')
>>> print(len(atoms),' atoms found')
45  atoms found
>>> print(list(atoms)[0].info(lvl='max'))
       O   ALA A   36  [  39.365,  23.584,   3.063]

Selection of a range of residues

>>> atoms = pdb.query(' resname ALA and resid > 40 ')
>>> print(len(atoms),' atoms found')
30  atoms found
>>> print(list(atoms)[0].info(lvl='max'))
       C   ALA A   60  [  38.528,   5.901,  -9.218]
>>> atoms = pdb.query(' chain A and resid 13..25 and not bkb ')
>>> print(len(atoms),' atoms found')
48  atoms found
>>> print(list(atoms)[0].info(lvl='max'))
       OG1 THR A   22  [  41.445,   7.379,  16.027]
>>> atoms = pdb.query(' resname GLU and not bkb and not oxygen and resid 10 to 90 and not atype CB ')
>>> print(len(atoms),' atoms found')
18  atoms found
>>> print(list(atoms)[0].info(lvl='max'))
       CD BGLU A   85  [  48.478,  13.105, -18.349]

Selection of non protein groups

>>> atoms = pdb.query(' not protein and oxygen and not resname HOH ')
>>> print(len(atoms),' atoms found')
42  atoms found
>>> print(list(atoms)[0].info(lvl='max'))
       O1  BCT    150  [  38.872,  19.789, -14.208]

Selection of a group of residue types

>>> atoms = pdb.query(' resname ALA, GLU, TYR ')
>>> print(len(atoms),' atoms found')
210  atoms found
>>> print(list(atoms)[0].info(lvl='max'))
       CD1 TYR A   75  [  43.226,  17.012,  -4.020]
>>> atoms = pdb.query(' residue id 40,50,60 ')
>>> print(len(atoms),' atoms found')
21  atoms found
>>> print(list(atoms)[0].info(lvl='max'))
       CG  PRO A   50  [  28.272,  21.060, -10.330]
>>> atoms = pdb.query(' protein and not resname ALA, GLU, TYR ')
>>> print(len(atoms),' atoms found')
839  atoms found
>>> print(list(atoms)[0].info(lvl='max'))
       CB BGLN A   86  [  47.846,  19.918, -15.382]
>>> atoms = pdb.query(' protein ')
>>> print(len(atoms),' atoms found')
1049  atoms found
>>> print(list(atoms)[0].info(lvl='max'))
       OE1 GLU A    2  [  25.790,   1.455,  17.078]

Usage of variables in query string

>>> LowerNumber = 40
>>> atoms = pdb.query('resid <',str(LowerNumber))
>>> print(len(atoms),' atoms found')
343  atoms found
>>> print(list(atoms)[0].info(lvl='max'))
       NE2 GLN A   34  [  32.215,  24.354,   7.919]

Usage of functions

>>> distance = 3
>>> atoms = pdb.query('first residue of chain A and within',str(distance),'of oxygen')
>>> print(len(atoms),' atoms found')
2  atoms found
>>> print(list(atoms)[0].info(lvl='max'))
       CA  ALA A    1  [  25.079,   3.417,  10.138]
>>> for i in range(1,10):
>>> atoms = a.query('not protein and within ',str(i),' of oxygen')
...   print(len(atoms)," atoms found")
0  atoms found
23  atoms found
136  atoms found
183  atoms found
199  atoms found
206  atoms found
207  atoms found
207  atoms found
207  atoms found

Usage of custom atom/vector objects in query string

>>> Vector_K = p3d.vector.Vector(40, 10 , -10)
>>> for i in range(1,10):
>>> atoms = a.query('protein and within ',str(i),' of',Vector_K)
...   print(len(atoms)," atoms found")
1  atoms found
3  atoms found
6  atoms found
16  atoms found
35  atoms found
52  atoms found
72  atoms found
96  atoms found
118  atoms found
>>> CustomSet = [ p3d.vector.Vector(40, 10 , -10) , p3d.vector.Vector(48, 15, -16) , p3d.vector.Vector(51, 25,-10) ]
>>> for i in range(1,10):
>>> atoms = a.query('protein and within ',str(i),' of',CustomSet)
...   print(len(atoms)," atoms found")
3  atoms found
11  atoms found
23  atoms found
39  atoms found
85  atoms found
121  atoms found
158  atoms found
193  atoms found
234  atoms found