Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
analyzecoord, Original Python Implementation
#!/usr/bin/env python2
import fileinput
import re
show = [ "Siloxane", "SiO4", "Si3O", "SiO3", \
"SiO2", "SiO1", "NBO", "FreeOH", \
"H2O", "H3O", "SiOH", "SiOH2", "Si2OH" ]
def printargs( counts, isave ):
print "%-8s" % isave,
for s in show:
print "%8d" % counts[s],
counts[s] = 0
print "\n",
print "%-8s" % "ird",
counts = {};
for s in show:
counts[s] = 0
print "%8s" % s,
print "\n",
isave = 0;
current = 0;
RE_LINE = \
re.compile(r'\s*(\d+)\s+([\d\w]+)\s+\d+\s+[\w\.]+\s+[\w\.]+\s+[\w\.]+\s*$')
for line in fileinput.input():
# for line in file('coord.out'):
#contents = file('coord.out').readlines()
#for line in contents:
match = re.match(RE_LINE, line)
if not match: continue
specie = match.group(2)
icur = int(match.group(1))
if current == 0:
current = icur
isave = current
elif current != icur:
printargs(counts, isave)
current = icur
isave += 1
if show.count(specie) > 0:
counts[specie] += 1;
printargs(counts,isave)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.