ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/osprai/osprai/trunk/modelclass1.py
Revision: 1
Committed: Wed Mar 17 05:34:43 2010 UTC (9 years, 4 months ago) by clausted
File size: 3237 byte(s)
Log Message:
Initial import of Osprai project
Line User Rev File contents
1 clausted 1 """
2     Provide the model for curvefitting.
3    
4     Yuhang Wan, Feb25, 2010
5     __version__ = "1.0"
6    
7     This is a basic 1:1 reaction model.
8    
9     """
10    
11     import numpy as np
12     import pylab as plt
13    
14    
15     class modelclass(object):
16     def __init__ (self, parainfo=[] ):
17     self.parainfo = parainfo
18     ## self.pfloat = []
19    
20     def wizard(self, ):
21     '''This function helps you to create a parameter information list.
22     This is a basic 1:1 reaction model, where there are 7 parameters:
23     Rmax,Kon,Koff,Conc,t_on,t_off,t_out'''
24     print ('')
25     pname = ['rmax','kon','koff','c','ton','toff','tout']
26     parainfo = []
27     for i in range(7):
28     print i
29     tmp={}
30     tmp['name'] = pname[i]
31     vstr = raw_input("input the value of parameter '%s', if a series, seperate with ',': " %pname[i])
32     vtmp = vstr.strip().split(',')
33     tmp['number'] = len(vtmp)
34     if len(vtmp) == 1:
35     vtmp = float(vtmp[0])
36     else:
37     vtmp = map(float, vtmp)
38     tmp['value'] = vtmp
39     tmp['fixed'] = bool(input("Is '%s' fixed? (1/0): " %pname[i]))
40    
41     parainfo.append(tmp)
42     ##parainfo.append({'name':'', 'value':0., 'fixed':0, 'number':0})
43     self.parainfo = parainfo
44    
45    
46     def function(self, t, paralist):
47     '''This function calculates the theoretical curve through the
48     parameter list you give.
49     '''
50     # for the basic 1:1 model
51    
52     ## Assign the parameters to calculate the curve
53     for p in paralist:
54     if p['name'] == 'rmax': rmax = p['value']
55     elif p['name'] == 'kon': kon = p['value']
56     elif p['name'] == 'koff': koff = p['value']
57     elif p['name'] == 'c': c = p['value']
58     elif p['name'] == 'ton': ton = p['value']
59     elif p['name'] == 'toff': toff = p['value']
60     elif p['name'] == 'tout': tout = p['value']
61     else: print p['name'], p['value']
62    
63    
64     t1 = ton ##100 ##234 # Initial injection
65     t2 = toff ##178 ##570 # Wash, begin of the dissociation
66     t3 = tout ##400 ##840 # End wash
67    
68     ## Must iterate through data, numerical integration.
69     g = np.zeros(len(t), dtype=float)
70    
71     for i in range(1,len(t)):
72     if (t[i] > t3): break #Speed things up.
73     if (t1 < t[i] < t2):
74     ## Association
75     dG = kon*c*(rmax-g[i-1]) - koff*g[i-1]
76     elif (t2 < t[i] < t3):
77     ## Dissociation
78     dG = 0 - koff*g[i-1]
79     else:
80     dG = 0
81     if (abs(g[i]) > 999999999): dG = 0
82    
83     g[i] = g[i-1] + dG * (t[i] - t[i-1])
84    
85     return g
86    
87    
88     def updatemodel(self, parainfo):
89     '''This function helps to update the parameter information.
90     Usually used when you want to keep the fitted value as the
91     initial guess for next curve fitting.
92     '''
93     self.parainfo = parainfo
94    
95