Skip to content

Instantly share code, notes, and snippets.

@glennklockwood
Created February 3, 2014 21:22
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save glennklockwood/8792688 to your computer and use it in GitHub Desktop.
Save glennklockwood/8792688 to your computer and use it in GitHub Desktop.
analyzecoord, New Version by Paul Davis
#!/usr/bin/env python2
import re
import sys
SHOW = """
Siloxane SiO4 Si3O SiO3
SiO2 SiO1 NBO FreeOH
H2O H3O SiOH SiOH2 Si2OH
""".split()
def printargs(counts, isave):
sys.stdout.write("%-8s" % isave)
for s in SHOW:
print "%8d" % counts[s],
counts[s] = 0
sys.stdout.write("\n")
def main():
sys.stdout.write("%-8s" % "ird")
counts = {};
for s in SHOW:
counts[s] = 0
sys.stdout.write("%8s" % s)
sys.stdout.write("\n")
isave = 0;
current = 0;
RE_LINE = re.compile(r"""
^
(\d+)
\s+
([\d\w]+)
\s+
\d+
\s+
[\w\.]+
\s+
[\w\.]+
\s+
[\w\.]+
\s*
$
""", re.VERBOSE)
with open("coord.out") as handle:
for line in handle:
line = line.lstrip(" \t\r")
match = RE_LINE.match(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 specie in SHOW:
counts[specie] += 1;
printargs(counts, isave)
if __name__ == '__main__':
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment