-
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 test for creation of alchemical ions.
- Loading branch information
Showing
1 changed file
with
31 additions
and
0 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
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) |