# $CVSHeader: pal8e/src/mkOverInsScript.py,v 1.2 2005/02/15 01:10:26 indraneel Rel $

# make insight logs for overpredictions

import os, sys

class Parm:
    datFile = '../dat/stat/pssdHover'
    PDBDir = '../../dat/cull100/'
    insLogDir = '../../dat/cull100overIns/'
    red = ' red '
    blue = ' blue '
    green = ' green '
    cyan = ' cyan '
    magenta = ' magenta '
    yellow = ' yellow '

class InsLog:
    def __init__(self, parm):
        self.parm = parm
        
    def mkInsLogFile(self, fname, logfname, data):
        parm = self.parm
        fn = os.path.basename(fname)
        ID = 'P_'+fn[:4]
        lines = []
        lines += ['Get Molecule PDB User '+fn+' '+ID]
        lines += [' Heteroatom -Reference_object\n']
        lines += ['Display Molecule Only Atoms Trace '+ID+'\n']
        lines += ['Color Molecule Atoms '+ID+ \
                  ' Specified Specification 247,247,247\n']
        lines += ['Clip -Auto 400 0 -Perspective INSIGHTII\n']
        line = None
        for resnum in data.keys():
            dat = data[resnum]
	    phi = dat['phi']
	    psi = dat['psi']
	    color = None
	    #if (-150 < phi < -125) and (50 < psi < 100):
	    #    color = parm.red
            #if (-75 < phi < -50) and (100 < psi < 150):
            #    color = parm.cyan
            #if (-100 < phi < -80) and (-10 < psi < 0):
            #    color = parm.green
            #if (-100 < phi < -50) and (-50 < psi < 0):
            #    color = parm.yellow
            #if (40 < phi < 100) and (25 < psi < 50):
            #    color = parm.magenta
            if (-125 < phi < -100) and (125 < psi < 150):
                color = parm.magenta
            #if (50 < phi < 125) and (-50 < psi < 50):
            #    color = parm.yellow
            #if (50 < phi < 150) and ((-180 < psi < -125) or (150 < psi < 180)):
            #    color = parm.green
	    if not color: continue
            line = 'Color Molecule Atoms '+ID+':'
            line += dat['cid'] + str(resnum)
            line += ' Specified Specification '+color+'\n'
            lines += line
        lines += ['#Stereo Stereo_Mode 3.5 Side_By_Side 0.25\n']
        if not line: return
        fh = file(logfname, 'w')
        fh.writelines(lines)
        fh.close()

    def mkInsLog(self):
        parm = self.parm
        fh = file(parm.datFile)
        lines = fh.readlines()
        fh.close()
        fnames = {}
        for line in lines:
            line = line[:-1]
            [fname, resnum, phi, psi] = line.split()
            if not fnames.has_key(fname):
                fnames[fname] = {}
            cid = fname[5]
            fnames[fname][resnum] = {'cid': cid, \
                                     'phi': float(phi), 'psi': float(psi)}
        for fn in fnames.keys():
            fname = parm.PDBDir + fn + '.pdb'
            logfname = parm.insLogDir + fn + '.log'
            self.mkInsLogFile(fname, logfname, fnames[fn])

if __name__ == '__main__':
    parm = Parm()
    inslog = InsLog(parm)
    inslog.mkInsLog()
