[lammps-users] Using Python packages through Python Module in LAMMPS

Hello,
Using the Python command of LAMMPS, one can write Python code to be run during the LAMMPS simulation. But, I want to use Python packages like NumPy, scipy, etc. It is giving an error “Python function evaluation failed” and is showing an error line for import of packages in the python code.

What should I do? Is there a way to use these wrappers?

Thank You,
Deepak Somani

Please always report which version of LAMMPS you are using and on what platform.
It would also be extremely helpful if you could provide a minimal example (e.g. based on a “melt” example) that demonstrates the failure.

axel.

This is the LAMMPS module I am using: “lammps/29Oct20_openmpi_4.0.5_gcc_10.2_slurm20”. Also, I am running it using slrum while inputting the data in a normal LAMMPS txt file.

Before applying the actual code, I was looking that whether my python module works in this simpler code. In the below example, I want to add an extra force in the x-direction to an atom with id 3 as a function of its coordinates. So, the python code “new_force_x.py” just returns a force value as a function of x, y, and z. The code works here. Now, in the actual code, I need to use the packages of NumPy, scipy, etc. So, I tried just writing “import numpy as np” in my python script. But this time the error shows “Python function evaluation failed.” Please help me out.

Thank you
Deepak Somani

new 2.txt (920 Bytes)

If just adding “import numpy as np” to your python function makes it fail, then the problem is not with LAMMPS but the python installation on your cluster/server.
It may not have numpy installed or it may be installed as an environment module and you didn’t load it in your batch script.

At any rate, those are questions you have to resolve with your local user support. That is not something that can be addressed from the LAMMPS side.