#!/usr/bin/env python
-# -*- coding: utf-8 -*-
+# -*- coding: iso-8859-1 -*-
'''
generalvclamp.py
Plugin regarding general velocity clamp measurements
'''
-from libhooke import WX_GOOD, ClickedPoint
+from hooke.libhooke import WX_GOOD, ClickedPoint
import wxversion
wxversion.select(WX_GOOD)
from wx import PostEvent
warnings.simplefilter('ignore',np.RankWarning)
-class generalvclampCommands:
-
+class generalvclampCommands(object):
+
def _plug_init(self):
self.basecurrent=None
self.basepoints=None
self.autofile=''
-
+
def do_distance(self,args):
'''
DISTANCE
return
else:
dx,unitx,dy,unity=self._delta(set=1)
- print "%.1f nm" %(dx*(10**9))
+ print str(dx*(10**9))+' nm'
to_dump='distance '+self.current.path+' '+str(dx*(10**9))+' nm'
self.outlet.push(to_dump)
Measure the force difference (in pN) between two points
---------------
Syntax: force
- '''
+ '''
if self.current.curve.experiment == 'clamp':
print 'This command makes no sense for a force clamp experiment.'
return
dx,unitx,dy,unity=self._delta(set=1)
- print " %.1f pN"%(dy*(10**12))
+ print str(dy*(10**12))+' pN'
to_dump='force '+self.current.path+' '+str(dy*(10**12))+' pN'
self.outlet.push(to_dump)
-
-
+
+
def do_forcebase(self,args):
'''
FORCEBASE
(generalvclamp.py)
Measures the difference in force (in pN) between a point and a baseline
took as the average between two points.
-
+
The baseline is fixed once for a given curve and different force measurements,
unless the user wants it to be recalculated
------------
'''
rebase=False #if true=we select rebase
maxpoint=False #if true=we measure the maximum peak
-
+
plot=self._get_displayed_plot()
whatset=1 #fixme: for all sets
if 'rebase' in args or (self.basecurrent != self.current.path):
rebase=True
if 'max' in args:
maxpoint=True
-
+
if rebase:
print 'Select baseline'
self.basepoints=self._measure_N_points(N=2, whatset=whatset)
self.basecurrent=self.current.path
-
+
if maxpoint:
print 'Select two points'
points=self._measure_N_points(N=2, whatset=whatset)
points=self._measure_N_points(N=1, whatset=whatset)
#whatplot=points[0].dest
y=points[0].graph_coords[1]
-
+
#fixme: code duplication
boundaries=[self.basepoints[0].index, self.basepoints[1].index]
boundaries.sort()
to_average=plot.vectors[whatset][1][boundaries[0]:boundaries[1]] #y points to average
-
+
avg=np.mean(to_average)
forcebase=abs(y-avg)
- print "%.1f pN"%(forcebase*(10**12))
+ print str(forcebase*(10**12))+' pN'
to_dump='forcebase '+self.current.path+' '+str(forcebase*(10**12))+' pN'
self.outlet.push(to_dump)
Multiplies all the Y values of an SMFS curve by a value stored in the 'force_multiplier'
configuration variable. Useful for calibrations and other stuff.
'''
-
+
#not a smfs curve...
if current.curve.experiment != 'smfs':
return plot
-
+
#only one set is present...
if len(self.plots[0].vectors) != 2:
return plot
-
+
#multiplier is 1...
if (self.config['force_multiplier']==1):
return plot
def plotmanip_flatten(self, plot, current, customvalue=False):
'''
Subtracts a polynomial fit to the non-contact part of the curve, as to flatten it.
- the best polynomial fit is chosen among polynomials of degree 1 to n, where n is
+ the best polynomial fit is chosen among polynomials of degree 1 to n, where n is
given by the configuration file or by the customvalue.
-
+
customvalue= int (>0) --> starts the function even if config says no (default=False)
'''
-
+
#not a smfs curve...
if current.curve.experiment != 'smfs':
return plot
-
+
#only one set is present...
if len(self.plots[0].vectors) != 2:
return plot
-
+
#config is not flatten, and customvalue flag is false too
if (not self.config['flatten']) and (not customvalue):
return plot
-
+
max_exponent=12
delta_contact=0
-
+
if customvalue:
max_cycles=customvalue
else:
max_cycles=self.config['flatten'] #Using > 1 usually doesn't help and can give artefacts. However, it could be useful too.
-
+
contact_index=self.find_contact_point()
-
+
valn=[[] for item in range(max_exponent)]
yrn=[0.0 for item in range(max_exponent)]
errn=[0.0 for item in range(max_exponent)]
max_cycles=0
for i in range(int(max_cycles)):
-
+
x_ext=plot.vectors[0][0][contact_index+delta_contact:]
y_ext=plot.vectors[0][1][contact_index+delta_contact:]
x_ret=plot.vectors[1][0][contact_index+delta_contact:]
return plot
best_exponent=errn.index(min(errn))
-
+
#extension
ycorr_ext=y_ext-yrn[best_exponent]+y_ext[0] #noncontact part
- yjoin_ext=np.array(plot.vectors[0][1][0:contact_index+delta_contact]) #contact part
+ yjoin_ext=np.array(plot.vectors[0][1][0:contact_index+delta_contact]) #contact part
#retraction
ycorr_ret=y_ret-yrn[best_exponent]+y_ext[0] #noncontact part
yjoin_ret=np.array(plot.vectors[1][1][0:contact_index+delta_contact]) #contact part
-
+
ycorr_ext=np.concatenate((yjoin_ext, ycorr_ext))
ycorr_ret=np.concatenate((yjoin_ret, ycorr_ret))
-
+
plot.vectors[0][1]=list(ycorr_ext)
plot.vectors[1][1]=list(ycorr_ret)
-
+
return plot
-
+
#---SLOPE---
def do_slope(self,args):
'''
x=0
for x in xtoplot:
ytoplot.append((x*parameters[0])+parameters[1])
-
+
clickvector_x, clickvector_y=[], []
for item in points:
clickvector_x.append(item.graph_coords[0])
clickvector_y.append(item.graph_coords[1])
lineplot=self._get_displayed_plot(0) #get topmost displayed plot
-
+
lineplot.add_set(xtoplot,ytoplot)
lineplot.add_set(clickvector_x, clickvector_y)
-
-
+
+
if lineplot.styles==[]:
lineplot.styles=[None,None,None,'scatter']
else:
# Translates the indexes into two vectors containing the x,y data to fit
xtofit=self.plots[0].vectors[whatset][0][index1:index2]
ytofit=self.plots[0].vectors[whatset][1][index1:index2]
-
+
# Does the actual linear fitting (simple least squares with numpy.polyfit)
linefit=[]
linefit=np.polyfit(xtofit,ytofit,1)
return (linefit[0],linefit[1],xtofit,ytofit)
-
-
-