Hi all,

I want to use lammps_extract_fix from python to access a fixed based per-atom type array (3 components per atoms) from python.
My python code is :

from lammps import lammps
lmp = lammps()

v1 = lmp.extract_fix(“f1”, 1, 2, 1, 1) # f1 is the fix id
print("v1=s" v1)
v2 = v1[1]
print("v2=s" v2)
v3= v2[0]
print("v3=s" v3)

but I get the following error :

Step Atoms KinEng 1 Volume CPU
1 30 0.0076871121 8.3995398e-07 0.0008 0
10 30 0.13298132 0.00042168989 0.0008 0.0013921261
11 30 0.13211083 0.00044754583 0.0008 0.00157094
Loop time of 0.00158596 on 1 procs for 10 steps with 30 atoms
v1=<lammps.LP_LP_c_double object at 0x872077c>
v2=<lammps.LP_c_double object at 0x872080c>
[joris-desktop:25652] *** Process received signal ***
[joris-desktop:25652] Signal: Segmentation fault (11)
[joris-desktop:25652] Signal code: Address not mapped (1)
[joris-desktop:25652] Failing at address: 0x5f6164fd
[joris-desktop:25652] [ 0] [0xb772940c]
[joris-desktop:25652] [ 1] /usr/lib/python2.7/lib-dynload/ [0xb5f8e7b2]
[joris-desktop:25652] [ 2] python(PyEval_EvalFrameEx+0x11a4) [0x81958d4]
[joris-desktop:25652] [ 3] python(PyEval_EvalCodeEx+0x150) [0x819af70]
[joris-desktop:25652] [ 4] python(PyRun_FileExFlags+0xe1) [0x819b8a1]
[joris-desktop:25652] [ 5] python(PyRun_SimpleFileExFlags+0x21a) [0x80a8bda]
[joris-desktop:25652] [ 6] python(Py_Main+0x559) [0x80a9949]
[joris-desktop:25652] [ 7] python(main+0x1b) [0x805ea5b]
[joris-desktop:25652] [ 8] /lib/i386-linux-gnu/ [0xb73384d3]
[joris-desktop:25652] [ 9] python() [0x805ea81]
[joris-desktop:25652] *** End of error message ***
Segmentation fault (core dumped)

I don’t understand if it is my way of making use in python of the pointer of extract_variable that is wrong, or the function itself that is not intended for fix per_atom type vectors…
I precise that my fix works perfectly on lammps alone.

Thanks for your help !

PS: Steve, I have really no idea how to save last step variable so I’m still trying a python-lammps coupling to manage the external force field and send it to lammps.

What fix are you extracting from?


A property/atom kind. For instance, the creation function for the force is :

void FixPforce::post_create()
         char* fixarg[11];
         fixarg[4]="vector"; // 1 vector per particle to be registered
         fixarg[5]="yes"; // restart
         fixarg[6]="no"; // communicate ghost
         fixarg[7]="no"; // communicate rev
         fix_Pforce_ = modify->add_fix_property_atom(11,fixarg,style);


I join the whole fix_Pforce.cpp file.

It seems that extract_fix can find the id of my fix, and give the pointer to pointer.
But then, it breaks when trying to get a value of the array...

Thanks a lot,


fix_Pforce.cpp (3.62 KB)

fix_Pforce.h (1.24 KB)

I don't know what you are trying to do with your new fix.

But try the following. Add this line to python/example/in.simple
fix 2 all store/force
Add these lines to python/example/
after the print "XGATHER" line
f = lmp.extract_fix("2",1,2,0,0)
print "FORCE on 1st atom",f[0][0],f[0][1],f[0][2]
(Note that the final 0,0 in extract_fix are irrelevant args for this case)

Then run "python in.simple"
and you get this output:
FORCE on 1st atom 32.2075661444 -16.5046728466 -32.6479875593


Ok, it works for the fix store/force.

My new fix create a property/atom constant vector that will be modified by python and that is applied every time step in lammps as a POST_FORCE().