Openff-toolkit: Charge Assignment from molecule is failing

Created on 5 Jun 2019  路  5Comments  路  Source: openforcefield/openff-toolkit

Hi there,

I was trying to use generate an OpenMM system starting from a given molecule topology created starting from an OpenEye molecule. Unfortunately, I was unsuccessful. I'm using the openforcefield v 0.3.0 on Mac Osx. The problem seems to be related to the charge assignment. My molecule already provides partial charges and I do not want to recompute them. Here is the code snippet that you can use to reproduce the bug:

from openeye import oechem
from openforcefield.topology import Molecule
from openforcefield.typing.engines.smirnoff.parameters import ToolkitAM1BCCHandler

oemol = oechem.OEMol()

with oechem.oemolistream("2799.oeb") as ifs:
    oechem.OEReadMolecule(ifs, oemol)

# These lines are a temporary fix for the bug #344
oechem.OE3DToAtomStereo(oemol)
oechem.OE3DToBondStereo(oemol)

molecule = Molecule(oemol)

tool = ToolkitAM1BCCHandler()
tool.assign_charge_from_molecules(molecule, [molecule])

I'm getting the following error:

Traceback (most recent call last):
File "charge.py", line 16, in
tool.assign_charge_from_molecules(molecule, [molecule])
File "/Users/gcalabro/local/miniconda3/envs/smirnoff_new/lib/python3.6/site-packages/openforcefield/typing/engines/smirnoff/parameters.py", line 2212, in assign_charge_from_molecules
temp_mol_charges[ref_idx] = charge_mol.partial_charges[charge_idx]
File "/Users/gcalabro/local/miniconda3/envs/smirnoff_new/lib/python3.6/site-packages/simtk/unit/quantity.py", line 748, in __setitem__
self._value[key] = value / self.unit
ValueError: assignment destination is read-only

I've attached the offending zipped molecule:

[2799.oeb.zip]
(https://github.com/openforcefield/openforcefield/files/3258970/2799.oeb.zip)

bug

Most helpful comment

Maybe we can add this common use case to a list of online examples or docstring examples?

All 5 comments

Hey @nividic.

My molecule already provides partial charges and I do not want to recompute them.

In the constructor Molecule(oemol), the molecule should already read the partial charges from the OEMol object. Once you create the OFF Topology, I think the current syntax to use your charges is

ff = ForceField(force_field_file)
system = ff.create_openmm_system(topology, charge_from_molecules=[molecule])

In theory, you should never need to work with the toolkit backends directly.

Maybe we can add this common use case to a list of online examples or docstring examples?

@andrrizzi Thanks a lot. I was doing like that and I was getting the posted error. I was trying to make an easy reproducible bug case

Ah! I see. Just noticed that this is probably related to this #330 . I'll put it in the same milestone.

I was able to reproduce this error with the 0.3.0 toolkit, and the changes in 0.4.0 did indeed resolve it.

I've opened a new issue to add a charges_from_molecule example.

Thanks again for the great feedback,. @nividic!

Was this page helpful?
0 / 5 - 0 ratings