# $CVSHeader: pal8e/src/DSSPQuadParams.py,v 1.4 2005/02/15 01:10:25 indraneel Rel $

# calculates quadruplet params from DSSP for making a plot

from Bin import Bin
from Sigma import Sigma
from Log import LogFH
from DSSPRunner import DSSPRunner
from DSSPStat import DSSPStat
from DSSPPlot import DSSPPlot
import Numeric

testfile = "../../dat/nrchn2787.dssp/1czf_A.dssp"
#testfile = "../../dat/nrchn2787.dssp/1a6r.dssp"
DSSPDIR = "../../dat/nrchn2787.dssp/"
#DSSPDIR = "../../dat/dssp.test/"

class DSSPQuadParams:
    def __init__(self):
        self.logger = LogFH('DSSPdih-testlog')
        
    def getData(self, bin_size, start, end, fn):
        logger = self.logger
        runner = DSSPRunner()
        typedef={'E':'E'}
        etype = typedef.values()[0]
        data_array = []
        #runner.runfile(logger, testfile, typedef, etype, data_array, fn)
        runner.rundir(logger, DSSPDIR, typedef, etype, data_array, fn)
        bin = Bin(data_array)
        bin.bin(bin_size, start, end)
        bin.normalise()
        #for k in bin.keys():
        #    print k, '\t', bin[k]
        data = bin.getNumarray()
        sigma = Sigma(data_array)
        s = sigma.sigma()
        return (data, s)

    def run(self):
        stat = DSSPStat()
        
#       (synDistData, synDistSigma)=self.getData(0.1, 3.0, 8.5, stat.synDist)
#       (antiDistData, antiDistSigma)=self.getData(0.1, 3, 8.5, stat.antiDist)
#
#       data = Numeric.transpose((synDistData[:,0], synDistData[:,1],
#                                 antiDistData[:,0], antiDistData[:,1]))
#       plot = DSSPPlot()
#       title = "CA-CA Pair Distances for Parallel and Antiparallel Strands"
#       xlabel = "Distance (A)"
#       ylabel = "Normalised Points"
#       fname = 'sheet_dist.eps'
#       cols = [[0,1], [2,3]]
#       titles = ['Parallel','Antiparallel']
#       plot.plot(data, cols, titles, title, xlabel, ylabel, fname)
#
#       (synBondData, synBondSigma)=self.getData(1, 0, 90, stat.synBond)
#       (antiBondData, antiBondSigma)=self.getData(1, 0, 90, stat.antiBond)
#
#       data = Numeric.transpose((synBondData[:,0], synBondData[:,1],
#                                 antiBondData[:,0], antiBondData[:,1]))
#       plot = DSSPPlot()
#       title = "Base-Vertex Angles for Parallel and Antiparallel Strands"
#       xlabel = "Angle"
#       ylabel = "Normalised Points"
#       fname = 'sheet_bond.eps'
#       cols = [[0,1], [2,3]]
#       titles = ['Parallel','Antiparallel']
#       plot.plot(data, cols, titles, title, xlabel, ylabel, fname)

        (synTorData, synTorSigma)=self.getData(1, -180, 180, stat.synTor)
        (antiTorData, antiTorSigma)=self.getData(1, -180, 180, stat.antiTor)

        data = Numeric.transpose((synTorData[:,0], synTorData[:,1],
                                  antiTorData[:,0], antiTorData[:,1]))
        plot = DSSPPlot()
        title = "Torsion Angles for Parallel and Antiparallel Strands"
        xlabel = "Angle"
        ylabel = "Normalised Points"
        fname = 'sheet_tor.eps'
        cols = [[0,1], [2,3]]
        titles = ['Parallel','Antiparallel']
        plot.plot(data, cols, titles, title, xlabel, ylabel, fname)

if __name__ == '__main__':
    qp = DSSPQuadParams()
    qp.run()
