setParameter leads to AttributeError

The functionality of OpenMM will (eventually) include everything that one would need to run modern molecular simulation.
POST REPLY
User avatar
martin spichty
Posts: 10
Joined: Thu Jul 23, 2009 12:36 am

setParameter leads to AttributeError

Post by martin spichty » Sun Sep 20, 2020 7:20 am

Hi, all,

I am experiencing a problem with OpenMM, version -7.4.2-py37_cuda101_rc1. I tested the platforms CPU and CUDA, both have the same issue: I want to update a global parameter with context.setParamter() which fails with the following error:

Traceback (most recent call last):
File "openmm_run.py", line 106, in <module>
simulation.context.setParamter('ref', 4.0)
File "xxx/lib/python3.7/site-packages/simtk/openmm/openmm.py", line 18255, in <lambda>
__getattr__ = lambda self, name: _swig_getattr(self, Context, name)
File "xxx/lib/python3.7/site-packages/simtk/openmm/openmm.py", line 74, in _swig_getattr
return _swig_getattr_nondynamic(self, class_type, name, 0)
File "xxx/lib/python3.7/site-packages/simtk/openmm/openmm.py", line 69, in _swig_getattr_nondynamic
return object.__getattr__(self, name)
AttributeError: type object 'object' has no attribute '__getattr__'

My python input is given below. Any ideas would be great!! Thanks!
Best,
Martin

***
# Build system
system = psf.createSystem(params, nonbondedMethod=inputs.coulomb,
nonbondedCutoff=inputs.r_off*nanometers,
constraints=inputs.cons,
ewaldErrorTolerance=inputs.ewald_Tol)

# Add custom force
xpos = 5.0
ypos = 0.0
zpos = 4.6
r6 = CustomExternalForce('1000*(sqrt((x-x0)^2+(y-y0)^2+(z-z0)^2)-ref)^2')
r6.addGlobalParameter('ref', 4.0)
r6.addPerParticleParameter('x0')
r6.addPerParticleParameter('y0')
r6.addPerParticleParameter('z0')
atom2 = 4000
r6.addParticle(atom2, [xpos, ypos, zpos])
system.addForce(r6)

# Set platform
platform = Platform.getPlatformByName('CUDA')
prop = dict(CudaPrecision='single')

# Build simulation context
integrator = LangevinIntegrator(inputs.temp*kelvin, inputs.fric_coeff/picosecond, inputs.dt*picoseconds)
simulation = Simulation(psf.topology, system, integrator, platform, prop)
simulation.context.setPositions(crd.positions)
simulation.context.setParamter('ref', 0.0)
stop

User avatar
martin spichty
Posts: 10
Joined: Thu Jul 23, 2009 12:36 am

Re: setParameter leads to AttributeError

Post by martin spichty » Sun Sep 20, 2020 7:47 am

An add-on:
This error seems related to the use of set.Parameter() in the context of a Simulation object.
The following works just fine:

# Build system
system = psf.createSystem(params, nonbondedMethod=inputs.coulomb,
nonbondedCutoff=inputs.r_off*nanometers,
constraints=inputs.cons,
ewaldErrorTolerance=inputs.ewald_Tol)

# Add custom force
xpos = 5.0
ypos = 0.0
zpos = 4.6
r6 = CustomExternalForce('1000*(sqrt((x-x0)^2+(y-y0)^2+(z-z0)^2)-ref)^2')
r6.addGlobalParameter('ref', 4.0)
r6.addPerParticleParameter('x0')
r6.addPerParticleParameter('y0')
r6.addPerParticleParameter('z0')
atom2 = 4000
r6.addParticle(atom2, [xpos, ypos, zpos])
system.addForce(r6)

# Set platform
platform = Platform.getPlatformByName('CUDA')
prop = dict(CudaPrecision='single')

# Build simulation context
integrator = LangevinIntegrator(inputs.temp*kelvin, inputs.fric_coeff/picosecond, inputs.dt*picoseconds)
context = Context(system, integrator,platform,prop)
context.setPositions(crd.positions)
context.setParameter('ref', 1.0)

User avatar
Peter Eastman
Posts: 2546
Joined: Thu Aug 09, 2007 1:25 pm

Re: setParameter leads to AttributeError

Post by Peter Eastman » Mon Sep 21, 2020 1:10 pm

You have a typo in your code:

Code: Select all

 simulation.context.setParamter('ref', 0.0)
It should be setParameter(), not setParamter().

User avatar
martin spichty
Posts: 10
Joined: Thu Jul 23, 2009 12:36 am

Re: setParameter leads to AttributeError

Post by martin spichty » Tue Sep 22, 2020 12:48 am

How embarrassing!!! :o
Thank you, Peter!!

POST REPLY