Skip to content

ForceField.create_interchange has no argument for box vectors, but Interchange.from_smirnoff does #2079

@mattwthompson

Description

@mattwthompson

Description

These class methods don't line up as well as they could - a user should either be able to specify box vectors at Interchange creation time or they shouldn't be able to. There is no reason for the inconsistency and is a detail which well-meaning and well-informed users can easily get tripped up on (openforcefield/openff-interchange#1246).

Long ago, these did match up. I was able to narrow the discrepancy down to an unrelated change (#1281). I don't recall any reason for this happening and think it was incidental.

    @requires_package("openff.interchange")
-   def create_interchange(self, topology: "Topology", box=None):
+   def create_interchange(
+        self,
+        topology: "Topology",
+        toolkit_registry: Optional[Union["ToolkitRegistry", "ToolkitWrapper"]] = None,
+    ):

I don't care much which we go with, I just care that they're consistent. In openforcefield/openff-interchange#1246 (comment) I laid out some reasons why it shouldn't be separate from the topology argument, having forgotten that Interchange.from_smirnoff does exactly that.

Reproduction

In [1]: from openff.interchange import Interchange

In [2]: from openff.toolkit import Quantity, Molecule, ForceField

In [3]: molecule = Molecule.from_smiles("CCO")

In [4]: box = Quantity([4, 4, 4], 'nanometer')

In [5]: force_field = ForceField("openff-2.0.0.offxml")

In [6]: Interchange.from_smirnoff(force_field=force_field, topology=molecule.to_topology(), box=box).box
Out[6]:
<Quantity([[4. 0. 0.]
 [0. 4. 0.]
 [0. 0. 4.]], 'nanometer')>

In [7]: force_field.create_interchange(molecule.to_topology(), box=box)
---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
Cell In[7], line 1
----> 1 force_field.create_interchange(molecule.to_topology(), box=box)

File ~/micromamba/envs/openff-interchange-dev/lib/python3.12/site-packages/openff/utilities/utilities.py:81, in requires_package.<locals>.inner_decorator.<locals>.wrapper(*args, **kwargs)
     78 except Exception as e:
     79     raise e
---> 81 return function(*args, **kwargs)

TypeError: ForceField.create_interchange() got an unexpected keyword argument 'box'

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions