Coder Social home page Coder Social logo

Comments (4)

mattwthompson avatar mattwthompson commented on June 11, 2024

Probably a type mismatch - no, it's converted correctly when passed to OpenMM

tolerance = InputAttribute(
docstring="The energy tolerance to which the system should be minimized.",
type_hint=unit.Quantity,
default_value=10 * unit.kilojoules / unit.mole,
)

from openff-evaluator.

mattwthompson avatar mattwthompson commented on June 11, 2024

OpenMM doesn't actually check the dimensionality of that argument. This block runs without error, even though I expected it to error:

import openmm
import openmm.unit


simulation = interchange.to_openmm_simulation(
    integrator=openmm.LangevinMiddleIntegrator(
        300 * openmm.unit.kelvin,
        1 / openmm.unit.picosecond,
        1.0,
    )
)

simulation.minimizeEnergy(10 * openmm.unit.kilojoule_per_mole / openmm.unit.nanometer)
simulation.minimizeEnergy(10 * openmm.unit.kilojoule_per_mole)
simulation.minimizeEnergy(10 * openmm.unit.picosecond)
simulation.minimizeEnergy(10 * openmm.unit.kelvin)

from openff-evaluator.

mattwthompson avatar mattwthompson commented on June 11, 2024

This one is confusing to me. Switching the units over to $\dfrac{kJ}{mol * nm}$ might fix it, but if that was the problem the above code block should be throwing errors (and this would have been an issue years ago).

I don't think it's likely that the conversion drops the nanometer in the denominator:

In [1]: import openmm.unit

In [2]: 10 * openmm.unit.kilojoule_per_mole / openmm.unit.nanometer
Out[2]: Quantity(value=10, unit=kilojoule/(nanometer*mole))

In [3]: from openff.units import Quantity, unit

In [4]: from openff.units.openmm import to_openmm

In [5]: to_openmm(Quantity("10 kilojoule/mol/nanometer"))
Out[5]: Quantity(value=10.0, unit=kilojoule/(nanometer*mole))

In [6]: Quantity("10 kilojoule/mol/nanometer").to_openmm()
Out[6]: Quantity(value=10.0, unit=kilojoule/(nanometer*mole))

from openff-evaluator.

mattwthompson avatar mattwthompson commented on June 11, 2024

This can be reproduced with openmm==8.1.0beta, but no earlier versions. Until builds were made of this release, I didn't have an easy way of accessing these changes. This behavior change is attributed to openmm/openmm#2972, though I don't believe that's the cause. Previously, no unit checks happened and I don't see how changing the default value of an argument would introduce new logic. I tried digging deeper, but most of the code his obfuscated by the nature of being SWIG-generated. Anyway,

from openff.toolkit import Molecule, ForceField

import openmm
import openmm.unit


molecule = Molecule.from_smiles("OC[C@H](O)[C@H]1OC(=O)C(O)=C1O")
molecule.generate_conformers()

interchange = ForceField("openff-2.1.0.offxml").create_interchange(molecule.to_topology())

simulation = interchange.to_openmm_simulation(
    integrator=openmm.LangevinMiddleIntegrator(
        300 * openmm.unit.kelvin,
        1 / openmm.unit.picosecond,
        1.0,
    )
)

simulation.minimizeEnergy(10 * openmm.unit.kilojoule_per_mole / openmm.unit.nanometer)
simulation.minimizeEnergy(10 * openmm.unit.kilojoule_per_mole)
simulation.minimizeEnergy(10 * openmm.unit.picosecond)
simulation.minimizeEnergy(10 * openmm.unit.kelvin)
$ python repro.py
Traceback (most recent call last):
  File "/Users/mattthompson/software/openff-evaluator/repro.py", line 21, in <module>
    simulation.minimizeEnergy(10 * openmm.unit.kilojoule_per_mole)
  File "/Users/mattthompson/mambaforge/envs/openmm-beta/lib/python3.11/site-packages/openmm/app/simulation.py", line 143, in minimizeEnergy
    mm.LocalEnergyMinimizer.minimize(self.context, tolerance, maxIterations, reporter)
  File "/Users/mattthompson/mambaforge/envs/openmm-beta/lib/python3.11/site-packages/openmm/openmm.py", line 12476, in minimize
    tolerance = tolerance.value_in_unit(unit.kilojoules_per_mole/unit.nanometer)
                ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/mattthompson/mambaforge/envs/openmm-beta/lib/python3.11/site-packages/openmm/unit/quantity.py", line 626, in value_in_unit
    val = self.in_units_of(unit)
          ^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/mattthompson/mambaforge/envs/openmm-beta/lib/python3.11/site-packages/openmm/unit/quantity.py", line 662, in in_units_of
    raise TypeError('Unit "%s" is not compatible with Unit "%s".' % (self.unit, other_unit))
TypeError: Unit "kilojoule/mole" is not compatible with Unit "kilojoule/(nanometer*mole)".

from openff-evaluator.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.