lmp.extract_compute returns Null

Hello everyone!

I am working on a course project to make a very simple interface to LAMMPS through the PyLammps package working with Python3.6 and the latest LAMMPS release. My hope is to be able to run a simulation without having to save files (dump, RDF, MSD, etc). So far I have succeeded by setting up LAMMPS with

lmp = lammps()
L = PyLammps(ptr=lmp)

and then collecting thermo data from L.runs[...] and coordinates by using lmp.gather_atoms("x", 1,3). My problem is with trying to find collect the MSD and RDF computes from the provided methods. After I run the program below, I have been trying to read the RDF using variations of the command lmp.extract_compute("myRDF",0,1), but only receive types <lammps.LP_c_double at 0x7f3b88156510> that can't be subscripted as they seem to be Null. I'm not sure what I'm doing wrong here as these commands seem to follow the manuals. Is what I am trying to do even possible? Would it be better to just collect the coordinate data and then use another Python function to compute these?

Thanks,

Patrick

from lammps import lammps, PyLammps
lmp = lammps()
L = PyLammps(ptr=lmp)

L.units("lj")
L.atom_style(" atomic")
L.atom_modify("map array")
L.lattice("fcc 0.8442")
L.region("box block 0 4 0 4 0 4")
L.create_box("1 box")
L.create_atoms("1 box")
L.mass("1 1.0")
L.velocity("all create 1.44 87287 loop geom")
L.pair_style("lj/cut 2.5")
L.pair_coeff("1 1 1.0 1.0 2.5")
L.neighbor("0.3 bin")
L.neigh_modify("delay 0 every 20 check no")
L.fix("1 all nve")

L.compute("msdcal all msd") #Compute msd
L.compute("myRDF all rdf 50") # Compute rdf

L.fix("4 all ave/time 100 1 100 c_myRDF[*] file RDF.data mode vector")
L.fix("5 all ave/time 1 1 1 c_msdcal[4] file MSD.data mode scalar")

L.thermo(50)
L.thermo_style("custom step temp ke pe etotal vol press pxx pyy pzz lx ly lz enthalpy")
L.dump("id all atom 50 dump.melt")
L.run(250)

lmp.extract_compute("myRDF",0,1) #returns null

Hello everyone!

I am working on a course project to make a very simple interface to LAMMPS
through the PyLammps package working with Python3.6 and the latest LAMMPS
release. My hope is to be able to run a simulation without having to save
files (dump, RDF, MSD, etc). So far I have succeeded by setting up LAMMPS
with

lmp = lammps()
L = PyLammps(ptr=lmp)

and then collecting thermo data from L.runs[...] and coordinates by using
lmp.gather_atoms("x", 1,3). My problem is with trying to find collect the
MSD and RDF computes from the provided methods. After I run the program
below, I have been trying to read the RDF using variations of the command
lmp.extract_compute("myRDF",0,1), but only receive types <lammps.LP_c_double
at 0x7f3b88156510> that can't be subscripted as they seem to be Null.

i don't understand why you are trying to extract data from the
compute. shouldn't you instead extract the averaged data from fix 4
instead?

anyway, your code is not correct. compute rdf computes a global array
(with 2*n+1 columns with n being the number of pairs to types to be
processed)
these will be in a 2d-double array, so you would have to do something like this:

rdfone=POINTER(POINTER(c_double))
rdfone=lmp.extract_compute("myRDF",0,2)
for i in range(0,50):
  print("%8.3f %g g&quot; (rdfone[i][0],rdfone[i][1],rdfone[i][2]))

for the fix, the API for getting access is slightly different, as the
indexing is already done from within the code. so the equivalent
output from above would be created with:

for i in range(0,50):
  print("%8.3f %g g&quot;
(lmp.extract_fix("4",0,2,i,0),lmp.extract_fix("4",0,2,i,1),lmp.extract_fix("4",0,2,i,2)))

in both cases, you have three columns: the value r, g(r), Int_0^r(g(r))

I'm
not sure what I'm doing wrong here as these commands seem to follow the
manuals. Is what I am trying to do even possible? Would it be better to just
collect the coordinate data and then use another Python function to compute
these?

it is possible. it looks like you need to look a bit closer at the
documentation.

axel.