1#!/usr/bin/env python -i
2# preceeding line should have path for Python on your machine
3
4# viz_vmd.py
5# Purpose: viz running LIGGGHTS simulation via VMD
6# Syntax:  viz_vmd.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_vmd.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
37lmp.file(infile)
38lmp.command("thermo %d" % nfreq)
39lmp.command("dump python all atom %d tmp.dump" % nfreq)
40
41# initial 0-step run to generate dump file and image
42
43lmp.command("run 0 pre yes post no")
44ntimestep = 0
45
46# wrapper on VMD window via Pizza.py vmd tool
47# just proc 0 handles reading of dump file and viz
48
49if me == 0:
50  from vmd import vmd
51  v = vmd()
52  v('menu main off')
53  v.rep('VDW')
54
55  from dump import dump
56  from pdbfile import pdbfile
57
58  d = dump('tmp.dump',0)
59  p = pdbfile(d)
60  d.next()
61  d.unscale()
62  p.single(ntimestep)
63  v.new('tmp.pdb','pdb')
64
65# run nfreq steps at a time w/out pre/post, read dump snapshot, display it
66
67while ntimestep < nsteps:
68  lmp.command("run %d pre no post no" % nfreq)
69  ntimestep += nfreq
70  if me == 0:
71    d.next()
72    d.unscale()
73    p.single(ntimestep)
74    # add frame to current data set
75    v.append('tmp.pdb','pdb')
76    # delete all frame and add new.
77    #v.update('tmp.dump')
78
79lmp.command("run 0 pre no post yes")
80
81if me == 0:
82  v.flush()
83  # uncomment the following, if you want to work with the viz some more.
84  #v('menu main on')
85  #print "type quit to terminate."
86  #v.enter()
87  #v.stop()
88
89# uncomment if running in parallel via Pypar
90#print "Proc %d out of %d procs has" % (me,nprocs), lmp
91#pypar.finalize()
92