openforcefield / openff-toolkit

The Open Forcefield Toolkit provides implementations of the SMIRNOFF format, parameterization engine, and other tools. Documentation available at http://open-forcefield-toolkit.readthedocs.io
http://openforcefield.org
MIT License
311 stars 91 forks source link

Fix error message in scaling factors #1726

Closed mattwthompson closed 1 year ago

mattwthompson commented 1 year ago

Resolves #1725

In [1]: from openff.toolkit import ForceField

In [2]: sage = ForceField("openff-2.0.0.offxml")

In [3]: sage["vdW"].scale12 = 1 / 3
---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
File ~/software/openff-toolkit/openff/toolkit/typing/engines/smirnoff/parameters.py:424, in ParameterAttribute._call_converter(self, value, instance)
    422 try:
    423     # Static function.
--> 424     return self._converter(value)
    425 except TypeError:
    426     # Instance method.

TypeError: vdWHandler.scale12() missing 2 required positional arguments: 'attrs' and 'new_scale12'

During handling of the above exception, another exception occurred:

SMIRNOFFSpecError                         Traceback (most recent call last)
Cell In[3], line 1
----> 1 sage["vdW"].scale12 = 1 / 3

File ~/software/openff-toolkit/openff/toolkit/typing/engines/smirnoff/parameters.py:1168, in _ParameterAttributeHandler.__setattr__(self, key, value)
   1163         raise MissingIndexedAttributeError(
   1164             f"'{key}' is out of bounds for indexed attribute '{attr_name}'"
   1165         )
   1167 # Forward the request to the next class in the MRO.
-> 1168 super().__setattr__(key, value)

File ~/software/openff-toolkit/openff/toolkit/typing/engines/smirnoff/parameters.py:373, in ParameterAttribute.__set__(self, instance, value)
    371 def __set__(self, instance, value):
    372     # Convert and validate the value.
--> 373     value = self._convert_and_validate(instance, value)
    374     setattr(instance, self._name, value)

File ~/software/openff-toolkit/openff/toolkit/typing/engines/smirnoff/parameters.py:391, in ParameterAttribute._convert_and_validate(self, instance, value)
    389 value = self._validate_units(value)
    390 # Call the custom converter before setting the value.
--> 391 value = self._call_converter(value, instance)
    392 return value

File ~/software/openff-toolkit/openff/toolkit/typing/engines/smirnoff/parameters.py:427, in ParameterAttribute._call_converter(self, value, instance)
    424         return self._converter(value)
    425     except TypeError:
    426         # Instance method.
--> 427         return self._converter(instance, self, value)
    428 return value

File ~/software/openff-toolkit/openff/toolkit/typing/engines/smirnoff/parameters.py:2861, in vdWHandler.scale12(self, attrs, new_scale12)
   2858 @scale12.converter
   2859 def scale12(self, attrs, new_scale12):
   2860     if new_scale12 != 0.0:
-> 2861         raise SMIRNOFFSpecError(
   2862             "Current OpenFF toolkit is unable to handle scale12 values other than 0.0. "
   2863             f"Specified 1-2 scaling was {new_scale12}."
   2864         )
   2865     return new_scale12

SMIRNOFFSpecError: Current OpenFF toolkit is unable to handle scale12 values other than 0.0. Specified 1-2 scaling was 0.3333333333333333.
codecov[bot] commented 1 year ago

Codecov Report

Merging #1726 (784a23a) into main (c3fc003) will not change coverage. The diff coverage is n/a.

Additional details and impacted files