"platforms/vscode:/vscode.git/clone" did not exist on "1945dd6c89023cfbc17aebf16bcb996d0adca946"
Commit e53d4f27 authored by peastman's avatar peastman
Browse files

Simplified handling of hex values

parent edbe9a74
......@@ -141,8 +141,6 @@ class PdbStructure(object):
self.sequences = []
self.modified_residues = []
# read file
self._atom_numbers_are_hex = False
self._residue_numbers_are_hex = False
self._load(input_stream)
def _load(self, input_stream):
......@@ -150,7 +148,7 @@ class PdbStructure(object):
for pdb_line in input_stream:
# Look for atoms
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
# in the structure->model->chain->residue->atom->position hierarchy
elif (pdb_line.find("MODEL") == 0):
......@@ -655,7 +653,7 @@ class Residue(object):
class Atom(object):
"""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.
Example line:
......@@ -690,17 +688,13 @@ class Atom(object):
self.is_first_atom_in_chain = False
self.is_final_atom_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
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])
except:
self.serial_number = int(pdb_line[6:11], 16)
pdbstructure._atom_numbers_are_hex = True
try:
self.serial_number = int(pdb_line[6:11])
except:
self.serial_number = int(pdb_line[6:11], 16) # Try to parse it as hex
self.name_with_spaces = pdb_line[12:16]
alternate_location_indicator = pdb_line[16]
......@@ -716,14 +710,10 @@ class Atom(object):
self.residue_name = self.residue_name_with_spaces.strip()
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])
except:
self.residue_number = int(pdb_line[22:26], 16)
pdbstructure._residue_numbers_are_hex = True
try:
self.residue_number = int(pdb_line[22:26])
except:
self.residue_number = int(pdb_line[22:26], 16) # Try to parse it as hex
self.insertion_code = pdb_line[26]
# coordinates, occupancy, and temperature factor belong in Atom.Location object
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