problems in python inteface

Dear Lammps users:
I have installed the latest lammps version with its python interface (lammps-22Aug18). I have tested it with the instruction in the manual. However, I cannot execute the fix python/invoke function correctly in the examples. The error code is:

python end_of_step_callback here “”"
from future import print_function
from lammps import lammps

def end_of_step_callback(lmp):
L = lammps(ptr=lmp)
t = L.extract_global(“ntimestep”, 0)
print("### END OF STEP ###", t)

def post_force_callback(lmp, v):
L = lammps(ptr=lmp)
t = L.extract_global(“ntimestep”, 0)
print("### POST_FORCE ###", t)
“”"

fix 1 all nve
fix 2 all python/invoke 50 end_of_step end_of_step_callback
fix 3 all python/invoke 50 post_force post_force_callback

The error message is

Exception AttributeError: “‘lammps’ object has no attribute ‘lmp’” in <bound method lammps.del of <lammps.lammps object at 0x2aae33f19f90>> ignored

In fact, in python, if I type

from lammps import lammps
lmp = lammps(ptr=lmpptr)
natoms = lmp.get_natoms()
It will tell me that name ‘lmpptr’ is not defined.

Can you give me some suggestions? Thank you!

Shijun Zhao

Dear Lammps users:
I have installed the latest lammps version with its python interface (lammps-22Aug18). I have tested it with the instruction in the manual. However, I cannot execute the fix python/invoke

[…]

The error message is

Exception AttributeError: “‘lammps’ object has no attribute ‘lmp’” in <bound method lammps.del of <lammps.lammps object at 0x2aae33f19f90>> ignored

this error message would happen, if you have not installed the python wrapper correctly or did not update your PYTHONPATH variable accordingly, in case you installed it into a non-default location.

In fact, in python, if I type

from lammps import lammps
lmp = lammps(ptr=lmpptr)
natoms = lmp.get_natoms()
It will tell me that name ‘lmpptr’ is not defined.

this is to be expected. you didn’t define lmpptr it is not passed as an argument into the (main) function.

Can you give me some suggestions? Thank you!

your example works for me with the 15 November 2018 version of LAMMPS.

axel.