-
Notifications
You must be signed in to change notification settings - Fork 23
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Remove replica states from results dictionary (#603)
* [WIP] Remove replica states from results dictionary * Make it so that you can access replica states from file * fix missing import * fix key & remove tests * fix FEAnalysis test * add file not found errors * plural on replica * fix error messages being raised * Fix slow test + add "reading the replica states" test to slow test * Add longer test for HFEs * Add new json files
- Loading branch information
Showing
14 changed files
with
190 additions
and
35 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file modified
BIN
-72.7 KB
(34%)
openfe/tests/data/openmm_afe/CN_absolute_solvation_transformation.json.gz
Binary file not shown.
Binary file added
BIN
+21.4 KB
openfe/tests/data/openmm_rfe/RFE-ProtocolUnitResult-0f3457edf947483aa03d0f4fe88bf566.json.gz
Binary file not shown.
Binary file removed
BIN
-22.5 KB
openfe/tests/data/openmm_rfe/Transformation-e1702a3efc0fa735d5c14fc7572b5278_results.json.gz
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,106 @@ | ||
# This code is part of OpenFE and is licensed under the MIT license. | ||
# For details, see https://github.com/OpenFreeEnergy/openfe | ||
|
||
from gufe.protocols import execute_DAG | ||
import pytest | ||
from openff.units import unit | ||
from openmm import Platform | ||
import os | ||
import pathlib | ||
|
||
import openfe | ||
from openfe.protocols import openmm_afe | ||
|
||
|
||
@pytest.fixture | ||
def available_platforms() -> set[str]: | ||
return {Platform.getPlatform(i).getName() for i in range(Platform.getNumPlatforms())} | ||
|
||
|
||
@pytest.fixture | ||
def set_openmm_threads_1(): | ||
# for vacuum sims, we want to limit threads to one | ||
# this fixture sets OPENMM_CPU_THREADS='1' for a single test, then reverts to previously held value | ||
previous: str | None = os.environ.get('OPENMM_CPU_THREADS') | ||
|
||
try: | ||
os.environ['OPENMM_CPU_THREADS'] = '1' | ||
yield | ||
finally: | ||
if previous is None: | ||
del os.environ['OPENMM_CPU_THREADS'] | ||
else: | ||
os.environ['OPENMM_CPU_THREADS'] = previous | ||
|
||
|
||
@pytest.mark.integration # takes too long to be a slow test ~ 4 mins locally | ||
@pytest.mark.flaky(reruns=3) # pytest-rerunfailures; we can get bad minimisation | ||
@pytest.mark.parametrize('platform', ['CPU', 'CUDA']) | ||
def test_openmm_run_engine(platform, | ||
available_platforms, | ||
benzene_modifications, | ||
set_openmm_threads_1, tmpdir): | ||
if platform not in available_platforms: | ||
pytest.skip(f"OpenMM Platform: {platform} not available") | ||
|
||
# Run a really short calculation to check everything is going well | ||
s = openmm_afe.AbsoluteSolvationProtocol.default_settings() | ||
s.alchemsampler_settings.n_repeats = 1 | ||
s.solvent_simulation_settings.output_indices = "resname UNK" | ||
s.vacuum_simulation_settings.equilibration_length = 0.1 * unit.picosecond | ||
s.vacuum_simulation_settings.production_length = 0.1 * unit.picosecond | ||
s.solvent_simulation_settings.equilibration_length = 0.1 * unit.picosecond | ||
s.solvent_simulation_settings.production_length = 0.1 * unit.picosecond | ||
s.vacuum_engine_settings.compute_platform = platform | ||
s.solvent_engine_settings.compute_platform = platform | ||
s.integrator_settings.n_steps = 5 * unit.timestep | ||
s.vacuum_simulation_settings.checkpoint_interval = 5 * unit.timestep | ||
s.solvent_simulation_settings.checkpoint_interval = 5 * unit.timestep | ||
s.alchemsampler_settings.n_replicas = 14 | ||
s.alchemical_settings.lambda_elec_windows = 5 | ||
s.alchemical_settings.lambda_vdw_windows = 9 | ||
|
||
protocol = openmm_afe.AbsoluteSolvationProtocol( | ||
settings=s, | ||
) | ||
|
||
stateA = openfe.ChemicalSystem({ | ||
'benzene': benzene_modifications['benzene'], | ||
'solvent': openfe.SolventComponent() | ||
}) | ||
|
||
stateB = openfe.ChemicalSystem({ | ||
'solvent': openfe.SolventComponent(), | ||
}) | ||
|
||
# Create DAG from protocol, get the vacuum and solvent units | ||
# and eventually dry run the first solvent unit | ||
dag = protocol.create( | ||
stateA=stateA, | ||
stateB=stateB, | ||
mapping=None, | ||
) | ||
|
||
|
||
cwd = pathlib.Path(str(tmpdir)) | ||
r = execute_DAG(dag, shared_basedir=cwd, scratch_basedir=cwd, | ||
keep_shared=True) | ||
|
||
assert r.ok() | ||
for pur in r.protocol_unit_results: | ||
unit_shared = tmpdir / f"shared_{pur.source_key}_attempt_0" | ||
assert unit_shared.exists() | ||
assert pathlib.Path(unit_shared).is_dir() | ||
checkpoint = pur.outputs['last_checkpoint'] | ||
assert checkpoint == f"{pur.outputs['simtype']}_checkpoint.nc" | ||
assert (unit_shared / checkpoint).exists() | ||
nc = pur.outputs['nc'] | ||
assert nc == unit_shared / f"{pur.outputs['simtype']}.nc" | ||
assert nc.exists() | ||
|
||
# Test results methods that need files present | ||
results = protocol.gather([r]) | ||
states = results.get_replica_states() | ||
assert len(states.items()) == 2 | ||
assert len(states['solvent']) == 1 | ||
assert states['solvent'][0].shape[1] == 14 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters