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
b7088b74
"plugins/amoeba/vscode:/vscode.git/clone" did not exist on "29654b8000371484c3311cfb6d8bf719de3b65c1"
Commit
b7088b74
authored
Aug 10, 2015
by
peastman
Committed by
Robert McGibbon
Aug 27, 2015
Browse files
Python 2/3 compatibility in single code base, plus python 3 testing on travis.
parent
4c00b312
Changes
123
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
44 additions
and
30 deletions
+44
-30
wrappers/python/tests/TestNumpyCompatibility.py
wrappers/python/tests/TestNumpyCompatibility.py
+33
-26
wrappers/python/tests/TestPdbFile.py
wrappers/python/tests/TestPdbFile.py
+9
-4
wrappers/python/tests/TestPdbxFile.py
wrappers/python/tests/TestPdbxFile.py
+2
-0
No files found.
wrappers/python/tests/TestNumpyCompatibility.py
View file @
b7088b74
import
unittest
import
numpy
as
np
from
simtk.openmm
import
app
import
simtk.openmm
as
mm
from
simtk
import
unit
try
:
import
numpy
as
np
NUMPY_IMPORT_FAILED
=
False
except
ImportError
:
NUMPY_IMPORT_FAILED
=
True
@
unittest
.
skipIf
(
NUMPY_IMPORT_FAILED
,
'Numpy is not installed'
)
class
TestNumpyCompatibility
(
unittest
.
TestCase
):
def
setUp
(
self
):
prmtop
=
app
.
AmberPrmtopFile
(
'systems/water-box-216.prmtop'
)
system
=
prmtop
.
createSystem
(
nonbondedMethod
=
app
.
PME
,
system
=
prmtop
.
createSystem
(
nonbondedMethod
=
app
.
PME
,
nonbondedCutoff
=
0.9
*
unit
.
nanometers
,
constraints
=
app
.
HBonds
,
rigidWater
=
True
,
constraints
=
app
.
HBonds
,
rigidWater
=
True
,
ewaldErrorTolerance
=
0.0005
)
integrator
=
mm
.
LangevinIntegrator
(
300
*
unit
.
kelvin
,
1.0
/
unit
.
picoseconds
,
integrator
=
mm
.
LangevinIntegrator
(
300
*
unit
.
kelvin
,
1.0
/
unit
.
picoseconds
,
2.0
*
unit
.
femtoseconds
)
self
.
simulation
=
app
.
Simulation
(
prmtop
.
topology
,
system
,
integrator
,
mm
.
Platform
.
getPlatformByName
(
'Reference'
))
def
test_setPositions
(
self
):
n_particles
=
self
.
simulation
.
context
.
getSystem
().
getNumParticles
()
input
=
np
.
random
.
randn
(
n_particles
,
3
)
self
.
simulation
.
context
.
setPositions
(
input
)
output
=
self
.
simulation
.
context
.
getState
(
getPositions
=
True
).
getPositions
(
asNumpy
=
True
)
np
.
testing
.
assert_array_almost_equal
(
input
,
output
)
def
test_setPositions_units
(
self
):
n_particles
=
self
.
simulation
.
context
.
getSystem
().
getNumParticles
()
input
=
unit
.
Quantity
(
np
.
random
.
randn
(
n_particles
,
3
),
unit
.
angstroms
)
self
.
simulation
.
context
.
setPositions
(
input
)
output
=
self
.
simulation
.
context
.
getState
(
getPositions
=
True
).
getPositions
(
asNumpy
=
True
)
np
.
testing
.
assert_array_almost_equal
(
input
.
value_in_unit
(
unit
.
nanometers
),
output
.
value_in_unit
(
unit
.
nanometers
))
def
test_setVelocities
(
self
):
n_particles
=
self
.
simulation
.
context
.
getSystem
().
getNumParticles
()
input
=
np
.
random
.
randn
(
n_particles
,
3
)
self
.
simulation
.
context
.
setVelocities
(
input
)
output
=
self
.
simulation
.
context
.
getState
(
getVelocities
=
True
).
getVelocities
(
asNumpy
=
True
)
np
.
testing
.
assert_array_almost_equal
(
input
,
output
)
def
test_setVelocities_units
(
self
):
n_particles
=
self
.
simulation
.
context
.
getSystem
().
getNumParticles
()
input
=
unit
.
Quantity
(
np
.
random
.
randn
(
n_particles
,
3
),
unit
.
angstroms
/
unit
.
femtoseconds
)
self
.
simulation
.
context
.
setVelocities
(
input
)
output
=
self
.
simulation
.
context
.
getState
(
getVelocities
=
True
).
getVelocities
(
asNumpy
=
True
)
np
.
testing
.
assert_array_almost_equal
(
input
.
value_in_unit
(
unit
.
angstroms
/
unit
.
femtoseconds
),
output
.
value_in_unit
(
unit
.
angstroms
/
unit
.
femtoseconds
))
def
test_tabulatedFunction
(
self
):
f
=
mm
.
CustomNonbondedForce
(
'g(r)'
)
r
=
np
.
linspace
(
0
,
10
)
g_of_r
=
np
.
sin
(
r
)
indx
=
f
.
addFunction
(
'g'
,
g_of_r
,
np
.
min
(
r
),
np
.
max
(
r
))
indx
=
f
.
addFunction
(
'g'
,
g_of_r
,
np
.
min
(
r
),
np
.
max
(
r
))
name
,
g_of_r_out
,
min_r_out
,
max_r_out
=
f
.
getFunctionParameters
(
indx
)
np
.
testing
.
assert_array_almost_equal
(
g_of_r
,
np
.
asarray
(
g_of_r_out
))
assert
min_r_out
==
np
.
min
(
r
)
assert
max_r_out
==
np
.
max
(
r
)
def
test_CMAP
(
self
):
f
=
mm
.
CMAPTorsionForce
()
energy
=
np
.
random
.
randn
(
10
*
10
)
...
...
@@ -76,10 +81,12 @@ class TestNumpyCompatibility(unittest.TestCase):
size
,
energy_out
=
f
.
getMapParameters
(
0
)
energy_out
=
energy_out
.
value_in_unit_system
(
unit
.
md_unit_system
)
self
.
assertEqual
(
size
,
10
)
np
.
testing
.
assert_array_almost_equal
(
energy
,
np
.
asarray
(
energy_out
))
@
unittest
.
skipIf
(
NUMPY_IMPORT_FAILED
,
'Numpy is not installed'
)
class
TestNumpyUnits
(
unittest
.
TestCase
):
def
setUp
(
self
):
...
...
wrappers/python/tests/TestPdbFile.py
View file @
b7088b74
import
sys
import
unittest
from
simtk.openmm.app
import
*
from
simtk.openmm
import
*
from
simtk.unit
import
*
import
simtk.openmm.app.element
as
elem
import
cStringIO
if
sys
.
version_info
>=
(
3
,
0
):
from
io
import
StringIO
else
:
from
cStringIO
import
StringIO
class
TestPdbFile
(
unittest
.
TestCase
):
"""Test the PDB file parser"""
def
test_Triclinic
(
self
):
"""Test parsing a file that describes a triclinic box."""
pdb
=
PDBFile
(
'systems/triclinic.pdb'
)
...
...
@@ -43,9 +48,9 @@ class TestPdbFile(unittest.TestCase):
def
test_WriteFile
(
self
):
"""Write a file, read it back, and make sure it matches the original."""
pdb1
=
PDBFile
(
'systems/triclinic.pdb'
)
output
=
cStringIO
.
StringIO
()
output
=
StringIO
()
PDBFile
.
writeFile
(
pdb1
.
topology
,
pdb1
.
positions
,
output
)
input
=
cStringIO
.
StringIO
(
output
.
getvalue
())
input
=
StringIO
(
output
.
getvalue
())
pdb2
=
PDBFile
(
input
)
output
.
close
();
input
.
close
();
...
...
wrappers/python/tests/TestPdbxFile.py
View file @
b7088b74
...
...
@@ -70,6 +70,7 @@ class TestPdbxFile(unittest.TestCase):
# There should only be 10 frames (0 through 9)
self
.
assertRaises
(
IndexError
,
lambda
:
pdb
.
getPositions
(
frame
=
10
))
self
.
assertIs
(
pdb
.
topology
.
getPeriodicBoxVectors
(),
None
)
del
sim
os
.
unlink
(
'test.cif'
)
def
assertAlmostEqualVec
(
self
,
vec1
,
vec2
,
*
args
,
**
kwargs
):
...
...
@@ -111,6 +112,7 @@ class TestPdbxFile(unittest.TestCase):
self
.
assertAlmostEqualVec
(
parm
.
topology
.
getPeriodicBoxVectors
()[
2
],
pdb
.
topology
.
getPeriodicBoxVectors
()[
2
],
places
=
5
)
del
sim
os
.
unlink
(
'test.cif'
)
if
__name__
==
'__main__'
:
...
...
Prev
1
…
3
4
5
6
7
Next
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