Update examples to use Python API constants
This commit is contained in:
@ -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
|
||||
from lammps import lammps, LAMMPS_INT
|
||||
|
||||
def post_force_callback(lmp, v):
|
||||
try:
|
||||
@ -35,9 +35,9 @@ 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", 0)
|
||||
nghost = L.extract_global("nghost", 0)
|
||||
ntypes = L.extract_global("ntypes", 0)
|
||||
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)
|
||||
|
||||
@ -1,12 +1,12 @@
|
||||
from __future__ import print_function
|
||||
import lammps
|
||||
from lammps import lammps, LAMMPS_INT, LAMMPS_DOUBLE
|
||||
import ctypes
|
||||
import traceback
|
||||
import numpy as np
|
||||
|
||||
class LAMMPSFix(object):
|
||||
def __init__(self, ptr, group_name="all"):
|
||||
self.lmp = lammps.lammps(ptr=ptr)
|
||||
self.lmp = lammps(ptr=ptr)
|
||||
self.group_name = group_name
|
||||
|
||||
class LAMMPSFixMove(LAMMPSFix):
|
||||
@ -39,14 +39,14 @@ class NVE(LAMMPSFixMove):
|
||||
assert(self.group_name == "all")
|
||||
|
||||
def init(self):
|
||||
dt = self.lmp.extract_global("dt", 1)
|
||||
ftm2v = self.lmp.extract_global("ftm2v", 1)
|
||||
self.ntypes = self.lmp.extract_global("ntypes", 0)
|
||||
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)
|
||||
self.dtv = dt
|
||||
self.dtf = 0.5 * dt * ftm2v
|
||||
|
||||
def initial_integrate(self, vflag):
|
||||
nlocal = self.lmp.extract_global("nlocal", 0)
|
||||
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)
|
||||
@ -59,7 +59,7 @@ class NVE(LAMMPSFixMove):
|
||||
x[i,:] += self.dtv * v[i,:]
|
||||
|
||||
def final_integrate(self):
|
||||
nlocal = self.lmp.extract_global("nlocal", 0)
|
||||
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)
|
||||
@ -77,15 +77,15 @@ class NVE_Opt(LAMMPSFixMove):
|
||||
assert(self.group_name == "all")
|
||||
|
||||
def init(self):
|
||||
dt = self.lmp.extract_global("dt", 1)
|
||||
ftm2v = self.lmp.extract_global("ftm2v", 1)
|
||||
self.ntypes = self.lmp.extract_global("ntypes", 0)
|
||||
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)
|
||||
self.dtv = dt
|
||||
self.dtf = 0.5 * dt * ftm2v
|
||||
self.mass = self.lmp.numpy.extract_atom_darray("mass", self.ntypes+1)
|
||||
|
||||
def initial_integrate(self, vflag):
|
||||
nlocal = self.lmp.extract_global("nlocal", 0)
|
||||
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)
|
||||
@ -102,13 +102,12 @@ class NVE_Opt(LAMMPSFixMove):
|
||||
x[:,d] += dtv * v[:,d]
|
||||
|
||||
def final_integrate(self):
|
||||
nlocal = self.lmp.extract_global("nlocal", 0)
|
||||
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)
|
||||
dtf = self.dtf
|
||||
dtv = self.dtv
|
||||
mass = self.mass
|
||||
|
||||
dtfm = dtf / np.take(mass, atype)
|
||||
|
||||
Reference in New Issue
Block a user