-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #185 from Becksteinlab/fix-mdpow-solvationenergy
fix mdpow solvationenergy and p_transfer()
- Loading branch information
Showing
9 changed files
with
154 additions
and
38 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 |
---|---|---|
@@ -1 +1,17 @@ | ||
# tests for MDPOW | ||
|
||
import py.path | ||
from pkg_resources import resource_filename | ||
|
||
|
||
RESOURCES = py.path.local(resource_filename(__name__, 'testing_resources')) | ||
|
||
MOLECULES = { | ||
"benzene": RESOURCES.join("molecules", "benzene"), | ||
} | ||
STATES = { | ||
"FEP": RESOURCES.join("states", "FEP"), | ||
"base": RESOURCES.join("states", "base"), | ||
"md_npt": RESOURCES.join("states", "FEP"), | ||
} | ||
CONFIGURATIONS = RESOURCES.join("test_configurations") |
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 |
---|---|---|
@@ -1,7 +1,6 @@ | ||
from __future__ import absolute_import | ||
|
||
import sys | ||
from six.moves import reload_module | ||
|
||
import pytest | ||
|
||
|
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,81 @@ | ||
from __future__ import absolute_import | ||
|
||
import pytest | ||
|
||
import os.path | ||
import shutil | ||
import copy | ||
|
||
import mdpow.fep | ||
|
||
from . import STATES | ||
|
||
@pytest.fixture | ||
def FEP_dir(tmpdir): | ||
name = STATES['FEP'].basename # a py.path.local | ||
fepdir = tmpdir.join(name) # a py.path.local | ||
shutil.copytree(STATES['FEP'].strpath, fepdir.strpath) | ||
assert os.path.isdir(fepdir.strpath) | ||
return fepdir | ||
|
||
def setup_Ghyd(fepdir): | ||
basedir = fepdir.join("benzene") | ||
gsolv = basedir.join("FEP", "water", "Gsolv.fep") | ||
G = mdpow.fep.Ghyd(filename=gsolv.strpath) | ||
# patch paths | ||
G.basedir = basedir.strpath | ||
G.filename = gsolv.strpath | ||
return G | ||
|
||
|
||
@pytest.fixture | ||
def Ghyd(FEP_dir): | ||
return setup_Ghyd(FEP_dir) | ||
|
||
@pytest.fixture | ||
def Ghyd_other(FEP_dir): | ||
return setup_Ghyd(FEP_dir) | ||
|
||
def test_load_Ghyd(Ghyd): | ||
assert isinstance(Ghyd, mdpow.fep.Ghyd) | ||
|
||
@pytest.mark.parametrize("kwargs", ( | ||
{}, | ||
{'SI': True, 'estimator': 'alchemlyb', 'method': 'TI'}, | ||
{'SI': False, 'estimator': 'alchemlyb', 'method': 'MBAR', 'force': False}, | ||
{'SI': False, 'estimator': 'mdpow', 'method': 'TI', 'force': True}, | ||
), | ||
ids=["defaults", | ||
"SI=True, estimator='alchemlyb', method='TI'", | ||
"SI=False, estimator='alchemlyb', method='MBAR', force=False", | ||
"SI=False, estimator='mdpow', method='TI', force=True", | ||
] | ||
) | ||
def test_p_transfer(Ghyd, Ghyd_other, kwargs): | ||
"""Test transfer water <-> water with same data.""" | ||
G1 = Ghyd | ||
G2 = Ghyd_other | ||
|
||
transferFE, logPow = mdpow.fep.p_transfer(G1, G2, **kwargs) | ||
|
||
assert transferFE == pytest.approx(0.0) | ||
assert logPow == pytest.approx(0.0) | ||
|
||
def test_p_transfer_wrong_method(Ghyd, Ghyd_other): | ||
"""Test transfer water <-> water with same data.""" | ||
G1 = Ghyd | ||
G2 = Ghyd_other | ||
|
||
with pytest.raises(ValueError, | ||
match="Method MBAR is not implemented in MDPOW, use estimator='alchemlyb'"): | ||
mdpow.fep.p_transfer(G1, G2, estimator="mdpow", method="MBAR") | ||
|
||
|
||
def test_pOW_error(Ghyd, Ghyd_other): | ||
with pytest.raises(ValueError): | ||
mdpow.fep.pOW(Ghyd, Ghyd_other) | ||
|
||
def test_pCW_error(Ghyd, Ghyd_other): | ||
with pytest.raises(ValueError): | ||
mdpow.fep.pCW(Ghyd, Ghyd_other) | ||
|
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