Update examples
This commit is contained in:
@ -23,12 +23,12 @@ from lammps import lammps
|
|||||||
|
|
||||||
def end_of_step_callback(lmp):
|
def end_of_step_callback(lmp):
|
||||||
L = lammps(ptr=lmp)
|
L = lammps(ptr=lmp)
|
||||||
t = L.extract_global("ntimestep", 0)
|
t = L.extract_global("ntimestep")
|
||||||
print("### END OF STEP ###", t)
|
print("### END OF STEP ###", t)
|
||||||
|
|
||||||
def post_force_callback(lmp, v):
|
def post_force_callback(lmp, v):
|
||||||
L = lammps(ptr=lmp)
|
L = lammps(ptr=lmp)
|
||||||
t = L.extract_global("ntimestep", 0)
|
t = L.extract_global("ntimestep")
|
||||||
print("### POST_FORCE ###", t)
|
print("### POST_FORCE ###", t)
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
|||||||
@ -25,9 +25,9 @@ lmp.file("in.demo")
|
|||||||
|
|
||||||
print("\nPython output:")
|
print("\nPython output:")
|
||||||
|
|
||||||
natoms = lmp.extract_global("natoms", LAMMPS_INT)
|
natoms = lmp.extract_global("natoms")
|
||||||
mass = lmp.extract_atom("mass", LAMMPS_DOUBLE)
|
mass = lmp.extract_atom("mass")
|
||||||
x = lmp.extract_atom("x", LAMMPS_DOUBLE2D)
|
x = lmp.extract_atom("x")
|
||||||
print("Natoms, mass, x[0][0] coord =",natoms,mass[1],x[0][0])
|
print("Natoms, mass, x[0][0] coord =",natoms,mass[1],x[0][0])
|
||||||
|
|
||||||
temp = lmp.extract_compute("thermo_temp", LMP_STYLE_GLOBAL, LAMMPS_INT)
|
temp = lmp.extract_compute("thermo_temp", LMP_STYLE_GLOBAL, LAMMPS_INT)
|
||||||
|
|||||||
@ -42,14 +42,14 @@ lmp.command("variable e equal pe")
|
|||||||
|
|
||||||
lmp.command("run 0")
|
lmp.command("run 0")
|
||||||
|
|
||||||
natoms = lmp.extract_global("natoms",LAMMPS_INT)
|
natoms = lmp.extract_global("natoms")
|
||||||
emin = lmp.extract_compute("thermo_pe",LMP_STYLE_GLOBAL,LAMMPS_INT) / natoms
|
emin = lmp.extract_compute("thermo_pe",LMP_STYLE_GLOBAL,LAMMPS_INT) / natoms
|
||||||
lmp.command("variable emin equal $e")
|
lmp.command("variable emin equal $e")
|
||||||
|
|
||||||
# disorder the system
|
# disorder the system
|
||||||
# estart = initial energy
|
# estart = initial energy
|
||||||
|
|
||||||
x = lmp.extract_atom("x", LAMMPS_DOUBLE2D)
|
x = lmp.extract_atom("x")
|
||||||
|
|
||||||
for i in range(natoms):
|
for i in range(natoms):
|
||||||
x[i][0] += deltaperturb * (2*random.random()-1)
|
x[i][0] += deltaperturb * (2*random.random()-1)
|
||||||
@ -58,7 +58,7 @@ for i in range(natoms):
|
|||||||
lmp.command("variable elast equal $e")
|
lmp.command("variable elast equal $e")
|
||||||
lmp.command("thermo_style custom step v_emin v_elast pe")
|
lmp.command("thermo_style custom step v_emin v_elast pe")
|
||||||
lmp.command("run 0")
|
lmp.command("run 0")
|
||||||
x = lmp.extract_atom("x", LAMMPS_DOUBLE2D)
|
x = lmp.extract_atom("x")
|
||||||
lmp.command("variable elast equal $e")
|
lmp.command("variable elast equal $e")
|
||||||
|
|
||||||
estart = lmp.extract_compute("thermo_pe", LMP_STYLE_GLOBAL, LAMMPS_INT) / natoms
|
estart = lmp.extract_compute("thermo_pe", LMP_STYLE_GLOBAL, LAMMPS_INT) / natoms
|
||||||
@ -78,7 +78,7 @@ for i in range(nloop):
|
|||||||
x[iatom][1] += deltamove * (2*random.random()-1)
|
x[iatom][1] += deltamove * (2*random.random()-1)
|
||||||
|
|
||||||
lmp.command("run 1 pre no post no")
|
lmp.command("run 1 pre no post no")
|
||||||
x = lmp.extract_atom("x", LAMMPS_DOUBLE2D)
|
x = lmp.extract_atom("x")
|
||||||
e = lmp.extract_compute("thermo_pe", LMP_STYLE_GLOBAL, LAMMPS_INT) / natoms
|
e = lmp.extract_compute("thermo_pe", LMP_STYLE_GLOBAL, LAMMPS_INT) / natoms
|
||||||
|
|
||||||
if e <= elast:
|
if e <= elast:
|
||||||
|
|||||||
@ -61,7 +61,7 @@ lmp.command("run 1");
|
|||||||
|
|
||||||
# extract force on single atom two different ways
|
# extract force on single atom two different ways
|
||||||
|
|
||||||
f = lmp.extract_atom("f",3)
|
f = lmp.extract_atom("f")
|
||||||
print("Force on 1 atom via extract_atom: ",f[0][0])
|
print("Force on 1 atom via extract_atom: ",f[0][0])
|
||||||
|
|
||||||
fx = lmp.extract_variable("fx","all",1)
|
fx = lmp.extract_variable("fx","all",1)
|
||||||
|
|||||||
@ -57,7 +57,7 @@ if color == 0:
|
|||||||
lmp.scatter_atoms("x",1,3,x)
|
lmp.scatter_atoms("x",1,3,x)
|
||||||
lmp.command("run 1");
|
lmp.command("run 1");
|
||||||
|
|
||||||
f = lmp.extract_atom("f",3)
|
f = lmp.extract_atom("f")
|
||||||
print("Force on 1 atom via extract_atom: ",f[0][0])
|
print("Force on 1 atom via extract_atom: ",f[0][0])
|
||||||
|
|
||||||
fx = lmp.extract_variable("fx","all",1)
|
fx = lmp.extract_variable("fx","all",1)
|
||||||
|
|||||||
Reference in New Issue
Block a user