PYTHON interface to LAMMPS

Hi all,

I’m trying to get python interface to lammps working on my machine. Basically, based on LAMMPS manual I chose second option for using LAMMPS from python which is:

(2) Use LAMMPS in parallel, where each processor runs Python, but your Python program does not use MPI.

I followed the manual and I created a shared MPI library (I use MPICH2) which I have it installed under ~/packages/mpich2-1.4.1p1_Shared
Next I edited the setup.py of LAMMPS such that I have :

library_dirs = ["~/packages/mpich2-1.4.1p1_Shared/lib"]

libraries = [“mpich”,“mpl”,“pthread”]

however for include_dirs = ["…/src"] I changed it to include_dirs = ["/home/kasra/packages/mpich2-1.4.1p1_Shared/include"] because it couldn’t find mpi.h otherwise and I assumed I need to feed in the mpi include location not the lammps source files location, am I right?

So with all the changes I made I was able to build and install LAMMPS under /usr/local/lib/python2.5/site-packages which created following files under:

-rwxr-xr-x 1 root staff 11564946 2012-04-12 11:54 _lammps.so
-rw-r–r-- 1 root staff 5859 2012-04-12 15:32 lammps.py
-rw-r–r-- 1 root staff 5345 2012-04-12 16:06 lammps.pyc
-rw-r–r-- 1 root staff 254 2012-04-12 16:06 lammps-28Nov11.egg-info

I can import lammps module as : from lammps import lammps
and by dir(lammps) I get:
[‘del’, ‘doc’, ‘init’, ‘module’, ‘close’, ‘command’, ‘extract_atom’, ‘extract_compute’, ‘extract_fix’, ‘extract_global’, ‘extract_variable’, ‘file’, ‘get_coords’, ‘get_natoms’, ‘put_coords’]

which I assume lammps module has been imported successfully (?)

However, when I want to create a LAMMPS object by lmp = lammps() I get following error:

Traceback (most recent call last):
File “”, line 1, in
File “/usr/local/lib/python2.6/dist-packages/lammps.py”, line 37, in init
raise OSError,“Could not load LAMMPS dynamic library”
OSError: Could not load LAMMPS dynamic library

Would you please tell me what is going wrong? And how can I handle this problem?

Best,
Kasra.

Hi all,

I'm trying to get python interface to lammps working on my machine.
Basically, based on LAMMPS manual I chose second option for using LAMMPS
from python which is:

(2) Use LAMMPS in parallel, where each processor runs Python, but your
Python program does not use MPI.

I followed the manual and I created a shared MPI library (I use MPICH2)
which I have it installed under ~/packages/mpich2-1.4.1p1_Shared
Next I edited the setup.py of LAMMPS such that I have :
library_dirs =
["~/packages/mpich2-1.4.1p1_Shared/lib"]
libraries = ["mpich","mpl","pthread"]
however for include_dirs = ["../src"] I changed it to include_dirs =
["/home/kasra/packages/mpich2-1.4.1p1_Shared/include"] because it couldn't
find mpi.h otherwise and I assumed I need to feed in the mpi include
location not the lammps source files location, am I right?

So with all the changes I made I was able to build and install LAMMPS under
/usr/local/lib/python2.5/site-packages which created following files under:

-rwxr-xr-x 1 root staff 11564946 2012-04-12 11:54 _lammps.so
-rw-r--r-- 1 root staff 5859 2012-04-12 15:32 lammps.py
-rw-r--r-- 1 root staff 5345 2012-04-12 16:06 lammps.pyc
-rw-r--r-- 1 root staff 254 2012-04-12 16:06 lammps-28Nov11.egg-info

I can import lammps module as : from lammps import lammps
and by dir(lammps) I get:
['__del__', '__doc__', '__init__', '__module__', 'close', 'command',
'extract_atom', 'extract_compute', 'extract_fix', 'extract_global',
'extract_variable', 'file', 'get_coords', 'get_natoms', 'put_coords']

which I assume lammps module has been imported successfully (?)

However, when I want to create a LAMMPS object by lmp = lammps() I get
following error:

Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/usr/local/lib/python2.6/dist-packages/lammps.py", line 37, in
__init__
raise OSError,"Could not load LAMMPS dynamic library"
OSError: Could not load LAMMPS dynamic library

Would you please tell me what is going wrong? And how can I handle this
problem?

did you set up LD_LIBRARY_PATH so that it can find lammps.so?

axel.

well, the _lammps.so is in my Python’s site-packages sub-directory ( /usr/local/lib/python2.6/site-packages) and I have added following line to my .bashrc and also source it:

export LD_LIBRARY_PATH=/usr/local/lib/python2.6/dist-packages:$LD_LIBRARY_PATH

but I still get the error!

Best,
Kasra.

well, the _lammps.so is in my Python's site-packages sub-directory (
/usr/local/lib/python2.6/site-packages) and I have added following line to
my .bashrc and also source it:

export
LD_LIBRARY_PATH=/usr/local/lib/python2.6/dist-packages:$LD_LIBRARY_PATH

but I still get the error!

what about the shared libraries that lammps.so depends on?

the fact that the lammps DSO fails to be imported due
to unresolved dependencies will be reported as an error
for lammps.so, even though it was a different DSO that
was causing the issue.

axel.

Thanks a lot Axel. I exported mpich shared library path and it solved the problem :wink:

Best,
Kasra.