ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/osprai/osprai/trunk/models2010/modelparallel_varyC.py
Revision: 41
Committed: Tue Jan 18 00:35:23 2011 UTC (8 years, 9 months ago) by clausted
File size: 4965 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 PARALLEL REACTION model with time variable concentration..
4 The reaction equations:
5 L1 + A ==ka1=> L1A
6 L1 + A <=kd1== L1A
7 L2 + A ==ka2=> L2A
8 L2 + A <=kd2== L2A
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 modelparallel_varyC as mpvc
15 >m = mpvc.parallelmodel_varyC()
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 class parallelmodel_varyC(modelclass):
29 """The data attributes of the class:
30 parainfo: the parameter information
31 sim_data: the simulated data
32 conc: the time variable concentration data
33 """
34
35 def __init__ (self, parainfo=[], sim_data=[], conc=[] ):
36 modelclass.__init__(self,parainfo,sim_data)
37 self.conc = conc
38
39 ##------------ not finished yet---------------
40 def load_conc(self, fname):
41 ##fp = file(fname, 'r+')
42 conc = np.loadtxt(fname)
43 self.conc = conc
44 return
45
46 def create_conc(self, t):
47 # create a step-function as concentration curve for debugging now
48 c = np.zeros(len(t), dtype=float)
49 conc = np.zeros((2,len(t)), dtype=float)
50 t = np.array(t)
51 t1 = input("start time:")
52 t2 = input("end time:")
53 ind = plt.find((t>t1-(t[1]-t[0]))&(t<t2-(t[1]-t[0])))
54 c[ind] = 1
55 conc[0] = t
56 conc[1] = c
57 self.conc = conc
58 plt.plot(t,c,'.')
59 plt.show()
60 return
61
62 ##----------------for debugging now------------
63
64 def wizard(self, ):
65 '''This function helps you to create a parameter information list.
66 This is a competing reactions model, where there are 7 parameters:
67 rmax1: Maximum analyte binding capacity for L1(RU),
68 ka1: Association rate constant for L1+A=L1A(M-1S-1),
69 kd1: Dissociation rate constant for L1A=L1+A(S-1),
70 rmax2: Maximum analyte binding capacity for L2(RU),
71 ka2: Association rate constant for L2+A=L2A(M-1S-1),
72 kd2: Dissociation rate constant for L2A=L2+A(S-1),
73 ca: Analyte concentration(M).'''
74 print ('')
75 pname = ['rmax1','ka1','kd1','rmax2','ka2','kd2','ca']
76 parainfo = []
77 for i in range(7):
78 print i
79 tmp={}
80 tmp['name'] = pname[i]
81 vstr = raw_input("input the value of parameter '%s', if a series, seperate with ',': " %pname[i])
82 vtmp = vstr.strip().split(',')
83 tmp['number'] = len(vtmp)
84 if len(vtmp) == 1:
85 vtmp = float(vtmp[0])
86 else:
87 vtmp = map(float, vtmp)
88 tmp['value'] = vtmp
89 tmp['fixed'] = bool(input("Is '%s' fixed? (1/0): " %pname[i]))
90
91 parainfo.append(tmp)
92 ##parainfo.append({'name':'', 'value':0., 'fixed':0, 'number':0})
93 self.parainfo = parainfo
94
95
96 def function(self, t, paralist):
97 '''This function calculates the theoretical curve through the
98 parameter list you give.
99 '''
100 # for parallel reactions model
101 ## Assign the parameters to calculate the curve
102 conc = copy.deepcopy(self.conc)
103 C = np.interp(t,conc[0],conc[1])
104 for p in paralist:
105 if p['name'] == 'rmax1': rmax1 = p['value']
106 elif p['name'] == 'ka1': ka1 = p['value']
107 elif p['name'] == 'kd1': kd1 = p['value']
108 elif p['name'] == 'rmax2': rmax2 = p['value']
109 elif p['name'] == 'ka2': ka2 = p['value']
110 elif p['name'] == 'kd2': kd2 = p['value']
111 elif p['name'] == 'ca': ca = p['value']
112 else: print p['name'], p['value']
113 if type(ca1) == list or type(ca2) == list:
114 print "Error: This function can only generate data for a single concentration."
115 return
116
117 ## Must iterate through data, numerical integration.
118 g = np.zeros(len(C), dtype=float)
119 g1 = np.zeros(len(C), dtype=float)
120 g2 = np.zeros(len(C), dtype=float)
121
122 for i in range(1,len(C)):
123 dG1 = ka1*ca*C[i-1]*(rmax1-g1[i-1]) - kd1*g1[i-1]
124 dG2 = ka2*ca*C[i-1]*(rmax2-g2[i-1]) - kd2*g2[i-1]
125 elif (t2 < t[i] < t3):
126
127 if (abs(g1[i]) > 999999999): dG1 = 0
128 if (abs(g2[i]) > 999999999): dG2 = 0
129
130 g1[i] = g1[i-1] + dG1 * (t[i] - t[i-1])
131 g2[i] = g2[i-1] + dG2 * (t[i] - t[i-1])
132 g[i] = g1[i] + g2[i]
133
134 return g
135
136 ##### End of time variable concentrated parallel model class definition.