"...ssh:/git@developer.sourcefind.cn:2222/tsoc/openmm.git" did not exist on "8c91abb6a17e2d0d82318e589bba4eb48c08608c"
Commit e53d4f27 authored by peastman's avatar peastman
Browse files

Simplified handling of hex values

parent edbe9a74
...@@ -141,8 +141,6 @@ class PdbStructure(object): ...@@ -141,8 +141,6 @@ 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):
...@@ -150,7 +148,7 @@ class PdbStructure(object): ...@@ -150,7 +148,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)) self._add_atom(Atom(pdb_line))
# 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):
...@@ -655,7 +653,7 @@ class Residue(object): ...@@ -655,7 +653,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, pdbstructure=None): def __init__(self, pdb_line):
"""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:
...@@ -690,17 +688,13 @@ class Atom(object): ...@@ -690,17 +688,13 @@ class Atom(object):
self.is_first_atom_in_chain = False self.is_first_atom_in_chain = False
self.is_final_atom_in_chain = False self.is_final_atom_in_chain = False
self.is_first_residue_in_chain = False self.is_first_residue_in_chain = False
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: try:
self.serial_number = int(pdb_line[6:11], 16) self.serial_number = int(pdb_line[6:11])
else: except:
try: self.serial_number = int(pdb_line[6:11], 16) # Try to parse it as hex
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]
...@@ -716,14 +710,10 @@ class Atom(object): ...@@ -716,14 +710,10 @@ 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: try:
self.residue_number = int(pdb_line[22:26], 16) self.residue_number = int(pdb_line[22:26])
else: except:
try: self.residue_number = int(pdb_line[22:26], 16) # Try to parse it as hex
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