Having issue to run ASE's LAMMPSlib on a cluster (CentOS)

Hi everyone,

I have successfully compiled and installed a static local version of LAMMPS with python pkg on the cluster following the instructions on this webpage.

However I cannot run the ASE example using ase.calculators.lammpslib.LAMMPSlib

The error codes are following:

Traceback (most recent call last):
File “ase_test.py”, line 15, in
print("Energy ", NiH.get_potential_energy())
File “~/.local/lib/python3.8/site-packages/ase/atoms.py”, line 731, in get_potential_energy
energy = self._calc.get_potential_energy(self)
File “~/.local/lib/python3.8/site-packages/ase/calculators/calculator.py”, line 709, in get_potential_energy
energy = self.get_property(‘energy’, atoms)
File “~/.local/lib/python3.8/site-packages/ase/calculators/calculator.py”, line 737, in get_property
self.calculate(atoms, [name], system_changes)
File “~/.local/lib/python3.8/site-packages/ase/calculators/lammpslib.py”, line 356, in calculate
self.propagate(atoms, properties, system_changes, 0)
File “~/.local/lib/python3.8/site-packages/ase/calculators/lammpslib.py”, line 377, in propagate
self.start_lammps()
File “~/.local/lib/python3.8/site-packages/ase/calculators/lammpslib.py”, line 630, in start_lammps
self.lmp = lammps(self.parameters.lammps_name, self.cmd_args,
File “~/.local/lib/python3.8/site-packages/lammps/core.py”, line 150, in init
self.lib = CDLL(libpath,RTLD_GLOBAL)
File “/projects/community/python/3.8.5/gc563/lib/python3.8/ctypes/init.py”, line 373, in init
self._handle = _dlopen(self._name, mode)
OSError: liblammps.so: cannot open shared object file: No such file or directory

Modules I am loading:

module use /projects/community/modulefiles

module load intel/17.0.4 python/3.8.5-gc563

Any suggestions to solve this issue?

The python wrapper requires a shared library version.

Which specific instructions did you follow (that website lists multiple different ways) and how did you confirm that the installation was successful?

Difficult to say without knowing more details including the exact LAMMPS version that you are trying to install.

Which specific instructions did you follow (that website lists multiple different ways) and how did you confirm that the installation was successful?

mkdir build
cd build
cmake -C …/cmake/presets/basic.cmake -D BUILD_LIBS=on
-D LAMMPS_EXCEPTIONS=on -D PKG_PYTHON=on …/cmake
cmake --build .
cmake --install .

The python wrapper requires a shared library version.

I’ve tried that with -D BUILD_SHARED_LIBS=on, but it throw me following errors:

[ 98%] Linking CXX shared library liblammps.so
/usr/bin/ld: /projects/community/python/3.8.5/gc563/lib/libpython3.8.a(call.o): relocation R_X86_64_32 against `.rodata.str1.8’ can not be used when making a shared object; recompile with -fPIC

So your python installation is the problem. As the error message indicates it must be either compiled as a shared library, too, or with the -fPIC flag, so that it can be used to either link to or create a shared LAMMPS library. Without there is no chance and unlike your claim, the installation was not successful.

I used the python module on the cluster (module load python/3.8.5-gc563), because that’s where my ASE packagesite was installed in.

And I also tried to set the -fPIC flag, didn’t work out

cmake -C …/cmake/presets/basic.cmake -D CMAKE_C_FLAGS=-fPIC -D CMAKE_CXX_FLAGS=-fPIC -D PYTHON_EXECUTABLE=/projects/community/python/3.8.5/gc563/bin/python3 -D BUILD_LIB=yes -D LAMMPS_EXCEPTIONS=on -D PKG_PYTHON=on …/cmake

As I already wrote, your python installation is not suitable. You cannot fix that by changing the flags to compile LAMMPS. The only way you may be able to get a working shared library for LAMMPS without changing/updating your python library is by not linking to python which requires that you do not enable the PYTHON package when compiling LAMMPS. It is not needed to call LAMMPS from python, only to call python from LAMMPS.

You mean drop the ‘’-D PKG_PYTHON=on’’ option and keep the ‘’-D PYTHON_EXECUTABLE=/projects/community/python/3.8.5/gc563/bin/python3’’ option?

I meant what I wrote and if you need further explanations or confirmations about details you will find them in the documentation.