LAMMPS WWW Site - LAMMPS Documentation - LAMMPS Mailing List Archives
Re: [lammps-users] Extracting per-atom potential energy with LAMMPS-Python interface
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [lammps-users] Extracting per-atom potential energy with LAMMPS-Python interface


From: Axel Kohlmeyer <akohlmey@...24...>
Date: Mon, 23 Oct 2017 16:40:58 -0400

On Mon, Oct 23, 2017 at 10:52 AM, Wise, Ethan Allen <eawise@...2437...> wrote:
> Hi LAMMPS users,
>
>
>
> In my current project, I am using the python-LAMMPS interface from a python
> function embedded within my LAMMPS input script.  This python function is
> called during each timestep and accesses/changes per-atom properties using
> the “lmp.gather_atoms()” and “lmp.scatter_atoms()” methods.  I now want to
> access a per-atom potential energy variable (and corresponding per-atom id)
> in a similar fashion.  I am accessing this atom style variable from within
> python via the “lmp.extract_variable()” method.  However, I noticed that
> each processor seems to return a separate python list.  Is there a way to
> retrieve the per-atom potential energy as a single list in python?  If not,
> is there a way for me to combine these variables into a single variable?
> The python code is mpi4py enabled and I am running on LAMMPS version
> 20161117.  Thanks for your help.

two comments:

1) you should upgrade your LAMMPS version. there have been significant
improvements to the LAMMPS python interface over the last year.

2) you will have to do your own MPI communication in python to collect
the information into a properly ordered array. or extend the C library
interface and correspondingly the python wrapper.
  the procedure is straightforward: you get a suitable storage on rank
0 of size natoms ready for the data.
  then you loop over all ranks > 0 and receive a data chunk with all
atom tags and the property you are interested. those will be in
"local" order.
  then you loop over the received data (mind you, that each MPI rank
may have a different number of nlocal atoms)
  for (i=0; i < nlocal_rank; ++i) { data[tag[i]] = recv[i]; }
  now you have your data in order of the global atom id in the array
"data". this can be done more efficient (e.g. using MPI_Gatherv), but
this is the general principle.

axel.

>
>
>
> Ethan
>
>
> ------------------------------------------------------------------------------
> Check out the vibrant tech community on one of the world's most
> engaging tech sites, Slashdot.org! http://sdm.link/slashdot
> _______________________________________________
> lammps-users mailing list
> lammps-users@lists.sourceforge.net
> https://lists.sourceforge.net/lists/listinfo/lammps-users
>



-- 
Dr. Axel Kohlmeyer  akohlmey@...24...  http://goo.gl/1wk0
College of Science & Technology, Temple University, Philadelphia PA, USA
International Centre for Theoretical Physics, Trieste. Italy.