14974dc7225380678f8064fdaf390e2cd8e50012
[hooke.git] / generalclamp.py
1 #!/usr/bin/env python
2
3 '''
4 GENERALCLAMP.py
5
6 (c) 2008 Marco Brucale, Massimo Sandal
7
8 Plugin regarding general force clamp measurements
9 '''
10 from libhooke import WX_GOOD, ClickedPoint
11 import wxversion
12 import libhookecurve as lhc
13 wxversion.select(WX_GOOD)
14 from wx import PostEvent
15
16 class generalclampCommands:
17
18     def plotmanip_clamp(self, plot, current, customvalue=False):
19         '''
20         Handles some viewing options for the "force clamp" data format, depending on the state of these configuration variables:
21         (1) If self.config['fc_showphase'] != 0, the 'phase' data column (i.e. the 2nd) is shown in the 0th graph (else it isn't)
22         (2) If self.config['fc_showimposed'] != 0, the 'imposed deflection' data column (i.e. the 5th) is shown in the 1st graph (else it isn't)
23         (3) If self.config['fc_interesting'] == 0, the entire curve is shown in the graphs; if it has a non-zero value N, only phase N is shown.
24
25         NOTE - my implementation of point(3) feels quite awkward - someone smarter than me plz polish that!
26
27         '''
28         
29         #not a fclamp curve...
30         if current.curve.experiment != 'clamp':
31             return plot
32
33         if self.config['fc_interesting'] != 0 and plot.destination==0:
34             lower = int((self.config['fc_interesting'])-1)
35             upper = int((self.config['fc_interesting'])+1)
36             trim = current.curve.trimindexes()[lower:upper]
37             newtime = []
38             newzpiezo = []
39             newphase = []
40             for x in range(trim[0],trim[1]):
41                 newtime.append(self.plots[0].vectors[0][0][x])
42                 newzpiezo.append(self.plots[0].vectors[0][1][x])
43                 newphase.append(self.plots[0].vectors[1][1][x])
44             self.plots[0].vectors[0][0] = newtime
45             self.plots[0].vectors[0][1] = newzpiezo
46             self.plots[0].vectors[1][0] = newtime
47             self.plots[0].vectors[1][1] = newphase
48
49         if self.config['fc_interesting'] != 0 and plot.destination==1:
50             lower = int((self.config['fc_interesting'])-1)
51             upper = int((self.config['fc_interesting'])+1)
52             trim = current.curve.trimindexes()[lower:upper]
53             newtime = []
54             newdefl = []
55             newimposed = []
56             for x in range(trim[0],trim[1]):
57                 newtime.append(self.plots[1].vectors[0][0][x])
58                 newdefl.append(self.plots[1].vectors[0][1][x])
59                 newimposed.append(self.plots[1].vectors[1][1][x])
60             self.plots[1].vectors[0][0] = newtime
61             self.plots[1].vectors[0][1] = newdefl
62             self.plots[1].vectors[1][0] = newtime
63             self.plots[1].vectors[1][1] = newimposed            
64                         
65         if self.config['fc_showphase'] == 0 and plot.destination==0:
66             self.plots[0].remove_set(1)
67             
68         if self.config['fc_showimposed'] == 0 and plot.destination==1:
69             self.plots[1].remove_set(1)
70                          
71         return plot
72       
73     def do_time(self,args):
74         '''
75         TIME
76         Measure the time difference (in seconds) between two points
77         Implemented only for force clamp
78         ----
79         Syntax: time
80         '''
81         if self.current.curve.experiment == 'clamp':
82             print 'Click two points.'
83             time=self._delta(set=0)[0]
84             print str(time*1000)+' ms'
85         else:
86             print 'This command makes no sense for a non-force clamp experiment.'
87             
88     def do_zpiezo(self,args):
89         '''
90         ZPIEZO
91         Measure the zpiezo difference (in nm) between two points
92         Implemented only for force clamp
93         ----
94         Syntax: zpiezo
95         '''
96         if self.current.curve.experiment == 'clamp':
97             print 'Click two points.'
98             points=self._measure_N_points(N=2)
99             zpiezo=abs(points[0].graph_coords[1]-points[1].graph_coords[1])
100             print str(zpiezo*(10**9))+' nm'
101             to_dump='zpiezo '+self.current.path+' '+str(zpiezo*(10**9))+' nm'
102             self.outlet.push(to_dump)
103         else:
104             print 'This command makes no sense for a non-force clamp experiment.'
105             
106     def do_defl(self,args):
107         '''
108         DEFL
109         Measure the deflection difference (in nm) between two points
110         Implemented only for force clamp
111         NOTE: It makes sense only on the time VS defl plot; it is still not masked for the other plot...
112         -----
113         Syntax: defl
114         '''
115         if self.current.curve.experiment == 'clamp':
116             print 'Click two points.'
117             points=self._measure_N_points(N=2)
118             defl=abs(points[0].graph_coords[1]-points[1].graph_coords[1])
119             print str(defl*(10**12))+' pN'
120             to_dump='deflection '+self.current.path+' '+str(defl*(10**12))+' pN'
121             self.outlet.push(to_dump)
122         else:
123             print 'This command makes no sense for a non-force clamp experiment.'
124             
125     def do_step(self,args):
126         '''
127         STEP
128         
129         Measures the length and time duration of a time-Z step
130         -----
131         Syntax: step
132         '''
133         if self.current.curve.experiment == 'clamp':
134             print 'Click three points in this fashion:'
135             print ' (0)-------(1)'
136             print '           |'
137             print '           |'
138             print '           (2)----------'
139             points=self._measure_N_points(N=3,whatset=0)
140             dz=abs(points[2].graph_coords[1]-points[1].graph_coords[1])*(10e+8)
141             dt=abs(points[1].graph_coords[0]-points[0].graph_coords[0])
142             print 'dZ: ',dz,' nm'
143             print 'dT: ',dt,' s'
144             to_dump='step '+self.current.path+' '+'dZ: '+str(dz)+' nm'+' dT: '+str(dt)+' s'
145             self.outlet.push(to_dump)
146             
147         else:
148             print 'This command makes no sense for a non-force clamp experiment.'