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
309 stars 90 forks source link

Topology issue from openmm topology for enantiomers from SMILES #538

Open ocmadin opened 4 years ago

ocmadin commented 4 years ago

Describe the bug Parameterizing a mixture of enantiomers, with stereochemistry defined in their SMILES strings, raises a DuplicateUniqueMoleculeError when creating a Topology object from an openmm topology.

To Reproduce Steps to reproduce the behavior. A minimal reproducing set of python commands is ideal.

from openforcefield.topology import Molecule

m1 = Molecule.from_smiles('[H][C@](C(=O)OC([H])([H])[H])(C([H])([H])[H])C([H])([H])O[H]')
m2 = Molecule.from_smiles('[H][C@@](C(=O)OC([H])([H])[H])(C([H])([H])[H])C([H])([H])O[H]')

from openforcefield.topology import Topology
from openforcefield.typing.engines.smirnoff import ForceField

topology = Topology()
topology.add_molecule(m1)
topology.add_molecule(m2)
omm_topology = topology.to_openmm()
recreated_topology = Topology.from_openmm(omm_topology,unique_molecules=[m1,m2])

# Load the OpenFF "Parsley" force field.
forcefield = ForceField('openff-1.0.0.offxml')

# Parametrize the topology and create an OpenMM System.
system = forcefield.create_openmm_system(topology)```
If the problem involves a specific molecule or file, please upload that as well.

Output

    recreated_topology = Topology.from_openmm(omm_topology,unique_molecules=[m1,m2])

  File "/home/owenmadin/anaconda3/envs/evaluator/lib/python3.7/site-packages/openforcefield/topology/topology.py", line 1622, in from_openmm
    raise DuplicateUniqueMoleculeError(msg)

DuplicateUniqueMoleculeError: Error: Two unique molecules have indistinguishable graphs: Molecule with name '' and SMILES '[H][C@@](C(=O)OC([H])([H])[H])(C([H])([H])[H])C([H])([H])O[H]' and Molecule with name '' and SMILES '[H][C@](C(=O)OC([H])([H])[H])(C([H])([H])[H])C([H])([H])O[H]'

Computing environment (please complete the following information): RHEL 7

_libgcc_mutex             0.1                 conda_forge    conda-forge
_openmp_mutex             4.5                       0_gnu    conda-forge
alabaster                 0.7.12                     py_0    conda-forge
amberlite                 16.0                     pypi_0    pypi
ambertools                17.0                     pypi_0    pypi
argh                      0.26.2                py37_1001    conda-forge
astroid                   2.3.3                    py37_1    conda-forge
atomicwrites              1.3.0                      py_0    conda-forge
attrs                     19.3.0                     py_0    conda-forge
autopep8                  1.5                        py_0    conda-forge
babel                     2.8.0                      py_0    conda-forge
backcall                  0.1.0                      py_0    conda-forge
bleach                    3.1.0                      py_0    conda-forge
blosc                     1.17.1               he1b5a44_0    conda-forge
bokeh                     1.4.0                    py37_0    conda-forge
boost                     1.70.0           py37h9de70de_1    conda-forge
boost-cpp                 1.70.0               h8e57a91_2    conda-forge
bson                      0.5.9                      py_0    conda-forge
bzip2                     1.0.8                h516909a_2    conda-forge
ca-certificates           2019.11.28           hecc5488_0    conda-forge
cairo                     1.16.0            hfb77d84_1002    conda-forge
cerberus                  1.3.2                      py_0    conda-forge
certifi                   2019.11.28               py37_0    conda-forge
cffi                      1.13.2           py37h8022711_0    conda-forge
cftime                    1.0.4.2          py37hc1659b7_0    conda-forge
chardet                   3.0.4                 py37_1003    conda-forge
click                     7.0                        py_0    conda-forge
cloudpickle               1.2.2                      py_1    conda-forge
clusterutils              0.3.1                    py37_1    omnia
cmiles                    0.1.5                    py37_2    omnia
codecov                   2.0.15                     py_1    conda-forge
coverage                  5.0.3            py37h516909a_0    conda-forge
cryptography              2.8              py37h72c5cf5_1    conda-forge
curl                      7.68.0               hf8cf82a_0    conda-forge
cycler                    0.10.0                     py_2    conda-forge
cython                    0.29.15          py37he1b5a44_0    conda-forge
cytoolz                   0.10.1           py37h516909a_0    conda-forge
dask                      2.10.1                     py_0    conda-forge
dask-core                 2.10.1                     py_0    conda-forge
dask-jobqueue             0.7.0                      py_0    conda-forge
dbus                      1.13.6               he372182_0    conda-forge
decorator                 4.4.1                      py_0    conda-forge
defusedxml                0.6.0                      py_0    conda-forge
diff-match-patch          20181111                   py_0    conda-forge
distributed               2.10.0                     py_0    conda-forge
docopt                    0.6.2                      py_1    conda-forge
docutils                  0.16                     py37_0    conda-forge
entrypoints               0.3                   py37_1000    conda-forge
expat                     2.2.9                he1b5a44_2    conda-forge
fftw                      3.3.8           nompi_h7f3a6c3_1110    conda-forge
fftw3f                    3.3.4                         2    omnia
flake8                    3.7.9                    py37_0    conda-forge
fontconfig                2.13.1            h86ecdb6_1001    conda-forge
forcebalance              1.7.1                    py37_1    omnia
freetype                  2.10.0               he983fc9_1    conda-forge
fsspec                    0.6.2                      py_0    conda-forge
future                    0.18.2                   py37_0    conda-forge
gettext                   0.19.8.1          hc5be6a0_1002    conda-forge
glib                      2.58.3          py37h6f030ca_1002    conda-forge
gst-plugins-base          1.14.5               h0935bb2_2    conda-forge
gstreamer                 1.14.5               h36ae1b5_2    conda-forge
hdf4                      4.2.13            hf30be14_1003    conda-forge
hdf5                      1.10.5          nompi_h3c11f04_1104    conda-forge
heapdict                  1.0.1                      py_0    conda-forge
icu                       64.2                 he1b5a44_1    conda-forge
idna                      2.8                   py37_1000    conda-forge
imagesize                 1.2.0                      py_0    conda-forge
importlib_metadata        1.5.0                    py37_0    conda-forge
intervaltree              3.0.2                      py_0    conda-forge
ipykernel                 5.1.4            py37h5ca1d4c_0    conda-forge
ipython                   7.12.0           py37h5ca1d4c_0    conda-forge
ipython_genutils          0.2.0                      py_1    conda-forge
ipywidgets                7.5.1                      py_0    conda-forge
isort                     4.3.21                   py37_0    conda-forge
jedi                      0.14.1                   py37_0    conda-forge
jeepney                   0.4.2                      py_0    conda-forge
jinja2                    2.11.1                     py_0    conda-forge
jpeg                      9c                h14c3975_1001    conda-forge
jsonschema                3.2.0                    py37_0    conda-forge
jupyter                   1.0.0                      py_2    conda-forge
jupyter_client            5.3.4                    py37_1    conda-forge
jupyter_console           6.1.0                      py_0  
jupyter_core              4.6.2                    py37_0    conda-forge
keyring                   21.1.0                   py37_0    conda-forge
kiwisolver                1.1.0            py37hc9558a2_0    conda-forge
krb5                      1.16.4               h2fd8d38_0    conda-forge
latexcodec                2.0.0                      py_0    conda-forge
lazy-object-proxy         1.4.3            py37h516909a_1    conda-forge
ld_impl_linux-64          2.33.1               h53a641e_8    conda-forge
libblas                   3.8.0               14_openblas    conda-forge
libcblas                  3.8.0               14_openblas    conda-forge
libclang                  9.0.1           default_hde54327_0    conda-forge
libcurl                   7.68.0               hda55be3_0    conda-forge
libedit                   3.1.20170329      hf8c457e_1001    conda-forge
libffi                    3.2.1             he1b5a44_1006    conda-forge
libgcc-ng                 9.2.0                h24d8f2e_2    conda-forge
libgfortran-ng            7.3.0                hdf63c60_5    conda-forge
libgomp                   9.2.0                h24d8f2e_2    conda-forge
libiconv                  1.15              h516909a_1005    conda-forge
liblapack                 3.8.0               14_openblas    conda-forge
libllvm9                  9.0.1                hc9558a2_0    conda-forge
libnetcdf                 4.7.3           nompi_h9f9fd6a_101    conda-forge
libopenblas               0.3.7                h5ec1e0e_6    conda-forge
libpng                    1.6.37               hed695b0_0    conda-forge
libsodium                 1.0.17               h516909a_0    conda-forge
libspatialindex           1.9.3                he1b5a44_3    conda-forge
libssh2                   1.8.2                h22169c7_2    conda-forge
libstdcxx-ng              9.2.0                hdf63c60_2    conda-forge
libtiff                   4.1.0                hc3755c2_3    conda-forge
libuuid                   2.32.1            h14c3975_1000    conda-forge
libxcb                    1.13              h14c3975_1002    conda-forge
libxkbcommon              0.10.0               he1b5a44_0    conda-forge
libxml2                   2.9.10               hee79883_0    conda-forge
libxslt                   1.1.33               h31b3aaa_0    conda-forge
locket                    0.2.0                      py_2    conda-forge
lxml                      4.5.0            py37h7ec2d77_0    conda-forge
lz4-c                     1.8.3             he1b5a44_1001    conda-forge
lzo                       2.10              h14c3975_1000    conda-forge
markupsafe                1.1.1            py37h516909a_0    conda-forge
matplotlib                3.1.3                    py37_0    conda-forge
matplotlib-base           3.1.3            py37h250f245_0    conda-forge
mccabe                    0.6.1                      py_1    conda-forge
mdtraj                    1.9.3            py37h00575c5_0    conda-forge
mistune                   0.8.4           py37h516909a_1000    conda-forge
mmpbsa-py                 16.0                     pypi_0    pypi
mock                      3.0.5                    py37_0    conda-forge
more-itertools            8.2.0                      py_0    conda-forge
mpi                       1.0                       mpich    conda-forge
mpich                     3.3.2                hc856adb_0    conda-forge
mpiplus                   v0.0.1                py37_1000    conda-forge
msgpack-python            0.6.2            py37hc9558a2_0    conda-forge
nbconvert                 5.6.1                    py37_0    conda-forge
nbformat                  5.0.4                      py_0    conda-forge
ncurses                   6.1               hf484d3e_1002    conda-forge
netcdf-fortran            4.5.2           nompi_h09cde99_103    conda-forge
netcdf4                   1.5.3           nompi_py37hd35fb8e_102    conda-forge
networkx                  2.4                        py_0    conda-forge
nistdataselection         0.0.2+54.ge7f3dfc           dev_0    <develop>
notebook                  6.0.3                    py37_0    conda-forge
nspr                      4.25                 he1b5a44_0    conda-forge
nss                       3.47                 he751ad9_0    conda-forge
numexpr                   2.7.1            py37hb3f55d8_0    conda-forge
numpy                     1.18.1           py37h95a1406_0    conda-forge
numpydoc                  0.9.2                      py_0    conda-forge
olefile                   0.46                       py_0    conda-forge
openeye-toolkits          2019.10.2                py37_0    openeye
openff-evaluator          0.1.0                    py37_0    omnia/label/beta
openforcefield            0.6.0                    py37_1    omnia
openforcefields           1.0.0                    py37_0    omnia
openmm                    7.4.1           py37_cuda101_rc_1    omnia
openmmtools               0.19.0                   py37_1    omnia
openmoltools              0.8.5                    py37_0    omnia
openssl                   1.1.1d               h516909a_0    conda-forge
oset                      0.1.3                      py_1    conda-forge
packaging                 20.1                       py_0    conda-forge
packmol                   18.169               h6e990d7_1    conda-forge
pandas                    1.0.1            py37hb3f55d8_0    conda-forge
pandoc                    2.9.1.1                       0    conda-forge
pandocfilters             1.4.2                      py_1    conda-forge
parmed                    3.2.0                    pypi_0    pypi
parso                     0.5.2                      py_0    conda-forge
partd                     1.1.0                      py_0    conda-forge
pathtools                 0.1.2                      py_1    conda-forge
pcre                      8.44                 he1b5a44_0    conda-forge
pdb4amber                 1.7.dev0                 pypi_0    pypi
pdbfixer                  1.6                      py37_0    omnia
perl                      5.26.2            h516909a_1006    conda-forge
pexpect                   4.8.0                    py37_0    conda-forge
pickleshare               0.7.5                 py37_1000    conda-forge
pillow                    7.0.0            py37hefe7db6_0    conda-forge
pint                      0.10.1                     py_0    conda-forge
pip                       20.0.2                     py_2    conda-forge
pixman                    0.38.0            h516909a_1003    conda-forge
pluggy                    0.13.0                   py37_0    conda-forge
prometheus_client         0.7.1                      py_0    conda-forge
prompt_toolkit            3.0.3                      py_0    conda-forge
psutil                    5.6.7            py37h516909a_0    conda-forge
pthread-stubs             0.4               h14c3975_1001    conda-forge
ptyprocess                0.6.0                   py_1001    conda-forge
py                        1.8.1                      py_0    conda-forge
pybtex                    0.22.2                   py37_0    conda-forge
pybtex-docutils           0.2.2                    py37_0    conda-forge
pycairo                   1.19.0           py37h438ddbb_0    conda-forge
pycodestyle               2.5.0                      py_0    conda-forge
pycparser                 2.19                     py37_1    conda-forge
pydocstyle                5.0.2                      py_0    conda-forge
pyflakes                  2.1.1                      py_0    conda-forge
pygments                  2.5.2                      py_0    conda-forge
pylint                    2.4.4                    py37_0    conda-forge
pymbar                    3.0.5            py37hc1659b7_0    conda-forge
pyopenssl                 19.1.0                   py37_0    conda-forge
pyparsing                 2.4.6                      py_0    conda-forge
pyqt                      5.12.3           py37hcca6a23_1    conda-forge
pyqt5                     5.14.1                   pypi_0    pypi
pyqt5-sip                 4.19.18                  pypi_0    pypi
pyqtwebengine             5.12.1                   pypi_0    pypi
pyrsistent                0.15.7           py37h516909a_0    conda-forge
pysocks                   1.7.1                    py37_0    conda-forge
pytables                  3.6.1            py37h9f153d1_1    conda-forge
pytest                    5.3.5                    py37_1    conda-forge
pytest-cov                2.8.1                      py_0    conda-forge
python                    3.7.6                h357f687_2    conda-forge
python-dateutil           2.8.1                      py_0    conda-forge
python-jsonrpc-server     0.3.4                      py_0    conda-forge
python-language-server    0.31.7                   py37_0    conda-forge
pytraj                    2.0.5                    pypi_0    pypi
pytz                      2019.3                     py_0    conda-forge
pyxdg                     0.26                       py_0    conda-forge
pyyaml                    5.3              py37h516909a_0    conda-forge
pyzmq                     18.1.1           py37h1768529_0    conda-forge
qdarkstyle                2.8                        py_0    conda-forge
qt                        5.12.5               hd8c4c69_1    conda-forge
qtawesome                 0.7.0                      py_0    conda-forge
qtconsole                 4.6.0                      py_0    conda-forge
qtpy                      1.9.0                      py_0    conda-forge
rdkit                     2019.09.3        py37hb31dc5d_0    conda-forge
readline                  8.0                  hf8c457e_0    conda-forge
requests                  2.22.0                   py37_1    conda-forge
requests-mock             1.7.0                      py_0    conda-forge
rope                      0.16.0                     py_0    conda-forge
rtree                     0.9.4            py37h7b0cdae_0    conda-forge
sander                    16.0                     pypi_0    pypi
scipy                     1.4.1            py37h921218d_0    conda-forge
secretstorage             3.1.2                    py37_0    conda-forge
send2trash                1.5.0                      py_0    conda-forge
setuptools                45.2.0                   py37_0    conda-forge
six                       1.14.0                   py37_0    conda-forge
smirnoff99frosst          1.1.0                    py37_1    omnia
snowballstemmer           2.0.0                      py_0    conda-forge
sortedcontainers          2.1.0                      py_0    conda-forge
sphinx                    2.4.1                      py_0    conda-forge
sphinxcontrib-applehelp   1.0.1                      py_0    conda-forge
sphinxcontrib-bibtex      1.0.0                      py_0    conda-forge
sphinxcontrib-devhelp     1.0.1                      py_0    conda-forge
sphinxcontrib-htmlhelp    1.0.2                      py_0    conda-forge
sphinxcontrib-jsmath      1.0.1                      py_0    conda-forge
sphinxcontrib-qthelp      1.0.2                      py_0    conda-forge
sphinxcontrib-serializinghtml 1.1.3                      py_0    conda-forge
spyder                    4.0.1                    py37_2    conda-forge
spyder-kernels            1.8.1                    py37_1    conda-forge
sqlite                    3.30.1               hcee41ef_0    conda-forge
swig                      3.0.8                         0    omnia
tabulate                  0.8.6                      py_0    conda-forge
tblib                     1.6.0                      py_0    conda-forge
terminado                 0.8.3                    py37_0    conda-forge
testpath                  0.4.4                      py_0    conda-forge
tk                        8.6.10               hed695b0_0    conda-forge
toml                      0.10.0                     py_0    conda-forge
toolz                     0.10.0                     py_0    conda-forge
tornado                   6.0.3            py37h516909a_3    conda-forge
tqdm                      4.42.1                     py_0    conda-forge
traitlets                 4.3.3                    py37_0    conda-forge
typed-ast                 1.4.1            py37h516909a_0    conda-forge
ujson                     1.35            py37h516909a_1001    conda-forge
uncertainties             3.1.2                    py37_0    conda-forge
urllib3                   1.25.7                   py37_0    conda-forge
watchdog                  0.10.2                   py37_0    conda-forge
wcwidth                   0.1.8                      py_0    conda-forge
webencodings              0.5.1                      py_1    conda-forge
wheel                     0.34.2                     py_1    conda-forge
widgetsnbextension        3.5.1                    py37_0    conda-forge
wrapt                     1.11.2           py37h516909a_0    conda-forge
wurlitzer                 2.0.0                    py37_0    conda-forge
xmltodict                 0.12.0                     py_0    conda-forge
xorg-kbproto              1.0.7             h14c3975_1002    conda-forge
xorg-libice               1.0.10               h516909a_0    conda-forge
xorg-libsm                1.2.3             h84519dc_1000    conda-forge
xorg-libx11               1.6.9                h516909a_0    conda-forge
xorg-libxau               1.0.9                h14c3975_0    conda-forge
xorg-libxdmcp             1.1.3                h516909a_0    conda-forge
xorg-libxext              1.3.4                h516909a_0    conda-forge
xorg-libxrender           0.9.10            h516909a_1002    conda-forge
xorg-libxt                1.2.0                h516909a_0    conda-forge
xorg-renderproto          0.11.1            h14c3975_1002    conda-forge
xorg-xextproto            7.3.0             h14c3975_1002    conda-forge
xorg-xproto               7.0.31            h14c3975_1007    conda-forge
xz                        5.2.4             h14c3975_1001    conda-forge
yaml                      0.2.2                h516909a_1    conda-forge
yank                      0.25.2                   py37_1    omnia
yapf                      0.28.0                     py_0    conda-forge
zeromq                    4.3.2                he1b5a44_2    conda-forge
zict                      1.0.0                      py_0    conda-forge
zipp                      2.2.0                      py_0    conda-forge
zlib                      1.2.11            h516909a_1006    conda-forge
zstd                      1.4.4                h3b9ef0a_1    conda-forge

Additional context Here's an image of the molecules: image

jchodera commented 4 years ago

There is no way for an OpenMM Topology object to encode the chirality of the molecule since it only include connectivity and elements. This isn't a bug, but rather a limitation of the OpenMM Topology object.

Can you use a different way to get your system into the parameterization pipeline? How did you generate your simulation box? Do you have coordinates too?

jchodera commented 4 years ago

One idea: We could allow the user to specify an optional map of residue names to molecules that could be used to force assignment of molecules to any specified residues in the topology? This is an abuse of OpenMM's Topology format, but may be a convenient one.

ocmadin commented 4 years ago

This is part of mixture benchmark set that we're running via evaluator, so we'd have to make changes to evaluator system generation pipeline to avoid this. Since it's just a benchmark set, we'll probably just omit these molecules for now, and circle back to to it later.

jchodera commented 4 years ago

Since the evaluator uses an object model that cannot represent a mixture of enantiomers, you will absolutely need to make changes to the evaluator system generation pipeline if you ever want to represent systems containing more than one enantiomer of the same compound correctly.

My question for you and @SimonBoothroyd is "what would be the most convenient way for you to augment your representation to indicate chirality?" Is it via an alternative object representation, or would the simple suggestion above (of forcing assignment to specific molecules) be an easier path?

SimonBoothroyd commented 4 years ago

Since the evaluator uses an object model that cannot represent a mixture of enantiomers

Currently we do carry along the stereochemistry of the components in the system (as well as the relative amounts of the different enantiomers), however at some point we need to go from a list of OpenFF Molecule objects (created with stereochemical information) and a coordinate file to an OpenFF Topology and then onto a System object.

My preference would be for from_openmm to take an optional coordinates argument, from which the stereochemistry may be inferred.

davidlmobley commented 4 years ago

Seems like taking an optional coordinates argument would be a good solution to this problem. CC @j-wags and @trevorgokey