{"action":"created","issue":{"url":"https://api.github.com/repos/pandegroup/openmm/issues/1321","labels_url":"https://api.github.com/repos/pandegroup/openmm/issues/1321/labels{/name}","comments_url":"https://api.github.com/repos/pandegroup/openmm/issues/1321/comments","events_url":"https://api.github.com/repos/pandegroup/openmm/issues/1321/events","html_url":"https://github.com/pandegroup/openmm/issues/1321","id":124912028,"number":1321,"title":"minimize is very slow","user":{"login":"isjoung","id":7530585,"avatar_url":"https://avatars.githubusercontent.com/u/7530585?v=3","gravatar_id":"","url":"https://api.github.com/users/isjoung","html_url":"https://github.com/isjoung","followers_url":"https://api.github.com/users/isjoung/followers","following_url":"https://api.github.com/users/isjoung/following{/other_user}","gists_url":"https://api.github.com/users/isjoung/gists{/gist_id}","starred_url":"https://api.github.com/users/isjoung/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/isjoung/subscriptions","organizations_url":"https://api.github.com/users/isjoung/orgs","repos_url":"https://api.github.com/users/isjoung/repos","events_url":"https://api.github.com/users/isjoung/events{/privacy}","received_events_url":"https://api.github.com/users/isjoung/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":1,"created_at":"2016-01-05T07:30:07Z","updated_at":"2016-01-05T07:44:42Z","closed_at":null,"body":"Hi,\r\nFirst, I like to appreciate the efforts of developers for maintaining this nice project. Currently, I am using openmm for minimizing various conformations of a molecule. However, it seems that the native minimizer is very slow for some reason.\r\n  \r\nI have two examples below for comparing minimization methods. I used a single CPU thread.\r\n\r\nThe first one uses the native minimizer.\r\n```python\r\nimport os\r\nos.environ['OPENMM_CPU_THREADS'] = '1'\r\nfrom simtk.openmm.app import *\r\nfrom simtk.openmm import *\r\nfrom simtk.unit import *\r\nimport numpy as np\r\n\r\nprmtop = AmberPrmtopFile('model.prmtop')\r\ninpcrd = AmberInpcrdFile('model.inpcrd')\r\nsystem = prmtop.createSystem(nonbondedMethod=NoCutoff,implicitSolvent=GBn2, nonbondedCutoff=999.0*nanometer, constraints=HBonds)\r\nintegrator = LangevinIntegrator(300*kelvin, 1/picosecond, 0.002*picoseconds)\r\nsimulation = Simulation(prmtop.topology, system, integrator)\r\nsimulation.context.setPositions(inpcrd.positions)\r\nsimulation.minimizeEnergy(tolerance=Quantity(value=10.0,unit=kilojoule/mole),maxIterations=20)\r\nst = simulation.context.getState(getPositions=True,getEnergy=True)\r\nprint st.getPotentialEnergy()\r\n```\r\n\r\nThe second one uses scipy's L-BFGS-B minimizer\r\n```python\r\nimport os\r\nos.environ['OPENMM_CPU_THREADS'] = '1'\r\nfrom simtk.openmm.app import *\r\nfrom simtk.openmm import *\r\nfrom simtk.unit import *\r\nimport numpy as np\r\nfrom scipy import optimize\r\n\r\nprmtop = AmberPrmtopFile('model.prmtop')\r\ninpcrd = AmberInpcrdFile('model.inpcrd')\r\nsystem = prmtop.createSystem(nonbondedMethod=NoCutoff, implicitSolvent=GBn2, nonbondedCutoff=999.0*nanometer, constraints=HBonds)\r\nintegrator = LangevinIntegrator(300*kelvin, 1/picosecond, 0.002*picoseconds)\r\nsimulation = Simulation(prmtop.topology, system, integrator)\r\npos = np.array( inpcrd.positions.value_in_unit(nanometer) )\r\ncon = simulation.context\r\n\r\ndef target_function(xyz):\r\n    con.setPositions(xyz.reshape(-1,3))\r\n    state = con.getState(getEnergy=True, getForces=True)\r\n    frc = state.getForces(asNumpy=True)\r\n    ene = state.getPotentialEnergy().value_in_unit(kilojoule_per_mole)\r\n    frc = frc.value_in_unit(kilojoule_per_mole/nanometer)\r\n    return ene, -frc.flatten()\r\n\r\nresults = optimize.minimize(target_function, pos, method='L-BFGS-B',\r\n                            jac=True, options=dict(maxiter=20, disp=True, gtol=0.1))\r\n```\r\n\r\nThis is the result\r\n\r\nmeasure | script1 | script2\r\n-------- | ------------ | -------------\r\nTime | 2m9.3s | 30.5s\r\nEnergy | -7778.68 kJ/mol | -8693.76 kJ/mol\r\n\r\nThe native minimizer is worse in terms of both speed and performance.\r\nCan anyone tell me what could be wrong?"},"comment":{"url":"https://api.github.com/repos/pandegroup/openmm/issues/comments/168925873","html_url":"https://github.com/pandegroup/openmm/issues/1321#issuecomment-168925873","issue_url":"https://api.github.com/repos/pandegroup/openmm/issues/1321","id":168925873,"user":{"login":"rmcgibbo","id":641278,"avatar_url":"https://avatars.githubusercontent.com/u/641278?v=3","gravatar_id":"","url":"https://api.github.com/users/rmcgibbo","html_url":"https://github.com/rmcgibbo","followers_url":"https://api.github.com/users/rmcgibbo/followers","following_url":"https://api.github.com/users/rmcgibbo/following{/other_user}","gists_url":"https://api.github.com/users/rmcgibbo/gists{/gist_id}","starred_url":"https://api.github.com/users/rmcgibbo/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/rmcgibbo/subscriptions","organizations_url":"https://api.github.com/users/rmcgibbo/orgs","repos_url":"https://api.github.com/users/rmcgibbo/repos","events_url":"https://api.github.com/users/rmcgibbo/events{/privacy}","received_events_url":"https://api.github.com/users/rmcgibbo/received_events","type":"User","site_admin":false},"created_at":"2016-01-05T07:44:42Z","updated_at":"2016-01-05T07:44:42Z","body":"Can you try turning off the HBond constraints and see what happens? That makes it a lot trickier for the minimizer."}}