Use Sphinx's :manpage: construct for python(1).
[hooke.git] / doc / tutorial.txt
1 ********
2 Tutorial
3 ********
4
5 `A short video showing Hooke in action`_! (courtesy of Fabrizio
6 Benedetti, EPFL, Lausanne)
7
8 .. _A short video showing Hooke in action:
9   https://documents.epfl.ch/users/f/fb/fbenedet/www/hooke_short_demostration.ogv
10
11 .. toctree::
12    :maxdepth: 2
13
14    gui
15
16 Introduction
17 ============
18
19 This tutorial will focus on the command-line interface as the most
20 powerful, and leave the :doc:`gui` interface to another document.
21
22 .. _command-line: `Command-line interface`_
23
24 Installation
25 ============
26
27 See :doc:`install` for details on downloading and installing Hooke.
28
29
30 Command-line interface
31 ======================
32
33 Running the hooke shell
34 -----------------------
35
36 Hooke has a set of commands that depend on the loaded
37 :class:`hooke.plugin.Plugin`\s.  To access these commands, you'll need
38 to run the Hooke shell.::
39
40     $ hooke
41
42 If you are running hooke from the source directory (see
43 :doc:`install`), the equivalent command is::
44
45     $ python bin/hooke
46
47 You may need to give the full path for Python on Windows systems, and
48 also check that the current working directory (`.`) is in your
49 `PYTHONPATH`.  See :manpage:`python(1)` for details.
50
51 As Hooke launches, you should see something like the following in your
52 terminal::
53
54     Hooke version 0.8.0 Seinei
55
56     COPYRIGHT
57     ----
58     hooke>
59
60 The final line, ``hooke>``, is the Hooke prompt.  It allows you to
61 enter commands to interact with the interpreter.
62
63 Help
64 ----
65
66 All commands have help text explaining their purpose and usage.  The
67 text is stored in the code itself, and therefore more likely to be up
68 to date than this tutorial.  You can get a list of commands and topics
69 with::
70
71     hooke> help
72
73 Or see specific help on ``TOPIC`` with::
74
75     hooke> help TOPIC
76
77 for example::
78
79     hooke> help load_playlist
80
81 will give help on the ``load_playlist`` command.
82
83 Leaving Hooke
84 -------------
85
86 When you're done with an interactive Hooke session, you can close the
87 session with ``exit`` or its aliases ``quit`` and ``EOF`` (``EOF`` is
88 the end of the stdin stream, which is Ctrl-d in many shells).
89
90 Creating a playlist
91 -------------------
92
93 To start analyzing your curves, you first have to build a playlist. The
94 playlist is just an index of the force curve files you want to
95 analyze. Imagine it as a music playlist (that’s why it is called a
96 playlist), but with data files instead of audio files.
97
98 Suppose you have 100 PicoForce curve files in your curves directory,
99 starting from :file:`mycurve.000` and ending in :file:`mycurve.100`
100 and you want to analyze them all.
101
102 You then can ``cd`` (change directory) to the directory::
103
104     hooke> cd --path c:\curves
105
106 Type ``pwd`` (print working directory) to check the directory is correct.::
107
108     hooke> pwd
109     c:\curves
110
111 You can list the files in the directory using ``ls`` or ``dir``
112 (they’re synonyms).::
113
114     hooke> ls
115     mycurve.000
116     mycurve.001
117     ...
118
119 Now you are ready to generate the playlist. The command to use is
120 ``glob_curves_to_playlist``.::
121
122     hooke> glob_curves_to_playlist mycurve.*
123
124 You can also be more specific with wildcards.  For example
125
126     hooke> glob_curve_to_playlist mycurve.05*
127
128 will take only curves from :file:`mycurve.050` to :file:`mycurve.059`.
129
130 Note that by using ``glob_curve_to_playlist`` you just generate the
131 playlist in the local session. To save your playlist to a file for
132 future reuse, type::
133
134     hooke> save_playlist --output mylist
135
136 In this example, the list will be saved in the file
137 :file:`mylist.hkp`.  Hooke will add the extension ``.hkp`` (Hooke
138 playlist) to the playlist if you forget to.  The ``.hkp`` file is an
139 XML file you can read and edit with any text editor (i.e. Wordpad), if
140 needed.  If you want to load it, simply issue ``load_playlist
141 mylist.hkp`` or ``load_playlist mylist``, Hooke will add ``.hkp`` if
142 necessary.
143
144 If, generating the playlist, you are including by chance a non-force
145 curve file that Hooke cannot open, Hooke will print an error and
146 continue on.
147
148 Navigating the playlist
149 -----------------------
150
151 Now you can navigate through your playlist using the commands
152 ``next_curve`` and ``previous_curve``. You don’t need to type
153 ``next_curve`` every time to run along a list of curves.  If you press
154 Return to an empty prompt, Hooke will repeat the last command you
155 issued explicitly.  You can also navigate through the command history
156 by using the up and down arrows, or auto-complete partial commands
157 with TAB.  From the last curve of your playlist, ``next_curve`` will
158 wrap around to the first curve.  Analogously, issuing
159 ``previous_curve`` at the first curve will jump to the last.
160
161 You can also jump to a given curve::
162
163     hooke> jump_to_curve 14
164
165 will jump to the 14th curve in the playlist.  TODO: jump_to_curve
166 <PATH>, where the path can be either an absolute path or a path
167 relative to the directory holding the playlist file.
168
169 Taking notes
170 ------------
171
172 You can take notes about the curves you are looking at.  Just type
173 ``add_note`` followed by the text you want to append to that curve.
174 Hooke will save the text in your current playlist and in an external
175 log file (TODO: no external file yet.  Is this important?).  The
176 output will look like this::
177
178     Notes taken at Sun Sep 17 20:42:07 2006
179     /home/cyclopia/work/tris/20060620a.041 | This is a note
180     /home/cyclopia/work/tris/20060620a.207 | This is another note
181     /home/cyclopia/work/tris/20060620a.286 | This is a third one
182
183 The log file name can be configured (:doc:`config`), but it defaults
184 to :file:`hooke.log`.
185
186 Usually curves you annotated are useful later.  You can create a
187 playlist for only annotated curves with
188
189     hooke> note_filter_playlist --name c:\curves\nice.hkp
190
191 will create sub-playlist :file:`c:\curves\nice.hkp`.  Make sure that
192 the target directory (here :file:`c:\curves\`) already exists before
193 doing that.
194
195 If you change your mind about a note, you can remove it with
196 ``clear_note``.
197
198 Exporting curves
199 ----------------
200
201 You can export Hooke curves as images and as text columns. To export
202 as images or text, use the ``export_block`` command.  Supported
203 formats are PNG (Portable Network Graphic, raster) and EPS
204 (Encapsulated Postscript, vector).  The export format is determined by
205 the filename extension, so ``export_block foo.png``, ``export_block
206 foo.eps``, and ``export_block foo.txt`` will save PNG, EPS, and
207 TAB-delimited text files respectively.
208
209 TODO: multiple cycles?  Solution: blank lines for "breaks", add option
210 to extract specific sections using Python's slice notation.
211
212 If you don't want the entire block, try the ``cut`` command.
213
214 Interacting with the plot
215 -------------------------
216
217 (no plots in command line mode...)
218
219 Measuring distances and forces
220 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
221
222 You can easily zoom in the plot by dragging a rectangle on it with the
223 left mouse button.  To zoom out, click the right mouse
224 button. Sometimes by zooming in and out too much, you can lose the
225 picture (this is probably a small bug in Matplotlib).  Just type
226 ``plot`` at the command line and the curve will be refreshed.
227
228 You can measure distances and forces directly in the plot. Just issue
229 the command ``distance``.  You will be asked to click two points.
230 When you click a point, a blue dot should appear.  When you click the
231 second point, the distances (in nanometers and piconewtons) will
232 appear on the command line.  You can use ``delta`` if you prefer,
233 which gives meaningful values for every kind of graph (not only force
234 curves). If you want to know the coordinates of a single point, use
235 ``point``.
236
237 Hooke automatically adjusts the position of the clicked point to the
238 nearest point in the graph, so you will be always measuring distances
239 and forces between points in the graph.
240
241 The commands ``force`` and ``distance`` are present in the
242 ``generalvclamp`` plugin.
243
244 Worm like chain and freely jointed chain fitting
245 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
246
247 You can measure by hand the parameters relative to a force peak using
248 a worm-like chain fitting with the ``fit`` command.  The command by
249 default automatically finds the contact point, asks for two points
250 delimiting the portion to fit, and performs a two-variable fit, with
251 contour length, persistence length, and their relative errors as
252 output.  If desired, one can use the ``noauto`` option to manually
253 click the contact point, and/or the ``pl=NUMBER`` options to impose a
254 specific persistence or Kuhn length (in nanometers). You can choose
255 which model to use with ``set fit_function wlc`` or ``set fit_function
256 fjc``.  See the help of the ``fit`` command from the Hooke command
257 line for details.
258
259 Multiple curve fitting and measuring
260 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
261
262 You can cycle through all your current playlist obtaining WLC fit, FJC
263 fit, rupture force and slope (loading rate) information from each
264 curve using the ``multifit`` command.  The collected data can be saved
265 in a text file for further analysis in your favourite spreadsheet or
266 statistical program.  If you want to check your parameters on the
267 current curve before fitting all the files in your playlist, use
268 ``multifit justone``.  See the ``multifit`` help for more options.
269
270 Fast curve reviewing and saving
271 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
272
273 When automatic routines are not good enough to filter your data, use
274 ``review`` command to cycle through your playlist presenting ten
275 curves in the same graph.  You can then enter the numbers of the
276 interesting curves and automatically save a copy of them into another
277 directory.
278
279 Configuring Hooke
280 -----------------
281
282 You can set environment variables to influence the behaviour of
283 Hooke. The command to use is ``set_config``.
284
285 You can alter permanently the behaviour of Hooke by setting these
286 variables in a Hooke configuration file.  See :doc:`config` for
287 details.