OpenBioSim / sire

Sire Molecular Simulations Framework
https://sire.openbiosim.org
GNU General Public License v3.0
39 stars 11 forks source link

[BUG] AttributeError: 'EMLEEngine' object has no attribute 'get_forces' #196

Closed Lactoria-cornuta closed 4 months ago

Lactoria-cornuta commented 4 months ago

Describe the bug When I try to reproduce the OpenMM-ML section of EMLE tutorial at https://github.com/OpenBioSim/sire/blob/feature_emle/doc/source/tutorial/partXX/01_emle.rst#interfacing-with-openmm-ml

the line emle_force, interpolation_force = engine.get_forces() gives me AttributeError: 'EMLEEngine' object has no attribute 'get_forces'

I can still get the emle force with emle_force = d._d._omm_mols.getSystem().getForce(0) after creating the dynamics object, but then I encounter AttributeError: module 'sire.qm' has no attribute 'zero_charge'. Does the tutorial describe some unimplemented features?

To reproduce import sire as sr from emle.calculator import EMLECalculator calculator = EMLECalculator(backend=None, device="cpu") mols = sr.load_test_files("ala.crd", "ala.top") mols, engine = sr.qm.emle(mols, mols[0], calculator, "7.5A", 20) engine.get_forces()

OS: Ubuntu 20.04 Python: 3.10.14 Sire: 2024.1.0.dev from openbiosim/label/emle

lohedges commented 4 months ago

Could you please try recreating your conda environment? The API for sire-emle is currently unstable so this function is only available in our most recent conda build, i.e. either of those available here.

lohedges commented 4 months ago

I've just created the environment myself and see:

In [1]: import sire as sr

In [2]: help(sr.qm.zero_charge)
Help on function _zero_charge in module sire.qm._utils:

_zero_charge(mols, qm_atoms, map=None)
    Zero the charge for the QM atoms in the system.

    Parameters
    ----------

    mols : sire.system.System
        The molecular system.

    qm_atoms : str, int, list, molecule view/collection etc.
        Any valid search string, atom index, list of atom indicies,
        or molecule view/container that can be used to select
        qm_atoms from 'mols'.

    Returns
    -------

    mols : sire.system.System
        The molecular system with the QM atom charges zeroed.

In [3]: help(sr.legacy.Convert._SireOpenMM.EMLEEngine.get_forces)
Help on function _get_openmm_forces in module sire.qm._emle:

_get_openmm_forces(self)
    Get the OpenMM forces for this engine. The first force is the actual
    EMLEForce, which uses a CustomCPPForceImpl to calculate the electrostatic
    embedding force. The second is a null CustomBondForce that can be used to
    add a "lambda_emle" global parameter to a context to allow the force to be
    scaled.

    Returns
    -------

    emle_force : openmm.Force
        The EMLEForce object to compute the electrostatic embedding force.

    interpolation_force : openmm.CustomBondForce
        A null CustomBondForce object that can be used to add a "lambda_emle"
        global parameter to an OpenMM context. This allows the electrostatic
        embedding force to be scaled.
lines 1-19/19 (END)
Lactoria-cornuta commented 4 months ago

Recreating the environment fixed the issue for me. Thank you!

lohedges commented 4 months ago

No problem. For now assume that the tutorials always refer to the latest version of the code, so check for updates when reading anything new. I currently delete all old conda packages so the only ones available will be up to date.