openforcefield / openff-toolkit

The Open Forcefield Toolkit provides implementations of the SMIRNOFF format, parameterization engine, and other tools. Documentation available at http://open-forcefield-toolkit.readthedocs.io
http://openforcefield.org
MIT License
311 stars 90 forks source link

nglview mangles bonds #752

Open j-wags opened 3 years ago

j-wags commented 3 years ago

Describe the bug In some cases, switching between multiple conformers using nglview mixes up the bonding of the molecule.

To Reproduce

from openforcefield.topology import Molecule
from openforcefield.utils.toolkits import RDKitToolkitWrapper, OpenEyeToolkitWrapper
mol = Molecule.from_smiles('[H]c1c(c(c(c(c1[H])S(=O)(=O)N=N#N)S(=O)(=O)N=N#N)[H])[H]')
mol.generate_conformers(n_conformers=2, toolkit_registry=RDKitToolkitWrapper())
mol.visualize(backend='nglview')

Initially this looks fine.

Screen Shot 2020-10-27 at 12 19 16 PM

But after switching to the second conformer, and then back, the bonds and coordinates are mangled

Screen Shot 2020-10-27 at 12 19 24 PM

Output The full error message (may be large, that's fine. Better to paste too much than too little.)

Computing environment (please complete the following information):

Additional context I found this problem in the course of looking into hard-to-parameterize molecules detected in https://github.com/openforcefield/openforcefields/pull/27

mattwthompson commented 3 years ago

Our subclass uses the same molecular skeleton for all "frames" (conformers) in the "trajectory." I think we can rule out the possibilities of atoms being re-ordered between conformers or the base molecule changing between "frames." Maybe something is happening with the PDB conversion within NGLView?

https://github.com/openforcefield/openforcefield/blob/e1a20b9682287de42606b84b895164c8413adaa6/openforcefield/topology/molecule.py#L5545