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
8316b626
Commit
8316b626
authored
Nov 05, 2019
by
peastman
Browse files
Improved determination of elements from Gromacs top files
parent
ba62a938
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
27 additions
and
13 deletions
+27
-13
wrappers/python/simtk/openmm/app/gromacstopfile.py
wrappers/python/simtk/openmm/app/gromacstopfile.py
+20
-13
wrappers/python/tests/TestGromacsTopFile.py
wrappers/python/tests/TestGromacsTopFile.py
+7
-0
No files found.
wrappers/python/simtk/openmm/app/gromacstopfile.py
View file @
8316b626
...
@@ -563,20 +563,27 @@ class GromacsTopFile(object):
...
@@ -563,20 +563,27 @@ class GromacsTopFile(object):
if
atomName
in
atomReplacements
:
if
atomName
in
atomReplacements
:
atomName
=
atomReplacements
[
atomName
]
atomName
=
atomReplacements
[
atomName
]
# Try to guess the element.
# Try to determine the element.
upper
=
atomName
.
upper
()
atomicNumber
=
self
.
_atomTypes
[
fields
[
1
]][
2
]
if
upper
.
startswith
(
'CL'
):
if
atomicNumber
is
None
:
element
=
elem
.
chlorine
# Try to guess the element from the name.
elif
upper
.
startswith
(
'NA'
):
upper
=
atomName
.
upper
()
element
=
elem
.
sodium
if
upper
.
startswith
(
'CL'
):
elif
upper
.
startswith
(
'MG'
):
element
=
elem
.
chlorine
element
=
elem
.
magnesium
elif
upper
.
startswith
(
'NA'
):
element
=
elem
.
sodium
elif
upper
.
startswith
(
'MG'
):
element
=
elem
.
magnesium
else
:
try
:
element
=
elem
.
get_by_symbol
(
atomName
[
0
])
except
KeyError
:
element
=
None
elif
atomicNumber
==
'0'
:
element
=
None
else
:
else
:
try
:
element
=
elem
.
Element
.
getByAtomicNumber
(
int
(
atomicNumber
))
element
=
elem
.
get_by_symbol
(
atomName
[
0
])
except
KeyError
:
element
=
None
atoms
.
append
(
top
.
addAtom
(
atomName
,
element
,
r
))
atoms
.
append
(
top
.
addAtom
(
atomName
,
element
,
r
))
# Add bonds to the topology
# Add bonds to the topology
...
...
wrappers/python/tests/TestGromacsTopFile.py
View file @
8316b626
...
@@ -172,6 +172,13 @@ class TestGromacsTopFile(unittest.TestCase):
...
@@ -172,6 +172,13 @@ class TestGromacsTopFile(unittest.TestCase):
top
=
GromacsTopFile
(
'systems/bnz.top'
)
top
=
GromacsTopFile
(
'systems/bnz.top'
)
gro
=
GromacsGroFile
(
'systems/bnz.gro'
)
gro
=
GromacsGroFile
(
'systems/bnz.gro'
)
for
atom
in
top
.
topology
.
atoms
():
if
atom
.
name
.
startswith
(
'C'
):
self
.
assertEqual
(
elem
.
carbon
,
atom
.
element
)
elif
atom
.
name
.
startswith
(
'H'
):
self
.
assertEqual
(
elem
.
hydrogen
,
atom
.
element
)
else
:
self
.
assertIsNone
(
atom
.
element
)
system
=
top
.
createSystem
()
system
=
top
.
createSystem
()
self
.
assertEqual
(
26
,
system
.
getNumParticles
())
self
.
assertEqual
(
26
,
system
.
getNumParticles
())
...
...
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