Page 1 of 1

debuggin 'All Forces must agree on whether to use a cutoff' on CUDA

Posted: Tue Nov 19, 2019 2:08 am
by lewiso1
Hi all,

I've got stuck at the `simulation` creation stage, but only when using `platform = Platform.getPlatformByName('CUDA')`, which causes the following Exception:

Code: Select all

integrator = LangevinIntegrator(310*kelvin, 1/picosecond, 0.002*picoseconds)
#platform = Platform.getPlatformByName('CPU')
platform = Platform.getPlatformByName('CUDA')
simulation = Simulation(complex_structure.topology, complex_system, integrator, platform)

>>> Exception: All Forces must agree on whether to use a cutoff
Changing platform to CPU allows the simulation to be created, and will run without error.

So, question is: which forces use a cutoff? And how can I ensure they all agree?

Maybe overkill but here are some details that might be relevant:

Code: Select all

for i in complex_system.getForces():
    print(i.usesPeriodicBoundaryConditions(), i)


>>> False <simtk.openmm.openmm.HarmonicBondForce; proxy of <Swig Object of type 'OpenMM::HarmonicBondForce *' at 0x7f78bd04f270> >
>>> False <simtk.openmm.openmm.HarmonicAngleForce; proxy of <Swig Object of type 'OpenMM::HarmonicAngleForce *' at 0x7f78bd04f930> >
>>> False <simtk.openmm.openmm.PeriodicTorsionForce; proxy of <Swig Object of type 'OpenMM::PeriodicTorsionForce *' at 0x7f78bd04f390> >
>>> True <simtk.openmm.openmm.NonbondedForce; proxy of <Swig Object of type 'OpenMM::NonbondedForce *' at 0x7f78bd04f1e0> >
>>> False <simtk.openmm.openmm.CMMotionRemover; proxy of <Swig Object of type 'OpenMM::CMMotionRemover *' at 0x7f78bd04f660> >
>>> False <simtk.openmm.openmm.CustomNonbondedForce; proxy of <Swig Object of type 'OpenMM::CustomNonbondedForce *' at 0x7f78bd04f570> >
>>> False <simtk.openmm.openmm.MonteCarloMembraneBarostat; proxy of <Swig Object of type 'OpenMM::MonteCarloMembraneBarostat *' at 0x7f78bd04f360> >
>>> True <simtk.openmm.openmm.CustomExternalForce; proxy of <Swig Object of type 'OpenMM::CustomExternalForce *' at 0x7f78bd04f300> >
I've added a CustomNonbondedForce with the same cutoff distance as the NonBondedForce, as well as the CustomExternalForce.

Code: Select all

print([i for i in complex_system.getForces()][3].getCutoffDistance())

print([i for i in complex_system.getForces()][5].getCutoffDistance())

>>> 0.9 nm
>>> 0.9 nm


Thanks for your time
lewis

Re: debuggin 'All Forces must agree on whether to use a cutoff' on CUDA

Posted: Tue Nov 19, 2019 11:59 am
by peastman
This looks like a conflict between the NonbondedForce and the CustomNonbondedForce. Print out getNonbondedMethod() for each of them. One of them is using method 0 (NoCutoff), while the other is using something that involves a cutoff.

Re: debuggin 'All Forces must agree on whether to use a cutoff' on CUDA

Posted: Tue Nov 19, 2019 2:42 pm
by lewiso1
Spot on, thanks so much Peter.

Ultimately my error was that I normally add pairwise interaction groups to the CustomNonbondedForce to implement a short-range repulsive potential that prevents aggregation of drugs. Anyway while trying to get a minimal example I reduced the number of drugs to 1, meaning there was no second group, which then broke the CustomNonbondedForce.


If anyone comes up against the original exception but for a different reason, it can be fixed with:
drugForce.setNonbondedMethod(2) where 2 refers to CutoffPeriodic
cheers