from pymol import cmd
from string import Template

f = open('dist.txt', 'a')
d = Template('$struc///$res/$atom')
res1 = ['2','3','13']
res2 = ['65', '7', '17']
atom1 = ['OD2', 'O', 'NE']
atom2 = ['ND2', 'N', 'OE2']

dst = [None] * 3

dst[0]='%.1f' % cmd.distance('tmp',d.substitute(struc = '1C15', res = '2', atom = 'OD2'), d.substitute(struc = '1C15', res = '65', atom = 'ND2'))
dst[1]='%.1f' % cmd.distance('tmp',d.substitute(struc = '1C15', res = '3', atom = 'O'),d.substitute(struc = '1C15', res = '7', atom = 'N'))
dst[2]='%.1f' % cmd.distance('tmp',d.substitute(struc = '1C15', res = '13', atom = 'NE'),d.substitute(struc = '1C15', res = '17', atom = 'OE2'))

f.write('1C15' + '	' + dst[0] + '	' + dst[1] + '	' + dst[2] + '\n')

cmd.split_states('1C15')
pref = '1C15_00'

i = 1
while i != 17:
    if 10 - i <= 0:
        post = str(i)
    else:
        post = '0' + str(i)
    for el in range(3):
        dst[el] = '%.1f' % cmd.distance('tmp',d.substitute(struc = pref + post, res = res1[el], atom = atom1[el]), d.substitute(struc = pref + post, res = res2[el], atom = atom2[el]))
    f.write(pref + post + '	' + dst[0] + '	' + dst[1] + '	' + dst[2] + '	' + '\n')
    i += 1

f.close()

