Commit 5719a05d authored by peastman's avatar peastman
Browse files

PdbStructure records SEQRES records

parent 30b4cf1c
...@@ -138,6 +138,7 @@ class PdbStructure(object): ...@@ -138,6 +138,7 @@ class PdbStructure(object):
self.default_model = None self.default_model = None
self.models_by_number = {} self.models_by_number = {}
self._unit_cell_dimensions = None self._unit_cell_dimensions = None
self.sequences = []
# read file # read file
self._load(input_stream) self._load(input_stream)
...@@ -172,6 +173,11 @@ class PdbStructure(object): ...@@ -172,6 +173,11 @@ class PdbStructure(object):
except: except:
pass pass
self._current_model.connects.append(atoms) self._current_model.connects.append(atoms)
elif (pdb_line.find("SEQRES") == 0):
chain_id = pdb_line[11]
if len(self.sequences) == 0 or chain_id != self.sequences[-1].chain_id:
self.sequences.append(Sequence(chain_id))
self.sequences[-1].residues.extend(pdb_line[19:].split())
self._finalize() self._finalize()
def write(self, output_stream=sys.stdout): def write(self, output_stream=sys.stdout):
...@@ -266,6 +272,13 @@ class PdbStructure(object): ...@@ -266,6 +272,13 @@ class PdbStructure(object):
return self._unit_cell_dimensions return self._unit_cell_dimensions
class Sequence(object):
"""Sequence holds the sequence of a chain, as specified by SEQRES records."""
def __init__(self, chain_id):
self.chain_id = chain_id
self.residues = []
class Model(object): class Model(object):
"""Model holds one model of a PDB structure. """Model holds one model of a PDB structure.
......
...@@ -70,10 +70,13 @@ class PDBFile(object): ...@@ -70,10 +70,13 @@ class PDBFile(object):
# Load the PDB file # Load the PDB file
inputfile = file if isinstance(file, PdbStructure):
if isinstance(file, str): pdb = file
inputfile = open(file) else:
pdb = PdbStructure(inputfile, load_all_models=True) inputfile = file
if isinstance(file, str):
inputfile = open(file)
pdb = PdbStructure(inputfile, load_all_models=True)
PDBFile._loadNameReplacementTables() PDBFile._loadNameReplacementTables()
# Build the topology # Build the topology
......
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