Skip to content

Commit

Permalink
attempted fix of surface tension test
Browse files Browse the repository at this point in the history
  • Loading branch information
Olllom committed Oct 29, 2019
1 parent d1c1812 commit 46308b0
Showing 1 changed file with 11 additions and 10 deletions.
21 changes: 11 additions & 10 deletions openmmtools/tests/test_states.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,8 @@ def setup_class(cls):
"""Create the test systems used in the test suite."""
cls.std_pressure = ThermodynamicState._STANDARD_PRESSURE
cls.std_temperature = ThermodynamicState._STANDARD_TEMPERATURE
cls.std_surface_tension = 100.0 * unit.bar * unit.nanometer
cls.std_surface_tension = ThermodynamicState._STANDARD_SURFACE_TENSION
cls.modified_surface_tension = 100.0 * unit.bar * unit.nanometer

alanine_explicit = testsystems.AlanineDipeptideExplicit()
cls.alanine_positions = alanine_explicit.positions
Expand Down Expand Up @@ -106,7 +107,7 @@ def setup_class(cls):
cls.membrane_barostat_alanine_gamma_nonzero = copy.deepcopy(cls.alanine_explicit)
# working around a bug in the unit conversion https://github.com/openmm/openmm/issues/2406
cls.membrane_barostat_gamma_nonzero = openmm.MonteCarloMembraneBarostat(
cls.std_pressure, cls.std_surface_tension.value_in_unit(unit.bar*unit.nanometer), cls.std_temperature,
cls.std_pressure, cls.modified_surface_tension.value_in_unit(unit.bar*unit.nanometer), cls.std_temperature,
openmm.MonteCarloMembraneBarostat.XYIsotropic, openmm.MonteCarloMembraneBarostat.ZFree
)
cls.membrane_barostat_alanine_gamma_nonzero.addForce(cls.membrane_barostat_gamma_nonzero)
Expand Down Expand Up @@ -396,15 +397,15 @@ def test_surface_tension(self):

# test setting and getting surface tension
state = ThermodynamicState(self.membrane_barostat_alanine_gamma_zero, self.std_temperature)
assert utils.is_quantity_close(state.surface_tension, 0.0 * unit.bar * unit.nanometer)
state.surface_tension = self.std_surface_tension
assert utils.is_quantity_close(state.surface_tension, self.std_surface_tension)
assert utils.is_quantity_close(state.surface_tension, 0.0 * unit.bar * unit.nanometer, rtol=0.0, atol=1e-10)
state.surface_tension = self.modified_surface_tension
assert utils.is_quantity_close(state.surface_tension, self.modified_surface_tension)
state.surface_tension = 0.0 * unit.bar * unit.nanometer
assert utils.is_quantity_close(state.surface_tension, 0.0 * unit.bar * unit.nanometer)
assert utils.is_quantity_close(state.surface_tension, 0.0 * unit.bar * unit.nanometer, rtol=0.0, atol=1e-10)

# test initial surface tension of nonzero-gamma barostat
state = ThermodynamicState(self.membrane_barostat_alanine_gamma_nonzero, self.std_temperature)
assert utils.is_quantity_close(state.surface_tension, self.std_surface_tension)
assert utils.is_quantity_close(state.surface_tension, self.modified_surface_tension)

def test_property_volume(self):
"""Check that volume is computed correctly."""
Expand Down Expand Up @@ -807,10 +808,10 @@ def test_method_apply_to_context(self):
gamma_context = openmm.Context(self.membrane_barostat_alanine_gamma_zero, openmm.VerletIntegrator(0.001))
state3.apply_to_context(gamma_context)
assert gamma_context.getParameter(self.membrane_barostat_gamma_nonzero.SurfaceTension()) == 0.0
state3.surface_tension = self.std_surface_tension
state3.surface_tension = self.modified_surface_tension
state3.apply_to_context(gamma_context)
assert (gamma_context.getParameter(self.membrane_barostat_gamma_nonzero.SurfaceTension())
== self.std_surface_tension.value_in_unit(unit.nanometer*unit.bar))
== self.modified_surface_tension.value_in_unit(unit.nanometer*unit.bar))
state3.surface_tension = 0.0 * unit.nanometer * unit.bar


Expand Down Expand Up @@ -870,7 +871,7 @@ def test_method_reduced_potential(self):
reduced_potential = state.reduced_potential(sampler_state)
pressure_volume_work = (self.std_pressure * sampler_state.volume *
unit.AVOGADRO_CONSTANT_NA)
surface_work = (self.std_surface_tension * sampler_state.area_xy *
surface_work = (self.modified_surface_tension * sampler_state.area_xy *
unit.AVOGADRO_CONSTANT_NA)
potential_energy = (reduced_potential / beta - pressure_volume_work + surface_work) / kj_mol

Expand Down

0 comments on commit 46308b0

Please sign in to comment.