library interface to computes

Hi all,

I'm using the python/C interface to interact with LAMMPS between runs.

At the moment, I can start/stop simulations and tweak the fixes,
basically by feeding text commands into the "command()" function, and
I've also used the "extract_atom()" function to read and update
properties like atom positions.

What I'd like to do now is be able to use LAMMPS' compute
functionality to calculate energy for me (I've tried doing it myself
in Python, but I don't seem to get answers that are consistent with
the thermodynamic output from LAMMPS, and I trust its numbers more
than my own!) I can already see the output I think I want on stdout,
but I need to be able to retrieve that data into Python through the
interface.

Initially I took a look at the "extract_compute()" function, but that
seems to refer to a compute already set up somehow, rather than
allowing me to say "run this compute and return the answer".

My question is, is there a way to do this already, say by running a
command and then extracting a LAMMPS variable with
"extract_variable()", or do I need to modify the interface to allow
it?

Any help on this, and how to write a one-liner in LAMMPS script that
calculates kinetic plus potential energy and stores it in a variable,
would be much appreciated.

Thanks,

Joe

joe,

Hi all,

I'm using the python/C interface to interact with LAMMPS between runs.

At the moment, I can start/stop simulations and tweak the fixes,
basically by feeding text commands into the "command()" function, and
I've also used the "extract_atom()" function to read and update
properties like atom positions.

What I'd like to do now is be able to use LAMMPS' compute
functionality to calculate energy for me (I've tried doing it myself
in Python, but I don't seem to get answers that are consistent with
the thermodynamic output from LAMMPS, and I trust its numbers more
than my own!) I can already see the output I think I want on stdout,
but I need to be able to retrieve that data into Python through the
interface.

Initially I took a look at the "extract_compute()" function, but that
seems to refer to a compute already set up somehow, rather than
allowing me to say "run this compute and return the answer".

this is not how "computes" work. they are updated (as needed)
during an MD run. so you have to first set up the compute and
*then* do an MD step. if you don't want atoms to move, you can
just do this without having a fix for time integration enabled.

My question is, is there a way to do this already, say by running a
command and then extracting a LAMMPS variable with
"extract_variable()", or do I need to modify the interface to allow
it?

using this via variables should work with the caveats from above.

Any help on this, and how to write a one-liner in LAMMPS script that
calculates kinetic plus potential energy and stores it in a variable,
would be much appreciated.

here is a modified version of the melt example.

HTH,
    axel.

cat in.melt-variable
# 3d Lennard-Jones melt

units lj
atom_style atomic

lattice fcc 0.8442
region box block 0 10 0 10 0 10
create_box 1 box
create_atoms 1 box
mass 1 1.0

velocity all create 3.0 87287

pair_style lj/cut 2.5
pair_coeff 1 1 1.0 1.0 2.5

variable total equal etotal
variable potential equal pe
variable kinetic equal ke

thermo 1
run 0 pre no post no

print "total: \{total\} potential: {potential} kinetic: ${kinetic}"