Skip to content

Pickling a callback function with access to the LAMMPS instance itself #354

@raynol-dsouza

Description

@raynol-dsouza

in.simple.txt

As discussed with @jan-janssen, LammpsLibrary at the moment cannot be used as follows:

from pylammpsmpi import LammpsLibrary

def callback(caller, ntimestep, nlocal, tag, x, f):
    lmp = caller[0]
    print(f"energy_pot = {lmp.get_thermo('pe')}")

lmp = LammpsLibrary(cores=4,
                    oversubscribe=False,
                    working_directory=".",
                    client=None,
                    cmdargs=None)

lmp.file("in.simple")
lmp.fix(f"test all external pf/callback 1 1")
lmp.set_fix_external_callback("test", callback, [lmp])
lmp.run(0)

The objective here is to use LAMMPS' fix external command to do some math in the callback function using properties from the LAMMPS instance.

It works without any issues with lammps.lammps.

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions