Simplify Python examples to use numpy.extract_atom
This commit is contained in:
@ -20,7 +20,7 @@ neigh_modify every 20 delay 0 check no
|
|||||||
|
|
||||||
python post_force_callback here """
|
python post_force_callback here """
|
||||||
from __future__ import print_function
|
from __future__ import print_function
|
||||||
from lammps import lammps, LAMMPS_INT
|
from lammps import lammps
|
||||||
|
|
||||||
def post_force_callback(lmp, v):
|
def post_force_callback(lmp, v):
|
||||||
try:
|
try:
|
||||||
@ -35,14 +35,13 @@ def post_force_callback(lmp, v):
|
|||||||
#mylist = L.get_neighlist(0)
|
#mylist = L.get_neighlist(0)
|
||||||
mylist = L.find_pair_neighlist("lj/cut", request=0)
|
mylist = L.find_pair_neighlist("lj/cut", request=0)
|
||||||
print(pid_prefix, mylist)
|
print(pid_prefix, mylist)
|
||||||
nlocal = L.extract_global("nlocal", LAMMPS_INT)
|
nlocal = L.extract_global("nlocal")
|
||||||
nghost = L.extract_global("nghost", LAMMPS_INT)
|
nghost = L.extract_global("nghost")
|
||||||
ntypes = L.extract_global("ntypes", LAMMPS_INT)
|
mass = L.numpy.extract_atom("mass")
|
||||||
mass = L.numpy.extract_atom_darray("mass", ntypes+1)
|
atype = L.numpy.extract_atom("type", nelem=nlocal+nghost)
|
||||||
atype = L.numpy.extract_atom_iarray("type", nlocal+nghost)
|
x = L.numpy.extract_atom("x", nelem=nlocal+nghost, dim=3)
|
||||||
x = L.numpy.extract_atom_darray("x", nlocal+nghost, dim=3)
|
v = L.numpy.extract_atom("v", nelem=nlocal+nghost, dim=3)
|
||||||
v = L.numpy.extract_atom_darray("v", nlocal+nghost, dim=3)
|
f = L.numpy.extract_atom("f", nelem=nlocal+nghost, dim=3)
|
||||||
f = L.numpy.extract_atom_darray("f", nlocal+nghost, dim=3)
|
|
||||||
|
|
||||||
for iatom, numneigh, neighs in mylist:
|
for iatom, numneigh, neighs in mylist:
|
||||||
print(pid_prefix, "- {}".format(iatom), x[iatom], v[iatom], f[iatom], " : ", numneigh, "Neighbors")
|
print(pid_prefix, "- {}".format(iatom), x[iatom], v[iatom], f[iatom], " : ", numneigh, "Neighbors")
|
||||||
|
|||||||
@ -39,19 +39,18 @@ class NVE(LAMMPSFixMove):
|
|||||||
assert(self.group_name == "all")
|
assert(self.group_name == "all")
|
||||||
|
|
||||||
def init(self):
|
def init(self):
|
||||||
dt = self.lmp.extract_global("dt", LAMMPS_DOUBLE)
|
dt = self.lmp.extract_global("dt")
|
||||||
ftm2v = self.lmp.extract_global("ftm2v", LAMMPS_DOUBLE)
|
ftm2v = self.lmp.extract_global("ftm2v")
|
||||||
self.ntypes = self.lmp.extract_global("ntypes", LAMMPS_INT)
|
self.ntypes = self.lmp.extract_global("ntypes")
|
||||||
self.dtv = dt
|
self.dtv = dt
|
||||||
self.dtf = 0.5 * dt * ftm2v
|
self.dtf = 0.5 * dt * ftm2v
|
||||||
|
|
||||||
def initial_integrate(self, vflag):
|
def initial_integrate(self, vflag):
|
||||||
nlocal = self.lmp.extract_global("nlocal", LAMMPS_INT)
|
mass = self.lmp.numpy.extract_atom("mass")
|
||||||
mass = self.lmp.numpy.extract_atom_darray("mass", self.ntypes+1)
|
atype = self.lmp.numpy.extract_atom("type")
|
||||||
atype = self.lmp.numpy.extract_atom_iarray("type", nlocal)
|
x = self.lmp.numpy.extract_atom("x")
|
||||||
x = self.lmp.numpy.extract_atom_darray("x", nlocal, dim=3)
|
v = self.lmp.numpy.extract_atom("v")
|
||||||
v = self.lmp.numpy.extract_atom_darray("v", nlocal, dim=3)
|
f = self.lmp.numpy.extract_atom("f")
|
||||||
f = self.lmp.numpy.extract_atom_darray("f", nlocal, dim=3)
|
|
||||||
|
|
||||||
for i in range(x.shape[0]):
|
for i in range(x.shape[0]):
|
||||||
dtfm = self.dtf / mass[int(atype[i])]
|
dtfm = self.dtf / mass[int(atype[i])]
|
||||||
@ -59,11 +58,10 @@ class NVE(LAMMPSFixMove):
|
|||||||
x[i,:] += self.dtv * v[i,:]
|
x[i,:] += self.dtv * v[i,:]
|
||||||
|
|
||||||
def final_integrate(self):
|
def final_integrate(self):
|
||||||
nlocal = self.lmp.extract_global("nlocal", LAMMPS_INT)
|
mass = self.lmp.numpy.extract_atom("mass")
|
||||||
mass = self.lmp.numpy.extract_atom_darray("mass", self.ntypes+1)
|
atype = self.lmp.numpy.extract_atom("type")
|
||||||
atype = self.lmp.numpy.extract_atom_iarray("type", nlocal)
|
v = self.lmp.numpy.extract_atom("v")
|
||||||
v = self.lmp.numpy.extract_atom_darray("v", nlocal, dim=3)
|
f = self.lmp.numpy.extract_atom("f")
|
||||||
f = self.lmp.numpy.extract_atom_darray("f", nlocal, dim=3)
|
|
||||||
|
|
||||||
for i in range(v.shape[0]):
|
for i in range(v.shape[0]):
|
||||||
dtfm = self.dtf / mass[int(atype[i])]
|
dtfm = self.dtf / mass[int(atype[i])]
|
||||||
@ -77,19 +75,19 @@ class NVE_Opt(LAMMPSFixMove):
|
|||||||
assert(self.group_name == "all")
|
assert(self.group_name == "all")
|
||||||
|
|
||||||
def init(self):
|
def init(self):
|
||||||
dt = self.lmp.extract_global("dt", LAMMPS_DOUBLE)
|
dt = self.lmp.extract_global("dt")
|
||||||
ftm2v = self.lmp.extract_global("ftm2v", LAMMPS_DOUBLE)
|
ftm2v = self.lmp.extract_global("ftm2v")
|
||||||
self.ntypes = self.lmp.extract_global("ntypes", LAMMPS_INT)
|
self.ntypes = self.lmp.extract_global("ntypes")
|
||||||
self.dtv = dt
|
self.dtv = dt
|
||||||
self.dtf = 0.5 * dt * ftm2v
|
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):
|
def initial_integrate(self, vflag):
|
||||||
nlocal = self.lmp.extract_global("nlocal", LAMMPS_INT)
|
nlocal = self.lmp.extract_global("nlocal")
|
||||||
atype = self.lmp.numpy.extract_atom_iarray("type", nlocal)
|
atype = self.lmp.numpy.extract_atom("type")
|
||||||
x = self.lmp.numpy.extract_atom_darray("x", nlocal, dim=3)
|
x = self.lmp.numpy.extract_atom("x")
|
||||||
v = self.lmp.numpy.extract_atom_darray("v", nlocal, dim=3)
|
v = self.lmp.numpy.extract_atom("v")
|
||||||
f = self.lmp.numpy.extract_atom_darray("f", nlocal, dim=3)
|
f = self.lmp.numpy.extract_atom("f")
|
||||||
dtf = self.dtf
|
dtf = self.dtf
|
||||||
dtv = self.dtv
|
dtv = self.dtv
|
||||||
mass = self.mass
|
mass = self.mass
|
||||||
@ -102,11 +100,11 @@ class NVE_Opt(LAMMPSFixMove):
|
|||||||
x[:,d] += dtv * v[:,d]
|
x[:,d] += dtv * v[:,d]
|
||||||
|
|
||||||
def final_integrate(self):
|
def final_integrate(self):
|
||||||
nlocal = self.lmp.extract_global("nlocal", LAMMPS_INT)
|
nlocal = self.lmp.extract_global("nlocal")
|
||||||
mass = self.lmp.numpy.extract_atom_darray("mass", self.ntypes+1)
|
mass = self.lmp.numpy.extract_atom("mass")
|
||||||
atype = self.lmp.numpy.extract_atom_iarray("type", nlocal)
|
atype = self.lmp.numpy.extract_atom("type")
|
||||||
v = self.lmp.numpy.extract_atom_darray("v", nlocal, dim=3)
|
v = self.lmp.numpy.extract_atom("v")
|
||||||
f = self.lmp.numpy.extract_atom_darray("f", nlocal, dim=3)
|
f = self.lmp.numpy.extract_atom("f")
|
||||||
dtf = self.dtf
|
dtf = self.dtf
|
||||||
mass = self.mass
|
mass = self.mass
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user