Commit edbe9a74 authored by peastman's avatar peastman
Browse files

Handle hex values for atom and residue numbers

parent ba66e90e
...@@ -141,6 +141,8 @@ class PdbStructure(object): ...@@ -141,6 +141,8 @@ class PdbStructure(object):
self.sequences = [] self.sequences = []
self.modified_residues = [] self.modified_residues = []
# read file # read file
self._atom_numbers_are_hex = False
self._residue_numbers_are_hex = False
self._load(input_stream) self._load(input_stream)
def _load(self, input_stream): def _load(self, input_stream):
...@@ -148,7 +150,7 @@ class PdbStructure(object): ...@@ -148,7 +150,7 @@ class PdbStructure(object):
for pdb_line in input_stream: for pdb_line in input_stream:
# Look for atoms # Look for atoms
if (pdb_line.find("ATOM ") == 0) or (pdb_line.find("HETATM") == 0): if (pdb_line.find("ATOM ") == 0) or (pdb_line.find("HETATM") == 0):
self._add_atom(Atom(pdb_line)) self._add_atom(Atom(pdb_line, self))
# Notice MODEL punctuation, for the next level of detail # Notice MODEL punctuation, for the next level of detail
# in the structure->model->chain->residue->atom->position hierarchy # in the structure->model->chain->residue->atom->position hierarchy
elif (pdb_line.find("MODEL") == 0): elif (pdb_line.find("MODEL") == 0):
...@@ -653,7 +655,7 @@ class Residue(object): ...@@ -653,7 +655,7 @@ class Residue(object):
class Atom(object): class Atom(object):
"""Atom represents one atom in a PDB structure. """Atom represents one atom in a PDB structure.
""" """
def __init__(self, pdb_line): def __init__(self, pdb_line, pdbstructure=None):
"""Create a new pdb.Atom from an ATOM or HETATM line. """Create a new pdb.Atom from an ATOM or HETATM line.
Example line: Example line:
...@@ -691,7 +693,14 @@ class Atom(object): ...@@ -691,7 +693,14 @@ class Atom(object):
self.is_final_residue_in_chain = False self.is_final_residue_in_chain = False
# Start parsing fields from pdb line # Start parsing fields from pdb line
self.record_name = pdb_line[0:6].strip() self.record_name = pdb_line[0:6].strip()
if pdbstructure is not None and pdbstructure._atom_numbers_are_hex:
self.serial_number = int(pdb_line[6:11], 16)
else:
try:
self.serial_number = int(pdb_line[6:11]) self.serial_number = int(pdb_line[6:11])
except:
self.serial_number = int(pdb_line[6:11], 16)
pdbstructure._atom_numbers_are_hex = True
self.name_with_spaces = pdb_line[12:16] self.name_with_spaces = pdb_line[12:16]
alternate_location_indicator = pdb_line[16] alternate_location_indicator = pdb_line[16]
...@@ -707,7 +716,14 @@ class Atom(object): ...@@ -707,7 +716,14 @@ class Atom(object):
self.residue_name = self.residue_name_with_spaces.strip() self.residue_name = self.residue_name_with_spaces.strip()
self.chain_id = pdb_line[21] self.chain_id = pdb_line[21]
if pdbstructure is not None and pdbstructure._residue_numbers_are_hex:
self.residue_number = int(pdb_line[22:26], 16)
else:
try:
self.residue_number = int(pdb_line[22:26]) self.residue_number = int(pdb_line[22:26])
except:
self.residue_number = int(pdb_line[22:26], 16)
pdbstructure._residue_numbers_are_hex = True
self.insertion_code = pdb_line[26] self.insertion_code = pdb_line[26]
# coordinates, occupancy, and temperature factor belong in Atom.Location object # coordinates, occupancy, and temperature factor belong in Atom.Location object
x = float(pdb_line[30:38]) x = float(pdb_line[30:38])
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment