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

import math
import Extparm_c

datdir = '../dat/stat/'

class extparm:
    def __init__(self):
        self._store_prob(datdir+'QbondSynTS', 'sblp')
        self._store_prob(datdir+'QbondAntiTS', 'ablp')
        self._store_prob(datdir+'QtorSynTS', 'stlp')
        self._store_prob(datdir+'QtorAntiTS', 'atlp')

    def _store_prob(self, fname, tag):
        probfile = open(fname);
        lines = probfile.readlines()
        probfile.close()
        stor = {}
        for line in lines:
            if line[0] == '#': continue
            (sd, prob) = line.split()
            if (float(prob) == 0): prob = 0.0001
            stor[sd] = -1 * math.log(float(prob))
        setattr(self, tag, stor)

    def get_val(self, tag, sd):
        if tag == 'lpg':
            val =  Extparm_c.lpg(sd)
            return val
        sd = '%.1f' % sd
        if sd == '-0.0': sd = '0.0'
        if hasattr(self, tag):
            stor = getattr(self, tag)
            if stor.has_key(sd):
                return stor[sd]

