Skip to content

Box vectors are are not consistently converted after being set #1480

@mattwthompson

Description

@mattwthompson

Description
The docs say that box vectors are stored internally with nanometers:

Positions [...] are represented in nanometers [...] internally and when reported.

but the setter will accept (and not convert) units like Angstroms.

Note that this is just a problem of being stored in nanometers vs. compatible units - this is not a problem at export time

Reproduction

When using a setter (with compatible units), the internal state isn't converted to use nanometers:

>>> from openff.toolkit import *
>>> out = ForceField("2.3.0.offxml").create_interchange(Molecule.from_smiles("CCO").to_topology())
>>> out.box = Quantity([1, 2, 3], 'picometer')
>>> out.box
<Quantity([[1. 0. 0.]
 [0. 2. 0.]
 [0. 0. 3.]], 'picometer')>

This isn't a huge deal with nanometers vs. Angstroms since we take care to ensure the correct units at export time. But consistent internal state is desirable.

I think this comes from a missed case here:

>>> from openff.interchange._annotations import _duck_to_nanometer
>>> _duck_to_nanometer([1, 2])
<Quantity([1 2], 'nanometer')>
>>> _duck_to_nanometer(Quantity([0.5, 1.5], "angstrom"))
<Quantity([0.5 1.5], 'angstrom')>

Software versions

  • Which operating system and version are you using? macOS 26.3.1
  • How did you install Interchange? Pixi, latest development branch
  • What is the output of running conda list?

Metadata

Metadata

Labels

bugSomething isn't workingdocumentationImprovements or additions to documentation

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions