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