1#!/usr/bin/env python -i
2# preceeding line should have path for Python on your machine
3
4# viz_gl.py
5# Purpose: viz running LIGGGHTS simulation via GL tool in Pizza.py
6# Syntax:  viz_gl.py in.liggghts Nfreq Nsteps
7#          in.liggghts = LIGGGHTS input script
8#          Nfreq = dump and viz shapshot every this many steps
9#          Nsteps = run for this many steps
10
11import sys
12sys.path.append("./pizza")
13
14# parse command line
15
16argv = sys.argv
17if len(argv) != 4:
18  print "Syntax: viz_gl.py in.liggghts Nfreq Nsteps"
19  sys.exit()
20
21infile = sys.argv[1]
22nfreq = int(sys.argv[2])
23nsteps = int(sys.argv[3])
24
25me = 0
26# uncomment if running in parallel via Pypar
27#import pypar
28#me = pypar.rank()
29#nprocs = pypar.size()
30
31from liggghts import liggghts
32lmp = liggghts()
33
34# run infile all at once
35# assumed to have no run command in it
36# dump a file in native LIGGGHTS dump format for Pizza.py dump tool
37
38lmp.file(infile)
39lmp.command("thermo %d" % nfreq)
40lmp.command("dump python all atom %d tmp.dump" % nfreq)
41
42# initial 0-step run to generate dump file and image
43
44lmp.command("run 0 pre yes post no")
45ntimestep = 0
46
47# wrapper on GL window via Pizza.py gl tool
48# just proc 0 handles reading of dump file and viz
49
50if me == 0:
51  import Tkinter
52  tkroot = Tkinter.Tk()
53  tkroot.withdraw()
54
55  from dump import dump
56  from gl import gl
57
58  d = dump("tmp.dump",0)
59  g = gl(d)
60  d.next()
61  d.unscale()
62  g.zoom(1)
63  g.shift(0,0)
64  g.rotate(0,270)
65  g.q(10)
66  g.box(1)
67  g.show(ntimestep)
68
69# run nfreq steps at a time w/out pre/post, read dump snapshot, display it
70
71while ntimestep < nsteps:
72  lmp.command("run %d pre no post no" % nfreq)
73  ntimestep += nfreq
74  if me == 0:
75    d.next()
76    d.unscale()
77    g.show(ntimestep)
78
79lmp.command("run 0 pre no post yes")
80
81# uncomment if running in parallel via Pypar
82#print "Proc %d out of %d procs has" % (me,nprocs), lmp
83#pypar.finalize()
84