Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Change ion defaults #32

Merged
merged 2 commits into from
Jun 24, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 12 additions & 14 deletions gufe/solventcomponent.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,19 +28,19 @@ class SolventComponent(Component):

def __init__(self, *, # force kwarg usage
smiles: str = 'O',
positive_ion: Optional[str] = None,
negative_ion: Optional[str] = None,
positive_ion: str = 'Na+',
negative_ion: str = 'Cl-',
neutralize: bool = True,
ion_concentration: unit.Quantity = None):
"""
Parameters
----------
smiles : str, optional
smiles of the solvent, default 'O' (water)
positive_ion, negative_ion : str, optional
positive_ion, negative_ion : str
the pair of ions which is used to neutralize (if neutralize=True) and
bring the solvent to the required ionic concentration. Must be a
positive and negative monoatomic ions, default `None`
positive and negative monoatomic ions, defaults "Na+", "Cl-"
neutralize : bool, optional
if the net charge on the chemical state is neutralized by the ions in
this solvent component. Default `True`
Expand All @@ -57,17 +57,15 @@ def __init__(self, *, # force kwarg usage

"""
self._smiles = smiles
if positive_ion is not None:
norm = positive_ion.strip('-+').capitalize()
if norm not in _CATIONS:
raise ValueError(f"Invalid positive ion, got {positive_ion}")
positive_ion = norm + '+'
norm = positive_ion.strip('-+').capitalize()
if norm not in _CATIONS:
raise ValueError(f"Invalid positive ion, got {positive_ion}")
positive_ion = norm + '+'
self._positive_ion = positive_ion
if negative_ion is not None:
norm = negative_ion.strip('-+').capitalize()
if norm not in _ANIONS:
raise ValueError(f"Invalid negative ion, got {negative_ion}")
negative_ion = norm + '-'
norm = negative_ion.strip('-+').capitalize()
if norm not in _ANIONS:
raise ValueError(f"Invalid negative ion, got {negative_ion}")
negative_ion = norm + '-'
self._negative_ion = negative_ion

self._neutralize = neutralize
Expand Down
14 changes: 2 additions & 12 deletions gufe/tests/test_solvents.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ def test_defaults():
s = SolventComponent()

assert s.smiles == 'O'
assert s.positive_ion is None
assert s.negative_ion is None
assert s.positive_ion == "Na+"
assert s.negative_ion == "Cl-"
assert s.ion_concentration is None


Expand Down Expand Up @@ -81,13 +81,3 @@ def test_solvent_charge():
def test_bad_inputs(pos, neg):
with pytest.raises(ValueError):
_ = SolventComponent(positive_ion=pos, negative_ion=neg)


@pytest.mark.parametrize('pos, neg', [
('Na', None), (None, 'Cl'), (None, None),
])
def test_conc_no_ions(pos, neg):
# if you specify concentration you must also give ions
with pytest.raises(ValueError):
_ = SolventComponent(positive_ion=pos, negative_ion=neg,
ion_concentration=1.5 * unit.molar)