Skip to content

ConstraintsCollection always added, even when empty #1432

@mattwthompson

Description

@mattwthompson

Description

The creation pathway from SMIRNOFF sources results in a ConstraintsCollection always being added, even if there's no corresponding ConstraintHandler or possible way for constraints to be added later.

This is harmless, I think, but also an unexpected result. We could take care to remove it if empty, or simply not create it if no handler is present.

Reproduction

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

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

In [3]: sage.deregister_parameter_handler("Bonds")

In [4]: sage.deregister_parameter_handler("Constraints")

In [5]: interchange = sage.create_interchange(Molecule.from_smiles("CCO").to_topology())

In [6]: interchange.collections
Out[6]:
{'Constraints': Handler 'Constraints' with expression '', 0 mapping keys, and 0 potentials,
 'Angles': Handler 'Angles' with expression 'k/2*(theta-angle)**2', 13 mapping keys, and 3 potentials,
 'ProperTorsions': Handler 'ProperTorsions' with expression 'k*(1+cos(periodicity*theta-phase))', 16 mapping keys, and 6 potentials,
 'ImproperTorsions': Handler 'ImproperTorsions' with expression 'k*(1+cos(periodicity*theta-phase))', 0 mapping keys, and 0 potentials,
 'vdW': Handler 'vdW' with expression '4*epsilon*((sigma/r)**12-(sigma/r)**6)', 9 mapping keys, and 5 potentials,
 'Electrostatics': Handler 'Electrostatics' with expression 'coul', 9 mapping keys, and 9 potentials}

A sillier example involves a force field with no handlers at all, which still results in an empty collection being present:

In [8]: [*ForceField().create_interchange(Molecule.from_smiles("CCO").to_topology()).collections.values()]
Out[8]: [Handler 'Constraints' with expression '', 0 mapping keys, and 0 potentials]

Software versions

  • Which operating system and version are you using?
  • How did you install Interchange?
  • What is the output of running conda list?

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