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
e84f0727
Commit
e84f0727
authored
Feb 17, 2015
by
peastman
Browse files
Topology records PDB ids for chains, residues, and atoms
parent
37ab709f
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
35 additions
and
15 deletions
+35
-15
wrappers/python/simtk/openmm/app/pdbfile.py
wrappers/python/simtk/openmm/app/pdbfile.py
+3
-3
wrappers/python/simtk/openmm/app/pdbxfile.py
wrappers/python/simtk/openmm/app/pdbxfile.py
+4
-3
wrappers/python/simtk/openmm/app/topology.py
wrappers/python/simtk/openmm/app/topology.py
+28
-9
No files found.
wrappers/python/simtk/openmm/app/pdbfile.py
View file @
e84f0727
...
...
@@ -88,12 +88,12 @@ class PDBFile(object):
atomByNumber
=
{}
for
chain
in
pdb
.
iter_chains
():
c
=
top
.
addChain
()
c
=
top
.
addChain
(
chain
.
chain_id
)
for
residue
in
chain
.
iter_residues
():
resName
=
residue
.
get_name
()
if
resName
in
PDBFile
.
_residueNameReplacements
:
resName
=
PDBFile
.
_residueNameReplacements
[
resName
]
r
=
top
.
addResidue
(
resName
,
c
)
r
=
top
.
addResidue
(
resName
,
c
,
str
(
residue
.
number
)
)
if
resName
in
PDBFile
.
_atomNameReplacements
:
atomReplacements
=
PDBFile
.
_atomNameReplacements
[
resName
]
else
:
...
...
@@ -129,7 +129,7 @@ class PDBFile(object):
element
=
elem
.
get_by_symbol
(
atomName
[
0
])
except
KeyError
:
pass
newAtom
=
top
.
addAtom
(
atomName
,
element
,
r
)
newAtom
=
top
.
addAtom
(
atomName
,
element
,
r
,
str
(
atom
.
serial_number
)
)
atomByNumber
[
atom
.
serial_number
]
=
newAtom
self
.
_positions
=
[]
for
model
in
pdb
.
iter_models
(
True
):
...
...
wrappers/python/simtk/openmm/app/pdbxfile.py
View file @
e84f0727
...
...
@@ -78,6 +78,7 @@ class PDBxFile(object):
atomIdCol
=
atomData
.
getAttributeIndex
(
'id'
)
resNameCol
=
atomData
.
getAttributeIndex
(
'label_comp_id'
)
resIdCol
=
atomData
.
getAttributeIndex
(
'label_seq_id'
)
resNumCol
=
atomData
.
getAttributeIndex
(
'auth_seq_id'
)
asymIdCol
=
atomData
.
getAttributeIndex
(
'label_asym_id'
)
chainIdCol
=
atomData
.
getAttributeIndex
(
'label_entity_id'
)
elementCol
=
atomData
.
getAttributeIndex
(
'type_symbol'
)
...
...
@@ -107,13 +108,13 @@ class PDBxFile(object):
if
lastChainId
!=
row
[
chainIdCol
]:
# The start of a new chain.
chain
=
top
.
addChain
()
chain
=
top
.
addChain
(
row
[
chainIdCol
]
)
lastChainId
=
row
[
chainIdCol
]
lastResId
=
None
lastAsymId
=
None
if
lastResId
!=
row
[
resIdCol
]
or
lastAsymId
!=
row
[
asymIdCol
]:
# The start of a new residue.
res
=
top
.
addResidue
(
row
[
resNameCol
],
chain
)
res
=
top
.
addResidue
(
row
[
resNameCol
],
chain
,
None
if
resNumCol
==
-
1
else
row
[
resNumCol
]
)
lastResId
=
row
[
resIdCol
]
if
lastResId
==
'.'
:
lastResId
=
None
...
...
@@ -123,7 +124,7 @@ class PDBxFile(object):
element
=
elem
.
get_by_symbol
(
row
[
elementCol
])
except
KeyError
:
pass
atom
=
top
.
addAtom
(
row
[
atomNameCol
],
element
,
res
)
atom
=
top
.
addAtom
(
row
[
atomNameCol
],
element
,
res
,
row
[
atomIdCol
]
)
atomTable
[
atomKey
]
=
atom
else
:
# This row defines coordinates for an existing atom in one of the later models.
...
...
wrappers/python/simtk/openmm/app/topology.py
View file @
e84f0727
...
...
@@ -59,38 +59,51 @@ class Topology(object):
self
.
_bonds
=
[]
self
.
_periodicBoxVectors
=
None
def
addChain
(
self
):
def
addChain
(
self
,
id
=
None
):
"""Create a new Chain and add it to the Topology.
Parameters:
- id (string=None) An optional identifier for the chain. If this is omitted, an id
is generated based on the chain index.
Returns: the newly created Chain
"""
chain
=
Chain
(
len
(
self
.
_chains
),
self
)
if
id
is
None
:
id
=
str
(
len
(
self
.
_chains
)
+
1
)
chain
=
Chain
(
len
(
self
.
_chains
),
self
,
id
)
self
.
_chains
.
append
(
chain
)
return
chain
def
addResidue
(
self
,
name
,
chain
):
def
addResidue
(
self
,
name
,
chain
,
id
=
None
):
"""Create a new Residue and add it to the Topology.
Parameters:
- name (string) The name of the residue to add
- chain (Chain) The Chain to add it to
- id (string=None) An optional identifier for the residue. If this is omitted, an id
is generated based on the residue index.
Returns: the newly created Residue
"""
residue
=
Residue
(
name
,
self
.
_numResidues
,
chain
)
if
id
is
None
:
id
=
str
(
self
.
_numResidues
+
1
)
residue
=
Residue
(
name
,
self
.
_numResidues
,
chain
,
id
)
self
.
_numResidues
+=
1
chain
.
_residues
.
append
(
residue
)
return
residue
def
addAtom
(
self
,
name
,
element
,
residue
):
def
addAtom
(
self
,
name
,
element
,
residue
,
id
=
None
):
"""Create a new Atom and add it to the Topology.
Parameters:
- name (string) The name of the atom to add
- element (Element) The element of the atom to add
- residue (Residue) The Residue to add it to
- id (string=None) An optional identifier for the atom. If this is omitted, an id
is generated based on the atom index.
Returns: the newly created Atom
"""
atom
=
Atom
(
name
,
element
,
self
.
_numAtoms
,
residue
)
if
id
is
None
:
id
=
str
(
self
.
_numAtoms
+
1
)
atom
=
Atom
(
name
,
element
,
self
.
_numAtoms
,
residue
,
id
)
self
.
_numAtoms
+=
1
residue
.
_atoms
.
append
(
atom
)
return
atom
...
...
@@ -258,12 +271,14 @@ class Topology(object):
class
Chain
(
object
):
"""A Chain object represents a chain within a Topology."""
def
__init__
(
self
,
index
,
topology
):
def
__init__
(
self
,
index
,
topology
,
id
):
"""Construct a new Chain. You should call addChain() on the Topology instead of calling this directly."""
## The index of the Chain within its Topology
self
.
index
=
index
## The Topology this Chain belongs to
self
.
topology
=
topology
## A user defined identifier for this Chain
self
.
id
=
id
self
.
_residues
=
[]
def
residues
(
self
):
...
...
@@ -278,7 +293,7 @@ class Chain(object):
class
Residue
(
object
):
"""A Residue object represents a residue within a Topology."""
def
__init__
(
self
,
name
,
index
,
chain
):
def
__init__
(
self
,
name
,
index
,
chain
,
id
):
"""Construct a new Residue. You should call addResidue() on the Topology instead of calling this directly."""
## The name of the Residue
self
.
name
=
name
...
...
@@ -286,6 +301,8 @@ class Residue(object):
self
.
index
=
index
## The Chain this Residue belongs to
self
.
chain
=
chain
## A user defined identifier for this Residue
self
.
id
=
id
self
.
_atoms
=
[]
def
atoms
(
self
):
...
...
@@ -295,7 +312,7 @@ class Residue(object):
class
Atom
(
object
):
"""An Atom object represents a residue within a Topology."""
def
__init__
(
self
,
name
,
element
,
index
,
residue
):
def
__init__
(
self
,
name
,
element
,
index
,
residue
,
id
):
"""Construct a new Atom. You should call addAtom() on the Topology instead of calling this directly."""
## The name of the Atom
self
.
name
=
name
...
...
@@ -305,4 +322,6 @@ class Atom(object):
self
.
index
=
index
## The Residue this Atom belongs to
self
.
residue
=
residue
## A user defined identifier for this Atom
self
.
id
=
id
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