Added 'delta' command to hooke.plugin.curve
authorW. Trevor King <wking@drexel.edu>
Sat, 7 Aug 2010 18:54:01 +0000 (14:54 -0400)
committerW. Trevor King <wking@drexel.edu>
Sat, 7 Aug 2010 18:54:01 +0000 (14:54 -0400)
doc/tutorial.txt
hooke/plugin/curve.py
hooke/plugin/tutorial.py

index f4746b81d5d2ab85bf4ee770752487cae34cff12..bea22824b52cb02be324299fcafa8c1ab23ac89e 100644 (file)
@@ -247,28 +247,22 @@ Interacting with the plot
 Measuring distances and forces
 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
 
-You can easily zoom in the plot by dragging a rectangle on it with the
-left mouse button.  To zoom out, click the right mouse
-button. Sometimes by zooming in and out too much, you can lose the
-picture (this is probably a small bug in Matplotlib).  Just type
-``plot`` at the command line and the curve will be refreshed.
+You can move about the plot using its navigation toolbar.  See the
+`Matplotlib manual`_ for details.
+
+.. _Matplotlib manual:
+  http://matplotlib.sourceforge.net/users/navigation_toolbar.html
 
 You can measure distances and forces directly in the plot. Just issue
-the command ``distance``.  You will be asked to click two points.
-When you click a point, a blue dot should appear.  When you click the
-second point, the distances (in nanometers and piconewtons) will
-appear on the command line.  You can use ``delta`` if you prefer,
-which gives meaningful values for every kind of graph (not only force
-curves). If you want to know the coordinates of a single point, use
-``point``.
+the command ``delta``.  You will be asked to click two points.  When
+you click a point, a blue dot should appear.  When you click the
+second point, the distances will appear in the output panel.  If you
+want to know the coordinates of a single point, left click on it.
 
 Hooke automatically adjusts the position of the clicked point to the
 nearest point in the graph, so you will be always measuring distances
 and forces between points in the graph.
 
-The commands ``force`` and ``distance`` are present in the
-``generalvclamp`` plugin.
-
 Worm like chain and freely jointed chain fitting
 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
 
index 158cb772a3e2c4ba31dcaf0aa4284c24e93c2f92..3208afad5ece570529465db55df27c2bae74c6e5 100644 (file)
@@ -32,15 +32,16 @@ from ..plugin import Builtin
 from ..plugin.playlist import current_playlist_callback
 from ..util.calculus import derivative
 from ..util.fft import unitary_avg_power_spectrum
+from ..util.si import ppSI, split_data_label
 
 
 class CurvePlugin (Builtin):
     def __init__(self):
         super(CurvePlugin, self).__init__(name='curve')
         self._commands = [
-            GetCommand(self), InfoCommand(self), ExportCommand(self),
-            DifferenceCommand(self), DerivativeCommand(self),
-            PowerSpectrumCommand(self)]
+            GetCommand(self), InfoCommand(self), DeltaCommand(self),
+            ExportCommand(self), DifferenceCommand(self),
+            DerivativeCommand(self), PowerSpectrumCommand(self)]
 
 
 # Define common or complicated arguments
@@ -134,6 +135,50 @@ class InfoCommand (Command):
     def _get_block_sizes(self, curve):
         return [block.shape for block in curve.data]
 
+
+class DeltaCommand (Command):
+    """Get distance information between two points.
+
+    With two points A and B, the returned distances are A-B.
+    """
+    def __init__(self, plugin):
+        super(DeltaCommand, self).__init__(
+            name='delta',
+            arguments=[
+                CurveArgument,
+                Argument(name='block', type='int', default=0,
+                    help="""
+Data block that points are selected from.  For an approach/retract
+force curve, `0` selects the approaching curve and `1` selects the
+retracting curve.
+""".strip()),
+                Argument(name='point', type='point', optional=False, count=2,
+                         help="""
+Indicies of points bounding the selected data.
+""".strip()),
+                Argument(name='SI', type='bool', default=False,
+                         help="""
+Return distances in SI notation.
+""".strip())
+                ],
+            help=self.__doc__, plugin=plugin)
+
+    def _run(self, hooke, inqueue, outqueue, params):
+        data = params['curve'].data[params['block']]
+        As = data[params['point'][0],:]
+        Bs = data[params['point'][1],:]
+        ds = [A-B for A,B in zip(As, Bs)]
+        if params['SI'] == False:
+            out = [(name, d) for name,d in zip(data.info['columns'], ds)]
+        else:
+            out = []
+            for name,d in zip(data.info['columns'], ds):
+                n,units = split_data_label(name)
+                out.append(
+                  (n, ppSI(value=d, unit=units, decimals=2)))
+        outqueue.put(out)
+
+
 class ExportCommand (Command):
     """Export a :class:`hooke.curve.Curve` data block as TAB-delimeted
     ASCII text.
index c9efa31569b5bea428c5146be314b9224aed3401..08b48f954cadf4a9beca4f37e4e19ad6c4f3f8a2 100644 (file)
@@ -252,7 +252,7 @@ class HookeInfoCommand (Command):
 
 
 class PointInfoCommand (Command):
-    """Get information about two user-selected points.
+    """Get information about user-selected points.
 
     Ordinarily a command that knew it would need user selected points
     would declare an appropriate argument (see, for example,