Simplify Python examples to use numpy.extract_atom

This commit is contained in:
Richard Berger 2020-09-17 16:51:46 -04:00
parent ab6b69d6bd
commit be72ce2534
No known key found for this signature in database
GPG Key ID: A9E83994E0BA0CAB
2 changed files with 34 additions and 37 deletions

View File

@ -20,7 +20,7 @@ neigh_modify every 20 delay 0 check no
python post_force_callback here """
from __future__ import print_function
from lammps import lammps, LAMMPS_INT
from lammps import lammps
def post_force_callback(lmp, v):
try:
@ -35,14 +35,13 @@ def post_force_callback(lmp, v):
#mylist = L.get_neighlist(0)
mylist = L.find_pair_neighlist("lj/cut", request=0)
print(pid_prefix, mylist)
nlocal = L.extract_global("nlocal", LAMMPS_INT)
nghost = L.extract_global("nghost", LAMMPS_INT)
ntypes = L.extract_global("ntypes", LAMMPS_INT)
mass = L.numpy.extract_atom_darray("mass", ntypes+1)
atype = L.numpy.extract_atom_iarray("type", nlocal+nghost)
x = L.numpy.extract_atom_darray("x", nlocal+nghost, dim=3)
v = L.numpy.extract_atom_darray("v", nlocal+nghost, dim=3)
f = L.numpy.extract_atom_darray("f", nlocal+nghost, dim=3)
nlocal = L.extract_global("nlocal")
nghost = L.extract_global("nghost")
mass = L.numpy.extract_atom("mass")
atype = L.numpy.extract_atom("type", nelem=nlocal+nghost)
x = L.numpy.extract_atom("x", nelem=nlocal+nghost, dim=3)
v = L.numpy.extract_atom("v", nelem=nlocal+nghost, dim=3)
f = L.numpy.extract_atom("f", nelem=nlocal+nghost, dim=3)
for iatom, numneigh, neighs in mylist:
print(pid_prefix, "- {}".format(iatom), x[iatom], v[iatom], f[iatom], " : ", numneigh, "Neighbors")

View File

@ -39,19 +39,18 @@ class NVE(LAMMPSFixMove):
assert(self.group_name == "all")
def init(self):
dt = self.lmp.extract_global("dt", LAMMPS_DOUBLE)
ftm2v = self.lmp.extract_global("ftm2v", LAMMPS_DOUBLE)
self.ntypes = self.lmp.extract_global("ntypes", LAMMPS_INT)
dt = self.lmp.extract_global("dt")
ftm2v = self.lmp.extract_global("ftm2v")
self.ntypes = self.lmp.extract_global("ntypes")
self.dtv = dt
self.dtf = 0.5 * dt * ftm2v
def initial_integrate(self, vflag):
nlocal = self.lmp.extract_global("nlocal", LAMMPS_INT)
mass = self.lmp.numpy.extract_atom_darray("mass", self.ntypes+1)
atype = self.lmp.numpy.extract_atom_iarray("type", nlocal)
x = self.lmp.numpy.extract_atom_darray("x", nlocal, dim=3)
v = self.lmp.numpy.extract_atom_darray("v", nlocal, dim=3)
f = self.lmp.numpy.extract_atom_darray("f", nlocal, dim=3)
mass = self.lmp.numpy.extract_atom("mass")
atype = self.lmp.numpy.extract_atom("type")
x = self.lmp.numpy.extract_atom("x")
v = self.lmp.numpy.extract_atom("v")
f = self.lmp.numpy.extract_atom("f")
for i in range(x.shape[0]):
dtfm = self.dtf / mass[int(atype[i])]
@ -59,11 +58,10 @@ class NVE(LAMMPSFixMove):
x[i,:] += self.dtv * v[i,:]
def final_integrate(self):
nlocal = self.lmp.extract_global("nlocal", LAMMPS_INT)
mass = self.lmp.numpy.extract_atom_darray("mass", self.ntypes+1)
atype = self.lmp.numpy.extract_atom_iarray("type", nlocal)
v = self.lmp.numpy.extract_atom_darray("v", nlocal, dim=3)
f = self.lmp.numpy.extract_atom_darray("f", nlocal, dim=3)
mass = self.lmp.numpy.extract_atom("mass")
atype = self.lmp.numpy.extract_atom("type")
v = self.lmp.numpy.extract_atom("v")
f = self.lmp.numpy.extract_atom("f")
for i in range(v.shape[0]):
dtfm = self.dtf / mass[int(atype[i])]
@ -77,19 +75,19 @@ class NVE_Opt(LAMMPSFixMove):
assert(self.group_name == "all")
def init(self):
dt = self.lmp.extract_global("dt", LAMMPS_DOUBLE)
ftm2v = self.lmp.extract_global("ftm2v", LAMMPS_DOUBLE)
self.ntypes = self.lmp.extract_global("ntypes", LAMMPS_INT)
dt = self.lmp.extract_global("dt")
ftm2v = self.lmp.extract_global("ftm2v")
self.ntypes = self.lmp.extract_global("ntypes")
self.dtv = dt
self.dtf = 0.5 * dt * ftm2v
self.mass = self.lmp.numpy.extract_atom_darray("mass", self.ntypes+1)
self.mass = self.lmp.numpy.extract_atom("mass")
def initial_integrate(self, vflag):
nlocal = self.lmp.extract_global("nlocal", LAMMPS_INT)
atype = self.lmp.numpy.extract_atom_iarray("type", nlocal)
x = self.lmp.numpy.extract_atom_darray("x", nlocal, dim=3)
v = self.lmp.numpy.extract_atom_darray("v", nlocal, dim=3)
f = self.lmp.numpy.extract_atom_darray("f", nlocal, dim=3)
nlocal = self.lmp.extract_global("nlocal")
atype = self.lmp.numpy.extract_atom("type")
x = self.lmp.numpy.extract_atom("x")
v = self.lmp.numpy.extract_atom("v")
f = self.lmp.numpy.extract_atom("f")
dtf = self.dtf
dtv = self.dtv
mass = self.mass
@ -102,11 +100,11 @@ class NVE_Opt(LAMMPSFixMove):
x[:,d] += dtv * v[:,d]
def final_integrate(self):
nlocal = self.lmp.extract_global("nlocal", LAMMPS_INT)
mass = self.lmp.numpy.extract_atom_darray("mass", self.ntypes+1)
atype = self.lmp.numpy.extract_atom_iarray("type", nlocal)
v = self.lmp.numpy.extract_atom_darray("v", nlocal, dim=3)
f = self.lmp.numpy.extract_atom_darray("f", nlocal, dim=3)
nlocal = self.lmp.extract_global("nlocal")
mass = self.lmp.numpy.extract_atom("mass")
atype = self.lmp.numpy.extract_atom("type")
v = self.lmp.numpy.extract_atom("v")
f = self.lmp.numpy.extract_atom("f")
dtf = self.dtf
mass = self.mass