From ed0ea638016e6d1673f9b66edc42fec2e1d83eed Mon Sep 17 00:00:00 2001 From: devicerandom Date: Fri, 13 Feb 2009 13:48:23 +0000 Subject: [PATCH] added first (still to debug) version of pcluster --- convfilt.conf | 4 +- hooke.conf | 3 +- hooke_cli.py | 8 +-- pcluster.py | 183 ++++++++++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 191 insertions(+), 7 deletions(-) create mode 100644 pcluster.py diff --git a/convfilt.conf b/convfilt.conf index ef5254c..db7134a 100644 --- a/convfilt.conf +++ b/convfilt.conf @@ -16,5 +16,5 @@ blindwindow=nm after the contact point where we do not count peaks. --> - - \ No newline at end of file + + diff --git a/hooke.conf b/hooke.conf index d929b61..439816d 100755 --- a/hooke.conf +++ b/hooke.conf @@ -34,6 +34,7 @@ This section defines which plugins have to be loaded by Hooke. + - + diff --git a/hooke_cli.py b/hooke_cli.py index a822042..6b0d314 100755 --- a/hooke_cli.py +++ b/hooke_cli.py @@ -99,10 +99,10 @@ class HookeCli(cmd.Cmd): pass - self.playlist_saved=0 - self.playlist_name='' - self.notes_saved=1 - self.notes_filename=None + self.playlist_saved=0 #Did we save the playlist? + self.playlist_name='' #Name of playlist + self.notes_saved=1 #Did we save the notes? + self.notes_filename=None #Name of notes #create outlet self.outlet=lout.Outlet() diff --git a/pcluster.py b/pcluster.py new file mode 100644 index 0000000..a70a7b7 --- /dev/null +++ b/pcluster.py @@ -0,0 +1,183 @@ +#!/usr/bin/env python + +from libhooke import WX_GOOD, ClickedPoint +import wxversion +wxversion.select(WX_GOOD) +from wx import PostEvent +import numpy as np +import scipy as sp +import copy +import os.path +import time + +import warnings +warnings.simplefilter('ignore',np.RankWarning) + + +class pclusterCommands: + + def do_pcluster(self,args): + ''' + pCLUSTER + (pcluster.py) + ''' + + #configuration variables + min_npks = 5 + min_deviation = 5 + + # ------ FUNCTION ------ + def fit_interval_nm(start_index,plot,nm,backwards): + ''' + Calculates the number of points to fit, given a fit interval in nm + start_index: index of point + plot: plot to use + backwards: if true, finds a point backwards. + ''' + whatset=1 #FIXME: should be decidable + x_vect=plot.vectors[1][0] + + c=0 + i=start_index + start=x_vect[start_index] + maxlen=len(x_vect) + while abs(x_vect[i]-x_vect[start_index])*(10**9) < nm: + if i==0 or i==maxlen-1: #we reached boundaries of vector! + return c + if backwards: + i-=1 + else: + i+=1 + c+=1 + return c + + def plot_informations(itplot): + ''' + OUR VARIABLES + contact_point.absolute_coords (2.4584142802103689e-007, -6.9647135616234017e-009) + peak_point.absolute_coords (3.6047748250571423e-008, -7.7142802788854212e-009) + other_fit_point.absolute_coords (4.1666139243838867e-008, -7.3759393477579707e-009) + peak_location [510, 610, 703, 810, 915, 1103] + peak_size [-1.2729111505202212e-009, -9.1632775347399312e-010, -8.1707438353929907e-010, -8.0335812578148904e-010, -8.7483955226387558e-010, -3.6269619757067322e-009] + params [2.2433999931959462e-007, 3.3230248825175678e-010] + fit_errors [6.5817195369767644e-010, 2.4415923138871498e-011] + ''' + fit_points=int(self.config['auto_fit_points']) # number of points to fit before the peak maximum <50> + pl_value=None # persistent length + T=self.config['temperature'] #temperature of the system in kelvins. By default it is 293 K. <301.0> + cindex=self.find_contact_point() #Automatically find contact point <158, libhooke.ClickedPoint> + contact_point=self._clickize(itplot[0].vectors[1][0], itplot[0].vectors[1][1], cindex) + self.basepoints=[] + base_index_0=peak_location[-1]+fit_interval_nm(peak_location[-1], itplot[0], self.config['auto_right_baseline'],False) + self.basepoints.append(self._clickize(itplot[0].vectors[1][0],itplot[0].vectors[1][1],base_index_0)) + base_index_1=self.basepoints[0].index+fit_interval_nm(self.basepoints[0].index, itplot[0], self.config['auto_left_baseline'],False) + self.basepoints.append(self._clickize(itplot[0].vectors[1][0],itplot[0].vectors[1][1],base_index_1)) + self.basecurrent=self.current.path + boundaries=[self.basepoints[0].index, self.basepoints[1].index] + boundaries.sort() + to_average=itplot[0].vectors[1][1][boundaries[0]:boundaries[1]] #y points to average + avg=np.mean(to_average) + return fit_points, contact_point, pl_value, T, cindex, avg + + def features_peaks(itplot, peak, fit_points, contact_point, pl_value, T, cindex, avg): + ''' + calculate informations for each peak and add they in + c_lengths, p_lengths, sigma_c_lengths, sigma_p_lengths, forces, slopes + ''' + c_leng=None + p_leng=None + sigma_c_leng=None + sigma_p_leng=None + force=None + slope=None + + delta_force=10 + slope_span=int(self.config['auto_slope_span']) + + peak_point=self._clickize(itplot[0].vectors[1][0],itplot[0].vectors[1][1],peak) + other_fit_point=self._clickize(itplot[0].vectors[1][0],itplot[0].vectors[1][1],peak-fit_points) + + points=[contact_point, peak_point, other_fit_point] + + params, yfit, xfit, fit_errors = self.wlc_fit(points, itplot[0].vectors[1][0], itplot[0].vectors[1][1], pl_value, T, return_errors=True) + + #Measure forces + delta_to_measure=itplot[0].vectors[1][1][peak-delta_force:peak+delta_force] + y=min(delta_to_measure) + #Measure slopes + slope=self.linefit_between(peak-slope_span,peak)[0] + #check fitted data and, if right, add peak to the measurement + if len(params)==1: #if we did choose 1-value fit + p_leng=pl_value + c_leng=params[0]*(1.0e+9) + sigma_p_lengths=0 + sigma_c_lengths=fit_errors[0]*(1.0e+9) + force = abs(y-avg)*(1.0e+12) + else: #2-value fit + p_leng=params[1]*(1.0e+9) + #check if persistent length makes sense. otherwise, discard peak. + if p_leng>self.config['auto_min_p'] and p_leng