From 140780bcd6e42c9fbd701db5faa820cd232c6042 Mon Sep 17 00:00:00 2001 From: sjplimp Date: Mon, 8 Nov 2010 21:04:35 +0000 Subject: [PATCH] git-svn-id: svn://svn.icms.temple.edu/lammps-ro/trunk@5229 f3b2605a-c512-4ea7-a41b-209d697bcdaa --- python/examples/viz_atomeye.py | 71 +++++++ python/examples/{viz.py => viz_gl.py} | 1 + python/examples/viz_pymol.py | 82 +++++++++ python/examples/vizplotgui_atomeye.py | 164 +++++++++++++++++ .../{vizplotgui.py => vizplotgui_gl.py} | 1 + python/examples/vizplotgui_pymol.py | 174 ++++++++++++++++++ 6 files changed, 493 insertions(+) create mode 100755 python/examples/viz_atomeye.py rename python/examples/{viz.py => viz_gl.py} (96%) create mode 100755 python/examples/viz_pymol.py create mode 100755 python/examples/vizplotgui_atomeye.py rename python/examples/{vizplotgui.py => vizplotgui_gl.py} (98%) create mode 100755 python/examples/vizplotgui_pymol.py diff --git a/python/examples/viz_atomeye.py b/python/examples/viz_atomeye.py new file mode 100755 index 0000000000..64f7505eda --- /dev/null +++ b/python/examples/viz_atomeye.py @@ -0,0 +1,71 @@ +#!/usr/local/bin/python -i +# preceeding line should have path for Python on your machine + +# viz.py +# Purpose: viz running LAMMPS simulation via GL tool in Pizza.py +# Syntax: viz.py in.lammps Nfreq Nsteps +# in.lammps = LAMMPS input script +# Nfreq = dump and viz shapshot every this many steps +# Nsteps = run for this many steps + +import sys,os + +# set this to point to AtomEye version 3 executable + +ATOMEYE3 = "/home/sjplimp/tools/atomeye3/A3.i686-20060530" + +# parse command line + +argv = sys.argv +if len(argv) != 4: + print "Syntax: viz.py in.lammps Nfreq Nsteps" + sys.exit() + +infile = sys.argv[1] +nfreq = int(sys.argv[2]) +nsteps = int(sys.argv[3]) + +me = 0 +# uncomment if running in parallel via Pypar +#import pypar +#me = pypar.rank() +#nprocs = pypar.size() + +from lammps import lammps +lmp = lammps() + +# run infile all at once +# assumed to have no run command in it +# dump a file in extended CFG format for AtomEye + +lmp.file(infile) +lmp.command("thermo %d" % nfreq) +lmp.command("dump python all cfg %d tmp.cfg.* id type xs ys zs" % nfreq) + +# initial 0-step run to generate dump file and image + +lmp.command("run 0 pre yes post no") +ntimestep = 0 + +# wrapper on GL window via Pizza.py gl tool +# just proc 0 handles reading of dump file and viz + +if me == 0: + a = os.popen(ATOMEYE3,'w') + a.write("load_config tmp.cfg.0\n") + a.flush() + +# run nfreq steps at a time w/out pre/post, read dump snapshot, display it + +while ntimestep < nsteps: + lmp.command("run %d pre no post no" % nfreq) + ntimestep += nfreq + if me == 0: + a.write("load_config tmp.cfg.%d\n" % ntimestep) + a.flush() + +lmp.command("run 0 pre no post yes") + +# uncomment if running in parallel via Pypar +#print "Proc %d out of %d procs has" % (me,nprocs), lmp +#pypar.finalize() diff --git a/python/examples/viz.py b/python/examples/viz_gl.py similarity index 96% rename from python/examples/viz.py rename to python/examples/viz_gl.py index 16b056123e..8117e70e29 100755 --- a/python/examples/viz.py +++ b/python/examples/viz_gl.py @@ -33,6 +33,7 @@ lmp = lammps() # run infile all at once # assumed to have no run command in it +# dump a file in native LAMMPS dump format for Pizza.py dump tool lmp.file(infile) lmp.command("thermo %d" % nfreq) diff --git a/python/examples/viz_pymol.py b/python/examples/viz_pymol.py new file mode 100755 index 0000000000..887c523c7a --- /dev/null +++ b/python/examples/viz_pymol.py @@ -0,0 +1,82 @@ +#!/usr/local/bin/python -i +# preceeding line should have path for Python on your machine + +# viz_pymol.py +# Purpose: viz running LAMMPS simulation via PyMol +# Syntax: viz_pymol.py in.lammps Nfreq Nsteps +# in.lammps = LAMMPS input script +# Nfreq = dump and viz shapshot every this many steps +# Nsteps = run for this many steps + +import sys +sys.path.append("./pizza") + +# parse command line + +argv = sys.argv +if len(argv) != 4: + print "Syntax: viz_pymol.py in.lammps Nfreq Nsteps" + sys.exit() + +infile = sys.argv[1] +nfreq = int(sys.argv[2]) +nsteps = int(sys.argv[3]) + +me = 0 +# uncomment if running in parallel via Pypar +#import pypar +#me = pypar.rank() +#nprocs = pypar.size() + +from lammps import lammps +lmp = lammps() + +# run infile all at once +# assumed to have no run command in it +# dump a file in native LAMMPS dump format for Pizza.py dump tool + +lmp.file(infile) +lmp.command("thermo %d" % nfreq) +lmp.command("dump python all atom %d tmp.dump" % nfreq) + +# initial 0-step run to generate dump file and image + +lmp.command("run 0 pre yes post no") +ntimestep = 0 + +# wrapper on GL window via Pizza.py gl tool +# just proc 0 handles reading of dump file and viz + +if me == 0: + import pymol + pymol.finish_launching() + + from dump import dump + from pdbfile import pdbfile + from pymol import cmd as pm + + d = dump("tmp.dump",0) + p = pdbfile(d) + d.next() + d.unscale() + p.single(ntimestep) + pm.load("tmp.pdb") + pm.show("spheres","tmp") + +# run nfreq steps at a time w/out pre/post, read dump snapshot, display it + +while ntimestep < nsteps: + lmp.command("run %d pre no post no" % nfreq) + ntimestep += nfreq + if me == 0: + d.next() + d.unscale() + p.single(ntimestep) + pm.load("tmp.pdb") + pm.forward() + +lmp.command("run 0 pre no post yes") + +# uncomment if running in parallel via Pypar +#print "Proc %d out of %d procs has" % (me,nprocs), lmp +#pypar.finalize() diff --git a/python/examples/vizplotgui_atomeye.py b/python/examples/vizplotgui_atomeye.py new file mode 100755 index 0000000000..7969e8a1bd --- /dev/null +++ b/python/examples/vizplotgui_atomeye.py @@ -0,0 +1,164 @@ +#!/usr/local/bin/python -i +# preceeding line should have path for Python on your machine + +# vizplotgui.py +# Purpose: viz running LAMMPS simulation with plot and GUI +# Syntax: vizplotgui.py in.lammps Nfreq compute-ID +# in.lammps = LAMMPS input script +# Nfreq = plot data point and viz shapshot every this many steps +# compute-ID = ID of compute that calculates temperature +# (or any other scalar quantity) + +# IMPORTANT: this script cannot yet be run in parallel via Pypar, +# because I can't seem to do a MPI-style broadcast in Pypar + +import sys,os,time +sys.path.append("./pizza") + +# first line if want AtomEye output to screen, 2nd line to file +#ATOMEYE3 = "/home/sjplimp/tools/atomeye3/A3.i686-20060530" +ATOMEYE3 = "/home/sjplimp/tools/atomeye3/A3.i686-20060530 > atomeye.out" + +# methods called by GUI + +def run(): + global runflag + runflag = 1 +def stop(): + global runflag + runflag = 0 +def settemp(value): + global temptarget + temptarget = slider.get() +def quit(): + global breakflag + breakflag = 1 + +# method called by timestep loop every Nfreq steps +# read dump snapshot and viz it, update plot with compute value + +def update(ntimestep): + a.write("load_config tmp.cfg.%d\n" % ntimestep) + a.flush() + value = lmp.extract_compute(compute,0,0) + xaxis.append(ntimestep) + yaxis.append(value) + gn.plot(xaxis,yaxis) + +# parse command line + +argv = sys.argv +if len(argv) != 4: + print "Syntax: vizplotgui.py in.lammps Nfreq compute-ID" + sys.exit() + +infile = sys.argv[1] +nfreq = int(sys.argv[2]) +compute = sys.argv[3] + +me = 0 +# uncomment if running in parallel via Pypar +#import pypar +#me = pypar.rank() +#nprocs = pypar.size() + +from lammps import lammps +lmp = lammps() + +# run infile all at once +# assumed to have no run command in it +# dump a file in extended CFG format for AtomEye + +lmp.file(infile) +lmp.command("thermo %d" % nfreq) +lmp.command("dump python all cfg %d tmp.cfg.* id type xs ys zs" % nfreq) + +# initial 0-step run to generate initial 1-point plot, dump file, and image + +lmp.command("run 0 pre yes post no") +value = lmp.extract_compute(compute,0,0) +ntimestep = 0 +xaxis = [ntimestep] +yaxis = [value] + +breakflag = 0 +runflag = 0 +temptarget = 1.0 + +# wrapper on GL window via Pizza.py gl tool +# just proc 0 handles reading of dump file and viz + +if me == 0: + a = os.popen(ATOMEYE3,'w') + a.write("load_config tmp.cfg.0\n") + a.flush() + +# display GUI with run/stop buttons and slider for temperature + +if me == 0: + from Tkinter import * + tkroot = Tk() + tkroot.withdraw() + root = Toplevel(tkroot) + root.title("LAMMPS GUI") + + frame = Frame(root) + Button(frame,text="Run",command=run).pack(side=LEFT) + Button(frame,text="Stop",command=stop).pack(side=LEFT) + slider = Scale(frame,from_=0.0,to=5.0,resolution=0.1, + orient=HORIZONTAL,label="Temperature") + slider.bind('',settemp) + slider.set(temptarget) + slider.pack(side=LEFT) + Button(frame,text="Quit",command=quit).pack(side=RIGHT) + frame.pack() + tkroot.update() + +# wrapper on GnuPlot via Pizza.py gnu tool + +if me == 0: + from gnu import gnu + gn = gnu() + gn.plot(xaxis,yaxis) + gn.title(compute,"Timestep","Temperature") + +# endless loop, checking status of GUI settings every Nfreq steps +# run with pre yes/no and post yes/no depending on go/stop status +# re-invoke fix langevin with new seed when temperature slider changes +# after re-invoke of fix langevin, run with pre yes + +running = 0 +temp = temptarget +seed = 12345 + +lmp.command("fix 2 all langevin %g %g 0.1 %d" % (temp,temp,seed)) + +while 1: + if me == 0: tkroot.update() + if temp != temptarget: + temp = temptarget + seed += me+1 + lmp.command("fix 2 all langevin %g %g 0.1 12345" % (temp,temp)) + running = 0 + if runflag and running: + lmp.command("run %d pre no post no" % nfreq) + ntimestep += nfreq + if me == 0: update(ntimestep) + elif runflag and not running: + lmp.command("run %d pre yes post no" % nfreq) + ntimestep += nfreq + if me == 0: update(ntimestep) + elif not runflag and running: + lmp.command("run %d pre no post yes" % nfreq) + ntimestep += nfreq + if me == 0: update(ntimestep) + if breakflag: break + if runflag: running = 1 + else: running = 0 + time.sleep(0.01) + +lmp.command("run 0 pre no post yes") + +# uncomment if running in parallel via Pypar +#print "Proc %d out of %d procs has" % (me,nprocs), lmp +#pypar.finalize() diff --git a/python/examples/vizplotgui.py b/python/examples/vizplotgui_gl.py similarity index 98% rename from python/examples/vizplotgui.py rename to python/examples/vizplotgui_gl.py index ea2d004f21..2cf08dae68 100755 --- a/python/examples/vizplotgui.py +++ b/python/examples/vizplotgui_gl.py @@ -64,6 +64,7 @@ lmp = lammps() # run infile all at once # assumed to have no run command in it +# dump a file in native LAMMPS dump format for Pizza.py dump tool lmp.file(infile) lmp.command("thermo %d" % nfreq) diff --git a/python/examples/vizplotgui_pymol.py b/python/examples/vizplotgui_pymol.py new file mode 100755 index 0000000000..d5b356e390 --- /dev/null +++ b/python/examples/vizplotgui_pymol.py @@ -0,0 +1,174 @@ +#!/usr/local/bin/python -i +# preceeding line should have path for Python on your machine + +# vizplotgui_pymol.py +# Purpose: viz running LAMMPS simulation with plot and GUI +# Syntax: vizplotgui_pymol.py in.lammps Nfreq compute-ID +# in.lammps = LAMMPS input script +# Nfreq = plot data point and viz shapshot every this many steps +# compute-ID = ID of compute that calculates temperature +# (or any other scalar quantity) + +# IMPORTANT: this script cannot yet be run in parallel via Pypar, +# because I can't seem to do a MPI-style broadcast in Pypar + +import sys,time +sys.path.append("./pizza") + +# methods called by GUI + +def run(): + global runflag + runflag = 1 +def stop(): + global runflag + runflag = 0 +def settemp(value): + global temptarget + temptarget = slider.get() +def quit(): + global breakflag + breakflag = 1 + +# method called by timestep loop every Nfreq steps +# read dump snapshot and viz it, update plot with compute value + +def update(ntimestep): + d.next() + d.unscale() + p.single(ntimestep) + pm.load("tmp.pdb") + pm.forward() + value = lmp.extract_compute(compute,0,0) + xaxis.append(ntimestep) + yaxis.append(value) + gn.plot(xaxis,yaxis) + +# parse command line + +argv = sys.argv +if len(argv) != 4: + print "Syntax: vizplotgui.py in.lammps Nfreq compute-ID" + sys.exit() + +infile = sys.argv[1] +nfreq = int(sys.argv[2]) +compute = sys.argv[3] + +me = 0 +# uncomment if running in parallel via Pypar +#import pypar +#me = pypar.rank() +#nprocs = pypar.size() + +from lammps import lammps +lmp = lammps() + +# run infile all at once +# assumed to have no run command in it +# dump a file in native LAMMPS dump format for Pizza.py dump tool + +lmp.file(infile) +lmp.command("thermo %d" % nfreq) +lmp.command("dump python all atom %d tmp.dump" % nfreq) + +# initial 0-step run to generate initial 1-point plot, dump file, and image + +lmp.command("run 0 pre yes post no") +value = lmp.extract_compute(compute,0,0) +ntimestep = 0 +xaxis = [ntimestep] +yaxis = [value] + +breakflag = 0 +runflag = 0 +temptarget = 1.0 + +# wrapper on PyMol +# just proc 0 handles reading of dump file and viz + +if me == 0: + import pymol + pymol.finish_launching() + + from dump import dump + from pdbfile import pdbfile + from pymol import cmd as pm + + d = dump("tmp.dump",0) + p = pdbfile(d) + d.next() + d.unscale() + p.single(ntimestep) + pm.load("tmp.pdb") + pm.show("spheres","tmp") + +# display GUI with run/stop buttons and slider for temperature + +if me == 0: + from Tkinter import * + tkroot = Tk() + tkroot.withdraw() + root = Toplevel(tkroot) + root.title("LAMMPS GUI") + + frame = Frame(root) + Button(frame,text="Run",command=run).pack(side=LEFT) + Button(frame,text="Stop",command=stop).pack(side=LEFT) + slider = Scale(frame,from_=0.0,to=5.0,resolution=0.1, + orient=HORIZONTAL,label="Temperature") + slider.bind('',settemp) + slider.set(temptarget) + slider.pack(side=LEFT) + Button(frame,text="Quit",command=quit).pack(side=RIGHT) + frame.pack() + tkroot.update() + +# wrapper on GnuPlot via Pizza.py gnu tool + +if me == 0: + from gnu import gnu + gn = gnu() + gn.plot(xaxis,yaxis) + gn.title(compute,"Timestep","Temperature") + +# endless loop, checking status of GUI settings every Nfreq steps +# run with pre yes/no and post yes/no depending on go/stop status +# re-invoke fix langevin with new seed when temperature slider changes +# after re-invoke of fix langevin, run with pre yes + +running = 0 +temp = temptarget +seed = 12345 + +lmp.command("fix 2 all langevin %g %g 0.1 %d" % (temp,temp,seed)) + +while 1: + if me == 0: tkroot.update() + if temp != temptarget: + temp = temptarget + seed += me+1 + lmp.command("fix 2 all langevin %g %g 0.1 12345" % (temp,temp)) + running = 0 + if runflag and running: + lmp.command("run %d pre no post no" % nfreq) + ntimestep += nfreq + if me == 0: update(ntimestep) + elif runflag and not running: + lmp.command("run %d pre yes post no" % nfreq) + ntimestep += nfreq + if me == 0: update(ntimestep) + elif not runflag and running: + lmp.command("run %d pre no post yes" % nfreq) + ntimestep += nfreq + if me == 0: update(ntimestep) + if breakflag: break + if runflag: running = 1 + else: running = 0 + time.sleep(0.01) + +lmp.command("run 0 pre no post yes") + +# uncomment if running in parallel via Pypar +#print "Proc %d out of %d procs has" % (me,nprocs), lmp +#pypar.finalize()