[lammps-users] Unable to call

Hi,

I have been using Pylammps to run lammps code.

Here I am trying to call piar_style python inside the Pylammps functions as follows

granular = granular_lammps_module()
granular.file(“Hooke_potential.lmp”)

However, I get the following error

TypeError: str returned non-string (type str)
ERROR: Calling ‘check_units’ function failed (…/pair_python.cpp:340)
Last command: pair_coeff * * py_pot.LJCut lj1

But when I run the same Hooke_potential.lmp from the command line using

lmp_serial < Hooke_potential.lmp

It works. I can’t understand where is the problem.

I have attached my file for reference

script_1.py (476 Bytes)

Hooke_potential.lmp (3.78 KB)

py_pot.py (2.16 KB)

you failed to mention which LAMMPS version and which Python version you are using. this is crucial information.
I can run the attached input with the current LAMMPS development branch (i.e. git master branch) and python 3.8.7 without issues.

axel.

Hi,

It says python 3.8.5 and Lammps version as LAMMPS (29 Oct 2020)

you should try the latest patch release version from 10 March 2021. possibly this error is due to a bug that has been fixed since.
since the stable release from a year ago we have done some significant internal refactoring of the C++ and Python code in LAMMPS and also expanded the internal unit testing for C++ and Python code and in that process found and fixed quite a few issues with either part of the code that don’t show up when running the simple examples.

Hi Axel,

Thanks for the suggestion. But now I am facing a problem with the compilation.Here are the steps I followed

  1. git pull
  2. make purge
  3. make package-update

the make serial and make mpi works and it shows the updated version, however since I need to use python package, I tried to install in shared mode
“sudo make mode=shared serial”

But I get the following error

/usr/bin/x86_64-linux-gnu-ld: final link failed: Bad value
collect2: error: ld returned 1 exit status
Makefile:101: recipe for target ‘liblammps_serial.so’ failed
make[2]: *** [liblammps_serial.so] Error 1
make[2]: Leaving directory ‘/opt/lammps/src/Obj_shared_serial’
Makefile:195: recipe for target ‘serial’ failed
make[1]: *** [serial] Error 2
make[1]: Leaving directory ‘/opt/lammps/src’
Makefile:195: recipe for target ‘serial’ failed
make: *** [serial] Error 2