Merged with trunk
[hooke.git] / hooke / plugin / generalvclamp.py
index 45cfa2c41d18e3199eb6cc8388aef02ce6a2fa13..5f6657be81d7e205a5bd1f51e8664e49f230e505 100644 (file)
@@ -1,3 +1,6 @@
+#!/usr/bin/env python
+# -*- coding: iso-8859-1 -*-
+
 '''
 generalvclamp.py
 
@@ -118,10 +121,10 @@ class generalvclampCommands(object):
         print str(forcebase*(10**12))+' pN'
         to_dump='forcebase '+self.current.path+' '+str(forcebase*(10**12))+' pN'
         self.outlet.push(to_dump)
-\r
+
     def plotmanip_multiplier(self, plot, current):
         '''
-        Multiplies all the Y values of an SMFS curve by a value stored in the 'force_multiplier'\r
+        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.
         '''
 
@@ -135,17 +138,17 @@ class generalvclampCommands(object):
 
         #multiplier is 1...
         if (self.config['force_multiplier']==1):
-            return plot\r
-\r
+            return plot
+
         for i in range(len(plot.vectors[0][1])):
-            plot.vectors[0][1][i]=plot.vectors[0][1][i]*self.config['force_multiplier']        \r
-\r
-        for i in range(len(plot.vectors[1][1])):
-            plot.vectors[1][1][i]=plot.vectors[1][1][i]*self.config['force_multiplier']\r
-\r
-        return plot            \r
+            plot.vectors[0][1][i]=plot.vectors[0][1][i]*self.config['force_multiplier']        
 
+        for i in range(len(plot.vectors[1][1])):
+            plot.vectors[1][1][i]=plot.vectors[1][1][i]*self.config['force_multiplier']
 
+        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.
@@ -180,7 +183,17 @@ class generalvclampCommands(object):
         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)]
-
+        
+        #Check if we have a proper numerical value
+        try:
+            zzz=int(max_cycles)
+        except:
+            #Loudly and annoyingly complain if it's not a number, then fallback to zero
+            print '''Warning: flatten value is not a number!
+            Use "set flatten" or edit hooke.conf to set it properly
+            Using zero.'''
+            max_cycles=0
+        
         for i in range(int(max_cycles)):
 
             x_ext=plot.vectors[0][0][contact_index+delta_contact:]
@@ -240,30 +253,34 @@ class generalvclampCommands(object):
         if fitspan == 0:
             # Gets the Xs of two clicked points as indexes on the current curve vector
             print 'Click twice to delimit chunk'
-            clickedpoints=[]
             points=self._measure_N_points(N=2,whatset=1)
-            clickedpoints=[points[0].index,points[1].index]
-            clickedpoints.sort()
         else:
             print 'Click once on the leftmost point of the chunk (i.e.usually the peak)'
-            clickedpoints=[]
             points=self._measure_N_points(N=1,whatset=1)
-            clickedpoints=[points[0].index-fitspan,points[0].index]
+            
+        slope=self._slope(points,fitspan)
 
-        # Calls the function linefit_between
+        # Outputs the relevant slope parameter
+        print 'Slope:'
+        print str(slope)
+        to_dump='slope '+self.current.path+' '+str(slope)
+        self.outlet.push(to_dump)
+
+    def _slope(self,points,fitspan):
+               # Calls the function linefit_between
         parameters=[0,0,[],[]]
+        try:
+            clickedpoints=[points[0].index,points[1].index]
+            clickedpoints.sort()
+        except:
+            clickedpoints=[points[0].index-fitspan,points[0].index]        
+
         try:
             parameters=self.linefit_between(clickedpoints[0],clickedpoints[1])
         except:
             print 'Cannot fit. Did you click twice the same point?'
             return
-
-        # Outputs the relevant slope parameter
-        print 'Slope:'
-        print str(parameters[0])
-        to_dump='slope '+self.current.path+' '+str(parameters[0])
-        self.outlet.push(to_dump)
-
+             
         # Makes a vector with the fitted parameters and sends it to the GUI
         xtoplot=parameters[2]
         ytoplot=[]
@@ -287,12 +304,15 @@ class generalvclampCommands(object):
         else:
             lineplot.styles+=[None,'scatter']
         if lineplot.colors==[]:
-            lineplot.styles=[None,None,None,None]
+            lineplot.colors=[None,None,'black',None]
         else:
-            lineplot.colors+=[None,None]
+            lineplot.colors+=['black',None]
+        
+        
+        self._send_plot([lineplot])
 
+        return parameters[0]   
 
-        self._send_plot([lineplot])
 
     def linefit_between(self,index1,index2,whatset=1):
         '''