ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/osprai/osprai/trunk/models2010/modeltwostate.py
Revision: 41
Committed: Tue Jan 18 00:35:23 2011 UTC (8 years, 4 months ago) by clausted
File size: 4634 byte(s)
Log Message:
Moved old data class "SPRdataclass" and accompanying surface interaction model modules to /models2010 subdirectory.  The plan is to implement these models for use with the "ba_class" and the modules in the parent directory.  

Should all the models be added to mdl_module or should they each go in their own module?  I am undecided.  
Line File contents
1 """
2 Provide the model for curvefitting.
3 This is a TWO STATE REACTION model.
4 The reaction equations are:
5 L + A ==ka1=> LA
6 L + A <=kd1== LA
7 LA ==ka2=> LA*
8 LA <=kd2== LA*
9
10 Rui Hou, Yuhang Wan
11 Last modified on 100427 (yymmdd) by YW
12
13 Typical Pipeline:(work together with "modelclass.py" the father class):
14 >import modeltwostate as mt
15 >m = mt.twostatemodel()
16 >...
17
18 """
19 __version__ = "100427"
20
21 import numpy as np
22 import pylab as plt
23 import copy
24 import os
25 import pickle
26 from modelclass import *
27
28
29 class twostatemodel(modelclass):
30 """The data attributes of the class:
31 parainfo: the parameter information
32 sim_data: the simulated data
33 """
34 def __init__ (self, parainfo=[], sim_data=[] ):
35 modelclass.__init__(self,parainfo,sim_data)
36
37
38 def wizard(self, ):
39 '''This function helps you to create a parameter information list.
40 This is a competing reactions model, where there are 9 parameters:
41 rmax: Maximum analyte binding capacity(RU),
42 ka1: Association rate constant for L+A=LA(M-1S-1),
43 kd1: Dissociation rate constant for LA=L+A(S-1),
44 ka2: Forward rate constant for LA=LA*(S-1),
45 kd2: Backward rate constant for LA*=LA(S-1),
46 ca: Analyte concentration(M),
47 ton: Starting time for sample injection(s),
48 toff: Ending time for sample injection(s),
49 tout: Total time(s).'''
50 print ('')
51 pname = ['rmax','ka1','kd1','ka2','kd2','ca','ton','toff','tout']
52 parainfo = []
53 for i in range(9):
54 print i
55 tmp={}
56 tmp['name'] = pname[i]
57 vstr = raw_input("input the value of parameter '%s', if a series, seperate with ',': " %pname[i])
58 vtmp = vstr.strip().split(',')
59 tmp['number'] = len(vtmp)
60 if len(vtmp) == 1:
61 vtmp = float(vtmp[0])
62 else:
63 vtmp = map(float, vtmp)
64 tmp['value'] = vtmp
65 tmp['fixed'] = bool(input("Is '%s' fixed? (1/0): " %pname[i]))
66
67 parainfo.append(tmp)
68 ##parainfo.append({'name':'', 'value':0., 'fixed':0, 'number':0})
69 self.parainfo = parainfo
70
71
72 def function(self, t, paralist):
73 '''This function calculates the theoretical curve through the
74 parameter list you give.
75 '''
76 # for two state reaction model
77
78 ## Assign the parameters to calculate the curve
79 for p in paralist:
80 if p['name'] == 'rmax': rmax = p['value']
81 elif p['name'] == 'ka1': ka1 = p['value']
82 elif p['name'] == 'kd1': kd1 = p['value']
83 elif p['name'] == 'ka2': ka2 = p['value']
84 elif p['name'] == 'kd2': kd2 = p['value']
85 elif p['name'] == 'ca': ca = p['value']
86 elif p['name'] == 'ton': ton = p['value']
87 elif p['name'] == 'toff': toff = p['value']
88 elif p['name'] == 'tout': tout = p['value']
89 else: print p['name'], p['value']
90 if type(ca1) == list or type(ca2) == list:
91 print "Error: This function can only generate data for a single concentration."
92 return
93
94 t1 = ton ##100 ##234 # Initial injection
95 t2 = toff ##178 ##570 # Wash, begin of the dissociation
96 t3 = tout ##400 ##840 # End wash
97
98 ## Must iterate through data, numerical integration.
99 g = np.zeros(len(t), dtype=float)
100 g1 = np.zeros(len(t), dtype=float)
101 g2 = np.zeros(len(t), dtype=float)
102
103 for i in range(1,len(t)):
104 if (t[i] > t3): break #Speed things up.
105 if (t1 < t[i] < t2):
106 ## Association
107 dG1 = (ka1*ca*(rmax-g1[i-1]-g2[i-1]) - kd1*g1[i-1])-(ka2*g1[i-1]- kd2*g2[i-1])
108 dG2 = ka2*g1[i-1]- kd2*g2[i-1]
109 elif (t2 < t[i] < t3):
110 ## Dissociation
111 dG1 = 0 - kd1*g1[i-1] - ka2*g1[i-1] + kd2*g2[i-1]
112 dG2 = ka2*g1[i-1]- kd2*g2[i-1]
113 else:
114 dG1 = 0
115 dG2 = 0
116 if (abs(g1[i]) > 999999999): dG1 = 0
117 if (abs(g2[i]) > 999999999): dG2 = 0
118
119 g1[i] = g1[i-1] + dG1 * (t[i] - t[i-1])
120 g2[i] = g2[i-1] + dG2 * (t[i] - t[i-1])
121 g[i] = g1[i] + g2[i]
122
123 return g
124
125 ##### End of twostate model class definition.