Committer: ckloss <ckloss@fluid38.(none)>

On branch master
 Initial commit for lpp, version 2011-10-11
This commit is contained in:
ckloss
2012-02-03 14:10:31 +01:00
commit 80592c0da1
227 changed files with 119295 additions and 0 deletions

20
scripts/README Normal file
View File

@ -0,0 +1,20 @@
This directory contains a collection of scripts written by Pizza.py
users that are generically useful; you may wish to use them directly
or modify them for your own purposes. You can add your own scripts to
this directory as well.
Any script in this directory (or other directories you define, see the
Pizza.py manual), can be run from Pizza.py, by typing a line
appropriate to the script's syntax, e.g.
% pizza.py -f movie.py svg 0.5 60 135 dump.* from the shell
> @run movie.py svg 0.5 60 135 dump.* from Pizza.py
The top of each script file describes its purpose and syntax. That
information can be be accessed from within Pizza.py by typing "??" or
"? name.py" or "?? name.py".
Many of the scripts can also be run directly from Python (without
running Pizza.py), so long as the Pizza.py tools (Python files) it
needs to import (e.g. log.py) can be found by Python.

156
scripts/angle_distribute.py Normal file
View File

@ -0,0 +1,156 @@
#!/usr/bin/python
# Script: angle_distribute.py
# Purpose: binned angle distributions by angle type
# Syntax: angle_distribute.py datafile nbin theta_min theta_max outfile files ...
# datafile = lammps data file
# nbin = # of bins per angle type
# theta_min = min expected angle
# theta_max = max expected angle length
# outfile = file to write stats to
# files = series of dump files
# Example: angle_distribute.py pore.data 1000 110. 120. angles.out pore.dump.1
# Author: Paul Crozier (Sandia)
# enable script to run from Python directly w/out Pizza.py
import sys
from dump import dump
from math import sqrt,acos,atan
if not globals().has_key("argv"): argv = sys.argv
# main script
if len(argv) < 7:
raise StandardError, \
"Syntax: angle_distribute.py datafile nbin theta_min theta_max outfile files ..."
dt = data(argv[1])
nbins = int(argv[2])
theta_min = float(argv[3])
theta_max = float(argv[4])
outfile = argv[5]
files = ' '.join(argv[6:])
# get the angles from the data file
angle = dt.get("Angles")
nangles = len(angle)
atype = nangles * [0]
iatom = nangles * [0]
jatom = nangles * [0]
katom = nangles * [0]
for i in xrange(nangles):
atype[i] = int(angle[i][1] - 1)
iatom[i] = int(angle[i][2] - 1)
jatom[i] = int(angle[i][3] - 1)
katom[i] = int(angle[i][4] - 1)
ntypes = 0
for i in xrange(nangles): ntypes = max(angle[i][1],ntypes)
ntypes = int(ntypes)
ncount = ntypes * [0]
bin = nbins * [0]
for i in xrange(nbins):
bin[i] = ntypes * [0]
# read snapshots one-at-a-time
d = dump(files,0)
d.map(1,"id",2,"type",3,"x",4,"y",5,"z")
PI = 4.0*atan(1.0)
while 1:
time = d.next()
if time == -1: break
box = (d.snaps[-1].xlo,d.snaps[-1].ylo,d.snaps[-1].zlo,
d.snaps[-1].xhi,d.snaps[-1].yhi,d.snaps[-1].zhi)
xprd = box[3] - box[0]
yprd = box[4] - box[1]
zprd = box[5] - box[2]
d.unscale()
d.sort()
x,y,z = d.vecs(time,"x","y","z")
for i in xrange(nangles):
delx1 = x[iatom[i]] - x[jatom[i]]
dely1 = y[iatom[i]] - y[jatom[i]]
delz1 = z[iatom[i]] - z[jatom[i]]
if abs(delx1) > 0.5*xprd:
if delx1 < 0.0:
delx1 += xprd
else:
delx1 -= xprd
if abs(dely1) > 0.5*yprd:
if dely1 < 0.0:
dely1 += yprd
else:
dely1 -= yprd
if abs(delz1) > 0.5*zprd:
if delz1 < 0.0:
delz1 += zprd
else:
delz1 -= zprd
r1 = sqrt(delx1*delx1 + dely1*dely1 + delz1*delz1)
delx2 = x[katom[i]] - x[jatom[i]]
dely2 = y[katom[i]] - y[jatom[i]]
delz2 = z[katom[i]] - z[jatom[i]]
if abs(delx2) > 0.5*xprd:
if delx2 < 0.0:
delx2 += xprd
else:
delx2 -= xprd
if abs(dely2) > 0.5*yprd:
if dely2 < 0.0:
dely2 += yprd
else:
dely2 -= yprd
if abs(delz2) > 0.5*zprd:
if delz2 < 0.0:
delz2 += zprd
else:
delz2 -= zprd
r2 = sqrt(delx2*delx2 + dely2*dely2 + delz2*delz2)
c = delx1*delx2 + dely1*dely2 + delz1*delz2
c /= r1*r2
if (c > 1.0): c = 1.0
if (c < -1.0): c = -1.0
theta = 180.0*acos(c)/PI
ibin = int(nbins*(theta - theta_min)/(theta_max - theta_min) + 0.5)
if ((ibin >= 0) and (ibin <= nbins-1)):
bin[ibin][atype[i]] += nbins
ncount[atype[i]] += 1
else:
print "Warning: angle outside specified range"
print "angle type:", atype[i]+1
print "angle number:", i
print time,
print
print "Printing normalized angle distributions to",outfile
fp = open(outfile,"w")
theta_range = theta_max - theta_min
for i in xrange(nbins):
print >>fp, theta_min + theta_range*float(i)/float(nbins),
for j in xrange(ntypes):
if (ncount[j] > 0):
print >>fp, float(bin[i][j])/float(ncount[j])/theta_range,
else:
print >>fp, 0.0,
print >>fp
fp.close()

137
scripts/block.py Normal file
View File

@ -0,0 +1,137 @@
#!/usr/bin/python
# Script: block.py
# Purpose: thermodynamic block averages from LAMMPS log files
# Syntax: block.py nblocks nskip log.1 log.2 ...
# nblocks = number of blocks for block averages
# nskip = skip first nskip samples in the log file(s)
# files = series of log files (LAMMPS thermo one style only)
# Example: block.py 10 0 log.*
# Author: Paul Crozier (Sandia)
# enable script to run from Python directly w/out Pizza.py
import sys
from log import log
if not globals().has_key("argv"): argv = sys.argv
# main script
if len(argv) < 4:
raise StandardError, "Syntax: block.py nblocks nskip log.1 log.2 ..."
nblocks = int(argv[1])
nskip = int(argv[2])
files = ' '.join(argv[3:])
l = log(files)
# assumes LAMMPS thermo style one
e_bond,e_pair,e_total,pressure,step,temperature = \
l.get("E_bond","E_pair", "E_total", "Pressure", "Step", "Temperature")
if "Volume" in l.names:
vflag = 1
volume = l.get("Volume")
else: vflag = 0
print "Computing %g block averages" % nblocks
print "Skipping first %g samples" % nskip
n = len(step)
n_per_block = (n-nskip)/nblocks
k = nskip
temperature_ave = []
e_bond_ave = []
e_pair_ave = []
e_total_ave = []
pressure_ave = []
volume_ave = []
print
print " Block Samples Temperature E_bond E_pair", \
" E_total Pressure Volume"
for i in xrange(nblocks):
temperature_sum = 0
e_bond_sum = 0
e_pair_sum = 0
e_total_sum = 0
pressure_sum = 0
volume_sum = 0
samples = 0
for j in xrange(n_per_block):
temperature_sum += temperature[k]
e_bond_sum += e_bond[k]
e_pair_sum += e_pair[k]
e_total_sum += e_total[k]
pressure_sum += pressure[k]
if vflag: volume_sum += volume[k]
samples += 1
k += 1
temperature_ave.append(temperature_sum/samples)
e_bond_ave.append(e_bond_sum/samples)
e_pair_ave.append(e_pair_sum/samples)
e_total_ave.append(e_total_sum/samples)
pressure_ave.append(pressure_sum/samples)
volume_ave.append(volume_sum/samples)
print " %5i %10i %11.2f %11.2f %11.2f %11.2f %11.2f %11.2f" % \
(i+1, samples, temperature_ave[i], e_bond_ave[i], e_pair_ave[i], \
e_total_ave[i], pressure_ave[i], volume_ave[i])
grand_ave_temperature = 0.0
grand_ave_e_bond = 0.0
grand_ave_e_pair = 0.0
grand_ave_e_total = 0.0
grand_ave_pressure = 0.0
grand_ave_volume = 0.0
stdev_temperature = 0.0
stdev_e_bond = 0.0
stdev_e_pair = 0.0
stdev_e_total = 0.0
stdev_pressure = 0.0
stdev_volume = 0.0
for i in xrange(nblocks):
grand_ave_temperature += temperature_ave[i]
grand_ave_e_bond += e_bond_ave[i]
grand_ave_e_pair += e_pair_ave[i]
grand_ave_e_total += e_total_ave[i]
grand_ave_pressure += pressure_ave[i]
grand_ave_volume += volume_ave[i]
grand_ave_temperature /= nblocks
grand_ave_e_bond /= nblocks
grand_ave_e_pair /= nblocks
grand_ave_e_total /= nblocks
grand_ave_pressure /= nblocks
grand_ave_volume /= nblocks
for i in xrange(nblocks):
stdev_temperature += (temperature_ave[i] - grand_ave_temperature)* \
(temperature_ave[i] - grand_ave_temperature)
stdev_e_bond += (e_bond_ave[i] - grand_ave_e_bond)* \
(e_bond_ave[i] - grand_ave_e_bond)
stdev_e_pair += (e_pair_ave[i] - grand_ave_e_pair)* \
(e_pair_ave[i] - grand_ave_e_pair)
stdev_e_total += (e_total_ave[i] - grand_ave_e_total)* \
(e_total_ave[i] - grand_ave_e_total)
stdev_pressure += (pressure_ave[i] - grand_ave_pressure)* \
(pressure_ave[i] - grand_ave_pressure)
stdev_volume += (volume_ave[i] - grand_ave_volume)* \
(volume_ave[i] - grand_ave_volume)
from math import *
stdev_temperature = sqrt(stdev_temperature/(nblocks-1))
stdev_e_bond = sqrt(stdev_e_bond/(nblocks-1))
stdev_e_pair = sqrt(stdev_e_pair/(nblocks-1))
stdev_e_total = sqrt(stdev_e_total/(nblocks-1))
stdev_pressure = sqrt(stdev_pressure/(nblocks-1))
stdev_volume = sqrt(stdev_volume/(nblocks-1))
print " ====================================================", \
"==================================="
print " Ave. %11.2f %11.2f %11.2f %11.2f %11.2f %11.2f" % \
(grand_ave_temperature, grand_ave_e_bond, grand_ave_e_pair, \
grand_ave_e_total, grand_ave_pressure, grand_ave_volume)
print " Stdev %11.2f %11.2f %11.2f %11.2f %11.2f %11.2f" % \
(stdev_temperature, stdev_e_bond, stdev_e_pair, \
stdev_e_total, stdev_pressure, stdev_volume)

122
scripts/bond_distribute.py Normal file
View File

@ -0,0 +1,122 @@
#!/usr/bin/python
# Script: bond_distribute.py
# Purpose: binned bond length distributions by bond type
# Syntax: bond_distribute.py datafile nbin rmin rmax outfile files ...
# datafile = lammps data file
# nbin = # of bins per bond type
# rmin = min expected bond length
# rmax = max expected bond length
# outfile = file to write stats to
# files = series of dump files
# Example: bond_distribute.py pore.data 1000 1.5 1.85 bonds.out pore.dump.1
# Author: Paul Crozier (Sandia)
# enable script to run from Python directly w/out Pizza.py
import sys
from dump import dump
from math import sqrt
if not globals().has_key("argv"): argv = sys.argv
# main script
if len(argv) < 7:
raise StandardError, \
"Syntax: bond_distribute.py datafile nbin rmin rmax outfile files ..."
dt = data(argv[1])
nbins = int(argv[2])
rmin = float(argv[3])
rmax = float(argv[4])
outfile = argv[5]
files = ' '.join(argv[6:])
# get the bonds from the data file
bond = dt.get("Bonds")
nbonds = len(bond)
btype = nbonds * [0]
iatom = nbonds * [0]
jatom = nbonds * [0]
for i in xrange(nbonds):
btype[i] = int(bond[i][1] - 1)
iatom[i] = int(bond[i][2] - 1)
jatom[i] = int(bond[i][3] - 1)
ntypes = 0
for i in xrange(nbonds): ntypes = max(bond[i][1],ntypes)
ntypes = int(ntypes)
ncount = ntypes * [0]
bin = nbins * [0]
for i in xrange(nbins):
bin[i] = ntypes * [0]
# read snapshots one-at-a-time
d = dump(files,0)
d.map(1,"id",2,"type",3,"x",4,"y",5,"z")
while 1:
time = d.next()
if time == -1: break
box = (d.snaps[-1].xlo,d.snaps[-1].ylo,d.snaps[-1].zlo,
d.snaps[-1].xhi,d.snaps[-1].yhi,d.snaps[-1].zhi)
xprd = box[3] - box[0]
yprd = box[4] - box[1]
zprd = box[5] - box[2]
d.unscale()
d.sort()
x,y,z = d.vecs(time,"x","y","z")
for i in xrange(nbonds):
delx = x[jatom[i]] - x[iatom[i]]
dely = y[jatom[i]] - y[iatom[i]]
delz = z[jatom[i]] - z[iatom[i]]
if abs(delx) > 0.5*xprd:
if delx < 0.0:
delx += xprd
else:
delx -= xprd
if abs(dely) > 0.5*yprd:
if dely < 0.0:
dely += yprd
else:
dely -= yprd
if abs(delz) > 0.5*zprd:
if delz < 0.0:
delz += zprd
else:
delz -= zprd
r = sqrt(delx*delx + dely*dely + delz*delz)
ibin = int(nbins*(r - rmin)/(rmax - rmin) + 0.5)
if ((ibin >= 0) and (ibin <= nbins-1)):
bin[ibin][btype[i]] += nbins
ncount[btype[i]] += 1
else:
print "Warning: bond distance outside specified range"
print "Bond type:", btype[i]+1
print "Bond number:", i
print time,
print
print "Printing bond distance normalized distribution to",outfile
fp = open(outfile,"w")
rrange = rmax - rmin
for i in xrange(nbins):
print >>fp, rmin + rrange*float(i)/float(nbins),
for j in xrange(ntypes):
if (ncount[j] > 0):
print >>fp, float(bin[i][j])/float(ncount[j])/rrange,
else:
print >>fp, 0.0,
print >>fp
fp.close()

32
scripts/clogview.py Normal file
View File

@ -0,0 +1,32 @@
#!/usr/bin/python
# Script: clogview.py
# Purpose: plots of ChemCell log-file concentration data
# Syntax: clogview.py gnu/matlab files ...
# gnu/matlab = style of plots to create
# files = one or more log files
# Example: clogview.py gnu log.*
# Author: Steve Plimpton (Sandia)
# enable script to run from Python directly w/out Pizza.py
import sys
from clog import clog
from plotview import plotview
from gnu import gnu
from matlab import matlab
if not globals().has_key("argv"): argv = sys.argv
# main script
if len(argv) < 3:
raise StandardError, "Syntax: clogview.py gnu/matlab files ..."
style = argv[1]
files = ' '.join(argv[2:])
c = clog(files)
exec "plot = %s()" % style
p = plotview(c,plot)
p.x = "Time"

123
scripts/cluster.py Normal file
View File

@ -0,0 +1,123 @@
#!/usr/bin/python
# Script: cluster.py
# Purpose: histogram of cluster size of type2 atoms near type1
# Syntax: cluster.py type1 type2 cutoff nbin dump.1 dump.2 ...
# type1,type2 = atom types (1-N)
# cutoff = only consider atom pairs within distance cutoff
# nbin = # of bins for histogram
# files = series of dump files
# Example: cluster.py 1 5 2.0 10 dump.*
# Author: Steve Plimpton (Sandia)
# for all snapshots, for each type1 atom, count # of type2 atoms within cutoff
# will be very slow (N^2) if are too many type1 atoms
# enable script to run from Python directly w/out Pizza.py
import sys
from dump import dump
from gnu import gnu
if not globals().has_key("argv"): argv = sys.argv
# main script
# function to compute distance sq between 2 atoms with PBC
def distance(atom1,atom2,box):
x1 = atom1[2]
y1 = atom1[3]
z1 = atom1[4]
x2 = atom2[2]
y2 = atom2[3]
z2 = atom2[4]
delx = x2 - x1
dely = y2 - y1
delz = z2 - z1
xprd = box[3] - box[0]
yprd = box[4] - box[1]
zprd = box[5] - box[2]
if abs(delx) > 0.5*xprd:
if delx < 0.0:
delx += xprd
else:
delx -= xprd
if abs(dely) > 0.5*yprd:
if dely < 0.0:
dely += yprd
else:
dely -= yprd
if abs(delz) > 0.5*zprd:
if delz < 0.0:
delz += zprd
else:
delz -= zprd
distsq = delx*delx + dely*dely + delz*delz
return distsq
# main script
if len(argv) < 6:
raise StandardError,"cluster.py type1 type2 cutoff nbin dump.1 dump.2 ..."
type1 = int(argv[1])
type2 = int(argv[2])
cutoff = float(argv[3])
nbin = int(argv[4])
files = ' '.join(argv[5:])
# read in dump file(s) and select only type1 or type2 atoms
d = dump(files)
d.aselect.test("$type == %d or $type == %d" % (type1,type2))
# loop over snapshots
# viz returns list of atoms in one snapshot
cutsq = cutoff*cutoff
cluster = nbin*[0]
print "Clustering ..."
flag = 0
while 1:
which,time,flag = d.iterator(flag)
if flag == -1: break
time,box,atoms,bonds,tris = d.viz(which)
print time,
sys.stdout.flush()
# loop over all type1 atoms
n = len(atoms)
for i in xrange(n):
itype = atoms[i][1]
if itype != type1: continue
ncount = 0
# loop over all type2 atoms
# increment cluster count if distance is within cutoff
for j in xrange(n):
jtype = atoms[j][1]
if jtype != type2 or i == j: continue
distsq = distance(atoms[i],atoms[j],box)
if distsq < cutsq: ncount += 1
# increment histogram count
if ncount >= nbin: cluster[nbin-1] += 1
else: cluster[ncount] += 1
print
print "Cluster size and count:"
for i in range(nbin): print i,cluster[i]
# comment out if don't want plot
#g = gnu()
#g.plot(range(nbin),cluster)

77
scripts/density.py Normal file
View File

@ -0,0 +1,77 @@
#!/usr/bin/python
# Script: density.py
# Purpose: binned atom density by atom type
# Syntax: density.py x/y/z nbin outfile files ...
# x/y/z = get density distribution along this axis
# nbin = # of bins in desired direction
# outfile = file to write flux stats to
# files = series of dump files
# Example: density.py z 100 dens.out dump.*
# Author: Paul Crozier (Sandia)
# enable script to run from Python directly w/out Pizza.py
import sys
from dump import dump
if not globals().has_key("argv"): argv = sys.argv
# main script
if len(argv) < 5:
raise StandardError, "Syntax: density.py x/y/z nbin outfile files ..."
direction = argv[1]
nbins = int(argv[2])
outfile = argv[3]
files = ' '.join(argv[4:])
# read snapshots one-at-a-time
d = dump(files,0)
d.map(1,"id",2,"type",3,"x",4,"y",5,"z")
first = 1
nsnaps = 0
while 1:
time = d.next()
if time == -1: break
if first:
tmp,ntypes = d.minmax("type")
ntypes = int(ntypes)
bin = nbins * [0]
for i in xrange(nbins): bin[i] = ntypes * [0]
first = 0
box = (d.snaps[-1].xlo,d.snaps[-1].ylo,d.snaps[-1].zlo,
d.snaps[-1].xhi,d.snaps[-1].yhi,d.snaps[-1].zhi)
vol = (box[3] - box[0]) * (box[4] - box[1]) * (box[5] - box[2])
if direction == "x": type,x = d.vecs(time,"type","x")
elif direction == "y": type,x = d.vecs(time,"type","y")
elif direction == "z": type,x = d.vecs(time,"type","z")
type = map(int,type)
natoms = len(type)
for i in xrange(natoms): type[i] -= 1
for i in xrange(natoms):
ibin = int(nbins*x[i] + 0.5)
if (ibin < 0): ibin += nbins
if (ibin > nbins-1): ibin -= nbins
bin[ibin][type[i]] += nbins/vol
nsnaps += 1
print time,
print
print "Printing ", direction, "-directional density distribution in mol/L to",outfile
conversion = 1660.53873 # convert from atoms/Angs^3 to mol/L
fp = open(outfile,"w")
for i in xrange(nbins):
print >>fp, float(i)/float(nbins),
for j in xrange(ntypes):
print >>fp, conversion*bin[i][j]/nsnaps,
print >>fp
fp.close()

138
scripts/density2d.py Normal file
View File

@ -0,0 +1,138 @@
#!/usr/bin/python
# Script: density2d.py
# Purpose: binned atom density by atom type
# Syntax: density.py x/y/z nbin vmin vmax outfile files ...
# x/y/z = get density distribution along this (vertical) axis,
# bining along the other two (planar) axes
# nbin = # of bins along each of planar axes
# vmin, vmax = min and max along the vertical axis,
# use 0 for both for the complete box
# outfile = file to write flux stats to
# files = series of dump files
# Example: density2d.py z 100 dens.out dump.*
# Modified from density.py: David Hart (Sandia)
# enable script to run from Python directly w/out Pizza.py
import sys
import numpy as np
from dump import dump
if not globals().has_key("argv"): argv = sys.argv
# main script
if len(argv) < 5:
raise StandardError, "Syntax: density.py x/y/z nbin vmin vmax outfile files ..."
direction = argv[1]
nbins = int(argv[2])
if nbins < 1:
nbins = 100
try:
zmin = float(argv[3])
except ValueError:
zmin = -np.inf
try:
zmax = float(argv[4])
except ValueError:
zmax = np.inf
if zmax == zmin:
zmin = -np.inf
zmax = np.inf
outfile = argv[5]
files = ' '.join(argv[6:])
# read snapshots one-at-a-time
d = dump(files,0)
d.map(1,"id",2,"type",3,"x",4,"y",5,"z")
bidirect = 'x/y'
first = 1
nsnaps = 0
dx = 0
dy = 0
x0 = 0
y0 = 0
vol = 0
while 1:
time = d.next()
if time == -1: break
if first:
tmp,ntypes = d.minmax("type")
ntypes = int(ntypes)
bin = np.zeros(shape=(nbins,nbins,ntypes))
first = 0
box = (d.snaps[-1].xlo,d.snaps[-1].ylo,d.snaps[-1].zlo,
d.snaps[-1].xhi,d.snaps[-1].yhi,d.snaps[-1].zhi)
vol = (box[3] - box[0]) * (box[4] - box[1]) * (box[5] - box[2])
if direction == "z":
type,x,y,z = d.vecs(time,"type","x","y","z")
bidirect = 'x/y'
dx = box[3] - box[0]
dy = box[4] - box[1]
dz = box[5] - box[2]
x0 = box[0] + float(dx)/float(nbins)/2.0
y0 = box[1] + float(dy)/float(nbins)/2.0
zmax = min(zmax,box[5])
zmin = max(zmin,box[2])
elif direction == "y":
type,x,y,z = d.vecs(time,"type","x","z","y")
bidirect = 'x/z'
dx = box[3] - box[0]
dy = box[5] - box[2]
dz = box[4] - box[1]
x0 = box[0] + float(dx)/float(nbins)/2.0
y0 = box[2] + float(dy)/float(nbins)/2.0
zmax = min(zmax,box[4])
zmin = max(zmin,box[1])
elif direction == "x":
type,x,y,z = d.vecs(time,"type","y","z","x")
bidirect = 'y/z'
dx = box[4] - box[1]
dy = box[5] - box[2]
dz = box[3] - box[0]
x0 = box[1] + float(dx)/float(nbins)/2.0
y0 = box[2] + float(dy)/float(nbins)/2.0
zmax = min(zmax,box[3])
zmin = max(zmin,box[0])
vol = dx * dy * float(zmax - zmin)
type = map(int,type)
natoms = len(type)
for i in xrange(natoms): type[i] -= 1
for i in xrange(natoms):
ibin = int(nbins*x[i])
jbin = int(nbins*y[i])
zloc = float(z[i])*float(dz)
if zloc < zmin or zloc > zmax: continue
if (ibin < 0): ibin = 0
if (ibin > nbins-1): ibin = nbins - 1
if (jbin < 0): jbin = 0
if (jbin > nbins-1): jbin = nbins - 1
bin[jbin][ibin][type[i]] += nbins*nbins/vol
nsnaps += 1
print time,
print
print "Printing %s-mapped density distribution for %s-slice [%.2f,%.2f] in mol/L to %s" %(bidirect, direction, zmin, zmax, outfile)
conversion = 1660.53873 # convert from atoms/Angs^3 to mol/L
fp = open(outfile,"w")
# '''Uncomment for column headers. Commented for consistency with density.py'''
# print >>fp, " %8s %8s " %('ra', 'rb'),
# for k in xrange(ntypes):
# print >>fp, " %8s " %(k),
# print >>fp
for i in xrange(nbins):
for j in xrange(nbins):
print >>fp, " %8.3f %8.3f " %(float(i)/float(nbins)*float(dx)+float(x0), float(j)/float(nbins)*float(dy)+float(y0)),
for k in xrange(ntypes):
print >>fp, " %8.3f " % (conversion*bin[j][i][k]/nsnaps),
print >>fp
fp.close()

97
scripts/density_area.py Normal file
View File

@ -0,0 +1,97 @@
#!/usr/bin/python
# Script: density_area.py
# Purpose: binned atom density by atom type and running area under the curve
# Syntax: density.py x/y/z nbin outfile files ...
# x/y/z = get density distribution along this axis
# nbin = # of bins in desired direction
# outfile = file to write flux stats to
# files = series of dump files
# Example: density_area.py z 100 dens.out dump.*
# Author: Paul Crozier (Sandia).
# Modified by Jeff Greathouse (Sandia) to include
# calculation of area under the curve
# enable script to run from Python directly w/out Pizza.py
import sys
from dump import dump
if not globals().has_key("argv"): argv = sys.argv
# main script
if len(argv) < 5:
raise StandardError, "Syntax: density.py x/y/z nbin outfile files ..."
direction = argv[1]
nbins = int(argv[2])
outfile = argv[3]
files = ' '.join(argv[4:])
# read snapshots one-at-a-time
d = dump(files,0)
d.map(1,"id",2,"type",3,"x",4,"y",5,"z")
first = 1
nsnaps = 0
ntypes = 0
while 1:
time = d.next()
if time == -1: break
if first:
tmp,ntypes = d.minmax("type")
ntypes = int(ntypes)
bin = nbins * [0]
for i in xrange(nbins): bin[i] = ntypes * [0]
first = 0
box = (d.snaps[-1].xlo,d.snaps[-1].ylo,d.snaps[-1].zlo,
d.snaps[-1].xhi,d.snaps[-1].yhi,d.snaps[-1].zhi)
vol = (box[3] - box[0]) * (box[4] - box[1]) * (box[5] - box[2])
if direction == "x": type,x = d.vecs(time,"type","x")
elif direction == "y": type,x = d.vecs(time,"type","y")
elif direction == "z": type,x = d.vecs(time,"type","z")
type = map(int,type)
natoms = len(type)
for i in xrange(natoms): type[i] -= 1
for i in xrange(natoms):
ibin = int(nbins*x[i] + 0.5)
if (ibin < 0): ibin += nbins
if (ibin > nbins-1): ibin -= nbins
bin[ibin][type[i]] += nbins/vol
nsnaps += 1
print time,
print
print "Printing ",direction,"-directional density distribution in mol/L to", \
outfile
conversion = 1660.53873 # convert from atoms/Angs^3 to mol/L
# Output as x, density_1, area_1, ...
fp = open(outfile,"w")
first = 1
xden = nbins * [0]
yden = nbins * [0]
for i in xrange(nbins): yden[i] = ntypes * [0]
sum = ntypes * [0]
for i in xrange(nbins):
xden[i] = float(i)/float(nbins)
print >>fp, xden[i],
if first:
for j in xrange(ntypes):
yden[i][j] = conversion*bin[i][j]/nsnaps
print >>fp, yden[i][j], sum[j],
first = 0
else:
for j in xrange(ntypes):
yden[i][j] = conversion*bin[i][j]/nsnaps
sum[j] += 0.5 * (xden[i] - xden[i-1]) * (yden[i][j] + yden[i-1][j])
print >>fp, yden[i][j], sum[j],
print >>fp
fp.close()

75
scripts/distance.py Normal file
View File

@ -0,0 +1,75 @@
#!/usr/bin/python
# Script: distance.py
# Purpose: check if any atom pairs are closer than specified distance
# Syntax: distance.py maxcut dump.file1 dump.file2 ...
# maxcut = flag atoms which are less than this distance apart
# Example: distance.py 0.95 dump.file1
# Author: Paul Crozier (Sandia)
# print out 2 atoms less than maxcut apart (with PBC)
from math import sqrt
if len(argv) < 3:
raise StandardError,"distance.py maxcut dump.file1 dump.file2 ..."
maxcut = float(argv[1])
maxcut_sq = maxcut*maxcut
files = ' '.join(argv[2:]) # dump files
d = dump(files,0)
d.map(1,"id",2,"type",3,"x",4,"y",5,"z")
while 1:
time = d.next()
if time < 0: break
d.unscale(time)
box = (d.snaps[-1].xlo,d.snaps[-1].ylo,d.snaps[-1].zlo,
d.snaps[-1].xhi,d.snaps[-1].yhi,d.snaps[-1].zhi)
d.aselect.all(time)
id,type,x,y,z = d.vecs(time,"id","type","x","y","z")
n = len(x)
xprd = box[3] - box[0]
yprd = box[4] - box[1]
zprd = box[5] - box[2]
for i in xrange(n):
for j in xrange(i+1,n):
delx = x[j] - x[i]
if abs(delx) > 0.5*xprd:
if delx < 0.0:
delx += xprd
else:
delx -= xprd
if (delx*delx < maxcut_sq):
dely = y[j] - y[i]
if abs(dely) > 0.5*yprd:
if dely < 0.0:
dely += yprd
else:
dely -= yprd
if ((dely*dely + delx*delx) < maxcut_sq):
delz = z[j] - z[i]
if abs(delz) > 0.5*zprd:
if delz < 0.0:
delz += zprd
else:
delz -= zprd
rsq = delx*delx + dely*dely + delz*delz
if rsq < maxcut_sq:
print "time = %d, id[i] = %d, id[j] = %d," \
" type[i] = %d, type[j] = %d, distance = %g" % \
(time, id[i], id[j], type[i], type[j], sqrt(rsq))
d.tselect.none()
d.tselect.one(time)
print "timestep = ", time
d.delete()

19
scripts/dview.py Normal file
View File

@ -0,0 +1,19 @@
#!/usr/bin/python
# Script: dview.py
# Purpose: launch vcr tool on LAMMPS dump files
# Syntax: dview.py dump.1 dump.2 ...
# files = one or more dump files
# Example: dview.py dump.*
# Author: Steve Plimpton (Sandia)
# main script
if len(argv) < 2:
raise StandardError, "Syntax: dview.py dump.1 ..."
files = ' '.join(argv[1:])
d = dump(files)
g = gl(d)
v = vcr(g)

33
scripts/dview_standalone.py Executable file
View File

@ -0,0 +1,33 @@
#!/usr/bin/python
# Script: dview.py
# Purpose: launch vcr tool on LAMMPS dump files
# Syntax: dview.py dump.1 dump.2 ...
# files = one or more dump files
# Example: dview.py dump.*
# Author: Steve Plimpton (Sandia)
# enable script to run from Python directly w/out Pizza.py
import sys
from dump import dump
# w/out Pizza.py these lines need to come before import of gl tool
import Tkinter
tkroot = Tkinter.Tk()
tkroot.withdraw()
from gl import gl
from vcr import vcr
if not globals().has_key("argv"): argv = sys.argv
# main script
if len(argv) < 2:
raise StandardError, "Syntax: dview.py dump.1 ..."
files = ' '.join(argv[1:])
d = dump(files)
g = gl(d)
v = vcr(g)

87
scripts/flux.py Normal file
View File

@ -0,0 +1,87 @@
#!/usr/bin/python
# Script: flux.py
# Purpose: flux of atoms through a user-defined plane
# Syntax: flux.py x/y/z plane outfile files ...
# x/y/z = measure flux in x, y, or z direction
# plane = plane where flux is measured, fraction of L from 0 to 1
# outfile = file to write flux stats to
# files = series of dump files
# Example: flux.py z 0.5 flux.out dump.*
# Author: Paul Crozier (Sandia)
# enable script to run from Python directly w/out Pizza.py
import sys
from dump import dump
if not globals().has_key("argv"): argv = sys.argv
# main script
if len(argv) < 5:
raise StandardError, "Syntax: flux.py x/y/z plane outfile files ..."
direction = argv[1]
scaled_plane = float(argv[2])
outfile = argv[3]
files = ' '.join(argv[4:])
d = dump(files)
d.unwrap()
tmp,ntypes = d.minmax("type")
ntypes = int(ntypes)
ntypes += 1
# loop over snapshots and compute net flux vs. first snapshot
f = open(outfile,"w")
jconfig = crossings = 0
flag = 0
while 1:
which,time,flag = d.iterator(flag)
if flag == -1: break
if direction == "x":
id,type,x = d.vecs(time,"id","type","x")
lo = d.snaps[which].xlo
hi = d.snaps[which].xhi
elif direction == "y":
id,type,x = d.vecs(time,"id","type","y")
lo = d.snaps[which].ylo
hi = d.snaps[which].yhi
elif direction == "z":
id,type,x = d.vecs(time,"id","type","z")
lo = d.snaps[which].zlo
hi = d.snaps[which].zhi
prd = hi - lo
plane = lo + scaled_plane*prd
print time,
sys.stdout.flush()
natoms = len(x)
if jconfig == 0: x_initial = (natoms+1) * [0]
jconfig += 1
typeflux = ntypes * [0]
for i in xrange(natoms):
id[i] = int(id[i])
type[i] = int(type[i])
if jconfig == 1: x_initial[id[i]] = x[i]
if x_initial[id[i]] < plane and x[i] > plane :
crossings = int((x[i] - plane)/prd) + 1
typeflux[type[i]] += crossings
elif x_initial[id[i]] > plane and x[i] < plane :
crossings = int((plane - x[i])/prd) + 1
typeflux[type[i]] -= crossings
print >>f,time,
for j in xrange(ntypes-1):
print >>f,typeflux[j+1],
print >>f
print
f.close()

20
scripts/iview.py Normal file
View File

@ -0,0 +1,20 @@
#!/usr/bin/python
# Script: iview.py
# Purpose: launch animate tool on series of image files
# Syntax: iview.py files ...
# files = one or more image files
# Example: iview.py image*png
# Author: Steve Plimpton (Sandia)
# enable script to run from Python directly w/out Pizza.py
import sys
from animate import animate
if not globals().has_key("argv"): argv = sys.argv
# main script
# this could be done with one-line alias in shell start-up file
if len(argv) < 2: raise StandardError, "Syntax: iview.py files ..."
a = animate(' '.join(argv[1:]))

31
scripts/logview.py Normal file
View File

@ -0,0 +1,31 @@
#!/usr/bin/python
# Script: logview.py
# Purpose: plots of LAMMPS log-file thermodynamic data
# Syntax: logview.py gnu/matlab files ...
# gnu/matlab = style of plots to create
# files = one or more log files
# Example: logview.py gnu log.*
# Author: Steve Plimpton (Sandia)
# enable script to run from Python directly w/out Pizza.py
import sys
from log import log
from plotview import plotview
from gnu import gnu
from matlab import matlab
if not globals().has_key("argv"): argv = sys.argv
# main script
if len(argv) < 3:
raise StandardError, "Syntax: logview.py gnu/matlab files ..."
style = argv[1]
files = ' '.join(argv[2:])
lg = log(files)
exec "plot = %s()" % style
p = plotview(lg,plot)

33
scripts/movie.py Normal file
View File

@ -0,0 +1,33 @@
#!/usr/bin/python
# Script: movie.py
# Purpose: create images from LAMMPS dump snapshots
# Syntax: movie.py raster/svg theta phi dump.1 dump.2 ...
# raster/svg = style of image to create
# theta/phi = vertical (z) and azimuthal angle to view from
# files = one or more dump files
# Example: movie.py svg 60 130 dump.*
# Author: Steve Plimpton (Sandia)
# enable script to run from Python directly w/out Pizza.py
import sys
from dump import dump
from raster import raster
from svg import svg
if not globals().has_key("argv"): argv = sys.argv
# main script
if len(argv) < 5:
raise StandardError, "Syntax: movie.py raster/svg theta phi dump.1 ..."
style = argv[1]
theta = float(argv[2])
phi = float(argv[3])
files = ' '.join(argv[4:])
d = dump(files)
exec "viz = %s(d)" % style
viz.rotate(theta,phi)
viz.all()

30
scripts/plot.py Normal file
View File

@ -0,0 +1,30 @@
#!/usr/bin/python
# Script: plot.py
# Purpose: plots of a file of vectors
# Syntax: plot.py gnu/matlab file
# gnu/matlab = style of plots to create
# file = a file with columns of data
# Example: plot.py gnu file.dat
# Author: Steve Plimpton (Sandia)
# enable script to run from Python directly w/out Pizza.py
import sys
from plotview import plotview
from gnu import gnu
from matlab import matlab
if not globals().has_key("argv"): argv = sys.argv
# main script
if len(argv) != 3:
raise StandardError, "Syntax: plot.py gnu/matlab file"
style = argv[1]
file = argv[2]
v = vec(file)
exec "plot = %s()" % style
p = plotview(v,plot)