Ugly fix for contact point freeze; some copyright notices updated.
[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         else:
102             print 'This command makes no sense for a non-force clamp experiment.'
103             
104     def do_defl(self,args):
105         '''
106         DEFL
107         Measure the deflection difference (in nm) between two points
108         Implemented only for force clamp
109         NOTE: It makes sense only on the time VS defl plot; it is still not masked for the other plot...
110         -----
111         Syntax: defl
112         '''
113         if self.current.curve.experiment == 'clamp':
114             print 'Click two points.'
115             points=self._measure_N_points(N=2)
116             defl=abs(points[0].graph_coords[1]-points[1].graph_coords[1])
117             print str(defl*(10**12))+' pN'
118         else:
119             print 'This command makes no sense for a non-force clamp experiment.'
120             
121     def do_step(self,args):
122         '''
123         STEP
124         
125         Measures the length and time duration of a time-Z step
126         -----
127         Syntax: step
128         '''
129         if self.current.curve.experiment == 'clamp':
130             print 'Click three points in this fashion:'
131             print ' (0)-------(1)'
132             print '           |'
133             print '           |'
134             print '           (2)----------'
135             points=self._measure_N_points(N=3,whatset=0)
136             dz=abs(points[2].graph_coords[1]-points[1].graph_coords[1])*(10e+8)
137             dt=abs(points[1].graph_coords[0]-points[0].graph_coords[0])
138             print 'dZ: ',dz,' nm'
139             print 'dT: ',dt,' s'
140             
141         else:
142             print 'This command makes no sense for a non-force clamp experiment.'