Skip to content

Commit

Permalink
Merge pull request #750 from openforcefield/rmin-half-sigma
Browse files Browse the repository at this point in the history
Fix missing sigma/rmin_half attrs
  • Loading branch information
mattwthompson committed Nov 10, 2020
2 parents b9d499f + 71f2277 commit 2d73f3d
Show file tree
Hide file tree
Showing 4 changed files with 85 additions and 10 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/CI.yml
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ jobs:
if: ${{ matrix.cfg.rdkit == 'true' && matrix.cfg.openeye == 'TRUE' }}
continue-on-error: true
run: |
pytest -r fE -tb=short openforcefield/tests/test_links.py
pytest -r fE --tb=short openforcefield/tests/test_links.py
- name: Run unit tests
shell: bash -l {0}
Expand Down
18 changes: 10 additions & 8 deletions docs/releasehistory.rst
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ API-breaking changes
there are no special behaviors that are accessed in the case of partially-licensed OpenEye backends. The
new behavior of this method is the same as if the default value above is always provided.


New features
""""""""""""
- `PR #751 <https://github.com/openforcefield/openforcefield/pull/751>`_: Adds
Expand All @@ -40,21 +39,24 @@ New features
to look up individual :py:class:`ParameterType <openforcefield.typing.engines.smirnoff.parameters.ParameterType>`
objects.

Behavior changed
""""""""""""""""
- `PR #753 <https://github.com/openforcefield/openforcefield/pull/753>`_: ``ParameterLookupError``
is now raised when passing to
:py:meth:`ParameterList.index <openforcefield.typing.engines.smirnoff.parameters.ParameterList>`
a SMIRKS pattern not found in the parameter list.

Bugfixes
""""""""
- `PR #745 <https://github.com/openforcefield/openforcefield/pull/745>`_: Fixes bug when
serializing molecule with conformers to JSON.
- `PR #750 <https://github.com/openforcefield/openforcefield/pull/750>`_: Fixes a bug causing either
``sigma`` or ``rmin_half`` to sometimes be missing on
:py:class:`vdWHandler.vdWType <openforcefield.typing.engines.smirnoff.parameters.vdWHandler>`
objects.
- `PR #756 <https://github.com/openforcefield/openforcefield/pull/756>`_: Fixes bug when running
:py:meth:`vdWHandler.create_force <openforcefield.typing.engines.smirnoff.parameters.vdWHandler.create_force>`
using a ``vdWHandler`` that was initialized using the API.

Behavior changed
""""""""""""""""
- `PR #753 <https://github.com/openforcefield/openforcefield/pull/753>`_: ``ParameterLookupError``
is now raised when passing to
:py:meth:`ParameterList.index <openforcefield.typing.engines.smirnoff.parameters.ParameterList>`
a SMIRKS pattern not found in the parameter list.


0.8.0 - Virtual Sites
Expand Down
35 changes: 35 additions & 0 deletions openforcefield/tests/test_parameters.py
Original file line number Diff line number Diff line change
Expand Up @@ -1728,6 +1728,41 @@ def test_create_force_defaults(self):
vdw_handler.create_force(omm_sys, topology)


class TestvdWType:
"""
Test the behavior of vdWType
"""

def test_sigma_rmin_half(self):
"""Test the setter/getter behavior or sigma and rmin_half"""
from openforcefield.typing.engines.smirnoff.parameters import vdWHandler

data = {
"smirks": "[*:1]",
"sigma": 0.5 * unit.angstrom,
"epsilon": 0.5 * unit.kilocalorie_per_mole,
}
param = vdWHandler.vdWType(**data)

assert param.sigma is not None
assert param.rmin_half is not None
assert param.sigma == param.rmin_half / 2 ** (1 / 6)
assert "sigma" in param.to_dict()
assert "rmin_half" not in param.to_dict()

param.sigma = 0.8 * unit.angstrom

assert param.sigma == param.rmin_half / 2 ** (1 / 6)
assert "sigma" in param.to_dict()
assert "rmin_half" not in param.to_dict()

param.rmin_half = 0.8 * unit.angstrom

assert param.sigma == param.rmin_half / 2 ** (1 / 6)
assert "sigma" not in param.to_dict()
assert "rmin_half" in param.to_dict()


class TestVirtualSiteHandler:
"""
Test the creation of a VirtualSiteHandler and the implemented VirtualSiteTypes
Expand Down
40 changes: 39 additions & 1 deletion openforcefield/typing/engines/smirnoff/parameters.py
Original file line number Diff line number Diff line change
Expand Up @@ -1066,7 +1066,7 @@ def _process_indexed_attributes(self, smirnoff_data, indexed_attr_lengths=None):

return smirnoff_data

def to_dict(self, discard_cosmetic_attributes=False):
def to_dict(self, discard_cosmetic_attributes=False, duplicate_attributes=None):
"""
Convert this object to dict format.
Expand All @@ -1078,6 +1078,9 @@ def to_dict(self, discard_cosmetic_attributes=False):
----------
discard_cosmetic_attributes : bool, optional. Default = False
Whether to discard non-spec attributes of this object
duplicate_attributes : list of string, optional. Default = None
A list of names of attributes that redundantly decsribe
data and should be discarded during serializaiton
Returns
-------
Expand All @@ -1090,6 +1093,10 @@ def to_dict(self, discard_cosmetic_attributes=False):
# optional attributes that are set to None defaults.
attribs_to_return = list(self._get_defined_parameter_attributes().keys())

if duplicate_attributes is not None:
for duplicate in duplicate_attributes:
attribs_to_return.pop(attribs_to_return.index(duplicate))

# Start populating a dict of the attribs.
indexed_attribs = set(self._get_indexed_parameter_attributes().keys())
mapped_attribs = set(self._get_mapped_parameter_attributes().keys())
Expand Down Expand Up @@ -3496,6 +3503,31 @@ def __init__(self, **kwargs):

super().__init__(**kwargs)

if sigma:
self._extra_nb_var = "rmin_half"
if rmin_half:
self._extra_nb_var = "sigma"

def __setattr__(self, name, value):
super().__setattr__(key=name, value=value)
if name == "rmin_half":
super().__setattr__("sigma", value / 2 ** (1 / 6))
self._extra_nb_var = "sigma"

if name == "sigma":
super().__setattr__("rmin_half", value * 2 ** (1 / 6))
self._extra_nb_var = "rmin_half"

def to_dict(
self,
discard_cosmetic_attributes=False,
duplicate_attributes=None,
):
return super().to_dict(
discard_cosmetic_attributes=discard_cosmetic_attributes,
duplicate_attributes=[self._extra_nb_var],
)

_TAGNAME = "vdW" # SMIRNOFF tag name to process
_INFOTYPE = vdWType # info type to store
# _KWARGS = ['ewaldErrorTolerance',
Expand Down Expand Up @@ -5066,6 +5098,11 @@ def __init__(self, **kwargs):

super().__init__(**kwargs)

if sigma:
self._extra_nb_var = "rmin_half"
if rmin_half:
self._extra_nb_var = "sigma"

# @type.converter
# def type(self, attr, vsite_type):
# """
Expand Down Expand Up @@ -5203,6 +5240,7 @@ def _add_virtual_site(self, fn, atoms, orientations, *args, **kwargs):
"replace": kwargs.pop("replace", False),
}
kwargs.update(base_args)
kwargs.pop(self._extra_nb_var)

return fn(*args, **kwargs)

Expand Down

0 comments on commit 2d73f3d

Please sign in to comment.