Skip to content

Instantly share code, notes, and snippets.

@schwancr
Created July 8, 2014 19:43
Show Gist options
  • Save schwancr/823ceee5fc9c6da33cfe to your computer and use it in GitHub Desktop.
Save schwancr/823ceee5fc9c6da33cfe to your computer and use it in GitHub Desktop.
translation for theobald rmsd code from original syntax/indexing to mdtraj's
import re
with open('toadd.txt') as fh:
lines = fh.readlines()
def trans(m):
s = m.group(0)
return 'k%d%d%s' % tuple([int(s[i]) - 1 for i in [1, 2]] + [s[-1]])
def trans2(m):
s = m.group(0)
return 'k%d%d%d%d_%d%d%d%d%s' % tuple([int(s[i]) - 1 for i in [1, 2, 3, 4] + [6, 7, 8, 9]] + [s[-1]])
def transq(m):
s = m.group(0)
return 'q%d%s' % (int(s[1]) - 1, s[-1])
for line in lines:
line = re.sub('q\d\D', transq, line)
line = re.sub('a\d\d\D', trans, line)
line = re.sub('a\d\d\d\d_\d\d\d\d\D', trans2, line)
print line,
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment