PEATDB/plugins/VantHoffAnalysis.py
def fitVantHoff(self, E=None, d=None, xy=None, transwidth=80, invert=False,
                        show=True, figname=None):
        """Derive fraction unfolded, get K and fit to Van't Hoff.
           see http://www.jbc.org/content/277/43/40717.full
           or http://www.ncbi.nlm.nih.gov/pmc/articles/PMC2144003/
        """
        if E != None:
            if not d in E.datasets:
                print 'no such dataset, %s' %d
                print 'available datasets:', E.datasets
                return
            ek = E.getDataset(d)
            x,y = ek.getxySorted()
        elif xy!=None:
            x,y = xy

        if 'Convert Celsius-Kelvin' in self.conversions.getcurselection():
            x = [i+273 for i in x]
        if invert == True:
            y = [max(y)-i for i in y[:]]

        f=plt.figure(figsize=(18,6))
        ax=f.add_subplot(131)
        p=ax.plot(x,y,'o',alpha=0.6)
        ax.set_xlabel('T(K)'); ax.set_ylabel('mdeg')
        ax.set_title('raw data')

        x1,y1,x,y = self.transformCD(x,y,transwidth,ax)
        cw=csv.writer(open('frac_unfolded_'+d+'.csv','w'))
        cw.writerow(['temp','frac'])
        for i in zip(x1,y1):
            cw.writerow(i)

        #derive lnK vs 1/T
        t=[]; k=[]

        for T,fu in zip(x,y):
            if fu>=1 or fu<=0:
                continue
            K = fu/(1-fu)
            klog = math.log(K)
            k.append(klog)
            t.append(1/T)

        if len(t)<2: return None, None, None

        ax=f.add_subplot(132)
        p=ax.plot(x1,y1,'o',color='g',alpha=0.6)
        ax.set_xlabel('T(K)'); ax.set_ylabel('fu')
        ax.set_title('fraction unfolded')

        ax=f.add_subplot(133)
        p=ax.plot(t,k,'x',mew=2,color='black')
        ax.set_xlabel('1/T')#(r'$1/T ($K^-1)$')
        ax.set_ylabel('ln K')

        formatter = matplotlib.ticker.ScalarFormatter()
        formatter.set_scientific(True)
        formatter.set_powerlimits((0,0))
        ax.xaxis.set_major_formatter(formatter)
        for l in ax.get_xticklabels():
            l.set_rotation(30)

        #fit this van't hoff plot
        A,X=Fitting.doFit(expdata=zip(t,k),model='Linear')
        fitk = X.getFitLine(t)
        p=ax.plot(t,fitk,'r',lw=2)
        fd=X.getFitDict()
        #self.drawParams(ax,fd)

        #slope is deltaH/R/1000 in kJ
        deltaH = -fd['a']*self.R/1000
        deltaS = fd['b']*self.R/1000
        f.suptitle("Method 1 - deltaH: %2.2f deltaS: %2.2f" %(deltaH,deltaS),size=18)
        f.subplots_adjust(bottom=0.15,top=0.85)

        if show==True:
            self.showTkFigure(f)

        if figname == None: figname = d
        figname = figname.replace('.','_')
        fname = figname+'m1'+'.png'
        f.savefig(fname,dpi=300)
        print 'plot saved to %s' %os.path.abspath(fname)
        #plt.close()
        if E!=None:
            fdata = Fitting.makeFitData(X.name,vrs=X.variables)
            E.insertDataset(xydata=[t,k], newname=d+'_vanthoff',replace=True,fit=fdata)
            #E.saveProject()
        return deltaH, deltaS, ax
Derive fraction unfolded, get K and fit to Van't Hoff.
           see http://www.jbc.org/content/277/43/40717.full
           or http://www.ncbi.nlm.nih.gov/pmc/articles/PMC2144003/
        
Derive fraction unfolded, get K and fit to Van't Hoff.
Derive fraction unfolded get K and fit to Van ' t Hoff .
def fitVantHoff(self, E=None, d=None, xy=None, transwidth=80, invert=False,
                        show=True, figname=None):
        if E != None:
            if not d in E.datasets:
                print 'no such dataset, %s' %d
                print 'available datasets:', E.datasets
                return
            ek = E.getDataset(d)
            x,y = ek.getxySorted()
        elif xy!=None:
            x,y = xy
        if 'Convert Celsius-Kelvin' in self.conversions.getcurselection():
            x = [i+273 for i in x]
        if invert == True:
            y = [max(y)-i for i in y[:]]
        f=plt.figure(figsize=(18,6))
        ax=f.add_subplot(131)
        p=ax.plot(x,y,'o',alpha=0.6)
        ax.set_xlabel('T(K)'); ax.set_ylabel('mdeg')
        ax.set_title('raw data')
        x1,y1,x,y = self.transformCD(x,y,transwidth,ax)
        cw=csv.writer(open('frac_unfolded_'+d+'.csv','w'))
        cw.writerow(['temp','frac'])
        for i in zip(x1,y1):
            cw.writerow(i)
        t=[]; k=[]
        for T,fu in zip(x,y):
            if fu>=1 or fu<=0:
                continue
            K = fu/(1-fu)
            klog = math.log(K)
            k.append(klog)
            t.append(1/T)
        if len(t)<2: return None, None, None
        ax=f.add_subplot(132)
        p=ax.plot(x1,y1,'o',color='g',alpha=0.6)
        ax.set_xlabel('T(K)'); ax.set_ylabel('fu')
        ax.set_title('fraction unfolded')
        ax=f.add_subplot(133)
        p=ax.plot(t,k,'x',mew=2,color='black')
        ax.set_xlabel('1/T')
        ax.set_ylabel('ln K')
        formatter = matplotlib.ticker.ScalarFormatter()
        formatter.set_scientific(True)
        formatter.set_powerlimits((0,0))
        ax.xaxis.set_major_formatter(formatter)
        for l in ax.get_xticklabels():
            l.set_rotation(30)
        A,X=Fitting.doFit(expdata=zip(t,k),model='Linear')
        fitk = X.getFitLine(t)
        p=ax.plot(t,fitk,'r',lw=2)
        fd=X.getFitDict()
        deltaH = -fd['a']*self.R/1000
        deltaS = fd['b']*self.R/1000
        f.suptitle("Method 1 - deltaH: %2.2f deltaS: %2.2f" %(deltaH,deltaS),size=18)
        f.subplots_adjust(bottom=0.15,top=0.85)
        if show==True:
            self.showTkFigure(f)
        if figname == None: figname = d
        figname = figname.replace('.','_')
        fname = figname+'m1'+'.png'
        f.savefig(fname,dpi=300)
        print 'plot saved to %s' %os.path.abspath(fname)
        if E!=None:
            fdata = Fitting.makeFitData(X.name,vrs=X.variables)
            E.insertDataset(xydata=[t,k], newname=d+'_vanthoff',replace=True,fit=fdata)
        return deltaH, deltaS, ax
def fitVantHoff ( self , E = None , d = None , xy = None , transwidth = 80 , invert = False , show = True , figname = None ) : if E != None : if not d in E . datasets : print 'no such dataset, %s' % d print 'available datasets:' , E . datasets return ek = E . getDataset ( d ) x , y = ek . getxySorted ( ) elif xy != None : x , y = xy if 'Convert Celsius-Kelvin' in self . conversions . getcurselection ( ) : x = [ i + 273 for i in x ] if invert == True : y = [ max ( y ) - i for i in y [ : ] ] f = plt . figure ( figsize = ( 18 , 6 ) ) ax = f . add_subplot ( 131 ) p = ax . plot ( x , y , 'o' , alpha = 0.6 ) ax . set_xlabel ( 'T(K)' ) ; ax . set_ylabel ( 'mdeg' ) ax . set_title ( 'raw data' ) x1 , y1 , x , y = self . transformCD ( x , y , transwidth , ax ) cw = csv . writer ( open ( 'frac_unfolded_' + d + '.csv' , 'w' ) ) cw . writerow ( [ 'temp' , 'frac' ] ) for i in zip ( x1 , y1 ) : cw . writerow ( i ) t = [ ] ; k = [ ] for T , fu in zip ( x , y ) : if fu >= 1 or fu <= 0 : continue K = fu / ( 1 - fu ) klog = math . log ( K ) k . append ( klog ) t . append ( 1 / T ) if len ( t ) < 2 : return None , None , None ax = f . add_subplot ( 132 ) p = ax . plot ( x1 , y1 , 'o' , color = 'g' , alpha = 0.6 ) ax . set_xlabel ( 'T(K)' ) ; ax . set_ylabel ( 'fu' ) ax . set_title ( 'fraction unfolded' ) ax = f . add_subplot ( 133 ) p = ax . plot ( t , k , 'x' , mew = 2 , color = 'black' ) ax . set_xlabel ( '1/T' ) ax . set_ylabel ( 'ln K' ) formatter = matplotlib . ticker . ScalarFormatter ( ) formatter . set_scientific ( True ) formatter . set_powerlimits ( ( 0 , 0 ) ) ax . xaxis . set_major_formatter ( formatter ) for l in ax . get_xticklabels ( ) : l . set_rotation ( 30 ) A , X = Fitting . doFit ( expdata = zip ( t , k ) , model = 'Linear' ) fitk = X . getFitLine ( t ) p = ax . plot ( t , fitk , 'r' , lw = 2 ) fd = X . getFitDict ( ) deltaH = - fd [ 'a' ] * self . R / 1000 deltaS = fd [ 'b' ] * self . R / 1000 f . suptitle ( "Method 1 - deltaH: %2.2f deltaS: %2.2f" % ( deltaH , deltaS ) , size = 18 ) f . subplots_adjust ( bottom = 0.15 , top = 0.85 ) if show == True : self . showTkFigure ( f ) if figname == None : figname = d figname = figname . replace ( '.' , '_' ) fname = figname + 'm1' + '.png' f . savefig ( fname , dpi = 300 ) print 'plot saved to %s' % os . path . abspath ( fname ) if E != None : fdata = Fitting . makeFitData ( X . name , vrs = X . variables ) E . insertDataset ( xydata = [ t , k ] , newname = d + '_vanthoff' , replace = True , fit = fdata ) return deltaH , deltaS , ax
Derive fraction unfolded, get K and fit to Van't Hoff.
Derive fraction unfolded get K and fit to Van ' t Hoff .
"""Derive fraction unfolded, get K and fit to Van't Hoff.
           see http://www.jbc.org/content/277/43/40717.full
           or http://www.ncbi.nlm.nih.gov/pmc/articles/PMC2144003/
        """ #derive lnK vs 1/T #(r'$1/T ($K^-1)$') #fit this van't hoff plot #self.drawParams(ax,fd) #slope is deltaH/R/1000 in kJ #plt.close() #E.saveProject()
self
E
d
xy
transwidth
invert
show
figname