question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Water LibraryCharges aren't used in output OpenMM systems in Sage

See original GitHub issue

Describe the bug

Hi there, I’m not certain if this is a bug, but I noticed it when I was trying to do stuff with water. It looks like water LibraryCharges are shipped with OpenFF 2.0.0, but it doesn’t look like they get used when creating an OpenMM system? I have no clue why because the smirks pattern matches with chemical_environment_matches, unless there’s a special case exception – and in that case I don’t understand why it’s in the force field.

To Reproduce

In [2]: # %load mwe.py
   ...: import openff.toolkit
   ...: from openff.toolkit.typing.engines.smirnoff import ForceField
   ...: from openff.toolkit.topology import Molecule
   ...:
   ...: print(openff.toolkit.__version__)
   ...:
   ...: ff = ForceField("openff-2.0.0.offxml")
   ...: handler = ff.get_parameter_handler("LibraryCharges")
   ...: water_parameters = handler.parameters[-2:]
   ...: print("water parameters:")
   ...: print(water_parameters)
   ...:
   ...: water = Molecule.from_smiles("O")
   ...:
   ...: print("Matches")
   ...: for parameter in water_parameters:
   ...:     print(water.chemical_environment_matches(parameter.smirks))
   ...:
   ...: system = ff.create_openmm_system(water.to_topology())
   ...:
   ...: print("OpenMM charges")
   ...: nbforce = system.getForces()[0]
   ...: for i in range(3):
   ...:     print(water.atoms[i].element, nbforce.getParticleParameters(i)[0])
   ...:
   ...: print("AM1BCC charges")
   ...: water.assign_partial_charges("am1bcc")
   ...: print(water.partial_charges)
0.10.2+9.gc29c9359
water parameters:
[<LibraryChargeType with smirks: [#1]-[#8X2H2+0:1]-[#1]  charge1: -0.834 e  id: q-tip3p-O  >, <LibraryChargeType with smirks: [#1:1]-[#8X2H2+0]-[#1]  charge1: 0.417 e  id: q-tip3p-H  >]
Matches
[(0,), (0,)]
[(1,), (2,)]
Warning: No principle axes found during inertial alignment
OpenMM charges
<Element oxygen> -0.7850599884986877 e
<Element hydrogen> 0.39252999424934387 e
<Element hydrogen> 0.39252999424934387 e
AM1BCC charges
Warning: No principle axes found during inertial alignment
[-0.78505999  0.39252999  0.39252999] e

Output

To break the above script down, basically:

  • 2.0.0 has the charges -0.834 e for oxygen ([#1]-[#8X2H2+0:1]-[#1]) and 0.417 e for hydrogen ([#1:1]-[#8X2H2+0]-[#1])
  • Both smirks patterns find their appropriate atom matches in a molecule Molecule.from_smiles("O")
  • If I create a system with create_openmm_system, I find instead that I get the same charges as OpenFF gives you for AM1BCC, suggesting that it’s ignoring the LibraryCharges.

Computing environment (please complete the following information):

  • Operating system
  • Toolkit version: master commit c29c935935edd1cda8ebe2458744315b580a1caa
  • Output of running conda list
# Name                    Version                   Build  Channel
abseil-cpp                20210324.1           he49afe7_0    conda-forge
amberlite                 16.0                     pypi_0    pypi
ambertools                21.0             py38h334589e_0    conda-forge
amberutils                21.0                     pypi_0    pypi
appdirs                   1.4.4                    pypi_0    pypi
appnope                   0.1.2            py38h50d1736_1    conda-forge
argon2-cffi               20.1.0           py38h5406a74_2    conda-forge
arpack                    3.7.0                hefb7bc6_2    conda-forge
arrow-cpp                 4.0.1           py38hbf72296_1_cpu    conda-forge
astunparse                1.6.2                      py_0    conda-forge
async_generator           1.10                       py_0    conda-forge
attrs                     21.2.0             pyhd8ed1ab_0    conda-forge
aws-c-cal                 0.5.9                h0df4f8a_0    conda-forge
aws-c-common              0.5.11               h0d85af4_0    conda-forge
aws-c-event-stream        0.2.7                h4fd1b92_8    conda-forge
aws-c-io                  0.10.1               h9daffe9_0    conda-forge
aws-checksums             0.1.11               h9daffe9_6    conda-forge
aws-sdk-cpp               1.8.186              h8d473ab_2    conda-forge
backcall                  0.2.0              pyh9f0ad1d_0    conda-forge
backports                 1.0                        py_2    conda-forge
backports.functools_lru_cache 1.6.4              pyhd8ed1ab_0    conda-forge
black                     21.7b0                   pypi_0    pypi
bleach                    3.3.0              pyh44b312d_0    conda-forge
blosc                     1.21.0               he49afe7_0    conda-forge
boost                     1.74.0           py38h692b87f_3    conda-forge
boost-cpp                 1.74.0               hff03dee_4    conda-forge
brotli                    1.0.9                h046ec9c_4    conda-forge
brotlipy                  0.7.0           py38h5406a74_1001    conda-forge
bson                      0.5.9                      py_0    conda-forge
bzip2                     1.0.8                h0d85af4_4    conda-forge
c-ares                    1.17.1               h0d85af4_1    conda-forge
ca-certificates           2021.10.8            h033912b_0    conda-forge
cached-property           1.5.2                hd8ed1ab_1    conda-forge
cached_property           1.5.2              pyha770c72_1    conda-forge
cachetools                4.2.2                    pypi_0    pypi
cairo                     1.16.0            he43a7df_1008    conda-forge
certifi                   2021.10.8        py38h50d1736_1    conda-forge
cffi                      1.14.5           py38ha97d567_0    conda-forge
chardet                   4.0.0            py38h50d1736_1    conda-forge
click                     8.0.1                    pypi_0    pypi
codecov                   2.1.11             pyhd3deb0d_0    conda-forge
colorama                  0.4.4              pyh9f0ad1d_0    conda-forge
coverage                  5.5              py38h96a0964_0    conda-forge
cryptography              3.4.7            py38h1fa4640_0    conda-forge
curl                      7.77.0               hb861fe1_0    conda-forge
cycler                    0.10.0                     py_2    conda-forge
cython                    0.29.23          py38ha048514_0    conda-forge
decorator                 4.4.2                      py_0    conda-forge
defusedxml                0.7.1              pyhd8ed1ab_0    conda-forge
entrypoints               0.3             pyhd8ed1ab_1003    conda-forge
fftw                      3.3.9           nompi_h02cd531_101    conda-forge
fontconfig                2.13.1            h10f422b_1005    conda-forge
freetype                  2.10.4               h4cff582_1    conda-forge
gettext                   0.19.8.1          h7937167_1005    conda-forge
gflags                    2.2.2             hb1e8313_1004    conda-forge
glog                      0.5.0                h25b26a9_0    conda-forge
greenlet                  1.1.0            py38ha048514_0    conda-forge
grpc-cpp                  1.38.0               hd641d5f_1    conda-forge
h5py                      3.2.1           nompi_py38h9a16e60_100    conda-forge
hdf4                      4.2.15               hefd3b78_3    conda-forge
hdf5                      1.10.6          nompi_hc5d9132_1114    conda-forge
icu                       68.1                 h74dc148_0    conda-forge
idna                      2.10               pyh9f0ad1d_0    conda-forge
importlib-metadata        4.5.0            py38h50d1736_0    conda-forge
importlib_metadata        4.5.0                hd8ed1ab_0    conda-forge
importlib_resources       5.1.4              pyhd8ed1ab_0    conda-forge
iniconfig                 1.1.1              pyh9f0ad1d_0    conda-forge
ipykernel                 5.5.5            py38h6c79ece_0    conda-forge
ipython                   7.24.1           py38h6c79ece_0    conda-forge
ipython_genutils          0.2.0                      py_1    conda-forge
ipywidgets                7.6.3              pyhd3deb0d_0    conda-forge
isort                     5.9.3                    pypi_0    pypi
jbig                      2.1               h0d85af4_2003    conda-forge
jedi                      0.18.0           py38h50d1736_2    conda-forge
jinja2                    3.0.1              pyhd8ed1ab_0    conda-forge
jpeg                      9d                   hbcb3906_0    conda-forge
jsonschema                3.2.0              pyhd8ed1ab_3    conda-forge
jupyter_client            6.1.12             pyhd8ed1ab_0    conda-forge
jupyter_core              4.7.1            py38h50d1736_0    conda-forge
jupyterlab_pygments       0.1.2              pyh9f0ad1d_0    conda-forge
jupyterlab_widgets        1.0.0              pyhd8ed1ab_1    conda-forge
khronos-opencl-icd-loader 2022.01.04           h0d85af4_0    conda-forge
kiwisolver                1.3.1            py38hd9c93a9_1    conda-forge
krb5                      1.19.1               hcfbf3a7_0    conda-forge
lcms2                     2.12                 h577c468_0    conda-forge
lerc                      2.2.1                h046ec9c_0    conda-forge
libblas                   3.9.0                9_openblas    conda-forge
libcblas                  3.9.0                9_openblas    conda-forge
libcurl                   7.77.0               hf45b732_0    conda-forge
libcxx                    11.1.0               habf9029_0    conda-forge
libdeflate                1.7                  h35c211d_5    conda-forge
libedit                   3.1.20191231         h0678c8f_2    conda-forge
libev                     4.33                 haf1e3a3_1    conda-forge
libevent                  2.1.10               hddc9c9b_3    conda-forge
libffi                    3.3                  h046ec9c_2    conda-forge
libgfortran               5.0.0           9_3_0_h6c81a4c_22    conda-forge
libgfortran5              9.3.0               h6c81a4c_22    conda-forge
libglib                   2.68.2               hd556434_2    conda-forge
libiconv                  1.16                 haf1e3a3_0    conda-forge
liblapack                 3.9.0                9_openblas    conda-forge
libnetcdf                 4.8.0           nompi_hb4d10b0_103    conda-forge
libnghttp2                1.43.0               h07e645a_0    conda-forge
libopenblas               0.3.15          openmp_h5e1b9a4_1    conda-forge
libpng                    1.6.37               h7cec526_2    conda-forge
libprotobuf               3.16.0               hcf210ce_0    conda-forge
libsodium                 1.0.18               hbcb3906_1    conda-forge
libssh2                   1.9.0                h52ee1ee_6    conda-forge
libthrift                 0.14.1               hab56fdc_1    conda-forge
libtiff                   4.3.0                h1167814_1    conda-forge
libutf8proc               2.6.1                h35c211d_0    conda-forge
libwebp-base              1.2.0                h0d85af4_2    conda-forge
libxcb                    1.13              h35c211d_1003    conda-forge
libxml2                   2.9.12               h93ec3fd_0    conda-forge
libzip                    1.7.3                hbc046b2_0    conda-forge
llvm-openmp               11.1.0               hda6cdc1_1    conda-forge
lz4-c                     1.9.3                h046ec9c_0    conda-forge
markupsafe                2.0.1            py38h96a0964_0    conda-forge
matplotlib-base           3.4.2            py38h6152e83_0    conda-forge
matplotlib-inline         0.1.2              pyhd8ed1ab_2    conda-forge
mdtraj                    1.9.6            py38h63a7c91_0    conda-forge
mendeleev                 0.9.0              pyh8a188c0_0    conda-forge
mistune                   0.8.4           py38h5406a74_1003    conda-forge
mmpbsa-py                 16.0                     pypi_0    pypi
mock                      4.0.3            py38h50d1736_1    conda-forge
more-itertools            8.8.0              pyhd8ed1ab_0    conda-forge
msgpack-python            1.0.2            py38hd9c93a9_1    conda-forge
mypy-extensions           0.4.3                    pypi_0    pypi
nbclient                  0.5.3              pyhd8ed1ab_0    conda-forge
nbconvert                 6.0.7            py38h50d1736_3    conda-forge
nbformat                  5.1.3              pyhd8ed1ab_0    conda-forge
nbval                     0.9.6              pyh9f0ad1d_0    conda-forge
ncurses                   6.2                  h2e338ed_4    conda-forge
nest-asyncio              1.5.1              pyhd8ed1ab_0    conda-forge
netcdf-fortran            4.5.3           nompi_hff36437_104    conda-forge
networkx                  2.5.1              pyhd8ed1ab_0    conda-forge
nglview                   3.0.1              pyh59e0f4d_0    conda-forge
notebook                  6.4.0              pyha770c72_0    conda-forge
numexpr                   2.7.3            py38h1588c1c_0    conda-forge
numpy                     1.20.3           py38had91d27_1    conda-forge
ocl_icd_wrapper_apple     1.0.0                hbcb3906_0    conda-forge
olefile                   0.46               pyh9f0ad1d_1    conda-forge
openeye-toolkits          2020.2.2                 py38_0    openeye
openff-forcefields        2.0.0              pyh6c4a22f_0    conda-forge
openff-toolkit            0.10.0+38.ge6b0124b           dev_0    <develop>
openff-units              0.1.4              pyh6c4a22f_0    conda-forge
openff-utilities          0.1.1              pyh6c4a22f_0    conda-forge
openjpeg                  2.4.0                h6e7aa92_1    conda-forge
openmm                    7.6.0           py38h0498e66_0_khronos    conda-forge
openssl                   1.1.1l               h0d85af4_0    conda-forge
orc                       1.6.8                hfe4c36d_0    conda-forge
packaging                 20.9               pyh44b312d_0    conda-forge
packmol                   20.010               h508aa58_0    conda-forge
packmol-memgen            1.1.0rc0                 pypi_0    pypi
pandas                    1.2.4            py38h1f261ad_0    conda-forge
pandoc                    2.14.0.1             h0d85af4_0    conda-forge
pandocfilters             1.4.2                      py_1    conda-forge
parmed                    3.4.1            py38ha048514_0    conda-forge
parquet-cpp               1.5.1                         2    conda-forge
parso                     0.8.2              pyhd8ed1ab_0    conda-forge
pathspec                  0.9.0                    pypi_0    pypi
pcre                      8.44                 hb1e8313_0    conda-forge
pdb4amber                 20.1                     pypi_0    pypi
perl                      5.32.1          0_h0d85af4_perl5    conda-forge
pexpect                   4.8.0              pyh9f0ad1d_2    conda-forge
pickleshare               0.7.5                   py_1003    conda-forge
pillow                    8.2.0            py38h83525de_1    conda-forge
pint                      0.17               pyhd8ed1ab_0    conda-forge
pip                       21.1.2             pyhd8ed1ab_0    conda-forge
pixman                    0.40.0               hbcb3906_0    conda-forge
plotly                    4.14.3             pyh44b312d_0    conda-forge
pluggy                    0.13.1           py38h50d1736_4    conda-forge
prometheus_client         0.11.0             pyhd8ed1ab_0    conda-forge
prompt-toolkit            3.0.18             pyha770c72_0    conda-forge
psutil                    5.8.0            py38h96a0964_1    conda-forge
pthread-stubs             0.4               hc929b4f_1001    conda-forge
ptyprocess                0.7.0              pyhd3deb0d_0    conda-forge
py                        1.10.0             pyhd3deb0d_0    conda-forge
py-cpuinfo                8.0.0              pyhd8ed1ab_0    conda-forge
pyarrow                   4.0.1           py38hf787c1d_1_cpu    conda-forge
pycairo                   1.20.1           py38h53d24c6_0    conda-forge
pycparser                 2.20               pyh9f0ad1d_2    conda-forge
pydantic                  1.8.2            py38h96a0964_0    conda-forge
pyfiglet                  0.8.post1                  py_0    conda-forge
pygments                  2.9.0              pyhd8ed1ab_0    conda-forge
pyopenssl                 20.0.1             pyhd8ed1ab_0    conda-forge
pyparsing                 2.4.7              pyh9f0ad1d_0    conda-forge
pyrsistent                0.17.3           py38h5406a74_2    conda-forge
pysocks                   1.7.1            py38h50d1736_3    conda-forge
pytables                  3.6.1            py38hfb086ad_3    conda-forge
pytest                    6.2.4            py38h50d1736_0    conda-forge
pytest-cov                2.12.1             pyhd8ed1ab_0    conda-forge
python                    3.8.10          h0e5c897_0_cpython    conda-forge
python-dateutil           2.8.1                      py_0    conda-forge
python_abi                3.8                      1_cp38    conda-forge
pytraj                    2.0.6                    pypi_0    pypi
pytz                      2021.1             pyhd8ed1ab_0    conda-forge
pyyaml                    5.4.1            py38h5406a74_0    conda-forge
pyzmq                     22.1.0           py38hd3b92b6_0    conda-forge
qcelemental               0.20.0             pyhd8ed1ab_0    conda-forge
qcengine                  0.19.0             pyhd8ed1ab_0    conda-forge
qcportal                  0.14.0                     py_1    conda-forge
rdkit                     2021.03.3        py38hba24be9_0    conda-forge
re2                       2021.06.01           he49afe7_0    conda-forge
readline                  8.1                  h05e3726_0    conda-forge
regex                     2021.8.21                pypi_0    pypi
reportlab                 3.5.67           py38hf6ac518_0    conda-forge
requests                  2.25.1             pyhd3deb0d_0    conda-forge
retrying                  1.3.3                      py_2    conda-forge
sander                    16.0                     pypi_0    pypi
scipy                     1.6.3            py38h431c0a8_0    conda-forge
send2trash                1.5.0                      py_0    conda-forge
setuptools                49.6.0           py38h50d1736_3    conda-forge
six                       1.16.0             pyh6c4a22f_0    conda-forge
smirnoff99frosst          1.1.0              pyh44b312d_0    conda-forge
snappy                    1.1.8                hb1e8313_3    conda-forge
sqlalchemy                1.4.17           py38h96a0964_0    conda-forge
sqlite                    3.35.5               h44b9ce1_0    conda-forge
terminado                 0.10.0           py38h50d1736_0    conda-forge
testpath                  0.5.0              pyhd8ed1ab_0    conda-forge
tk                        8.6.10               h0419947_1    conda-forge
toml                      0.10.2             pyhd8ed1ab_0    conda-forge
tomli                     1.2.1                    pypi_0    pypi
tornado                   6.1              py38h5406a74_1    conda-forge
tqdm                      4.61.0             pyhd8ed1ab_0    conda-forge
traitlets                 5.0.5                      py_0    conda-forge
typing-extensions         3.10.0.0             hd8ed1ab_0    conda-forge
typing_extensions         3.10.0.0           pyha770c72_0    conda-forge
urllib3                   1.26.5             pyhd8ed1ab_0    conda-forge
wcwidth                   0.2.5              pyh9f0ad1d_2    conda-forge
webencodings              0.5.1                      py_1    conda-forge
wheel                     0.36.2             pyhd3deb0d_0    conda-forge
widgetsnbextension        3.5.1            py38h50d1736_4    conda-forge
xmltodict                 0.12.0                     py_0    conda-forge
xorg-kbproto              1.0.7             h35c211d_1002    conda-forge
xorg-libice               1.0.10               h0d85af4_0    conda-forge
xorg-libsm                1.2.3             h0d85af4_1000    conda-forge
xorg-libx11               1.7.2                h0d85af4_0    conda-forge
xorg-libxau               1.0.9                h35c211d_0    conda-forge
xorg-libxdmcp             1.1.3                h35c211d_0    conda-forge
xorg-libxext              1.3.4                h0d85af4_1    conda-forge
xorg-libxt                1.2.1                h0d85af4_2    conda-forge
xorg-xextproto            7.3.0             h35c211d_1002    conda-forge
xorg-xproto               7.0.31            h35c211d_1007    conda-forge
xz                        5.2.5                haf1e3a3_1    conda-forge
yaml                      0.2.5                haf1e3a3_0    conda-forge
zeromq                    4.3.4                h1c7c35f_0    conda-forge
zipp                      3.4.1              pyhd8ed1ab_0    conda-forge
zlib                      1.2.11            h7795811_1010    conda-forge
zstd                      1.5.0                h582d3a0_0    conda-forge

Additional context

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:8 (6 by maintainers)

github_iconTop GitHub Comments

5reactions
j-wagscommented, Feb 25, 2022

The minimal fix I can find is changing unique=True to False here. Then this works with three-atom SMIRKS.

This change was introduced in #1036, which was merged Aug 13, shortly before the Sage release (Aug 16 2021). The change didn’t make it into a stable release until toolkit version 0.10.1, on October 26.

So the Sage fitting should be unaffected. But users using OFFTK 0.10.1 or 0.10.2 would have been getting AM1BCC water when they should have been getting TIP3P.

The most straightforward fix for this would be to

  • change the line linked above to have LibraryChargeHandler.find_matches NOT uniquify by default
  • add a test that ensures multiple variants of TIP3P parameters are applied correctly
  • cut an 0.10.3 release asap with a fix
  • loudly communicate the bug in the release notes and announcement

Then a subsequent PR could see if we can safely recover the performance gains from #1036.

This sucks, but I’m glad we found it before any more time had passed. I’ve been working on vsite tests for a long time, and I kept running into this vague unease about SMIRKS with untagged/“non-capturing” atoms, and I’ve been really waffling over whether that vague unease is a big waste of time. Well, this proves that it’s not!

0reactions
davidlmobleycommented, Feb 28, 2022

Yeah, I tried to think back and am not coming up with anything, so you may be right. One way to approach checking it would be to throw the switch and see if it results in energy differences/different numbers of parameters being applied.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Release History — OpenFF Toolkit 0.10.3+0.g757813d1.dirty ...
PR #1200: Fixes a bug (Issue #1199) in which library charges were ignored in some force fields, including openff-2.0.0 code name “Sage.” This...
Read more >
OpenFF Toolkit Documentation - Open Force Field Software
The implementation enables support for models using off-site charges, including 4- and 5-point water models, in addition to lone pair modeling.
Read more >
3. Running Simulations - OpenMM Documentation
Let's begin with our first example of an OpenMM script. It loads a PDB file called input.pdb that defines a biomolecular system, parameterizes...
Read more >
4. Model Building and Editing - OpenMM Documentation
Or perhaps you want to simulate the system in explicit water, but the PDB file ... To use it, create a Modeller object,...
Read more >
AmberPrmtopFile — OpenMM Python API 8.0.0.dev-b01017d ...
Construct an OpenMM System representing the topology described by this ... is used to make water molecules rigid, then water hydrogens are not...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found