1#!/usr/bin/env python -i
2# preceeding line should have path for Python on your machine
3
4# viz_pymol.py
5# Purpose: viz running LIGGGHTS simulation via PyMol
6# Syntax:  viz_pymol.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_pymol.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 PyMol
48# just proc 0 handles reading of dump file and viz
49
50if me == 0:
51  import pymol
52  pymol.finish_launching()
53
54  from dump import dump
55  from pdbfile import pdbfile
56  from pymol import cmd as pm
57
58  d = dump("tmp.dump",0)
59  p = pdbfile(d)
60  d.next()
61  d.unscale()
62  p.single(ntimestep)
63  pm.load("tmp.pdb")
64  pm.show("spheres","tmp")
65
66# run nfreq steps at a time w/out pre/post, read dump snapshot, display it
67
68while ntimestep < nsteps:
69  lmp.command("run %d pre no post no" % nfreq)
70  ntimestep += nfreq
71  if me == 0:
72    d.next()
73    d.unscale()
74    p.single(ntimestep)
75    pm.load("tmp.pdb")
76    pm.forward()
77
78lmp.command("run 0 pre no post yes")
79
80# uncomment if running in parallel via Pypar
81#print "Proc %d out of %d procs has" % (me,nprocs), lmp
82#pypar.finalize()
83