-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add support for sampling energies at different lambda values.
- Loading branch information
Showing
4 changed files
with
147 additions
and
6 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,90 @@ | ||
from pathlib import Path | ||
|
||
import tempfile | ||
import pytest | ||
|
||
import sire as sr | ||
|
||
from somd2.runner import Runner | ||
from somd2.config import Config | ||
from somd2.io import * | ||
|
||
|
||
def test_lambda_values(ethane_methanol): | ||
""" | ||
Validate that a simulation can be run with a custom list of lambda values. | ||
""" | ||
|
||
with tempfile.TemporaryDirectory() as tmpdir: | ||
mols = ethane_methanol.clone() | ||
|
||
config = { | ||
"runtime": "12fs", | ||
"restart": False, | ||
"output_directory": tmpdir, | ||
"energy_frequency": "4fs", | ||
"checkpoint_frequency": "4fs", | ||
"frame_frequency": "4fs", | ||
"platform": "CPU", | ||
"max_threads": 1, | ||
"lambda_values": [0.0, 0.5, 1.0], | ||
} | ||
|
||
# Instantiate a runner using the config defined above. | ||
runner = Runner(mols, Config(**config)) | ||
|
||
# Run the simulation. | ||
runner.run() | ||
|
||
# Load the energy trajectory. | ||
energy_traj, meta = parquet_to_dataframe(Path(tmpdir) / "energy_traj_0.parquet") | ||
|
||
# Make sure the lambda_array in the metadata is correct. This is the | ||
# lambda_values list in the config. | ||
assert meta["lambda_array"] == [0.0, 0.5, 1.0] | ||
|
||
# Make sure the second dimension of the energy trajectory is the correct | ||
# size. This is one for the current lambda value, one for its gradient, | ||
# and two for the additional values in the lambda_values list. | ||
assert energy_traj.shape[1] == 4 | ||
|
||
|
||
def test_lambda_energy(ethane_methanol): | ||
""" | ||
Validate that a simulation can sample energies at a different set of | ||
lambda values. | ||
""" | ||
|
||
with tempfile.TemporaryDirectory() as tmpdir: | ||
mols = ethane_methanol.clone() | ||
|
||
config = { | ||
"runtime": "12fs", | ||
"restart": False, | ||
"output_directory": tmpdir, | ||
"energy_frequency": "4fs", | ||
"checkpoint_frequency": "4fs", | ||
"frame_frequency": "4fs", | ||
"platform": "CPU", | ||
"max_threads": 1, | ||
"lambda_values": [0.0, 1.0], | ||
"lambda_energy": [0.5], | ||
} | ||
|
||
# Instantiate a runner using the config defined above. | ||
runner = Runner(mols, Config(**config)) | ||
|
||
# Run the simulation. | ||
runner.run() | ||
|
||
# Load the energy trajectory. | ||
energy_traj, meta = parquet_to_dataframe(Path(tmpdir) / "energy_traj_0.parquet") | ||
|
||
# Make sure the lambda_array in the metadata is correct. This is the | ||
# sampled lambda plus the lambda_energy values in the config. | ||
assert meta["lambda_array"] == [0.0, 0.5] | ||
|
||
# Make sure the second dimension of the energy trajectory is the correct | ||
# size. This is one for the current lambda value, one for its gradient, | ||
# and one for the length of lambda_energy. | ||
assert energy_traj.shape[1] == 3 |