Skip to content

[BUG] Lazy import can break NAGL detection #487

@lohedges

Description

@lohedges

The BioSImSpace parameters code has auto-detection for openff-nagl support, which appears to be broken if any openff-toolkit object is imported after BioSimSpace is imported when using lazy loading, e.g.:

This works:

from openff.toolkit import Topology
import BioSimSpace as BSS

mol = BSS.Parameters.openff_unconstrained_2_2_0("C", use_nagl=True).getMolecule()

giving:

INFO:openff.nagl.nn._models:Using lookup table for property am1bcc_charges
INFO:openff.interchange.smirnoff._nonbonded:Preset charges applied to atom index 0
INFO:openff.interchange.smirnoff._nonbonded:Preset charges applied to atom index 1
INFO:openff.interchange.smirnoff._nonbonded:Preset charges applied to atom index 2
INFO:openff.interchange.smirnoff._nonbonded:Preset charges applied to atom index 3
INFO:openff.interchange.smirnoff._nonbonded:Preset charges applied to atom index 4

But this fails, and falls back to AMBER AM1BCC:

import BioSimSpace as BSS
from openff.toolkit import Topology

mol = BSS.Parameters.openff_unconstrained_2_2_0("C", use_nagl=True).getMolecule()

giving:

INFO:openff.interchange.smirnoff._nonbonded:Charge section ToolkitAM1BCC, using charge method am1bcc, applied to topology atom index 0
INFO:openff.interchange.smirnoff._nonbonded:Charge section ToolkitAM1BCC, using charge method am1bcc, applied to topology atom index 1
INFO:openff.interchange.smirnoff._nonbonded:Charge section ToolkitAM1BCC, using charge method am1bcc, applied to topology atom index 2
INFO:openff.interchange.smirnoff._nonbonded:Charge section ToolkitAM1BCC, using charge method am1bcc, applied to topology atom index 3
INFO:openff.interchange.smirnoff._nonbonded:Charge section ToolkitAM1BCC, using charge method am1bcc, applied to topology atom index 4

However, running the script with the BSS_NO_LAZY_IMPORT environment variable set works, giving:

INFO:openff.nagl.nn._models:Using lookup table for property am1bcc_charges
INFO:openff.interchange.smirnoff._nonbonded:Preset charges applied to atom index 0
INFO:openff.interchange.smirnoff._nonbonded:Preset charges applied to atom index 1
INFO:openff.interchange.smirnoff._nonbonded:Preset charges applied to atom index 2
INFO:openff.interchange.smirnoff._nonbonded:Preset charges applied to atom index 3
INFO:openff.interchange.smirnoff._nonbonded:Preset charges applied to atom index 4

Metadata

Metadata

Assignees

Labels

bugSomething isn't working

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions