Skip to content

Commit

Permalink
Add test for creation of alchemical ions.
Browse files Browse the repository at this point in the history
  • Loading branch information
lohedges committed Jul 17, 2024
1 parent 7012ab2 commit f12716a
Showing 1 changed file with 31 additions and 0 deletions.
31 changes: 31 additions & 0 deletions tests/runner/test_alchemical_ions.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import math

from somd2.runner import Runner


def test_alchemical_ions(ethane_methanol):
"""Ensure that alchemical ions are added correctly."""

# Clone the system.
mols = ethane_methanol.clone()

# Helper function to return the charge difference between the end states.
def charge_difference(mols):
from sire import morph

reference = morph.link_to_reference(mols)
perturbed = morph.link_to_perturbed(mols)

return (perturbed.charge() - reference.charge()).value()

# Add 10 Cl- ions.
new_mols = Runner._create_alchemical_ions(mols, 10)

# Make sure the charge difference is correct.
assert math.isclose(charge_difference(new_mols), -10.0, rel_tol=1e-6)

# Add 10 Na+ ions.
new_mols = Runner._create_alchemical_ions(mols, -10)

# Make sure the charge difference is correct.
assert math.isclose(charge_difference(new_mols), 10.0, rel_tol=1e-6)

0 comments on commit f12716a

Please sign in to comment.