Skip to content

Commit

Permalink
Correct OpenMM API call
Browse files Browse the repository at this point in the history
  • Loading branch information
avirshup committed Jun 28, 2017
1 parent 68fec25 commit 2255ed3
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 11 deletions.
5 changes: 3 additions & 2 deletions moldesign/_tests/test_io.py
Original file line number Diff line number Diff line change
Expand Up @@ -87,8 +87,9 @@ def test_pdb_with_missing_chains(propane_pdb):
"""
mol = propane_pdb

pbmol = mdt.interfaces.mol_to_pybel(mol)
assert len(pbmol.atoms) == mol.num_atoms
if not mdt.interfaces.openbabel.force_remote:
pbmol = mdt.interfaces.mol_to_pybel(mol)
assert len(pbmol.atoms) == mol.num_atoms

pmedmol = mdt.interfaces.mol_to_parmed(mol)
assert len(pmedmol.atoms) == mol.num_atoms
Expand Down
20 changes: 11 additions & 9 deletions moldesign/models/openmm.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,8 @@ class OpenMMPotential(MMBase, opm.OpenMMPickleMixin):
Note that, while a dummy integrator is assigned, a different context will
be created for any MD calculations.
:ivar sim: openmm simulation object
:type sim: simtk.openmm.app.Simulation
Attributes:
sim (simtk.openmm.app.Simulation): OpenMM simulation object (once created)
"""
# NEWFEATURE: need to set/get platform (and properties, e.g. number of threads)
DEFAULT_PROPERTIES = ['potential_energy', 'forces']
Expand Down Expand Up @@ -352,23 +352,25 @@ def _get_platform(self):
preference = ['CUDA', 'OpenCL', 'CPU', 'Reference']
from_lower = {x.lower(): x for x in preference}

properties = None
properties = {}

if self.params.compute_platform.lower() == 'auto':
for platname in preference:
try:
platform = openmm.Platform.getPlatformByName(platname)
self.params.compute_platform = platname.lower()
except Exception: # it just throws "Exception" unfortunately
continue
else:
raise moldesign.NotSupportedError("Likely OpenMM installation error. "
"none of the expected platforms were found: "
+ ', '.join(preference))
else:
self.params.compute_platform = platname.lower()
break

raise moldesign.NotSupportedError("Likely OpenMM installation error. "
"none of the expected platforms were found: "
+ ', '.join(preference))
else:
platform = openmm.Platform.getPlatformByName(from_lower[self.params.compute_platform])

if self.params.compute_platform == 'cpu' and self.params.num_cpus > 0:
properties['numThreads'] = self.params.num_cpus
properties['Threads'] = str(self.params.num_cpus)

return platform, properties

0 comments on commit 2255ed3

Please sign in to comment.