Skip to content

Commit

Permalink
Merge pull request #33 from jchodera/segfault-workaround
Browse files Browse the repository at this point in the history
[WIP] Segfault workaround
  • Loading branch information
kyleabeauchamp committed Jan 15, 2015
2 parents bb9d535 + c2a882f commit 791baa2
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 27 deletions.
6 changes: 0 additions & 6 deletions openmmtools/tests/test_integrators.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,12 +67,6 @@ def check_stability(integrator, test, platform=None, nsteps=100, temperature=300
#=============================================================================================
# TESTS
#=============================================================================================
def test_doctest():
"""Performing integrators doctests.
"""
from openmmtools import integrators
import doctest
doctest.testmod(integrators)

def test_stabilities_harmonic_oscillator():
"""
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,12 @@ def test_integrators_and_testsystems():

# Create lists of integrator and testsystem names.
integrator_names = [ methodname for methodname in dir(integrators) if re.match('.*Integrator$', methodname) ]
testsystem_names = [ testsystem_class.__name__ for testsystem_class in testsystems.TestSystem.__subclasses__() ]

def all_subclasses(cls):
"""Return list of all subclasses and subsubclasses for a given class."""
return cls.__subclasses__() + [s for s in cls.__subclasses__()]
testsystem_classes = all_subclasses(testsystems.TestSystem)
testsystem_names = [ cls.__name__ for cls in testsystem_classes ]

# Use Reference platform.
platform = openmm.Platform.getPlatformByName('Reference')
Expand Down
33 changes: 18 additions & 15 deletions openmmtools/tests/test_testsystems.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,6 @@

from functools import partial

def test_doctest():
"""Performing testsystems doctests.
"""
import doctest
doctest.testmod(testsystems)

def test_get_data_filename():
"""Testing retrieval of data files shipped with distro.
"""
Expand All @@ -39,22 +33,28 @@ def test_subrandom_particle_positions():
box_vectors = openmm.System().getDefaultPeriodicBoxVectors()
positions = testsystems.subrandom_particle_positions(nparticles, box_vectors)

def check_properties(testsystem):
class_name = testsystem.__class__.__name__
property_list = testsystem.analytical_properties
state = testsystems.ThermodynamicState(temperature=300.0*unit.kelvin, pressure=1.0*unit.atmosphere)
if len(property_list) > 0:
for property_name in property_list:
method = getattr(testsystem, 'get_' + property_name)
logging.info("%32s . %32s : %32s" % (class_name, property_name, str(method(state))))
return

def test_properties_all_testsystems():
"""Testing computation of analytic properties for all systems.
"""
testsystem_classes = testsystems.TestSystem.__subclasses__()
logging.info("Testing analytical property computation:")
for testsystem_class in testsystem_classes:
class_name = testsystem_class.__name__
logging.info(class_name)
print(class_name) # DEBUG
testsystem = testsystem_class()
property_list = testsystem.analytical_properties
state = testsystems.ThermodynamicState(temperature=300.0*unit.kelvin, pressure=1.0*unit.atmosphere)
if len(property_list) > 0:
for property_name in property_list:
method = getattr(testsystem, 'get_' + property_name)
logging.info("%32s . %32s : %32s" % (class_name, property_name, str(method(state))))
f = partial(check_properties, testsystem)
f.description = "Testing properties for testsystem %s" % class_name
logging.info(f.description)
yield f

fast_testsystems = [
"HarmonicOscillator",
Expand Down Expand Up @@ -111,7 +111,10 @@ def check_potential_energy(system, positions):
def test_energy_all_testsystems(skip_slow_tests=False):
"""Testing computation of potential energy for all systems.
"""
testsystem_classes = testsystems.TestSystem.__subclasses__()
def all_subclasses(cls):
"""Return list of all subclasses and subsubclasses for a given class."""
return cls.__subclasses__() + [s for s in cls.__subclasses__()]
testsystem_classes = all_subclasses(testsystems.TestSystem)

for testsystem_class in testsystem_classes:
class_name = testsystem_class.__name__
Expand Down
14 changes: 9 additions & 5 deletions openmmtools/testsystems.py
Original file line number Diff line number Diff line change
Expand Up @@ -1343,12 +1343,16 @@ class LennardJonesFluid(TestSystem):
"""Create a periodic fluid of Lennard-Jones particles.
Initial positions are assigned using a subrandom grid to minimize steric interactions.
Note
----
The default reduced_density is set to 0.05 (gas) so that no minimization is needed to simulate the default system.
Parameters
----------
nparticles : int, optional, default=500
Number of Lennard-Jones particles.
reduced_density : float, optional, default=0.86
Reduced density (density * sigma**3); default is appropriate for liquid argon.
reduced_density : float, optional, default=0.05
Reduced density (density * sigma**3); default is appropriate for gas
mass : simtk.unit.Quantity, optional, default=39.9 * unit.amu
mass of each particle; default is appropriate for argon
sigma : simtk.unit.Quantity, optional, default=3.4 * unit.angstrom
Expand Down Expand Up @@ -1385,7 +1389,7 @@ class LennardJonesFluid(TestSystem):

def __init__(self,
nparticles=500,
reduced_density=0.86, # liquid
reduced_density=0.05, # liquid
mass=39.9 * unit.amu, # argon
sigma=3.4 * unit.angstrom, # argon,
epsilon=0.238 * unit.kilocalories_per_mole, # argon,
Expand All @@ -1405,8 +1409,8 @@ def __init__(self,
system = openmm.System()

# Determine volume and periodic box vectors.
density = reduced_density / sigma**3
volume = nparticles * (density ** -1)
number_density = reduced_density / sigma**3
volume = nparticles * (number_density ** -1)
box_edge = volume ** (1./3.)
a = unit.Quantity((box_edge, 0*unit.angstrom, 0*unit.angstrom))
b = unit.Quantity((0*unit.angstrom, box_edge, 0*unit.angstrom))
Expand Down

0 comments on commit 791baa2

Please sign in to comment.