From: W. Trevor King Date: Sat, 7 Aug 2010 18:54:01 +0000 (-0400) Subject: Added 'delta' command to hooke.plugin.curve X-Git-Url: http://git.tremily.us/?a=commitdiff_plain;h=a15ac14993d242ee0a52848f3e1b681c8fc22612;p=hooke.git Added 'delta' command to hooke.plugin.curve --- diff --git a/doc/tutorial.txt b/doc/tutorial.txt index f4746b8..bea2282 100644 --- a/doc/tutorial.txt +++ b/doc/tutorial.txt @@ -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 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ diff --git a/hooke/plugin/curve.py b/hooke/plugin/curve.py index 158cb77..3208afa 100644 --- a/hooke/plugin/curve.py +++ b/hooke/plugin/curve.py @@ -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. diff --git a/hooke/plugin/tutorial.py b/hooke/plugin/tutorial.py index c9efa31..08b48f9 100644 --- a/hooke/plugin/tutorial.py +++ b/hooke/plugin/tutorial.py @@ -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,