Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
tsoc
openmm
Commits
edbe9a74
Commit
edbe9a74
authored
Oct 22, 2014
by
peastman
Browse files
Handle hex values for atom and residue numbers
parent
ba66e90e
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
21 additions
and
5 deletions
+21
-5
wrappers/python/simtk/openmm/app/internal/pdbstructure.py
wrappers/python/simtk/openmm/app/internal/pdbstructure.py
+21
-5
No files found.
wrappers/python/simtk/openmm/app/internal/pdbstructure.py
View file @
edbe9a74
...
@@ -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
])
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment