Skip to content

get_charges_array fails when vsites are present at all #1254

@j-wags

Description

@j-wags
from openff.toolkit.typing.engines.smirnoff import ForceField
from openff.interchange import Interchange
sage = ForceField('openff-2.0.0.offxml')

sage.get_parameter_handler("VirtualSites")
sage["VirtualSites"].add_parameter(
    parameter=VirtualSiteType(
        smirks="[#6:2]-[#17X1:1]",
        type="BondCharge",
        match="all_permutations",
        distance="0.8 * angstrom ** 1",
        charge_increment1="0.123 * elementary_charge ** 1",
        charge_increment2="0.0 * elementary_charge ** 1",
    ),
)

# Create a molecule that would have virtual sites
molecule = Molecule.from_smiles("[Cl]CCO")

# Add NAGLCharges to the force field
sage.get_parameter_handler(
    "NAGLCharges",
    {
        "model_file": "openff-gnn-am1bcc-0.1.0-rc.3.pt",
        "version": "0.3",
    },
)

interchange = Interchange.from_smirnoff(
    force_field=sage,
    topology=molecule.to_topology(),
)

assigned_charges = interchange["Electrostatics"].get_charge_array()

raises

self = Handler 'Electrostatics' with expression 'coul', 10 mapping keys, and 10 potentials, include_virtual_sites = False

    def get_charge_array(self, include_virtual_sites: bool = False) -> Quantity:
        """Return a one-dimensional array-like of atomic charges, ordered topologically."""
        if include_virtual_sites:
            raise NotImplementedError("Not yet implemented with virtual sites")
    
>       return Quantity.from_list([q for _, q in sorted(self.charges.items(), key=lambda x: x[0].atom_indices)])
E       TypeError: '<' not supported between instances of 'NoneType' and 'tuple'

/Users/jeffreywagner/projects/OpenForceField/openff-interchange/openff/interchange/smirnoff/_nonbonded.py:341: TypeError

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions