convert tabs to spaces, remove extra spaces, fix comments

This commit is contained in:
danielque
2023-08-09 16:49:09 +02:00
parent 633058e1ab
commit d560b34214
47 changed files with 1263 additions and 1266 deletions

View File

@ -3,7 +3,7 @@
#
# Copyright (2005) Sandia Corporation. Under the terms of Contract
# DE-AC04-94AL85000 with Sandia Corporation, the U.S. Government retains
# certain rights in this software. This software is distributed under
# certain rights in this software. This software is distributed under
# the GNU General Public License.
# vtk tool
@ -11,13 +11,13 @@
oneline = "Convert LAMMPS snapshots to VTK format"
docstr = """
v = vtk(d) d = object containing atom coords (dump, data)
v = vtk(d) d = object containing atom coords (dump, data)
v.one() write all snapshots to tmp.vtk
v.one("new") write all snapshots to new.vtk
v.many() write snapshots to tmp0000.vtk, tmp0001.vtk, etc
v.many("new") write snapshots to new0000.vtk, new0001.vtk, etc
v.single(N) write snapshot for timestep N to tmp.vtk
v.single(N) write snapshot for timestep N to tmp.vtk
v.single(N,"file") write snapshot for timestep N to file.vtk
surfaces in snapshot will be written to SURF1.vtk, SURF2.vtk, etc
@ -39,12 +39,12 @@ import sys, re
# Class definition
class vtk:
# --------------------------------------------------------------------
def __init__(self,data):
self.data = data
# --------------------------------------------------------------------
def one(self,*args):
@ -59,16 +59,16 @@ class vtk:
sys.stdout.flush()
if len(tris): surface(tris)
allatoms = []
for atom in atoms:
allatoms.append(atom)
while 1:
which,time,flag = self.data.iterator(flag)
if flag == -1: break
time,box,atoms,bonds,tris,lines = self.data.viz(which)
for atom in atoms: allatoms.append(atom)
print time,
sys.stdout.flush()
@ -93,7 +93,7 @@ class vtk:
if surfflag == 0 and len(tris):
surfflag = 1
surface(tris)
if n < 10:
file = root + "000" + str(n) + ".vtk"
elif n < 100:
@ -104,19 +104,19 @@ class vtk:
file = root + str(n) + ".vtk"
particle(file,atoms)
print time,
sys.stdout.flush()
n += 1
print "\nwrote %s snapshots in VTK format" % n
# --------------------------------------------------------------------
def manyGran(self,*args,**kwargs):
# check whether to output or not
outputfl = True
if "output" in kwargs: outputfl = kwargs["output"]
# read startIndex (offset for filename due to parallel processing)
startIndex = 0
fileNos = []
@ -124,14 +124,14 @@ class vtk:
fileNos = kwargs["fileNos"]
else:
fileNos = range(len(self.data.snaps))
# output name
if len(args) == 0: root = "tmp"
else: root = args[0]
surfflag = 0
n = flag = 0
# iterate over snaps
while 1:
which,time,flag = self.data.iterator(flag)
@ -143,14 +143,14 @@ class vtk:
yhi=self.data.snaps[n].yhi
zlo=self.data.snaps[n].zlo
zhi=self.data.snaps[n].zhi
atoms=self.data.snaps[n].atoms
names=self.data.names
if surfflag == 0 and len(tris):
surfflag = 1
surface(tris)
file, file_bb, file_walls = generateFilename(root,fileNos,n)
boundingBox(file_bb,xlo,xhi,ylo,yhi,zlo,zhi)
@ -158,11 +158,11 @@ class vtk:
try: nvalues = len(self.data.snaps[0].atoms[0])
except: nvalues = 0
particleGran(file,atoms,names,nvalues)
if outputfl: print time,
if outputfl: sys.stdout.flush()
n += 1
if outputfl: print "\nwrote %s granular snapshots in VTK format" % n
# --------------------------------------------------------------------
@ -209,7 +209,7 @@ def generateFilename(root,fileNos,n):
def surface(tris):
ntypes = tris[-1][1]
for i in xrange(ntypes):
itype = i+1
v = {}
@ -234,10 +234,10 @@ def surface(tris):
vinverse = {}
for key in keys:
vinverse[v[key]] = key
filename = "SURF" + str(itype) + ".vtk"
f = open(filename,"w")
print >>f,"# vtk DataFile Version 3.0"
print >>f,"Generated by pizza.py"
print >>f,"ASCII"
@ -267,7 +267,7 @@ def surface(tris):
def particle(file,atoms):
f = open(file,"w")
print >>f,"# vtk DataFile Version 2.0"
print >>f,"Generated by pizza.py"
print >>f,"ASCII"
@ -285,13 +285,13 @@ def particle(file,atoms):
itype = int(atom[1])
print >>f,itype,
print >>f
f.close()
def boundingBox(file,xlo,xhi,ylo,yhi,zlo,zhi):
f = open(file,"w")
print >>f,"# vtk DataFile Version 2.0"
print >>f,"Generated by pizza.py"
print >>f,"ASCII"
@ -311,14 +311,14 @@ def typestr(o):
def particleGran(file,atoms,names,n_values):
f = open(file,"w")
# if no atoms are present
if atoms is None:
atoms = []
# find indices of scalars and vectors
scalars, vectors = findScalarsAndVectors(names)
# print head
print >>f,"# vtk DataFile Version 2.0"
print >>f,"Generated by lpp.py"
@ -331,7 +331,7 @@ def particleGran(file,atoms,names,n_values):
for i in xrange(len(atoms)):
print >>f,1,i
print >>f,"POINT_DATA",len(atoms)
if len(atoms) == 0:
print >> f
f.close()
@ -339,11 +339,11 @@ def particleGran(file,atoms,names,n_values):
# print VECTORS
for key in vectors.keys():
# don't print coodinates again
if key == 'x':
continue
vectortype = 'float'
if atoms != []:
vectortype = typestr(atoms[0][vectors[key]])
@ -352,11 +352,11 @@ def particleGran(file,atoms,names,n_values):
else: vectortype = 'float'
else: # if no atoms are present
pass
print >>f,"VECTORS",key,vectortype
for atom in atoms:
print >>f, atom[vectors[key]], atom[vectors[key]+1], atom[vectors[key]+2]
# print SCALARS
for key in scalars.keys():
scalartype =''
@ -367,30 +367,30 @@ def particleGran(file,atoms,names,n_values):
else: scalartype = 'int'
else: # if no atoms are present
pass
print >>f,"SCALARS",key,scalartype,1
print >>f,"LOOKUP_TABLE default"
for atom in atoms:
print >>f, atom[scalars[key]]
print >>f
f.close()
def findScalarsAndVectors(names):
vectors={}
scalars={}
# create reversed dictionary {position:name}
indices = {}
for name in names:
indices[names[name]]=name
# fill missing indices (occurrs e.g. if output is like vx vy vz fx fy fz vx vy vz)
for i in xrange(max(indices)):
if i not in indices:
indices[i]=""
# compile regexes to find vectors
regvx = re.compile(".*x")
regvy = re.compile(".*y")
@ -398,53 +398,53 @@ def findScalarsAndVectors(names):
regf = re.compile("f_.*\[[0-9]+\]")
regc = re.compile("c_.*\[[0-9]+\]")
regv = re.compile("v_.*\[[0-9]+\]")
# loop over all indices and look if their names represent a vector (if not: it's a scalar)
i = 0
while i<= max(indices):
if i+2 <= max(indices) and regvx.match(indices[i]) != None and regvy.match(indices[i+1]) != None and regvz.match(indices[i+2]) != None:
newname=''
if len(indices[i]) == 1:
newname=indices[i]
else:
newname=indices[i][:-1]
vectors[newname]=i
i+=3
continue
if regf.match(indices[i]) != None or regc.match(indices[i]) != None or regv.match(indices[i]) != None:
name = indices[i]
number = int( name.split('[')[1].split(']')[0] )
nextName = name.split('[')[0]+'['+str(number+1)+']'
nextButOneName = name.split('[')[0]+'['+str(number+2)+']'
newname = name[2:-(len(name.split('[')[1])+1)]
if i+2 <= max(indices) and indices[i+1] == nextName and indices[i+2] == nextButOneName:
vectors[newname]=i
i+=3
continue
else:
scalars[newname]=i
i+=1
continue
# program only here if not a vector
if indices[i] != '':
newname = indices[i]
scalars[newname]=i
i+=1
if 'x' not in vectors.keys():
print "vector x y z has to be contained in dump file. please change liggghts input script accordingly."
exit()
return scalars, vectors