BondCharge virtual sites are not overriding correctly
See original GitHub issueDescribe the bug SMIRNOFF hierarchy rules are somewhat complicated for virtualsites. A virtualsite should only override another virtualsite if they match the same atoms[1], and have the same name and type.
To Reproduce
This code makes two vsites with the same name and type, which should apply to the same atoms, but in a different order:
from openff.toolkit.typing.engines.smirnoff import ForceField
from openff.toolkit.topology import Molecule
from openff.units import unit
from openmm import unit as omm_unit
mol = Molecule.from_mapped_smiles('[Cl:1][Na:2]')
ff = ForceField()
vsh = ff.get_parameter_handler('VirtualSites', {"version":0.3})
# Define two vsites that apply in opposite directions to the same atoms of the test molecule.
# The vsites may collide (since they have the same name), but they should be
# distinguishable in the output based on their `distance` values
vsh.add_parameter({'type':'BondCharge',
'smirks':'[Cl:1][Na:2]',
'match':'once',
'charge_increment':[0.100, -0.100] * unit.elementary_charge,
'distance': [0.1010] * unit.angstrom,
'name':'aaa'})
vsh.add_parameter({'type':'BondCharge',
'smirks':'[Na:1][Cl:2]',
'match':'once',
'charge_increment':[0.100, -0.100] * unit.elementary_charge,
'distance': [0.220] * unit.angstrom,
'name':'aaa'})
sys = ff.create_openmm_system(mol.to_topology())
# For each vsite, print out which particles are involved, and at which distance.
for vsite_idx in range(sys.getNumParticles()):
if not(sys.isVirtualSite(vsite_idx)):
continue
vsite = sys.getVirtualSite(vsite_idx)
vsite_parents = []
for vsite_parent_idx in range(vsite.getNumParticles()):
vsite_parent = vsite.getParticle(vsite_parent_idx)
vsite_parents.append(vsite_parent)
distance = vsite.getLocalPosition()[0].value_in_unit(omm_unit.angstrom)
print(vsite_parents, distance)
[0, 1] -0.101
The specific problems shown in this code are:
- The first vsite applies to atoms (0,1), and the second applies to atoms (1,0). Since the atoms are in a different order, I don’t think that one should overwrite the other, and so I’d expect both vsites should be in the output[1]. Instead only a single vsite is in the output.
- If the second virtualsite (with distance
0.220
) MIGHT overwrite the first (with distance0.101
), then I expect that the output should EITHER have one vsite with each distance, OR one vsite with0.220
. Instead we get just one vsite with0.101
.
[1] It’s not specifically mentioned in the SMIRNOFF spec, but I assume this means “one vsite will overwrite another if they match the same atoms in the same order”
Computing environment (please complete the following information):
- Mac OS
- OFFTK topology biopolymer refactor branch
Issue Analytics
- State:
- Created 2 years ago
- Comments:11 (4 by maintainers)
Top Results From Across the Web
Virtual sites — OpenFF Toolkit 0.10.1+0.g88b03bf9.dirty ...
The "name" attribute encodes whether the virtual site to be added should override an existing virtual site of the same type (e.g. hierarchy...
Read more >Release History — openforcefield 0.8.3 documentation
The "name" attribute encodes whether the virtual site to be added should override an existing virtual site of the same type (e.g. hierarchy...
Read more >Virtual Double-System Single-Box for Absolute Dissociation ...
We describe a step-by-step protocol for the computation of absolute dissociation free energy with GROMACS code and PLUMED library, ...
Read more >MATCH: An Atom- Typing Toolset for Molecular Mechanics ...
Published online 2011 Nov 1. doi: 10.1002/jcc.21963 ... However, these force fields do not contain all the required parameters to represent drug-like ...
Read more >19 CFR Part 19 -- Customs Warehouses, Container ... - eCFR
(4) The warehouse proprietor does not provide secured facilities or properly safeguard merchandise within the bonded warehouse;.
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
So we have agreement on what should happen. It might be harder to modify things in a way that realizes that.
@j-wags and I hacked on this for a while today. We successfully identified several places in the code that do not fix it and at least one place that might be the best place to attack. Below is an ugly diff tracking some places in the code we poked around in - right now we think the failure is a result of
if same_atoms and same_vsite and diff_keys:
evaluating to True inside of_reduce_virtual_particles_to_sites
, and at the end of today we’re at a loss as to how it could be patched to get the behavior we want. It might take a more extensive rewrite to handle these cross-interactions, I don’t currently have the energy or familiarity to help past that.Yeah, when I was looking at that failing test I was scratching my head at first. There are likely a few more tests than can hammer things out. The tests use a very symmetric problem, and I wouldn’t be surprised if your clever NaCl representation tricks show up in other places.
In any case, I am glad you are sitting down and really trying to hammer out a thorough test suite. As you can see, I only wrote the “does it work, in theory” tests, and you are making sure it works in practice. Much appreciated!