Advertisement
Guest User

Untitled

a guest
Apr 25th, 2018
99
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.09 KB | None | 0 0
  1. #! /usr/bin/env python
  2. import collections
  3. import sys
  4.  
  5. Atom = collections.namedtuple('Atom', ['x', 'y', 'z'])
  6. Residue = collections.namedtuple('Residue', ['index', 'name', 'atoms'])
  7.  
  8. with open(sys.argv[1]) as pdbfile:
  9.     residues = dict()
  10.  
  11.     interesting = {
  12.         'A': ('N1', 'N6'),
  13.         'C': ('N3', 'O2', 'N4'),
  14.         'G': ('N1', 'N2', 'O6'),
  15.         'U': ('N3', 'O2')
  16.     }
  17.  
  18.     for line in pdbfile.readlines():
  19.         if line.startswith('ATOM') or line.startswith('HETATM'):
  20.             name = line[12:16].strip()
  21.             resname = line[17:20].strip()
  22.  
  23.             if not resname in interesting or not name in interesting[resname]:
  24.                 continue
  25.  
  26.             x = float(line[30:38].strip())
  27.             y = float(line[38:46].strip())
  28.             z = float(line[46:54].strip())
  29.             atom = Atom(x, y, z)
  30.  
  31.             index = int(line[22:26].strip())
  32.             if not index in residues:
  33.                 residues[index] = Residue(index, resname, dict())
  34.  
  35.             atoms = residues[index].atoms
  36.             atoms[name] = atom
  37.  
  38.     print(residues)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement