-
Notifications
You must be signed in to change notification settings - Fork 2
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Tests for Receptor-Ligand Restraints #9
Tests for Receptor-Ligand Restraints #9
Conversation
…nitTests into feature_boresch_restraints
Thanks for this. Actually, the approach should be to test the from Sire.Tools.OpenMMMD import * Just to note that with @chryswoods' feat_web we are beginning the work of bring the tests into the main Sire repository to help keep things in sync. For space reasons, we will also be moving to an approach of keeping test input files elsewhere (on a remote server) and downloading them dynamically during testing. (The new Sire has functionality to do this.) This won't affect this PR. I will just test against your SIre PR to validate that it works and merge when happy. We can then move it into the main repo along with other tests for Cheers. |
Thanks very much for the comments - I will update this to use functionality from OpenMMMD.py shortly. Cheers. |
No problem. I'm just trying to update the |
Okay, I've re-written the test as follows: #
# Sire script to compare Sire and SOMD single point energies
#
from nose.tools import assert_almost_equal
from Sire.Tools import OpenMMMD
# Overwrite default parameters.
OpenMMMD.topfile = OpenMMMD.Parameter("topfile", "../io/combRules/toluene_methane.top",
"""File name of the topology file containing the system to be simulated.""")
OpenMMMD.crdfile = OpenMMMD.Parameter("crdfile", "../io/combRules/toluene_methane.crd",
"""File name of the coordinate file containing the coordinates of the
system to be simulated.""")
OpenMMMD.morphfile = OpenMMMD.Parameter("morphfile", "../io/combRules/toluene_methane.pert",
"""Name of the morph file containing the perturbation to apply to the system.""")
OpenMMMD.andersen = OpenMMMD.Parameter("thermostat", False,
"""Whether or not to use the Andersen thermostat (needed for NVT or NPT simulation).""")
OpenMMMD.barostat = OpenMMMD.Parameter("barostat", False, """Whether or not to use a barostat (needed for NPT simulation).""")
OpenMMMD.cutoff_type = OpenMMMD.Parameter("cutoff type", "nocutoff", """The cutoff method to use during the simulation.""")
OpenMMMD.constraint = OpenMMMD.Parameter("constraint", "none", """The constraint model to use during dynamics.""")
OpenMMMD.platform = OpenMMMD.Parameter("platform", "Reference", """Which OpenMM platform should be used to perform the dynamics.""")
def test_combining_rules(rule, verbose=False):
# Set the combining rule.
OpenMMMD.combining_rules = OpenMMMD.Parameter("combining rules", rule,
"""Combining rules to use for the non-bonded interactions.""")
amber = OpenMMMD.Amber()
(molecules, space) = amber.readCrdTop(OpenMMMD.crdfile.val, OpenMMMD.topfile.val)
system = OpenMMMD.createSystemFreeEnergy(molecules)
system = OpenMMMD.setupForceFieldsFreeEnergy(system, space)
if OpenMMMD.debug_seed.val:
ranseed = OpenMMMD.debug_seed.val
else:
ranseed = OpenMMMD.RanGenerator().randInt(100000, 1000000)
moves = OpenMMMD.setupMovesFreeEnergy(system, ranseed,
OpenMMMD.gpu.val, OpenMMMD.lambda_val.val)
# Get energy from Sire
nrg_sire = system.energy()
# Get energy from SOMD
mdmoves = moves.moves()[0]
integrator = mdmoves.integrator()
nrg_somd = integrator.getPotentialEnergy(system)
nrg_diff = (nrg_sire - nrg_somd).value()
if verbose:
print ("~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~")
if rule == 'arithmetic':
print ("TESTING ARITHMETIC COMBINING RULES")
else:
print ("TESTING GEOMETRIC COMBINING RULES")
print ("~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~")
print ("* The energy from Sire is: %s" %nrg_sire)
print ("* The energy from SOMD is: %s" % nrg_somd)
if rule == 'arithmetic':
print (" For the arithmetic combining rules the single point energy difference between sire and somd at lambda %s is %s " % (OpenMMMD.lambda_val.val, nrg_diff) )
else:
print (" For the geometric combining rules the single point energy difference between sire and somd at lambda %s is %s " % (OpenMMMD.lambda_val.val, nrg_diff) )
assert_almost_equal(nrg_diff, 0.0, 4)
if __name__ == '__main__':
test_combining_rules("arithmetic", True)
test_combining_rules("geometric", True) Interestingly, the test now fails for geometric combining rules with the following output:
I'll check to see if I've done something wrong. (Perhaps I'm missing a change to one of the default parameters.) If not, this is a good example of why you should test against Looking at the code in the original test vs that in the current
hydrogen_mass_repartitioning_factor = Parameter("hydrogen mass repartitioning factor",None,
"""If not None and is a number, all hydrogen atoms in the molecule will
have their mass increased by the input factor. The atomic mass of the heavy atom
bonded to the hydrogen is decreased to keep the mass constant.""")
hydrogen_mass_repartitioning_factor = \
Parameter('hydrogen mass repartitioning factor', 1.0,
f'If larger than {HMR_MIN} (maximum is {HMR_MAX}), all hydrogen '
'atoms in the molecule will have their mass increased by this '
'factor. The atomic mass of the heavy atom bonded to the '
'hydrogen is decreased to keep the total mass constant '
'(except when this would lead to a heavy atom to be lighter '
'than a minimum mass).') Looking at the
Those edits are fairly old. I'm wondering if the combining rules in the current version of I've also noted that @chryswoods has removed |
Interestingly, the SOMD energies do agree, but the Sire energies do not. Perhaps something needs to be set for the Sire system. I'll look in the functions within the old test script to see if anything has been edited when setting up the system. |
Hum that's concerning. I can see how something could have slipped by because we are not using in current projects forcefields with geometric combining rules. This could have an impact on QUBE work done currently by @djcole56 and @bieniekmateusz . I would expect the Sire single point energies to change for the same molecule when changing between arithmetic and geometric combining rules so the test likely fails because the test doesn't actually update SOMD to use geometric combining rules for the second set of single point energy calculations |
Thanks for the heads up, but I believe we've switched all our FF work to arithmetic combining rules now so shouldn't affect any current projects. |
Thanks for the example @lohedges - I've updated my script to match. |
Great. I just overrode the same parameters that were edited in the Cheers. |
Thanks. I've already made sure the overridden parameters are the ones required for my tests (and no others) and that my tests run as before. Cheers. |
Humm @fjclark could you investigate the test failure ? We don't want users to inadvertently use geometric combining rules if those have been broken |
@jmichel80 of course. |
Note that I've just updated the test script shown in my comment above. A few of the parameters that I needed to edit in |
Okay, I've figured it out, and the current version of SOMD is indeed broken. As @jmichel80 alluded to, combining rules are indeed not being set in SOMD. Comparing with the hard-coded version of
I can add this to |
Thanks for tracking the issue. Edits done OpenMMMD.py by Sofia must have been overwritten at some point. There is no support for geometric combining rules in vanilla somd currently. |
If I I'll fix in |
Yes, it looks like the edits were made in an earlier PR, then reverted following some breaking changes to SOMD. The correct C++ changes were reimplemented in the PR I link to above, but |
@lohedges can you please confirm that the script you posted is completely updated (as my version fails for the arithmetic test)? Thanks. |
Hmmm, same here. Will check what parameter is missing and update. Apologies. |
Okay, easy fix, not all parameters were being updated in the |
Hi, I would it be possible to merge this in now that the Boresch restraints PR has been merged into the Sire devel? I've updated it to be consistent with recent changes to Sire and I've checked that it passes. Thanks. |
Hi @fjclark. I don't think this test suite is currently being run. In fact, I don't think the |
Thanks - yes, I'll merge your changes for I will look at the test and see how to move it into the new pytests test directory. I am going to keep these |
Great, thanks very much both. |
Hello,
This accompanies my recent pull request to Sire, and implements a test for Boresch restraints. I've also implemented a test for the multiple distance restraints which are already present in Sire.
I've followed the style of test_combRules.py, copying over most of OpenMMMD.py and using this to set up systems with and without restraints, then testing for an expected energy difference.
Thanks,
Finlay