From 477a766853068428f9350f5b3a1ef4cd9a38ce67 Mon Sep 17 00:00:00 2001 From: "Matthew W. Thompson" Date: Mon, 19 Oct 2026 17:30:55 -0500 Subject: [PATCH 1/3] Update handling pressure configs --- tyff/_tests/compute/test_prep.py | 5 +++++ tyff/compute/_equilibrate.py | 7 ++++--- tyff/compute/_produce.py | 12 +++++++----- tyff/compute/prep.py | 2 +- tyff/configs/_compute.py | 2 +- tyff/configs/gas.py | 8 ++++++++ 6 files changed, 26 insertions(+), 10 deletions(-) diff --git a/tyff/_tests/compute/test_prep.py b/tyff/_tests/compute/test_prep.py index 13a2a4d..1abf275 100644 --- a/tyff/_tests/compute/test_prep.py +++ b/tyff/_tests/compute/test_prep.py @@ -87,4 +87,9 @@ def test_pressure_in_gas_configs(dhvap_entry): for this_config in compute_configs: for val in this_config: + # both liquid and gas configs should have a pressure key assert "pressure" in val + + # liquid configs must have non-null pressure, gas configs must have None + assert (val["tag"] == "liquid") == (val["pressure"] is not None) + assert (val["tag"] == "gas") == (val["pressure"] is None) diff --git a/tyff/compute/_equilibrate.py b/tyff/compute/_equilibrate.py index 0e3e7c1..69b1ba2 100644 --- a/tyff/compute/_equilibrate.py +++ b/tyff/compute/_equilibrate.py @@ -92,13 +92,14 @@ def _run_equilibration( if topology.getPeriodicBoxVectors() is not None: simulation.context.setPeriodicBoxVectors(*topology.getPeriodicBoxVectors()) + # let pressure be None for gas-phase NVT simulations, including reporting as None to TensorReporter later pressure = compute_config.get("pressure", None) - if pressure is None: - raise PressureNotDefinedError("Trying to set up NPT simulation but no pressure defined.") - # only set pressure in liquid NPT simulations, not in gas-phase NVT simulations if compute_config["tag"] == "liquid": + if pressure is None: + raise PressureNotDefinedError("Trying to set up NPT simulation in liquid phase but no pressure defined.") + barostat = openmm.MonteCarloBarostat( (pressure * openmm.unit.kilopascal).value_in_unit(openmm.unit.bar), # pressure in bar compute_config["temperature"], # temperature in kelvin diff --git a/tyff/compute/_produce.py b/tyff/compute/_produce.py index cd1d143..1ad0e61 100644 --- a/tyff/compute/_produce.py +++ b/tyff/compute/_produce.py @@ -91,7 +91,14 @@ def _run_production( logger.info("Reinitializing context (in production step)") simulation.context.reinitialize(preserveState=True) + # let pressure be None for gas-phase NVT simulations, including reporting as None to TensorReporter later + pressure = compute_config.get("pressure", None) + if compute_config["tag"] == "liquid": + if pressure is None: + # this clause should already be triggered in _run_equilibration + raise PressureNotDefinedError("Trying to set up NPT simulation but no pressure defined.") + # just double check pressure is loaded back in correctly from state barostat = next( force for force in simulation.system.getForces() if isinstance(force, openmm.MonteCarloBarostat) @@ -99,11 +106,6 @@ def _run_production( assert barostat.getDefaultPressure() is not None - pressure = compute_config.get("pressure", None) - - if pressure is None: - raise PressureNotDefinedError("Trying to set up NPT simulation but no pressure defined.") - simulation.context.setVelocitiesToTemperature( compute_config["temperature"], # kelvin, but as float compute_config["replicate_index"] + 1, diff --git a/tyff/compute/prep.py b/tyff/compute/prep.py index a21e6ea..3a2c1e8 100644 --- a/tyff/compute/prep.py +++ b/tyff/compute/prep.py @@ -164,7 +164,7 @@ def _make_enthalpy_of_vaporization_compute_configs( smiles=data_entry["smiles"], x=data_entry["x"], temperature=data_entry["temperature"], - pressure=data_entry["pressure"], + pressure=None, # should *always* be None, but not validated in the model ), ) ) diff --git a/tyff/configs/_compute.py b/tyff/configs/_compute.py index 6a326d7..a892797 100644 --- a/tyff/configs/_compute.py +++ b/tyff/configs/_compute.py @@ -18,4 +18,4 @@ class BaseComputeConfig(typing_extensions.TypedDict, extra_items=typing.Any): temperature: float - pressure: float + pressure: float | None diff --git a/tyff/configs/gas.py b/tyff/configs/gas.py index 07fdbc8..f4caa56 100644 --- a/tyff/configs/gas.py +++ b/tyff/configs/gas.py @@ -4,6 +4,14 @@ class VacuumGas(BaseComputeConfig): + """ + General model for vacuum simulations + + Note that `pressure` is inherited from the base class as `float | None`, + but should always be `None` in this model. + + """ + tag: typing.Literal["gas"] """ From 1b9a02ae4ac2b33b5559df05c9e7e6e3ed9c4b48 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Mon, 19 Oct 2026 22:43:31 +0000 Subject: [PATCH 2/3] Guard TensorReporter pressure when gas configs use None Co-authored-by: mattwthompson <7935382+mattwthompson@users.noreply.github.com> --- tyff/compute/_equilibrate.py | 4 +++- tyff/compute/_produce.py | 4 +++- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/tyff/compute/_equilibrate.py b/tyff/compute/_equilibrate.py index 69b1ba2..768f04b 100644 --- a/tyff/compute/_equilibrate.py +++ b/tyff/compute/_equilibrate.py @@ -137,12 +137,14 @@ def _run_equilibration( compute_config["replicate_index"] + 1, ) + pressure_for_report = None if pressure is None else pressure * openmm.unit.kilopascal + simulation.reporters.append( tyff.mm.TensorReporter( output_file=files["msgpack_trajectory"].filepath, report_interval=1000, beta=1.0 / (openmm.unit.MOLAR_GAS_CONSTANT_R * compute_config["temperature"] * openmm.unit.kelvin), - pressure=pressure * openmm.unit.kilopascal, + pressure=pressure_for_report, ) ) diff --git a/tyff/compute/_produce.py b/tyff/compute/_produce.py index 1ad0e61..9a271c5 100644 --- a/tyff/compute/_produce.py +++ b/tyff/compute/_produce.py @@ -133,12 +133,14 @@ def _run_production( ) ) + pressure_for_report = None if pressure is None else pressure * openmm.unit.kilopascal + simulation.reporters.append( tyff.mm.TensorReporter( output_file=files["msgpack_trajectory"].filepath, report_interval=1000, beta=1.0 / (openmm.unit.MOLAR_GAS_CONSTANT_R * compute_config["temperature"] * openmm.unit.kelvin), - pressure=pressure * openmm.unit.kilopascal, + pressure=pressure_for_report, ) ) From e4830d0df5786df8d3f0e8758d9db533d77f2503 Mon Sep 17 00:00:00 2001 From: "Matthew W. Thompson" Date: Mon, 19 Oct 2026 17:46:27 -0500 Subject: [PATCH 3/3] More accurately pass pressure to reporter --- tyff/compute/_equilibrate.py | 2 +- tyff/compute/_produce.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/tyff/compute/_equilibrate.py b/tyff/compute/_equilibrate.py index 69b1ba2..fed9387 100644 --- a/tyff/compute/_equilibrate.py +++ b/tyff/compute/_equilibrate.py @@ -142,7 +142,7 @@ def _run_equilibration( output_file=files["msgpack_trajectory"].filepath, report_interval=1000, beta=1.0 / (openmm.unit.MOLAR_GAS_CONSTANT_R * compute_config["temperature"] * openmm.unit.kelvin), - pressure=pressure * openmm.unit.kilopascal, + pressure=pressure if pressure is None else openmm.unit.kilopascal, ) ) diff --git a/tyff/compute/_produce.py b/tyff/compute/_produce.py index 1ad0e61..e5903df 100644 --- a/tyff/compute/_produce.py +++ b/tyff/compute/_produce.py @@ -138,7 +138,7 @@ def _run_production( output_file=files["msgpack_trajectory"].filepath, report_interval=1000, beta=1.0 / (openmm.unit.MOLAR_GAS_CONSTANT_R * compute_config["temperature"] * openmm.unit.kelvin), - pressure=pressure * openmm.unit.kilopascal, + pressure=pressure if pressure is None else openmm.unit.kilopascal, ) )