LAMMPS WWW Site - LAMMPS Documentation - LAMMPS Mailing List Archives
Re: [lammps-users] multiple instances of lammps in python
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [lammps-users] multiple instances of lammps in python


From: Axel Kohlmeyer <akohlmey@...24...>
Date: Sun, 12 Nov 2017 21:19:46 -0500

BTW: the cleaner way to get/set/update atom parameters for your kind of setup would be to use the gather_atoms and scatter_atoms functions.
axel.

On Sat, Nov 11, 2017 at 7:17 PM, Axel Kohlmeyer <akohlmey@...1125.....> wrote:


On Sat, Nov 11, 2017 at 3:17 PM, Gideon Simpson <gideon.simpson@...24...> wrote:
I am trying to test out some algorithmic ideas using lammps for forces/energies within python, and I’m encountering the following issue that I do not entirely know how to resolve.

My code layout is as follows:

# Problem setup

import numpy as np
from lammps import lammps
#from ctypes import *

lmp = lammps()
lmp2 = lammps()

lmp.file(“problem_setup.lammps")
lmp2.file(“problem_setup.lammps”)

natoms = lmp.get_natoms()

# Create two numpy wrappers for positions and forces for easy access/manipuliton
X = np.ctypeslib.as_array(lmp.extract_atom("x",3).contents,shape=(natoms,3))
F = np.ctypeslib.as_array(lmp.extract_atom("f",3).contents,shape=(natoms,3))

​this is not correct. the dimension of the array is *not* "natoms,3". it is o​f dimension "nlocal,3".
this is only working by coincidence, since you are not running LAMMPS in parallel.

 

X2 = np.ctypeslib.as_array(lmp2.extract_atom("x",3).contents,shape=(natoms,3))
F2 = np.ctypeslib.as_array(lmp2.extract_atom("f",3).contents,shape=(natoms,3))


# run some standard lammps code (i.e., with a standard fix) for some number of time steps
# not reproduced here

# As a first test, I will try copying over the current configuration, stored in X, and quench it
# to inspect the minimized state
X2 = np.copy(X)
lmp2.command("run 0")
lmp2.command("min_style cg")
lmp2.command("minimize 1.e-14 1.e-14 1000 1000")

It is at this point that I am encountering my “problem."  I would have thought X2 now held the quenched
positions.  But the values in X2 are unchanged.  The forces associated with lmp2, stored in F2, are altered
and are close to zero, as expected.

​from the comment about the lammps_extract_atom() function:

/* ----------------------------------------------------------------------
   extract a pointer to an internal LAMMPS atom-based entity
   name = desired quantity, e.g. x or mass
   returns a void pointer to the entity
     which the caller can cast to the proper data type
   returns a NULL if Atom::extract() does not recognize the name

**   the returned pointer is not a permanent valid reference to the
     per-atom quantity, since LAMMPS may reallocate per-atom data **

   customize by adding names to Atom::extract()
------------------------------------------------------------------------- */

 

-gideon


------------------------------------------------------------------------------
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@...655....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.



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