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
c8cbc3d5
Commit
c8cbc3d5
authored
Dec 16, 2015
by
Rafal P. Wiewiora
Browse files
add support for extraParticleIdentifier
parent
461fcdf0
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
23 additions
and
17 deletions
+23
-17
wrappers/python/simtk/openmm/app/internal/pdbstructure.py
wrappers/python/simtk/openmm/app/internal/pdbstructure.py
+12
-8
wrappers/python/simtk/openmm/app/pdbfile.py
wrappers/python/simtk/openmm/app/pdbfile.py
+11
-9
No files found.
wrappers/python/simtk/openmm/app/internal/pdbstructure.py
View file @
c8cbc3d5
...
@@ -123,7 +123,7 @@ class PdbStructure(object):
...
@@ -123,7 +123,7 @@ class PdbStructure(object):
"""
"""
def
__init__
(
self
,
input_stream
,
load_all_models
=
False
):
def
__init__
(
self
,
input_stream
,
load_all_models
=
False
,
extraParticleIdentifier
=
'EP'
):
"""Create a PDB model from a PDB file stream.
"""Create a PDB model from a PDB file stream.
Parameters
Parameters
...
@@ -138,6 +138,7 @@ class PdbStructure(object):
...
@@ -138,6 +138,7 @@ class PdbStructure(object):
"""
"""
# initialize models
# initialize models
self
.
load_all_models
=
load_all_models
self
.
load_all_models
=
load_all_models
self
.
extraParticleIdentifier
=
extraParticleIdentifier
self
.
models
=
[]
self
.
models
=
[]
self
.
_current_model
=
None
self
.
_current_model
=
None
self
.
default_model
=
None
self
.
default_model
=
None
...
@@ -157,7 +158,7 @@ class PdbStructure(object):
...
@@ -157,7 +158,7 @@ class PdbStructure(object):
pdb_line
=
pdb_line
.
decode
(
'utf-8'
)
pdb_line
=
pdb_line
.
decode
(
'utf-8'
)
# 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
,
self
,
self
.
extraParticleIdentifier
))
# 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
):
...
@@ -682,7 +683,7 @@ class Residue(object):
...
@@ -682,7 +683,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
,
pdbstructure
=
None
,
extraParticleIdentifier
=
'EP'
):
"""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:
...
@@ -795,6 +796,9 @@ class Atom(object):
...
@@ -795,6 +796,9 @@ class Atom(object):
try
:
self
.
formal_charge
=
int
(
pdb_line
[
78
:
80
])
try
:
self
.
formal_charge
=
int
(
pdb_line
[
78
:
80
])
except
ValueError
:
self
.
formal_charge
=
None
except
ValueError
:
self
.
formal_charge
=
None
# figure out atom element
# figure out atom element
if
self
.
element_symbol
==
extraParticleIdentifier
:
self
.
element
=
self
.
element_symbol
else
:
try
:
try
:
# Try to find a sensible element symbol from columns 76-77
# Try to find a sensible element symbol from columns 76-77
self
.
element
=
element
.
get_by_symbol
(
self
.
element_symbol
)
self
.
element
=
element
.
get_by_symbol
(
self
.
element_symbol
)
...
...
wrappers/python/simtk/openmm/app/pdbfile.py
View file @
c8cbc3d5
...
@@ -59,7 +59,7 @@ class PDBFile(object):
...
@@ -59,7 +59,7 @@ class PDBFile(object):
_residueNameReplacements
=
{}
_residueNameReplacements
=
{}
_atomNameReplacements
=
{}
_atomNameReplacements
=
{}
def
__init__
(
self
,
file
):
def
__init__
(
self
,
file
,
extraParticleIdentifier
=
'EP'
):
"""Load a PDB file.
"""Load a PDB file.
The atom positions and Topology can be retrieved by calling getPositions() and getTopology().
The atom positions and Topology can be retrieved by calling getPositions() and getTopology().
...
@@ -83,7 +83,7 @@ class PDBFile(object):
...
@@ -83,7 +83,7 @@ class PDBFile(object):
if
isinstance
(
file
,
str
):
if
isinstance
(
file
,
str
):
inputfile
=
open
(
file
)
inputfile
=
open
(
file
)
own_handle
=
True
own_handle
=
True
pdb
=
PdbStructure
(
inputfile
,
load_all_models
=
True
)
pdb
=
PdbStructure
(
inputfile
,
load_all_models
=
True
,
extraParticleIdentifier
=
extraParticleIdentifier
)
if
own_handle
:
if
own_handle
:
inputfile
.
close
()
inputfile
.
close
()
PDBFile
.
_loadNameReplacementTables
()
PDBFile
.
_loadNameReplacementTables
()
...
@@ -108,7 +108,9 @@ class PDBFile(object):
...
@@ -108,7 +108,9 @@ class PDBFile(object):
atomName
=
atomReplacements
[
atomName
]
atomName
=
atomReplacements
[
atomName
]
atomName
=
atomName
.
strip
()
atomName
=
atomName
.
strip
()
element
=
atom
.
element
element
=
atom
.
element
if
element
is
None
:
if
element
==
extraParticleIdentifier
:
element
=
None
elif
element
is
None
:
# Try to guess the element.
# Try to guess the element.
upper
=
atomName
.
upper
()
upper
=
atomName
.
upper
()
...
@@ -237,7 +239,7 @@ class PDBFile(object):
...
@@ -237,7 +239,7 @@ class PDBFile(object):
map
[
atom
.
attrib
[
id
]]
=
name
map
[
atom
.
attrib
[
id
]]
=
name
@
staticmethod
@
staticmethod
def
writeFile
(
topology
,
positions
,
file
=
sys
.
stdout
,
keepIds
=
False
):
def
writeFile
(
topology
,
positions
,
file
=
sys
.
stdout
,
keepIds
=
False
,
extraParticleIdentifier
=
'EP'
):
"""Write a PDB file containing a single model.
"""Write a PDB file containing a single model.
Parameters
Parameters
...
@@ -255,7 +257,7 @@ class PDBFile(object):
...
@@ -255,7 +257,7 @@ class PDBFile(object):
PDB format. Otherwise, the output file will be invalid.
PDB format. Otherwise, the output file will be invalid.
"""
"""
PDBFile
.
writeHeader
(
topology
,
file
)
PDBFile
.
writeHeader
(
topology
,
file
)
PDBFile
.
writeModel
(
topology
,
positions
,
file
,
keepIds
=
keepIds
)
PDBFile
.
writeModel
(
topology
,
positions
,
file
,
keepIds
=
keepIds
,
extraParticleIdentifier
=
extraParticleIdentifier
)
PDBFile
.
writeFooter
(
topology
,
file
)
PDBFile
.
writeFooter
(
topology
,
file
)
@
staticmethod
@
staticmethod
...
@@ -278,7 +280,7 @@ class PDBFile(object):
...
@@ -278,7 +280,7 @@ class PDBFile(object):
a
*
10
,
b
*
10
,
c
*
10
,
alpha
*
RAD_TO_DEG
,
beta
*
RAD_TO_DEG
,
gamma
*
RAD_TO_DEG
),
file
=
file
)
a
*
10
,
b
*
10
,
c
*
10
,
alpha
*
RAD_TO_DEG
,
beta
*
RAD_TO_DEG
,
gamma
*
RAD_TO_DEG
),
file
=
file
)
@
staticmethod
@
staticmethod
def
writeModel
(
topology
,
positions
,
file
=
sys
.
stdout
,
modelIndex
=
None
,
keepIds
=
False
):
def
writeModel
(
topology
,
positions
,
file
=
sys
.
stdout
,
modelIndex
=
None
,
keepIds
=
False
,
extraParticleIdentifier
=
'EP'
):
"""Write out a model to a PDB file.
"""Write out a model to a PDB file.
Parameters
Parameters
...
@@ -327,7 +329,7 @@ class PDBFile(object):
...
@@ -327,7 +329,7 @@ class PDBFile(object):
else
:
else
:
resId
=
"%4d"
%
((
resIndex
+
1
)
%
10000
)
resId
=
"%4d"
%
((
resIndex
+
1
)
%
10000
)
for
atom
in
res
.
atoms
():
for
atom
in
res
.
atoms
():
if
len
(
atom
.
name
)
<
4
and
atom
.
name
[:
1
].
isalpha
()
and
(
atom
.
element
is
None
or
len
(
atom
.
element
.
symbol
)
<
2
):
if
len
(
atom
.
name
)
<
4
and
atom
.
name
[:
1
].
isalpha
()
and
(
(
atom
.
element
is
None
and
extraParticleIdentifier
is
not
None
)
or
len
(
atom
.
element
.
symbol
)
<
2
):
atomName
=
' '
+
atom
.
name
atomName
=
' '
+
atom
.
name
elif
len
(
atom
.
name
)
>
4
:
elif
len
(
atom
.
name
)
>
4
:
atomName
=
atom
.
name
[:
4
]
atomName
=
atom
.
name
[:
4
]
...
@@ -337,7 +339,7 @@ class PDBFile(object):
...
@@ -337,7 +339,7 @@ class PDBFile(object):
if
atom
.
element
is
not
None
:
if
atom
.
element
is
not
None
:
symbol
=
atom
.
element
.
symbol
symbol
=
atom
.
element
.
symbol
else
:
else
:
symbol
=
' '
symbol
=
extraParticleIdentifier
line
=
"ATOM %5d %-4s %3s %s%4s %s%s%s 1.00 0.00 %2s "
%
(
line
=
"ATOM %5d %-4s %3s %s%4s %s%s%s 1.00 0.00 %2s "
%
(
atomIndex
%
100000
,
atomName
,
resName
,
chainName
,
resId
,
_format_83
(
coords
[
0
]),
atomIndex
%
100000
,
atomName
,
resName
,
chainName
,
resId
,
_format_83
(
coords
[
0
]),
_format_83
(
coords
[
1
]),
_format_83
(
coords
[
2
]),
symbol
)
_format_83
(
coords
[
1
]),
_format_83
(
coords
[
2
]),
symbol
)
...
...
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