File: demo.py

package info (click to toggle)
lammps 20250204%2Bdfsg.1-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 474,368 kB
  • sloc: cpp: 1,060,070; python: 27,785; ansic: 8,956; f90: 7,254; sh: 6,044; perl: 4,171; fortran: 2,442; xml: 1,714; makefile: 1,352; objc: 238; lisp: 188; yacc: 58; csh: 16; awk: 14; tcl: 6; javascript: 2
file content (54 lines) | stat: -rwxr-xr-x 1,406 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
#!/usr/bin/env python -i
# preceding line should have path for Python on your machine

# demo.py
# Purpose: illustrate use of many library interface commands
# Syntax:  demo.py
#          uses in.demo as LAMMPS input script

from __future__ import print_function
import sys

# parse command line

argv = sys.argv
if len(argv) != 1:
  print("Syntax: demo.py")
  sys.exit()

from lammps import lammps, LAMMPS_INT, LMP_STYLE_GLOBAL, LMP_VAR_EQUAL, LMP_VAR_ATOM
lmp = lammps()

# test out various library functions after running in.demo

lmp.file("in.demo")

print("\nPython output:")

natoms = lmp.extract_global("natoms")
mass = lmp.extract_atom("mass")
x = lmp.extract_atom("x")
print("Natoms, mass, x[0][0] coord =",natoms,mass[1],x[0][0])

temp = lmp.extract_compute("thermo_temp", LMP_STYLE_GLOBAL, LAMMPS_INT)
print("Temperature from compute =",temp)

eng = lmp.extract_variable("eng",None, LMP_VAR_EQUAL)
print("Energy from equal-style variable =",eng)

vy = lmp.extract_variable("vy","all", LMP_VAR_ATOM)
print("Velocity component from atom-style variable =",vy[1])

vol = lmp.get_thermo("vol")
print("Volume from get_thermo = ",vol)

natoms = lmp.get_natoms()
print("Natoms from get_natoms =",natoms)

xc = lmp.gather_atoms("x",1,3)
print("Global coords from gather_atoms =",xc[0],xc[1],xc[31])

xc[0] = xc[0] + 1.0
lmp.scatter_atoms("x",1,3,xc)

print("Changed x[0][0] via scatter_atoms =",x[0][0])