1 # Copyright (C) 2010-2012 W. Trevor King <wking@drexel.edu>
3 # This file is part of Hooke.
5 # Hooke is free software: you can redistribute it and/or modify it
6 # under the terms of the GNU Lesser General Public License as
7 # published by the Free Software Foundation, either version 3 of the
8 # License, or (at your option) any later version.
10 # Hooke is distributed in the hope that it will be useful, but WITHOUT
11 # ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
12 # or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General
13 # Public License for more details.
15 # You should have received a copy of the GNU Lesser General Public
16 # License along with Hooke. If not, see
17 # <http://www.gnu.org/licenses/>.
19 from ..libhooke import WX_GOOD, ClickedPoint
21 wxversion.select(WX_GOOD)
22 from wx import PostEvent
30 warnings.simplefilter('ignore',np.RankWarning)
33 class jumpstatCommands():
35 def do_jumpstat(self,args):
39 Based on the convolution recognition automatically give:
40 - the delta distance between the peaks,
41 - the delta-force from the top of the peaks and subsequent relaxation,
42 - the delta-force from the top of the peaks and the baseline
43 The command allow also to remove the unwanted peaks that can be due to interference.
44 When you first issue the command, it will ask for the filename. If you are giving the filename
45 of an existing file, autopeak will resume it and append measurements to it. If you are giving
46 a new filename, it will create the file and append to it until you close Hooke.
47 You can also define a minimun deviation of the peaks.
51 deviation = number of times the convolution signal is above the noise absolute deviation.
55 #finding the max and the minimum positions for all the peaks
57 #we use if else only to avoid a "bad input" message from find_current_peaks
59 max_peaks_location, peak_size=self.find_current_peaks(noflatten)
60 min_peaks_location, pks2=self.find_current_peaks(noflatten, True, False)
62 max_peaks_location, peak_size=self.find_current_peaks(noflatten, args)
63 min_peaks_location, pks2=self.find_current_peaks(noflatten, args, False)
66 #print "max_peaks_location: "+str(len(max_peaks_location))
67 #print "min_peaks_location: "+str(len(min_peaks_location))
69 #if no peaks, we have nothing to plot. exit.
70 if len(max_peaks_location)==0:
71 print "No peaks on this curve."
74 if len(max_peaks_location)!=len(min_peaks_location):
75 print "Something went wrong in peaks recognition, number of minima is different from number of maxima. Exiting."
78 #otherwise, we plot the peak locations.
79 xplotted_ret=self.plots[0].vectors[1][0]
80 yplotted_ret=self.plots[0].vectors[1][1]
81 xgood=[xplotted_ret[index] for index in max_peaks_location]
82 ygood=[yplotted_ret[index] for index in max_peaks_location]
84 xafter=[xplotted_ret[index] for index in min_peaks_location]
85 yafter=[yplotted_ret[index] for index in min_peaks_location]
87 recplot=self._get_displayed_plot()
88 recplot2=self._get_displayed_plot()
89 recplot.vectors.append([xgood,ygood])
90 recplot2.vectors.append([xafter,yafter])
92 if recplot.styles==[]:
93 recplot.styles=[None,None,'scatter']
94 recplot.colors=[None,None,None]
96 recplot.styles+=['scatter']
97 recplot.colors+=[None]
99 if recplot2.styles==[]:
100 recplot2.styles=[None,None,None]
101 recplot2.colors=[None,'1.0',None]
103 recplot2.styles+=['scatter']
104 recplot2.colors+=['0.5']
106 self._send_plot([recplot])
107 self._send_plot([recplot2])
110 #finding the baseline
111 self.basepoints=self.baseline_points(max_peaks_location, recplot)
112 boundaries=[self.basepoints[0].index, self.basepoints[1].index]
114 to_average=recplot.vectors[1][1][boundaries[0]:boundaries[1]] #y points to average
115 avg=np.mean(to_average)
122 #we calculate the distance vector
123 for g in range(len(max_peaks_location)-1):
124 dist.append((10**9)*(xplotted_ret[max_peaks_location[g]]-xplotted_ret[max_peaks_location[g+1]]))
125 print "Distance values for the peaks in nm:"
128 #the jump-force vector
129 for g in range(len(max_peaks_location)):
130 jumpforce.append((10**12) *(yplotted_ret[min_peaks_location[g]] -yplotted_ret[max_peaks_location[g]]) )
131 print "Force values for the jumps of the peaks in pN:"
134 #the force from baseline vector
135 for g in range(len(max_peaks_location)):
136 force.append((10**12)*(avg-yplotted_ret[max_peaks_location[g]]))
137 print "Force values for the peaks in pN:"
142 #Now ask for the peaks that we don't want
143 print 'Peaks to ignore (0,1...n from contact point,return to take all)'
144 print 'N to discard measurement'
145 exclude_raw=raw_input('Input:')
150 if not exclude_raw=='':
151 exclude=exclude_raw.split(',')
152 #we convert in numbers the input
154 exclude=[int(item) for item in exclude]
156 print 'Bad input, taking nothing.'
159 # we remove the peaks that we don't want from the list, we need a counter beacause if we remove
160 # a peaks the other peaks in the list are shifted by one at each step
164 max_peaks_location=max_peaks_location[1:]
165 min_peaks_location=min_peaks_location[1:]
168 max_peaks_location= max_peaks_location[0:new_a]+max_peaks_location[new_a+1:]
169 min_peaks_location= min_peaks_location[0:new_a]+min_peaks_location[new_a+1:]
170 peak_size= peak_size[0:new_a]+peak_size[new_a+1:]
174 #print "max_peaks_location: "+str(len(max_peaks_location))
175 #print "min_peaks_location: "+str(len(min_peaks_location))
181 #we recalculate the distances and the forces after the removing of the unwanted peaks
182 for g in range(len(max_peaks_location)-1):
183 dist.append(xplotted_ret[max_peaks_location[g]]-xplotted_ret[max_peaks_location[g+1]])
184 for g in range(len(max_peaks_location)):
185 jumpforce.append( yplotted_ret[min_peaks_location[g]] - yplotted_ret[max_peaks_location[g]] )
186 for g in range(len(max_peaks_location)):
187 force.append(avg - yplotted_ret[max_peaks_location[g]])
194 if self.autofile=='':
195 self.autofile=raw_input('Jumpstat filename? (return to ignore) ')
196 if self.autofile=='':
200 if not os.path.exists(self.autofile):
201 f=open(self.autofile,'w+')
202 f.write('Analysis started '+time.asctime()+'\n')
203 f.write('----------------------------------------\n')
204 f.write('; Delta Distance length (m); Jump Force pN; Standard Force pN\n')
205 f.write(self.current.path+'\n')
206 for k in range(len(dist)):
208 f.write(str(dist[k])+";"+str(jumpforce[k])+";"+str(force[k])+"\n" )
213 f=open(self.autofile,'a+')
214 f.write(self.current.path+'\n')
215 for k in range(len(dist)):
217 f.write(str(dist[k])+";"+str(jumpforce[k])+";"+str(force[k])+"\n" )