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
f6e6b6ed
Unverified
Commit
f6e6b6ed
authored
Nov 30, 2023
by
Peter Eastman
Committed by
GitHub
Nov 30, 2023
Browse files
Optimizations to reporters (#4330)
* Optimizations to reporters * Removed unneeded imports
parent
127a3733
Changes
7
Show whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
18 additions
and
16 deletions
+18
-16
wrappers/python/openmm/app/dcdfile.py
wrappers/python/openmm/app/dcdfile.py
+3
-2
wrappers/python/openmm/app/dcdreporter.py
wrappers/python/openmm/app/dcdreporter.py
+1
-1
wrappers/python/openmm/app/pdbfile.py
wrappers/python/openmm/app/pdbfile.py
+3
-2
wrappers/python/openmm/app/pdbreporter.py
wrappers/python/openmm/app/pdbreporter.py
+4
-4
wrappers/python/openmm/app/pdbxfile.py
wrappers/python/openmm/app/pdbxfile.py
+3
-2
wrappers/python/openmm/app/xtcfile.py
wrappers/python/openmm/app/xtcfile.py
+3
-4
wrappers/python/openmm/app/xtcreporter.py
wrappers/python/openmm/app/xtcreporter.py
+1
-1
No files found.
wrappers/python/openmm/app/dcdfile.py
View file @
f6e6b6ed
...
@@ -121,9 +121,10 @@ class DCDFile(object):
...
@@ -121,9 +121,10 @@ class DCDFile(object):
raise
ValueError
(
'The number of positions must match the number of atoms'
)
raise
ValueError
(
'The number of positions must match the number of atoms'
)
if
is_quantity
(
positions
):
if
is_quantity
(
positions
):
positions
=
positions
.
value_in_unit
(
nanometers
)
positions
=
positions
.
value_in_unit
(
nanometers
)
if
any
(
math
.
isnan
(
norm
(
pos
))
for
pos
in
positions
):
import
numpy
as
np
if
np
.
isnan
(
positions
).
any
():
raise
ValueError
(
'Particle position is NaN. For more information, see https://github.com/openmm/openmm/wiki/Frequently-Asked-Questions#nan'
)
raise
ValueError
(
'Particle position is NaN. For more information, see https://github.com/openmm/openmm/wiki/Frequently-Asked-Questions#nan'
)
if
any
(
math
.
isinf
(
norm
(
pos
))
for
pos
in
positions
):
if
np
.
isinf
(
positions
)
.
any
()
:
raise
ValueError
(
'Particle position is infinite. For more information, see https://github.com/openmm/openmm/wiki/Frequently-Asked-Questions#nan'
)
raise
ValueError
(
'Particle position is infinite. For more information, see https://github.com/openmm/openmm/wiki/Frequently-Asked-Questions#nan'
)
file
=
self
.
_file
file
=
self
.
_file
...
...
wrappers/python/openmm/app/dcdreporter.py
View file @
f6e6b6ed
...
@@ -104,7 +104,7 @@ class DCDReporter(object):
...
@@ -104,7 +104,7 @@ class DCDReporter(object):
self
.
_out
,
simulation
.
topology
,
simulation
.
integrator
.
getStepSize
(),
self
.
_out
,
simulation
.
topology
,
simulation
.
integrator
.
getStepSize
(),
simulation
.
currentStep
,
self
.
_reportInterval
,
self
.
_append
simulation
.
currentStep
,
self
.
_reportInterval
,
self
.
_append
)
)
self
.
_dcd
.
writeModel
(
state
.
getPositions
(),
periodicBoxVectors
=
state
.
getPeriodicBoxVectors
())
self
.
_dcd
.
writeModel
(
state
.
getPositions
(
asNumpy
=
True
),
periodicBoxVectors
=
state
.
getPeriodicBoxVectors
())
def
__del__
(
self
):
def
__del__
(
self
):
self
.
_out
.
close
()
self
.
_out
.
close
()
wrappers/python/openmm/app/pdbfile.py
View file @
f6e6b6ed
...
@@ -343,9 +343,10 @@ class PDBFile(object):
...
@@ -343,9 +343,10 @@ class PDBFile(object):
raise
ValueError
(
'The number of positions must match the number of atoms'
)
raise
ValueError
(
'The number of positions must match the number of atoms'
)
if
is_quantity
(
positions
):
if
is_quantity
(
positions
):
positions
=
positions
.
value_in_unit
(
angstroms
)
positions
=
positions
.
value_in_unit
(
angstroms
)
if
any
(
math
.
isnan
(
norm
(
pos
))
for
pos
in
positions
):
import
numpy
as
np
if
np
.
isnan
(
positions
).
any
():
raise
ValueError
(
'Particle position is NaN. For more information, see https://github.com/openmm/openmm/wiki/Frequently-Asked-Questions#nan'
)
raise
ValueError
(
'Particle position is NaN. For more information, see https://github.com/openmm/openmm/wiki/Frequently-Asked-Questions#nan'
)
if
any
(
math
.
isinf
(
norm
(
pos
))
for
pos
in
positions
):
if
np
.
isinf
(
positions
)
.
any
()
:
raise
ValueError
(
'Particle position is infinite. For more information, see https://github.com/openmm/openmm/wiki/Frequently-Asked-Questions#nan'
)
raise
ValueError
(
'Particle position is infinite. For more information, see https://github.com/openmm/openmm/wiki/Frequently-Asked-Questions#nan'
)
nonHeterogens
=
PDBFile
.
_standardResidues
[:]
nonHeterogens
=
PDBFile
.
_standardResidues
[:]
nonHeterogens
.
remove
(
'HOH'
)
nonHeterogens
.
remove
(
'HOH'
)
...
...
wrappers/python/openmm/app/pdbreporter.py
View file @
f6e6b6ed
...
@@ -104,12 +104,12 @@ class PDBReporter(object):
...
@@ -104,12 +104,12 @@ class PDBReporter(object):
topology
=
self
.
_subsetTopology
topology
=
self
.
_subsetTopology
#PDBFile will convert to angstroms so do it here first instead
#PDBFile will convert to angstroms so do it here first instead
positions
=
state
.
getPositions
().
value_in_unit
(
angstroms
)
positions
=
state
.
getPositions
(
asNumpy
=
True
).
value_in_unit
(
angstroms
)
positions
=
[
positions
[
i
]
for
i
in
self
.
_atomSubset
]
positions
=
[
positions
[
i
]
for
i
in
self
.
_atomSubset
]
else
:
else
:
topology
=
simulation
.
topology
topology
=
simulation
.
topology
positions
=
state
.
getPositions
()
positions
=
state
.
getPositions
(
asNumpy
=
True
)
if
self
.
_nextModel
==
0
:
if
self
.
_nextModel
==
0
:
PDBFile
.
writeHeader
(
topology
,
self
.
_out
)
PDBFile
.
writeHeader
(
topology
,
self
.
_out
)
...
@@ -202,12 +202,12 @@ class PDBxReporter(PDBReporter):
...
@@ -202,12 +202,12 @@ class PDBxReporter(PDBReporter):
topology
=
self
.
_subsetTopology
topology
=
self
.
_subsetTopology
#PDBFile will convert to angstroms so do it here first instead
#PDBFile will convert to angstroms so do it here first instead
positions
=
state
.
getPositions
().
value_in_unit
(
angstroms
)
positions
=
state
.
getPositions
(
asNumpy
=
True
).
value_in_unit
(
angstroms
)
positions
=
[
positions
[
i
]
for
i
in
self
.
_atomSubset
]
positions
=
[
positions
[
i
]
for
i
in
self
.
_atomSubset
]
else
:
else
:
topology
=
simulation
.
topology
topology
=
simulation
.
topology
positions
=
state
.
getPositions
()
positions
=
state
.
getPositions
(
asNumpy
=
True
)
if
self
.
_nextModel
==
0
:
if
self
.
_nextModel
==
0
:
PDBxFile
.
writeHeader
(
topology
,
self
.
_out
)
PDBxFile
.
writeHeader
(
topology
,
self
.
_out
)
...
...
wrappers/python/openmm/app/pdbxfile.py
View file @
f6e6b6ed
...
@@ -418,9 +418,10 @@ class PDBxFile(object):
...
@@ -418,9 +418,10 @@ class PDBxFile(object):
raise
ValueError
(
'The number of positions must match the number of atoms'
)
raise
ValueError
(
'The number of positions must match the number of atoms'
)
if
is_quantity
(
positions
):
if
is_quantity
(
positions
):
positions
=
positions
.
value_in_unit
(
angstroms
)
positions
=
positions
.
value_in_unit
(
angstroms
)
if
any
(
math
.
isnan
(
norm
(
pos
))
for
pos
in
positions
):
import
numpy
as
np
if
np
.
isnan
(
positions
).
any
():
raise
ValueError
(
'Particle position is NaN. For more information, see https://github.com/openmm/openmm/wiki/Frequently-Asked-Questions#nan'
)
raise
ValueError
(
'Particle position is NaN. For more information, see https://github.com/openmm/openmm/wiki/Frequently-Asked-Questions#nan'
)
if
any
(
math
.
isinf
(
norm
(
pos
))
for
pos
in
positions
):
if
np
.
isinf
(
positions
)
.
any
()
:
raise
ValueError
(
'Particle position is infinite. For more information, see https://github.com/openmm/openmm/wiki/Frequently-Asked-Questions#nan'
)
raise
ValueError
(
'Particle position is infinite. For more information, see https://github.com/openmm/openmm/wiki/Frequently-Asked-Questions#nan'
)
nonHeterogens
=
PDBFile
.
_standardResidues
[:]
nonHeterogens
=
PDBFile
.
_standardResidues
[:]
nonHeterogens
.
remove
(
'HOH'
)
nonHeterogens
.
remove
(
'HOH'
)
...
...
wrappers/python/openmm/app/xtcfile.py
View file @
f6e6b6ed
...
@@ -9,11 +9,9 @@ from openmm.app.internal.xtc_utils import (
...
@@ -9,11 +9,9 @@ from openmm.app.internal.xtc_utils import (
get_xtc_nframes
,
get_xtc_nframes
,
get_xtc_natoms
,
get_xtc_natoms
,
)
)
import
numpy
as
np
import
os
import
os
from
openmm
import
Vec3
from
openmm
import
Vec3
from
openmm.unit
import
nanometers
,
picoseconds
,
is_quantity
,
norm
from
openmm.unit
import
nanometers
,
picoseconds
,
is_quantity
,
norm
import
math
import
tempfile
import
tempfile
import
shutil
import
shutil
...
@@ -92,11 +90,12 @@ class XTCFile(object):
...
@@ -92,11 +90,12 @@ class XTCFile(object):
raise
ValueError
(
"The number of positions must match the number of atoms"
)
raise
ValueError
(
"The number of positions must match the number of atoms"
)
if
is_quantity
(
positions
):
if
is_quantity
(
positions
):
positions
=
positions
.
value_in_unit
(
nanometers
)
positions
=
positions
.
value_in_unit
(
nanometers
)
if
any
(
math
.
isnan
(
norm
(
pos
))
for
pos
in
positions
):
import
numpy
as
np
if
np
.
isnan
(
positions
).
any
():
raise
ValueError
(
raise
ValueError
(
"Particle position is NaN. For more information, see https://github.com/openmm/openmm/wiki/Frequently-Asked-Questions#nan"
"Particle position is NaN. For more information, see https://github.com/openmm/openmm/wiki/Frequently-Asked-Questions#nan"
)
)
if
any
(
math
.
isinf
(
norm
(
pos
))
for
pos
in
positions
):
if
np
.
isinf
(
positions
)
.
any
()
:
raise
ValueError
(
raise
ValueError
(
"Particle position is infinite. For more information, see https://github.com/openmm/openmm/wiki/Frequently-Asked-Questions#nan"
"Particle position is infinite. For more information, see https://github.com/openmm/openmm/wiki/Frequently-Asked-Questions#nan"
)
)
...
...
wrappers/python/openmm/app/xtcreporter.py
View file @
f6e6b6ed
...
@@ -71,5 +71,5 @@ class XTCReporter(object):
...
@@ -71,5 +71,5 @@ class XTCReporter(object):
self
.
_append
,
self
.
_append
,
)
)
self
.
_xtc
.
writeModel
(
self
.
_xtc
.
writeModel
(
state
.
getPositions
(),
periodicBoxVectors
=
state
.
getPeriodicBoxVectors
()
state
.
getPositions
(
asNumpy
=
True
),
periodicBoxVectors
=
state
.
getPeriodicBoxVectors
()
)
)
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