Created
April 8, 2015 14:16
-
-
Save SeanMcGrath/68747d8ef3be7b03572e to your computer and use it in GitHub Desktop.
Calculate the RMS deviation between the values in 2 distance matrices computed by Gaussian and parsed by matrixparse.
This file contains 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 python | |
import argparse, sys, csv, math | |
def calcRMS(reader1, reader2): | |
def makeList(reader): | |
l = [] | |
for row in reader: | |
for val in row: | |
if val != '': | |
l.append(float(val.strip())) | |
return l | |
dist1 = makeList(reader1) | |
dist2 = makeList(reader2) | |
if len(dist1) != len(dist2): | |
return 'File dimensions are incompatible' | |
else: | |
gen = zip([el for el in dist1], [el for el in dist2]) | |
diffs = [a - b for a, b in gen] | |
squares = [a*a for a in diffs] | |
return math.sqrt(sum(squares)/len(squares)) | |
def main(args): | |
parser = argparse.ArgumentParser(description = 'Calculate the RMS deviation of one Gaussian distance matrix from another.') | |
parser.add_argument('File1', type=str) | |
parser.add_argument('File2', type=str) | |
args = parser.parse_args(args) | |
try: | |
file1 = open(args.File1, 'r') | |
file1reader = csv.reader(file1) | |
except: | |
print('{} is not a valid file'.format(file1)) | |
return 2 | |
try: | |
file2 = open(args.File2, 'r') | |
file2reader = csv.reader(file2) | |
except: | |
print('{} is not a valid file'.format(file2)) | |
return 2 | |
print(calcRMS(file1reader,file2reader)) | |
if __name__ == '__main__': | |
sys.exit(main(sys.argv[1:])) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment