(Generate patch)
# Line 17 | Line 17
17
18   ## Import libraries
19   import numpy as np
20 < #import ba_class as ba
21 < #from copy import deepcopy
20 > from copy import deepcopy
21
22
23 < def drift(time, data0, params):
23 > def drift(time, data, params):
24      """
25      This function simply models a constant signal drift in units/second.
26 <    It requires numpys array of times and starting data values,
26 >    It requires numpy arrays of times and starting data values,
27      It only requires one parameter in the params list.
28 <    params['Rate']['value']
28 >    params['rate']['value']
29      """
30 <    data1 = np.zeros(len(times))
30 >    y = np.zeros(len(time), dtype=float)
31      try:
32 <        rate = params['Rate']['value']
32 >        rate = params['rate']['value']
33      except KeyError:
34          print "Error: Rate parameter not supplied to drift() model."
35 <        return data1
35 >        return y
36
37 <    ## ToDo: Finish this code.
37 >    ## Numerical integration.
38 >    y[0] = data[0]
39 >    for i in range(1,len(time)):
40 >        dy = rate * (time[i]-time[i-1])
41 >        y[i] = y[i-1] + dy
42 >
43 >    return y
44 >
45 >
46 > def simple1to1(time, data, params):
47 >    """
48 >    This function simply models a 1:1 interaction
49 >    It requires numpy arrays of times and starting data values,
50 >    params['t1']['value']   is time of injection for binding
51 >    params['rmax']['value'] is maximum response.
52 >    params['conc']['value'] is time of concentration of analyte
53 >    params['kon']['value']  is on-rate of analyte
54 >    params['t2']['value']   is time of end binding / begin washing
55 >    params['koff']['value']  is off-rate of analyte
56 >    params['t3']['value']   is time end of washing / data fitting.
57 >    """
58 >    ## Skip parameter validation steps for now.
59 >    t1 = params['t1']['value']
60 >    rmax = params['rmax']['value']
61 >    conc = params['conc']['value']
62 >    kon = params['kon']['value']
63 >    t2 = params['t2']['value']
64 >    koff = params['koff']['value']
65 >    t3 = params['t3']['value']
66 >
67 >    y = np.zeros(len(time), dtype=float)
68 >    base = y[0] = data[0]  ## Baseline SPR signal.
69
40    return data1
70 +    ## Must iterate through data, numerical integration.
71 +    for i in range(1,len(time)):
72 +        if (time[i] <= t1):
73 +            ## Pre-binding phase.
74 +            base = y[i] = data[i]
75 +        elif (t1 < time[i] <= t2):
76 +            ## Binding phase
77 +            yb = y[i-1] - base
78 +            dy = conc*kon*(rmax-yb) - koff*yb
79 +            if (abs(y[i-1]) > 999999999): dy = 0  ## Is this useful?
80 +            y[i] = y[i-1] + dy * (time[i] - time[i-1])
81 +        elif (t2 < time[i] <= t3):
82 +            ## Dissociation
83 +            yb = y[i-1]-base
84 +            dy = 0 - koff*yb
85 +            y[i] = y[i-1] + dy * (time[i] - time[i-1])
86 +
87 +    return y
88 +

### Diff Legend

 – Removed lines + Added lines < Changed lines > Changed lines