Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

bonds don't work with plugins #1591

Closed
astatt opened this issue Jul 24, 2023 · 1 comment · Fixed by #1594
Closed

bonds don't work with plugins #1591

astatt opened this issue Jul 24, 2023 · 1 comment · Fixed by #1594
Labels
bug Something isn't working

Comments

@astatt
Copy link
Contributor

astatt commented Jul 24, 2023

Description

The bond python class isn't working with plugins because it is missing the string that let's you redefine where the module is implemented, see pair python class for reference. The fix should be fairly simple, see attached python snippet with proposed changes for the bond class.

I am happy to supply a bug fix.

Script

class Bond(Force):
    """Base class bond force.

    `Bond` is the base class for all bond forces.

    Warning:
        This class should not be instantiated by users. The class can be used
        for `isinstance` or `issubclass` checks.
    """

    def __init__(self):
        super().__init__()

    def _attach_hook(self):
        """Create the c++ mirror class."""
        if isinstance(self._simulation.device, hoomd.device.CPU):
            cpp_cls = getattr(_md, self._cpp_class_name)
        else:
            cpp_cls = getattr(_md, self._cpp_class_name + "GPU")

        self._cpp_obj = cpp_cls(self._simulation.state._cpp_sys_def)
 

changed to:

class Bond(Force):
    """Base class bond force.

    `Bond` is the base class for all bond forces.

    Warning:
        This class should not be instantiated by users. The class can be used
        for `isinstance` or `issubclass` checks.
    """

    # Module where the C++ class is defined. Reassign this when developing an
    # external plugin.
    _ext_module = _md

    def __init__(self):
        super().__init__()

    def _attach_hook(self):
        """Create the c++ mirror class."""
        if isinstance(self._simulation.device, hoomd.device.CPU):
            cpp_cls = getattr(self._ext_module, self._cpp_class_name)
        else:
            cpp_cls = getattr(self._ext_module, self._cpp_class_name + "GPU")

        self._cpp_obj = cpp_cls(self._simulation.state._cpp_sys_def)

Input files

No response

Output

When developing a plugin with a new bond potential, it will compile but then not correctly find it, i.e when wanting to use or import "plugin_name.bond.BondPotentialName" it will instead look for "hoomd.bond.BondPotentialName". The simple inclusion of "_ext_module = _md" that can be overwritten by the plugin fixes this issue.

Expected output

Plugins should be able to develop bond potentials the same way as pair potentials.

Platform

CPU, GPU, Linux, macOS

Installation method

Compiled from source

HOOMD-blue version

4.0.1

Python version

3.10

@astatt astatt added the bug Something isn't working label Jul 24, 2023
@joaander
Copy link
Member

Thank you for reporting this. I would welcome a pull request implementing the _ext_module solution. Could you do the same for angles, dihedrals, impropers, and special pairs for completeness?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants