Skip to content

Misleading error message for adding a duplicate VirtualSite parameter #2157

@lilyminium

Description

@lilyminium

Describe the bug

For most parameters, adding new parameters with the same SMIRKS triggers an error. Uniquely for VirtualSites, parameters are allowed to have the same SMIRKS but must have different combinations of SMIRKS and names. However, the error message still only references SMIRKS.

To Reproduce

>>> from openff.toolkit import ForceField, unit
>>> vsite_kwargs = {
...             "smirks": "[#1:1]-[#8X2H2+0:2]-[#1:3]",
...             "name": f"LP",
...             "type": "DivalentLonePair",
...             "distance": -0.0106 * unit.nanometers,
...             "outOfPlaneAngle": 0.0 * unit.degrees,
...             "match": "once",
...             "charge_increment": [
...                 0.0 * unit.elementary_charge,
...                 0.0 * unit.elementary_charge,
...                 0.0 * unit.elementary_charge,
...             ],
...         }
>>> ff = ForceField()
>>> vsite_handler = ff.get_parameter_handler("VirtualSites")
>>> vsite_handler.add_parameter(vsite_kwargs)
>>> vsite_handler.add_parameter(vsite_kwargs)
Traceback (most recent call last):
  File "<python-input-8>", line 1, in <module>
    vsite_handler.add_parameter(vsite_kwargs)
    ~~~~~~~~~~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^
  File "/Users/lilywang/pydev/openff-toolkit/openff/toolkit/typing/engines/smirnoff/parameters.py", line 2028, in add_parameter
    raise DuplicateParameterError(msg)
openff.toolkit.utils.exceptions.DuplicateParameterError: A parameter SMIRKS pattern [#1:1]-[#8X2H2+0:2]-[#1:3] already exists.

Ideally, the error message here would reference the virtual site name as well.

Output

Computing environment (please complete the following information):

  • Operating system
  • Output of running conda list

Additional context

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions