Last active
August 29, 2015 13:56
-
-
Save glennklockwood/8792481 to your computer and use it in GitHub Desktop.
analyzecoord, Original Python Implementation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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