2013-06-10 23:01:35 +08:00
|
|
|
#!/usr/bin/env python -i
|
2017-03-07 13:57:23 +08:00
|
|
|
# preceding line should have path for Python on your machine
|
2010-11-02 23:07:40 +08:00
|
|
|
|
|
|
|
# demo.py
|
|
|
|
# Purpose: illustrate use of many library interface commands
|
|
|
|
# Syntax: demo.py
|
|
|
|
# uses in.demo as LAMMPS input script
|
|
|
|
|
2016-07-23 06:57:54 +08:00
|
|
|
from __future__ import print_function
|
2010-11-02 23:07:40 +08:00
|
|
|
import sys
|
|
|
|
|
|
|
|
# parse command line
|
|
|
|
|
|
|
|
argv = sys.argv
|
|
|
|
if len(argv) != 1:
|
2016-07-23 06:57:54 +08:00
|
|
|
print("Syntax: demo.py")
|
2010-11-02 23:07:40 +08:00
|
|
|
sys.exit()
|
|
|
|
|
|
|
|
from lammps import lammps
|
|
|
|
lmp = lammps()
|
|
|
|
|
|
|
|
# test out various library functions after running in.demo
|
|
|
|
|
|
|
|
lmp.file("in.demo")
|
|
|
|
|
2016-07-23 06:57:54 +08:00
|
|
|
print("\nPython output:")
|
2010-11-02 23:07:40 +08:00
|
|
|
|
2012-10-25 23:21:33 +08:00
|
|
|
natoms = lmp.extract_global("natoms",0)
|
|
|
|
mass = lmp.extract_atom("mass",2)
|
|
|
|
x = lmp.extract_atom("x",3)
|
2016-07-23 06:57:54 +08:00
|
|
|
print("Natoms, mass, x[0][0] coord =",natoms,mass[1],x[0][0])
|
2010-11-02 23:07:40 +08:00
|
|
|
|
|
|
|
temp = lmp.extract_compute("thermo_temp",0,0)
|
2016-07-23 06:57:54 +08:00
|
|
|
print("Temperature from compute =",temp)
|
2010-11-02 23:07:40 +08:00
|
|
|
|
|
|
|
eng = lmp.extract_variable("eng",None,0)
|
2016-07-23 06:57:54 +08:00
|
|
|
print("Energy from equal-style variable =",eng)
|
2010-11-02 23:07:40 +08:00
|
|
|
|
|
|
|
vy = lmp.extract_variable("vy","all",1)
|
2016-07-23 06:57:54 +08:00
|
|
|
print("Velocity component from atom-style variable =",vy[1])
|
|
|
|
|
|
|
|
vol = lmp.get_thermo("vol")
|
|
|
|
print("Volume from get_thermo = ",vol)
|
2010-11-02 23:07:40 +08:00
|
|
|
|
|
|
|
natoms = lmp.get_natoms()
|
2016-07-23 06:57:54 +08:00
|
|
|
print("Natoms from get_natoms =",natoms)
|
2010-11-02 23:07:40 +08:00
|
|
|
|
2012-10-25 23:21:33 +08:00
|
|
|
xc = lmp.gather_atoms("x",1,3)
|
2016-07-23 06:57:54 +08:00
|
|
|
print("Global coords from gather_atoms =",xc[0],xc[1],xc[31])
|
2010-11-02 23:07:40 +08:00
|
|
|
|
|
|
|
xc[0] = xc[0] + 1.0
|
2012-10-25 23:21:33 +08:00
|
|
|
lmp.scatter_atoms("x",1,3,xc)
|
2010-11-02 23:07:40 +08:00
|
|
|
|
2016-07-23 06:57:54 +08:00
|
|
|
print("Changed x[0][0] via scatter_atoms =",x[0][0])
|