Added illysam branch 0.9.0
authordevicerandom <devnull@localhost>
Mon, 1 Feb 2010 16:09:54 +0000 (16:09 +0000)
committerdevicerandom <devnull@localhost>
Mon, 1 Feb 2010 16:09:54 +0000 (16:09 +0000)
W. Trevor King (2010-6-3):
This branch originally had a separate root from the default branch,
despite being a fork.  The history of the forking has been lost, so
I'm grafting it on at a likely place.  The graft should help with
merging future changes, but don't consider it to be the true history
of this branch.

87 files changed:
CHANGELOG [deleted file]
LICENSE [deleted file]
autopeak.py [deleted file]
config/__init__.py [new file with mode: 0644]
config/config.py [new file with mode: 0644]
config/hooke configspec.ini [new file with mode: 0644]
config/hooke.ini [new file with mode: 0644]
convfilt.conf [deleted file]
csvdriver.py [deleted file]
data/default.000 [moved from default.000 with 100% similarity, mode: 0644]
drivers/__init__.py [new file with mode: 0644]
drivers/csvdriver.py [new file with mode: 0644]
drivers/hemingclamp.py [moved from hemingclamp.py with 56% similarity]
drivers/jpk.py [moved from jpk.py with 73% similarity]
drivers/mcs.py [moved from mcs.py with 54% similarity]
drivers/mfp1dexport.py [new file with mode: 0644]
drivers/picoforce.py [moved from picoforce.py with 80% similarity]
fit.py [deleted file]
flatfilts.py [deleted file]
generalclamp.py [deleted file]
generaltccd.py [deleted file]
generalvclamp.py [deleted file]
hooke.conf [deleted file]
hooke.py [changed mode: 0755->0644]
hooke_cli.py [deleted file]
lib/__init__.py [new file with mode: 0644]
lib/curve.py [new file with mode: 0644]
lib/driver.py [new file with mode: 0644]
lib/file.py [new file with mode: 0644]
lib/libhooke.py [new file with mode: 0644]
lib/peakspot.py [moved from libpeakspot.py with 87% similarity]
lib/playlist.py [new file with mode: 0644]
lib/plot.py [new file with mode: 0644]
lib/plotmanipulator.py [new file with mode: 0644]
lib/plugin.py [new file with mode: 0644]
lib/prettyformat.py [new file with mode: 0644]
lib/results.py [new file with mode: 0644]
libhooke.py [deleted file]
libhookecurve.py [deleted file]
libinput.py [deleted file]
liboutlet.py [deleted file]
libviewer.py [deleted file]
macro.py [deleted file]
massanalysis.py [deleted file]
mfp1dexport.py [deleted file]
mfp_igor_scripts/ExportMFP1D.ipf [deleted file]
mfp_igor_scripts/ExportMFP1DMenu.ipf [deleted file]
panels/__init__.py [new file with mode: 0644]
panels/commands.py [new file with mode: 0644]
panels/perspectives.py [new file with mode: 0644]
panels/playlist.py [new file with mode: 0644]
panels/plot.py [new file with mode: 0644]
panels/propertyeditor.py [new file with mode: 0644]
panels/results.py [new file with mode: 0644]
pca_config.txt [deleted file]
pcluster.py [deleted file]
picoforcealt.py [deleted file]
playlists/test.hkp [new file with mode: 0644]
plugins/__init__.py [new file with mode: 0644]
plugins/autopeak.ini [new file with mode: 0644]
plugins/autopeak.py [new file with mode: 0644]
plugins/core.ini [new file with mode: 0644]
plugins/export.ini [new file with mode: 0644]
plugins/export.py [new file with mode: 0644]
plugins/fit.ini [new file with mode: 0644]
plugins/fit.py [new file with mode: 0644]
plugins/flatfilts.ini [new file with mode: 0644]
plugins/flatfilts.py [new file with mode: 0644]
plugins/generalvclamp.ini [new file with mode: 0644]
plugins/generalvclamp.py [new file with mode: 0644]
plugins/pcluster.ini [new file with mode: 0644]
plugins/playlist.ini [new file with mode: 0644]
plugins/playlist.py [new file with mode: 0644]
plugins/plot.ini [new file with mode: 0644]
plugins/plot.py [new file with mode: 0644]
plugins/procplots.ini [new file with mode: 0644]
plugins/procplots.py [new file with mode: 0644]
plugins/results.ini [new file with mode: 0644]
plugins/results.py [new file with mode: 0644]
procplots.py [deleted file]
resources/hooke.jpg [moved from hooke.jpg with 100% similarity, mode: 0644]
resources/microscope.ico [new file with mode: 0644]
superimpose.py [deleted file]
test.hkp [deleted file]
tutorial.py [deleted file]
tutorialdriver.py [deleted file]
viewer.py [deleted file]

diff --git a/CHANGELOG b/CHANGELOG
deleted file mode 100755 (executable)
index 318ab34..0000000
--- a/CHANGELOG
+++ /dev/null
@@ -1,404 +0,0 @@
-THIS CHANGELOG FILE CONTANS PRE-SVN CHANGELOGS AND SUMMARIES OF POST-SVN CHANGELOGS.
-FROM 0.8.4 ONWARD, DETAILED CHANGELOGS ARE AVAILABLE ON THE HOOKE SUBVERSION REPOSITORY.
-
-0.8.4
-(2008-x-x)
-    PLUGINS:
-    macro.py:
-        hooke does not crash if it doesn't have permissions to create the folder
-       fixed overwriting of export for curves with the same name and different numerical extension
-       fixed macrodir (out of try-catch)
-       cleaned debug output in execmacro
-    DRIVERS:
-       alternative version of picoforce driver
-    INPUT
-       merged (partially) libinput (so far in hooke_cli)
-    OUTLET     
-       merged liboutlet
-
-
-0.8.3
-(2008-04-16)
-    PLUGINS:
-    generalvclamp.py:
-        fixed autopeak header 
-        fixed autopeak slope (now unwanted slope values are discarded)
-
-0.8.2
-(2008-04-10)
-    PLUGINS:
-    flatfilts.py:
-        convfilt does not crash if a file is not a curve
-    generalvclamp.py:
-        autopeak now saves curve data correctly
-        autopeak now generates a dummy note (so that copylog/notelog is aware you measured the curve)
-
-0.8.1
-(2008-04-07)
-    PLUGINS:
-    generalvclamp.py:
-        fixed DeprecationWarning in flatten
-    flatfilts.py
-        convfilt now working
-        
-
-0.8.0:
-(2008-04-04)
-    hooke.py:
-        sanity check of CLI plugins to avoid function overloading at startup
-    hooke_cli.py ; libhooke.py:
-        now playlists keep the index (when you reload the playlist, it starts from the
-            last observed curve)
-        updated plot to use _send_plot()
-        hooke.conf accepts lists as arguments for variables in <display>
-        txt, export now have consistent argument order (thanks to A.G.Casado for pointing me that)
-        txt crashes no more if no filename is given (thanks to A.G.Casado for pointing me that)
-    libhookecurve.py:
-        added add_set() , remove_set() methods to make life easier for plugin writers
-    procplots.py:
-        plotmanip_correct() works with new picoforce.py deflection output (see)
-    PLUGINS:
-    fit.py:
-        updated wlc to use _send_plot()
-        wlc noauto now keeps the contact point
-        wlc reclick to click again the contact point
-        temperature now set in hooke.conf
-    generalvclamp.py:
-        implemented slope (thanks to Marco Brucale)
-        implemented autopeak
-    flatfilts.py:
-        convfilt,peaks use flattened curve
-    macro.py:
-        (new) added macro plugin (thanks to Alberto Gomez Casado)
-    DRIVERS:
-    picoforce.py:
-        fixed trigger bug! (thanks to Alberto Gomez Casado)
-        better deflection output (separated extension,retraction)
-
-0.7.5:
-(2008-03-27)
-    hooke_cli.py:
-        removed outdated size command
-    PLUGINS:
-    generalvclamp.py:
-        implemented flatten
-    DRIVERS:
-    added tutorialdriver.py driver
-    csvdriver.py:
-        fixed (forgot close_all() method)
-
-0.7.4:
-(2008-03-19)
-    added csvdriver driver
-    hooke_cli.py:
-        fixed plot manipulators handling (now it's safe to comment a
-              plot manipulator on hooke.conf)
-    PLUGINS:
-    fit.py:
-        fixed possible crash when clicking two times the same point on wlc
-
-0.7.3:
-(2008-01-10)
-    hooke_cli.py:
-        fixed crash on copylog
-    PLUGINS:
-        massanalysis.py:
-            Initial release
-        tutorial.py:
-            Tutorial plugin, initial release
-
-0.7.2.1:
-(2007-11-30)
-    PLUGINS:
-        flatfilt.py:
-            fixed crash on Windows
-
-0.7.2:
-(2007-11-29)
-    hooke.py:
-        new configuration variable hookedir
-    hooke_cli.py:
-        copylog now checks if the destination is a real directory
-        fixed crashes in set
-    PLUGINS:
-        generalvclamp.py:
-            fixed a crash in forcebase when picking two times the same point
-        flatfilt.py:
-            fixed crash due to convfilt.conf impossible to load
-            initial implementation of the blind window for convfilt
-            initial data set maps (NOT FINISHED)
-
-0.7.1:
-(2007-11-26)
-    PLUGINS:
-        flatfilts.py:
-            fixed possible crash in convfilt
-            implemented configuration file convfilt.conf
-            convfilt defaults are now 5 peaks 5 times more the noise absdev
-            implemented convconf
-            implemented setconf
-        libpeakspot.py:
-            fixed:now it really uses noise_absdev
-
-0.7.0:
-(2007-11-15)
-    hooke_cli.py:
-        implemented _send_plot() helper API function
-    PLUGINS:
-        generalvclamp.py:
-            fixed forcebase to work with subtplot
-        flatfilts.py:
-            implemented convfilt!
-            added libpeakspot.py (helping library for convolution filter)
-
-0.6.5:
-(2007-11-06)
-    hooke_cli.py, hooke.py:
-        plateau and contact (unmaintained) deleted and scheduled for re-release in generalvramp
-        implemented _measure_N_points()
-    PLUGINS:
-    generalvclamp.py:
-        implemented forcebase
-    fit.py:
-        wlc now accepts and uses temperature as an argument
-        wlc has been cleaned and uses new APIs
-
-0.6.4:
-(2007-10-23)
-    hooke_cli.py, libhooke.py:
-        implemented support for defining order of plotmanip methods in hooke.conf
-    hooke_cli.py:
-        implemented delta
-        implemented point
-        attempted fix to bug 0033 (notelog crashing Hooke when using Unicode characters)
-    PLUGINS:
-    generalvramp.py:
-        began to move velocity ramp force spectroscopy-specific things in separate plugin
-    procplots.py:
-        added detriggerize; "set detrigger" 0/1 disables/enables it.
-    DRIVERS:
-    picoforce.py:
-        removed detriggerize() from driver
-
-0.6.3:
-(2007-10-02)
-    hooke_cli.py:
-        rewritten txt command, now working
-    DRIVERS:
-    picoforce.py:
-        implemented detriggerize() to bypass the Picoforce trigger bug
-    PLUGINS:
-    superimpose.py:
-        implemented plotavgimpose
-
-0.6.2:
-(2007-09-27)
-    hooke_cli.py:
-        fixed error handling in notelog
-        smarter handling of directory names in genlist
-        unexpected error handling in do_plot() 
-    hooke.py:
-        implemented GetDisplayedPlot event and handlers
-    PLUGINS:
-    fit.py:
-        fixed (bug 0029) about replotting of wlc on a subtplot curve
-        multiple fitting displayed (to refine...)
-
-0.6.1:
-(2007-08-06)
-    libhooke.py , hooke.py:
-        initial support for workdir configuration variable
-    libhooke.py:
-        fixed Driver() etc. semantics for gracefully handling unrecognized plots
-    hooke_cli.py:
-        fixed export namehandling
-        fixed plot error handling
-    PLUGINS:
-    flatfilts.py:
-        fixed memory leak
-    generalclamp.py:
-        fixed step command
-
-0.6.0 "Anko":
-(2007-07-25)
-    hooke.py:
-        initial plugin support for the gui
-        wlc fitting now 100% plugin
-        measure_points replaces measure_couple etc. and provides much better extensibility
-    hooke_cli.py:
-       curves are sorted at beginning
-    PLUGINS:
-    procplots.py:
-        fft now allows for user selection of curve segment; select the plot; etc.
-    fit.py:
-        added gui section of plugin, now completely independent
-        fixed bug of wlc output
-    superimpose.py:
-        new plugin for superimposition of curve segments (still in development)
-    generalclamp.py:
-        all clamp commands now in a single plugin
-        implemented step
-
-0.5.4:
-(2007-06-15)
-    procplots.py:
-        fixed fft crash with Numpy 1.0.1
-    hooke.py:
-        fixed crashes if plot.scatter[] was empty
-        fixed management of multiple plots (bug #0025)
-    hooke_cli.py
-        fixed zpiezo error in measurement
-    hemingclamp.py, picoforce.py:
-        implemented close_all() method in drivers to avoid too many open files error
-    flatfilts.py:
-        fixed memory leak
-0.5.3:
-(2007-06-06)
-    wlc.py, hooke.py:
-        fixing and cleaning fit code: now the fit is part of a PlotObject and 100% coded in wlc.py
-        plotting of the wlc.py clicked points also begin to be part of a PlotObject
-        management of 'scatter' style property of plots
-    hooke_cli.py
-        fixed measuring error in defl, zpiezo
-    flatfilts.py:
-        slightly optimized has_features() routine
-    procplots.py:
-        fixed derivplot for every number of vectors
-        fixed possible crash of subtplot if applied on a file with != 2 plots
-        added fft command
-    libhookecurve.py:
-        fixed xaxis, yaxis for non-default plots: now defined from PlotObject
-        PlotObject now defines a styles[] vector
-0.5.2:
-(2007-05-21)
-    versioning a bit cleaned
-    fixed bug in hemingclamp.py preventing filename to appear
-    fixed wxversion problem for 2.8
-    fixed too many open files bug (bug 0024)
-    added index command
-0.5.1:
-(2007-05-09)
-    using wxversion to choose from multiple wx versions
-    fixed old dependencies remaining
-0.5.0 "Ingyo":
-(2007-05-03)
-    general code updating and rewriting due to plugin support/better plot management
-    hooke.py:
-        initial plugin architecture for the command line.
-        initial plugin architecture for file drivers
-        initial plugin architecture for processing plots
-        export can now export both top and bottom plot (not together)
-    hooke_cli.py:
-        wlc fitting moved to fit.py plugin
-        flatfilt moved to flatfilts.py plugin
-        subtplot, derivplot moved to procplots.py plugin
-        double plot temporarily fixed for previous commands
-        export can now export both top and bottom plot (not together)
-
-0.4.1:
-(2007-02-13)
-    hooke_cli.py:
-        double plot now default for clamp experiments
-    libhooke.py:
-        fixed bug that prevented flatfilt to work
-        (maybe) fixed memory leak in flatfilt
-    
-0.4.0 "Hanzei":
-(2007-02-08)
-    general code updating and rewriting due to double plot/force clamp supports
-    hooke.py:
-        initial dummy menu sketch
-    hooke.py, hooke_cli.py:
-        first general support in code for double plot: 
-        - derivplot now in separate plot
-        - implemented show and close commands
-        - all functions should be double plot-aware
-        - clicking a point is double plot-aware
-    libhooke.py, hooke_cli.py:
-        general code cleanup: vectors_to_plot(), subtract_plot(), find_contact_point() and derivplot routines are now methods of class HookeCurve
-    hooke_cli.py:
-        implemented quit (alias of exit)
-        implemented version
-    libhooke.py, hooke.py, hooke_cli.py:
-        initial support for force clamp experiments:
-        - hemingclamp driver supported
-        - "experiment" flag describes what kind of experiment is a curve
-        - time, zpiezo, defl commands implemented
-    libhemingclamp.py:
-        inital release.
-
-0.3.1:
-    hooke.py:
-        fixed stupid bug in plateau
-        fixed bug in derivplot and subtplot not taking into account xaxes/yaxes variables
-0.3.0:
-    from now on, all changelog is stored in CHANGELOG
-    hooke.py, libhooke.py, hooke_cli.py:
-        fixed plot and flatfilt crash when processing corrupt files
-        flatfilt output now more verbose
-        implemented system (execute an external OS command)
-        implemented copylog (copies annotated curves to a given directory) (todo 0033)
-        initial txt implementation (exports the current curve as a text file) (todo 0023)
-        fixed exit behaviour (bug 0013)
-        xaxes and yaxes variables now control visualization of plot (todo 0018)
-        new (better) contact point algorithm + workaround for the picoforce trigger bug
-0.2.2 :
-    hooke.py, hooke_cli.py, libhooke.py:
-        support for fixed persistent length in WLC
-0.2.1 :
-    hooke.py , libhooke.py:
-        fixed 'wlc noauto' bug (0012) preventing correct contact point to be used
-0.2.0 : 
-    hooke_cli.py:
-        implemented getlist (alias of genlist)
-        implemented contact (to plot the contact point)
-        fixed bug 0001 (Hooke crashes when opening a non-pf file)
-        fixed bug 0008  (Hooke crashes when generating a playlist with malformed namefiles/nonexistent files)
-        now the plot is refreshed after a "set" command (todo 0014)
-        wlc fit can use the (new) automatic contact point detection (old behaviour is preserved with "noauto" option)
-    hooke.py:
-        fixed versioning printing
-        complete refactoring of contact point routines
-        wlc fit adapted to use the (new) automatic contact point detection
-        wlc fit code a bit cleaned; parts moved to libhooke.py
-    libhooke.py:
-        new contact point algorithm (new algorithm)
-        wlc fit now uses a fancier domain (from contact point to a bit more than last point); initial chunk preparation section moved from hooke.py
-    
-
-OLDER CHANGELOGS:
-
-hooke.py:
-0.1.1   : 
-    From now on, all changelog is stored in hooke.py
-    hooke_cli.py:
-        corrected bug 0010 (addtolist bug), alerts when hitting start/end of playlist
-2006_09_15_devel=0.1.0: initial WLC fit support. We hit 0.1 milestone :D
-2006_08_28_devel: refactoring of plot interaction
-2006_06_14_devel: fixed libhooke calls
-2006_06_08_devel: initial automatic contact point finding
-2006_05_30_devel: configuration file support
-
-hooke_cli.py:
-0.1.1 : from now on, all changelog is in hooke.py
-2006_09_15_devel: implemented wlc; 0.1.0 milestone.
-2006_08_28_devel: refactoring of plot interaction
-2006_07_23_devel: implemented note; implemented flatfilt; implemented notelog; exit now warns if playlist/notes 
-                  have not been saved.
-2006_07_18_devel: implemented subtplot; bug 0007 ("cd" crashing) fixed
-2006_06_16_devel: moved math helper functions in libhooke.py
-2006_06_14_devel: fixed "jump" output; fixed "exit" (now it works!); fixed off-by-one bug in deflection-correction
-2006_06_08_devel: fixed "loadlist" output;
-2006_05_30_devel: initial configuration file support; added "set" command; initial deflection-correction support; added "ls" command as an alias of "dir"
-2006_05_23_devel: rewriting of playlist-handling code due to major rewrite of hooke_playlist.py
-
-libhooke.py
-0.1.1   : from now on, all changelog is in hooke.py
-2006_09_15_devel : initial WLC support
-2006_09_14_devel : initial support for Hemingway velocity clamp files, minor refactorings
-2006_07_22_devel : implemented math function has_features
-2006_06_16_devel : math functions moved here
-2006_06_08_devel : hooke_playlist.py becomes libhooke.py
-2006_05_30_devel : support for deflection in HookeCurve
-2006_05_29_devel : Initial configuration file support
-2006_05_23_devel : Major rewrite. Fixed bug 0002
diff --git a/LICENSE b/LICENSE
deleted file mode 100644 (file)
index fc8a5de..0000000
--- a/LICENSE
+++ /dev/null
@@ -1,165 +0,0 @@
-                  GNU LESSER GENERAL PUBLIC LICENSE
-                       Version 3, 29 June 2007
-
- Copyright (C) 2007 Free Software Foundation, Inc. <http://fsf.org/>
- Everyone is permitted to copy and distribute verbatim copies
- of this license document, but changing it is not allowed.
-
-
-  This version of the GNU Lesser General Public License incorporates
-the terms and conditions of version 3 of the GNU General Public
-License, supplemented by the additional permissions listed below.
-
-  0. Additional Definitions. 
-
-  As used herein, "this License" refers to version 3 of the GNU Lesser
-General Public License, and the "GNU GPL" refers to version 3 of the GNU
-General Public License.
-
-  "The Library" refers to a covered work governed by this License,
-other than an Application or a Combined Work as defined below.
-
-  An "Application" is any work that makes use of an interface provided
-by the Library, but which is not otherwise based on the Library.
-Defining a subclass of a class defined by the Library is deemed a mode
-of using an interface provided by the Library.
-
-  A "Combined Work" is a work produced by combining or linking an
-Application with the Library.  The particular version of the Library
-with which the Combined Work was made is also called the "Linked
-Version".
-
-  The "Minimal Corresponding Source" for a Combined Work means the
-Corresponding Source for the Combined Work, excluding any source code
-for portions of the Combined Work that, considered in isolation, are
-based on the Application, and not on the Linked Version.
-
-  The "Corresponding Application Code" for a Combined Work means the
-object code and/or source code for the Application, including any data
-and utility programs needed for reproducing the Combined Work from the
-Application, but excluding the System Libraries of the Combined Work.
-
-  1. Exception to Section 3 of the GNU GPL.
-
-  You may convey a covered work under sections 3 and 4 of this License
-without being bound by section 3 of the GNU GPL.
-
-  2. Conveying Modified Versions.
-
-  If you modify a copy of the Library, and, in your modifications, a
-facility refers to a function or data to be supplied by an Application
-that uses the facility (other than as an argument passed when the
-facility is invoked), then you may convey a copy of the modified
-version:
-
-   a) under this License, provided that you make a good faith effort to
-   ensure that, in the event an Application does not supply the
-   function or data, the facility still operates, and performs
-   whatever part of its purpose remains meaningful, or
-
-   b) under the GNU GPL, with none of the additional permissions of
-   this License applicable to that copy.
-
-  3. Object Code Incorporating Material from Library Header Files.
-
-  The object code form of an Application may incorporate material from
-a header file that is part of the Library.  You may convey such object
-code under terms of your choice, provided that, if the incorporated
-material is not limited to numerical parameters, data structure
-layouts and accessors, or small macros, inline functions and templates
-(ten or fewer lines in length), you do both of the following:
-
-   a) Give prominent notice with each copy of the object code that the
-   Library is used in it and that the Library and its use are
-   covered by this License.
-
-   b) Accompany the object code with a copy of the GNU GPL and this license
-   document.
-
-  4. Combined Works.
-
-  You may convey a Combined Work under terms of your choice that,
-taken together, effectively do not restrict modification of the
-portions of the Library contained in the Combined Work and reverse
-engineering for debugging such modifications, if you also do each of
-the following:
-
-   a) Give prominent notice with each copy of the Combined Work that
-   the Library is used in it and that the Library and its use are
-   covered by this License.
-
-   b) Accompany the Combined Work with a copy of the GNU GPL and this license
-   document.
-
-   c) For a Combined Work that displays copyright notices during
-   execution, include the copyright notice for the Library among
-   these notices, as well as a reference directing the user to the
-   copies of the GNU GPL and this license document.
-
-   d) Do one of the following:
-
-       0) Convey the Minimal Corresponding Source under the terms of this
-       License, and the Corresponding Application Code in a form
-       suitable for, and under terms that permit, the user to
-       recombine or relink the Application with a modified version of
-       the Linked Version to produce a modified Combined Work, in the
-       manner specified by section 6 of the GNU GPL for conveying
-       Corresponding Source.
-
-       1) Use a suitable shared library mechanism for linking with the
-       Library.  A suitable mechanism is one that (a) uses at run time
-       a copy of the Library already present on the user's computer
-       system, and (b) will operate properly with a modified version
-       of the Library that is interface-compatible with the Linked
-       Version. 
-
-   e) Provide Installation Information, but only if you would otherwise
-   be required to provide such information under section 6 of the
-   GNU GPL, and only to the extent that such information is
-   necessary to install and execute a modified version of the
-   Combined Work produced by recombining or relinking the
-   Application with a modified version of the Linked Version. (If
-   you use option 4d0, the Installation Information must accompany
-   the Minimal Corresponding Source and Corresponding Application
-   Code. If you use option 4d1, you must provide the Installation
-   Information in the manner specified by section 6 of the GNU GPL
-   for conveying Corresponding Source.)
-
-  5. Combined Libraries.
-
-  You may place library facilities that are a work based on the
-Library side by side in a single library together with other library
-facilities that are not Applications and are not covered by this
-License, and convey such a combined library under terms of your
-choice, if you do both of the following:
-
-   a) Accompany the combined library with a copy of the same work based
-   on the Library, uncombined with any other library facilities,
-   conveyed under the terms of this License.
-
-   b) Give prominent notice with the combined library that part of it
-   is a work based on the Library, and explaining where to find the
-   accompanying uncombined form of the same work.
-
-  6. Revised Versions of the GNU Lesser General Public License.
-
-  The Free Software Foundation may publish revised and/or new versions
-of the GNU Lesser General Public License from time to time. Such new
-versions will be similar in spirit to the present version, but may
-differ in detail to address new problems or concerns.
-
-  Each version is given a distinguishing version number. If the
-Library as you received it specifies that a certain numbered version
-of the GNU Lesser General Public License "or any later version"
-applies to it, you have the option of following the terms and
-conditions either of that published version or of any later version
-published by the Free Software Foundation. If the Library as you
-received it does not specify a version number of the GNU Lesser
-General Public License, you may choose any version of the GNU Lesser
-General Public License ever published by the Free Software Foundation.
-
-  If the Library as you received it specifies that a proxy can decide
-whether future versions of the GNU Lesser General Public License shall
-apply, that proxy's public statement of acceptance of any version is
-permanent authorization for you to choose that version for the
-Library.
diff --git a/autopeak.py b/autopeak.py
deleted file mode 100644 (file)
index ffacd82..0000000
+++ /dev/null
@@ -1,369 +0,0 @@
-#!/usr/bin/env python
-
-from libhooke import WX_GOOD, ClickedPoint
-import wxversion
-wxversion.select(WX_GOOD)
-from wx import PostEvent
-import numpy as np
-import scipy as sp
-import copy
-import os.path
-import time
-
-import warnings
-warnings.simplefilter('ignore',np.RankWarning)
-
-
-class autopeakCommands:
-    
-    def do_autopeak(self,args):
-        '''
-        AUTOPEAK
-        (autopeak.py)
-        Automatically performs a number of analyses on the peaks of the given curve.
-        Currently it automatically:
-        - fits peaks with WLC function
-        - measures peak maximum forces with a baseline
-        - measures slope in proximity of peak maximum
-        Requires flatten plotmanipulator , fit.py plugin , flatfilts.py plugin with convfilt
-        
-        Syntax:
-        autopeak [rebase] [pl=value] [t=value] [noauto] [reclick]
-        
-        rebase : Re-asks baseline interval
-        
-        pl=[value] : Use a fixed persistent length for the fit. If pl is not given, 
-                     the fit will be a 2-variable  
-                     fit. DO NOT put spaces between 'pl', '=' and the value.
-                     The value must be in meters. 
-                     Scientific notation like 0.35e-9 is fine.
-        
-        t=[value] : Use a user-defined temperature. The value must be in
-                    kelvins; by default it is 293 K.
-                    DO NOT put spaces between 't', '=' and the value.
-        
-        noauto : allows for clicking the contact point by 
-                 hand (otherwise it is automatically estimated) the first time.
-                 If subsequent measurements are made, the same contact point
-                 clicked the first time is used
-        
-        reclick : redefines by hand the contact point, if noauto has been used before
-                  but the user is unsatisfied of the previously choosen contact point.
-        
-        usepoints : fit interval by number of points instead than by nanometers
-        
-        noflatten : does not use the "flatten" plot manipulator
-        
-        When you first issue the command, it will ask for the filename. If you are giving the filename
-        of an existing file, autopeak will resume it and append measurements to it. If you are giving
-        a new filename, it will create the file and append to it until you close Hooke.
-        
-        
-        Useful variables (to set with SET command):
-        ---
-        temperature= temperature of the system for wlc fit (in K)
-        
-        auto_slope_span = number of points on which measure the slope, for slope
-        
-        auto_fit_nm = number of nm to fit before the peak maximum, for WLC (if usepoints false)
-        auto_fit_points = number of points to fit before the peak maximum, for WLC (if usepoints true)
-        
-        baseline_clicks = -1: no baseline, f=0 at the contact point (whether hand-picked or automatically found)
-                           0: automatic baseline
-                           1: decide baseline with a single click and length defined in auto_left_baseline
-                           2: let user click points of baseline
-        auto_left_baseline = length in nm to use as baseline from the right point (if baseline_clicks=0 , 1)
-        auto_right_baseline = distance in nm of peak-most baseline point from last peak (if baseline_clicks = 0)
-        '''
-        
-        #MACROS.
-        #FIXME: to move outside function
-        def fit_interval_nm(start_index,plot,nm,backwards):
-            '''
-            Calculates the number of points to fit, given a fit interval in nm
-            start_index: index of point
-            plot: plot to use
-            backwards: if true, finds a point backwards.
-            '''
-            whatset=1 #FIXME: should be decidable
-            x_vect=plot.vectors[1][0]
-            
-            c=0
-            i=start_index
-            start=x_vect[start_index]
-            maxlen=len(x_vect)
-            while abs(x_vect[i]-x_vect[start_index])*(10**9) < nm:
-                if i==0 or i==maxlen-1: #we reached boundaries of vector!
-                    return c
-                
-                if backwards:
-                    i-=1
-                else:
-                    i+=1
-                c+=1
-            return c
-                
-        def pickup_contact_point():
-            '''macro to pick up the contact point by clicking'''
-            contact_point=self._measure_N_points(N=1, whatset=1)[0]
-            contact_point_index=contact_point.index
-            self.wlccontact_point=contact_point
-            self.wlccontact_index=contact_point.index
-            self.wlccurrent=self.current.path
-            return contact_point, contact_point_index
-        
-        def find_current_peaks(noflatten):
-            #Find peaks.
-            defplot=self.current.curve.default_plots()[0]
-            if not noflatten:
-                flatten=self._find_plotmanip('flatten') #Extract flatten plotmanip
-                defplot=flatten(defplot, self.current, customvalue=1) #Flatten curve before feeding it to has_peaks
-            peak_location,peak_size=self.has_peaks(defplot, self.convfilt_config['mindeviation'])
-            return peak_location, peak_size
-    
-        #default fit etc. variables
-        pl_value=None
-        T=self.config['temperature']
-        
-        slope_span=int(self.config['auto_slope_span'])
-        delta_force=10
-        rebase=False #if true=we select rebase
-        noflatten=False #if true=we avoid flattening
-        
-        #initialize output data vectors
-        c_lengths=[]
-        p_lengths=[]
-        sigma_c_lengths=[]
-        sigma_p_lengths=[]
-        forces=[]
-        slopes=[]
-        
-        #pick up plot
-        displayed_plot=self._get_displayed_plot(0)
-        
-        #COMMAND LINE PARSING
-        #--Using points instead of nm interval
-        if 'usepoints' in args.split():
-            fit_points=int(self.config['auto_fit_points'])
-            usepoints=True
-        else:
-            fit_points=None
-            usepoints=False
-        #--Recalculate baseline
-        if 'rebase' in args or (self.basecurrent != self.current.path):
-            rebase=True 
-        
-        if 'noflatten' in args:
-            noflatten=True
-        
-        #--Custom persistent length / custom temperature
-        for arg in args.split():
-            #look for a persistent length argument.
-            if 'pl=' in arg:
-                pl_expression=arg.split('=')
-                pl_value=float(pl_expression[1]) #actual value
-            #look for a T argument. FIXME: spaces are not allowed between 'pl' and value
-            if ('t=' in arg[0:2]) or ('T=' in arg[0:2]):
-                t_expression=arg.split('=')
-                T=float(t_expression[1])                   
-        #--Contact point arguments
-        if 'reclick' in args.split():
-            print 'Click contact point'
-            contact_point, contact_point_index = pickup_contact_point()
-        elif 'noauto' in args.split():
-            if self.wlccontact_index==None or self.wlccurrent != self.current.path:
-                print 'Click contact point'
-                contact_point , contact_point_index = pickup_contact_point()
-            else:
-                contact_point=self.wlccontact_point
-                contact_point_index=self.wlccontact_index
-        else:
-            #Automatically find contact point
-            cindex=self.find_contact_point()
-            contact_point=self._clickize(displayed_plot.vectors[1][0], displayed_plot.vectors[1][1], cindex)
-        #--END COMMAND LINE PARSING--
-        
-        
-        peak_location, peak_size = find_current_peaks(noflatten)
-        
-        if len(peak_location) == 0:
-            print 'No peaks to fit.'
-            return
-        
-        fitplot=copy.deepcopy(displayed_plot)
-        
-        #Pick up force baseline
-        if rebase:
-            clicks=self.config['baseline_clicks']
-            if clicks==0:
-                self.basepoints=[]
-                base_index_0=peak_location[-1]+fit_interval_nm(peak_location[-1], displayed_plot, self.config['auto_right_baseline'],False)
-                self.basepoints.append(self._clickize(displayed_plot.vectors[1][0],displayed_plot.vectors[1][1],base_index_0))
-                base_index_1=self.basepoints[0].index+fit_interval_nm(self.basepoints[0].index, displayed_plot, self.config['auto_left_baseline'],False)
-                self.basepoints.append(self._clickize(displayed_plot.vectors[1][0],displayed_plot.vectors[1][1],base_index_1))
-            elif clicks>0:
-                print 'Select baseline'
-                if clicks==1:
-                    self.basepoints=self._measure_N_points(N=1, whatset=whatset)
-                    base_index_1=self.basepoints[0].index+fit_interval_nm(self.basepoints[0].index, displayed_plot, self.config['auto_left_baseline'], False)
-                    self.basepoints.append(self._clickize(displayed_plot.vectors[1][0],displayed_plot.vectors[1][1],base_index_1))
-                else:
-                    self.basepoints=self._measure_N_points(N=2, whatset=whatset)
-            
-            self.basecurrent=self.current.path
-        
-        boundaries=[self.basepoints[0].index, self.basepoints[1].index]
-        boundaries.sort()
-        to_average=displayed_plot.vectors[1][1][boundaries[0]:boundaries[1]] #y points to average
-        avg=np.mean(to_average)
-        
-        clicks=self.config['baseline_clicks']
-        if clicks==-1:
-            try:
-                avg=displayed_plot.vectors[1][1][contact_point_index]
-            except:
-                avg=displayed_plot.vectors[1][1][cindex]
-        
-        for peak in peak_location:
-            #WLC FITTING
-            #define fit interval
-            if not usepoints:
-                fit_points=fit_interval_nm(peak, displayed_plot, self.config['auto_fit_nm'], True)
-            peak_point=self._clickize(displayed_plot.vectors[1][0],displayed_plot.vectors[1][1],peak)
-            other_fit_point=self._clickize(displayed_plot.vectors[1][0],displayed_plot.vectors[1][1],peak-fit_points)
-            
-            #points for the fit
-            points=[contact_point, peak_point, other_fit_point]
-            
-            if abs(peak_point.index-other_fit_point.index) < 2:
-                continue
-            
-            params, yfit, xfit, fit_errors = self.wlc_fit(points, displayed_plot.vectors[1][0], displayed_plot.vectors[1][1], pl_value, T, return_errors=True)
-            
-                
-            #Measure forces
-            delta_to_measure=displayed_plot.vectors[1][1][peak-delta_force:peak+delta_force]
-            y=min(delta_to_measure)
-            #save force values (pN)   
-            #Measure slopes
-            slope=self.linefit_between(peak-slope_span,peak)[0]
-            
-            
-            #check fitted data and, if right, add peak to the measurement
-            #FIXME: code duplication
-            if len(params)==1: #if we did choose 1-value fit
-                p_lengths.append(pl_value)
-                c_lengths.append(params[0]*(1.0e+9))
-                sigma_p_lengths.append(0)
-                sigma_c_lengths.append(fit_errors[0]*(1.0e+9))
-                forces.append(abs(y-avg)*(1.0e+12))
-                slopes.append(slope)     
-                #Add WLC fit lines to plot
-                fitplot.add_set(xfit,yfit)
-                if len(fitplot.styles)==0:
-                    fitplot.styles=[]
-                    fitplot.colors=[]
-                else:
-                    fitplot.styles.append(None)
-                    fitplot.colors.append(None)
-            else: #2-value fit
-                p_leng=params[1]*(1.0e+9)
-                #check if persistent length makes sense. otherwise, discard peak.
-                if p_leng>self.config['auto_min_p'] and p_leng<self.config['auto_max_p']:
-                    p_lengths.append(p_leng)       
-                    c_lengths.append(params[0]*(1.0e+9))
-                    sigma_c_lengths.append(fit_errors[0]*(1.0e+9))
-                    sigma_p_lengths.append(fit_errors[1]*(1.0e+9))
-                    forces.append(abs(y-avg)*(1.0e+12))
-                    slopes.append(slope)     
-                    
-                    #Add WLC fit lines to plot
-                    fitplot.add_set(xfit,yfit)
-                    if len(fitplot.styles)==0:
-                        fitplot.styles=[]
-                        fitplot.colors=[]
-                    else:
-                        fitplot.styles.append(None)
-                        fitplot.colors.append(None)
-                else:
-                    pass
-            
-        #add basepoints to fitplot
-        fitplot.add_set([self.basepoints[0].graph_coords[0],self.basepoints[1].graph_coords[0]],[self.basepoints[0].graph_coords[1],self.basepoints[1].graph_coords[1]]) 
-        fitplot.styles.append('scatter')
-        fitplot.colors.append(None)
-        
-        #Show wlc fits and peak locations
-        self._send_plot([fitplot])
-        #self.do_peaks('')
-        
-        print 'Measurements for all peaks detected:'
-        print 'contour (nm)', c_lengths
-        print 'sigma contour (nm)',sigma_c_lengths
-        print 'p (nm)',p_lengths
-        print 'sigma p (nm)',sigma_p_lengths
-        print 'forces (pN)',forces
-        print 'slopes (N/m)',slopes
-        
-        #Ask the user what peaks to ignore from analysis.
-        print 'Peaks to ignore (0,1...n from contact point,return to take all)'
-        print 'N to discard measurement'
-        exclude_raw=raw_input('Input:')
-        if exclude_raw=='N':
-            print 'Discarded.'
-            return
-        if not exclude_raw=='':
-            exclude=exclude_raw.split(',')
-            try:
-                exclude=[int(item) for item in exclude]
-                for i in exclude:
-                    c_lengths[i]=None
-                    p_lengths[i]=None
-                    forces[i]=None
-                    slopes[i]=None
-                    sigma_c_lengths[i]=None
-                    sigma_p_lengths[i]=None
-            except:
-                 print 'Bad input, taking all...'
-        #Clean data vectors from ignored peaks        
-        #FIXME:code duplication
-        c_lengths=[item for item in c_lengths if item != None]
-        p_lengths=[item for item in p_lengths if item != None]
-        forces=[item for item in forces if item != None]
-        slopes=[item for item in slopes if item != None]    
-        sigma_c_lengths=[item for item in sigma_c_lengths if item != None]    
-        sigma_p_lengths=[item for item in sigma_p_lengths if item != None]    
-        
-        print 'Measurements for chosen peaks:'
-        print 'contour (nm)',c_lengths
-        print 'sigma contour (nm)',sigma_c_lengths
-        print 'p (nm)',p_lengths
-        print 'sigma p (nm)',sigma_p_lengths
-        print 'forces (pN)',forces
-        print 'slopes (N/m)',slopes
-        
-        #Save file info
-        if self.autofile=='':
-            self.autofile=raw_input('Autopeak filename? (return to ignore) ')
-            if self.autofile=='':
-                print 'Not saved.'
-                return
-        
-        if not os.path.exists(self.autofile):
-            f=open(self.autofile,'w+')
-            f.write('Analysis started '+time.asctime()+'\n')
-            f.write('----------------------------------------\n')
-            f.write('; Contour length (nm)  ;  Persistence length (nm) ;  Max.Force (pN)  ;  Slope (N/m) ;  Sigma contour (nm) ; Sigma persistence (nm)\n')
-            f.close()
-            
-        print 'Saving...'
-        f=open(self.autofile,'a+')
-        
-        f.write(self.current.path+'\n')
-        for i in range(len(c_lengths)):
-            f.write(' ; '+str(c_lengths[i])+' ; '+str(p_lengths[i])+' ; '+str(forces[i])+' ; '+str(slopes[i])+' ; '+str(sigma_c_lengths[i])+' ; '+str(sigma_p_lengths[i])+'\n')
-            
-        f.close()
-        self.do_note('autopeak')
-        
\ No newline at end of file
diff --git a/config/__init__.py b/config/__init__.py
new file mode 100644 (file)
index 0000000..803f29c
--- /dev/null
@@ -0,0 +1 @@
+#!/usr/bin/env python\r
diff --git a/config/config.py b/config/config.py
new file mode 100644 (file)
index 0000000..2c89feb
--- /dev/null
@@ -0,0 +1,32 @@
+#!/usr/bin/env python\r
+\r
+'''\r
+config.py\r
+\r
+Configuration for Hooke.\r
+\r
+Copyright 2009 by Dr. Rolf Schmidt (Concordia University, Canada)\r
+\r
+This program is released under the GNU General Public License version 2.\r
+'''\r
+\r
+from configobj import ConfigObj\r
+from validate import Validator\r
+import os.path\r
+\r
+import lib.libhooke as lh\r
+\r
+#configuration file\r
+config = ConfigObj()\r
+filename_ini = lh.get_file_path('hooke.ini', ['config'])\r
+#default values for configuration file\r
+filename_configspec = lh.get_file_path('hooke configspec.ini', ['config'])\r
+if os.path.isfile(filename_ini) and os.path.isfile(filename_configspec):\r
+    config = ConfigObj(filename_ini, configspec=filename_configspec)\r
+    validator = Validator()\r
+    if not config.validate(validator):\r
+        #TODO: send message\r
+        print 'Ini file validation failed'\r
+else:\r
+    #TODO: send message\r
+    print 'Ini file not found'\r
diff --git a/config/hooke configspec.ini b/config/hooke configspec.ini
new file mode 100644 (file)
index 0000000..3bb1cda
--- /dev/null
@@ -0,0 +1,42 @@
+[core]\r
+list = string(default = 'test.hkp')\r
+workdir = string(default = '')\r
+\r
+[drivers]\r
+csvdriver = boolean(default = False)\r
+hemingclamp = boolean(default = False)\r
+jpk = boolean(default = False)\r
+mcs = boolean(default = False)\r
+mfp1dexport = boolean(default = True)\r
+picoforce = boolean(default = True)\r
+picoforcealt = boolean(default = False)\r
+tutorialdriver = boolean(default = False)\r
+\r
+[folders]\r
+filterindex = integer(default = 0)\r
+filters = string(default = 'Playlist files (*.hkp)|*.hkp|Text files (*.txt)|*.txt|All files (*.*)|*.*')\r
+\r
+[main]\r
+height = integer(default = 500)\r
+left = integer(default = 50)\r
+top = integer(default = 50)\r
+width = integer(default = 700)\r
+\r
+[perspectives]\r
+active = string(default = Default)\r
+\r
+[plugins]\r
+autopeak = boolean(default = True)\r
+export = boolean(default = True)\r
+fit = boolean(default = True)\r
+flatfilts = boolean(default = True)\r
+generalvclamp = boolean(default = True)\r
+playlist = boolean(default = True)\r
+plot = boolean(default = True)\r
+procplots = boolean(default = True)\r
+results = boolean(default = True)\r
+\r
+[splashscreen]\r
+#duration in milliseconds\r
+duration = integer(default = 1000)\r
+show = boolean(default = True)\r
diff --git a/config/hooke.ini b/config/hooke.ini
new file mode 100644 (file)
index 0000000..b803753
--- /dev/null
@@ -0,0 +1,54 @@
+#prefix with '#' to add a comment\r
+\r
+[command]\r
+command = autopeak\r
+plugin = autopeak\r
+\r
+[core]\r
+#substitute your work directory\r
+workdir = C:\hooke\r
+#the default playlist to load at startup\r
+list = playlists/test.hkp\r
+\r
+#this section defines which drivers have to be loaded by Hooke\r
+[drivers]\r
+csvdriver = False\r
+hemingclamp = False\r
+jpk = False\r
+mcs = False\r
+mfp1dexport = True\r
+picoforce = True\r
+picoforcealt = False\r
+tutorialdriver = False\r
+\r
+[folders]\r
+filterindex = 0\r
+filters = Playlist files (*.hkp)|*.hkp|Text files (*.txt)|*.txt|All files (*.*)|*.*')\r
+\r
+#this section defines the window size and position\r
+[main]\r
+height = 500\r
+left = 20\r
+top = 20\r
+width = 600\r
+\r
+[perspectives]\r
+active = Default\r
+default = Default\r
+\r
+#this section defines which plugins have to be loaded by Hooke\r
+[plugins]\r
+autopeak = True\r
+export = True\r
+fit = True\r
+flatfilts = True\r
+generalvclamp = True\r
+playlist = True\r
+plot = True\r
+procplots = True\r
+results = True\r
+\r
+[splashscreen]\r
+#duration in milliseconds\r
+duration = 1000\r
+show = True\r
diff --git a/convfilt.conf b/convfilt.conf
deleted file mode 100644 (file)
index db7134a..0000000
+++ /dev/null
@@ -1,20 +0,0 @@
-<?xml version="1.0" ?>
-<config>
-
-<!-- Parameters to calculate the noise absolute deviation.
-     positive= cut out most positive (1) or negative (0) values (default=0)
-     maxcut=cut at maximum a maxcut fraction of all points. (default=0.2) 
-     stable=convergency threshold (when cutting more points the ratio doesn't change more than stable, then stop) (default=0.005)
--->
-<noise_absdev positive="0" maxcut="0.2" stable="0.005"/>
-
-<!-- Parameters of the convfilt.
-     minpeaks=number minimum of peaks we want (default=5)
-     mindeviation=minimum absolute deviation of convolution to define a peak (default=5)
-     seedouble=if two peaks distance less than seedouble points, count them as a single peak (default=10)
-     convolution=the actual convolution vector (DO NOT TOUCH UNLESS YOU KNOW WHAT YOU ARE DOING)
-     blindwindow=nm after the contact point where we do not count peaks.
-    -->
-<convfilt minpeaks="5" mindeviation="5" seedouble="10" convolution="[6.0,-1.0,-1.0,-1.0,-1.0,-1.0,-1.0]" blindwindow="20"/>
-<!--convfilt minpeaks="5" mindeviation="5" seedouble="10" convolution="[11.0,-1.0,-1.0,-1.0,-1.0,-1.0,-1.0,-1.0,-1.0,-1.0,-1.0,-1.0]" blindwindow="100"/-->
-</config>
diff --git a/csvdriver.py b/csvdriver.py
deleted file mode 100644 (file)
index 4222255..0000000
+++ /dev/null
@@ -1,75 +0,0 @@
-#!/usr/bin/env python
-
-'''
-csvdriver.py
-
-Simple driver to read general comma-separated values in Hooke
-
-Columns are read this way:
-    
-X1 , Y1 , X2 , Y2 , X3 , Y3 ...
-
-If the number of columns is odd, the last column is ignored.
-
-(c)Massimo Sandal, 2008
-'''
-
-import libhookecurve as lhc
-import libhooke as lh
-import csv
-
-class csvdriverDriver(lhc.Driver):
-    
-        def __init__(self, filename):
-        
-            self.filedata = open(filename,'r')
-            self.data = list(self.filedata) 
-            self.filedata.close()
-        
-            self.filetype = 'generic'
-            self.experiment = ''
-            
-            self.filename=filename
-        
-        def is_me(self):
-            myfile=file(self.filename)
-            headerline=myfile.readlines()[0]
-            myfile.close()
-            
-            #using a custom header makes things much easier...
-            #(looking for raw CSV data is at strong risk of confusion)
-            if headerline[:-1]=='Hooke data':
-                return True
-            else:
-                return False
-        
-        def close_all(self):
-            self.filedata.close()
-        
-        def default_plots(self):
-            rrows=csv.reader(self.data)
-            rows=list(rrows) #transform the csv.reader iterator in a normal list
-            columns=lh.transposed2(rows[1:])
-            
-            main_plot=lhc.PlotObject()
-            main_plot.vectors=[]
-            
-            for index in range(0,len(columns),2):
-                main_plot.vectors.append([])
-                temp_x=columns[index]
-                temp_y=columns[index+1]
-                
-                #convert to float (the csv gives strings)
-                temp_x=[float(item) for item in temp_x]
-                temp_y=[float(item) for item in temp_y]
-                
-                main_plot.vectors[-1].append(temp_x)
-                main_plot.vectors[-1].append(temp_y)
-                
-            main_plot.units=['x','y']
-            main_plot.title=self.filename
-            main_plot.destination=0
-            
-            return [main_plot]
-            
-    
\ No newline at end of file
old mode 100755 (executable)
new mode 100644 (file)
similarity index 100%
rename from default.000
rename to data/default.000
diff --git a/drivers/__init__.py b/drivers/__init__.py
new file mode 100644 (file)
index 0000000..803f29c
--- /dev/null
@@ -0,0 +1 @@
+#!/usr/bin/env python\r
diff --git a/drivers/csvdriver.py b/drivers/csvdriver.py
new file mode 100644 (file)
index 0000000..0d385b4
--- /dev/null
@@ -0,0 +1,85 @@
+#!/usr/bin/env python
+
+'''
+csvdriver.py
+
+Simple driver to read general comma-separated values in Hooke
+
+Columns are read this way:
+
+X1 , Y1 , X2 , Y2 , X3 , Y3 ...
+
+If the number of columns is odd, the last column is ignored.
+
+Copyright 2008 by Massimo Sandal
+with modifications by Dr. Rolf Schmidt (Concordia University, Canada)
+
+This program is released under the GNU General Public License version 2.
+'''
+
+import csv
+import os.path
+
+import lib.curve
+import lib.driver
+import lib.libhooke
+import lib.plot
+
+class csvdriverDriver(lib.driver.Driver):
+
+    def __init__(self, filename):
+
+        self.filedata = open(filename,'r')
+        self.data = list(self.filedata)
+        self.filedata.close()
+
+        self.filetype = 'generic'
+        self.experiment = ''
+
+        self.filename=filename
+
+    def close_all(self):
+        self.filedata.close()
+
+    def default_plots(self):
+        rrows=csv.reader(self.data)
+        rows=list(rrows) #transform the csv.reader iterator into a normal list
+        columns=lib.libhooke.transposed2(rows[1:])
+
+        for index in range(0, len(columns), 2):
+            temp_x=columns[index]
+            temp_y=columns[index+1]
+            #convert to float (the csv gives strings)
+            temp_x=[float(item) for item in temp_x]
+            temp_y=[float(item) for item in temp_y]
+
+            curve = lib.curve.Curve()
+
+            curve.destination.row = index + 1
+            curve.label = 'curve ' + str(index)
+            curve.style = 'plot'
+            curve.units.x = 'x'
+            curve.units.y = 'y'
+            curve.x = temp_x
+            curve.y = temp_y
+
+            plot = lib.plot.Plot()
+            plot.title = os.path.basename(self.filename)
+            plot.curves.append(curve)
+
+        #TODO: is normalization helpful or detrimental here?
+        #plot.normalize()
+        return plot
+
+    def is_me(self):
+        myfile=file(self.filename)
+        headerline=myfile.readlines()[0]
+        myfile.close()
+
+        #using a custom header makes things much easier...
+        #(looking for raw CSV data is at strong risk of confusion)
+        if headerline[:-1]=='Hooke data':
+            return True
+        else:
+            return False
+
similarity index 56%
rename from hemingclamp.py
rename to drivers/hemingclamp.py
index e2f2e1c2ebaee147cf0500b020c3750be382a920..7b4af45bae48587bfab45ab7e5704e154c078ae1 100755 (executable)
@@ -1,62 +1,62 @@
 #!/usr/bin/env python
 
 '''
-libhemingclamp.py
+hemingclamp.py
 
 Library for interpreting Hemingway force spectroscopy files.
 
-Copyright (C) 2008 Massimo Sandal, Marco Brucale (University of Bologna, Italy) 
+Copyright 2008 by Massimo Sandal, Marco Brucale (University of Bologna, Italy)
+with modifications by Dr. Rolf Schmidt (Concordia University, Canada)
 
 This program is released under the GNU General Public License version 2.
 '''
+
 __version__='2007_02_15_devel'
 
 __changelog__='''
+2010_01_22: initial release for Hooke GUI
 2007_02_15: fixed time counter with my counter
-2007_02_07: Initial implementation
+2007_02_07: initial implementation
 '''
+
+import copy
+import os.path
 import string
-import libhookecurve as lhc 
+
+import lib.curve
+import lib.driver
+import lib.plot
 
 class DataChunk(list):
-    '''Dummy class to provide ext and ret methods to the data list.
+    #TODO: something similar is also used in jpk.py
+    #potential for OOP/inheritance?
+    '''
+    Dummy class to provide ext and ret methods to the data list.
     In this case ext and self can be equal.
     '''
-    
+
     def ext(self):
         return self
-        
+
     def ret(self):
         return self
 
-class hemingclampDriver(lhc.Driver):
-    
+class hemingclampDriver(lib.driver.Driver):
+
     def __init__(self, filename):
-        
+
         self.filedata = open(filename,'r')
         self.data = self.filedata.readlines()[6:]
         self.filedata.close()
-        
+
         self.filetype = 'hemingclamp'
         self.experiment = 'clamp'
-        
+
         self.filename=filename
-       
+
     def __del__(self):
-        self.filedata.close()   
-    
-    def is_me(self):
-        '''
-        we define our magic heuristic for HemingClamp files
-        '''
-        myfile=file(self.filename)
-        headerlines=myfile.readlines()[0:3]
-        myfile.close()
-        if headerlines[0][0:10]=='#Hemingway' and headerlines[1][0:19]=='#Experiment: FClamp':
-            return True
-        else:
-            return False
-        
+        self.filedata.close()
+
     def _getdata_all(self):
         time = []
         phase = []
@@ -65,7 +65,7 @@ class hemingclampDriver(lhc.Driver):
         imposed = []
         trim_indexes = []
         trim_counter = 0.0
-                        
+
         for i in self.data:
             temp = string.split(i)
             #time.append(float(temp[0])*(1.0e-3)) # This is managed differently now, since each data point = 1ms: see below
@@ -78,57 +78,98 @@ class hemingclampDriver(lhc.Driver):
             if phase[x] != trim_counter:
                 trim_indexes.append(x)
                 trim_counter = phase[x]
-       
+
         #we rebuild the time counter assuming 1 point = 1 millisecond
         c=0.0
         for z in zpiezo:
             time.append(c)
-            c+=(1.0e-3)            
-            
-        return time,phase,zpiezo,defl,imposed,trim_indexes
-        
-    def time(self):
-        return DataChunk(self._getdata_all()[0])
+            c+=(1.0e-3)
 
-    def phase(self):
-        return DataChunk(self._getdata_all()[1])
-    
-    def zpiezo(self):
-        return DataChunk(self._getdata_all()[2])
-     
-    def deflection(self):
-        return DataChunk(self._getdata_all()[3])
-
-    def imposed(self):
-        return DataChunk(self._getdata_all()[4])
+        return time,phase,zpiezo,defl,imposed,trim_indexes
 
-    def trimindexes(self):
-        return DataChunk(self._getdata_all()[5])
-    
     def close_all(self):
         '''
         Explicitly closes all files
         '''
         self.filedata.close()
-    
+
     def default_plots(self):
-        main_plot=lhc.PlotObject()
-        defl_plot=lhc.PlotObject()
-        
         time=self.time()
         phase=self.phase()
         zpiezo=self.zpiezo()
         deflection=self.deflection()
         imposed=self.imposed()
-                
-        main_plot.vectors=[[time,zpiezo],[time,phase]]
-        main_plot.units=['seconds','meters']
-        main_plot.destination=0
-        main_plot.title=self.filename
-        
-        defl_plot.vectors=[[time,deflection],[time,imposed]]
-        defl_plot.units=['seconds','Newtons']
-        defl_plot.destination=1
-        return [main_plot, defl_plot]
-    
\ No newline at end of file
+
+        #return [main_plot, defl_plot]
+        main_extension = lib.curve.Curve()
+        main_retraction = lib.curve.Curve()
+
+        #TODO: check 'title' below
+        main_extension.color = 'red'
+        main_extension.label = 'extension'
+        main_extension.style = 'plot'
+        main_extension.title = 'Force curve'
+        main_extension.units.x = 's'
+        main_extension.units.y = 'm'
+        main_extension.x = time
+        main_extension.y = zpiezo
+        main_retraction.color = 'blue'
+        main_retraction.label = 'retraction'
+        main_retraction.style = 'plot'
+        main_retraction.title = 'Force curve'
+        main_retraction.units.x = 's'
+        #TODO: what is the real unit for y?
+        main_retraction.units.y = 'degree'
+        main_retraction.x = time
+        main_retraction.y = phase
+
+        deflection_extension = copy.deepcopy(main_extension)
+        deflection_retraction = copy.deepcopy(main_retraction)
+        #TODO: check 'title' below
+        deflection_extension.destination.row = 2
+        deflection_extension.units.y = 'N'
+        deflection_extension.y = deflection
+        #TODO: what is the real unit for y?
+        deflection_retraction.destination.row = 2
+        deflection_retraction.units.y = 'N'
+        deflection_retraction.y = imposed
+
+        plot = lib.plot.Plot()
+        plot.title = os.path.basename(self.filename)
+        plot.curves.append(main_extension)
+        plot.curves.append(main_retraction)
+        plot.curves.append(deflection_extension)
+        plot.curves.append(deflection_retraction)
+
+        plot.normalize()
+        return plot
+
+    def deflection(self):
+        return DataChunk(self._getdata_all()[3])
+
+    def imposed(self):
+        return DataChunk(self._getdata_all()[4])
+
+    def is_me(self):
+        '''
+        we define our magic heuristic for HemingClamp files
+        '''
+        myfile=file(self.filename)
+        headerlines=myfile.readlines()[0:3]
+        myfile.close()
+        if headerlines[0][0:10]=='#Hemingway' and headerlines[1][0:19]=='#Experiment: FClamp':
+            return True
+        else:
+            return False
+
+    def phase(self):
+        return DataChunk(self._getdata_all()[1])
+
+    def time(self):
+        return DataChunk(self._getdata_all()[0])
+
+    def trimindexes(self):
+        return DataChunk(self._getdata_all()[5])
+
+    def zpiezo(self):
+        return DataChunk(self._getdata_all()[2])
similarity index 73%
rename from jpk.py
rename to drivers/jpk.py
index 4f643317891f685e6a42261079e01d7e25db04c5..90aa5c81c765756703c02617cde69588582be55d 100644 (file)
--- a/jpk.py
@@ -1,74 +1,74 @@
 #!/usr/bin/env python
 
-import string
-import libhookecurve as lhc 
+'''
+jpk.py
+
+Driver for jpk files.
+
+Copyright ??? by Massimo Sandal?
+with modifications by Dr. Rolf Schmidt (Concordia University, Canada)
+
+This program is released under the GNU General Public License version 2.
+'''
+
+import os.path
+
+import lib.curve
+import lib.driver
+import lib.plot
 
 class DataChunk(list):
     #Dummy class to provide ext and ret methods to the data list.
-    
+
     def ext(self):
         halflen=(len(self)/2)
         return self[0:halflen]
-        
+
     def ret(self):
         halflen=(len(self)/2)
         return self[halflen:]
 
-class jpkDriver(lhc.Driver):
+class jpkDriver(lib.driver.Driver):
 
     def __init__(self, filename):
         self.filename=filename #self.filename can always be useful, and should be defined
         self.filedata = open(filename,'r') #We open the file
         self.filelines=self.filedata.readlines()
-        self.filedata.close()        
-        '''These are two strings that can be used by Hooke commands/plugins to understand what they are looking at. They have no other
+        self.filedata.close()
+        '''
+        These are two strings that can be used by Hooke commands/plugins to understand what they are looking at. They have no other
         meaning. They have to be somehow defined however - commands often look for those variables.
-        
+
         self.filetype should contain the name of the exact filetype defined by the driver (so that filetype-specific commands can know
                       if they're dealing with the correct filetype)
         self.experiment should contain instead the type of data involved (for example, various drivers can be used for force-clamp experiments,
-                      but hooke commands could like to know if we're looking at force clamp data, regardless of their origin, and not other 
+                      but hooke commands could like to know if we're looking at force clamp data, regardless of their origin, and not other
                       kinds of data)
-        
+
         Of course, all other variables you like can be defined in the class.
         '''
         self.filetype = 'jpk'
         self.experiment = 'smfs'
-                  
-        
+
+
 
     def __del__(self):
-        self.filedata.close()   
-    
-    def is_me(self):
-        '''
-        we define our magic heuristic for jpk files
-        '''
-        myfile=file(self.filename)
-        headerlines=myfile.readlines()[0:3]
-        myfile.close()
-        if headerlines[0][0:11]=='# xPosition' and headerlines[1][0:11]=='# yPosition':
-            return True
-        else:
-            return False
-        
-    def close_all(self):
         self.filedata.close()
-        
+
     def _read_data_segment(self):
         #routine that actually reads the data
-        
+
         height_ms=[]
         height_m=[]
         height=[]
         v_deflection=[]
         h_deflection=[]
-        
+
         self.springconstant=0 #if we don't meet any spring constant, use deflection...
-        
+
         for line in self.filelines:
             #we meet the segment defining the order of data columns
-            
+
             if line[0:9]=='# columns':
                 splitline=line.split()[2:]
                 height_ms_index=splitline.index('smoothedStrainGaugeHeight')
@@ -76,10 +76,10 @@ class jpkDriver(lhc.Driver):
                 height_index=splitline.index('height')
                 v_deflection_index=splitline.index('vDeflection')
                 #h_deflection=splitline.index('hDeflection')
-            
+
             if line[0:16]=='# springConstant':
                 self.springconstant=float(line.split()[2])
-    
+
             if line[0] != '#' and len(line.split())>1:
                 dataline=line.split()
                 height_ms.append(float(dataline[height_ms_index]))
@@ -87,31 +87,27 @@ class jpkDriver(lhc.Driver):
                 height.append(float(dataline[height_index]))
                 v_deflection.append(float(dataline[v_deflection_index]))
                 #h_deflection.append(float(dataline[h_deflection_index]))
-        
+
         if self.springconstant != 0:
             force=[item*self.springconstant for item in v_deflection]
         else: #we have measured no spring constant :(
             force=v_deflection
-            
+
         height_ms=DataChunk([item*-1 for item in height_ms])
         height_m=DataChunk([item*-1 for item in height_m])
         height=DataChunk([item*-1 for item in height])
         deflection=DataChunk(v_deflection)
         force=DataChunk(force)
-        
+
         return height_ms,height_m,height,deflection,force
-        
-    def deflection(self):
-        height_ms,height_m,height,deflection,force=self._read_data_segment()
-        deflection_ext=deflection.ext()
-        deflection_ret=deflection.ret()
-        deflection_ret.reverse()
-        return deflection_ext,deflection_ret
-        
+
+    def close_all(self):
+        self.filedata.close()
+
     def default_plots(self):
-        
+
         height_ms,height_m,height,deflection,force=self._read_data_segment()
-        
+
         height_ms_ext=height_ms.ext()
         height_ms_ret=height_ms.ret()
         force_ext=force.ext()
@@ -119,21 +115,56 @@ class jpkDriver(lhc.Driver):
         #reverse the return data, to make it coherent with hooke standard
         height_ms_ret.reverse()
         force_ret.reverse()
-        
-        main_plot=lhc.PlotObject()  
-        main_plot.add_set(height_ms_ext,force_ext)
-        main_plot.add_set(height_ms_ret,force_ret)
-        
-        
-        
+
         if self.springconstant != 0:
-            main_plot.units=['meters','force']
+            #TODO: force is not really a unit
+            y_unit = 'force'
         else:
-            main_plot.units=['meters','meters']
-        
-        main_plot.normalize_vectors()
-        
-        main_plot.destination=0
-        main_plot.title=self.filename
-        
-        return [main_plot]
\ No newline at end of file
+            y_unit = 'm'
+
+        extension = lib.curve.Curve()
+        retraction = lib.curve.Curve()
+
+        extension.color = 'red'
+        extension.label = 'extension'
+        extension.style = 'plot'
+        extension.title = 'Force curve'
+        extension.units.x = 'm'
+        extension.units.y = y_unit
+        extension.x = height_ms_ext
+        extension.y = force_ext
+        retraction.color = 'blue'
+        retraction.label = 'retraction'
+        retraction.style = 'plot'
+        retraction.title = 'Force curve'
+        retraction.units.x = 'm'
+        retraction.units.y = y_unit
+        retraction.x = height_ms_ret
+        retraction.y = force_ret
+
+        plot = lib.plot.Plot()
+        plot.title = os.path.basename(self.filename)
+        plot.curves.append(extension)
+        plot.curves.append(retraction)
+
+        plot.normalize()
+        return plot
+
+    def deflection(self):
+        height_ms,height_m,height,deflection,force=self._read_data_segment()
+        deflection_ext=deflection.ext()
+        deflection_ret=deflection.ret()
+        deflection_ret.reverse()
+        return deflection_ext,deflection_ret
+
+    def is_me(self):
+        '''
+        we define our magic heuristic for jpk files
+        '''
+        myfile=file(self.filename)
+        headerlines=myfile.readlines()[0:3]
+        myfile.close()
+        if headerlines[0][0:11]=='# xPosition' and headerlines[1][0:11]=='# yPosition':
+            return True
+        else:
+            return False
similarity index 54%
rename from mcs.py
rename to drivers/mcs.py
index 711e8c359625e646ca8225b8476634695810fc35..df12df640b6deb09423ef89d3ab514eb566f9265 100644 (file)
--- a/mcs.py
@@ -3,17 +3,23 @@
 '''
 mcs.py
 
-driver for mcs fluorescence files
+Driver for mcs fluorescence files.
 
-Massimo Sandal, Allen Chen (c) 2009
+Copyright 2009 by Massimo Sandal, Allen Chen
+with modifications by Dr. Rolf Schmidt (Concordia University, Canada)
+
+This program is released under the GNU General Public License version 2.
 '''
 
-import libhookecurve as lhc
-import libhooke as lh
+import os.path
+
+import lib.curve
+import lib.driver
+import lib.plot
 import struct
 
-class mcsDriver(lhc.Driver):
-    
+class mcsDriver(lib.driver.Driver):
+
     def __init__(self, filename):
         '''
         Open the RED (A) ones; the BLUE (D) mirror ones will be automatically opened
@@ -25,54 +31,75 @@ class mcsDriver(lhc.Driver):
             oth[-8]='d'
             othername=''.join(oth)
         self.filename=filename
-        self.othername=othername    
-        
+        self.othername=othername
+
         #print self.filename, self.othername
-        
+
         self.filedata=open(filename,'rb')
         self.reddata=self.filedata.read()
         self.filedata.close()
-        
+
         self.filebluedata=open(othername,'rb') #open also the blue ones
         self.bluedata=self.filebluedata.read()
         self.filebluedata.close()
-        
+
         self.filetype = 'mcs'
         self.experiment = 'smfluo'
-        
-    def is_me(self):
-        if self.filename[-3:].lower()=='mcs':
-            return True
-        else:
-            return False
-        
+
     def close_all(self):
         self.filedata.close()
         self.filebluedata.close()
-        
-        
+
     def default_plots(self):
+        #TODO: rename blue and red data to something more appropriate if possible
         red_data=self.read_file(self.reddata)
         blue_data=self.read_file(self.bluedata)
         blue_data=[-1*float(item) for item in blue_data] #visualize blue as "mirror" of red
-        
-        main_plot=lhc.PlotObject()
-        main_plot.add_set(range(len(red_data)),red_data)
-        main_plot.add_set(range(len(blue_data)),blue_data)
-        main_plot.normalize_vectors()
-        main_plot.units=['time','count']  #FIXME: if there's an header saying something about the time count, should be used
-        main_plot.destination=0
-        main_plot.title=self.filename
-        main_plot.colors=['red','blue']
-        
-        return [main_plot]
-    
-    def read_file(self, raw_data):    
+
+        extension = lib.curve.Curve()
+        retraction = lib.curve.Curve()
+
+        extension.color = 'red'
+        extension.label = 'extension'
+        extension.style = 'plot'
+        extension.title = 'Force curve'
+        #FIXME: if there's an header saying something about the time count, should be used
+        #TODO: time is not really a unit
+        extension.units.x = 'time'
+        extension.units.y = 'count'
+        extension.x = range(len(red_data))
+        extension.y = red_data
+        retraction.color = 'blue'
+        retraction.label = 'retraction'
+        retraction.style = 'plot'
+        retraction.title = 'Force curve'
+        #FIXME: if there's an header saying something about the time count, should be used
+        #TODO: time is not really a unit
+        retraction.units.x = 'time'
+        retraction.units.y = 'count'
+        retraction.x = range(len(blue_data))
+        retraction.y = blue_data
+
+        plot = lib.plot.Plot()
+        plot.title = os.path.basename(self.filename)
+        plot.curves.append(extension)
+        plot.curves.append(retraction)
+
+        plot.normalize()
+        return plot
+
+    def is_me(self):
+        if self.filename[-3:].lower()=='mcs':
+            return True
+        else:
+            return False
+
+    def read_file(self, raw_data):
         real_data=[]
         intervalsperfile=struct.unpack('h', raw_data[10:12])[0] #read in number of intervals in this file
                                                                 #this data is contained in bit offset 10-12 in mcs file
         #see http://docs.python.org/library/struct.html#module-struct for additional explanation
-        
+
         numbytes=len(raw_data) #data is stored in 4-byte chunks, starting with pos 256
         for j in range(0,intervalsperfile): #read in all intervals in file
             temp=raw_data[256+j*4:256+j*4+4]    #data starts at byte offset 256
diff --git a/drivers/mfp1dexport.py b/drivers/mfp1dexport.py
new file mode 100644 (file)
index 0000000..0214866
--- /dev/null
@@ -0,0 +1,127 @@
+#!/usr/bin/env python
+
+'''
+mfp1dexport.py
+
+Driver for text-exported MFP 1D files.
+
+Copyright 2009 by Massimo Sandal
+with modifications by Dr. Rolf Schmidt (Concordia University, Canada)
+
+This program is released under the GNU General Public License version 2.
+'''
+
+import os.path
+
+import lib.driver
+import lib.curve
+import lib.plot
+
+__version__='0.0.0.20090923'
+
+class mfp1dexportDriver(lib.driver.Driver):
+
+    def __init__(self, filename):
+        '''
+        This is a driver to import Asylum Research MFP 1D data.
+        Status: experimental
+        '''
+        self.filename = filename
+        self.filedata = open(filename,'rU')
+        self.lines = list(self.filedata.readlines())
+        self.filedata.close()
+
+        self.filetype = 'mfp1dexport'
+        self.experiment = 'smfs'
+
+    def _read_columns(self):
+
+        self.raw_columns=self.lines[39:]
+
+        kline=None
+        for line in self.lines:
+            if line[:7]=='SpringC':
+                kline=line
+                break
+
+        kline=kline.split(':')
+
+        #self.k=float(self.raw_header[23][8:])
+        self.k=float(kline[1])
+
+        #find retract velocity to calculate loading rate
+        retract_velocity = None
+        for line in self.lines:
+            if line.startswith('RetractVelocity:'):
+                retract_velocity = line.split(':')
+                self.retract_velocity = float(retract_velocity[1])
+                break
+
+        xext=[]
+        xret=[]
+        yext=[]
+        yret=[]
+        for line in self.raw_columns:
+            spline=line.split()
+            xext.append(float(spline[0]))
+            yext.append(float(spline[1]))
+            xret.append(float(spline[2]))
+            yret.append(float(spline[3]))
+
+        return [[xext,yext],[xret,yret]]
+
+    def close_all(self):
+        self.filedata.close()
+
+    def is_me(self):
+        try:
+            self.raw_header = self.lines[0:38]
+        except:
+            #Not enough lines for a header; not a good file
+            return False
+
+        #FIXME: We want a more reasonable header recognition
+        if self.raw_header[0].startswith('Wave'):
+            return True
+        else:
+            return False
+
+    def default_plots(self):
+        '''
+        loads the curve data
+        '''
+        defl_ext, defl_ret = self.deflection()
+        yextforce = [i * self.k for i in defl_ext]
+        yretforce = [i * self.k for i in defl_ret]
+
+        extension = lib.curve.Curve()
+        retraction = lib.curve.Curve()
+
+        extension.color = 'red'
+        extension.label = 'extension'
+        extension.style = 'plot'
+        extension.title = 'Force curve'
+        extension.units.x = 'm'
+        extension.units.y = 'N'
+        extension.x = self.data[0][0]
+        extension.y = yextforce
+        retraction.color = 'blue'
+        retraction.label = 'retraction'
+        retraction.style = 'plot'
+        retraction.title = 'Force curve'
+        retraction.units.x = 'm'
+        retraction.units.y = 'N'
+        retraction.x = self.data[1][0]
+        retraction.y = yretforce
+
+        plot = lib.plot.Plot()
+        plot.title = os.path.basename(self.filename)
+        plot.curves.append(extension)
+        plot.curves.append(retraction)
+
+        plot.normalize()
+        return plot
+
+    def deflection(self):
+        self.data = self._read_columns()
+        return self.data[0][1], self.data[1][1]
similarity index 80%
rename from picoforce.py
rename to drivers/picoforce.py
index d331767e81eb79940c77458820ba19ad572ad137..5fe17baa6c8187d213a7b3d072a659066802a176 100755 (executable)
 #!/usr/bin/env python
 
 '''
-libpicoforce.py
+picoforce.py
 
 Library for interpreting Picoforce force spectroscopy files.
 
-Copyright (C) 2006 Massimo Sandal (University of Bologna, Italy).
+Copyright 2006 by Massimo Sandal (University of Bologna, Italy)
+with modifications by Dr. Rolf Schmidt (Concordia University, Canada)
 
 This program is released under the GNU General Public License version 2.
 '''
 
-import re, struct
+import os
+import re
+import struct
 from scipy import arange
 
-import libhookecurve as lhc
+import lib.libhooke as lh
+import lib.curve
+import lib.driver
+import lib.plot
 
-__version__='0.0.0.20080404'
+__version__='0.0.0.20090923'
 
 
 class DataChunk(list):
     #Dummy class to provide ext and ret methods to the data list.
-    
+
     def ext(self):
         halflen=(len(self)/2)
         return self[0:halflen]
-        
+
     def ret(self):
         halflen=(len(self)/2)
         return self[halflen:]
 
-class picoforceDriver(lhc.Driver):
+class picoforceDriver(lib.driver.Driver):
 
     #Construction and other special methods
-    
-    def __init__(self,filename):
+
+    def __init__(self, filename):
         '''
         constructor method
         '''
-        
-        self.textfile=file(filename)
-        self.binfile=file(filename,'rb')
-        
+
+        filename = lh.get_file_path(filename)
+        self.filename = filename
+
         #The 0,1,2 data chunks are:
         #0: D (vs T)
         #1: Z (vs T)
         #2: D (vs Z)
-        
-        
-        self.filepath=filename
-        self.debug=False
-        
-        self.filetype='picoforce'
-        self.experiment='smfs'
-    
-    
+
+        self.retract_velocity = None
+
+        self.debug = False
+
+        self.filetype = 'picoforce'
+        self.experiment = 'smfs'
+
     #Hidden methods. These are meant to be used only by API functions. If needed, however,
     #they can be called just like API methods.
-                    
+
     def _get_samples_line(self):
         '''
         Gets the samples per line parameters in the file, to understand trigger behaviour.
         '''
-        self.textfile.seek(0)
-        
+        textfile = file(self.filename)
+
         samps_expr=re.compile(".*Samps")
-        
+
         samps_values=[]
-        for line in self.textfile.readlines():
+        for line in textfile.readlines():
             if samps_expr.match(line):
                 try:
                     samps=int(line.split()[2]) #the third word splitted is the offset (in bytes)
                     samps_values.append(samps)
                 except:
                     pass
-                
+
                 #We raise a flag for the fact we meet an offset, otherwise we would take spurious data length arguments.
-                        
+
+        textfile.close()
+
         return int(samps_values[0])
-                    
+
     def _get_chunk_coordinates(self):
         '''
         This method gets the coordinates (offset and length) of a data chunk in our
         Picoforce file.
-        
-        It returns a list containing two tuples: 
-        the first element of each tuple is the data_offset, the second is the corresponding 
+
+        It returns a list containing two tuples:
+        the first element of each tuple is the data_offset, the second is the corresponding
         data size.
-        
-        In near future probably each chunk will get its own data structure, with 
+
+        In near future probably each chunk will get its own data structure, with
         offset, size, type, etc.
         '''
-        self.textfile.seek(0)
-        
+        textfile = file(self.filename)
+
         offset_expr=re.compile(".*Data offset")
         length_expr=re.compile(".*Data length")
 
@@ -99,48 +106,53 @@ class picoforceDriver(lhc.Driver):
         data_sizes=[]
         flag_offset=0
 
-        for line in self.textfile.readlines():
+        for line in textfile.readlines():
 
             if offset_expr.match(line):
                 offset=int(line.split()[2]) #the third word splitted is the offset (in bytes)
                 data_offsets.append(offset)
                 #We raise a flag for the fact we meet an offset, otherwise we would take spurious data length arguments.
-                flag_offset=1 
-    
+                flag_offset=1
+
             #same for the data length
-            if length_expr.match(line) and flag_offset: 
+            if length_expr.match(line) and flag_offset:
                 size=int(line.split()[2])
                 data_sizes.append(size)
                 #Put down the offset flag until the next offset is met.
                 flag_offset=0
 
+        textfile.close()
+
         return zip(data_offsets,data_sizes)
-        
-    def _get_data_chunk(self,whichchunk):
+
+    def _get_data_chunk(self, whichchunk):
         '''
         reads a data chunk and converts it in 16bit signed int.
         '''
+        binfile = file(self.filename,'rb')
+
         offset,size=self._get_chunk_coordinates()[whichchunk]
-        
-        
-        self.binfile.seek(offset)
-        raw_chunk=self.binfile.read(size)
-        
+
+        binfile.seek(offset)
+        raw_chunk = binfile.read(size)
+
         my_chunk=[]
         for data_position in range(0,len(raw_chunk),2):
             data_unit_bytes=raw_chunk[data_position:data_position+2]
             #The unpack function converts 2-bytes in a signed int ('h').
             #we use output[0] because unpack returns a 1-value tuple, and we want the number only
             data_unit=struct.unpack('h',data_unit_bytes)[0]
-            my_chunk.append(data_unit)                             
-        
+            my_chunk.append(data_unit)
+
+        binfile.close()
+
         return DataChunk(my_chunk)
-             
+
     def _get_Zscan_info(self,index):
         '''
         gets the Z scan informations needed to interpret the data chunk.
         These info come from the general section, BEFORE individual chunk headers.
-        
+
         By itself, the function will parse for three parameters.
         (index) that tells the function what to return when called by
         exposed API methods.
@@ -148,21 +160,21 @@ class picoforceDriver(lhc.Driver):
         index=1 : returns Zscan_V_start
         index=2 : returns Zscan_V_size
         '''
-        self.textfile.seek(0)
-        
+        textfile = file(self.filename)
+
         ciaoforcelist_expr=re.compile(".*Ciao force")
         zscanstart_expr=re.compile(".*@Z scan start")
         zscansize_expr=re.compile(".*@Z scan size")
-                
+
         ciaoforce_flag=0
-        theline=0
-        for line in self.textfile.readlines():
+#        theline=0
+        for line in textfile.readlines():
             if ciaoforcelist_expr.match(line):
                 ciaoforce_flag=1 #raise a flag: zscanstart and zscansize params to read are later
+
             if ciaoforce_flag and zscanstart_expr.match(line):
                 raw_Zscanstart_line=line.split()
-            
+
             if ciaoforce_flag and zscansize_expr.match(line):
                 raw_Zscansize_line=line.split()
 
@@ -171,36 +183,37 @@ class picoforceDriver(lhc.Driver):
         for itemscanstart,itemscansize in zip(raw_Zscanstart_line,raw_Zscansize_line):
             Zscanstart_line.append(itemscanstart.strip('[]()'))
             Zscansize_line.append(itemscansize.strip('[]()'))
-        
+
         Zscan_V_LSB=float(Zscanstart_line[6])
         Zscan_V_start=float(Zscanstart_line[8])
         Zscan_V_size=float(Zscansize_line[8])
-        
+
+        textfile.close()
+
         return (Zscan_V_LSB,Zscan_V_start,Zscan_V_size)[index]
-    
+
     def _get_Z_magnify_scale(self,whichchunk):
         '''
         gets Z scale and Z magnify
         Here we get Z scale/magnify from the 'whichchunk' only.
         whichchunk=1,2,3
-        TODO: make it coherent with data_chunks syntaxis (0,1,2)
-        
+        TODO: make it coherent with data_chunks syntax (0,1,2)
+
         In future, should we divide the *file* itself into chunk descriptions and gain
         true chunk data structures?
         '''
-        self.textfile.seek(0)
-        
+        textfile = file(self.filename)
+
         z_scale_expr=re.compile(".*@4:Z scale")
         z_magnify_expr=re.compile(".*@Z magnify")
-        
+
         ramp_size_expr=re.compile(".*@4:Ramp size")
         ramp_offset_expr=re.compile(".*@4:Ramp offset")
-                
+
         occurrences=0
         found_right=0
-        
-        
-        for line in self.textfile.readlines():
+
+        for line in textfile.readlines():
             if z_magnify_expr.match(line):
                 occurrences+=1
                 if occurrences==whichchunk:
@@ -208,177 +221,189 @@ class picoforceDriver(lhc.Driver):
                     raw_z_magnify_expression=line.split()
                 else:
                     found_right=0
-                    
+
             if found_right and z_scale_expr.match(line):
                 raw_z_scale_expression=line.split()
             if found_right and ramp_size_expr.match(line):
                 raw_ramp_size_expression=line.split()
             if found_right and ramp_offset_expr.match(line):
                 raw_ramp_offset_expression=line.split()
-                
+
+        textfile.close()
+
         return float(raw_z_magnify_expression[5]),float(raw_z_scale_expression[7]), float(raw_ramp_size_expression[7]), float(raw_ramp_offset_expression[7]), float(raw_z_scale_expression[5][1:])
-       
-    
+
+
     #Exposed APIs.
-    #These are the methods that are meant to be called from external apps.          
-    
+    #These are the methods that are meant to be called from external apps.
+
     def LSB_to_volt(self,chunknum,voltrange=20):
         '''
         Converts the LSB data of a given chunk (chunknum=0,1,2) in volts.
         First step to get the deflection and the force.
-        
+
         SYNTAXIS:
         item.LSB_to_volt(chunknum, [voltrange])
-                        
+
         The voltrange is by default set to 20 V.
         '''
         return DataChunk([((float(lsb)/65535)*voltrange) for lsb in self.data_chunks[chunknum]])
-        
+
     def LSB_to_deflection(self,chunknum,deflsensitivity=None,voltrange=20):
         '''
         Converts the LSB data in deflection (meters).
-        
+
         SYNTAXIS:
         item.LSB_to_deflection(chunknum, [deflection sensitivity], [voltrange])
-        
+
         chunknum is the chunk you want to parse (0,1,2)
-        
-        The deflection sensitivity by default is the one parsed from the file. 
+
+        The deflection sensitivity by default is the one parsed from the file.
         The voltrange is by default set to 20 V.
         '''
         if deflsensitivity is None:
             deflsensitivity=self.get_deflection_sensitivity()
-            
-        lsbvolt=self.LSB_to_volt(chunknum)     
+
+        lsbvolt=self.LSB_to_volt(chunknum)
         return DataChunk([volt*deflsensitivity for volt in lsbvolt])
-        
+
     def deflection(self):
         '''
         Get the actual force curve deflection.
         '''
         deflchunk= self.LSB_to_deflection(2)
         return deflchunk.ext(),deflchunk.ret()
-        
+
     def LSB_to_force(self,chunknum=2,Kspring=None,voltrange=20):
         '''
         Converts the LSB data (of deflection) in force (newtons).
-        
+
         SYNTAXIS:
         item.LSB_to_force([chunknum], [spring constant], [voltrange])
-        
+
         chunknum is the chunk you want to parse (0,1,2). The chunk used is by default 2.
         The spring constant by default is the one parsed from the file.
         The voltrange is by default set to 20 V.
         '''
         if Kspring is None:
             Kspring=self.get_spring_constant()
-            
-        lsbdefl=self.LSB_to_deflection(chunknum)        
+
+        lsbdefl=self.LSB_to_deflection(chunknum)
         return DataChunk([(meter*Kspring) for meter in lsbdefl])
-        
+
     def get_Zscan_V_start(self):
         return self._get_Zscan_info(1)
-        
+
     def get_Zscan_V_size(self):
         return self._get_Zscan_info(2)
-        
+
     def get_Z_scan_sensitivity(self):
         '''
         gets Z sensitivity
         '''
-        self.textfile.seek(0)
-        
+        textfile = file(self.filename)
+
         z_sensitivity_expr=re.compile(".*@Sens. Zsens")
-        
-        for line in self.textfile.readlines():
+
+        for line in textfile.readlines():
             if z_sensitivity_expr.match(line):
                 z_sensitivity=float(line.split()[3])
+
+        textfile.close()
+
         #return it in SI units (that is: m/V, not nm/V)
         return z_sensitivity*(10**(-9))
-          
+
     def get_Z_magnify(self,whichchunk):
         '''
         Gets the Z magnify factor. Normally it is 1, unknown exact use as of 2006-01-13
         '''
         return self._get_Z_magnify_scale(whichchunk)[0]
-    
+
     def get_Z_scale(self,whichchunk):
         '''
         Gets the Z scale.
         '''
         return self._get_Z_magnify_scale(whichchunk)[1]
-    
+
     def get_ramp_size(self,whichchunk):
         '''
         Gets the -user defined- ramp size
         '''
         return self._get_Z_magnify_scale(whichchunk)[2]
-        
+
     def get_ramp_offset(self,whichchunk):
         '''
         Gets the ramp offset
         '''
         return self._get_Z_magnify_scale(whichchunk)[3]
-        
+
     def get_Z_scale_LSB(self,whichchunk):
         '''
         Gets the LSB-to-volt conversion factor of the Z data.
         (so called hard-scale in the Nanoscope documentation)
-        
+
         '''
         return self._get_Z_magnify_scale(whichchunk)[4]
-                
+
     def get_deflection_sensitivity(self):
         '''
         gets deflection sensitivity
-        '''    
-        self.textfile.seek(0)
-        
+        '''
+        textfile = file(self.filename)
+
         def_sensitivity_expr=re.compile(".*@Sens. DeflSens")
-        
-        for line in self.textfile.readlines():
+
+        for line in textfile.readlines():
             if def_sensitivity_expr.match(line):
                 def_sensitivity=float(line.split()[3])
                 break
+
+        textfile.close()
+
         #return it in SI units (that is: m/V, not nm/V)
         return def_sensitivity*(10**(-9))
-        
+
     def get_spring_constant(self):
         '''
         gets spring constant.
         We actually find *three* spring constant values, one for each data chunk (F/t, Z/t, F/z).
         They are normally all equal, but we retain all three for future...
         '''
-        self.textfile.seek(0)
-        
+        textfile = file(self.filename)
+
         springconstant_expr=re.compile(".*Spring Constant")
-        
+
         constants=[]
-        
-        for line in self.textfile.readlines():
+
+        for line in textfile.readlines():
             if springconstant_expr.match(line):
                 constants.append(float(line.split()[2]))
-        
+
+        textfile.close()
+
         return constants[0]
-    
+
     def get_Zsensorsens(self):
         '''
         gets Zsensorsens for Z data.
-        
+
         This is the sensitivity needed to convert the LSB data in nanometers for the Z-vs-T data chunk.
-        '''        
-        self.textfile.seek(0)
-        
+        '''
+        textfile = file(self.filename)
+
         zsensorsens_expr=re.compile(".*Sens. ZSensorSens")
-        
-        for line in self.textfile.readlines():
+
+        for line in textfile.readlines():
             if zsensorsens_expr.match(line):
                 zsensorsens_raw_expression=line.split()
                 #we must take only first occurrence, so we exit from the cycle immediately
                 break
-        
+
+        textfile.close()
+
         return (float(zsensorsens_raw_expression[3]))*(10**(-9))
-        
+
     def Z_data(self):
         '''
         returns converted ext and ret Z curves.
@@ -390,18 +415,18 @@ class picoforceDriver(lhc.Driver):
         #rampsize_zt=self.get_ramp_size(2)
         #rampoffset_zt=self.get_ramp_offset(2)
         zsensorsens=self.get_Zsensorsens()
-        
+
         '''
         The magic formula that converts the Z data is:
-        
+
         meters = LSB * V_lsb_conversion_factor * ZSensorSens
         '''
-        
+
         #z_curves=[item*Zlsb_zt*zsensorsens for item in self.data_chunks[1].pair['ext']],[item*Zlsb_zt*zsensorsens for item in self.data_chunks[1].pair['ret']]
-        z_curves=[item*Zlsb_zt*zsensorsens for item in self.data_chunks[1].ext()],[item*Zlsb_zt*zsensorsens for item in self.data_chunks[1].ret()]                
+        z_curves=[item*Zlsb_zt*zsensorsens for item in self.data_chunks[1].ext()],[item*Zlsb_zt*zsensorsens for item in self.data_chunks[1].ret()]
         z_curves=[DataChunk(item) for item in z_curves]
         return z_curves
-    
+
     def Z_extremes(self):
         '''
         returns the extremes of the Z values
@@ -410,9 +435,9 @@ class picoforceDriver(lhc.Driver):
         z_extremes={}
         z_extremes['ext']=zcurves[0][0],zcurves[0][-1]
         z_extremes['ret']=zcurves[1][0],zcurves[1][-1]
-        
+
         return z_extremes
-        
+
     def Z_step(self):
         '''
         returns the calculated step between the Z values
@@ -421,10 +446,10 @@ class picoforceDriver(lhc.Driver):
         zpoints={}
 
         z_extremes=self.Z_extremes()
-        
+
         zrange['ext']=abs(z_extremes['ext'][0]-z_extremes['ext'][1])
         zrange['ret']=abs(z_extremes['ret'][0]-z_extremes['ret'][1])
-        
+
         #We must take 1 from the calculated zpoints, or when I use the arange function gives me a point more
         #with the step. That is, if I have 1000 points, and I use arange(start,stop,step), I have 1001 points...
         #For cleanness, solution should really be when using arange, but oh well...
@@ -432,17 +457,17 @@ class picoforceDriver(lhc.Driver):
         zpoints['ret']=len(self.Z_data()[1])-1
         #this syntax must become coherent!!
         return (zrange['ext']/zpoints['ext']),(zrange['ret']/zpoints['ret'])
-        
+
     def Z_domains(self):
         '''
         returns the Z domains on which to plot the force data.
-        
+
         The Z domains are returned as a single long DataChunk() extended list. The extension and retraction part
-        can be extracted using ext() and ret() methods.       
-        '''   
+        can be extracted using ext() and ret() methods.
+        '''
         x1step=self.Z_step()[0]
-        x2step=self.Z_step()[1]           
-        
+        x2step=self.Z_step()[1]
+
         try:
             xext=arange(self.Z_extremes()['ext'][0],self.Z_extremes()['ext'][1],-x1step)
             xret=arange(self.Z_extremes()['ret'][0],self.Z_extremes()['ret'][1],-x2step)
@@ -450,7 +475,7 @@ class picoforceDriver(lhc.Driver):
             xext=arange(0,1)
             xret=arange(0,1)
             print 'picoforce.py: Warning. xext, xret domains cannot be extracted.'
-                
+
         if not (len(xext)==len(xret)):
             if self.debug:
                 #print warning
@@ -460,36 +485,36 @@ class picoforceDriver(lhc.Driver):
                 print "You cannot trust the resulting curve."
                 print "Until a solution is found, I substitute the ext domain with the ret domain. Sorry."
             xext=xret
-        
+
         return DataChunk(xext.tolist()+xret.tolist())
-        
+
     def Z_scan_size(self):
         return self.get_Zscan_V_size()*self.get_Z_scan_sensitivity()
-        
+
     def Z_start(self):
         return self.get_Zscan_V_start()*self.get_Z_scan_sensitivity()
-    
+
     def ramp_size(self,whichchunk):
         '''
         to be implemented if needed
         '''
         raise "Not implemented yet."
-        
-    
+
+
     def ramp_offset(self,whichchunk):
         '''
         to be implemented if needed
         '''
         raise "Not implemented yet."
-    
+
     def detriggerize(self, forcext):
         '''
         Cuts away the trigger-induced s**t on the extension curve.
         DEPRECATED
         cutindex=2
         startvalue=forcext[0]
-        
-        for index in range(len(forcext)-1,2,-2):  
+
+        for index in range(len(forcext)-1,2,-2):
            if forcext[index]>startvalue:
                 cutindex=index
            else:
@@ -498,48 +523,61 @@ class picoforceDriver(lhc.Driver):
         return cutindex
         '''
         return 0
-        
+
     def is_me(self):
         '''
         self-identification of file type magic
         '''
-        curve_file=file(self.filepath)
+        curve_file=file(self.filename)
         header=curve_file.read(30)
         curve_file.close()
-        
+
         if header[2:17] == 'Force file list': #header of a picoforce file
             self.data_chunks=[self._get_data_chunk(num) for num in [0,1,2]]
             return True
         else:
             return False
-    
+
     def close_all(self):
         '''
         Explicitly closes all files
         '''
-        self.textfile.close()
-        self.binfile.close()
-    
+        pass
+
     def default_plots(self):
         '''
-        creates the default PlotObject
+        loads the curve data
         '''
-        
-                
-        force=self.LSB_to_force()
-        zdomain=self.Z_domains()
-        
-        samples=self._get_samples_line()
+        force = self.LSB_to_force()
+        zdomain = self.Z_domains()
+
+        samples = self._get_samples_line()
         #cutindex=0
         #cutindex=self.detriggerize(force.ext())
-        
-        main_plot=lhc.PlotObject()
-        
-        main_plot.vectors=[[zdomain.ext()[0:samples], force.ext()[0:samples]],[zdomain.ret()[0:samples], force.ret()[0:samples]]]
-        main_plot.normalize_vectors()
-        main_plot.units=['meters','newton']
-        main_plot.destination=0
-        main_plot.title=self.filepath
-        
-        
-        return [main_plot]
+        extension = lib.curve.Curve()
+        retraction = lib.curve.Curve()
+
+        extension.color = 'red'
+        extension.label = 'extension'
+        extension.style = 'plot'
+        extension.title = 'Force curve'
+        extension.units.x = 'm'
+        extension.units.y = 'N'
+        extension.x = zdomain.ext()[0:samples]
+        extension.y = force.ext()[0:samples]
+        retraction.color = 'blue'
+        retraction.label = 'retraction'
+        retraction.style = 'plot'
+        retraction.title = 'Force curve'
+        retraction.units.x = 'm'
+        retraction.units.y = 'N'
+        retraction.x = zdomain.ret()[0:samples]
+        retraction.y = force.ret()[0:samples]
+
+        plot = lib.plot.Plot()
+        plot.title = os.path.basename(self.filename)
+        plot.curves.append(extension)
+        plot.curves.append(retraction)
+
+        plot.normalize()
+        return plot
diff --git a/fit.py b/fit.py
deleted file mode 100755 (executable)
index 10d0331..0000000
--- a/fit.py
+++ /dev/null
@@ -1,455 +0,0 @@
-#!/usr/bin/env python
-
-'''
-FIT
-
-Force spectroscopy curves basic fitting plugin.
-Licensed under the GNU GPL version 2
-
-Non-standard Dependencies:
-procplots.py (plot processing plugin)
-'''
-from libhooke import WX_GOOD, ClickedPoint
-import wxversion
-wxversion.select(WX_GOOD)
-#from wx import PostEvent
-#from wx.lib.newevent import NewEvent
-import scipy
-import scipy.odr
-import numpy as np
-import copy
-import Queue
-
-global measure_wlc
-global EVT_MEASURE_WLC
-
-#measure_wlc, EVT_MEASURE_WLC = NewEvent()
-
-global events_from_fit
-events_from_fit=Queue.Queue() #GUI ---> CLI COMMUNICATION
-
-
-class fitCommands:
-    
-    def _plug_init(self):
-        self.wlccurrent=None
-        self.wlccontact_point=None
-        self.wlccontact_index=None
-    
-    def wlc_fit(self,clicked_points,xvector,yvector, pl_value, T=293, return_errors=False):
-        '''
-        Worm-like chain model fitting.
-        The function is the simple polynomial worm-like chain as proposed by C.Bustamante, J.F.Marko, E.D.Siggia
-        and S.Smith (Science. 1994 Sep 9;265(5178):1599-600.)
-        '''
-    
-        '''clicked_points[0] = contact point (calculated or hand-clicked)
-        clicked_points[1] and [2] are edges of chunk'''
-    
-        #STEP 1: Prepare the vectors to apply the fit.
-        
-        if pl_value is not None:
-            pl_value=pl_value/(10**9)
-        
-        #indexes of the selected chunk
-        first_index=min(clicked_points[1].index, clicked_points[2].index)
-        last_index=max(clicked_points[1].index, clicked_points[2].index)
-               
-        #getting the chunk and reverting it
-        xchunk,ychunk=xvector[first_index:last_index],yvector[first_index:last_index]
-        xchunk.reverse()
-        ychunk.reverse()    
-        #put contact point at zero and flip around the contact point (the fit wants a positive growth for extension and force)
-        xchunk_corr_up=[-(x-clicked_points[0].graph_coords[0]) for x in xchunk]
-        ychunk_corr_up=[-(y-clicked_points[0].graph_coords[1]) for y in ychunk]
-        
-        #make them arrays
-        xchunk_corr_up=scipy.array(xchunk_corr_up)
-        ychunk_corr_up=scipy.array(ychunk_corr_up)
-    
-        
-        #STEP 2: actually do the fit
-    
-        #Find furthest point of chunk and add it a bit; the fit must converge
-        #from an excess!
-        xchunk_high=max(xchunk_corr_up)
-        xchunk_high+=(xchunk_high/10)
-    
-        #Here are the linearized start parameters for the WLC.
-        #[lambd=1/Lo , pii=1/P]
-    
-        p0=[(1/xchunk_high),(1/(3.5e-10))]
-        p0_plfix=[(1/xchunk_high)]
-        '''
-        ODR STUFF
-        fixme: remove these comments after testing
-        '''
-        
-        
-        def f_wlc(params,x,T=T):
-            '''
-            wlc function for ODR fitting
-            '''
-            lambd,pii=params
-            Kb=(1.38065e-23)
-            therm=Kb*T
-            y=(therm*pii/4.0) * (((1-(x*lambd))**-2) - 1 + (4*x*lambd))
-            return y
-        
-        def f_wlc_plfix(params,x,pl_value=pl_value,T=T):
-            '''
-            wlc function for ODR fitting
-            '''
-            lambd=params
-            pii=1/pl_value
-            Kb=(1.38065e-23)
-            therm=Kb*T
-            y=(therm*pii/4.0) * (((1-(x*lambd))**-2) - 1 + (4*x*lambd))
-            return y
-        
-        #make the ODR fit
-        realdata=scipy.odr.RealData(xchunk_corr_up,ychunk_corr_up)
-        if pl_value:
-            model=scipy.odr.Model(f_wlc_plfix)
-            o = scipy.odr.ODR(realdata, model, p0_plfix)
-        else:
-            model=scipy.odr.Model(f_wlc)
-            o = scipy.odr.ODR(realdata, model, p0)
-        
-        o.set_job(fit_type=2)
-        out=o.run()
-        fit_out=[(1/i) for i in out.beta]
-        
-        #Calculate fit errors from output standard deviations.
-        #We must propagate the error because we fit the *inverse* parameters!
-        #The error = (error of the inverse)*(value**2)
-        fit_errors=[]
-        for sd,value in zip(out.sd_beta, fit_out):
-            err_real=sd*(value**2)
-            fit_errors.append(err_real)
-        
-        def wlc_eval(x,params,pl_value,T):    
-            '''
-            Evaluates the WLC function
-            '''
-            if not pl_value:
-                lambd, pii = params
-            else:
-                lambd = params
-        
-            if pl_value:
-                pii=1/pl_value
-        
-            Kb=(1.38065e-23) #boltzmann constant
-            therm=Kb*T #so we have thermal energy
-        
-            return ( (therm*pii/4.0) * (((1-(x*lambd))**-2.0) - 1 + (4.0*x*lambd)) )
-        
-        #STEP 3: plotting the fit
-        
-        #obtain domain to plot the fit - from contact point to last_index plus 20 points
-        thule_index=last_index+10
-        if thule_index > len(xvector): #for rare cases in which we fit something at the END of whole curve.
-            thule_index = len(xvector)
-        #reverse etc. the domain
-        xfit_chunk=xvector[clicked_points[0].index:thule_index]
-        xfit_chunk.reverse()
-        xfit_chunk_corr_up=[-(x-clicked_points[0].graph_coords[0]) for x in xfit_chunk]
-        xfit_chunk_corr_up=scipy.array(xfit_chunk_corr_up)
-    
-        #the fitted curve: reflip, re-uncorrect
-        yfit=wlc_eval(xfit_chunk_corr_up, out.beta, pl_value,T)
-        yfit_down=[-y for y in yfit]
-        yfit_corr_down=[y+clicked_points[0].graph_coords[1] for y in yfit_down]
-    
-        if return_errors:
-            return fit_out, yfit_corr_down, xfit_chunk, fit_errors
-        else:
-            return fit_out, yfit_corr_down, xfit_chunk, None
-    
-                
-    def do_wlc(self,args):
-        '''
-        WLC
-        (fit plugin)
-        Fits a worm-like chain entropic rise to a given chunk of the curve.
-
-        First you have to click a contact point.
-        Then you have to click the two edges of the data you want to fit.
-        The function is the simple polynomial worm-like chain as proposed by 
-        C.Bustamante, J.F.Marko, E.D.Siggia and S.Smith (Science. 1994 
-        Sep 9;265(5178):1599-600.)
-
-        Arguments:
-        pl=[value] : Use a fixed persistent length for the fit. If pl is not given, 
-                     the fit will be a 2-variable  
-                     fit. DO NOT put spaces between 'pl', '=' and the value.
-                     The value must be in nanometers. 
-        
-        t=[value] : Use a user-defined temperature. The value must be in
-                    kelvins; by default it is 293 K.
-                    DO NOT put spaces between 't', '=' and the value.
-        
-        noauto : allows for clicking the contact point by 
-                 hand (otherwise it is automatically estimated) the first time.
-                 If subsequent measurements are made, the same contact point
-                 clicked is used
-        
-        reclick : redefines by hand the contact point, if noauto has been used before
-                  but the user is unsatisfied of the previously choosen contact point.
-        ---------
-        Syntax: wlc [pl=(value)] [t=value] [noauto]
-        '''
-        pl_value=None
-        T=self.config['temperature']
-        for arg in args.split():
-            #look for a persistent length argument.
-            if 'pl=' in arg:
-                pl_expression=arg.split('=')
-                pl_value=float(pl_expression[1]) #actual value
-            #look for a T argument. FIXME: spaces are not allowed between 'pl' and value
-            if ('t=' in arg[0:2]) or ('T=' in arg[0:2]):
-                t_expression=arg.split('=')
-                T=float(t_expression[1])
-        
-        #use the currently displayed plot for the fit
-        displayed_plot=self._get_displayed_plot()
-               
-        #handle contact point arguments correctly
-        if 'reclick' in args.split():
-            print 'Click contact point'
-            contact_point=self._measure_N_points(N=1, whatset=1)[0]
-            contact_point_index=contact_point.index
-            self.wlccontact_point=contact_point
-            self.wlccontact_index=contact_point.index
-            self.wlccurrent=self.current.path
-        elif 'noauto' in args.split():
-            if self.wlccontact_index==None or self.wlccurrent != self.current.path:
-                print 'Click contact point'
-                contact_point=self._measure_N_points(N=1, whatset=1)[0]
-                contact_point_index=contact_point.index
-                self.wlccontact_point=contact_point
-                self.wlccontact_index=contact_point.index
-                self.wlccurrent=self.current.path
-            else:
-                contact_point=self.wlccontact_point
-                contact_point_index=self.wlccontact_index
-        else:
-            cindex=self.find_contact_point()
-            contact_point=ClickedPoint()
-            contact_point.absolute_coords=displayed_plot.vectors[1][0][cindex], displayed_plot.vectors[1][1][cindex]
-            contact_point.find_graph_coords(displayed_plot.vectors[1][0], displayed_plot.vectors[1][1])
-            contact_point.is_marker=True
-            
-        print 'Click edges of chunk'
-        points=self._measure_N_points(N=2, whatset=1)
-        points=[contact_point]+points
-        try:
-            params, yfit, xfit, fit_errors = self.wlc_fit(points, displayed_plot.vectors[1][0], displayed_plot.vectors[1][1],pl_value,T, return_errors=True )
-        except:
-            print 'Fit not possible. Probably wrong interval -did you click two *different* points?'
-            return
-        
-        print 'Contour length: ',params[0]*(1.0e+9),' nm'
-        to_dump='contour '+self.current.path+' '+str(params[0]*(1.0e+9))+' nm'
-        self.outlet.push(to_dump)
-        if len(params)==2: #if we did choose 2-value fit
-            print 'Persistent length: ',params[1]*(1.0e+9),' nm'
-            to_dump='persistent '+self.current.path+' '+str(params[1]*(1.0e+9))+' nm'
-            self.outlet.push(to_dump)
-        
-        if fit_errors:
-            fit_nm=[i*(10**9) for i in fit_errors]
-            print 'Standard deviation (contour length)', fit_nm[0]
-            if len(fit_nm)>1:
-                print 'Standard deviation (persistent length)', fit_nm[1]
-            
-            
-        #add the clicked points in the final PlotObject
-        clickvector_x, clickvector_y=[], []
-        for item in points:
-            clickvector_x.append(item.graph_coords[0])
-            clickvector_y.append(item.graph_coords[1])
-        
-        #create a custom PlotObject to gracefully plot the fit along the curves
-                        
-        fitplot=copy.deepcopy(displayed_plot)
-        fitplot.add_set(xfit,yfit)
-        fitplot.add_set(clickvector_x,clickvector_y)
-        
-        #FIXME: this colour/styles stuff must be solved at the root!
-        if fitplot.styles==[]:
-            fitplot.styles=[None,None,None,'scatter']
-        else:
-            fitplot.styles+=[None,'scatter']
-        
-        if fitplot.colors==[]:
-            fitplot.colors=[None,None,None,None]
-        else:
-            fitplot.colors+=[None,None]
-        
-        self._send_plot([fitplot])
-                
-    def find_contact_point(self,plot=False):
-        '''
-        Finds the contact point on the curve.
-    
-        The current algorithm (thanks to Francesco Musiani, francesco.musiani@unibo.it and Massimo Sandal) is:
-        - take care of the PicoForce trigger bug - exclude retraction portions with too high standard deviation
-        - fit the second half of the retraction curve to a line
-        - if the fit is not almost horizontal, take a smaller chunk and repeat
-        - otherwise, we have something horizontal
-        - so take the average of horizontal points and use it as a baseline
-    
-        Then, start from the rise of the retraction curve and look at the first point below the
-        baseline.
-        
-        FIXME: should be moved, probably to generalvclamp.py
-        '''
-        
-        if not plot:
-            plot=self.plots[0]
-        
-        outplot=self.subtract_curves(1)
-        xret=outplot.vectors[1][0]
-        ydiff=outplot.vectors[1][1]
-
-        xext=plot.vectors[0][0]
-        yext=plot.vectors[0][1]
-        xret2=plot.vectors[1][0]
-        yret=plot.vectors[1][1]
-        
-        #taking care of the picoforce trigger bug: we exclude portions of the curve that have too much
-        #standard deviation. yes, a lot of magic is here.
-        monster=True
-        monlength=len(xret)-int(len(xret)/20)
-        finalength=len(xret)
-        while monster:
-            monchunk=scipy.array(ydiff[monlength:finalength])
-            if abs(scipy.stats.std(monchunk)) < 2e-10:
-                monster=False
-            else: #move away from the monster
-                monlength-=int(len(xret)/50)
-                finalength-=int(len(xret)/50)
-    
-    
-        #take half of the thing
-        endlength=int(len(xret)/2)
-    
-        ok=False
-        
-        while not ok:
-            xchunk=yext[endlength:monlength]
-            ychunk=yext[endlength:monlength]
-            regr=scipy.stats.linregress(xchunk,ychunk)[0:2]
-            #we stop if we found an almost-horizontal fit or if we're going too short...
-            #FIXME: 0.1 and 6 here are "magic numbers" (although reasonable)
-            if (abs(regr[1]) > 0.1) and ( endlength < len(xret)-int(len(xret)/6) ) :
-                endlength+=10
-            else:
-                ok=True  
-                  
-        
-        ymean=scipy.mean(ychunk) #baseline
-    
-        index=0
-        point = ymean+1
-    
-        #find the first point below the calculated baseline
-        while point > ymean:
-            try:
-                point=yret[index]
-                index+=1    
-            except IndexError:
-                #The algorithm didn't find anything below the baseline! It should NEVER happen
-                index=0            
-                return index
-            
-        return index
-                        
-    
-    
-    def find_contact_point2(self, debug=False):
-        '''
-        TO BE DEVELOPED IN THE FUTURE
-        Finds the contact point on the curve.
-            
-        FIXME: should be moved, probably to generalvclamp.py
-        '''
-        
-        #raw_plot=self.current.curve.default_plots()[0]
-        raw_plot=self.plots[0]
-        '''xext=self.plots[0].vectors[0][0]
-        yext=self.plots[0].vectors[0][1]
-        xret2=self.plots[0].vectors[1][0]
-        yret=self.plots[0].vectors[1][1]
-        '''
-        xext=raw_plot.vectors[0][0]
-        yext=raw_plot.vectors[0][1]
-        xret2=raw_plot.vectors[1][0]
-        yret=raw_plot.vectors[1][1]
-        
-        first_point=[xext[0], yext[0]]
-        last_point=[xext[-1], yext[-1]]
-       
-        #regr=scipy.polyfit(first_point, last_point,1)[0:2]
-        diffx=abs(first_point[0]-last_point[0])
-        diffy=abs(first_point[1]-last_point[1])
-        
-        #using polyfit results in numerical errors. good old algebra.
-        a=diffy/diffx
-        b=first_point[1]-(a*first_point[0])
-        baseline=scipy.polyval((a,b), xext)
-        
-        ysub=[item-basitem for item,basitem in zip(yext,baseline)]
-        
-        contact=ysub.index(min(ysub))
-        
-        return xext,ysub,contact
-        
-        #now, exploit a ClickedPoint instance to calculate index...
-        dummy=ClickedPoint()
-        dummy.absolute_coords=(x_intercept,y_intercept)
-        dummy.find_graph_coords(xret2,yret)
-        
-        if debug:
-            return dummy.index, regr, regr_contact
-        else:
-            return dummy.index
-            
-        
-
-    def x_do_contact(self,args):
-        '''
-        DEBUG COMMAND to be activated in the future
-        '''
-        xext,ysub,contact=self.find_contact_point2(debug=True)
-        
-        contact_plot=self.plots[0]
-        contact_plot.add_set(xext,ysub)
-        contact_plot.add_set([xext[contact]],[self.plots[0].vectors[0][1][contact]])
-        #contact_plot.add_set([first_point[0]],[first_point[1]])
-        #contact_plot.add_set([last_point[0]],[last_point[1]])
-        contact_plot.styles=[None,None,None,'scatter']
-        self._send_plot([contact_plot])
-        return
-        
-        
-        index,regr,regr_contact=self.find_contact_point2(debug=True)
-        print regr
-        print regr_contact
-        raw_plot=self.current.curve.default_plots()[0]
-        xret=raw_plot.vectors[0][0]
-        #nc_line=[(item*regr[0])+regr[1] for item in x_nc]
-        nc_line=scipy.polyval(regr,xret)
-        c_line=scipy.polyval(regr_contact,xret)
-                     
-        
-        contact_plot=self.current.curve.default_plots()[0]
-        contact_plot.add_set(xret, nc_line)
-        contact_plot.add_set(xret, c_line)
-        contact_plot.styles=[None,None,None,None]
-        #contact_plot.styles.append(None)
-        contact_plot.destination=1
-        self._send_plot([contact_plot])
-        
\ No newline at end of file
diff --git a/flatfilts.py b/flatfilts.py
deleted file mode 100755 (executable)
index b287527..0000000
+++ /dev/null
@@ -1,427 +0,0 @@
-#!/usr/bin/env python
-
-'''
-FLATFILTS
-
-Force spectroscopy curves filtering of flat curves
-Licensed under the GNU LGPL version 2
-
-Other plugin dependencies:
-procplots.py (plot processing plugin)
-'''
-from libhooke import WX_GOOD
-import wxversion
-wxversion.select(WX_GOOD)
-
-import xml.dom.minidom
-
-import wx
-import scipy
-import numpy
-from numpy import diff
-
-#import pickle
-
-import libpeakspot as lps
-import libhookecurve as lhc
-
-
-class flatfiltsCommands:
-    
-    def _plug_init(self):
-        #configurate convfilt variables
-        convfilt_configurator=ConvfiltConfig()
-        
-        #different OSes have different path conventions
-        if self.config['hookedir'][0]=='/':
-            slash='/' #a Unix or Unix-like system
-        else:
-            slash='\\' #it's a drive letter, we assume it's Windows
-        
-        self.convfilt_config=convfilt_configurator.load_config(self.config['hookedir']+slash+'convfilt.conf')
-    
-    def do_flatfilt(self,args):
-        '''
-        FLATFILT
-        (flatfilts.py)
-        Filters out flat (featureless) curves of the current playlist,
-        creating a playlist containing only the curves with potential
-        features.
-        ------------
-        Syntax:
-        flatfilt [min_npks min_deviation]
-
-        min_npks = minmum number of points over the deviation
-        (default=4)
-
-        min_deviation = minimum signal/noise ratio
-        (default=9)
-
-        If called without arguments, it uses default values, that
-        should work most of the times.
-        '''
-        median_filter=7
-        min_npks=4
-        min_deviation=9
-        
-        args=args.split(' ')
-        if len(args) == 2:
-            min_npks=int(args[0])
-            min_deviation=int(args[1])
-        else:
-            pass
-        
-        print 'Processing playlist...'
-        notflat_list=[]
-        
-        c=0
-        for item in self.current_list:
-            c+=1
-                                   
-            try:
-                notflat=self.has_features(item, median_filter, min_npks, min_deviation)
-                print 'Curve',item.path, 'is',c,'of',len(self.current_list),': features are ',notflat
-            except:
-                notflat=False
-                print 'Curve',item.path, 'is',c,'of',len(self.current_list),': cannot be filtered. Probably unable to retrieve force data from corrupt file.'
-            
-            if notflat:
-                item.features=notflat
-                item.curve=None #empty the item object, to further avoid memory leak
-                notflat_list.append(item)
-        
-        if len(notflat_list)==0:
-            print 'Found nothing interesting. Check your playlist, could be a bug or criteria could be too much stringent'
-            return
-        else:
-            print 'Found ',len(notflat_list),' potentially interesting curves'
-            print 'Regenerating playlist...'
-            self.pointer=0
-            self.current_list=notflat_list
-            self.current=self.current_list[self.pointer]
-            self.do_plot(0)
-                 
-    def has_features(self,item,median_filter,min_npks,min_deviation):
-        '''
-        decides if a curve is flat enough to be rejected from analysis: it sees if there
-        are at least min_npks points that are higher than min_deviation times the absolute value
-        of noise.
-   
-        Algorithm original idea by Francesco Musiani, with my tweaks and corrections.
-        '''
-        retvalue=False
-        
-        item.identify(self.drivers)        
-        #we assume the first is the plot with the force curve
-        #do the median to better resolve features from noise
-        flat_plot=self.plotmanip_median(item.curve.default_plots()[0], item, customvalue=median_filter)
-        flat_vects=flat_plot.vectors 
-        item.curve.close_all()
-        #needed to avoid *big* memory leaks!
-        del item.curve
-        del item
-        
-        #absolute value of derivate        
-        yretdiff=diff(flat_vects[1][1])
-        yretdiff=[abs(value) for value in yretdiff]
-        #average of derivate values
-        diffmean=numpy.mean(yretdiff)
-        yretdiff.sort()
-        yretdiff.reverse()
-        c_pks=0
-        for value in yretdiff:
-            if value/diffmean > min_deviation:
-                c_pks+=1
-            else:
-                break
-                    
-        if c_pks>=min_npks:
-            retvalue = c_pks
-        
-        del flat_plot, flat_vects, yretdiff
-        
-        return retvalue
-
-    ################################################################
-    #-----CONVFILT-------------------------------------------------
-    #-----Convolution-based peak recognition and filtering.
-    #Requires the libpeakspot.py library
-    
-    def has_peaks(self, plot, abs_devs=None):
-        '''
-        Finds peak position in a force curve.
-        FIXME: should be moved in libpeakspot.py
-        '''
-        if abs_devs==None:
-            abs_devs=self.convfilt_config['mindeviation']
-        
-        
-        xret=plot.vectors[1][0]
-        yret=plot.vectors[1][1]
-        #Calculate convolution.
-        convoluted=lps.conv_dx(yret, self.convfilt_config['convolution'])
-        
-        #surely cut everything before the contact point
-        cut_index=self.find_contact_point(plot)
-        #cut even more, before the blind window
-        start_x=xret[cut_index]
-        blind_index=0
-        for value in xret[cut_index:]:
-            if abs((value) - (start_x)) > self.convfilt_config['blindwindow']*(10**-9):
-                break
-            blind_index+=1
-        cut_index+=blind_index
-        #do the dirty convolution-peak finding stuff
-        noise_level=lps.noise_absdev(convoluted[cut_index:], self.convfilt_config['positive'], self.convfilt_config['maxcut'], self.convfilt_config['stable'])               
-        above=lps.abovenoise(convoluted,noise_level,cut_index,abs_devs)     
-        peak_location,peak_size=lps.find_peaks(above,seedouble=self.convfilt_config['seedouble'])
-                
-        #take the maximum
-        for i in range(len(peak_location)):
-            peak=peak_location[i]
-            maxpk=min(yret[peak-10:peak+10])
-            index_maxpk=yret[peak-10:peak+10].index(maxpk)+(peak-10)
-            peak_location[i]=index_maxpk
-            
-        return peak_location,peak_size
-    
-    
-    def exec_has_peaks(self,item,abs_devs):
-        '''
-        encapsulates has_peaks for the purpose of correctly treating the curve objects in the convfilt loop,
-        to avoid memory leaks
-        '''
-        item.identify(self.drivers)        
-        #we assume the first is the plot with the force curve
-        plot=item.curve.default_plots()[0]
-        
-        if 'flatten' in self.config['plotmanips']:
-                    #If flatten is present, use it for better recognition of peaks...
-                    flatten=self._find_plotmanip('flatten') #extract flatten plot manipulator
-                    plot=flatten(plot, item, customvalue=1)
-        
-        peak_location,peak_size=self.has_peaks(plot,abs_devs)
-        #close all open files
-        item.curve.close_all()
-        #needed to avoid *big* memory leaks!
-        del item.curve
-        del item
-        return peak_location, peak_size
-        
-    #------------------------
-    #------commands----------
-    #------------------------    
-    def do_peaks(self,args):
-        '''
-        PEAKS
-        (flatfilts.py)
-        Test command for convolution filter / test.
-        ----
-        Syntax: peaks [deviations]
-        absolute deviation = number of times the convolution signal is above the noise absolute deviation.
-        Default is 5.
-        '''
-        if len(args)==0:
-            args=self.convfilt_config['mindeviation']
-        
-        try:
-            abs_devs=float(args)
-        except:
-            pass
-                        
-        defplots=self.current.curve.default_plots()[0] #we need the raw, uncorrected plots
-        
-        if 'flatten' in self.config['plotmanips']:
-            flatten=self._find_plotmanip('flatten') #extract flatten plot manipulator
-            defplots=flatten(defplots, self.current)
-        else:
-            print 'You have the flatten plot manipulator not loaded. Enabling it could give you better results.'
-        
-        peak_location,peak_size=self.has_peaks(defplots,abs_devs)
-        print 'Found '+str(len(peak_location))+' peaks.'
-        to_dump='peaks '+self.current.path+' '+str(len(peak_location))
-        self.outlet.push(to_dump)
-        #print peak_location
-        
-        #if no peaks, we have nothing to plot. exit.
-        if len(peak_location)==0:
-            return
-        
-        #otherwise, we plot the peak locations.
-        xplotted_ret=self.plots[0].vectors[1][0]
-        yplotted_ret=self.plots[0].vectors[1][1]
-        xgood=[xplotted_ret[index] for index in peak_location]
-        ygood=[yplotted_ret[index] for index in peak_location]
-        
-        recplot=self._get_displayed_plot()
-        recplot.vectors.append([xgood,ygood])
-        if recplot.styles==[]:
-            recplot.styles=[None,None,'scatter']
-            recplot.colors=[None,None,None]
-        else:
-            recplot.styles+=['scatter']
-            recplot.colors+=[None]
-        
-        self._send_plot([recplot])
-        
-    def do_convfilt(self,args):
-        '''
-        CONVFILT
-        (flatfilts.py)
-        Filters out flat (featureless) curves of the current playlist,
-        creating a playlist containing only the curves with potential
-        features.
-        ------------
-        Syntax:
-        convfilt [min_npks min_deviation]
-
-        min_npks = minmum number of peaks
-        (to set the default, see convfilt.conf file; CONVCONF and SETCONF commands)
-
-        min_deviation = minimum signal/noise ratio *in the convolution*
-        (to set the default, see convfilt.conf file; CONVCONF and SETCONF commands)
-
-        If called without arguments, it uses default values.
-        '''
-        
-        min_npks=self.convfilt_config['minpeaks']
-        min_deviation=self.convfilt_config['mindeviation']
-        
-        args=args.split(' ')
-        if len(args) == 2:
-            min_npks=int(args[0])
-            min_deviation=int(args[1])
-        else:
-            pass
-        
-        print 'Processing playlist...'
-        print '(Please wait)'
-        notflat_list=[]
-        
-        c=0
-        for item in self.current_list:
-            c+=1
-                                   
-            try:    
-                peak_location,peak_size=self.exec_has_peaks(item,min_deviation)
-                if len(peak_location)>=min_npks:
-                    isok='+'
-                else:
-                    isok=''
-                print 'Curve',item.path, 'is',c,'of',len(self.current_list),': found '+str(len(peak_location))+' peaks.'+isok
-            except:
-                peak_location,peak_size=[],[]
-                print 'Curve',item.path, 'is',c,'of',len(self.current_list),': cannot be filtered. Probably unable to retrieve force data from corrupt file.'
-            
-            if len(peak_location)>=min_npks:
-                item.peak_location=peak_location
-                item.peak_size=peak_size
-                item.curve=None #empty the item object, to further avoid memory leak
-                notflat_list.append(item)
-        
-        #Warn that no flattening had been done.
-        if not ('flatten' in self.config['plotmanips']):
-            print 'Flatten manipulator was not found. Processing was done without flattening.'
-            print 'Try to enable it in your configuration file for better results.'
-        
-        if len(notflat_list)==0:
-            print 'Found nothing interesting. Check your playlist, could be a bug or criteria could be too much stringent'
-            return
-        else:
-            print 'Found ',len(notflat_list),' potentially interesting curves'
-            print 'Regenerating playlist...'
-            self.pointer=0
-            self.current_list=notflat_list
-            self.current=self.current_list[self.pointer]
-            self.do_plot(0)
-        
-        
-    def do_setconv(self,args):
-        '''
-        SETCONV
-        (flatfilts.py)
-        Sets the convfilt configuration variables
-        ------
-        Syntax: setconv variable value
-        '''
-        args=args.split()
-        #FIXME: a general "set dictionary" function has to be built
-        if len(args)==0:
-            print self.convfilt_config
-        else:
-            if not (args[0] in self.convfilt_config.keys()):
-                print 'This is not an internal convfilt variable!'
-                print 'Run "setconv" without arguments to see a list of defined variables.'
-                return
-            
-            if len(args)==1:
-                print self.convfilt_config[args[0]]
-            elif len(args)>1:
-                try:
-                    self.convfilt_config[args[0]]=eval(args[1])
-                except NameError: #we have a string argument
-                    self.convfilt_config[args[0]]=args[1]
-
-
-#########################
-#HANDLING OF CONFIGURATION FILE
-class ConvfiltConfig:
-    '''
-    Handling of convfilt configuration file
-    
-    Mostly based on the simple-yet-useful examples of the Python Library Reference
-    about xml.dom.minidom
-    
-    FIXME: starting to look a mess, should require refactoring
-    '''
-    
-    def __init__(self):
-        self.config={}
-        
-                
-    def load_config(self, filename):
-        myconfig=file(filename)                    
-        #the following 3 lines are needed to strip newlines. otherwise, since newlines
-        #are XML elements too, the parser would read them (and re-save them, multiplying
-        #newlines...)
-        #yes, I'm an XML n00b
-        the_file=myconfig.read()
-        the_file_lines=the_file.split('\n')
-        the_file=''.join(the_file_lines)
-                       
-        self.config_tree=xml.dom.minidom.parseString(the_file)  
-        
-        def getText(nodelist):
-            #take the text from a nodelist
-            #from Python Library Reference 13.7.2
-            rc = ''
-            for node in nodelist:
-                if node.nodeType == node.TEXT_NODE:
-                    rc += node.data
-            return rc
-        
-        def handleConfig(config):
-            noiseabsdev_elements=config.getElementsByTagName("noise_absdev")
-            convfilt_elements=config.getElementsByTagName("convfilt")
-            handleAbsdev(noiseabsdev_elements)
-            handleConvfilt(convfilt_elements)
-                        
-        def handleAbsdev(noiseabsdev_elements):
-            for element in noiseabsdev_elements:
-                for attribute in element.attributes.keys():
-                    self.config[attribute]=element.getAttribute(attribute)
-                    
-        def handleConvfilt(convfilt_elements):
-            for element in convfilt_elements:
-                for attribute in element.attributes.keys():
-                    self.config[attribute]=element.getAttribute(attribute)
-            
-        handleConfig(self.config_tree)
-        #making items in the dictionary machine-readable
-        for item in self.config.keys():
-            try:
-                self.config[item]=eval(self.config[item])
-            except NameError: #if it's an unreadable string, keep it as a string
-                pass
-            
-        return self.config
\ No newline at end of file
diff --git a/generalclamp.py b/generalclamp.py
deleted file mode 100644 (file)
index 4ac30e7..0000000
+++ /dev/null
@@ -1,251 +0,0 @@
-#!/usr/bin/env python
-
-'''
-GENERALCLAMP.py
-
-Plugin regarding general force clamp measurements
-'''
-from libhooke import WX_GOOD, ClickedPoint
-import wxversion\r
-import libhookecurve as lhc
-wxversion.select(WX_GOOD)
-from wx import PostEvent\r
-
-class generalclampCommands:\r
-\r
-    def plotmanip_clamp(self, plot, current, customvalue=False):
-        '''
-        Handles some viewing options for the "force clamp" data format, depending on the state of these configuration variables:\r
-        (1) If self.config['fc_showphase'] != 0, the 'phase' data column (i.e. the 2nd) is shown in the 0th graph (else it isn't)\r
-        (2) If self.config['fc_showimposed'] != 0, the 'imposed deflection' data column (i.e. the 5th) is shown in the 1st graph (else it isn't)\r
-        (3) If self.config['fc_interesting'] == 0, the entire curve is shown in the graphs; if it has a non-zero value N, only phase N is shown.
-\r
-        NOTE - my implementation of point(3) feels quite awkward - someone smarter than me plz polish that!\r
-\r
-        '''
-        
-        #not a fclamp curve...
-        if current.curve.experiment != 'clamp':
-            return plot\r
-\r
-        if self.config['fc_interesting'] != 0 and plot.destination==0:\r
-            lower = int((self.config['fc_interesting'])-1)\r
-            upper = int((self.config['fc_interesting'])+1)\r
-            trim = current.curve.trimindexes()[lower:upper]\r
-            newtime = []\r
-            newzpiezo = []\r
-            newphase = []\r
-            for x in range(trim[0],trim[1]):\r
-                newtime.append(self.plots[0].vectors[0][0][x])\r
-                newzpiezo.append(self.plots[0].vectors[0][1][x])\r
-                newphase.append(self.plots[0].vectors[1][1][x])\r
-            self.plots[0].vectors[0][0] = newtime\r
-            self.plots[0].vectors[0][1] = newzpiezo\r
-            self.plots[0].vectors[1][0] = newtime\r
-            self.plots[0].vectors[1][1] = newphase\r
-\r
-        if self.config['fc_interesting'] != 0 and plot.destination==1:\r
-            lower = int((self.config['fc_interesting'])-1)\r
-            upper = int((self.config['fc_interesting'])+1)\r
-            trim = current.curve.trimindexes()[lower:upper]\r
-            newtime = []\r
-            newdefl = []\r
-            newimposed = []\r
-            for x in range(trim[0],trim[1]):\r
-                newtime.append(self.plots[1].vectors[0][0][x])\r
-                newdefl.append(self.plots[1].vectors[0][1][x])\r
-                newimposed.append(self.plots[1].vectors[1][1][x])\r
-            self.plots[1].vectors[0][0] = newtime\r
-            self.plots[1].vectors[0][1] = newdefl\r
-            self.plots[1].vectors[1][0] = newtime\r
-            self.plots[1].vectors[1][1] = newimposed            \r
-                        \r
-        if self.config['fc_showphase'] == 0 and plot.destination==0:\r
-            self.plots[0].remove_set(1)\r
-            \r
-        if self.config['fc_showimposed'] == 0 and plot.destination==1:\r
-            self.plots[1].remove_set(1)\r
-                         \r
-        return plot
-      
-    def do_time(self,args):
-        '''
-        Measures the time difference (in seconds) between two points
-        Implemented only for force clamp
-        ----
-        Syntax: time
-        '''
-        if self.current.curve.experiment == 'clamp':\r
-            time=self._delta(set=0)[0]\r
-            print str(time*1000)+' ms'
-        else:
-            print 'This command makes no sense for a non-force clamp experiment.'
-            
-    def do_zpiezo(self,args):
-        '''
-        Measures the zpiezo difference (in nm) between two points
-        Implemented only for force clamp
-        ----
-        Syntax: zpiezo
-        '''
-        if self.current.curve.experiment == 'clamp':
-            zpiezo=self._delta(set=0)[2]\r
-            print str(zpiezo*(10**9))+' nm'
-        else:
-            print 'This command makes no sense for a non-force clamp experiment.'
-            
-    def do_defl(self,args):
-        '''
-        Measures the deflection difference (in nm) between two points
-        Implemented only for force clamp
-        NOTE: It makes sense only on the time VS defl plot; it is still not masked for the other plot...
-        -----
-        Syntax: defl
-        '''
-        if self.current.curve.experiment == 'clamp':
-            print "Warning - don't use on the zpiezo plot!"
-            defl=self._delta(set=1)[2]
-            print str(defl*(10**12))+' pN'
-        else:
-            print 'This command makes no sense for a non-force clamp experiment.'
-            
-    def do_step(self,args):
-        '''
-        Measures the length and time duration of a time-Z step
-        -----
-        Syntax: step
-        '''
-        if self.current.curve.experiment == 'clamp':
-            print 'Click three points in this fashion:'
-            print ' (0)-------(1)'
-            print '           |'
-            print '           |'
-            print '           (2)----------'
-            points=self._measure_N_points(N=3,whatset=0)
-            dz=abs(points[2].graph_coords[1]-points[1].graph_coords[1])*(10e+8)
-            dt=abs(points[1].graph_coords[0]-points[0].graph_coords[0])
-            print 'dZ: ',dz,' nm'
-            print 'dT: ',dt,' s'
-            
-        else:
-            print 'This command makes no sense for a non-force clamp experiment.'\r
-\r
-    def do_fcfilt(self,args):\r
-        '''\r
-        Filters out featureless force clamp curves of the current playlist.\r
-        It's very similar to 'flatfilt' for velocity clamp curves.\r
-        Creates a new playlist only containing non-empty curves.\r
-\r
-        WARNING - Only works if you set an appropriate fc_interesting config variable!\r
-        WARNING - arguments are NOT optional at the moment!\r
-\r
-        Syntax: fcfilt maxretraction(nm) mindeviation (pN)\r
-\r
-        Suggested values for an (i27)8 experiment with our setup are 200nm and 10-15 pN\r
-        '''\r
-\r
-        if self.config['fc_interesting'] == 0:\r
-            print 'You must specify the phase of interest (using set fc_interesing X) prior to running fcfilt!'\r
-            return\r
-        \r
-        maxretraction=0\r
-        threshold=0\r
-        args=args.split(' ')\r
-        if len(args)==2:\r
-            maxretraction=int(args[0])\r
-            threshold=int(args[1])\r
-        else:\r
-            print 'Arguments are not optional for fcfilt. You should pass two numbers:'\r
-            print '(1) the maximum plausible piezo retraction in NANOMETERS (e.g. the length of the protein)'\r
-            print "(2) the threshold, in PICONEWTONS. If signal deviates from imposed more than this, it's an event"\r
-            return\r
-        \r
-\r
-        print 'Processing playlist... go get yourself a cup of coffee.'\r
-        notflat_list=[]\r
-\r
-        c=0\r
-\r
-        for item in self.current_list:\r
-            c+=1\r
-            try:\r
-                notflat=self.has_stuff(item,maxretraction,threshold)\r
-                print 'Curve',item.path,'is',c,'of',len(self.current_list),'--->Has Stuff =',notflat\r
-            except:\r
-                notflat=False\r
-                print 'Curve',item.path,'is',c,'of',len(self.current_list),'--->could not be processed'\r
-            if notflat:\r
-                item.features=notflat\r
-                item.curve=None\r
-                notflat_list.append(item)\r
-\r
-        if len(notflat_list)==0:\r
-            print 'Nothing interesting here. Reconsider either your filtering criteria or your experimental data'\r
-            return\r
-        else:\r
-            print 'Found',len(notflat_list),'potentially interesting curves.'\r
-            print 'Regenerating Playlist...'\r
-            self.pointer=0\r
-            self.current_list=notflat_list\r
-            self.current=self.current_list[self.pointer]\r
-            self.do_plot(0)\r
-\r
-    def has_stuff(self,item,maxretraction,threshold):\r
-        '''\r
-        Decides whether a curve has some features in the interesting phase.\r
-        Algorithm:\r
-            - clip the interesting phase portion of the curve.\r
-            - discard the first 20 milliseconds (this is due to a quirk of our hardware).\r
-            - look at the zpiezo plot and note down when (if) retratcs more than [maxretraction] nm away from the first point.\r
-            - clip off any data after this point, with an excess of 100 points (again, an hardware quirk)\r
-            - if the remainder is less than 100 points, ditch the curve.\r
-            - now look at the deflection plot and check if there are points more than [threshold] pN over the 'flat zone'.\r
-            - if you find such points, bingo!            \r
-        '''\r
-\r
-        item.identify(self.drivers)\r
-   \r
-        lower = int((self.config['fc_interesting'])-1)\r
-        upper = int((self.config['fc_interesting'])+1)\r
-        trim_idxs = item.curve.trimindexes()[lower:upper]\r
-        lo=trim_idxs[0]+20                                                  #clipping the first 20 points off...\r
-        hi=trim_idxs[1]\r
-        trimmed_zpiezo=item.curve.default_plots()[0].vectors[0][1][lo:hi]\r
-        trimmed_defl=item.curve.default_plots()[1].vectors[0][1][lo:hi]\r
-        trimmed_imposed=item.curve.default_plots()[1].vectors[1][1][lo:hi]\r
-        imposed=trimmed_imposed[21]                                         #just to match the 20-pts clipping...\r
-        \r
-        item.curve.close_all()\r
-        del item.curve\r
-        del item\r
-\r
-        starting_z=trimmed_zpiezo[0]\r
-        plausible=starting_z-(maxretraction*1e-9)\r
-        det_trim=0\r
-        while trimmed_zpiezo[det_trim]>plausible:\r
-            det_trim+=1\r
-            if det_trim >= len(trimmed_zpiezo):                              #breaking cycles makes me shiver...\r
-                det_trim=len(trimmed_zpiezo)                                 #but I cannot think of anything better now.\r
-                break\r
-        further_trim=det_trim-100\r
-        if further_trim<100:\r
-            return False\r
-        trimmed_defl=trimmed_defl[:further_trim]\r
-\r
-        trimmed_defl.sort()\r
-        ninetypercent=int(0.9*len(trimmed_defl))\r
-        j=0\r
-        sum=0\r
-        for j in trimmed_defl[:ninetypercent]:\r
-            sum+=j\r
-        avg=float(sum/ninetypercent)\r
-        sweetspot=float(avg+(threshold*1e-12))\r
-        if trimmed_defl[-1]>sweetspot:\r
-            flag=True\r
-        else:\r
-            flag=False\r
-\r
-        del trimmed_defl,trimmed_zpiezo,trimmed_imposed            \r
-\r
-        return flag            \r
-        
\ No newline at end of file
diff --git a/generaltccd.py b/generaltccd.py
deleted file mode 100644 (file)
index 70ad513..0000000
+++ /dev/null
@@ -1,64 +0,0 @@
-#!/usr/bin/env python
-
-'''
-generaltccd.py
-
-General utilities for TCCD stuff
-'''
-
-class generaltccdCommands:
-    
-    def plotmanip_threshold(self, plot, current, customvalue=False):
-        '''
-        Cuts from the plot everything below the threshold.
-        Set the threshold with "set tccd_threshold"
-        '''
-        
-        if current.curve.experiment != 'smfluo':
-            return plot
-        
-        if not self.config['tccd_threshold'] and (not customvalue):
-            return plot
-        
-        if customvalue:
-            thresh=customvalue
-        else:
-            thresh=self.config['tccd_threshold']
-        
-        for set in plot.vectors:
-            newy=[]
-            for value in set[1]:
-                if abs(value) < thresh:
-                    newy.append(0)
-                else:
-                    newy.append(value)
-            
-            set[1]=newy
-                    
-        return plot
-                
-
-    def plotmanip_coincident(self,plot,current, customvalue=False):
-        '''
-        Shows only coincident events
-        '''
-        if current.curve.experiment != 'smfluo':
-            return plot
-        
-        if not self.config['tccd_coincident'] and (not customvalue):
-            return plot
-        
-        newred=[]
-        newblue=[]
-        for index in range(len(plot.vectors[0][1])):
-            if abs(plot.vectors[0][1][index])>self.config['tccd_threshold'] and abs(plot.vectors[1][1][index])>self.config['tccd_threshold']:
-                newred.append(plot.vectors[0][1][index])
-                newblue.append(plot.vectors[1][1][index])
-            else:
-                newred.append(0)
-                newblue.append(0)
-                
-        plot.vectors[0][1]=newred
-        plot.vectors[1][1]=newblue
-     
-        return plot
\ No newline at end of file
diff --git a/generalvclamp.py b/generalvclamp.py
deleted file mode 100644 (file)
index 1c71de0..0000000
+++ /dev/null
@@ -1,321 +0,0 @@
-#!/usr/bin/env python
-
-'''
-generalvclamp.py
-
-Plugin regarding general velocity clamp measurements
-'''
-
-from libhooke import WX_GOOD, ClickedPoint
-import wxversion
-wxversion.select(WX_GOOD)
-from wx import PostEvent
-import numpy as np
-import scipy as sp
-import copy
-import os.path
-import time
-
-import warnings
-warnings.simplefilter('ignore',np.RankWarning)
-
-
-class generalvclampCommands:
-    
-    def _plug_init(self):
-        self.basecurrent=None
-        self.basepoints=None
-        self.autofile=''
-    
-    def do_distance(self,args):
-        '''
-        DISTANCE
-        (generalvclamp.py)
-        Measure the distance (in nm) between two points.
-        For a standard experiment this is the delta X distance.
-        For a force clamp experiment this is the delta Y distance (actually becomes
-        an alias of zpiezo)
-        -----------------
-        Syntax: distance
-        '''
-        if self.current.curve.experiment == 'clamp':
-            print 'You wanted to use zpiezo perhaps?'
-            return
-        else:
-            dx,unitx,dy,unity=self._delta(set=1)
-            print str(dx*(10**9))+' nm'
-            to_dump='distance '+self.current.path+' '+str(dx*(10**9))+' nm'
-            self.outlet.push(to_dump)
-
-
-    def do_force(self,args):
-        '''
-        FORCE
-        (generalvclamp.py)
-        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 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
-        ------------
-        Syntax: forcebase [rebase]
-                rebase: Forces forcebase to ask again the baseline
-                max: Instead of asking for a point to measure, asks for two points and use
-                     the maximum peak in between
-        '''
-        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)
-            boundpoints=[points[0].index, points[1].index]
-            boundpoints.sort()
-            try:
-                y=min(plot.vectors[whatset][1][boundpoints[0]:boundpoints[1]])
-            except ValueError:
-                print 'Chosen interval not valid. Try picking it again. Did you pick the same point as begin and end of interval?'
-        else:
-            print 'Select point to measure'
-            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 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
-        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\r
-\r
-        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
-   
-    
-    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 
-        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)]
-        
-        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:]
-            y_ret=plot.vectors[1][1][contact_index+delta_contact:]
-            for exponent in range(max_exponent):
-                try:
-                    valn[exponent]=sp.polyfit(x_ext,y_ext,exponent)
-                    yrn[exponent]=sp.polyval(valn[exponent],x_ret)
-                    errn[exponent]=sp.sqrt(sum((yrn[exponent]-y_ext)**2)/float(len(y_ext)))
-                except Exception,e:
-                    print 'Cannot flatten!'
-                    print e
-                    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        
-            #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):
-        '''
-        SLOPE
-        (generalvclamp.py)
-        Measures the slope of a delimited chunk on the return trace.
-        The chunk can be delimited either by two manual clicks, or have
-        a fixed width, given as an argument.
-        ---------------
-        Syntax: slope [width]
-                The facultative [width] parameter specifies how many
-                points will be considered for the fit. If [width] is
-                specified, only one click will be required.
-        (c) Marco Brucale, Massimo Sandal 2008
-        '''
-
-        # Reads the facultative width argument
-        try:
-            fitspan=int(args)
-        except:
-            fitspan=0
-
-        # Decides between the two forms of user input, as per (args)
-        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]
-        
-        # Calls the function linefit_between
-        parameters=[0,0,[],[]]
-        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=[]
-        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:
-            lineplot.styles+=[None,'scatter']
-        if lineplot.colors==[]:
-            lineplot.styles=[None,None,None,None]
-        else:
-            lineplot.colors+=[None,None]
-        
-        
-        self._send_plot([lineplot])
-
-    def linefit_between(self,index1,index2,whatset=1):
-        '''
-        Creates two vectors (xtofit,ytofit) slicing out from the
-        current return trace a portion delimited by the two indexes
-        given as arguments.
-        Then does a least squares linear fit on that slice.
-        Finally returns [0]=the slope, [1]=the intercept of the
-        fitted 1st grade polynomial, and [2,3]=the actual (x,y) vectors
-        used for the fit.
-        (c) Marco Brucale, Massimo Sandal 2008
-        '''
-        # 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)
-    
-    
-    
diff --git a/hooke.conf b/hooke.conf
deleted file mode 100755 (executable)
index 8c72cb6..0000000
+++ /dev/null
@@ -1,71 +0,0 @@
-<?xml version="1.0" ?>\r
-<!-- To comment something, put dashes and ! like here -->\r
-<config>\r
-<!-- Internal variabls. -->\r
-    <display ext="1" colour_ext="None" ret="1" colour_ret="None" correct="1" colour_correct="None" contact_point="0" medfilt="0" xaxes="0" yaxes="0" flatten="1" temperature="301" auto_fit_points="50" auto_slope_span="20" auto_delta_force="10" auto_fit_nm="5" auto_min_p="0.005" auto_max_p="10" baseline_clicks="0" auto_left_baseline="20" auto_right_baseline="20" force_multiplier="1" fc_showphase="0" fc_showimposed="0" fc_interesting="0" tccd_threshold="0" tccd_coincident="0"/>\r
-\r
-<!-- \r
-The following section defines your own work directory. Substitute your work directory.\r
-     -->\r
-<workdir>\r
-    insert directory\r
-</workdir>\r
-\r
-<!--\r
-The following section defines the default playlist to load at startup.\r
--->\r
-<defaultlist>\r
-    test.hkp\r
-</defaultlist>\r
-\r
-<!--\r
-This section defines which plugins have to be loaded by Hooke.\r
-    -->\r
-<plugins>\r
-    <fit/>\r
-    <procplots/>\r
-    <flatfilts/>\r
-    <generalclamp/>\r
-    <!-- dummyguiplug/ -->\r
-    <!-- superimpose/ -->\r
-    <generalvclamp/>\r
-    <massanalysis/>\r
-    <viewer/>\r
-    <!-- tutorial/ -->\r
-    <macro/>\r
-    <autopeak/>\r
-    <pcluster/>\r
-    <generaltccd/>\r
-</plugins>\r
-\r
-<!--\r
-This section defines which drivers have to be loaded by Hooke.\r
-    -->\r
-<drivers>\r
-    <picoforce/>\r
-    <!-- picoforcealt/ -->\r
-    <hemingclamp/>\r
-    <csvdriver/>\r
-    <!-- tutorialdriver/ -->\r
-    <jpk/>\r
-    <mfp1dexport/>\r
-    <mcs/>\r
-</drivers>\r
-\r
-<!--\r
-This section defines which plot manipulators have to be loaded by Hooke,\r
-and -IMPORTANTLY- their order.\r
-    -->\r
-<plotmanips>\r
-    <correct/>\r
-    <median/>\r
-    <!-- absvalue/ -->\r
-    <flatten/>\r
-    <multiplier/>\r
-    <clamp/>\r
-    <threshold/>\r
-    <coincident/>\r
-</plotmanips>\r
-\r
-</config>\r
-\r
old mode 100755 (executable)
new mode 100644 (file)
index 21cd509..6a28f12
--- a/hooke.py
+++ b/hooke.py
 '''\r
 HOOKE - A force spectroscopy review & analysis tool\r
 \r
-(C) 2008 Massimo Sandal\r
-\r
-Copyright (C) 2008 Massimo Sandal (University of Bologna, Italy).\r
+Copyright 2008 by Massimo Sandal (University of Bologna, Italy).\r
+Copyright 2010 by Rolf Schmidt (Concordia University, Canada).\r
 \r
 This program is released under the GNU General Public License version 2.\r
 '''\r
 \r
-from libhooke import HOOKE_VERSION\r
-from libhooke import WX_GOOD\r
-\r
-import os\r
-\r
 import wxversion\r
-wxversion.select(WX_GOOD)\r
-import wx\r
-import wxmpl\r
-from wx.lib.newevent import NewEvent\r
-\r
-import matplotlib.numerix as nx\r
-import scipy as sp\r
-\r
-from threading import *\r
-import Queue\r
-\r
-from hooke_cli import HookeCli\r
-from libhooke import *\r
-import libhookecurve as lhc\r
-\r
-#import file versions, just to know with what we're working...\r
-from hooke_cli import __version__ as hookecli_version\r
+import lib.libhooke as lh\r
+wxversion.select(lh.WX_GOOD)\r
+\r
+from configobj import ConfigObj\r
+import copy\r
+import os.path\r
+import platform\r
+import time\r
+#import wx\r
+import wx.html\r
+import wx.lib.agw.aui as aui\r
+import wx.lib.evtmgr as evtmgr\r
+import wx.propgrid as wxpg\r
+\r
+from matplotlib import __version__ as mpl_version\r
+from numpy import __version__ as numpy_version\r
+from scipy import __version__ as scipy_version\r
+from sys import version as python_version\r
+from wx import __version__ as wx_version\r
+\r
+try:\r
+    from agw import cubecolourdialog as CCD\r
+except ImportError: # if it's not there locally, try the wxPython lib.\r
+    import wx.lib.agw.cubecolourdialog as CCD\r
+\r
+#set the Hooke directory\r
+lh.hookeDir = os.path.abspath(os.path.dirname(__file__))\r
+from config.config import config\r
+import drivers\r
+import lib.playlist\r
+import lib.plotmanipulator\r
+import panels.commands\r
+import panels.perspectives\r
+import panels.playlist\r
+import panels.plot\r
+import panels.propertyeditor\r
+import panels.results\r
+import plugins\r
 \r
 global __version__\r
-global events_from_gui\r
-global config\r
-global CLI_PLUGINS\r
-global GUI_PLUGINS\r
-global LOADED_PLUGINS\r
-global PLOTMANIP_PLUGINS\r
-global FILE_DRIVERS\r
-\r
-__version__=HOOKE_VERSION[0]\r
-__release_name__=HOOKE_VERSION[1]\r
-\r
-events_from_gui=Queue.Queue() #GUI ---> CLI COMMUNICATION\r
-\r
-print 'Starting Hooke.'\r
-#CONFIGURATION FILE PARSING\r
-config_obj=HookeConfig()\r
-config=config_obj.load_config('hooke.conf')\r
-\r
-#IMPORTING PLUGINS\r
-\r
-CLI_PLUGINS=[]\r
-GUI_PLUGINS=[]\r
-PLOTMANIP_PLUGINS=[]\r
-LOADED_PLUGINS=[]\r
-\r
-plugin_commands_namespaces=[]\r
-plugin_gui_namespaces=[]\r
-for plugin_name in config['plugins']:\r
-    try:\r
-        plugin=__import__(plugin_name)\r
-        try:\r
-            eval('CLI_PLUGINS.append(plugin.'+plugin_name+'Commands)') #take Command plugin classes\r
-            plugin_commands_namespaces.append(dir(eval('plugin.'+plugin_name+'Commands')))\r
-        except:\r
-            pass\r
-        try:\r
-            eval('GUI_PLUGINS.append(plugin.'+plugin_name+'Gui)') #take Gui plugin classes\r
-            plugin_gui_namespaces.append(dir(eval('plugin.'+plugin_name+'Gui')))\r
-        except:\r
-            pass\r
-    except ImportError:\r
-        print 'Cannot find plugin ',plugin_name\r
-    else:\r
-        LOADED_PLUGINS.append(plugin_name)\r
-        print 'Imported plugin ',plugin_name\r
-\r
-#eliminate names common to all namespaces\r
-for i in range(len(plugin_commands_namespaces)):\r
-    plugin_commands_namespaces[i]=[item for item in plugin_commands_namespaces[i] if (item != '__doc__' and item != '__module__' and item != '_plug_init')]\r
-#check for conflicts in namespaces between plugins\r
-#FIXME: only in commands now, because I don't have Gui plugins to check\r
-#FIXME: how to check for plugin-defined variables (self.stuff) ??\r
-plugin_commands_names=[]\r
-whatplugin_defines=[]\r
-plugin_gui_names=[]\r
-for namespace,plugin_name in zip(plugin_commands_namespaces, config['plugins']):\r
-    for item in namespace:\r
-        if item in plugin_commands_names:\r
-            i=plugin_commands_names.index(item) #we exploit the fact index gives the *first* occurrence of a name...\r
-            print 'Error. Plugin ',plugin_name,' defines a function already defined by ',whatplugin_defines[i],'!'\r
-            print 'This should not happen. Please disable one or both plugins and contact the plugin authors to solve the conflict.'\r
-            print 'Hooke cannot continue.'\r
-            exit()\r
-        else:\r
-            plugin_commands_names.append(item)\r
-            whatplugin_defines.append(plugin_name)\r
-\r
-\r
-config['loaded_plugins']=LOADED_PLUGINS #FIXME: kludge -this should be global but not in config!\r
-#IMPORTING DRIVERS\r
-#FIXME: code duplication\r
-FILE_DRIVERS=[]\r
-LOADED_DRIVERS=[]\r
-for driver_name in config['drivers']:\r
-    try:\r
-        driver=__import__(driver_name)\r
-        try:\r
-            eval('FILE_DRIVERS.append(driver.'+driver_name+'Driver)')\r
-        except:\r
-            pass\r
-    except ImportError:\r
-        print 'Cannot find driver ',driver_name\r
-    else:\r
-        LOADED_DRIVERS.append(driver_name)\r
-        print 'Imported driver ',driver_name\r
-config['loaded_drivers']=LOADED_DRIVERS\r
-\r
-#LIST OF CUSTOM WX EVENTS FOR CLI ---> GUI COMMUNICATION\r
-#FIXME: do they need to be here?\r
-list_of_events={}\r
-\r
-plot_graph, EVT_PLOT = NewEvent()\r
-list_of_events['plot_graph']=plot_graph\r
-\r
-plot_contact, EVT_PLOT_CONTACT = NewEvent()\r
-list_of_events['plot_contact']=plot_contact\r
-\r
-measure_points, EVT_MEASURE_POINTS = NewEvent()\r
-list_of_events['measure_points']=measure_points\r
-\r
-export_image, EVT_EXPORT_IMAGE = NewEvent()\r
-list_of_events['export_image']=export_image\r
-\r
-close_plot, EVT_CLOSE_PLOT = NewEvent()\r
-list_of_events['close_plot'] = close_plot\r
-\r
-show_plots, EVT_SHOW_PLOTS = NewEvent()\r
-list_of_events['show_plots'] = show_plots\r
-\r
-get_displayed_plot, EVT_GET_DISPLAYED_PLOT = NewEvent()\r
-list_of_events['get_displayed_plot'] = get_displayed_plot\r
-#------------\r
-\r
-class CliThread(Thread):\r
-\r
-    def __init__(self,frame,list_of_events):\r
-        Thread.__init__(self)\r
-\r
-        #here we have to put temporary references to pass to the cli object.\r
-        self.frame=frame\r
-        self.list_of_events=list_of_events\r
-\r
-        self.debug=0 #to be used in the future\r
-\r
-    def run(self):\r
-        print '\n\nThis is Hooke, version',__version__ , __release_name__\r
-        print\r
-        print '(c) Massimo Sandal & others, 2006-2008. Released under the GNU Lesser General Public License Version 3'\r
-        print 'Hooke is Free software.'\r
-        print '----'\r
-        print ''\r
+global __codename__\r
+global __releasedate__\r
+__version__ = lh.HOOKE_VERSION[0]\r
+__codename__ = lh.HOOKE_VERSION[1]\r
+__releasedate__ = lh.HOOKE_VERSION[2]\r
+__release_name__ = lh.HOOKE_VERSION[1]\r
+\r
+#TODO: add general preferences to Hooke\r
+#this might be useful\r
+#ID_Config = wx.NewId()\r
+ID_About = wx.NewId()\r
+ID_Next = wx.NewId()\r
+ID_Previous = wx.NewId()\r
+\r
+ID_ViewAssistant = wx.NewId()\r
+ID_ViewCommands = wx.NewId()\r
+ID_ViewFolders = wx.NewId()\r
+ID_ViewOutput = wx.NewId()\r
+ID_ViewPlaylists = wx.NewId()\r
+ID_ViewProperties = wx.NewId()\r
+ID_ViewResults = wx.NewId()\r
+\r
+ID_DeletePerspective = wx.NewId()\r
+ID_SavePerspective = wx.NewId()\r
+\r
+ID_FirstPerspective = ID_SavePerspective + 1000\r
+#I hope we'll never have more than 1000 perspectives\r
+ID_FirstPlot = ID_SavePerspective + 2000\r
+\r
+class Hooke(wx.App):\r
+\r
+    def OnInit(self):\r
+        self.SetAppName('Hooke')\r
+        self.SetVendorName('')\r
+\r
+        windowPosition = (config['main']['left'], config['main']['top'])\r
+        windowSize = (config['main']['width'], config['main']['height'])\r
+\r
+        #setup the splashscreen\r
+        if config['splashscreen']['show']:\r
+            filename = lh.get_file_path('hooke.jpg', ['resources'])\r
+            if os.path.isfile(filename):\r
+                bitmap = wx.Image(filename).ConvertToBitmap()\r
+                splashStyle = wx.SPLASH_CENTRE_ON_SCREEN|wx.SPLASH_TIMEOUT\r
+                splashDuration = config['splashscreen']['duration']\r
+                wx.SplashScreen(bitmap, splashStyle, splashDuration, None, -1)\r
+                wx.Yield()\r
+                '''\r
+                we need for the splash screen to disappear\r
+                for whatever reason splashDuration and sleep do not correspond to each other\r
+                at least not on Windows\r
+                maybe it's because duration is in milliseconds and sleep in seconds\r
+                thus we need to increase the sleep time a bit\r
+                a factor of 1.2 seems to work quite well\r
+                '''\r
+                sleepFactor = 1.2\r
+                time.sleep(sleepFactor * splashDuration / 1000)\r
+\r
+        plugin_objects = []\r
+        for plugin in config['plugins']:\r
+            if config['plugins'][plugin]:\r
+                filename = ''.join([plugin, '.py'])\r
+                path = lh.get_file_path(filename, ['plugins'])\r
+                if os.path.isfile(path):\r
+                    #get the corresponding filename and path\r
+                    plugin_name = ''.join(['plugins.', plugin])\r
+                    #import the module\r
+                    __import__(plugin_name)\r
+                    #get the file that contains the plugin\r
+                    class_file = getattr(plugins, plugin)\r
+                    #get the class that contains the commands\r
+                    class_object = getattr(class_file, plugin + 'Commands')\r
+                    plugin_objects.append(class_object)\r
 \r
         def make_command_class(*bases):\r
-            #FIXME: perhaps redundant\r
-            return type(HookeCli)("HookeCliPlugged", bases + (HookeCli,), {})\r
-        cli = make_command_class(*CLI_PLUGINS)(self.frame,self.list_of_events,events_from_gui,config,FILE_DRIVERS)\r
-        cli.cmdloop()\r
-\r
-'''\r
-GUI CODE\r
-\r
-FIXME: put it in a separate module in the future?\r
-'''\r
-class MainMenuBar(wx.MenuBar):\r
-    '''\r
-    Creates the menu bar\r
-    '''\r
-    def __init__(self):\r
-        wx.MenuBar.__init__(self)\r
-        '''the menu description. the key of the menu is XX&Menu, where XX is a number telling\r
-        the order of the menus on the menubar.\r
-        &Menu is the Menu text\r
-        the corresponding argument is ('&Item', 'itemname'), where &Item is the item text and itemname\r
-        the inner reference to use in the self.menu_items dictionary.\r
-\r
-        See create_menus() to see how it works\r
-\r
-        Note: the mechanism on page 124 of "wxPython in Action" is less awkward, maybe, but I want\r
-        binding to be performed later. Perhaps I'm wrong :)\r
-        ''' \r
-\r
-        self.menu_desc={'00&File':[('&Open playlist','openplaymenu'),('&Exit','exitmenu')], \r
-                        '01&Edit':[('&Export text...','exporttextmenu'),('&Export image...','exportimagemenu')],\r
-                        '02&Help':[('&About Hooke','aboutmenu')]}\r
-        self.create_menus()\r
-\r
-    def create_menus(self):\r
+            #create metaclass with plugins and plotmanipulators\r
+            return type(HookeFrame)("HookeFramePlugged", bases + (HookeFrame,), {})\r
+        frame = make_command_class(*plugin_objects)(parent=None, id=wx.ID_ANY, title='Hooke', pos=windowPosition, size=windowSize)\r
+        frame.Show(True)\r
+        self.SetTopWindow(frame)\r
+\r
+        return True\r
+\r
+    def OnExit(self):\r
+        return True\r
+\r
+\r
+class HookeFrame(wx.Frame):\r
+\r
+    def __init__(self, parent, id=-1, title='', pos=wx.DefaultPosition, size=wx.DefaultSize, style=wx.DEFAULT_FRAME_STYLE|wx.SUNKEN_BORDER|wx.CLIP_CHILDREN):\r
+        #call parent constructor\r
+        wx.Frame.__init__(self, parent, id, title, pos, size, style)\r
+        self.config = config\r
+        self.CreateApplicationIcon()\r
+        #self.configs contains: {the name of the Commands file: corresponding ConfigObj}\r
+        self.configs = {}\r
+        #self.displayed_plot holds the currently displayed plot\r
+        self.displayed_plot = None\r
+        #self.playlists contains: {the name of the playlist: [playlist, tabIndex, plotID]}\r
+        self.playlists = {}\r
+        #list of all plotmanipulators\r
+        self.plotmanipulators = []\r
+        #self.plugins contains: {the name of the plugin: [caption, function]}\r
+        self.plugins = {}\r
+\r
+        #tell FrameManager to manage this frame\r
+        self._mgr = aui.AuiManager()\r
+        self._mgr.SetManagedWindow(self)\r
+        #set the gradient style\r
+        self._mgr.GetArtProvider().SetMetric(aui.AUI_DOCKART_GRADIENT_TYPE, aui.AUI_GRADIENT_NONE)\r
+        #set transparent drag\r
+        self._mgr.SetFlags(self._mgr.GetFlags() ^ aui.AUI_MGR_TRANSPARENT_DRAG)\r
+\r
+        # set up default notebook style\r
+        self._notebook_style = aui.AUI_NB_DEFAULT_STYLE | aui.AUI_NB_TAB_EXTERNAL_MOVE | wx.NO_BORDER\r
+        self._notebook_theme = 0\r
+\r
+        #holds the perspectives: {name, perspective_str}\r
+        self._perspectives = {}\r
+\r
+        # min size for the frame itself isn't completely done.\r
+        # see the end up FrameManager::Update() for the test\r
+        # code. For now, just hard code a frame minimum size\r
+        self.SetMinSize(wx.Size(500, 500))\r
+        #create panels here\r
+        self.panelAssistant = self.CreatePanelAssistant()\r
+        self.panelCommands = self.CreatePanelCommands()\r
+        self.panelFolders = self.CreatePanelFolders()\r
+        self.panelPlaylists = self.CreatePanelPlaylists()\r
+        self.panelProperties = self.CreatePanelProperties()\r
+        self.panelOutput = self.CreatePanelOutput()\r
+        self.panelResults = self.CreatePanelResults()\r
+        self.plotNotebook = self.CreateNotebook()\r
+        #self.textCtrlCommandLine=self.CreateCommandLine()\r
+\r
+        # add panes\r
+        self._mgr.AddPane(self.panelFolders, aui.AuiPaneInfo().Name('Folders').Caption('Folders').Left().CloseButton(True).MaximizeButton(False))\r
+        self._mgr.AddPane(self.panelPlaylists, aui.AuiPaneInfo().Name('Playlists').Caption('Playlists').Left().CloseButton(True).MaximizeButton(False))\r
+        self._mgr.AddPane(self.plotNotebook, aui.AuiPaneInfo().Name('Plots').CenterPane().PaneBorder(False))\r
+        self._mgr.AddPane(self.panelCommands, aui.AuiPaneInfo().Name('Commands').Caption('Settings and commands').Right().CloseButton(True).MaximizeButton(False))\r
+        self._mgr.AddPane(self.panelProperties, aui.AuiPaneInfo().Name('Properties').Caption('Properties').Right().CloseButton(True).MaximizeButton(False))\r
+        self._mgr.AddPane(self.panelAssistant, aui.AuiPaneInfo().Name('Assistant').Caption('Assistant').Right().CloseButton(True).MaximizeButton(False))\r
+        self._mgr.AddPane(self.panelOutput, aui.AuiPaneInfo().Name('Output').Caption('Output').Bottom().CloseButton(True).MaximizeButton(False))\r
+        self._mgr.AddPane(self.panelResults, aui.AuiPaneInfo().Name('Results').Caption('Results').Bottom().CloseButton(True).MaximizeButton(False))\r
+        #self._mgr.AddPane(self.textCtrlCommandLine, aui.AuiPaneInfo().Name('CommandLine').CaptionVisible(False).Fixed().Bottom().Layer(2).CloseButton(False).MaximizeButton(False))\r
+        #self._mgr.AddPane(panelBottom, aui.AuiPaneInfo().Name("panelCommandLine").Bottom().Position(1).CloseButton(False).MaximizeButton(False))\r
+\r
+        # add the toolbars to the manager\r
+        #self.toolbar=self.CreateToolBar()\r
+        self.toolbarNavigation=self.CreateToolBarNavigation()\r
+        #self._mgr.AddPane(self.toolbar, aui.AuiPaneInfo().Name('toolbar').Caption('Toolbar').ToolbarPane().Top().Layer(1).Row(1).LeftDockable(False).RightDockable(False))\r
+        self._mgr.AddPane(self.toolbarNavigation, aui.AuiPaneInfo().Name('toolbarNavigation').Caption('Navigation').ToolbarPane().Top().Layer(1).Row(1).LeftDockable(False).RightDockable(False))\r
+        # "commit" all changes made to FrameManager\r
+        self._mgr.Update()\r
+        #create the menubar after the panes so that the default perspective\r
+        #is created with all panes open\r
+        self.CreateMenuBar()\r
+        self.statusbar = self.CreateStatusbar()\r
+        self._BindEvents()\r
+\r
+        name = self.config['perspectives']['active']\r
+        menu_item = self.GetPerspectiveMenuItem(name)\r
+        if menu_item is not None:\r
+            self.OnRestorePerspective(menu_item)\r
+            #TODO: config setting to remember playlists from last session\r
+        self.playlists = self.panelPlaylists.Playlists\r
+        #define the list of active drivers\r
+        self.drivers = []\r
+        for driver in self.config['drivers']:\r
+            if self.config['drivers'][driver]:\r
+                #get the corresponding filename and path\r
+                filename = ''.join([driver, '.py'])\r
+                path = lh.get_file_path(filename, ['drivers'])\r
+                #the driver is active for driver[1] == 1\r
+                if os.path.isfile(path):\r
+                    #driver files are located in the 'drivers' subfolder\r
+                    driver_name = ''.join(['drivers.', driver])\r
+                    __import__(driver_name)\r
+                    class_file = getattr(drivers, driver)\r
+                    for command in dir(class_file):\r
+                        if command.endswith('Driver'):\r
+                            self.drivers.append(getattr(class_file, command))\r
+        #import all active plugins and plotmanips\r
+        #add 'core.ini' to self.configs (this is not a plugin and thus must be imported separately)\r
+        ini_path = lh.get_file_path('core.ini', ['plugins'])\r
+        plugin_config = ConfigObj(ini_path)\r
+        #self.config.merge(plugin_config)\r
+        self.configs['core'] = plugin_config\r
+        #make sure we execute _plug_init() for every command line plugin we import\r
+        for plugin in self.config['plugins']:\r
+            if self.config['plugins'][plugin]:\r
+                filename = ''.join([plugin, '.py'])\r
+                path = lh.get_file_path(filename, ['plugins'])\r
+                if os.path.isfile(path):\r
+                    #get the corresponding filename and path\r
+                    plugin_name = ''.join(['plugins.', plugin])\r
+                    try:\r
+                        #import the module\r
+                        module = __import__(plugin_name)\r
+                        #prepare the ini file for inclusion\r
+                        ini_path = path.replace('.py', '.ini')\r
+                        #include ini file\r
+                        plugin_config = ConfigObj(ini_path)\r
+                        #self.config.merge(plugin_config)\r
+                        self.configs[plugin] = plugin_config\r
+                        #add to plugins\r
+                        commands = eval('dir(module.' + plugin+ '.' + plugin + 'Commands)')\r
+                        #keep only commands (ie names that start with 'do_')\r
+                        #TODO: check for existing commands and warn the user!\r
+                        commands = [command for command in commands if command.startswith('do_')]\r
+                        if commands:\r
+                            self.plugins[plugin] = commands\r
+                        try:\r
+                            #initialize the plugin\r
+                            eval('module.' + plugin+ '.' + plugin + 'Commands._plug_init(self)')\r
+                        except AttributeError:\r
+                            pass\r
+                    except ImportError:\r
+                        pass\r
+        #initialize the commands tree\r
+        commands = dir(HookeFrame)\r
+        commands = [command for command in commands if command.startswith('do_')]\r
+        if commands:\r
+            self.plugins['core'] = commands\r
+        self.panelCommands.Initialize(self.plugins)\r
+        for command in dir(self):\r
+            if command.startswith('plotmanip_'):\r
+                self.plotmanipulators.append(lib.plotmanipulator.Plotmanipulator(method=getattr(self, command), command=command))\r
+\r
+        #load default list, if possible\r
+        self.do_loadlist(self.config['core']['list'])\r
+        #self.do_loadlist()\r
+\r
+    def _BindEvents(self):\r
+        #TODO: figure out if we can use the eventManager for menu ranges\r
+        #and events of 'self' without raising an assertion fail error\r
+        self.Bind(wx.EVT_ERASE_BACKGROUND, self.OnEraseBackground)\r
+        self.Bind(wx.EVT_SIZE, self.OnSize)\r
+        self.Bind(wx.EVT_CLOSE, self.OnClose)\r
+        # Show How To Use The Closing Panes Event\r
+        self.Bind(aui.EVT_AUI_PANE_CLOSE, self.OnPaneClose)\r
+        self.Bind(aui.EVT_AUINOTEBOOK_PAGE_CLOSE, self.OnNotebookPageClose)\r
+        #menu\r
+        evtmgr.eventManager.Register(self.OnAbout, wx.EVT_MENU, win=self, id=wx.ID_ABOUT)\r
+        evtmgr.eventManager.Register(self.OnClose, wx.EVT_MENU, win=self, id=wx.ID_EXIT)\r
+        #view\r
+        self.Bind(wx.EVT_MENU_RANGE, self.OnView, id=ID_ViewAssistant, id2=ID_ViewResults)\r
+        #perspectives\r
+        self.Bind(wx.EVT_MENU, self.OnDeletePerspective, id=ID_DeletePerspective)\r
+        self.Bind(wx.EVT_MENU, self.OnSavePerspective, id=ID_SavePerspective)\r
+        self.Bind(wx.EVT_MENU_RANGE, self.OnRestorePerspective, id=ID_FirstPerspective, id2=ID_FirstPerspective+1000)\r
+        #toolbar\r
+        evtmgr.eventManager.Register(self.OnNext, wx.EVT_TOOL, win=self, id=ID_Next)\r
+        evtmgr.eventManager.Register(self.OnPrevious, wx.EVT_TOOL, win=self, id=ID_Previous)\r
+        #self.Bind(.EVT_AUITOOLBAR_TOOL_DROPDOWN, self.OnDropDownToolbarItem, id=ID_DropDownToolbarItem)\r
+        #dir control\r
+        treeCtrl = self.panelFolders.GetTreeCtrl()\r
+        #tree.Bind(wx.EVT_LEFT_UP, self.OnDirCtrl1LeftUp)\r
+        #tree.Bind(wx.EVT_LEFT_DOWN, self.OnGenericDirCtrl1LeftDown)\r
+        treeCtrl.Bind(wx.EVT_LEFT_DCLICK, self.OnDirCtrlLeftDclick)\r
+        #playlist tree\r
+        self.panelPlaylists.PlaylistsTree.Bind(wx.EVT_LEFT_DOWN, self.OnPlaylistsLeftDown)\r
+        self.panelPlaylists.PlaylistsTree.Bind(wx.EVT_LEFT_DCLICK, self.OnPlaylistsLeftDclick)\r
+        #commands tree\r
+        evtmgr.eventManager.Register(self.OnExecute, wx.EVT_BUTTON, self.panelCommands.ExecuteButton)\r
+        evtmgr.eventManager.Register(self.OnTreeCtrlCommandsSelectionChanged, wx.EVT_TREE_SEL_CHANGED, self.panelCommands.CommandsTree)\r
+        evtmgr.eventManager.Register(self.OnTreeCtrlItemActivated, wx.EVT_TREE_ITEM_ACTIVATED, self.panelCommands.CommandsTree)\r
+        #property editor\r
+        self.panelProperties.pg.Bind(wxpg.EVT_PG_CHANGED, self.OnPropGridChanged)\r
+        #results panel\r
+        self.panelResults.results_list.OnCheckItem = self.OnResultsCheck\r
+\r
+    def _GetActiveFileIndex(self):\r
+        lib.playlist.Playlist = self.GetActivePlaylist()\r
+        #get the selected item from the tree\r
+        selected_item = self.panelPlaylists.PlaylistsTree.GetSelection()\r
+        #test if a playlist or a curve was double-clicked\r
+        if self.panelPlaylists.PlaylistsTree.ItemHasChildren(selected_item):\r
+            return -1\r
+        else:\r
+            count = 0\r
+            selected_item = self.panelPlaylists.PlaylistsTree.GetPrevSibling(selected_item)\r
+            while selected_item.IsOk():\r
+                count += 1\r
+                selected_item = self.panelPlaylists.PlaylistsTree.GetPrevSibling(selected_item)\r
+            return count\r
+\r
+    def _GetPlaylistTab(self, name):\r
+        for index, page in enumerate(self.plotNotebook._tabs._pages):\r
+            if page.caption == name:\r
+                return index\r
+        return -1\r
+\r
+    def _GetUniquePlaylistName(self, name):\r
+        playlist_name = name\r
+        count = 1\r
+        while playlist_name in self.playlists:\r
+            playlist_name = ''.join([name, str(count)])\r
+            count += 1\r
+        return playlist_name\r
+\r
+    def _RestorePerspective(self, name):\r
+        self._mgr.LoadPerspective(self._perspectives[name])\r
+        self.config['perspectives']['active'] = name\r
+        self._mgr.Update()\r
+        all_panes = self._mgr.GetAllPanes()\r
+        for pane in all_panes:\r
+            if not pane.name.startswith('toolbar'):\r
+                if pane.name == 'Assistant':\r
+                    self.MenuBar.FindItemById(ID_ViewAssistant).Check(pane.window.IsShown())\r
+                if pane.name == 'Folders':\r
+                    self.MenuBar.FindItemById(ID_ViewFolders).Check(pane.window.IsShown())\r
+                if pane.name == 'Playlists':\r
+                    self.MenuBar.FindItemById(ID_ViewPlaylists).Check(pane.window.IsShown())\r
+                if pane.name == 'Commands':\r
+                    self.MenuBar.FindItemById(ID_ViewCommands).Check(pane.window.IsShown())\r
+                if pane.name == 'Properties':\r
+                    self.MenuBar.FindItemById(ID_ViewProperties).Check(pane.window.IsShown())\r
+                if pane.name == 'Output':\r
+                    self.MenuBar.FindItemById(ID_ViewOutput).Check(pane.window.IsShown())\r
+                if pane.name == 'Results':\r
+                    self.MenuBar.FindItemById(ID_ViewResults).Check(pane.window.IsShown())\r
+\r
+    def _SavePerspectiveToFile(self, name, perspective):\r
+        filename = ''.join([name, '.txt'])\r
+        filename = lh.get_file_path(filename, ['perspectives'])\r
+        perspectivesFile = open(filename, 'w')\r
+        perspectivesFile.write(perspective)\r
+        perspectivesFile.close()\r
+\r
+    def _UnbindEvents(self):\r
+        #menu\r
+        evtmgr.eventManager.DeregisterListener(self.OnAbout)\r
+        evtmgr.eventManager.DeregisterListener(self.OnClose)\r
+        #toolbar\r
+        evtmgr.eventManager.DeregisterListener(self.OnNext)\r
+        evtmgr.eventManager.DeregisterListener(self.OnPrevious)\r
+        #commands tree\r
+        evtmgr.eventManager.DeregisterListener(self.OnExecute)\r
+        evtmgr.eventManager.DeregisterListener(self.OnTreeCtrlCommandsSelectionChanged)\r
+\r
+    def AddPlaylist(self, playlist=None, name='Untitled'):\r
+        if playlist and playlist.count > 0:\r
+            playlist.name = self._GetUniquePlaylistName(name)\r
+            playlist.reset()\r
+            self.AddToPlaylists(playlist)\r
+\r
+    def AddPlaylistFromFiles(self, files=[], name='Untitled'):\r
+        if files:\r
+            playlist = lib.playlist.Playlist(self, self.drivers)\r
+            for item in files:\r
+                playlist.add_curve(item)\r
+        if playlist.count > 0:\r
+            playlist.name = self._GetUniquePlaylistName(name)\r
+            playlist.reset()\r
+            self.AddTayliss(playlist)\r
+\r
+    def AddToPlaylists(self, playlist):\r
+        if playlist.count > 0:\r
+            #setup the playlist in the Playlist tree\r
+            tree_root = self.panelPlaylists.PlaylistsTree.GetRootItem()\r
+            playlist_root = self.panelPlaylists.PlaylistsTree.AppendItem(tree_root, playlist.name, 0)\r
+            #add all files to the Playlist tree\r
+#            files = {}\r
+            for index, file_to_add in enumerate(playlist.files):\r
+                #TODO: optionally remove the extension from the name of the curve\r
+                #item_text, extension = os.path.splitext(curve.name)\r
+                #curve_ID = self.panelPlaylists.PlaylistsTree.AppendItem(playlist_root, item_text, 1)\r
+                file_ID = self.panelPlaylists.PlaylistsTree.AppendItem(playlist_root, file_to_add.name, 1)\r
+                if index == playlist.index:\r
+                    self.panelPlaylists.PlaylistsTree.SelectItem(file_ID)\r
+            playlist.reset()\r
+            #create the plot tab and add playlist to the dictionary\r
+            plotPanel = panels.plot.PlotPanel(self, ID_FirstPlot + len(self.playlists))\r
+            notebook_tab = self.plotNotebook.AddPage(plotPanel, playlist.name, True)\r
+            #tab_index = self.plotNotebook.GetSelection()\r
+            playlist.figure = plotPanel.get_figure()\r
+            self.playlists[playlist.name] = playlist\r
+            #self.playlists[playlist.name] = [playlist, figure]\r
+            self.panelPlaylists.PlaylistsTree.Expand(playlist_root)\r
+            self.statusbar.SetStatusText(playlist.get_status_string(), 0)\r
+            self.UpdatePlot()\r
+\r
+    def AppendToOutput(self, text):\r
+        self.panelOutput.AppendText(''.join([text, '\n']))\r
+\r
+    def AppliesPlotmanipulator(self, name):\r
         '''\r
-        Smartish routine to create the menu from the self.menu_desc dictionary\r
-        Hope it's a workable solution for the future.\r
+        returns True if the plotmanipulator 'name' is applied, False otherwise\r
+        name does not contain 'plotmanip_', just the name of the plotmanipulator (e.g. 'flatten')\r
         '''\r
-        self.menus=[] #the menu objects to append to the menubar\r
-        self.menu_items={} #the single menu items dictionary, to bind to events\r
-\r
-        names=self.menu_desc.keys() #we gotta sort, because iterating keys goes in odd order\r
-        names.sort()\r
-\r
-        for name in names:\r
-            self.menus.append(wx.Menu())\r
-            for menu_item in self.menu_desc[name]:\r
-                self.menu_items[menu_item[1]]=self.menus[-1].Append(-1, menu_item[0])\r
-\r
-        for menu,name in zip(self.menus,names):\r
-            self.Append(menu,name[2:])\r
-\r
-class MainPanel(wx.Panel):\r
-    def __init__(self,parent,id):  \r
-\r
-        wx.Panel.__init__(self,parent,id)\r
-        self.splitter = wx.SplitterWindow(self)\r
-\r
-ID_FRAME=100        \r
-class MainWindow(wx.Frame):\r
-    '''we make a frame inheriting wx.Frame and setting up things on the init'''\r
-    def __init__(self,parent,id,title):\r
-\r
-        #-----------------------------\r
-        #WX WIDGETS INITIALIZATION\r
-\r
-        wx.Frame.__init__(self,parent,ID_FRAME,title,size=(800,600),style=wx.DEFAULT_FRAME_STYLE|wx.NO_FULL_REPAINT_ON_RESIZE)\r
-\r
-        self.mainpanel=MainPanel(self,-1)\r
-        self.cpanels=[]\r
-\r
-        self.cpanels.append(wx.Panel(self.mainpanel.splitter,-1))\r
-        self.cpanels.append(wx.Panel(self.mainpanel.splitter,-1))\r
-\r
-        self.statusbar=wx.StatusBar(self,-1)\r
-        self.SetStatusBar(self.statusbar)\r
-\r
-        self.mainmenubar=MainMenuBar()\r
-        self.SetMenuBar(self.mainmenubar)\r
-\r
-        self.controls=[]\r
-        self.figures=[]\r
-        self.axes=[]\r
-\r
-        #This is our matplotlib plot\r
-        self.controls.append(wxmpl.PlotPanel(self.cpanels[0],-1))\r
-        self.controls.append(wxmpl.PlotPanel(self.cpanels[1],-1))\r
-        #These are our figure and axes, so to have easy references\r
-        #Also, we initialize\r
-        self.figures=[control.get_figure() for control in self.controls]\r
-        self.axes=[figure.gca() for figure in self.figures]\r
+        return self.GetBoolFromConfig('core', 'plotmanipulators', name)\r
+\r
+    def CreateApplicationIcon(self):\r
+        iconFile = 'resources' + os.sep + 'microscope.ico'\r
+        icon = wx.Icon(iconFile, wx.BITMAP_TYPE_ICO)\r
+        self.SetIcon(icon)\r
+\r
+    def CreateCommandLine(self):\r
+        return wx.TextCtrl(self, -1, '', style=wx.NO_BORDER|wx.EXPAND)\r
+\r
+    def CreatePanelAssistant(self):\r
+        panel = wx.TextCtrl(self, -1, '', wx.Point(0, 0), wx.Size(150, 90), wx.NO_BORDER|wx.TE_MULTILINE)\r
+        panel.SetEditable(False)\r
+        return panel\r
+\r
+    def CreatePanelCommands(self):\r
+        return panels.commands.Commands(self)\r
+\r
+    def CreatePanelFolders(self):\r
+        #set file filters\r
+        filters = self.config['folders']['filters']\r
+        index = self.config['folders'].as_int('filterindex')\r
+        #set initial directory\r
+        folder = self.config['core']['workdir']\r
+        return wx.GenericDirCtrl(self, -1, dir=folder, size=(200, 250), style=wx.DIRCTRL_SHOW_FILTERS, filter=filters, defaultFilter=index)\r
+\r
+    def CreatePanelOutput(self):\r
+        return wx.TextCtrl(self, -1, '', wx.Point(0, 0), wx.Size(150, 90), wx.NO_BORDER|wx.TE_MULTILINE)\r
+\r
+    def CreatePanelPlaylists(self):\r
+        return panels.playlist.Playlists(self)\r
+\r
+    def CreatePanelProperties(self):\r
+        return panels.propertyeditor.PropertyEditor(self)\r
+\r
+    def CreatePanelResults(self):\r
+        return panels.results.Results(self)\r
+\r
+    def CreatePanelWelcome(self):\r
+        #TODO: move into panels.welcome\r
+        ctrl = wx.html.HtmlWindow(self, -1, wx.DefaultPosition, wx.Size(400, 300))\r
+        introStr = '<h1>Welcome to Hooke</h1>' + \\r
+                 '<h3>Features</h3>' + \\r
+                 '<ul>' + \\r
+                 '<li>View, annotate, measure force files</li>' + \\r
+                 '<li>Worm-like chain fit of force peaks</li>' + \\r
+                 '<li>Automatic convolution-based filtering of empty files</li>' + \\r
+                 '<li>Automatic fit and measurement of multiple force peaks</li>' + \\r
+                 '<li>Handles force-clamp force experiments (experimental)</li>' + \\r
+                 '<li>It is extensible by users by means of plugins and drivers</li>' + \\r
+                 '</ul>' + \\r
+                 '<p>See the <a href="http://code.google.com/p/hooke/wiki/DocumentationIndex">DocumentationIndex</a> for more information</p>'\r
+        ctrl.SetPage(introStr)\r
+        return ctrl\r
+\r
+    def CreateMenuBar(self):\r
+        menu_bar = wx.MenuBar()\r
+        self.SetMenuBar(menu_bar)\r
+        #file\r
+        file_menu = wx.Menu()\r
+        file_menu.Append(wx.ID_EXIT, 'Exit\tCtrl-Q')\r
+#        edit_menu.AppendSeparator();\r
+#        edit_menu.Append(ID_Config, 'Preferences')\r
+        #view\r
+        view_menu = wx.Menu()\r
+        view_menu.AppendCheckItem(ID_ViewFolders, 'Folders\tF5')\r
+        view_menu.AppendCheckItem(ID_ViewPlaylists, 'Playlists\tF6')\r
+        view_menu.AppendCheckItem(ID_ViewCommands, 'Commands\tF7')\r
+        view_menu.AppendCheckItem(ID_ViewProperties, 'Properties\tF8')\r
+        view_menu.AppendCheckItem(ID_ViewAssistant, 'Assistant\tF9')\r
+        view_menu.AppendCheckItem(ID_ViewResults, 'Results\tF10')\r
+        view_menu.AppendCheckItem(ID_ViewOutput, 'Output\tF11')\r
+        #perspectives\r
+#        perspectives_menu = self.CreatePerspectivesMenu()\r
+        perspectives_menu = wx.Menu()\r
+\r
+        #help\r
+        help_menu = wx.Menu()\r
+        help_menu.Append(wx.ID_ABOUT, 'About Hooke')\r
+        #put it all together\r
+        menu_bar.Append(file_menu, 'File')\r
+#        menu_bar.Append(edit_menu, 'Edit')\r
+        menu_bar.Append(view_menu, 'View')\r
+        menu_bar.Append(perspectives_menu, "Perspectives")\r
+        self.UpdatePerspectivesMenu()\r
+        menu_bar.Append(help_menu, 'Help')\r
+\r
+    def CreateNotebook(self):\r
+        # create the notebook off-window to avoid flicker\r
+        client_size = self.GetClientSize()\r
+        ctrl = aui.AuiNotebook(self, -1, wx.Point(client_size.x, client_size.y), wx.Size(430, 200), self._notebook_style)\r
+        arts = [aui.AuiDefaultTabArt, aui.AuiSimpleTabArt, aui.VC71TabArt, aui.FF2TabArt, aui.VC8TabArt, aui.ChromeTabArt]\r
+        art = arts[self._notebook_theme]()\r
+        ctrl.SetArtProvider(art)\r
+        #uncomment if we find a nice icon\r
+        #page_bmp = wx.ArtProvider.GetBitmap(wx.ART_NORMAL_FILE, wx.ART_OTHER, wx.Size(16, 16))\r
+        ctrl.AddPage(self.CreatePanelWelcome(), "Welcome", False)\r
+        return ctrl\r
+\r
+    def CreateStatusbar(self):\r
+        statusbar = self.CreateStatusBar(2, wx.ST_SIZEGRIP)\r
+        statusbar.SetStatusWidths([-2, -3])\r
+        statusbar.SetStatusText('Ready', 0)\r
+        welcomeString=u'Welcome to Hooke (version '+__version__+', '+__release_name__+')!'\r
+        statusbar.SetStatusText(welcomeString, 1)\r
+        return statusbar\r
+\r
+    def CreateToolBarNavigation(self):\r
+        toolbar = wx.ToolBar(self, -1, wx.DefaultPosition, wx.DefaultSize, wx.TB_FLAT | wx.TB_NODIVIDER)\r
+        toolbar.SetToolBitmapSize(wx.Size(16,16))\r
+        toolbar_bmpBack = wx.ArtProvider_GetBitmap(wx.ART_GO_BACK, wx.ART_OTHER, wx.Size(16, 16))\r
+        toolbar_bmpForward = wx.ArtProvider_GetBitmap(wx.ART_GO_FORWARD, wx.ART_OTHER, wx.Size(16, 16))\r
+        toolbar.AddLabelTool(ID_Previous, 'Previous', toolbar_bmpBack, shortHelp='Previous curve')\r
+        toolbar.AddLabelTool(ID_Next, 'Next', toolbar_bmpForward, shortHelp='Next curve')\r
+        toolbar.Realize()\r
+        return toolbar\r
+\r
+    def DeleteFromPlaylists(self, name):\r
+        if name in self.playlists:\r
+            del self.playlists[name]\r
+        tree_root = self.panelPlaylists.PlaylistsTree.GetRootItem()\r
+        item, cookie = self.panelPlaylists.PlaylistsTree.GetFirstChild(tree_root)\r
+        while item.IsOk():\r
+            playlist_name = self.panelPlaylists.PlaylistsTree.GetItemText(item)\r
+            if playlist_name == name:\r
+                try:\r
+                    self.panelPlaylists.PlaylistsTree.Delete(item)\r
+                except:\r
+                    pass\r
+            item = self.panelPlaylists.PlaylistsTree.GetNextSibling(item)\r
+\r
+    def GetActiveFigure(self):\r
+        playlist_name = self.GetActivePlaylistName()\r
+        figure = self.playlists[playlist_name].figure\r
+        if figure is not None:\r
+            return figure\r
+        return None\r
+\r
+    def GetActiveFile(self):\r
+        playlist = self.GetActivePlaylist()\r
+        if playlist is not None:\r
+            return playlist.get_active_file()\r
+        return None\r
+\r
+    def GetActivePlaylist(self):\r
+        playlist_name = self.GetActivePlaylistName()\r
+        if playlist_name in self.playlists:\r
+            return self.playlists[playlist_name]\r
+        return None\r
+\r
+    def GetActivePlaylistName(self):\r
+        #get the selected item from the tree\r
+        selected_item = self.panelPlaylists.PlaylistsTree.GetSelection()\r
+        #test if a playlist or a curve was double-clicked\r
+        if self.panelPlaylists.PlaylistsTree.ItemHasChildren(selected_item):\r
+            playlist_item = selected_item\r
+        else:\r
+            #get the name of the playlist\r
+            playlist_item = self.panelPlaylists.PlaylistsTree.GetItemParent(selected_item)\r
+        #now we have a playlist\r
+        return self.panelPlaylists.PlaylistsTree.GetItemText(playlist_item)\r
+\r
+    def GetActivePlot(self):\r
+        playlist = self.GetActivePlaylist()\r
+        if playlist is not None:\r
+            return playlist.get_active_file().plot\r
+        return None\r
+\r
+    def GetDisplayedPlot(self):\r
+        plot = copy.deepcopy(self.displayed_plot)\r
+        plot.curves = []\r
+        plot.curves = copy.deepcopy(plot.curves)\r
+        return plot\r
 \r
-        self.cpanels[1].Hide()\r
-        self.mainpanel.splitter.Initialize(self.cpanels[0])\r
+    def GetDisplayedPlotCorrected(self):\r
+        plot = copy.deepcopy(self.displayed_plot)\r
+        plot.curves = []\r
+        plot.curves = copy.deepcopy(plot.corrected_curves)\r
+        return plot\r
 \r
-        self.sizer_dance() #place/size the widgets\r
+    def GetDisplayedPlotRaw(self):\r
+        plot = copy.deepcopy(self.displayed_plot)\r
+        plot.curves = []\r
+        plot.curves = copy.deepcopy(plot.raw_curves)\r
+        return plot\r
 \r
-        self.controls[0].SetSize(self.cpanels[0].GetSize())\r
-        self.controls[1].SetSize(self.cpanels[1].GetSize())\r
+    def GetDockArt(self):\r
+        return self._mgr.GetArtProvider()\r
+\r
+    def GetBoolFromConfig(self, *args):\r
+        if len(args) == 2:\r
+            plugin = args[0]\r
+            section = args[0]\r
+            key = args[1]\r
+        elif len(args) == 3:\r
+            plugin = args[0]\r
+            section = args[1]\r
+            key = args[2]\r
+        if self.configs.has_key(plugin):\r
+            config = self.configs[plugin]\r
+            return config[section][key].as_bool('value')\r
+        return None\r
+\r
+    def GetColorFromConfig(self, *args):\r
+        if len(args) == 2:\r
+            plugin = args[0]\r
+            section = args[0]\r
+            key = args[1]\r
+        elif len(args) == 3:\r
+            plugin = args[0]\r
+            section = args[1]\r
+            key = args[2]\r
+        if self.configs.has_key(plugin):\r
+            config = self.configs[plugin]\r
+            color_tuple = eval(config[section][key]['value'])\r
+            color = [value / 255.0 for value in color_tuple]\r
+            return color\r
+        return None\r
+\r
+    def GetFloatFromConfig(self, *args):\r
+        if len(args) == 2:\r
+            plugin = args[0]\r
+            section = args[0]\r
+            key = args[1]\r
+        elif len(args) == 3:\r
+            plugin = args[0]\r
+            section = args[1]\r
+            key = args[2]\r
+        if self.configs.has_key(plugin):\r
+            config = self.configs[plugin]\r
+            return config[section][key].as_float('value')\r
+        return None\r
+\r
+    def GetIntFromConfig(self, *args):\r
+        if len(args) == 2:\r
+            plugin = args[0]\r
+            section = args[0]\r
+            key = args[1]\r
+        elif len(args) == 3:\r
+            plugin = args[0]\r
+            section = args[1]\r
+            key = args[2]\r
+        if self.configs.has_key(plugin):\r
+            config = self.configs[plugin]\r
+            return config[section][key].as_int('value')\r
+        return None\r
+\r
+    def GetStringFromConfig(self, *args):\r
+        if len(args) == 2:\r
+            plugin = args[0]\r
+            section = args[0]\r
+            key = args[1]\r
+        elif len(args) == 3:\r
+            plugin = args[0]\r
+            section = args[1]\r
+            key = args[2]\r
+        if self.configs.has_key(plugin):\r
+            config = self.configs[plugin]\r
+            return config[section][key]['value']\r
+        return None\r
+\r
+    def GetPerspectiveMenuItem(self, name):\r
+        if self._perspectives.has_key(name):\r
+            perspectives_list = [key for key, value in self._perspectives.iteritems()]\r
+            perspectives_list.sort()\r
+            index = perspectives_list.index(name)\r
+            perspective_Id = ID_FirstPerspective + index\r
+            menu_item = self.MenuBar.FindItemById(perspective_Id)\r
+            return menu_item\r
+        else:\r
+            return None\r
 \r
-        #resize the frame to properly draw on Windows\r
-        frameSize=self.GetSize()\r
-        frameSize.DecBy(1, 1)\r
-        self.SetSize(frameSize)\r
+    def HasPlotmanipulator(self, name):\r
         '''\r
-        #if you need the exact same size as before DecBy, uncomment this block\r
-        frameSize.IncBy(1, 1)\r
-        self.SetSize(frameSize)\r
+        returns True if the plotmanipulator 'name' is loaded, False otherwise\r
         '''\r
-\r
-        #-------------------------------------------\r
-        #NON-WX WIDGETS INITIALIZATION\r
-\r
-        #Flags.\r
-        self.click_plot=0\r
-\r
-        #FIXME: These could become a single flag with different (string?) values\r
-        #self.on_measure_distance=False\r
-        #self.on_measure_force=False\r
-\r
-        self.plot_fit=False\r
-\r
-        #Number of points to be clicked\r
-        self.num_of_points = 2\r
-\r
-        #Data.\r
+        for plotmanipulator in self.plotmanipulators:\r
+            if plotmanipulator.command == name:\r
+                return True\r
+        return False\r
+\r
+    def OnAbout(self, event):\r
+        message = 'Hooke\n\n'+\\r
+            'A free, open source data analysis platform\n\n'+\\r
+            'Copyright 2006-2008 by Massimo Sandal\n'+\\r
+            'Copyright 2010 by Dr. Rolf Schmidt\n\n'+\\r
+            'Hooke is released under the GNU General Public License version 2.'\r
+        dialog = wx.MessageDialog(self, message, 'About Hooke', wx.OK | wx.ICON_INFORMATION)\r
+        dialog.ShowModal()\r
+        dialog.Destroy()\r
+\r
+    def OnClose(self, event):\r
+        #apply changes\r
+        self.config['main']['height'] = str(self.GetSize().GetHeight())\r
+        self.config['main']['left'] = str(self.GetPosition()[0])\r
+        self.config['main']['top'] = str(self.GetPosition()[1])\r
+        self.config['main']['width'] = str(self.GetSize().GetWidth())\r
+        #save the configuration file to 'config/hooke.ini'\r
+        self.config.write()\r
+        #save all plugin config files\r
+        for config in self.configs:\r
+            plugin_config = self.configs[config]\r
+            plugin_config.write()\r
+        self._UnbindEvents()\r
+        self._mgr.UnInit()\r
+        del self._mgr\r
+        self.Destroy()\r
+\r
+    def OnDeletePerspective(self, event):\r
+        dialog = panels.perspectives.Perspectives(self, -1, 'Delete perspective(s)')\r
+        dialog.CenterOnScreen()\r
+        dialog.ShowModal()\r
+        dialog.Destroy()\r
+        self.UpdatePerspectivesMenu()\r
+        #unfortunately, there is a bug in wxWidgets (Ticket #3258) that\r
+        #makes the radio item indicator in the menu disappear\r
+        #the code should be fine once this issue is fixed\r
+\r
+    def OnDirCtrlLeftDclick(self, event):\r
+        file_path = self.panelFolders.GetPath()\r
+        if os.path.isfile(file_path):\r
+            if file_path.endswith('.hkp'):\r
+                self.do_loadlist(file_path)\r
+        event.Skip()\r
+\r
+    def OnEraseBackground(self, event):\r
+        event.Skip()\r
+\r
+    def OnExecute(self, event):\r
+        item = self.panelCommands.CommandsTree.GetSelection()\r
+        if item.IsOk():\r
+            if not self.panelCommands.CommandsTree.ItemHasChildren(item):\r
+                item_text = self.panelCommands.CommandsTree.GetItemText(item)\r
+                command = ''.join(['self.do_', item_text, '()'])\r
+                #self.AppendToOutput(command + '\n')\r
+                exec(command)\r
+\r
+    def OnExit(self, event):\r
+        self.Close()\r
+\r
+    def OnNext(self, event):\r
         '''\r
-            self.current_x_ext=[[],[]]\r
-            self.current_y_ext=[[],[]]\r
-            self.current_x_ret=[[],[]]\r
-            self.current_y_ret=[[],[]]\r
-\r
-\r
-            self.current_x_unit=[None,None]\r
-            self.current_y_unit=[None,None]\r
-            '''\r
-\r
-        #Initialize xaxes, yaxes\r
-        #FIXME: should come from config\r
-        self.current_xaxes=0\r
-        self.current_yaxes=0\r
-\r
-        #Other\r
-\r
-\r
-        self.index_buffer=[]\r
-\r
-        self.clicked_points=[]\r
-\r
-        self.measure_set=None\r
-\r
-        self.events_from_gui = events_from_gui\r
-\r
-        '''\r
-            This dictionary keeps all the flags and the relative functon names that\r
-            have to be called when a point is clicked.\r
-            That is:\r
-            - if point is clicked AND foo_flag=True\r
-            - foo()\r
-\r
-            Conversely, foo_flag is True if a corresponding event is launched by the CLI.\r
-\r
-            self.ClickedPoints() takes care of handling this\r
-            '''\r
-\r
-        self.click_flags_functions={'measure_points':[False, 'MeasurePoints']}\r
-\r
-        #Binding of custom events from CLI --> GUI functions!                       \r
-        #FIXME: Should use the self.Bind() syntax\r
-        EVT_PLOT(self, self.PlotCurve)\r
-        EVT_PLOT_CONTACT(self, self.PlotContact)\r
-        EVT_GET_DISPLAYED_PLOT(self, self.OnGetDisplayedPlot)\r
-        EVT_MEASURE_POINTS(self, self.OnMeasurePoints)\r
-        EVT_EXPORT_IMAGE(self,self.ExportImage)\r
-        EVT_CLOSE_PLOT(self, self.OnClosePlot)\r
-        EVT_SHOW_PLOTS(self, self.OnShowPlots)\r
-\r
-        #This event and control decide what happens when I click on the plot 0.\r
-        wxmpl.EVT_POINT(self, self.controls[0].GetId(), self.ClickPoint0)\r
-        wxmpl.EVT_POINT(self, self.controls[1].GetId(), self.ClickPoint1)\r
-\r
-        #RUN PLUGIN-SPECIFIC INITIALIZATION\r
-        #make sure we execute _plug_init() for every command line plugin we import\r
-        for plugin_name in config['plugins']:\r
-            try:\r
-                plugin=__import__(plugin_name)\r
-                try:\r
-                    eval('plugin.'+plugin_name+'Gui._plug_init(self)')\r
-                    pass\r
-                except AttributeError:\r
-                    pass\r
-            except ImportError:\r
-                pass\r
-\r
-\r
-\r
-    #WX-SPECIFIC FUNCTIONS\r
-    def sizer_dance(self):\r
+        NEXT\r
+        Go to the next curve in the playlist.\r
+        If we are at the last curve, we come back to the first.\r
+        -----\r
+        Syntax: next, n\r
         '''\r
-            adjust size and placement of wxpython widgets.\r
-            '''\r
-        self.splittersizer = wx.BoxSizer(wx.VERTICAL)\r
-        self.splittersizer.Add(self.mainpanel.splitter, 1, wx.EXPAND)\r
-\r
-        self.plot1sizer = wx.BoxSizer()\r
-        self.plot1sizer.Add(self.controls[0], 1, wx.EXPAND)\r
-\r
-        self.plot2sizer = wx.BoxSizer()\r
-        self.plot2sizer.Add(self.controls[1], 1, wx.EXPAND)\r
-\r
-        self.panelsizer=wx.BoxSizer()\r
-        self.panelsizer.Add(self.mainpanel, -1, wx.EXPAND)\r
-\r
-        self.cpanels[0].SetSizer(self.plot1sizer)\r
-        self.cpanels[1].SetSizer(self.plot2sizer)\r
-\r
-        self.mainpanel.SetSizer(self.splittersizer)\r
-        self.SetSizer(self.panelsizer)\r
-\r
-    def binding_dance(self):\r
-        self.Bind(wx.EVT_MENU, self.OnOpenPlayMenu, self.menubar.menu_items['openplaymenu'])\r
-        self.Bind(wx.EVT_MENU, self.OnExitMenu, self.menubar.menu_items['exitmenu'])\r
-        self.Bind(wx.EVT_MENU, self.OnExportText, self.menubar.menu_items['exporttextmenu'])\r
-        self.Bind(wx.EVT_MENU, self.OnExportImage, self.menubar.menu_items['exportimagemenu'])\r
-        self.Bind(wx.EVT_MENU, self.OnAboutMenu, self.menubar.menu_items['aboutmenu'])\r
-\r
-    # DOUBLE PLOT MANAGEMENT\r
-    #----------------------\r
-    def show_both(self):\r
+        selected_item = self.panelPlaylists.PlaylistsTree.GetSelection()\r
+        if self.panelPlaylists.PlaylistsTree.ItemHasChildren(selected_item):\r
+            #GetFirstChild returns a tuple\r
+            #we only need the first element\r
+            next_item = self.panelPlaylists.PlaylistsTree.GetFirstChild(selected_item)[0]\r
+        else:\r
+            next_item = self.panelPlaylists.PlaylistsTree.GetNextSibling(selected_item)\r
+            if not next_item.IsOk():\r
+                parent_item = self.panelPlaylists.PlaylistsTree.GetItemParent(selected_item)\r
+                #GetFirstChild returns a tuple\r
+                #we only need the first element\r
+                next_item = self.panelPlaylists.PlaylistsTree.GetFirstChild(parent_item)[0]\r
+        self.panelPlaylists.PlaylistsTree.SelectItem(next_item, True)\r
+        if not self.panelPlaylists.PlaylistsTree.ItemHasChildren(selected_item):\r
+            playlist = self.GetActivePlaylist()\r
+            if playlist.count > 1:\r
+                playlist.next()\r
+                self.statusbar.SetStatusText(playlist.get_status_string(), 0)\r
+                self.UpdatePlot()\r
+\r
+    def OnNotebookPageClose(self, event):\r
+        ctrl = event.GetEventObject()\r
+        playlist_name = ctrl.GetPageText(ctrl._curpage)\r
+        self.DeleteFromPlaylists(playlist_name)\r
+\r
+    def OnPaneClose(self, event):\r
+        event.Skip()\r
+\r
+    def OnPlaylistsLeftDclick(self, event):\r
+        if self.panelPlaylists.PlaylistsTree.Count > 0:\r
+            playlist_name = self.GetActivePlaylistName()\r
+            #if that playlist already exists\r
+            #we check if it is the active playlist (ie selected in panelPlaylists)\r
+            #and switch to it if necessary\r
+            if playlist_name in self.playlists:\r
+                index = self.plotNotebook.GetSelection()\r
+                current_playlist = self.plotNotebook.GetPageText(index)\r
+                if current_playlist != playlist_name:\r
+                    index = self._GetPlaylistTab(playlist_name)\r
+                    self.plotNotebook.SetSelection(index)\r
+                #if a curve was double-clicked\r
+                item = self.panelPlaylists.PlaylistsTree.GetSelection()\r
+                if not self.panelPlaylists.PlaylistsTree.ItemHasChildren(item):\r
+                    index = self._GetActiveFileIndex()\r
+                else:\r
+                    index = 0\r
+                if index >= 0:\r
+                    playlist = self.GetActivePlaylist()\r
+                    playlist.index = index\r
+                    self.statusbar.SetStatusText(playlist.get_status_string(), 0)\r
+                    self.UpdatePlot()\r
+            #if you uncomment the following line, the tree will collapse/expand as well\r
+            #event.Skip()\r
+\r
+    def OnPlaylistsLeftDown(self, event):\r
+        hit_item, hit_flags = self.panelPlaylists.PlaylistsTree.HitTest(event.GetPosition())\r
+        if (hit_flags & wx.TREE_HITTEST_ONITEM) != 0:\r
+            self.panelPlaylists.PlaylistsTree.SelectItem(hit_item)\r
+            playlist_name = self.GetActivePlaylistName()\r
+            playlist = self.GetActivePlaylist()\r
+            #if a curve was clicked\r
+            item = self.panelPlaylists.PlaylistsTree.GetSelection()\r
+            if not self.panelPlaylists.PlaylistsTree.ItemHasChildren(item):\r
+                index = self._GetActiveFileIndex()\r
+                if index >= 0:\r
+                    playlist.index = index\r
+            self.playlists[playlist_name] = playlist\r
+        event.Skip()\r
+\r
+    def OnPrevious(self, event):\r
         '''\r
-            Shows both plots.\r
-            '''\r
-        self.mainpanel.splitter.SplitHorizontally(self.cpanels[0],self.cpanels[1])\r
-        self.mainpanel.splitter.SetSashGravity(0.5)\r
-        self.mainpanel.splitter.SetSashPosition(300) #FIXME: we should get it and restore it\r
-        self.mainpanel.splitter.UpdateSize()\r
-\r
-    def close_plot(self,plot):\r
+        PREVIOUS\r
+        Go to the previous curve in the playlist.\r
+        If we are at the first curve, we jump to the last.\r
+        -------\r
+        Syntax: previous, p\r
         '''\r
-            Closes one plot - only if it's open\r
-            '''\r
-        if not self.cpanels[plot].IsShown():\r
-            return\r
-        if plot != 0:\r
-            self.current_plot_dest = 0\r
+        #playlist = self.playlists[self.GetActivePlaylistName()][0]\r
+        #select the previous curve and tell the user if we wrapped around\r
+        #self.AppendToOutput(playlist.previous())\r
+        selected_item = self.panelPlaylists.PlaylistsTree.GetSelection()\r
+        if self.panelPlaylists.PlaylistsTree.ItemHasChildren(selected_item):\r
+            previous_item = self.panelPlaylists.PlaylistsTree.GetLastChild(selected_item)\r
         else:\r
-            self.current_plot_dest = 1\r
-        self.cpanels[plot].Hide()\r
-        self.mainpanel.splitter.Unsplit(self.cpanels[plot])\r
-        self.mainpanel.splitter.UpdateSize()\r
-\r
+            previous_item = self.panelPlaylists.PlaylistsTree.GetPrevSibling(selected_item)\r
+            if not previous_item.IsOk():\r
+                parent_item = self.panelPlaylists.PlaylistsTree.GetItemParent(selected_item)\r
+                previous_item = self.panelPlaylists.PlaylistsTree.GetLastChild(parent_item)\r
+        self.panelPlaylists.PlaylistsTree.SelectItem(previous_item, True)\r
+        playlist = self.GetActivePlaylist()\r
+        if playlist.count > 1:\r
+            playlist.previous()\r
+            self.statusbar.SetStatusText(playlist.get_status_string(), 0)\r
+            self.UpdatePlot()\r
+\r
+    def OnPropGridChanged (self, event):\r
+        prop = event.GetProperty()\r
+        if prop:\r
+            item_section = self.panelProperties.SelectedTreeItem\r
+            item_plugin = self.panelCommands.CommandsTree.GetItemParent(item_section)\r
+            plugin = self.panelCommands.CommandsTree.GetItemText(item_plugin)\r
+            config = self.configs[plugin]\r
+            property_section = self.panelCommands.CommandsTree.GetItemText(item_section)\r
+            property_key = prop.GetName()\r
+            property_value = prop.GetDisplayedString()\r
+\r
+            config[property_section][property_key]['value'] = property_value\r
+\r
+    def OnRestorePerspective(self, event):\r
+        name = self.MenuBar.FindItemById(event.GetId()).GetLabel()\r
+        self._RestorePerspective(name)\r
+#        self._mgr.LoadPerspective(self._perspectives[name])\r
+#        self.config['perspectives']['active'] = name\r
+#        self._mgr.Update()\r
+#        all_panes = self._mgr.GetAllPanes()\r
+#        for pane in all_panes:\r
+#            if not pane.name.startswith('toolbar'):\r
+#                if pane.name == 'Assistant':\r
+#                    self.MenuBar.FindItemById(ID_ViewAssistant).Check(pane.window.IsShown())\r
+#                if pane.name == 'Folders':\r
+#                    self.MenuBar.FindItemById(ID_ViewFolders).Check(pane.window.IsShown())\r
+#                if pane.name == 'Playlists':\r
+#                    self.MenuBar.FindItemById(ID_ViewPlaylists).Check(pane.window.IsShown())\r
+#                if pane.name == 'Commands':\r
+#                    self.MenuBar.FindItemById(ID_ViewCommands).Check(pane.window.IsShown())\r
+#                if pane.name == 'Properties':\r
+#                    self.MenuBar.FindItemById(ID_ViewProperties).Check(pane.window.IsShown())\r
+#                if pane.name == 'Output':\r
+#                    self.MenuBar.FindItemById(ID_ViewOutput).Check(pane.window.IsShown())\r
+#                if pane.name == 'Results':\r
+#                    self.MenuBar.FindItemById(ID_ViewResults).Check(pane.window.IsShown())\r
+\r
+    def OnResultsCheck(self, index, flag):\r
+        #TODO: fix for multiple results\r
+        results = self.GetActivePlot().results\r
+        fit_function_str = self.GetStringFromConfig('results', 'show_results', 'fit_function')\r
+        results[fit_function_str].results[index].visible = flag\r
+        self.UpdatePlot()\r
+\r
+    def OnSavePerspective(self, event):\r
+\r
+        def nameExists(name):\r
+            menu_position = self.MenuBar.FindMenu('Perspectives') \r
+            menu = self.MenuBar.GetMenu(menu_position)\r
+            for item in menu.GetMenuItems():\r
+                if item.GetText() == name:\r
+                    return True\r
+            return False\r
+\r
+        done = False\r
+        while not done:\r
+            dialog = wx.TextEntryDialog(self, 'Enter a name for the new perspective:', 'Save perspective')\r
+            dialog.SetValue('New perspective')\r
+            if dialog.ShowModal() != wx.ID_OK:\r
+                return\r
+            else:\r
+                name = dialog.GetValue()\r
 \r
-    def OnClosePlot(self,event):\r
-        self.close_plot(event.to_close)       \r
+            if nameExists(name):\r
+                dialogConfirm = wx.MessageDialog(self, 'A file with this name already exists.\n\nDo you want to replace it?', 'Confirm', wx.YES_NO|wx.ICON_QUESTION|wx.CENTER)\r
+                if dialogConfirm.ShowModal() == wx.ID_YES:\r
+                    done = True\r
+            else:\r
+                done = True\r
+\r
+        perspective = self._mgr.SavePerspective()\r
+        self._SavePerspectiveToFile(name, perspective)\r
+        self.config['perspectives']['active'] = name\r
+        self.UpdatePerspectivesMenu()\r
+#        if nameExists(name):\r
+#            #check the corresponding menu item\r
+#            menu_item = self.GetPerspectiveMenuItem(name)\r
+#            #replace the perspectiveStr in _pespectives\r
+#            self._perspectives[name] = perspective\r
+#        else:\r
+#            #because we deal with radio items, we need to do some extra work\r
+#            #delete all menu items from the perspectives menu\r
+#            for item in self._perspectives_menu.GetMenuItems():\r
+#                self._perspectives_menu.DeleteItem(item)\r
+#            #recreate the perspectives menu\r
+#            self._perspectives_menu.Append(ID_SavePerspective, 'Save Perspective')\r
+#            self._perspectives_menu.Append(ID_DeletePerspective, 'Delete Perspective')\r
+#            self._perspectives_menu.AppendSeparator()\r
+#            #convert the perspectives dictionary into a list\r
+#            # the list contains:\r
+#            #[0]: name of the perspective\r
+#            #[1]: perspective\r
+#            perspectives_list = [key for key, value in self._perspectives.iteritems()]\r
+#            perspectives_list.append(name)\r
+#            perspectives_list.sort()\r
+#            #add all previous perspectives\r
+#            for index, item in enumerate(perspectives_list):\r
+#                menu_item = self._perspectives_menu.AppendRadioItem(ID_FirstPerspective + index, item)\r
+#                if item == name:\r
+#                    menu_item.Check()\r
+#            #add the new perspective to _perspectives\r
+#            self._perspectives[name] = perspective\r
+\r
+    def OnSize(self, event):\r
+        event.Skip()\r
+\r
+    def OnTreeCtrlCommandsSelectionChanged(self, event):\r
+        selected_item = event.GetItem()\r
+        if selected_item is not None:\r
+            plugin = ''\r
+            section = ''\r
+            #deregister/register the listener to avoid infinite loop\r
+            evtmgr.eventManager.DeregisterListener(self.OnTreeCtrlCommandsSelectionChanged)\r
+            self.panelCommands.CommandsTree.SelectItem(selected_item)\r
+            evtmgr.eventManager.Register(self.OnTreeCtrlCommandsSelectionChanged, wx.EVT_TREE_SEL_CHANGED, self.panelCommands.CommandsTree)\r
+            self.panelProperties.SelectedTreeItem = selected_item\r
+            #if a command was clicked\r
+            properties = []\r
+            if not self.panelCommands.CommandsTree.ItemHasChildren(selected_item):\r
+                item_plugin = self.panelCommands.CommandsTree.GetItemParent(selected_item)\r
+                plugin = self.panelCommands.CommandsTree.GetItemText(item_plugin)\r
+                if self.configs.has_key(plugin):\r
+                    #config = self.panelCommands.CommandsTree.GetPyData(item_plugin)\r
+                    config = self.configs[plugin]\r
+                    section = self.panelCommands.CommandsTree.GetItemText(selected_item)\r
+                    #display docstring in help window\r
+                    doc_string = eval('self.do_' + section + '.__doc__')\r
+                    if section in config:\r
+                        for option in config[section]:\r
+                            properties.append([option, config[section][option]])\r
+            else:\r
+                plugin = self.panelCommands.CommandsTree.GetItemText(selected_item)\r
+                if plugin != 'core':\r
+                    doc_string = eval('plugins.' + plugin + '.' + plugin + 'Commands.__doc__')\r
+                else:\r
+                    doc_string = 'The module "core" contains Hooke core functionality'\r
+            if doc_string is not None:\r
+                self.panelAssistant.ChangeValue(doc_string)\r
+            else:\r
+                self.panelAssistant.ChangeValue('')\r
+            panels.propertyeditor.PropertyEditor.Initialize(self.panelProperties, properties)\r
+            #save the currently selected command/plugin to the config file\r
+            self.config['command']['command'] = section\r
+            self.config['command']['plugin'] = plugin\r
+\r
+    def OnTreeCtrlItemActivated(self, event):\r
+        self.OnExecute(event)\r
+\r
+    def OnView(self, event):\r
+        menu_id = event.GetId()\r
+        menu_item = self.MenuBar.FindItemById(menu_id)\r
+        menu_label = menu_item.GetLabel()\r
+\r
+        pane = self._mgr.GetPane(menu_label)\r
+        pane.Show(not pane.IsShown())\r
+        #if we don't do the following, the Folders pane does not resize properly on hide/show\r
+        if pane.caption == 'Folders' and pane.IsShown() and pane.IsDocked():\r
+            #folders_size = pane.GetSize()\r
+            self.panelFolders.Fit()\r
+        self._mgr.Update()\r
+\r
+    def _measure_N_points(self, N, message='', whatset=lh.RETRACTION):\r
+        '''\r
+        General helper function for N-points measurements\r
+        By default, measurements are done on the retraction\r
+        '''\r
+        if message != '':\r
+            dialog = wx.MessageDialog(None, message, 'Info', wx.OK)\r
+            dialog.ShowModal()\r
+\r
+        figure = self.GetActiveFigure()\r
+\r
+        xvector = self.displayed_plot.curves[whatset].x\r
+        yvector = self.displayed_plot.curves[whatset].y\r
+\r
+        clicked_points = figure.ginput(N, timeout=-1, show_clicks=True)\r
+\r
+        points = []\r
+        for clicked_point in clicked_points:\r
+            point = lh.ClickedPoint()\r
+            point.absolute_coords = clicked_point[0], clicked_point[1]\r
+            point.dest = 0\r
+            #TODO: make this optional?\r
+            #so far, the clicked point is taken, not the corresponding data point\r
+            point.find_graph_coords(xvector, yvector)\r
+            point.is_line_edge = True\r
+            point.is_marker = True\r
+            points.append(point)\r
+        return points\r
+\r
+    def _clickize(self, xvector, yvector, index):\r
+        '''\r
+        returns a ClickedPoint() object from an index and vectors of x, y coordinates\r
+        '''\r
+        point = lh.ClickedPoint()\r
+        point.index = index\r
+        point.absolute_coords = xvector[index], yvector[index]\r
+        point.find_graph_coords(xvector, yvector)\r
+        return point\r
 \r
-    def OnShowPlots(self,event):\r
-        self.show_both()\r
+    def _delta(self, color='black', message='Click 2 points', show=True, whatset=1):\r
+        '''\r
+        calculates the difference between two clicked points\r
+        '''\r
+        clicked_points = self._measure_N_points(N=2, message=message, whatset=whatset)\r
+        dx = abs(clicked_points[0].graph_coords[0] - clicked_points[1].graph_coords[0])\r
+        dy = abs(clicked_points[0].graph_coords[1] - clicked_points[1].graph_coords[1])\r
 \r
+        plot = self.GetDisplayedPlotCorrected()\r
 \r
-    #FILE MENU FUNCTIONS\r
-    #--------------------\r
-    def OnOpenPlayMenu(self, event):\r
-        pass \r
+        curve = plot.curves[whatset]\r
+        unitx = curve.units.x\r
+        unity = curve.units.y\r
 \r
-    def OnExitMenu(self,event):\r
-        pass\r
+        #TODO: move this to clicked_points?\r
+        if show:\r
+            for point in clicked_points:\r
+                points = copy.deepcopy(curve)\r
+                points.x = point.graph_coords[0]\r
+                points.y = point.graph_coords[1]\r
 \r
-    def OnExportText(self,event):\r
-        pass\r
+                points.color = color\r
+                points.size = 20\r
+                points.style = 'scatter'\r
+                plot.curves.append(points)\r
 \r
-    def OnExportImage(self,event):\r
-        pass\r
+        self.UpdatePlot(plot)\r
 \r
-    def OnAboutMenu(self,event):\r
-        pass\r
+        return dx, unitx, dy, unity\r
 \r
-    #PLOT INTERACTION    \r
-    #----------------                        \r
-    def PlotCurve(self,event):\r
+    def do_plotmanipulators(self):\r
         '''\r
-            plots the current ext,ret curve.\r
-            '''\r
-        dest=0\r
-\r
-        #FIXME: BAD kludge following. There should be a well made plot queue mechanism, with replacements etc.\r
-        #---\r
-        #If we have only one plot in the event, we already have one in self.plots and this is a secondary plot,\r
-        #do not erase self.plots but append the new plot to it.\r
-        if len(event.plots) == 1 and event.plots[0].destination != 0 and len(self.plots) == 1:\r
-            self.plots.append(event.plots[0])\r
-        #if we already have two plots and a new secondary plot comes, we substitute the previous\r
-        if len(event.plots) == 1 and event.plots[0].destination != 0 and len(self.plots) > 1:\r
-            self.plots[1] = event.plots[0]\r
-        else:\r
-            self.plots = event.plots\r
-\r
-        #FIXME. Should be in PlotObject, somehow\r
-        c=0\r
-        for plot in self.plots:\r
-            if self.plots[c].styles==[]:\r
-                self.plots[c].styles=[None for item in plot.vectors] \r
-            if self.plots[c].colors==[]:\r
-                self.plots[c].colors=[None for item in plot.vectors] \r
-\r
-        for plot in self.plots:\r
-            '''\r
-                MAIN LOOP FOR ALL PLOTS (now only 2 are allowed but...)\r
-                '''\r
-            if 'destination' in dir(plot):\r
-                dest=plot.destination\r
-\r
-            #if the requested panel is not shown, show it\r
-            if not ( self.cpanels[dest].IsShown() ):\r
-                self.show_both()\r
-\r
-            self.axes[dest].hold(False)\r
-            self.current_vectors=plot.vectors\r
-            self.current_title=plot.title\r
-            self.current_plot_dest=dest #let's try this way to take into account the destination plot...\r
-\r
-            c=0\r
-\r
-            if len(plot.colors)==0:\r
-                plot.colors=[None] * len(plot.vectors)\r
-            if len(plot.styles)==0:\r
-                plot.styles=[None] * len(plot.vectors)     \r
-\r
-            for vectors_to_plot in self.current_vectors: \r
-                if plot.styles[c]=='scatter':\r
-                    if plot.colors[c]==None:\r
-                        self.axes[dest].scatter(vectors_to_plot[0], vectors_to_plot[1])\r
-                    else:\r
-                        self.axes[dest].scatter(vectors_to_plot[0], vectors_to_plot[1],color=plot.colors[c])\r
-                else:\r
-                    if plot.colors[c]==None:\r
-                        self.axes[dest].plot(vectors_to_plot[0], vectors_to_plot[1])\r
-                    else:\r
-                        self.axes[dest].plot(vectors_to_plot[0], vectors_to_plot[1], color=plot.colors[c])\r
-                self.axes[dest].hold(True)\r
-                c+=1\r
-\r
-            '''\r
-                for vectors_to_plot in self.current_vectors:\r
-                    if len(vectors_to_plot)==2: #3d plots are to come...\r
-                        if len(plot.styles) > 0 and plot.styles[c] == 'scatter':\r
-                            self.axes[dest].scatter(vectors_to_plot[0],vectors_to_plot[1])\r
-                        elif len(plot.styles) > 0 and plot.styles[c] == 'scatter_red':\r
-                            self.axes[dest].scatter(vectors_to_plot[0],vectors_to_plot[1],color='red')\r
-                        else:\r
-                            self.axes[dest].plot(vectors_to_plot[0],vectors_to_plot[1])\r
-\r
-                        self.axes[dest].hold(True)\r
-                        c+=1\r
-                    else:\r
-                        pass\r
-                '''               \r
-            #FIXME: tackles only 2d plots\r
-            self.axes[dest].set_xlabel(plot.units[0])\r
-            self.axes[dest].set_ylabel(plot.units[1])\r
-\r
-            #FIXME: set smaller fonts\r
-            self.axes[dest].set_title(plot.title)\r
-\r
-            if plot.xaxes: \r
-                #swap X axis\r
-                xlim=self.axes[dest].get_xlim()\r
-                self.axes[dest].set_xlim((xlim[1],xlim[0])) \r
-            if plot.yaxes:\r
-                #swap Y axis\r
-                ylim=self.axes[dest].get_ylim()        \r
-                self.axes[dest].set_ylim((ylim[1],ylim[0])) \r
-\r
-            self.controls[dest].draw()\r
-\r
+        Please select the plotmanipulators you would like to use\r
+        and define the order in which they will be applied to the data.\r
 \r
-    def PlotContact(self,event):\r
+        Click 'Execute' to apply your changes.\r
         '''\r
-            plots the contact point\r
-            DEPRECATED!\r
-            '''\r
-        self.axes[0].hold(True)\r
-        self.current_contact_index=event.contact_index\r
+        self.UpdatePlot()\r
 \r
-        #now we fake a clicked point \r
-        self.clicked_points.append(ClickedPoint())\r
-        self.clicked_points[-1].absolute_coords=self.current_x_ret[dest][self.current_contact_index], self.current_y_ret[dest][self.current_contact_index]\r
-        self.clicked_points[-1].is_marker=True    \r
-\r
-        self._replot()\r
-        self.clicked_points=[]\r
+    def do_test(self):\r
+        self.AppendToOutput(self.config['perspectives']['active'])\r
+        pass\r
 \r
-    def OnMeasurePoints(self,event):\r
+    def do_version(self):\r
         '''\r
-            trigger flags to measure N points\r
-            '''\r
-        self.click_flags_functions['measure_points'][0]=True\r
-        if 'num_of_points' in dir(event):\r
-            self.num_of_points=event.num_of_points\r
-        if 'set' in dir(event):    \r
-            self.measure_set=event.set            \r
-\r
-    def ClickPoint0(self,event):\r
-        self.current_plot_dest=0\r
-        self.ClickPoint(event)\r
-    def ClickPoint1(self,event):\r
-        self.current_plot_dest=1\r
-        self.ClickPoint(event)\r
-\r
-    def ClickPoint(self,event):\r
+        VERSION\r
+        ------\r
+        Prints the current version and codename, plus library version. Useful for debugging.\r
         '''\r
-            this function decides what to do when we receive a left click on the axes.\r
-            We trigger other functions:\r
-            - the action chosen by the CLI sends an event\r
-            - the event raises a flag : self.click_flags_functions['foo'][0]\r
-            - the raised flag wants the function in self.click_flags_functions[1] to be called after a click\r
-            '''\r
-        for key, value in self.click_flags_functions.items():\r
-            if value[0]:\r
-                eval('self.'+value[1]+'(event)')\r
-\r
-\r
-\r
-    def MeasurePoints(self,event,current_set=1):\r
-        dest=self.current_plot_dest\r
-        try:\r
-            current_set=self.measure_set\r
-        except AttributeError:\r
-            pass\r
-\r
-        #find the current plot matching the clicked destination\r
-        plot=self._plot_of_dest()\r
-        if len(plot.vectors)-1 < current_set: #what happens if current_set is 1 and we have only 1 vector?\r
-            current_set=current_set-len(plot.vectors)\r
-\r
-        xvector=plot.vectors[current_set][0]\r
-        yvector=plot.vectors[current_set][1]\r
-\r
-        self.clicked_points.append(ClickedPoint())            \r
-        self.clicked_points[-1].absolute_coords=event.xdata, event.ydata\r
-        self.clicked_points[-1].find_graph_coords(xvector,yvector)\r
-        self.clicked_points[-1].is_marker=True    \r
-        self.clicked_points[-1].is_line_edge=True\r
-        self.clicked_points[-1].dest=dest                \r
-\r
-        self._replot()\r
-\r
-        if len(self.clicked_points)==self.num_of_points:\r
-            self.events_from_gui.put(self.clicked_points)\r
-            #restore to default state:\r
-            self.clicked_points=[]\r
-            self.click_flags_functions['measure_points'][0]=False    \r
-\r
-\r
-    def OnGetDisplayedPlot(self,event):\r
-        if 'dest' in dir(event):\r
-            self.GetDisplayedPlot(event.dest)\r
+        self.AppendToOutput('Hooke ' + __version__ + ' (' + __codename__ + ')')\r
+        self.AppendToOutput('Released on: ' + __releasedate__)\r
+        self.AppendToOutput('---')\r
+        self.AppendToOutput('Python version: ' + python_version)\r
+        self.AppendToOutput('WxPython version: ' + wx_version)\r
+        self.AppendToOutput('Matplotlib version: ' + mpl_version)\r
+        self.AppendToOutput('SciPy version: ' + scipy_version)\r
+        self.AppendToOutput('NumPy version: ' + numpy_version)\r
+        self.AppendToOutput('---')\r
+        self.AppendToOutput('Platform: ' + str(platform.uname()))\r
+        #TODO: adapt to 'new' config\r
+        #self.AppendToOutput('---')\r
+        #self.AppendToOutput('Loaded plugins:', self.config['loaded_plugins'])\r
+\r
+    def UpdatePerspectivesMenu(self):\r
+        #add perspectives to menubar and _perspectives\r
+        perspectivesDirectory = os.path.join(lh.hookeDir, 'perspectives')\r
+        self._perspectives = {}\r
+        if os.path.isdir(perspectivesDirectory):\r
+            perspectiveFileNames = os.listdir(perspectivesDirectory)\r
+            for perspectiveFilename in perspectiveFileNames:\r
+                filename = lh.get_file_path(perspectiveFilename, ['perspectives'])\r
+                if os.path.isfile(filename):\r
+                    perspectiveFile = open(filename, 'rU')\r
+                    perspective = perspectiveFile.readline()\r
+                    perspectiveFile.close()\r
+                    if perspective != '':\r
+                        name, extension = os.path.splitext(perspectiveFilename)\r
+                        if extension == '.txt':\r
+                            self._perspectives[name] = perspective\r
+\r
+        #in case there are no perspectives\r
+        if not self._perspectives:\r
+            perspective = self._mgr.SavePerspective()\r
+            self._perspectives['Default'] = perspective\r
+            self._SavePerspectiveToFile('Default', perspective)\r
+\r
+        selected_perspective = self.config['perspectives']['active']\r
+        if not self._perspectives.has_key(selected_perspective):\r
+            self.config['perspectives']['active'] = 'Default'\r
+            selected_perspective = 'Default'\r
+\r
+        perspectives_list = [key for key, value in self._perspectives.iteritems()]\r
+        perspectives_list.sort()\r
+\r
+        #get the Perspectives menu\r
+        menu_position = self.MenuBar.FindMenu('Perspectives') \r
+        menu = self.MenuBar.GetMenu(menu_position)\r
+        #delete all menu items\r
+        for item in menu.GetMenuItems():\r
+            menu.DeleteItem(item)\r
+        #rebuild the menu by adding the standard menu items\r
+        menu.Append(ID_SavePerspective, 'Save Perspective')\r
+        menu.Append(ID_DeletePerspective, 'Delete Perspective')\r
+        menu.AppendSeparator()\r
+        #add all previous perspectives\r
+        for index, label in enumerate(perspectives_list):\r
+            menu_item = menu.AppendRadioItem(ID_FirstPerspective + index, label)\r
+            if label == selected_perspective:\r
+                self._RestorePerspective(label)\r
+                menu_item.Check(True)\r
+\r
+    def UpdatePlaylistsTreeSelection(self):\r
+        playlist = self.GetActivePlaylist()\r
+        if playlist is not None:\r
+            if playlist.index >= 0:\r
+                self.statusbar.SetStatusText(playlist.get_status_string(), 0)\r
+                self.UpdatePlot()\r
+\r
+    def UpdatePlot(self, plot=None):\r
+\r
+        def add_to_plot(curve):\r
+            if curve.visible and curve.x and curve.y:\r
+                destination = (curve.destination.column - 1) * number_of_rows + curve.destination.row - 1\r
+                axes_list[destination].set_title(curve.title)\r
+                axes_list[destination].set_xlabel(curve.units.x)\r
+                axes_list[destination].set_ylabel(curve.units.y)\r
+                if curve.style == 'plot':\r
+                    axes_list[destination].plot(curve.x, curve.y, color=curve.color, label=curve.label, zorder=1)\r
+                if curve.style == 'scatter':\r
+                    axes_list[destination].scatter(curve.x, curve.y, color=curve.color, label=curve.label, s=curve.size, zorder=2)\r
+\r
+        if plot is None:\r
+            active_file = self.GetActiveFile()\r
+            if not active_file.driver:\r
+                active_file.identify(self.drivers)\r
+            self.displayed_plot = copy.deepcopy(active_file.plot)\r
+            #add raw curves to plot\r
+            self.displayed_plot.raw_curves = copy.deepcopy(self.displayed_plot.curves)\r
+            #apply all active plotmanipulators and add the 'manipulated' data\r
+            for plotmanipulator in self.plotmanipulators:\r
+                if self.GetBoolFromConfig('core', 'plotmanipulators', plotmanipulator.name):\r
+                    self.displayed_plot = plotmanipulator.method(self.displayed_plot, active_file)\r
+            #add corrected curves to plot\r
+            self.displayed_plot.corrected_curves = copy.deepcopy(self.displayed_plot.curves)\r
         else:\r
-            self.GetDisplayedPlot(self.current_plot_dest)\r
+            active_file = None\r
+            self.displayed_plot = copy.deepcopy(plot)\r
 \r
-    def GetDisplayedPlot(self,dest):\r
-        '''\r
-            returns to the CLI the currently displayed plot for the given destination\r
-            '''\r
-        displayed_plot=self._plot_of_dest(dest)\r
-        events_from_gui.put(displayed_plot)\r
+        figure = self.GetActiveFigure()\r
 \r
-    def ExportImage(self,event):\r
-        '''\r
-            exports an image as a file.\r
-            Current supported file formats: png, eps\r
-            (matplotlib docs say that jpeg should be supported too, but with .jpg it doesn't work for me!)\r
-            '''\r
-        #dest=self.current_plot_dest\r
-        dest=event.dest\r
-        filename=event.name\r
-        self.figures[dest].savefig(filename)\r
-\r
-    '''\r
-        def _find_nearest_point(self, mypoint, dataset=1):\r
-\r
-            #Given a clicked point on the plot, finds the nearest point in the dataset (in X) that\r
-            #corresponds to the clicked point.\r
-\r
-            dest=self.current_plot_dest\r
-\r
-            xvector=plot.vectors[dataset][0]\r
-            yvector=plot.vectors[dataset][1]\r
-\r
-            #Ye Olde sorting algorithm...\r
-            #FIXME: is there a better solution?\r
-            index=0\r
-            best_index=0\r
-            best_diff=10^9 #hope we never go over this magic number :(\r
-            for point in xvector:\r
-                diff=abs(point-mypoint)\r
-                if diff<best_diff:\r
-                    best_index=index\r
-                    best_diff=diff\r
-                index+=1\r
-\r
-            return best_index,xvector[best_index],yvector[best_index]\r
-         '''   \r
-\r
-    def _plot_of_dest(self,dest=None):\r
-        '''\r
-            returns the plot that has the current destination\r
-            '''\r
-        if dest==None:\r
-            dest=self.current_plot_dest\r
-\r
-        plot=None\r
-        for aplot in self.plots:\r
-            if aplot.destination == dest:\r
-                plot=aplot\r
-        return plot\r
+        figure.clear()\r
+        figure.suptitle(self.displayed_plot.title, fontsize=14)\r
 \r
-    def _replot(self):\r
-        '''\r
-            this routine is needed for a fresh clean-and-replot of interface\r
-            otherwise, refreshing works very badly :(\r
-\r
-            thanks to Ken McIvor, wxmpl author!\r
-            '''\r
-        dest=self.current_plot_dest\r
-        #we get current zoom limits\r
-        xlim=self.axes[dest].get_xlim()\r
-        ylim=self.axes[dest].get_ylim()           \r
-        #clear axes\r
-        self.axes[dest].cla()\r
-\r
-        #Plot curve:         \r
-        #find the current plot matching the clicked destination\r
-        plot=self._plot_of_dest()\r
-        #plot all superimposed plots \r
-        c=0 \r
-        if len(plot.colors)==0:\r
-            plot.colors=[None] * len(plot.vectors)\r
-        if len(plot.styles)==0:\r
-            plot.styles=[None] * len(plot.vectors)     \r
-        for plotset in plot.vectors: \r
-            if plot.styles[c]=='scatter':\r
-                if plot.colors[c]==None:\r
-                    self.axes[dest].scatter(plotset[0], plotset[1])\r
-                else:\r
-                    self.axes[dest].scatter(plotset[0], plotset[1],color=plot.colors[c])\r
-            else:\r
-                if plot.colors[c]==None:\r
-                    self.axes[dest].plot(plotset[0], plotset[1])\r
-                else:\r
-                    self.axes[dest].plot(plotset[0], plotset[1], color=plot.colors[c])\r
-            '''    \r
-                if len(plot.styles) > 0 and plot.styles[c]=='scatter':\r
-                    self.axes[dest].scatter(plotset[0], plotset[1],color=plot.colors[c])\r
-                elif len(plot.styles) > 0 and plot.styles[c] == 'scatter_red':\r
-                    self.axes[dest].scatter(plotset[0],plotset[1],color='red')\r
-                else:\r
-                    self.axes[dest].plot(plotset[0], plotset[1])\r
-                '''\r
-            c+=1\r
-        #plot points we have clicked\r
-        for item in self.clicked_points:\r
-            if item.is_marker:\r
-                if item.graph_coords==(None,None): #if we have no graph coords, we display absolute coords\r
-                    self.axes[dest].scatter([item.absolute_coords[0]],[item.absolute_coords[1]])\r
-                else:\r
-                    self.axes[dest].scatter([item.graph_coords[0]],[item.graph_coords[1]])               \r
-\r
-        if self.plot_fit:\r
-            print 'DEBUGGING WARNING: use of self.plot_fit is deprecated!'\r
-            self.axes[dest].plot(self.plot_fit[0],self.plot_fit[1])\r
+        axes_list =[]\r
 \r
-        self.axes[dest].hold(True)      \r
-        #set old axes again\r
-        self.axes[dest].set_xlim(xlim)\r
-        self.axes[dest].set_ylim(ylim)\r
-        #set title and names again...\r
-        self.axes[dest].set_title(self.current_title)           \r
-        self.axes[dest].set_xlabel(plot.units[0])\r
-        self.axes[dest].set_ylabel(plot.units[1])\r
-        #and redraw!\r
-        self.controls[dest].draw()\r
+        number_of_columns = max([curve.destination.column for curve in self.displayed_plot.curves])\r
+        number_of_rows = max([curve.destination.row for curve in self.displayed_plot.curves])\r
 \r
+        for index in range(number_of_rows * number_of_columns):\r
+            axes_list.append(figure.add_subplot(number_of_rows, number_of_columns, index + 1))\r
 \r
-class MySplashScreen(wx.SplashScreen):\r
-    """\r
-    Create a splash screen widget.\r
-    That's just a fancy addition... every serious application has a splash screen!\r
-    """\r
-    def __init__(self, frame):\r
-        # This is a recipe to a the screen.\r
-        # Modify the following variables as necessary.\r
-        #aBitmap = wx.Image(name = "wxPyWiki.jpg").ConvertToBitmap()\r
-        aBitmap=wx.Image(name='hooke.jpg').ConvertToBitmap()\r
-        splashStyle = wx.SPLASH_CENTRE_ON_SCREEN | wx.SPLASH_TIMEOUT\r
-        splashDuration = 2000 # milliseconds\r
-        splashCallback = None\r
-        # Call the constructor with the above arguments in exactly the\r
-        # following order.\r
-        wx.SplashScreen.__init__(self, aBitmap, splashStyle,\r
-                                 splashDuration, None, -1)\r
-        wx.EVT_CLOSE(self, self.OnExit)\r
-        self.frame=frame\r
-        wx.Yield()\r
+        for curve in self.displayed_plot.curves:\r
+            add_to_plot(curve)\r
 \r
-    def OnExit(self, evt):\r
-        self.Hide()\r
+        #make sure the titles of 'subplots' do not overlap with the axis labels of the 'main plot'\r
+        figure.subplots_adjust(hspace=0.3)\r
 \r
-        self.frame.Show()\r
-        # The program will freeze without this line.\r
-        evt.Skip()  # Make sure the default handler runs too...\r
-\r
-\r
-#------------------------------------------------------------------------------\r
-\r
-def main():\r
-\r
-    #save the directory where Hooke is located\r
-    config['hookedir']=os.getcwd()\r
-\r
-    #now change to the working directory.\r
-    try:\r
-        os.chdir(config['workdir'])\r
-    except OSError:\r
-        print "Warning: Invalid work directory."\r
+        #TODO: add multiple results support to fit in curve.results:\r
+        #get the fit_function results to display\r
+        fit_function_str = self.GetStringFromConfig('results', 'show_results', 'fit_function')\r
+        self.panelResults.ClearResults()\r
+        plot = self.GetActivePlot()\r
+        if plot is not None:\r
+            if plot.results.has_key(fit_function_str):\r
+                for curve in plot.results[fit_function_str].results:\r
+                    add_to_plot(curve)\r
+                self.panelResults.DisplayResults(plot.results[fit_function_str])\r
+            else:\r
+                self.panelResults.ClearResults()\r
 \r
-    app=wx.PySimpleApp()\r
+        figure.canvas.draw()\r
 \r
-    def make_gui_class(*bases):\r
-        return type(MainWindow)("MainWindowPlugged", bases + (MainWindow,), {})\r
+        for axes in axes_list:\r
+            #TODO: add legend as global option or per graph option\r
+            #axes.legend()\r
+            axes.figure.canvas.draw()\r
 \r
-    main_frame = make_gui_class(*GUI_PLUGINS)(None, -1, ('Hooke '+__version__))\r
 \r
-    #FIXME. The frame.Show() is called by the splashscreen here! Ugly as hell.\r
+if __name__ == '__main__':\r
 \r
-    mysplash=MySplashScreen(main_frame)\r
-    mysplash.Show()\r
+    ## now, silence a deprecation warning for py2.3\r
+    import warnings\r
+    warnings.filterwarnings("ignore", "integer", DeprecationWarning, "wxPython.gdi")\r
 \r
-    my_cmdline=CliThread(main_frame, list_of_events)\r
-    my_cmdline.start()\r
+    redirect = True\r
+    if __debug__:\r
+        redirect=False\r
 \r
+    app = Hooke(redirect=redirect)\r
 \r
     app.MainLoop()\r
 \r
-main()\r
+\r
diff --git a/hooke_cli.py b/hooke_cli.py
deleted file mode 100755 (executable)
index 4746ca5..0000000
+++ /dev/null
@@ -1,990 +0,0 @@
-#!/usr/bin/env python
-
-'''
-hooke_cli.py
-
-Command line module of Hooke.
-
-Copyright (C) 2006 Massimo Sandal (University of Bologna, Italy).
-
-This program is released under the GNU General Public License version 2.
-'''
-
-
-from libhooke import * #FIXME
-import libhookecurve as lhc
-
-import libinput as linp
-import liboutlet as lout
-
-from libhooke import WX_GOOD
-from libhooke import HOOKE_VERSION
-
-import wxversion
-wxversion.select(WX_GOOD)
-import wx
-
-from wx.lib.newevent import NewEvent
-from matplotlib.numerix import * #FIXME
-
-import xml.dom.minidom
-import sys, os, os.path, glob, shutil
-import Queue
-import cmd
-import time
-
-global __version__
-global __codename__
-global __releasedate__
-__version__ = HOOKE_VERSION[0]
-__codename__ = HOOKE_VERSION[1]
-__releasedate__ = HOOKE_VERSION[2]
-
-from matplotlib import __version__ as mpl_version
-from wx import __version__ as wx_version
-from wxmpl import __version__ as wxmpl_version
-from scipy import __version__ as scipy_version
-from numpy import __version__ as numpy_version
-from sys import version as python_version
-import platform
-
-
-class HookeCli(cmd.Cmd):
-    
-    def __init__(self,frame,list_of_events,events_from_gui,config,drivers):
-        cmd.Cmd.__init__(self)
-                       
-        self.prompt = 'hooke: '
-        
-        
-        self.current_list=[] #the playlist we're using
-        
-        self.current=None    #the current curve under analysis. 
-        self.plots=None
-        '''
-        The actual hierarchy of the "current curve" is a bit complex:
-        
-        self.current = the lhc.HookeCurve container object of the current curve
-        self.current.curve = the current "real" curve object as defined in the filetype driver class
-        self.current.curve.default_plots() = the default plots of the filetype driver.
-        
-        The plot objects obtained by mean of self.current.curve.default_plots() 
-        then undergoes modifications by the plotmanip
-        modifier functions. The modified plot is saved in self.plots and used if needed by other functions.       
-        '''
-        
-        
-        self.pointer=0       #a pointer to navigate the current list
-                        
-        #Things that come from outside
-        self.frame=frame                        #the wx frame we refer to
-        self.list_of_events=list_of_events      #a list of wx events we use to interact with the GUI
-        self.events_from_gui=events_from_gui    #the Queue object we use to have messages from the GUI
-        self.config=config                      #the configuration dictionary
-        self.drivers=drivers                    #the file format drivers
-        
-        #get plot manipulation functions
-        plotmanip_functions=[]
-        for object_name in dir(self):
-                if object_name[0:9]=='plotmanip':
-                    plotmanip_functions.append(getattr(self,object_name))
-        #put plotmanips in order
-        self.plotmanip=[None for item in self.config['plotmanips']]
-        for item in plotmanip_functions:
-            namefunction=item.__name__[10:]
-            if namefunction in self.config['plotmanips']:
-                nameindex=self.config['plotmanips'].index(namefunction) #index of function in plotmanips config
-                self.plotmanip[nameindex] = item
-            else:
-                pass
-           
-            
-        self.playlist_saved=0 #Did we save the playlist?
-        self.playlist_name='' #Name of playlist
-        self.notes_saved=1 #Did we save the notes?
-        self.notes_filename=None #Name of notes
-
-        #create outlet
-        self.outlet=lout.Outlet()
-        
-        #Data that must be saved in the playlist, related to the whole playlist (not individual curves)
-        self.playlist_generics={} 
-        
-        #make sure we execute _plug_init() for every command line plugin we import
-        for plugin_name in self.config['plugins']:
-            try:
-                plugin=__import__(plugin_name)
-                try:
-                    eval('plugin.'+plugin_name+'Commands._plug_init(self)')
-                except AttributeError:
-                    pass
-            except ImportError:
-                pass
-
-        #load default list, if possible
-        self.do_loadlist(self.config['defaultlist'])
-        
-#HELPER FUNCTIONS
-#Everything sending an event should be here
-    def _measure_N_points(self, N, whatset=1):
-        '''
-        general helper function for N-points measures
-        '''
-        wx.PostEvent(self.frame,self.list_of_events['measure_points'](num_of_points=N, set=whatset))
-        while 1:
-            try:
-                points=self.frame.events_from_gui.get()
-                break
-            except Empty:
-                pass
-        return points
-        
-    def _get_displayed_plot(self,dest=0):
-        '''
-        returns the currently displayed plot.
-        '''
-        wx.PostEvent(self.frame, self.list_of_events['get_displayed_plot'](dest=dest))
-        while 1:
-            try:
-                displayed_plot=self.events_from_gui.get()
-            except Empty:
-                pass
-            if displayed_plot:
-                break
-        return displayed_plot
-    
-    def _send_plot(self,plots):
-        '''
-        sends a plot to the GUI
-        '''
-        wx.PostEvent(self.frame, self.list_of_events['plot_graph'](plots=plots))
-        return
-        
-    def _find_plotmanip(self, name):
-        '''
-        returns a plot manipulator function from its name
-        '''
-        return self.plotmanip[self.config['plotmanips'].index(name)]
-    
-    def _clickize(self, xvector, yvector, index):
-        '''
-        returns a ClickedPoint() object from an index and vectors of x, y coordinates       
-        '''
-        point=ClickedPoint()
-        point.index=index
-        point.absolute_coords=xvector[index],yvector[index]
-        point.find_graph_coords(xvector,yvector)
-        return point
-    
-#HERE COMMANDS BEGIN
-    
-    def help_set(self):
-        print '''
-SET
-Sets a local configuration variable
--------------
-Syntax: set [variable] [value]
-        '''
-    def do_set(self,args):
-        #FIXME: some variables in self.config should be hidden or intelligently configurated...
-        args=args.split()
-        if len(args)==0:
-            print 'You must specify a variable and a value'
-            print 'Available variables:'
-            print self.config.keys()
-            return
-        if args[0] not in self.config.keys():
-            print 'This is not an internal Hooke variable!'
-            return
-        if len(args)==1:
-            #FIXME:we should reload the config file and reset the config value
-            print self.config[args[0]]
-            return
-        key=args[0]
-        try: #try to have a numeric value
-            value=float(args[1])
-        except ValueError: #if it cannot be converted to float, it's None, or a string...
-            if value.lower()=='none':
-                value=None
-            else:
-                value=args[1]
-                
-        self.config[key]=value
-        self.do_plot(0)
-        
-#PLAYLIST MANAGEMENT AND NAVIGATION
-#------------------------------------
-    
-    def help_loadlist(self):
-        print '''
-LOADLIST
-Loads a file playlist
------------
-Syntax: loadlist [playlist file]
-        '''
-    def do_loadlist(self, args):
-        #checking for args: if nothing is given as input, we warn and exit.
-        while len(args)==0:
-            args=linp.safeinput('File to load?')
-        
-        arglist=args.split()
-        play_to_load=arglist[0]
-        
-        #We assume a Hooke playlist has the extension .hkp
-        if play_to_load[-4:] != '.hkp':
-            play_to_load+='.hkp'
-        
-        try:            
-            playxml=PlaylistXML()
-            self.current_list, self.playlist_generics=playxml.load(play_to_load)
-            self.current_playxml=playxml
-        except IOError:
-            print 'File not found.'
-            return
-        
-        print 'Loaded %s curves' %len(self.current_list)
-        
-        if 'pointer' in self.playlist_generics.keys():
-            self.pointer=int(self.playlist_generics['pointer'])
-        else:
-            #if no pointer is found, set the current curve as the first curve of the loaded playlist
-            self.pointer=0
-        print 'Starting at curve ',self.pointer
-            
-        self.current=self.current_list[self.pointer]
-        
-        #resets saved/notes saved state
-        self.playlist_saved=0
-        self.playlist_name=''
-        self.notes_saved=0        
-    
-        self.do_plot(0)
-        
-        
-    def help_genlist(self):
-        print '''
-GENLIST
-Generates a file playlist.
-Note it doesn't *save* it: see savelist for this.
-
-If [input files] is a directory, it will use all files in the directory for playlist.
-So:
-genlist dir
-genlist dir/
-genlist dir/*.*
-
-are all equivalent syntax.
-------------
-Syntax: genlist [input files]
-        
-'''
-    def do_genlist(self,args):
-        #args list is: input path, output name
-        if len(args)==0:
-            args=linp.safeinput('Input files?')
-                    
-        arglist=args.split()      
-        list_path=arglist[0]
-                  
-        #if it's a directory, is like /directory/*.*
-        #FIXME: probably a bit kludgy.
-        if os.path.isdir(list_path): 
-            if platform.system == 'Windows':
-                SLASH="\\"
-            else:
-                SLASH="/"
-            if list_path[-1] == SLASH:
-                list_path=list_path+'*.*'
-            else:    
-                list_path=list_path+SLASH+'*.*'
-        
-        #expanding correctly the input list with the glob module :)        
-        list_files=glob.glob(list_path)
-        list_files.sort()
-
-        self.current_list=[]
-        for item in list_files:
-            try:
-                if os.path.isfile(item):
-                    self.current_list.append(lhc.HookeCurve(os.path.abspath(item))) 
-            except:
-                pass
-            
-        self.pointer=0    
-        if len(self.current_list)>0:
-            self.current=self.current_list[self.pointer]
-        else:
-            print 'Empty list!'
-            return
-        
-        #resets saved/notes saved state
-        self.playlist_saved=0
-        self.playlist_name=''
-        self.notes_saved=0  
-        
-        self.do_plot(0)
-       
-        
-    def do_savelist(self,args):
-        '''
-        SAVELIST
-        Saves the current file playlist on disk.
-        ------------
-        Syntax: savelist [filename]
-        '''
-        while len(args)==0:
-            args=linp.safeinput('Output file?',['savedlist.txt'])
-    
-        output_filename=args
-        
-        self.playlist_generics['pointer']=self.pointer
-        
-        #autocomplete filename if not specified
-        if output_filename[-4:] != '.hkp':
-            output_filename+='.hkp'
-        
-        playxml=PlaylistXML()
-        playxml.export(self.current_list, self.playlist_generics)
-        playxml.save(output_filename)                  
-        
-        #remembers we have saved playlist
-        self.playlist_saved=1
-        
-    def help_addtolist(self):
-        print '''
-ADDTOLIST
-Adds a file to the current playlist
---------------
-Syntax: addtolist [filename]
-'''
-    def do_addtolist(self,args):
-        #args list is: input path
-        if len(args)==0:
-            print 'You must give the input filename you want to add'
-            self.help_addtolist()
-            return
-          
-        filenames=glob.glob(args)
-        
-        for filename in filenames:
-            self.current_list.append(lhc.HookeCurve(os.path.abspath(filename)))
-        #we need to save playlist
-        self.playlist_saved=0
-    
-    def help_printlist(self):
-        print '''
-PRINTLIST
-Prints the list of curves in the current playlist
--------------
-Syntax: printlist
-'''
-    def do_printlist(self,args):
-        for item in self.current_list:
-            print item.path
-            
-    
-    def help_jump(self):
-        print '''
-JUMP
-Jumps to a given curve.
-------
-Syntax: jump {$curve}
-
-If the curve is not in the current playlist, it politely asks if we want to add it.
-        '''  
-    def do_jump(self,filename):
-        '''
-        jumps to the curve with the given filename.
-        if the filename is not in the playlist, it asks if we must add it or not.
-        '''
-        
-        if filename=='':
-            filename=linp.safeinput('Jump to?')
-            
-        filepath=os.path.abspath(filename)
-        print filepath
-                
-        c=0
-        item_not_found=1
-        while item_not_found:
-            try:
-                
-                if self.current_list[c].path == filepath:
-                    self.pointer=c
-                    self.current=self.current_list[self.pointer]
-                    item_not_found=0
-                    self.do_plot(0)
-                else:
-                    c+=1  
-            except IndexError:
-                #We've found the end of the list.
-                answer=linp.safeinput('Curve not found in playlist. Add it to list?',['y'])
-                if answer.lower()[0]=='y':
-                    try:
-                        self.do_addtolist(filepath)
-                    except:
-                        print 'Curve file not found.'
-                        return
-                    self.current=self.current_list[-1]
-                    self.pointer=(len(current_list)-1)
-                    self.do_plot(0)
-                    
-                item_not_found=0
-    
-    
-    def do_index(self,args):
-        '''
-        INDEX
-        Prints the index of the current curve in the list
-        -----
-        Syntax: index
-        '''
-        print self.pointer+1, 'of', len(self.current_list) 
-    
-    
-    def help_next(self):
-        print '''
-NEXT
-Go the next curve in the playlist.
-If we are at the last curve, we come back to the first.
------
-Syntax: next, n
-        '''
-    def do_next(self,args):
-        try:
-            self.current.curve.close_all()
-        except:
-            print 'No curve file loaded, currently!'
-            print 'This should not happen, report to http://code.google.com/p/hooke'
-            return
-        
-        if self.pointer == (len(self.current_list)-1):
-            self.pointer=0
-            print 'Playlist finished; back to first curve.'
-        else:
-            self.pointer+=1
-        
-        self.current=self.current_list[self.pointer]
-        self.do_plot(0)
-        
-    
-    def help_n(self):
-        self.help_next()
-    def do_n(self,args):
-        self.do_next(args)
-        
-    def help_previous(self,args):
-        print '''
-PREVIOUS
-Go to the previous curve in the playlist.
-If we are at the first curve, we jump to the last.
--------
-Syntax: previous, p
-    '''
-    def do_previous(self,args):
-        try:
-            self.current.curve.close_all()
-        except:
-            print 'No curve file loaded, currently!'
-            print 'This should not happen, report to http://code.google.com/p/hooke'
-            return
-        if self.pointer == 0:
-            self.pointer=(len(self.current_list)-1)
-            print 'Start of playlist; jump to last curve.' 
-        else:
-            self.pointer-=1
-            
-        self.current=self.current_list[self.pointer]
-        self.do_plot(args)
-        
-            
-    def help_p(self):
-        self.help_previous()
-    def do_p(self,args):
-        self.do_previous(args)
-
-        
-#PLOT INTERACTION COMMANDS
-#-------------------------------    
-    def help_plot(self):
-        print '''
-PLOT
-Plots the current force curve
--------
-Syntax: plot
-        '''
-    def do_plot(self,args):
-        
-        self.current.identify(self.drivers)
-        self.plots=self.current.curve.default_plots()
-        try:
-            self.plots=self.current.curve.default_plots()
-        except Exception, e:
-            print 'Unexpected error occurred in do_plot().'
-            print e
-            return
-            
-        #apply the plotmanip functions eventually present
-        nplots=len(self.plots)
-        c=0
-        while c<nplots:
-            for function in self.plotmanip: #FIXME: something strange happens about self.plotmanip[0]
-                self.plots[c]=function(self.plots[c], self.current)
-                
-            self.plots[c].xaxes=self.config['xaxes'] #FIXME: in the future, xaxes and yaxes should be set per-plot
-            self.plots[c].yaxes=self.config['yaxes']
-                
-            c+=1
-
-        self._send_plot(self.plots)
-        
-    def _delta(self, set=1):
-        '''
-        calculates the difference between two clicked points
-        '''
-        print 'Click two points'
-        points=self._measure_N_points(N=2, whatset=set)
-        dx=abs(points[0].graph_coords[0]-points[1].graph_coords[0])
-        dy=abs(points[0].graph_coords[1]-points[1].graph_coords[1])
-        unitx=self.plots[points[0].dest].units[0]
-        unity=self.plots[points[0].dest].units[1]
-        return dx,unitx,dy,unity
-        
-    def do_delta(self,args):
-        '''
-        DELTA
-        
-        Measures the delta X and delta Y between two points.
-        ----
-        Syntax: delta
-        '''
-        dx,unitx,dy,unity=self._delta()
-        print str(dx)+' '+unitx
-        print str(dy)+' '+unity
-    
-    def _point(self, set=1):
-        '''calculates the coordinates of a single clicked point'''
-
-        print 'Click one point'
-        point=self._measure_N_points(N=1, whatset=set)
-        
-        x=point[0].graph_coords[0]
-        y=point[0].graph_coords[1]
-        unitx=self.plots[point[0].dest].units[0]
-        unity=self.plots[point[0].dest].units[1]
-        return x,unitx,y,unity
-        
-    def do_point(self,args):
-        '''
-        POINT
-        
-        Returns the coordinates of a point on the graph.
-        ----
-        Syntax: point
-        '''
-        x,unitx,y,unity=self._point()
-        print str(x)+' '+unitx
-        print str(y)+' '+unity
-        to_dump='point '+self.current.path+' '+str(x)+' '+unitx+', '+str(y)+' '+unity
-        self.outlet.push(to_dump)    
-   
-        
-    def do_close(self,args=None):
-        '''
-        CLOSE
-        Closes one of the two plots. If no arguments are given, the bottom plot is closed.
-        ------
-        Syntax: close [top,bottom]
-        '''
-        if args=='top':
-            to_close=0
-        elif args=='bottom':
-            to_close=1
-        else:
-            to_close=1
-        
-        close_plot=self.list_of_events['close_plot']
-        wx.PostEvent(self.frame, close_plot(to_close=to_close))
-        
-    def do_show(self,args=None):
-        '''
-        SHOW
-        Shows both plots.
-        ''' 
-        show_plots=self.list_of_events['show_plots']
-        wx.PostEvent(self.frame, show_plots())
-       
-        
-    
-    #PLOT EXPORT AND MANIPULATION COMMANDS
-    def help_export(self):
-        print '''
-EXPORT
-Saves the current plot as an image file
----------------
-Syntax: export [filename] {plot to export}
-
-The supported formats are PNG and EPS; the file extension of the filename is automatically recognized
-and correctly exported. Resolution is (for now) fixed at 150 dpi.
-
-If you have a multiple plot, the optional plot to export argument tells Hooke which plot you want to export. If 0, the top plot is exported. If 1, the bottom plot is exported (Exporting both plots is still to implement)
-        '''
-    def do_export(self,args):
-        #FIXME: the bottom plot doesn't have the title
-        
-        dest=0
-        
-        if len(args)==0:
-            #FIXME: We have to go into the libinput stuff and fix it, for now here's a dummy replacement...
-            #name=linp.safeinput('Filename?',[self.current.path+'.png'])
-            name=raw_input('Filename? ')
-        else:
-            args=args.split()
-            name=args[0]
-            if len(args) > 1:
-                dest=int(args[1]) 
-                
-        export_image=self.list_of_events['export_image']
-        wx.PostEvent(self.frame, export_image(name=name, dest=dest))
-        
-        
-    def help_txt(self):
-        print '''
-TXT
-Saves the current curve as a text file
-Columns are, in order:
-X1 , Y1 , X2 , Y2 , X3 , Y3 ...
-
--------------
-Syntax: txt [filename] {plot to export}
-        '''
-    def do_txt(self,args):
-        
-        def transposed2(lists, defval=0):
-            '''
-            transposes a list of lists, i.e. from [[a,b,c],[x,y,z]] to [[a,x],[b,y],[c,z]] without losing
-            elements
-            (by Zoran Isailovski on the Python Cookbook online)
-            '''
-            if not lists: return []
-            return map(lambda *row: [elem or defval for elem in row], *lists)
-        
-        whichplot=0
-        args=args.split()
-        if len(args)==0:
-            filename=linp.safeinput('Filename?',[self.current.path+'.txt'])
-        else:
-            filename=linp.checkalphainput(args[0],self.current.path+'.txt',[])
-            try:
-                whichplot=int(args[1])
-            except:
-                pass
-            
-        columns=[]     
-        for dataset in self.plots[whichplot].vectors:
-            for i in range(0,len(dataset)): 
-                columns.append([])
-                for value in dataset[i]:
-                    columns[-1].append(str(value))                   
-        
-        rows=transposed2(columns, 'nan')
-        rows=[' , '.join(item) for item in rows]
-        text='\n'.join(rows)
-        
-        txtfile=open(filename,'w+')
-        #Save units of measure in header
-        txtfile.write('X:'+self.plots[whichplot].units[0]+'\n')
-        txtfile.write('Y:'+self.plots[whichplot].units[1]+'\n')
-        txtfile.write(text)
-        txtfile.close()
-        
-    
-    #LOGGING, REPORTING, NOTETAKING
-    
-
-    def do_note_old(self,args):
-        '''
-        NOTE_OLD
-        **deprecated**: Use note instead. Will be removed in 0.9
-        
-        Writes or displays a note about the current curve.
-        If [anything] is empty, it displays the note, otherwise it adds a note.
-        The note is then saved in the playlist if you issue a savelist command
-        ---------------
-        Syntax: note_old [anything]        
-
-        '''
-        if args=='':
-            print self.current_list[self.pointer].notes
-        else:
-            #bypass UnicodeDecodeError troubles
-            try:
-                args=args.decode('ascii')
-            except:
-                args=args.decode('ascii','ignore')
-                if len(args)==0:
-                    args='?'
-                    
-            self.current_list[self.pointer].notes=args
-        self.notes_saved=0
-            
-            
-    def do_note(self,args):
-        '''
-        NOTE
-        
-        Writes or displays a note about the current curve.
-        If [anything] is empty, it displays the note, otherwise it adds a note.
-        The note is then saved in the playlist if you issue a savelist command.
-        ---------------
-        Syntax: note_old [anything]        
-
-        '''
-        if args=='':
-            print self.current_list[self.pointer].notes
-        else:
-            if self.notes_filename == None:
-                self.notes_filename=raw_input('Notebook filename? ')
-                title_line='Notes taken at '+time.asctime()+'\n'
-                f=open(self.notes_filename,'w')
-                f.write(title_line)
-                f.close()
-                
-            #bypass UnicodeDecodeError troubles    
-            try:
-               args=args.decode('ascii')
-            except:
-               args=args.decode('ascii','ignore')
-               if len(args)==0:
-                   args='?'
-            self.current_list[self.pointer].notes=args
-            
-            f=open(self.notes_filename,'a+')
-            note_string=(self.current.path+'  |  '+self.current.notes+'\n')
-            f.write(note_string)
-            f.close()
-                           
-    def help_notelog(self):
-        print '''
-NOTELOG
-Writes a log of the notes taken during the session for the current
-playlist
---------------        
-Syntax notelog [filename]
-'''        
-    def do_notelog(self,args):
-        
-        if len(args)==0:
-            args=linp.safeinput('Notelog filename?',['notelog.txt'])
-            
-        note_lines='Notes taken at '+time.asctime()+'\n'
-        for item in self.current_list:
-            if len(item.notes)>0:
-                #FIXME: log should be justified
-                #FIXME: file path should be truncated...
-                note_string=(item.path+'  |  '+item.notes+'\n')
-                note_lines+=note_string
-                
-        try:
-            f=open(args,'a+')
-            f.write(note_lines)
-            f.close()
-        except IOError, (ErrorNumber, ErrorMessage):
-            print 'Error: notes cannot be saved. Catched exception:'
-            print ErrorMessage
-        
-        self.notes_saved=1
-
-    def help_copylog(self):
-        print '''
-COPYLOG
-Moves the annotated curves to another directory
------------
-Syntax copylog [directory]
-        '''
-    def do_copylog(self,args):
-        
-        if len(args)==0:
-            args=linp.safeinput('Destination directory?')  #TODO default
-        
-        mydir=os.path.abspath(args)
-        if not os.path.isdir(mydir):
-            print 'Destination is not a directory.'
-            return
-        
-        for item in self.current_list:
-            if len(item.notes)>0:
-                try:
-                    shutil.copy(item.path, mydir)
-                except (OSError, IOError):
-                    print 'Cannot copy file. '+item.path+' Perhaps you gave me a wrong directory?'
-
-#OUTLET management
-#-----------------
-    def do_outlet_show(self,args):
-        '''OUTLET_SHOW
-        ---------
-        Shows current content of outlet with index for reference
-        '''
-        self.outlet.printbuf()
-
-    def do_outlet_undo(self, args):
-        '''OUTLET_UNDO
-        ---------
-        Eliminates last entry in outlet
-        '''
-        print 'Erasing last entry'
-        self.outlet.pop()
-
-    def do_outlet_delete(self, args):
-        '''OUTLET_DELETE
-        Eliminates a particular entry from outlet
-        Syntax: outlet_delete n
-        '''
-        if len(args)==0:
-            print 'Index needed!, use outlet_show to know it'
-        else:
-            self.outlet.delete(args)
-
-#OS INTERACTION COMMANDS
-#-----------------    
-    def help_dir(self):
-        print '''
-DIR, LS
-Lists the files in the directory
----------
-Syntax: dir [path]
-          ls  [path]
-        '''
-    def do_dir(self,args):
-        
-        if len(args)==0:
-            args='*'
-        print glob.glob(args)
-        
-    def help_ls(self):
-        self.help_dir(self)
-    def do_ls(self,args):
-        self.do_dir(args)
-        
-    def help_pwd(self):
-        print '''
-PWD
-Gives the current working directory.
-------------
-Syntax: pwd
-        '''
-    def do_pwd(self,args):
-        print os.getcwd()         
-    
-    def help_cd(self):
-        print '''
-CD
-Changes the current working directory
------
-Syntax: cd
-        '''
-    def do_cd(self,args):
-        mypath=os.path.abspath(args)
-        try:
-            os.chdir(mypath)
-        except OSError:
-            print 'I cannot access that directory.'
-    
-    
-    def help_system(self):
-        print '''
-SYSTEM
-Executes a system command line and reports the output
------
-Syntax system [command line]
-        '''
-        pass
-    def do_system(self,args):
-        waste=os.system(args)           
-            
-    def do_debug(self,args):
-        '''
-        this is a dummy command where I put debugging things
-        '''
-        print self.config['plotmanips']
-        pass
-            
-    def help_current(self):
-        print '''
-CURRENT
-Prints the current curve path.
-------
-Syntax: current
-        '''
-    def do_current(self,args):
-        print self.current.path
-        
-    def do_info(self,args):
-        '''
-        INFO
-        ----
-        Returns informations about the current curve.
-        '''
-        print 'Path: ',self.current.path
-        print 'Experiment: ',self.current.curve.experiment
-        print 'Filetype: ',self.current.curve.filetype
-        for plot in self.current.curve.default_plots():
-            for set in plot.vectors:
-                lengths=[len(item) for item in set]
-                print 'Data set size: ',lengths
-        
-    def do_version(self,args):
-        '''
-        VERSION
-        ------
-        Prints the current version and codename, plus library version. Useful for debugging.
-        '''     
-        print 'Hooke '+__version__+' ('+__codename__+')'
-        print 'Released on: '+__releasedate__
-        print '---'
-        print 'Python version: '+python_version
-        print 'WxPython version: '+wx_version
-        print 'wxMPL version: '+wxmpl_version
-        print 'Matplotlib version: '+mpl_version
-        print 'SciPy version: '+scipy_version
-        print 'NumPy version: '+numpy_version
-        print '---'
-        print 'Platform: '+str(platform.uname())
-        print '---'
-        print 'Loaded plugins:',self.config['loaded_plugins']
-        
-    def help_exit(self):
-        print '''
-EXIT, QUIT
-Exits the program cleanly.
-------
-Syntax: exit
-Syntax: quit
-'''    
-    def do_exit(self,args):
-        we_exit='N'
-        
-        if (not self.playlist_saved) or (not self.notes_saved):
-            we_exit=linp.safeinput('You did not save your playlist and/or notes. Exit?',['n'])
-        else:
-            we_exit=linp.safeinput('Exit?',['y'])
-        
-        if we_exit[0].upper()=='Y':
-            wx.CallAfter(self.frame.Close)
-            sys.exit(0)
-        else:
-            return
-    
-    def help_quit(self):
-        self.help_exit()
-    def do_quit(self,args):
-        self.do_exit(args)
-
-
-
-
-
-if __name__ == '__main__':
-    mycli=HookeCli(0)
-    mycli.cmdloop()
diff --git a/lib/__init__.py b/lib/__init__.py
new file mode 100644 (file)
index 0000000..803f29c
--- /dev/null
@@ -0,0 +1 @@
+#!/usr/bin/env python\r
diff --git a/lib/curve.py b/lib/curve.py
new file mode 100644 (file)
index 0000000..176d7bf
--- /dev/null
@@ -0,0 +1,39 @@
+#!/usr/bin/env python\r
+\r
+'''\r
+curve.py\r
+\r
+Curve and related classes for Hooke.\r
+\r
+Copyright 2010 by Dr. Rolf Schmidt (Concordia University, Canada)\r
+\r
+This program is released under the GNU General Public License version 2.\r
+'''\r
+\r
+class Curve(object):\r
+\r
+    def __init__(self):\r
+        self.color = 'blue'\r
+        self.destination = Destination()\r
+        self.label = ''\r
+        self.size = 0.5\r
+        self.style = 'plot'\r
+        self.title = ''\r
+        self.units = Units()\r
+        self.visible = True\r
+        self.x = []\r
+        self.y = []\r
+\r
+\r
+class Destination(object):\r
+\r
+    def __init__(self):\r
+        self.column = 1\r
+        self.row = 1\r
+\r
+\r
+class Units(object):\r
+\r
+    def __init__(self):\r
+        self.x = ''\r
+        self.y = ''\r
diff --git a/lib/driver.py b/lib/driver.py
new file mode 100644 (file)
index 0000000..b5b4809
--- /dev/null
@@ -0,0 +1,45 @@
+#!/usr/bin/env python
+
+'''
+driver.py
+
+Base class for file format drivers.
+
+Copyright 2006 by Massimo Sandal (University of Bologna, Italy).
+
+This program is released under the GNU General Public License version 2.
+'''
+
+import lib.plot
+
+class Driver(object):
+    '''
+    Base class for file format drivers.
+
+    To be overridden
+    '''
+    def __init__(self):
+        self.experiment = ''
+        self.filetype = ''
+
+    def is_me(self):
+        '''
+        This method must read the file and return True if the filetype can be managed by the driver, False if not.
+        '''
+        return False
+
+    def close_all(self):
+        '''
+        This method must close all the open files of the driver, explicitly.
+        '''
+        return None
+
+    def default_plots(self):
+        plot = lib.plot.Plot()
+        plot.curves.append([0])
+        plot.curves.append([0])
+        
+        return [plot]
+
+
+
diff --git a/lib/file.py b/lib/file.py
new file mode 100644 (file)
index 0000000..c7ff7d3
--- /dev/null
@@ -0,0 +1,40 @@
+#!/usr/bin/env python\r
+\r
+'''\r
+file.py\r
+\r
+File class for Hooke.\r
+\r
+Copyright 2010 by Dr. Rolf Schmidt (Concordia University, Canada)\r
+\r
+This program is released under the GNU General Public License version 2.\r
+'''\r
+\r
+import os.path\r
+import lib.plot\r
+\r
+class File(object):\r
+\r
+    def __init__(self, filename=None, drivers=None):\r
+        self.driver = None\r
+        self.notes = ''\r
+        self.plot = lib.plot.Plot()\r
+        if filename is None:\r
+            self.filename = None\r
+            self.name = None\r
+            self.path = None\r
+        else:\r
+            self.filename = filename\r
+            self.path, self.name = os.path.split(filename)\r
+\r
+    def identify(self, drivers):\r
+        '''\r
+        identifies a curve and returns the corresponding object\r
+        '''\r
+        for driver in drivers:\r
+            current_driver = driver(self.filename)\r
+            if current_driver.is_me():\r
+                #bring on all the driver, with its load of methods etc.\r
+                #so we can access the whole of it.\r
+                self.plot = current_driver.default_plots()\r
+                self.driver = current_driver\r
diff --git a/lib/libhooke.py b/lib/libhooke.py
new file mode 100644 (file)
index 0000000..f69f2d2
--- /dev/null
@@ -0,0 +1,108 @@
+#!/usr/bin/env python
+
+'''
+libhooke.py
+
+General library of internal objects and utilities for Hooke.
+
+Copyright 2006 by Massimo Sandal (University of Bologna, Italy).
+With algorithms contributed by Francesco Musiani (University of Bologna, Italy)
+And additions contributed by Dr. Rolf Schmidt (Concordia University, Canada)
+
+This program is released under the GNU General Public License version 2.
+'''
+
+import csv
+import os.path
+import numpy
+import scipy
+
+HOOKE_VERSION=['0.9.0_devel', 'Kenzo', '2010-01-31']
+WX_GOOD=['2.6','2.8']
+hookeDir=''
+
+#constants for 'special' curves
+#this can make it easier to understand what curve we are working on
+EXTENSION = 0
+RETRACTION = 1
+
+def delete_empty_lines_from_xmlfile(filename):
+    #the following 3 lines are needed to strip newlines.
+    #Otherwise, since newlines are XML elements too, the parser would read them
+    #(and re-save them, multiplying newlines...)
+    aFile=file(filename).read()
+    aFile=aFile.split('\n')
+    aFile=''.join(aFile)
+    return aFile
+
+def get_file_path(filename, folders = []):
+    if os.path.dirname(filename) == '' or os.path.isabs(filename) == False:
+        path = ''
+        for folder in folders:
+            path = os.path.join(path, folder)
+        filename = os.path.join(hookeDir, path, filename)
+
+    return filename
+
+def coth(z):
+    '''
+    hyperbolic cotangent
+    '''
+    return (numpy.exp(2 * z) + 1) / (numpy.exp(2 * z) - 1)
+
+class ClickedPoint(object):
+    '''
+    this class defines what a clicked point on the curve plot is
+    '''
+    def __init__(self):
+
+        self.is_marker = None #boolean ; decides if it is a marker
+        self.is_line_edge = None #boolean ; decides if it is the edge of a line (unused)
+        self.absolute_coords = (None, None) #(float,float) ; the absolute coordinates of the clicked point on the graph
+        self.graph_coords = (None, None) #(float,float) ; the coordinates of the plot that are nearest in X to the clicked point
+        self.index = None #integer ; the index of the clicked point with respect to the vector selected
+        self.dest = None #0 or 1 ; 0=top plot 1=bottom plot
+
+    def find_graph_coords(self, xvector, yvector):
+        '''
+        Given a clicked point on the plot, finds the nearest point in the dataset (in X) that
+        corresponds to the clicked point.
+        '''
+        dists = []
+        for index in scipy.arange(1, len(xvector), 1):
+            dists.append(((self.absolute_coords[0] - xvector[index]) ** 2)+((self.absolute_coords[1] - yvector[index]) ** 2))
+
+        self.index=dists.index(min(dists))
+        self.graph_coords=(xvector[self.index], yvector[self.index])
+#-----------------------------------------
+#CSV-HELPING FUNCTIONS
+
+def transposed2(lists, defval=0):
+    '''
+    transposes a list of lists, i.e. from [[a,b,c],[x,y,z]] to [[a,x],[b,y],[c,z]] without losing
+    elements
+    (by Zoran Isailovski on the Python Cookbook online)
+    '''
+    if not lists: return []
+    return map(lambda *row: [elem or defval for elem in row], *lists)
+
+def csv_write_dictionary(f, data, sorting='COLUMNS'):
+    '''
+    Writes a CSV file from a dictionary, with keys as first column or row
+    Keys are in "random" order.
+
+    Keys should be strings
+    Values should be lists or other iterables
+    '''
+    keys=data.keys()
+    values=data.values()
+    t_values=transposed2(values)
+    writer=csv.writer(f)
+
+    if sorting=='COLUMNS':
+        writer.writerow(keys)
+        for item in t_values:
+            writer.writerow(item)
+
+    if sorting=='ROWS':
+        print 'Not implemented!' #FIXME: implement it.
similarity index 87%
rename from libpeakspot.py
rename to lib/peakspot.py
index 398fe846cf7abb8d186cefa63e7d44f20dff6113..1a715ac4722b410bab978a5e56e6c9666b5a52a3 100644 (file)
@@ -1,11 +1,16 @@
 #!/usr/bin/env python
 
 '''
-a library of helping functions for spotting force spectroscopy peaks
+peakspot.py
 
-(c)Fabrizio Benedetti and Massimo Sandal , 2007
+A library of helping functions for spotting force spectroscopy peaks.
+
+Copyright 2007 by Fabrizio Benedetti and Massimo Sandal
+
+This program is released under the GNU General Public License version 2.
 '''
-import numpy as np
+
+from numpy import mean
 
 def conv_dx(data,vect):
     '''
@@ -14,43 +19,44 @@ def conv_dx(data,vect):
     dim=len(data)
     window=len(vect)
     temparr=[0.0]*dim
-    
+
     end=dim-window
 
     for j in range(end):
-     for k in range(window):
-      temparr[j]+=data[j+k]*vect[k]
+        for k in range(window):
+            temparr[j]+=data[j+k]*vect[k]
+
+    return temparr
 
-    return temparr  
 def absdev(arr):
     '''
     Calculates the absolute deviation of a vector
     '''
     med=0.0
     absD=0.0
-    
-    med=np.mean(arr)
+
+    med=mean(arr)
     for j in arr:
         absD+=abs(j-med)
     return absD/len(arr)
+
 def noise_absdev(data,positive=False,maxcut=0.2,stable=0.005):
     '''
     Returns the standard deviation of the noise.
     The logic is: we cut the most negative (or positive) data points until the absolute deviation
     becomes stable (it doesn't vary more than 0.005) or we have cut more than maxcut*len(data) points.
     Then calculate the absolute deviation.
-    
+
     If positive=True we cut the most positive data points, False=we cut the negative ones.
     '''
+    #TOD: check if this is necessary
     out=[item for item in data] #we copy just to be sure...
     out.sort()
     if positive:
         out.reverse()
-        
+
     temp_absdev=absdev(out)
-    
+
     for index in range(len(out)):
         cutindex=(index+1)*5
         cut_absdev=absdev(out[cutindex:]) #we jump five points after five points...
@@ -58,18 +64,18 @@ def noise_absdev(data,positive=False,maxcut=0.2,stable=0.005):
             temp_absdev=cut_absdev
         else:
             break
-        
+
     return cut_absdev
-        
+
 def abovenoise(convoluted,noise_level,cut_index=0,abs_devs=4):
     '''
     Generates a vector which is 0 where the vector is less than abs_devs*noise_level ; 1 if not (spike).
     '''
     #calculate absolute noise deviation
     #noise_level=noise_absdev(convoluted[cut_index:])
-        
+
     above=[]
-        
+
     for index in range(len(convoluted)):
         if index<cut_index:
             above.append(0)
@@ -80,14 +86,14 @@ def abovenoise(convoluted,noise_level,cut_index=0,abs_devs=4):
             else:
                 above.append(0)
     return above
-        
+
 def find_peaks(above, seedouble=10):
     '''
     Finds individual peak location.
     abovenoise() finds all points above a given threshold in the convolution. This point is often not unique
     but there is a "cluster" of points above a threshold.
-    Here we obtain only the coordinates of the largest *convolution* spike for each cluster.       
-        
+    Here we obtain only the coordinates of the largest *convolution* spike for each cluster.
+
     above=vector obtained from abovenoise()
     seedouble=value at which we want to "delete" double peaks. That is, if two peaks have a distance
     < than $seedouble points , only the first is kept.
@@ -95,7 +101,7 @@ def find_peaks(above, seedouble=10):
     nonzero=[]
     peaks_location=[]
     peaks_size=[]
-        
+
     for index in range(len(above)):
         if above[index] != 0:
             nonzero.append(index)
@@ -108,7 +114,7 @@ def find_peaks(above, seedouble=10):
                 nonzero=[]
             else:
                 pass
-                
+
     #recursively eliminate double peaks
     #(maybe not the smartest of cycles, but i'm asleep...)
     temp_location=None
@@ -119,6 +125,6 @@ def find_peaks(above, seedouble=10):
                 if peaks_location[index+1]-peaks_location[index] < seedouble:
                     temp_location=peaks_location[:index]+peaks_location[index+1:]
         if temp_location != []:
-            peaks_location=temp_location           
-        
+            peaks_location=temp_location
+
     return peaks_location,peaks_size
\ No newline at end of file
diff --git a/lib/playlist.py b/lib/playlist.py
new file mode 100644 (file)
index 0000000..c82e697
--- /dev/null
@@ -0,0 +1,174 @@
+#!/usr/bin/env python\r
+\r
+'''\r
+playlist.py\r
+\r
+Playlist class for Hooke.\r
+\r
+Copyright 2010 by Dr. Rolf Schmidt (Concordia University, Canada)\r
+\r
+This program is released under the GNU General Public License version 2.\r
+'''\r
+\r
+import os.path\r
+import xml.dom.minidom\r
+\r
+import lib.libhooke\r
+import lib.file\r
+\r
+class Playlist(object):\r
+\r
+    def __init__(self, filename=None):\r
+        self._saved = False\r
+        self.count = 0\r
+        self.figure = None\r
+        self.files = []\r
+        self.generics_dict = {}\r
+        self.hidden_attributes = ['curve', 'data', 'driver', 'fits', 'name', 'plots']\r
+        self.index = -1\r
+        self.name = None\r
+        self.path = None\r
+        self.plot_panel = None\r
+        self.plot_tab = None\r
+        if filename is None:\r
+            self.filename = None\r
+        else:\r
+            self.load(filename)\r
+\r
+    def add_file(self, filename):\r
+        if os.path.isfile(filename):\r
+            file_to_add = lib.file.File(filename)\r
+            self.files.append(file_to_add)\r
+            self._saved = False\r
+        self.count = len(self.files)\r
+\r
+    def delete_file(self, name):\r
+        for index, item in enumerate(self.files):\r
+            if item.name == name:\r
+                del self.files[index]\r
+                self.index = index\r
+        self.count = len(self.files)\r
+        if self.index > self.count - 1:\r
+            self.index = 0\r
+\r
+    def filter_curves(self, curves_to_keep=[]):\r
+        playlist = Playlist()\r
+        for curve_index in curves_to_keep:\r
+            playlist.files.append(self.files[curve_index])\r
+        playlist.count = len(playlist.files)\r
+        playlist.index = 0\r
+        return playlist\r
+\r
+    def get_active_file(self):\r
+        return self.files[self.index]\r
+\r
+    #def get_active_plot(self):\r
+        ##TODO: is this the only active (or default?) plot?\r
+        #return self.files[self.index].plots[0]\r
+\r
+    def get_status_string(self):\r
+        if self.count > 0:\r
+            activeFileStr = ''.join([' (%s/%s)' %(self.index + 1, self.count)])\r
+            return ''.join([self.name, activeFileStr])\r
+        else:\r
+            return ''.join(['The file ', self.name, ' does not contain any valid force curve data.\n'])\r
+\r
+    def load(self, filename):\r
+        '''\r
+        loads a playlist file\r
+        '''\r
+        self.filename = filename\r
+        self.path, self.name = os.path.split(filename)\r
+        playlist_file = lib.libhooke.delete_empty_lines_from_xmlfile(filename)\r
+        self.xml = xml.dom.minidom.parseString(playlist_file)\r
+        #TODO: rename 'element' to 'curve' or something in hkp file\r
+        #TODO: rename 'path' to 'filename'\r
+        #TODO: switch from attributes to nodes, it's cleaner XML in my eyes\r
+\r
+        element_list = self.xml.getElementsByTagName('element')\r
+        #populate playlist with files\r
+        for index, element in enumerate(element_list):\r
+            #rebuild a data structure from the xml attributes\r
+            #the next two lines are here for backwards compatibility, newer playlist files use 'filename' instead of 'path'\r
+            if element.hasAttribute('path'):\r
+                filename = lib.libhooke.get_file_path(element.getAttribute('path'))\r
+            if element.hasAttribute('filename'):\r
+                filename = lib.libhooke.get_file_path(element.getAttribute('filename'))\r
+            if os.path.isfile(filename):\r
+                data_file = lib.file.File(filename)\r
+                self.files.append(data_file)\r
+        self.count = len(self.files)\r
+        if self.count > 0:\r
+            #populate generics\r
+            genericsDict = {}\r
+            generics_list = self.xml.getElementsByTagName('generics')\r
+            if generics_list:\r
+                for attribute in generics_list[0].attributes.keys():\r
+                    genericsDict[attribute] = generics_list[0].getAttribute(attribute)\r
+            if genericsDict.has_key('pointer'):\r
+                index = int(genericsDict['pointer'])\r
+                if index >= 0 and index < self.count:\r
+                    self.index = index\r
+                else:\r
+                    index = 0\r
+            self._saved = True\r
+\r
+    def next(self):\r
+        self.index += 1\r
+        if self.index > self.count - 1:\r
+            self.index = 0\r
+\r
+    def previous(self):\r
+        self.index -= 1\r
+        if self.index < 0:\r
+            self.index = self.count - 1\r
+\r
+    def reset(self):\r
+        if self.count > 0:\r
+            self.index = 0\r
+        else:\r
+            self.index = -1\r
+\r
+    def save(self, filename):\r
+        '''\r
+        Saves a playlist from a list of files.\r
+        A playlist is an XML document with the following syntax:\r
+        <playlist>\r
+        <element path="/my/file/path/"/ attribute="attribute">\r
+        <element path="...">\r
+        </playlist>\r
+        '''\r
+        try:\r
+            output_file = file(filename, 'w')\r
+        except IOError:\r
+            self.AppendToOutput('Cannot save playlist. Wrong path or filename')\r
+            return\r
+        #create the output playlist, a simple XML document\r
+        implementation = xml.dom.minidom.getDOMImplementation()\r
+        #create the document DOM object and the root element\r
+        self.xml = implementation.createDocument(None, 'playlist', None)\r
+        root = self.xml.documentElement\r
+\r
+        #save generics variables\r
+        playlist_generics = self.xml.createElement('generics')\r
+        root.appendChild(playlist_generics)\r
+        self.generics_dict['pointer'] = self.index\r
+        for key in self.generics_dict.keys():\r
+        #for key in generics.keys():\r
+            self.xml.createAttribute(key)\r
+            playlist_generics.setAttribute(key, str(self.generics_dict[key]))\r
+\r
+        #save files and their attributes\r
+        for item in self.files:\r
+            #playlist_element=newdoc.createElement("file")\r
+            playlist_element = self.xml.createElement('element')\r
+            root.appendChild(playlist_element)\r
+            for key in item.__dict__:\r
+                if not (key in self.hidden_attributes):\r
+                    self.xml.createAttribute(key)\r
+                    playlist_element.setAttribute(key, str(item.__dict__[key]))\r
+        self._saved = False\r
+\r
+        self.xml.writexml(output_file, indent='\n')\r
+        output_file.close()\r
+        self._saved = True\r
diff --git a/lib/plot.py b/lib/plot.py
new file mode 100644 (file)
index 0000000..cfad721
--- /dev/null
@@ -0,0 +1,40 @@
+#!/usr/bin/env python\r
+\r
+'''\r
+plot.py\r
+\r
+Plot class for Hooke.\r
+\r
+Copyright 2010 by Dr. Rolf Schmidt (Concordia University, Canada)\r
+\r
+This program is released under the GNU General Public License version 2.\r
+'''\r
+\r
+class Invert(object):\r
+\r
+    def __init__(self):\r
+        self.x = False\r
+        self.y = False\r
+\r
+\r
+class Plot(object):\r
+\r
+    def __init__(self):\r
+        self.corrected_curves = []\r
+        self.curves = []\r
+        self.invert = Invert()\r
+        self.raw_curves = []\r
+        self.results = {}\r
+        self.title = ''\r
+\r
+    def normalize(self):\r
+        '''\r
+        Trims the vector lengths as to be equal in a plot.\r
+        '''\r
+        lengths = []\r
+        for curve in self.curves:\r
+            lengths.append(len(curve.x))\r
+            lengths.append(len(curve.y))\r
+            if min(lengths) != max(lengths):\r
+                curve.x = curve.x[0:min(lengths)]\r
+                curve.y = curve.y[0:min(lengths)]\r
diff --git a/lib/plotmanipulator.py b/lib/plotmanipulator.py
new file mode 100644 (file)
index 0000000..2d820d3
--- /dev/null
@@ -0,0 +1,25 @@
+#!/usr/bin/env python\r
+\r
+'''\r
+plotmanipulator.py\r
+\r
+Plotmanipulator class for Hooke.\r
+\r
+Copyright 2010 by Dr. Rolf Schmidt (Concordia University, Canada)\r
+\r
+This program is released under the GNU General Public License version 2.\r
+'''\r
+\r
+from string import replace\r
+\r
+class Plotmanipulator(object):\r
+    def __init__(self, command=None, method=None):\r
+        #the command (e.g. plotmanip_correct)\r
+        self.command = command\r
+        #the method associated with the command\r
+        self.method = method\r
+        #the suffix of the command (e.g. correct) to retrieve\r
+        #status (active or not from config)\r
+        self.name = command.replace('plotmanip_', '')\r
+\r
+\r
diff --git a/lib/plugin.py b/lib/plugin.py
new file mode 100644 (file)
index 0000000..a4641a6
--- /dev/null
@@ -0,0 +1,18 @@
+#!/usr/bin/env python\r
+\r
+'''\r
+plugin.py\r
+\r
+ConfigObj plugin class for Hooke.\r
+\r
+Copyright 2010 by Dr. Rolf Schmidt (Concordia University, Canada)\r
+\r
+This program is released under the GNU General Public License version 2.\r
+'''\r
+\r
+class Plugin(object):\r
+\r
+    def __init__(self):\r
+        self.key = ''\r
+        self.name = ''\r
+        self.prefix = ''\r
diff --git a/lib/prettyformat.py b/lib/prettyformat.py
new file mode 100644 (file)
index 0000000..b346115
--- /dev/null
@@ -0,0 +1,142 @@
+#!/usr/bin/env python\r
+\r
+'''\r
+prettyformat.py\r
+\r
+Simple Python function to format values with nice prefixes\r
+Version 1.0.1\r
+\r
+History\r
+2009 07 16: added negative number support\r
+            added decimal-formatted output\r
+\r
+Copyright 2009 by Dr. Rolf Schmidt (Concordia University, Canada)\r
+\r
+This program is released under the GNU General Public License version 2.\r
+'''\r
+\r
+import math\r
+from numpy import isnan\r
+\r
+def pretty_format(fValue, sUnit='', iDecimals=-1, iMultiplier=1, bLeadingSpaces=False):\r
+    if fValue != 0:\r
+        iLeadingSpaces = 0\r
+        if bLeadingSpaces:\r
+            iLeadingSpaces = 5\r
+        if iMultiplier == 1:\r
+            iMultiplier=get_multiplier(fValue)\r
+        sUnitString = ''\r
+        if sUnit != '':\r
+            sUnitString = ' ' + get_prefix(iMultiplier) + sUnit\r
+        if iDecimals >= 0:\r
+            formatString = '% ' + repr(iLeadingSpaces + iDecimals) + '.' + repr(iDecimals) + 'f'\r
+            return formatString % (fValue / iMultiplier) + sUnitString\r
+        else:\r
+            return str(fValue / iMultiplier) + sUnitString\r
+    else:\r
+        return '0'\r
+    return str(fValue / iMultiplier) + ' ' + get_prefix(fValue / iMultiplier) + sUnit\r
+\r
+def get_multiplier(fValue):\r
+    return pow(10, get_power(fValue))\r
+\r
+def get_power(fValue):\r
+    if fValue != 0 and not isnan(fValue):\r
+        #get the log10 from fValue (make sure the value is not negative)\r
+        dHelp = math.floor(math.log10(math.fabs(fValue)))\r
+        #reduce the log10 to a multiple of 3 and return it\r
+        return dHelp-(dHelp % 3)\r
+    else:\r
+        return 0\r
+\r
+def get_prefix(fValue):\r
+    #set up a dictionary to find the prefix\r
+    prefix = {\r
+        24: lambda: 'Y',\r
+        21: lambda: 'Z',\r
+        18: lambda: 'E',\r
+        15: lambda: 'P',\r
+        12: lambda: 'T',\r
+        9: lambda: 'G',\r
+        6: lambda: 'M',\r
+        3: lambda: 'k',\r
+        0: lambda: '',\r
+        -3: lambda: 'm',\r
+        -6: lambda: u'\u00B5',\r
+        -9: lambda: 'n',\r
+        -12: lambda: 'p',\r
+        -15: lambda: 'f',\r
+        -18: lambda: 'a',\r
+        -21: lambda: 'z',\r
+        -24: lambda: 'y',\r
+    }\r
+    if fValue != 0 and not isnan(fValue):\r
+        #get the log10 from fValue\r
+        dHelp = math.floor(math.log10(math.fabs(fValue)))\r
+    else:\r
+        dHelp = 0\r
+    #reduce the log10 to a multiple of 3 and create the return string\r
+    return prefix.get(dHelp - (dHelp % 3))()\r
+\r
+'''\r
+dTestValue=-2.4115665714484597e-008\r
+print 'Value: '+str(dTestValue)+')'\r
+print 'pretty_format example (value, unit)'\r
+print pretty_format(dTestValue, 'N')\r
+print'-----------------------'\r
+print 'pretty_format example (value, unit, decimals)'\r
+print pretty_format(dTestValue, 'N', 3)\r
+print'-----------------------'\r
+print 'pretty_format example (value, unit, decimals, multiplier)'\r
+print pretty_format(dTestValue, 'N', 5, 0.000001)\r
+print'-----------------------'\r
+print 'pretty_format example (value, unit, decimals, multiplier, leading spaces)'\r
+print pretty_format(0.0166276297705, 'N', 3, 0.001, True)\r
+print pretty_format(0.00750520813323, 'N', 3, 0.001, True)\r
+print pretty_format(0.0136453282825, 'N', 3, 0.001, True)\r
+'''\r
+'''\r
+#example use autoFormatValue\r
+dTestValue=0.00000000567\r
+print 'autoFormatValue example ('+str(dTestValue)+')'\r
+print autoFormatValue(dTestValue, 'N')\r
+#outputs 5.67 nN\r
+'''\r
+'''\r
+#example use of decimalFormatValue(fValue, iDecimals, sUnit):\r
+dTestValue=-2.4115665714484597e-008\r
+iDecimals=3\r
+print 'decimalFormatValue example ('+str(dTestValue)+')'\r
+print decimalFormatValue(dTestValue, iDecimals, 'N')\r
+#outputs -24.116 nN\r
+#change iDecimals to see the effect\r
+'''\r
+'''\r
+#example use formatValue\r
+dTestValue=0.000000000567\r
+print 'formatValue example ('+str(dTestValue)+')'\r
+#find the (common) multiplier\r
+iMultiplier=get_multiplier(dTestValue)\r
+#use the multiplier and a unit to format the value\r
+print formatValue(dTestValue, iMultiplier, 'N')\r
+#outputs 567.0 pN\r
+'''\r
+'''\r
+#to output a scale:\r
+#choose any value on the axis and find the multiplier and prefix for it\r
+#use those to format the rest of the scale\r
+#as values can span several orders of magnitude, you have to decide what units to use\r
+\r
+#tuple of values:\r
+scaleValues=0.000000000985, 0.000000001000, 0.000000001015\r
+#use this element (change to 1 or 2 to see the effect on the scale and label)\r
+iIndex=0\r
+#get the multiplier from the value at iIndex\r
+iMultiplier=get_multiplier(scaleValues[iIndex])\r
+print '\nScale example'\r
+iDecimals=3\r
+#print the scale\r
+for aValue in scaleValues: print decimalFormat(aValue/iMultiplier, iDecimals),\r
+#print the scale label using the value at iIndex\r
+print '\n'+get_prefix(scaleValues[iIndex])+'N'\r
+'''
\ No newline at end of file
diff --git a/lib/results.py b/lib/results.py
new file mode 100644 (file)
index 0000000..7535ac9
--- /dev/null
@@ -0,0 +1,199 @@
+#!/usr/bin/env python\r
+\r
+'''\r
+results.py\r
+\r
+Result and Results classes for Hooke.\r
+\r
+Copyright 2009 by Dr. Rolf Schmidt (Concordia University, Canada)\r
+\r
+This program is released under the GNU General Public License version 2.\r
+'''\r
+\r
+import prettyformat\r
+import lib.curve\r
+\r
+DEFAULT_COLOR = 'green'\r
+DEFAULT_DECIMAL = 2\r
+DEFAULT_STYLE = 'scatter'\r
+\r
+class Result(lib.curve.Curve):\r
+    def __init__(self):\r
+        lib.curve.Curve.__init__(self)\r
+        self.color = DEFAULT_COLOR\r
+        self.result = {}\r
+        self.style = DEFAULT_STYLE\r
+\r
+class Results(object):\r
+    def __init__(self):\r
+        self.columns = []\r
+        self.decimals = {}\r
+        self.has_multipliers = False\r
+        self.multipliers = {}\r
+        self.results = []\r
+        self.separator='\t'\r
+        self.units = {}\r
+\r
+    def get_pretty_value(self, column, value):\r
+        if self.has_multipliers and self.has_results():\r
+            multiplier = self.multipliers[column]\r
+            decimals = self.decimals[column]\r
+            return prettyformat.pretty_format(value, '', decimals, multiplier, True)\r
+        return str(value)\r
+\r
+    #def get_fit_result(self):\r
+        #if not(self.has_multipliers):\r
+            #self.set_multipliers()\r
+\r
+        #sResult = 'Contour length ['+prettyformat.get_prefix(self.multiplierContourLength) + 'm]' + self.separator\r
+        #sResult += prettyformat.pretty_format(self.contourLength[0], '', self.decimals, self.multiplierContourLength, True) + '\n'\r
+        #sResult += 'Persistence length ['+prettyformat.get_prefix(self.multiplierPersistenceLength) + 'm]' + self.separator\r
+        #sResult += prettyformat.pretty_format(self.persistenceLength[0], '', self.decimals, self.multiplierPersistenceLength, True) + '\n'\r
+        #sResult += 'Rupture force ['+prettyformat.get_prefix(self.multiplierRuptureForce) + 'N]' + self.separator\r
+        #sResult += prettyformat.pretty_format(self.ruptureForces[0], '', self.decimals, self.multiplierRuptureForce, True) + '\n'\r
+        #sResult += 'Slope ['+prettyformat.get_prefix(self.multiplierSlope) + 'N/m]' + self.separator\r
+        #sResult += prettyformat.pretty_format(self.slopes[0], '', self.decimals, self.multiplierSlope, True)+'\n'\r
+        #sResult += 'Sigma contour ['+prettyformat.get_prefix(self.multiplierContourLength) + 'm]' + self.separator\r
+        #sResult += prettyformat.pretty_format(self.contourLengthSigma[0], '', self.decimals, self.multiplierContourLength, True) + '\n'\r
+        #sResult += 'Sigma persistence ['+prettyformat.get_prefix(self.multiplierPersistenceLength) + 'm]' + self.separator\r
+        #sResult += prettyformat.pretty_format(self.persistenceLengthSigma[0], '', self.decimals, self.multiplierPersistenceLength, True)\r
+\r
+        #return sResult\r
+\r
+    #def get_fit_results(self, index):\r
+        #if index >= 0 and index < len(self.contourLength):\r
+            #if not(self.has_multipliers):\r
+                #self.set_multipliers()\r
+            #sLine = prettyformat.pretty_format(self.contourLength[index], '', self.decimals, self.multiplierContourLength, True) + self.separator\r
+            #sLine += prettyformat.pretty_format(self.persistenceLength[index], '', self.decimals, self.multiplierPersistenceLength, True) + self.separator\r
+            #sLine += prettyformat.pretty_format(self.ruptureForces[index], '', self.decimals, self.multiplierRuptureForce, True) + self.separator\r
+            #sLine += prettyformat.pretty_format(self.slopes[index], '', self.decimals, self.multiplierSlope, True) + self.separator\r
+            #sLine += prettyformat.pretty_format(self.contourLengthSigma[index], '', self.decimals, self.multiplierContourLength, True) + self.separator\r
+            #sLine += prettyformat.pretty_format(self.persistenceLengthSigma[index], '', self.decimals, self.multiplierPersistenceLength, True)\r
+\r
+            #return sLine\r
+        #else:\r
+            #return ''\r
+\r
+    def has_results(self):\r
+        return len(self.results) > 0\r
+\r
+    def get_header_as_list(self):\r
+        header_list = []\r
+        if self.has_results():\r
+            if not self.has_multipliers:\r
+                self.set_multipliers()\r
+            for column in self.columns:\r
+                unit_str = ''.join([prettyformat.get_prefix(self.multipliers[column]), self.units[column]])\r
+                header_str = ''.join([column, ' [', unit_str, ']'])\r
+                header_list.append(header_str)\r
+        return header_list\r
+\r
+    def get_header_as_str(self, separator=None):\r
+        if separator is None:\r
+            separator = self.separator\r
+        return separator.join(map(str, self.get_header_as_list()))\r
+\r
+    def get_result_as_list(self, index=0):\r
+        if index >= 0 and index < len(self.results):\r
+            result_list = []\r
+            if self.has_results():\r
+                if not self.has_multipliers:\r
+                    self.set_multipliers()\r
+                for column in self.columns:\r
+                    result_str = prettyformat.pretty_format(self.results[index].result[column], '', self.decimals[column], self.multipliers[column], True)\r
+                    result_list.append(result_str)\r
+            return result_list\r
+        else:\r
+            return None\r
+\r
+    def get_result_as_string(self, index=0):\r
+        results_list = self.get_result_as_list(index)\r
+        if results_list is not None:\r
+            return self.separator.join(map(str, results_list))\r
+        else:\r
+            return ''\r
+\r
+    def set_decimal(self, column, decimal=DEFAULT_DECIMAL):\r
+        if self.decimals.has_key(column):\r
+            self.decimals[column] = decimal\r
+\r
+    def set_decimals(self, decimals=DEFAULT_DECIMAL):\r
+        if decimals < 0:\r
+            #set default value if necessary\r
+            decimals = DEFAULT_DECIMAL\r
+        for column in self.columns:\r
+            self.decimals[column] = decimals\r
+\r
+    def set_multipliers(self, index=0):\r
+        if self.has_results():\r
+            if index >= 0 and index < len(self.results):\r
+                for column in self.columns:\r
+                    #result will contain the results dictionary at 'index'\r
+                    result = self.results[index][0]\r
+                    #in position 0 of the result we find the value\r
+                    self.multipliers[column] = prettyformat.get_multiplier(result[column][0])\r
+                self.has_multipliers = True\r
+        else:\r
+            self.has_multipliers = False\r
+\r
+\r
+class ResultsFJC(Results):\r
+    def __init__(self):\r
+        Results.__init__(self)\r
+        self.columns = ['Contour length', 'sigma contour length', 'Kuhn length', 'sigma Kuhn length', 'Rupture force', 'Slope', 'Loading rate']\r
+        self.units['Contour length'] = 'm'\r
+        self.units['sigma contour length'] = 'm'\r
+        self.units['Kuhn length'] = 'm'\r
+        self.units['sigma Kuhn length'] = 'm'\r
+        self.units['Rupture force'] = 'N'\r
+        self.units['Slope'] = 'N/m'\r
+        self.units['Loading rate'] = 'N/s'\r
+        self.set_decimals(2)\r
+\r
+    def set_multipliers(self, index=0):\r
+        if self.has_results():\r
+            if index >= 0 and index < len(self.results):\r
+                for column in self.columns:\r
+                    #result will contain the results dictionary at 'index'\r
+                    result = self.results[index].result\r
+                    #in position 0 of the result we find the value\r
+                    if column == 'sigma contour length':\r
+                        self.multipliers[column] = self.multipliers['Contour length']\r
+                    elif column == 'sigma Kuhn length':\r
+                        self.multipliers[column] = self.multipliers['Kuhn length']\r
+                    else:\r
+                        self.multipliers[column] = prettyformat.get_multiplier(result[column])\r
+                self.has_multipliers = True\r
+        else:\r
+            self.has_multipliers = False\r
+\r
+class ResultsWLC(Results):\r
+    def __init__(self):\r
+        Results.__init__(self)\r
+        self.columns = ['Contour length', 'sigma contour length', 'Persistence length', 'sigma persistence length', 'Rupture force', 'Slope', 'Loading rate']\r
+        self.units['Contour length'] = 'm'\r
+        self.units['sigma contour length'] = 'm'\r
+        self.units['Persistence length'] = 'm'\r
+        self.units['sigma persistence length'] = 'm'\r
+        self.units['Rupture force'] = 'N'\r
+        self.units['Slope'] = 'N/m'\r
+        self.units['Loading rate'] = 'N/s'\r
+        self.set_decimals(2)\r
+\r
+    def set_multipliers(self, index=0):\r
+        if self.has_results():\r
+            if index >= 0 and index < len(self.results):\r
+                for column in self.columns:\r
+                    #result will contain the results dictionary at 'index'\r
+                    result = self.results[index].result\r
+                    #in position 0 of the result we find the value\r
+                    if column == 'sigma contour length':\r
+                        self.multipliers[column] = self.multipliers['Contour length']\r
+                    elif column == 'sigma persistence length':\r
+                        self.multipliers[column] = self.multipliers['Persistence length']\r
+                    else:\r
+                        self.multipliers[column] = prettyformat.get_multiplier(result[column])\r
+                self.has_multipliers = True\r
+        else:\r
+            self.has_multipliers = False\r
diff --git a/libhooke.py b/libhooke.py
deleted file mode 100755 (executable)
index ed5c088..0000000
+++ /dev/null
@@ -1,346 +0,0 @@
-#!/usr/bin/env python
-
-'''
-libhooke.py
-
-General library of internal objects and utilities for Hooke.
-
-Copyright (C) 2006 Massimo Sandal (University of Bologna, Italy).
-With algorithms contributed by Francesco Musiani (University of Bologna, Italy)
-
-This program is released under the GNU General Public License version 2.
-'''
-
-
-
-import libhookecurve as lhc
-
-import scipy
-import scipy.signal
-import scipy.optimize
-import scipy.stats
-import numpy
-import xml.dom.minidom
-import os
-import string
-import csv
-
-HOOKE_VERSION=['0.8.3_devel', 'Seinei', '2008-04-16']
-WX_GOOD=['2.6','2.8'] 
-    
-class PlaylistXML:
-        '''
-        This module allows for import/export of an XML playlist into/out of a list of HookeCurve objects
-        '''
-        
-        def __init__(self):
-            
-            self.playlist=None #the DOM object representing the playlist data structure
-            self.playpath=None #the path of the playlist XML file
-            self.plaything=None
-            self.hidden_attributes=['curve'] #This list contains hidden attributes that we don't want to go into the playlist.
-        
-        def export(self, list_of_hooke_curves, generics):
-            '''
-            Creates an initial playlist from a list of files.
-            A playlist is an XML document with the following syntaxis:
-            <playlist>
-            <element path="/my/file/path/"/ attribute="attribute">
-            <element path="...">
-            </playlist>
-            '''   
-        
-            #create the output playlist, a simple XML document
-            impl=xml.dom.minidom.getDOMImplementation()
-            #create the document DOM object and the root element
-            newdoc=impl.createDocument(None, "playlist",None)
-            top_element=newdoc.documentElement
-            
-            #save generics variables
-            playlist_generics=newdoc.createElement("generics")
-            top_element.appendChild(playlist_generics)
-            for key in generics.keys():
-                newdoc.createAttribute(key)
-                playlist_generics.setAttribute(key,str(generics[key]))
-            
-            #save curves and their attributes
-            for item in list_of_hooke_curves:
-                #playlist_element=newdoc.createElement("curve")
-                playlist_element=newdoc.createElement("element")
-                top_element.appendChild(playlist_element)
-                for key in item.__dict__:
-                    if not (key in self.hidden_attributes):
-                        newdoc.createAttribute(key)
-                        playlist_element.setAttribute(key,str(item.__dict__[key]))    
-            
-            self.playlist=newdoc
-            
-        def load(self,filename):
-            '''
-            loads a playlist file
-            '''
-            myplay=file(filename)
-            self.playpath=filename
-            
-            #the following 3 lines are needed to strip newlines. otherwise, since newlines
-            #are XML elements too (why?), the parser would read them (and re-save them, multiplying
-            #newlines...)
-            #yes, I'm an XML n00b
-            the_file=myplay.read()
-            the_file_lines=the_file.split('\n')
-            the_file=''.join(the_file_lines)
-                       
-            self.playlist=xml.dom.minidom.parseString(the_file)  
-                           
-            #inner parsing functions
-            def handlePlaylist(playlist):
-                list_of_files=playlist.getElementsByTagName("element")
-                generics=playlist.getElementsByTagName("generics")
-                return handleFiles(list_of_files), handleGenerics(generics)
-            
-            def handleGenerics(generics):
-                generics_dict={}
-                if len(generics)==0:
-                    return generics_dict
-                
-                for attribute in generics[0].attributes.keys():
-                    generics_dict[attribute]=generics[0].getAttribute(attribute)
-                return generics_dict
-        
-            def handleFiles(list_of_files):
-                new_playlist=[]
-                for myfile in list_of_files:
-                    #rebuild a data structure from the xml attributes
-                    the_curve=lhc.HookeCurve(myfile.getAttribute('path'))
-                    for attribute in myfile.attributes.keys(): #extract attributes for the single curve
-                        the_curve.__dict__[attribute]=myfile.getAttribute(attribute)
-                    new_playlist.append(the_curve)
-                
-                return new_playlist #this is the true thing returned at the end of this function...(FIXME: clarity)
-                    
-            return handlePlaylist(self.playlist)
-            
-
-        def save(self,output_filename):
-            '''
-            saves the playlist in a XML file.
-            '''
-            try:
-                outfile=file(output_filename,'w')
-            except IOError:
-                print 'libhooke.py : Cannot save playlist. Wrong path or filename'
-                return
-            
-            self.playlist.writexml(outfile,indent='\n')
-            outfile.close()
-
-
-class HookeConfig:
-    '''
-    Handling of Hooke configuration file
-    
-    Mostly based on the simple-yet-useful examples of the Python Library Reference
-    about xml.dom.minidom
-    
-    FIXME: starting to look a mess, should require refactoring
-    '''
-    
-    def __init__(self):
-        self.config={}
-        self.config['plugins']=[]
-        self.config['drivers']=[]
-        self.config['plotmanips']=[]
-                
-    def load_config(self, filename):
-        myconfig=file(filename)
-                    
-        #the following 3 lines are needed to strip newlines. otherwise, since newlines
-        #are XML elements too, the parser would read them (and re-save them, multiplying
-        #newlines...)
-        #yes, I'm an XML n00b
-        the_file=myconfig.read()
-        the_file_lines=the_file.split('\n')
-        the_file=''.join(the_file_lines)
-                       
-        self.config_tree=xml.dom.minidom.parseString(the_file)  
-        
-        def getText(nodelist):
-            #take the text from a nodelist
-            #from Python Library Reference 13.7.2
-            rc = ''
-            for node in nodelist:
-                if node.nodeType == node.TEXT_NODE:
-                    rc += node.data
-            return rc
-        
-        def handleConfig(config):
-            display_elements=config.getElementsByTagName("display")
-            plugins_elements=config.getElementsByTagName("plugins")
-            drivers_elements=config.getElementsByTagName("drivers")
-            workdir_elements=config.getElementsByTagName("workdir")
-            defaultlist_elements=config.getElementsByTagName("defaultlist")
-            plotmanip_elements=config.getElementsByTagName("plotmanips")
-            handleDisplay(display_elements)
-            handlePlugins(plugins_elements)
-            handleDrivers(drivers_elements)
-            handleWorkdir(workdir_elements)
-            handleDefaultlist(defaultlist_elements)
-            handlePlotmanip(plotmanip_elements)
-            
-        def handleDisplay(display_elements):
-            for element in display_elements:
-                for attribute in element.attributes.keys():
-                    self.config[attribute]=element.getAttribute(attribute)
-                    
-        def handlePlugins(plugins):
-            for plugin in plugins[0].childNodes:
-                try:
-                    self.config['plugins'].append(str(plugin.tagName))
-                except: #if we allow fancy formatting of xml, there is a text node, so tagName fails for it...
-                    pass
-        #FIXME: code duplication
-        def handleDrivers(drivers):
-            for driver in drivers[0].childNodes:
-                try:
-                    self.config['drivers'].append(str(driver.tagName))
-                except: #if we allow fancy formatting of xml, there is a text node, so tagName fails for it...
-                    pass
-        
-        def handlePlotmanip(plotmanips):
-            for plotmanip in plotmanips[0].childNodes:
-                try:
-                    self.config['plotmanips'].append(str(plotmanip.tagName))
-                except: #if we allow fancy formatting of xml, there is a text node, so tagName fails for it...
-                    pass
-        
-        def handleWorkdir(workdir):
-            '''
-            default working directory
-            '''
-            wdir=getText(workdir[0].childNodes)
-            self.config['workdir']=wdir.strip()
-            
-        def handleDefaultlist(defaultlist):
-            '''
-            default playlist
-            '''
-            dflist=getText(defaultlist[0].childNodes)
-            self.config['defaultlist']=dflist.strip()
-            
-        handleConfig(self.config_tree)
-        #making items in the dictionary more machine-readable
-        for item in self.config.keys():
-            try:
-                self.config[item]=float(self.config[item])
-            except TypeError: #we are dealing with a list, probably. keep it this way.
-                try:
-                    self.config[item]=eval(self.config[item])
-                except: #not a list, not a tuple, probably a string?
-                    pass
-            except ValueError: #if we can't get it to a number, it must be None or a string
-                if string.lower(self.config[item])=='none':
-                    self.config[item]=None
-                else:
-                    pass
-                                                
-        return self.config
-        
-        
-    def save_config(self, config_filename):
-        print 'Not Implemented.'
-        pass    
-
-
-class ClickedPoint:
-    '''
-    this class defines what a clicked point on the curve plot is
-    '''
-    def __init__(self):
-        
-        self.is_marker=None #boolean ; decides if it is a marker
-        self.is_line_edge=None #boolean ; decides if it is the edge of a line (unused)
-        self.absolute_coords=(None,None) #(float,float) ; the absolute coordinates of the clicked point on the graph
-        self.graph_coords=(None,None) #(float,float) ; the coordinates of the plot that are nearest in X to the clicked point
-        self.index=None #integer ; the index of the clicked point with respect to the vector selected
-        self.dest=None #0 or 1 ; 0=top plot 1=bottom plot
-                
-        
-    def find_graph_coords_old(self, xvector, yvector):
-        '''
-        Given a clicked point on the plot, finds the nearest point in the dataset (in X) that
-        corresponds to the clicked point.
-        OLD & DEPRECATED - to be removed
-        '''
-                   
-        #FIXME: a general algorithm using min() is needed!
-        best_index=0
-        best_dist=10**9 #should be more than enough given the scale
-                
-        for index in scipy.arange(1,len(xvector),1):
-            dist=((self.absolute_coords[0]-xvector[index])**2)+(100*((self.absolute_coords[1]-yvector[index])))**2
-                        #TODO, generalize? y coordinate is multiplied by 100 due to scale differences in the plot
-            if dist<best_dist:
-                best_index=index
-                best_dist=dist
-                        
-        self.index=best_index
-        self.graph_coords=(xvector[best_index],yvector[best_index])
-        return
-            
-    def find_graph_coords(self,xvector,yvector):
-        '''
-        Given a clicked point on the plot, finds the nearest point in the dataset (in X) that
-        corresponds to the clicked point.
-        '''
-        dists=[]
-        for index in scipy.arange(1,len(xvector),1):
-            dists.append(((self.absolute_coords[0]-xvector[index])**2)+((self.absolute_coords[1]-yvector[index])**2))
-                        
-        self.index=dists.index(min(dists))
-        self.graph_coords=(xvector[self.index],yvector[self.index])
-#-----------------------------------------
-#CSV-HELPING FUNCTIONS        
-        
-def transposed2(lists, defval=0):
-    '''
-    transposes a list of lists, i.e. from [[a,b,c],[x,y,z]] to [[a,x],[b,y],[c,z]] without losing
-    elements
-    (by Zoran Isailovski on the Python Cookbook online)
-    '''
-    if not lists: return []
-    return map(lambda *row: [elem or defval for elem in row], *lists)
-        
-def csv_write_dictionary(f, data, sorting='COLUMNS'):
-    '''
-    Writes a CSV file from a dictionary, with keys as first column or row
-    Keys are in "random" order.
-    
-    Keys should be strings
-    Values should be lists or other iterables
-    '''
-    keys=data.keys()
-    values=data.values()
-    t_values=transposed2(values)
-    writer=csv.writer(f)
-
-    if sorting=='COLUMNS':
-        writer.writerow(keys)
-        for item in t_values:
-            writer.writerow(item)
-        
-    if sorting=='ROWS':
-        print 'Not implemented!' #FIXME: implement it.
-
-
-#-----------------------------------------        
-                    
-def debug():
-    '''
-    debug stuff from latest rewrite of hooke_playlist.py
-    should be removed sooner or later (or substituted with new debug code!)
-    '''
-    confo=HookeConfig()
-    print confo.load_config('hooke.conf')
-
-if __name__ == '__main__':
-    debug()
\ No newline at end of file
diff --git a/libhookecurve.py b/libhookecurve.py
deleted file mode 100755 (executable)
index 37cd1b1..0000000
+++ /dev/null
@@ -1,142 +0,0 @@
-#!/usr/bin/env python
-
-
-class HookeCurve(object):
-    
-    def __init__(self,path):
-        self.path=path
-        self.curve=Driver()
-        self.notes=''
-    
-    def identify(self, drivers):
-        '''
-        identifies a curve and returns the corresponding object
-        '''
-        for driver in drivers:
-            tempcurve=driver(self.path)
-            if tempcurve.is_me():
-                #bring on all the driver, with his load of methods etc.
-                #so we can access the whole of it.
-                self.curve=tempcurve
-                del tempcurve
-                return True
-        
-        print 'Not a recognizable curve format.'
-        return False
-        
-        
-class Driver:
-    '''
-    Base class for file format drivers.
-    
-    To be overridden
-    '''
-    def __init__(self):
-        self.experiment=''
-        self.filetype=''
-    
-    def is_me(self):
-        '''
-        This method must read the file and return True if the filetype can be managed by the driver, False if not.
-        '''
-        return False
-    
-    def close_all(self):
-        '''
-        This method must close all the open files of the driver, explicitly.
-        '''
-        return None
-    
-    def default_plots(self):
-        dummy_default=PlotObject()
-        dummy_default.vectors.append([[[0]],[[0]]])
-        return [dummy_default]
-   
-
-class PlotObject:
-    
-    def __init__(self):
-        
-        '''
-        the plot destination
-        0=top
-        1=bottom
-        '''
-        self.destination=0 
-        
-        '''
-        self.vectors is a multidimensional array:
-        self.vectors[0]=plot1
-        self.vectors[1]=plot2
-        self.vectors[2]=plot3
-        etc.
-        
-        2 curves in a x,y plot are:
-        [[[x1],[y1]],[[x2],[y2]]]
-        for example:
-            x1          y1              x2         y2
-        [[[1,2,3,4],[10,20,30,40]],[[3,6,9,12],[30,60,90,120]]]
-        x1 = self.vectors[0][0]
-        y1 = self.vectors[0][1]
-        x2 = self.vectors[1][0]
-        y2 = self.vectors[1][1]
-        '''
-        self.vectors=[]
-
-        '''
-        self.units is simpler. for each plot with N axes (x,y,z...) only N labels
-        can be made, regardless of the number of superimposed plots
-        so units for the double plot above is: [unitx, unity]
-        
-        units are strings
-        '''
-        self.units=['','']
-        
-        '''
-        xaxes and yaxes directions. 0,0 means the common +X=right, +Y=top directions
-        '''
-        self.xaxes=0
-        self.yaxes=0
-        
-        self.title='' #title 
-        
-        '''
-        styles: defines what is the style of the current plots. If undefined or None, it is line plot.
-        If an element of the list is 'scatter', the corresponding dataset
-        is drawn with scattered points and not a continuous line.
-        '''
-        self.styles=[]
-        
-        '''
-        colors: define what is the colour of the current plots
-        '''
-        self.colors=[]
-        
-    def add_set(self,x,y):
-        '''
-        Adds an x,y data set to the vectors.
-        '''
-        self.vectors.append([])
-        self.vectors[-1].append(x)
-        self.vectors[-1].append(y)
-        return
-    
-    def remove_set(self,whichset):
-        '''
-        Removes a set
-        '''
-        waste=self.vectors.pop(whichset)
-        return
-    
-    def normalize_vectors(self):
-        '''
-        Trims the vector lengths as to be equal in a plot.
-        '''
-        
-        for index in range(0,len(self.vectors)):
-            vectors_to_plot=self.vectors[index]
-            lengths=[len(vector) for vector in vectors_to_plot]
-            if min(lengths) != max(lengths):
-                for indexplot in range(0,len(vectors_to_plot)):
-                    self.vectors[index][indexplot] = self.vectors[index][indexplot][0:min(lengths)]
-
diff --git a/libinput.py b/libinput.py
deleted file mode 100644 (file)
index e863b32..0000000
+++ /dev/null
@@ -1,155 +0,0 @@
-#!/usr/bin/env python
-
-'''
-Input check routines.
-
-Copyright (C) 2008 Alberto Gomez-Casado (University of Twente).
-
-This program is released under the GNU General Public License version 2.
-'''
-
-from types import *
-
-
-
-def safeinput (message, valid=[]):
-    '''
-    friendlier frontend for alphainput and numinput
-    valid should be a list of 0...n values
-    '''
-
-    #if possible values are not listed we just ask for any non-null input 
-    if len(valid)==0:
-        return alphainput(message, '',1,[])
-    
-    
-    if len(valid)>0:
-        #if valid values are string we use alphainput, if it is only one we take as default
-        if type(valid[0]) is StringType:
-            if len(valid)==1:
-                return alphainput(message, valid[0], 0,[])
-            else:
-                return alphainput(message,'', 1,valid)
-            
-        #if valid values are numbers we use numinput
-        if type(valid[0]) is IntType:
-            if len(valid)==1:
-                return numinput(message,valid[0],1,[])
-            else:
-                return numinput(message,'',1,valid)
-    
-    
-
-def alphainput (message, default, repeat, valid):
-    '''
-    message: prompt for the user
-    default: return value if user input was not correct (and repeat=0)
-    repeat: keeps asking user till it gets a valid input
-    valid: list of allowed answers, empty list for "anything"
-    ''' 
-    if default and not repeat:
-        print 'Press [enter] for default: ('+str(default)+')'
-    reply=raw_input(message)
-    if len(valid)>0:
-        if reply in valid: 
-            return reply
-        else:
-            if repeat==1:
-                while reply not in valid:
-                    reply=raw_input('You should enter any of these: '+ str(valid) +'\n'+ message)
-                return reply
-            else:
-                return default
-    else:
-        if len(reply)>0:
-            return reply
-        else:
-            if not repeat:
-                return default
-            else:
-                while len(reply)==0:
-                    print 'Try again'
-                    reply=raw_input(message)
-                return reply
-
-                    
-
-def checkalphainput (test, default, valid):
-    #useful when input was taken form command args
-    if len(valid)>0:
-        if test in valid: 
-            return test
-        else:
-            return default
-    else:
-        #TODO: raise exception?
-        if len(test)>0:
-            return test
-        else:
-            return default
-
-
-def numinput(message, default, repeat, limits):
-    '''
-    message: prompt for the user
-    default: return value if user input was not correct (and repeat=0)
-    repeat: keeps asking user till it gets a valid input
-    limits: pair of values, input is checked to be between them, empty list for "any number"
-    ''' 
-    if default and not repeat:
-        print 'Press [enter] for default: '+str(default)
-        
-    reply=raw_input(message)
-    
-    try:
-        intreply=int(reply)
-    except:
-        intreply=None
-              
-    if len(limits)==2:
-        high=int(limits.pop())
-        low=int(limits.pop())
-        if intreply>=low and intreply <= high:
-            return intreply
-        else:
-            if repeat==1:
-                while intreply<low or intreply>high :
-                    reply=raw_input('You should enter values between: '+ str(low)+' and '+str(high) +'\n'+ message)
-                    try:
-                        intreply=int(reply)
-                    except:
-                        intreply=None
-                return intreply
-            else:
-                return default
-    else:
-        if intreply!=None:
-            return intreply
-        else:
-            if not repeat:
-                return default
-            else:
-                while intreply==None:
-                    print 'Try again'
-                    reply=raw_input(message)
-                    try:
-                        intreply=int(reply)
-                    except:
-                        intreply=None
-                return intreply
-
-def checknuminput(test,default,limits):
-    #useful when input was taken from command args
-    if len(limits)==2:
-        high=int(limits.pop())
-        low=int(limits.pop())
-        if test>=low and test <= high:
-            return int(test)
-        else:
-            return default
-    else:
-        if len(test)>0:
-            return int(test)
-        else:
-            return default
-
diff --git a/liboutlet.py b/liboutlet.py
deleted file mode 100644 (file)
index 06e0940..0000000
+++ /dev/null
@@ -1,61 +0,0 @@
-#!/usr/bin/env python
-
-'''
-Basic outlet object
-
-Copyright (C) 2008 Alberto Gomez-Casado (University of Twente).
-
-This program is released under the GNU General Public License version 2.
-'''
-
-
-import re
-
-
-class Outlet(object):
-    
-    def __init__(self):
-        self.buffer=[]
-       #relations is still unused
-        self.relations=[]
-    
-    def push(self, args):
-       #queue new entry
-        self.buffer.append(args)
-
-    def pop(self):
-       #delete last entry
-       return self.buffer.pop();
-
-    def printbuf(self):
-       j=1;
-        for i in self.buffer:
-            print j, i
-            j=j+1
-
-    def delete(self, number):
-       #delete entry matching given index
-       if len(self.buffer)>int(number)-1 and int(number)>0:
-           self.buffer.pop(int(number)-1)              
-
-    def empty(self):
-        self.buffer=[]
-        
-    def read_last(self):
-        return self.buffer[len(self.buffer)-1]
-    
-    def read_first(self):
-        return self.buffer[0]
-
-    def read_type(self,dtype):
-       #returns entries matching a given type (force, distance, point...)        
-       aux=[]
-        index=0
-       if dtype=='all':
-               return self.buffer
-       for i in self.buffer:
-               if re.match(dtype+'*',i):
-                       aux.append(i)
-        return aux
-    
-    
diff --git a/libviewer.py b/libviewer.py
deleted file mode 100644 (file)
index 99ff002..0000000
+++ /dev/null
@@ -1,53 +0,0 @@
-#!/usr/bin/env python
-
-'''
-Basic Viewer and ascii saver example
-
-Copyright (C) 2008 Alberto Gomez-Casado (University of Twente).
-
-This program is released under the GNU General Public License version 2.
-'''
-
-
-import liboutlet as lout
-import libinput as linput
-
-class Viewer(object):
-    source=[]
-    data=[]
-    dtype='all'
-    action=[]  #alias to call the actual viewer function, makes it general
-    
-
-    def setdtype(self, dt):
-        #determines wich type of data will be retrieved from outlet
-        self.dtype=dt  
-
-    def show(self):
-        #TODO should print only data matching 'type'
-        self.source.printbuf()
-
-    def getdata(self):
-        #retrieves data from outlet
-        self.data=self.source.read_type(self.dtype)
-
-
-
-class Ascii(Viewer):
-#example viewer, it just retrieves data and writes it to a text file
-#probably this should be in viewer.py?
-
-       def __init__(self,outref):
-               self.source=outref
-               #tells the viewer which outlet has the data (so far only one in hooke)
-               self.action=self.dump
-               #this allows to call dump (or any other function, depending on the viewer) from the CLI using 'vwaction'
-
-       def dump(self):
-               #retrieves and saves data
-               self.getdata()
-               destination=linput.safeinput('Enter filename:',['results.txt'])
-               destfile=open(destination,'w+')
-               destfile.write('\n'.join(self.data))
-               destfile.close()
-       
diff --git a/macro.py b/macro.py
deleted file mode 100644 (file)
index bdeafab..0000000
--- a/macro.py
+++ /dev/null
@@ -1,233 +0,0 @@
-#!/usr/bin/env python
-
-'''
-COMMAND MACRO PLUGIN FOR HOOKE
-
-Records, saves and executes batches of commands
-(c)Alberto Gomez-Casado 2008
-'''
-
-import libhookecurve as lhc
-import libinput as linput
-import os.path
-import string
-
-class macroCommands:
-
-       currentmacro=[]
-       pause=0
-       auxprompt=[]
-       macrodir=[]
-       
-
-       def _plug_init(self):
-               self.currentmacro=[]
-               self.auxprompt=self.prompt
-               self.macrodir=self.config['workdir']
-               if not os.path.exists(os.path.join(self.macrodir,'macros')):
-                    try:
-                        os.mkdir('macros')
-                    except:
-                        print 'Warning: cannot create macros folder.'
-                        print 'Probably you do not have permissions in your Hooke folder, use macro at your own risk.'
-                self.macrodir=os.path.join(self.macrodir,'macros')
-
-       def collect(self):
-                               
-               print 'Enter STOP / PAUSE to go back to normal mode\nUNDO to remove last command'
-               line=[]
-               while not(line=='STOP' or line=='PAUSE'):
-                       line=raw_input('hooke (macroREC): ')
-                       if line=='PAUSE':
-                               self.pause=1
-                               self.prompt='hooke (macroPAUSE): '
-                               break
-                       if line=='STOP':
-                               self.prompt=self.auxprompt
-                               self.do_recordmacro('stop')
-                               break
-                       if line=='UNDO':
-                               self.currentmacro.pop()
-                               continue
-                       param=line.split()
-
-                       #FIXME check if accessing param[2] when it doesnt exist breaks something
-                       if param[0] =='export':
-                               exportline=param[0]+' __curve__ '
-                               if len(param)==3:
-                                       exportline=exportline+param[2]
-                               self.currentmacro.append(exportline)
-                               self.onecmd(line)
-                               continue
-                       
-                       if param[0] =='txt':
-                               exportline=param[0]
-                               if len(param)==3:
-                                       exportline=exportline+' '+param[2]
-                               exportline=exportline+'__curve__'
-                               self.currentmacro.append(exportline)
-                               self.onecmd(line)
-                               continue
-
-                       self.onecmd(line)
-                       
-                       self.currentmacro.append(line)
-               
-
-       def do_recordmacro(self, args):
-               '''RECORDMACRO
-               Stores input commands to create script files
-               -------
-               Syntax: recordmacro [start / stop]
-               If a macro is currently paused start resumes recording
-               '''
-               
-               
-               if len(args)==0:
-                       args='start'
-
-               if args=='stop':
-                       self.pause=0
-                       self.prompt=self.auxprompt
-                       if len(self.currentmacro) != 0: 
-                               answer=linput.safeinput('Do you want to save this macro? ',['y'])
-                               if answer[0].lower() == 'y':
-                                       self.do_savemacro('')
-                               else:
-                                       print 'Macro discarded'
-                                       self.currentmacro=[]
-                       else:
-                               print 'Macro was empty' 
-
-               if args=='start':       
-
-                       if self.pause==1:
-                               self.pause=0    
-                               self.collect()  
-                       else:
-                               if len(self.currentmacro) != 0: 
-                                       answer=linput.safeinput('Another macro is already beign recorded\nDo you want to save it?',['y'])
-                                       if answer[0].lower() == 'y':
-                                               self.do_savemacro('')
-                                       else:
-                                               print 'Old macro discarded, you can start recording the new one'
-                       
-                               self.currentmacro=[]
-                               self.collect()
-               
-
-       def do_savemacro(self, macroname):
-
-               '''SAVEMACRO
-               Saves previously recorded macro into a script file for future use
-               -------
-               Syntax: savemacro [macroname]
-               If no macroname is supplied one will be interactively asked 
-               '''
-
-               saved_ok=0
-               if self.currentmacro==None:
-                       print 'No macro is being recorded!'
-                       return 0
-               if len(macroname)==0: 
-                       macroname=linput.safeinput('Enter new macro name: ')
-                       if len(macroname) == 0:
-                               print 'Invalid name'
-                               
-               macroname=os.path.join(self.macrodir,macroname+'.hkm')
-               if os.path.exists(macroname):
-                       overwrite=linput.safeinput('That name is in use, overwrite?',['n'])
-                       if overwrite[0].lower()!='y':
-                               print 'Cancelled save'
-                               return 0
-               txtfile=open(macroname,'w+')
-               self.currentmacro='\n'.join(self.currentmacro)
-               txtfile.write(self.currentmacro)
-               txtfile.close()
-               print 'Saved on '+macroname
-               self.currentmacro=[]
-
-       def do_execmacro (self, args):
-               
-               '''EXECMACRO
-               Loads a macro and executes it over current curve / playlist
-               -----
-               Syntax: execmacro macroname [playlist] [v]
-
-               macroname.hkm should be present at [hooke]/macros directory
-               By default the macro will be executed over current curve
-               passing 'playlist' word as second argument executes macroname 
-               over all curves
-               By default curve(s) will be processed silently, passing 'v' 
-               as second/third argument will print each command that is 
-               executed
-
-               Note that macros applied to playlists should end by export
-               commands so the processed curves are not lost
-               '''
-               verbose=0
-               cycle=0
-               curve=None              
-
-               if len(self.currentmacro) != 0:
-                       print 'Warning!: you are calling a macro while recording other'
-               if len(args) == 0:
-                       print 'You must provide a macro name'
-                       return 0
-               args=args.split()
-
-               #print 'args ' + ' '.join(args)
-               
-               if len(args)>1:
-                       if args[1] == 'playlist':
-                               cycle=1
-                               print 'Remember! macros applied over playlists should include export orders'
-                               if len(args)>2 and args[2] == 'v':
-                                       verbose=1
-                       else:
-                               if args[1] == 'v':
-                                       verbose=1       
-               #print cycle
-               #print verbose  
-
-               macropath=os.path.join(self.macrodir,args[0]+'.hkm')
-               if not os.path.exists(macropath):
-                       print 'Could not find a macro named '+macropath
-                       return 0
-               txtfile=open(macropath)
-               if cycle ==1: 
-                       #print self.current_list
-                       for item in self.current_list:
-                               self.current=item
-                               self.do_plot(0)        
-
-                               for command in txtfile:
-
-                                       if verbose==1:
-                                               print 'Executing command '+command
-                                       testcmd=command.split()
-                                       w=0
-                                       for word in testcmd:
-                                               if word=='__curve__':
-                                                       testcmd[w]=os.path.splitext(os.path.basename(item.path))[0]
-                                               w=w+1
-                                       self.onecmd(' '.join(testcmd))
-                               self.current.curve.close_all()
-                               txtfile.seek(0)
-               else:
-                       for command in txtfile:
-                                       testcmd=command.split()
-                                       w=0
-                                       for word in testcmd:
-                                               if word=='__curve__':
-                                                       w=w+1
-                                                       testcmd[w]=os.path.splitext(os.path.basename(self.current.path))[0]+'-'+string.lstrip(os.path.splitext(os.path.basename(self.current.path))[1],'.')
-                                       if verbose==1:
-                                               print 'Executing command '+' '.join(testcmd)
-                                       self.onecmd(' '.join(testcmd))
-               
-       
-
-
-
-
diff --git a/massanalysis.py b/massanalysis.py
deleted file mode 100644 (file)
index e3d3830..0000000
+++ /dev/null
@@ -1,143 +0,0 @@
-#!/usr/bin/env python
-
-'''
-massanalysis.py
-
-Global analysis of force curves with various parameters
-
-Requires:
-libpeakspot.py
-flatfilts.py
-'''
-
-
-import libpeakspot as lps
-import libhookecurve as lhc
-import libhooke as lh
-import numpy as np
-
-import csv
-
-class massanalysisCommands:
-
-    def _plug_init(self):
-        self.mass_variables={}        
-        self.interesting_variables=['curve','firstpeak_distance','lastpeak_distance','Npeaks','median_distance','mean_distance']
-        self._clean_data()
-        
-    def _clean_data(self):
-        for variable in self.interesting_variables:
-            self.mass_variables[variable]=[]
-
-    def peak_position_from_contact(self, item, locations):
-        '''
-        calculates X distance of a peak from the contact point
-        '''
-        item.identify(self.drivers)        
-        
-        real_positions=[]
-        cut_index=self.find_contact_point()
-        
-        #we assume the first is the plot with the force curve
-        plot=item.curve.default_plots()[0]
-        xret=plot.vectors[1][0]
-        
-        start_x=xret[cut_index]
-        
-        real_positions=[abs((xret[index])-(start_x)) for index in locations] 
-        #close all open files
-        item.curve.close_all()
-        #needed to avoid *big* memory leaks!
-        del item.curve
-        del item
-        return real_positions
-
-    def do_maplist(self,args):
-        '''
-        MAPLIST
-        (flatfilts.py)
-        ----
-        pass
-        '''
-        self._clean_data() #if we recall it, clean previous data!
-        min_deviation=self.convfilt_config['mindeviation']
-          
-        
-        c=0
-        for item in self.current_list:
-            try:
-                peak_location,peak_size=self.exec_has_peaks(item, min_deviation)
-                real_positions=self.peak_position_from_contact(item, peak_location)
-                
-                self.mass_variables['Npeaks'].append(len(peak_location))
-                
-                if len(peak_location) > 1:
-                    self.mass_variables['firstpeak_distance'].append(min(real_positions))
-                    self.mass_variables['lastpeak_distance'].append(max(real_positions))
-                    
-                    distancepeaks=[]
-                    for index in range(len(real_positions)-1):
-                        distancepeaks.append(real_positions[index+1]-real_positions[index])
-                else:
-                    self.mass_variables['firstpeak_distance'].append(0)
-                    self.mass_variables['lastpeak_distance'].append(0)    
-                    
-                if len(peak_location) > 2:
-                    self.mass_variables['median_distance'].append(np.median(distancepeaks))
-                    self.mass_variables['mean_distance'].append(np.mean(distancepeaks))    
-                else:
-                    self.mass_variables['median_distance'].append(0)
-                    self.mass_variables['mean_distance'].append(0)   
-                
-                print 'curve',c
-            except SyntaxError:
-                print 'curve',c,'not mapped'
-                pass
-            
-            c+=1
-
-    def do_plotmap(self,args):
-        '''
-        '''
-        args=args.split()
-        if len(args)>1:
-            x=self.mass_variables[args[0]]
-            y=self.mass_variables[args[1]]
-        else:
-            print 'Give me two arguments between those:'
-            print self.interesting_variables
-            return
-            
-        scattermap=lhc.PlotObject()
-        scattermap.vectors=[[]]
-        scattermap.vectors[0].append(x)
-        scattermap.vectors[0].append(y)
-        
-        scattermap.units=[args[0],args[1]]
-        scattermap.styles=['scatter']
-        scattermap.destination=1
-        
-        self._send_plot([scattermap])
-        
-    def do_savemaps(self,args):
-        '''
-        args=filename
-        '''
-        
-        '''
-        def csv_write_cols(data, f):
-            
-            #from Bruno Desthuillers on comp.lang.python
-            
-            writer = csv.writer(f)
-            keys = data.keys()
-            writer.writerow(dict(zip(keys,keys)))
-            for row in zip(*data.values()):
-                writer.writerow(dict(zip(keys, row))) 
-        '''
-        
-        f=open(args,'wb')
-        lh.csv_write_dictionary(f,self.mass_variables)
-        f.close()
-        
-        
\ No newline at end of file
diff --git a/mfp1dexport.py b/mfp1dexport.py
deleted file mode 100644 (file)
index 57e75d9..0000000
+++ /dev/null
@@ -1,88 +0,0 @@
-#!/usr/bin/env python
-
-'''
-mfp1dexport.py
-
-Driver for text-exported MFP 1D files
-
-Massimo Sandal (c) 2009
-'''
-
-import libhookecurve as lhc
-import libhooke as lh
-
-class mfp1dexportDriver(lhc.Driver):
-    
-    def __init__(self, filename):
-        
-        self.filename=filename
-        self.filedata=open(filename,'rU')
-        self.lines=list(self.filedata.readlines())
-        self.filedata.close()
-        
-        self.filetype='mfp1dexport'
-        self.experiment='smfs'
-        
-    def close_all(self):
-        self.filedata.close()
-        
-    def is_me(self):
-        try:
-            self.raw_header=self.lines[0:38]
-        except:
-            #Not enough lines for a header; not a good file
-            return False
-        
-        #FIXME: We want a more reasonable header recognition
-        if self.raw_header[0][0:4]=='Wave':
-            return True
-        else:
-            return False
-        
-    def _read_columns(self):
-        
-        self.raw_columns=self.lines[39:]
-        
-        kline=None
-        for line in self.lines:
-            if line[:7]=='SpringC':
-                kline=line
-                break
-        
-        kline=kline.split(':')
-        
-        #self.k=float(self.raw_header[23][8:])
-        self.k=float(kline[1])
-        
-        
-        xext=[]
-        xret=[]
-        yext=[]
-        yret=[]
-        for line in self.raw_columns:
-            spline=line.split()
-            xext.append(float(spline[0]))
-            yext.append(float(spline[1]))
-            xret.append(float(spline[2]))
-            yret.append(float(spline[3]))
-            
-        return [[xext,yext],[xret,yret]]
-        
-    def deflection(self):
-        self.data=self._read_columns()
-        return self.data[0][1],self.data[1][1]
-        
-        
-    def default_plots(self):   
-        main_plot=lhc.PlotObject()
-        defl_ext,defl_ret=self.deflection()
-        yextforce=[i*self.k for i in defl_ext]
-        yretforce=[i*self.k for i in defl_ret]
-        main_plot.add_set(self.data[0][0],yextforce)
-        main_plot.add_set(self.data[1][0],yretforce)
-        main_plot.normalize_vectors()
-        main_plot.units=['Z','force']  #FIXME: if there's an header saying something about the time count, should be used
-        main_plot.destination=0
-        main_plot.title=self.filename
-        #main_plot.colors=['red','blue']
-        return [main_plot]
diff --git a/mfp_igor_scripts/ExportMFP1D.ipf b/mfp_igor_scripts/ExportMFP1D.ipf
deleted file mode 100644 (file)
index d1234c3..0000000
+++ /dev/null
@@ -1,185 +0,0 @@
-#pragma rtGlobals=1            // Use modern global access method.\r
-#pragma IgorVersion = 4.0\r
-#pragma version = 0.4\r
-\r
-//\r
-// ExportMFP1D.ipf - A procedure to export force curves from MFP1D to 'hooke'\r
-//\r
-// Copyright (c) 2009 Rolf Schmidt, Montreal\r
-// rschmidt@alcor.concordia.ca\r
-// \r
-// This procedure is released under the GNU General Public License version 2\r
-//\r
-\r
-// History\r
-// 2009 07 24: v0.4\r
-// the wave note is now correctly and fully exported in Igor 4\r
-// 2009 06 29: v0.3\r
-// split functionality into ExportMFP1DFolder and ExportMFP1DWaves\r
-// ExportMFP1DFolder: export individual Igor binary waves file from a folder\r
-// ExportMFP1DWaves: export all currently open waves to a folder\r
-// 2009 06 26: v0.2.1\r
-// added the IgorVersion pragma\r
-// 2009 06 19: v0.2\r
-// changed the filename finding algorithm to work with Igor 4 and up\r
-// Igor 5 users can use the code marked 'the following only works in Igor 5 and up' instead\r
-// the procedure now catches 'Cancel' on NewPath\r
-// added version information\r
-// 2009 05 29: v0.1\r
-// changed the procedure so that it runs in Igor as well as in MFP (ie Igor with MFP plug-in)\r
-\r
-// How to use ExportMFP1D()\r
-// - save all current waves of interest (ExportMFP1D() kills all open waves before exporting files)\r
-// - execute ExportMFP1D() from the command line\r
-// - browse to a folder containing force curves (a 'force curve' consists of two files: one 'deflection' and one 'LVDT' file\r
-// - ExportMFP1D() will now iterate through all the waves in the folder, extract the header information and create four columns:\r
-//   1: approach (x) 2: approach (y) 3: retraction (x) 4; retraction (y)\r
-// - the resulting files are saved in the same folder and the same base name as the original files (ie without 'deflection' and 'LVDT')\r
-// CAUTION:  existing files will be overwritten!\r
-// - these files can then be analyzed with 'hooke'\r
-\r
-Function ExportMFP1DFolder()\r
-\r
-       String sList\r
-       Variable iCount\r
-\r
-       // set the path (used for opening the waves and saving the output files later)\r
-       NewPath /O /Q /M="Choose the folder that contains the waves" PathExport1D\r
-\r
-       KillWaves /A /Z\r
-       \r
-       if(V_flag>=0)\r
-               // get a list of all Igor binary waves in the folder\r
-               sList=IndexedFile(PathExport1D,-1,".ibw")\r
-               // load all waves\r
-               for(iCount=0; iCount<ItemsInList(sList); iCount+=1)\r
-                       LoadWave /P=PathExport1D /Q StringFromList(iCount, sList)\r
-               endfor\r
-               ExportMFP1DWaves()\r
-       endif\r
-       // kill the export path\r
-       KillPath /Z PathExport1D\r
-End\r
-\r
-Function ExportMFP1DWaves()\r
-\r
-       String sFileName1\r
-       String sFileName2\r
-       String sLine\r
-       String sList\r
-       String sNote\r
-       String sWaveCombined\r
-       String sWaveDeflection\r
-       String sWaveLVDT\r
-       Variable iCount\r
-       Variable iLine\r
-       Variable iPoints\r
-       Variable iRefNum\r
-       Wave wApproachX\r
-       Wave wApproachY\r
-       Wave wRetractionX\r
-       Wave wRetractionY\r
-\r
-       // set the path (used for saving the output files later)\r
-       NewPath /O /Q /M="Choose the folder to save the waves" PathExport1D\r
-       \r
-       // get a list of all LVDT waves (could be deflection as well, they always come in a pair)\r
-       sList=WaveList("*LVDT*", ";", "")\r
-       \r
-       // iterate through all the LVDT waves\r
-       for(iCount=0; iCount<ItemsInList(sList); iCount+=1)\r
-               // create the wave names as string\r
-// the following only works in Igor 5 and up\r
-//                     sWaveLVDT=ReplaceString(".ibw",StringFromList(iCount, sList), "")\r
-//                     sWaveDeflection=ReplaceString("LVDT",sWaveLVDT, "deflection")\r
-//                     sWaveCombined=ReplaceString("LVDT",sWaveLVDT, "_")\r
-// END: the following only works in Igor 5 and up\r
-\r
-// the following works in Igor 4 and up\r
-               // treat the filename as a key-value list with '.' as a separator\r
-               // use the first entry (ie 0) as the filename without extension\r
-               sWaveLVDT=StringFromList(0, StringFromList(iCount, sList), ".")\r
-               \r
-               // treat the filename as a key-value list with 'LVDT' as a separator\r
-               // use the first entry (ie 0) as the first part of the filename\r
-               sFileName1=StringFromList(0, sWaveLVDT, "LVDT")\r
-               // getting the second part of the filename is a bit trickier\r
-               // first, we 'remove' the first part of the filename by treating it as a key\r
-               // using 'LVDT' as a separator \r
-               sFileName2=StringByKey(sFileName1, sWaveLVDT, "LVDT")\r
-               // unfortunately, StringByKey only removes the first character of the separator\r
-               // to get the second part of the filename, we use VD as the key and 'T' as the separator\r
-               sFileName2=StringByKey("VD", sFileName2, "T")\r
-               // then we create the wave names as follows:\r
-               sWaveDeflection=sFileName1+"deflection"+sFileName2\r
-               \r
-               sWaveCombined=sFileName1+"_"+sFileName2\r
-               \r
-// END: the following works in Igor 4 and up\r
-\r
-               // create the waves we need\r
-               Wave wLVDT=$sWaveLVDT\r
-               Wave wDeflection=$sWaveDeflection\r
-       \r
-               // open the output text file, add extension\r
-               Open /P=PathExport1D iRefNum as sWaveCombined+".txt"\r
-\r
-               // create the header\r
-               fprintf iRefNum, "Wave:"+sWaveCombined+"\r"\r
-               fprintf iRefNum, "WaveLVDT:"+sWaveLVDT+"\r"\r
-               fprintf iRefNum, "WaveDeflection:"+sWaveDeflection+"\r"\r
-\r
-               // the number of points (use WaveStats to get them) are identical for LVDT and Deflection\r
-               WaveStats /q wLVDT\r
-               iPoints=V_npnts/2\r
-               fprintf iRefNum, "Rows:"+num2str(iPoints)+"\r"\r
-\r
-               // add the note to the file\r
-               // the notes are identical for LVDT and Deflection\r
-// the following only works in Igor 5 and up\r
-//             fprintf iRefNum, note(wDeflection)\r
-// END: the following only works in Igor 5 and up\r
-               sNote=note(wLVDT)\r
-               // in order to get the correct number of lines in the note, we have to specify the EOF as \r\n\r
-               for(iLine=0; iLine<ItemsInList(sNote, "\r\n");iLine+=1)\r
-                       // print every line to the output file\r
-                       fprintf iRefNum, StringFromList(iLine, sNote, "\r\n")\r
-                       // add a CR/LF for every but the last line\r
-                       if(iLine<ItemsInList(sNote, "\r\n")-1)\r
-                               fprintf iRefNum, "\r\n"\r
-                       endif\r
-               endfor\r
-\r
-               // separate the approach from the retraction\r
-               // by simply taking the first half of the points to be the approach\r
-               // and the second half to be the retraction\r
-               // this probably has to be changed for dual pulls\r
-               Duplicate /O /R=[0, iPoints] wLVDT, wApproachX\r
-               Duplicate /O /R=[0, iPoints] wDeflection, wApproachY\r
-               Duplicate /O /R=[iPoints+1] wLVDT, wRetractionX\r
-               Duplicate /O /R=[iPoints+1] wDeflection, wRetractionY\r
-\r
-               // create four columns line by line\r
-               // 1: approach x 2: approach y 3: retraction x 4: retraction y\r
-               for(iLine=0; iLine<iPoints; iLine+=1)\r
-                       sLine=num2str(wApproachX[iLine])+"\t"+num2str(wApproachY[iLine])\r
-                       sLine=sLine+"\t"+num2str(wRetractionX[iLine])+"\t"+num2str(wRetractionY[iLine])\r
-                       // add the line to the file\r
-                       fprintf iRefNum, "\r"+sLine\r
-               endfor\r
-\r
-               // save the text file to disk\r
-               print "Exporting "+sWaveCombined\r
-               Close iRefNum\r
-       endfor\r
-\r
-       // print message\r
-       print "Export completed ("+num2str(ItemsInList(sList))+" files)"\r
-\r
-       // kill the temporary waves used\r
-       // given the names, it is unlikely that this function will interfere with data\r
-       KillWaves /Z wApproachX\r
-       KillWaves /Z wApproachY\r
-       KillWaves /Z wRetractionX\r
-       KillWaves /Z wRetractionY\r
-End\r
diff --git a/mfp_igor_scripts/ExportMFP1DMenu.ipf b/mfp_igor_scripts/ExportMFP1DMenu.ipf
deleted file mode 100644 (file)
index a8cda3b..0000000
+++ /dev/null
@@ -1,4 +0,0 @@
-Menu "hooke"\r
-       "Export folder", ExportMFP1DFolder()\r
-       "Export waves", ExportMFP1DWaves()\r
-End
\ No newline at end of file
diff --git a/panels/__init__.py b/panels/__init__.py
new file mode 100644 (file)
index 0000000..803f29c
--- /dev/null
@@ -0,0 +1 @@
+#!/usr/bin/env python\r
diff --git a/panels/commands.py b/panels/commands.py
new file mode 100644 (file)
index 0000000..e634a94
--- /dev/null
@@ -0,0 +1,90 @@
+#!/usr/bin/env python\r
+\r
+'''\r
+commands.py\r
+\r
+Commands and settings panel for Hooke.\r
+\r
+Copyright 2009 by Dr. Rolf Schmidt (Concordia University, Canada)\r
+\r
+This program is released under the GNU General Public License version 2.\r
+'''\r
+\r
+from configobj import ConfigObj\r
+import os.path\r
+import wx\r
+\r
+import lib.libhooke as lh\r
+\r
+class Commands(wx.Panel):\r
+\r
+    def __init__(self, parent):\r
+        # Use the WANTS_CHARS style so the panel doesn't eat the Return key.\r
+        wx.Panel.__init__(self, parent, -1, style=wx.WANTS_CHARS|wx.NO_BORDER, size=(160, 200))\r
+\r
+        self.CommandsTree = wx.TreeCtrl(self, -1, wx.Point(0, 0), wx.Size(160, 250), wx.TR_DEFAULT_STYLE|wx.NO_BORDER|wx.TR_HIDE_ROOT)\r
+        imglist = wx.ImageList(16, 16, True, 2)\r
+        imglist.Add(wx.ArtProvider.GetBitmap(wx.ART_FOLDER, wx.ART_OTHER, wx.Size(16, 16)))\r
+        imglist.Add(wx.ArtProvider.GetBitmap(wx.ART_EXECUTABLE_FILE, wx.ART_OTHER, wx.Size(16, 16)))\r
+        self.CommandsTree.AssignImageList(imglist)\r
+        self.CommandsTree.AddRoot('Commands and Settings', 0)\r
+\r
+        self.ExecuteButton = wx.Button(self, -1, 'Execute')\r
+\r
+        sizer = wx.BoxSizer(wx.VERTICAL)\r
+        sizer.Add(self.CommandsTree, 1, wx.EXPAND)\r
+        sizer.Add(self.ExecuteButton, 0, wx.EXPAND)\r
+\r
+        self.SetSizer(sizer)\r
+        sizer.Fit(self)\r
+\r
+    def Initialize(self, plugins):\r
+        selected = None\r
+        tree_root = self.CommandsTree.GetRootItem()\r
+        path = lh.get_file_path('hooke.ini', ['config'])\r
+        config = ConfigObj()\r
+        if os.path.isfile(path):\r
+            config.filename = path\r
+            config.reload()\r
+            #get the selected command/plugin from the config file\r
+            command_str = config['command']['command']\r
+            module_str = config['command']['plugin']\r
+\r
+            for plugin in plugins:\r
+                filename = ''.join([plugin, '.ini'])\r
+                path = lh.get_file_path(filename, ['plugins'])\r
+                config = ConfigObj()\r
+                if os.path.isfile(path):\r
+                    config.filename = path\r
+                    config.reload()\r
+                    #append the ini file to the plugin\r
+                    plugin_root = self.CommandsTree.AppendItem(tree_root, plugin, 0, data=wx.TreeItemData(config))\r
+                else:\r
+                    plugin_root = self.CommandsTree.AppendItem(tree_root, plugin, 0)\r
+                #select the plugin according to the config file\r
+                if plugin == module_str:\r
+                    selected = plugin_root\r
+\r
+                #add all commands to the tree\r
+                for command in plugins[plugin]:\r
+                    command_label = command.replace('do_', '')\r
+                    #do not add the ini file to the command (we'll access the ini file of the plugin (ie parent) instead, see above)\r
+                    item = self.CommandsTree.AppendItem(plugin_root, command_label, 1)\r
+                    #select the command according to the config file\r
+                    if plugin == module_str and command_label == command_str:\r
+                        selected = item\r
+                        #e = wx.MouseEvent()\r
+                        #e.SetEventType(wx.EVT_LEFT_DOWN.typeId)\r
+                        #e.SetEventObject(self.CommandsTree)\r
+\r
+                        ##e.SetSelection(page)\r
+                        #self.Parent.OnTreeCtrlCommandsLeftDown(e)\r
+                        #wx.PostEvent(self, e)\r
+\r
+                        #self.CommandsTree.SelectItem(item, True)\r
+\r
+                self.CommandsTree.Expand(plugin_root)\r
+            #make sure the selected command/plugin is visible in the tree\r
+            if selected is not None:\r
+                self.CommandsTree.SelectItem(selected, True)\r
+                self.CommandsTree.EnsureVisible(selected)\r
diff --git a/panels/perspectives.py b/panels/perspectives.py
new file mode 100644 (file)
index 0000000..75eab72
--- /dev/null
@@ -0,0 +1,73 @@
+#!/usr/bin/env python\r
+\r
+'''\r
+perspectives.py\r
+\r
+Perspectives panel for deletion.\r
+\r
+Copyright 2010 by Dr. Rolf Schmidt (Concordia University, Canada)\r
+\r
+This program is released under the GNU General Public License version 2.\r
+'''\r
+\r
+from os import remove\r
+import wx\r
+\r
+import lib.libhooke as lh\r
+\r
+class Perspectives(wx.Dialog):\r
+\r
+    def __init__(self, parent, ID, title):\r
+        wx.Dialog.__init__(self, parent, ID, title, style=wx.DEFAULT_DIALOG_STYLE | wx.RESIZE_BORDER)\r
+\r
+        # contents\r
+        sizer_vertical = wx.BoxSizer(wx.VERTICAL)\r
+\r
+        message_str = "\nPlease check the perspectives\n\nyou want to delete and click 'Delete'.\n"\r
+        text = wx.StaticText(self, -1, message_str, wx.DefaultPosition, style=wx.ALIGN_CENTRE)\r
+        sizer_vertical.Add(text, 0, wx.GROW|wx.ALIGN_CENTER_VERTICAL|wx.ALL, 5)\r
+\r
+        perspectives_list = [item[0] for item in self.Parent._perspectives.items() if item[0] != 'Default']\r
+        perspectives_list.sort()\r
+        listbox = wx.CheckListBox(self, -1, wx.DefaultPosition, wx.Size(175, 200), perspectives_list)\r
+        self.Bind(wx.EVT_CHECKLISTBOX, self.EvtCheckListBox, listbox)\r
+        listbox.SetSelection(0)\r
+        sizer_vertical.Add(listbox, 1, wx.GROW|wx.ALIGN_CENTER_VERTICAL|wx.ALL, 5)\r
+        self.listbox = listbox\r
+\r
+        horizontal_line = wx.StaticLine(self, -1, size=(20,-1), style=wx.LI_HORIZONTAL)\r
+        sizer_vertical.Add(horizontal_line, 0, wx.GROW, 5)\r
+\r
+        sizer_buttons = wx.BoxSizer(wx.HORIZONTAL)\r
+\r
+        button_delete = wx.Button(self, wx.ID_DELETE)\r
+        self.Bind(wx.EVT_BUTTON, self.OnButtonDelete, button_delete)\r
+        button_delete.SetDefault()\r
+        sizer_buttons.Add(button_delete, 0, wx.GROW|wx.ALIGN_CENTER_VERTICAL|wx.ALL, 5)\r
+\r
+        button_close = wx.Button(self, wx.ID_CLOSE)\r
+        self.Bind(wx.EVT_BUTTON, self.OnButtonClose, button_close)\r
+        sizer_buttons.Add(button_close, 0, wx.GROW|wx.ALIGN_CENTER_VERTICAL|wx.ALL, 5)\r
+\r
+        sizer_vertical.Add(sizer_buttons, 0, wx.ALIGN_CENTER_VERTICAL|wx.ALIGN_CENTER_HORIZONTAL|wx.ALL, 5)\r
+\r
+        self.SetSizer(sizer_vertical)\r
+        sizer_vertical.Fit(self)\r
+\r
+    def EvtCheckListBox(self, event):\r
+        index = event.GetSelection()\r
+        self.listbox.SetSelection(index)    # so that (un)checking also selects (moves the highlight)\r
+\r
+    def OnButtonClose(self, event):\r
+        self.EndModal(wx.ID_CLOSE)\r
+\r
+    def OnButtonDelete(self, event):\r
+        items = self.listbox.GetItems()\r
+        selected_perspective = self.Parent.config['perspectives']['active']\r
+        for index in reversed(self.listbox.GetChecked()):\r
+            self.listbox.Delete(index)\r
+            if items[index] == selected_perspective:\r
+                self.Parent.config['perspectives']['active'] = 'Default'\r
+\r
+            filename = lh.get_file_path(items[index] + '.txt', ['perspectives'])\r
+            remove(filename)\r
diff --git a/panels/playlist.py b/panels/playlist.py
new file mode 100644 (file)
index 0000000..3868a4f
--- /dev/null
@@ -0,0 +1,85 @@
+#!/usr/bin/env python\r
+\r
+'''\r
+playlist.py\r
+\r
+Playlist panel for Hooke.\r
+\r
+Copyright 2009 by Dr. Rolf Schmidt (Concordia University, Canada)\r
+\r
+This program is released under the GNU General Public License version 2.\r
+'''\r
+\r
+import wx\r
+\r
+class Playlists(wx.Panel):\r
+\r
+    def __init__(self, parent):\r
+        # Use the WANTS_CHARS style so the panel doesn't eat the Return key.\r
+        wx.Panel.__init__(self, parent, -1, style=wx.WANTS_CHARS|wx.NO_BORDER, size=(160, 200))\r
+\r
+        self.PlaylistsTree = wx.TreeCtrl(self, -1, wx.Point(0, 0), wx.Size(160, 250), wx.TR_DEFAULT_STYLE | wx.NO_BORDER | wx.TR_HIDE_ROOT)\r
+        imglist = wx.ImageList(16, 16, True, 2)\r
+        imglist.Add(wx.ArtProvider.GetBitmap(wx.ART_FOLDER, wx.ART_OTHER, wx.Size(16, 16)))\r
+        imglist.Add(wx.ArtProvider.GetBitmap(wx.ART_NORMAL_FILE, wx.ART_OTHER, wx.Size(16, 16)))\r
+        self.PlaylistsTree.AssignImageList(imglist)\r
+        self.PlaylistsTree.AddRoot('Playlists', 0)\r
+        self.PlaylistsTree.Bind(wx.EVT_RIGHT_DOWN , self.OnContextMenu)\r
+\r
+        self.Playlists = {}\r
+\r
+        sizer = wx.BoxSizer(wx.VERTICAL)\r
+        sizer.Add(self.PlaylistsTree, 1, wx.EXPAND)\r
+        self.SetSizer(sizer)\r
+        sizer.Fit(self)\r
+\r
+    def OnContextMenu(self, event):\r
+        hit_item, hit_flags = self.PlaylistsTree.HitTest(event.GetPosition())\r
+        if (hit_flags & wx.TREE_HITTEST_ONITEM) != 0:\r
+            self.PlaylistsTree.SelectItem(hit_item)\r
+            # only do this part the first time so the events are only bound once\r
+            # Yet another alternate way to do IDs. Some prefer them up top to\r
+            # avoid clutter, some prefer them close to the object of interest\r
+            # for clarity.\r
+            if not hasattr(self, 'ID_popupAdd'):\r
+                #self.ID_popupAdd = wx.NewId()\r
+                self.ID_popupDelete = wx.NewId()\r
+                #self.Bind(wx.EVT_MENU, self.OnPopupAdd, id=self.ID_popupAdd)\r
+                self.Bind(wx.EVT_MENU, self.OnPopupDelete, id=self.ID_popupDelete)\r
+            # make a menu\r
+            menu = wx.Menu()\r
+            #items = [['Add', self.ID_popupAdd] , ['Delete', self.ID_popupDelete]]\r
+            items = [['Delete', self.ID_popupDelete]]\r
+            for item in items:\r
+                menu.Append(item[1], item[0])\r
+            # Popup the menu.  If an item is selected then its handler\r
+            # will be called before PopupMenu returns.\r
+            self.PopupMenu(menu)\r
+            menu.Destroy()\r
+\r
+    def OnPopupAdd(self, event):\r
+        pass\r
+\r
+    def OnPopupDelete(self, event):\r
+        item = self.PlaylistsTree.GetSelection()\r
+        playlist = self.Parent.GetActivePlaylist()\r
+        if self.PlaylistsTree.ItemHasChildren(item):\r
+            playlist_name = self.PlaylistsTree.GetItemText(item)\r
+            notebook = self.Parent.plotNotebook\r
+            index = self.Parent._GetPlaylistTab(playlist_name)\r
+            notebook.SetSelection(index)\r
+            notebook.DeletePage(notebook.GetSelection())\r
+            self.Parent.DeleteFromPlaylists(playlist_name)\r
+        else:\r
+            if playlist is not None:\r
+                if playlist.count == 1:\r
+                    notebook = self.Parent.plotNotebook\r
+                    index = self.Parent._GetPlaylistTab(playlist.name)\r
+                    notebook.SetSelection(index)\r
+                    notebook.DeletePage(notebook.GetSelection())\r
+                    self.Parent.DeleteFromPlaylists(playlist.name)\r
+                else:\r
+                    file_name = self.PlaylistsTree.GetItemText(item)\r
+                    playlist.delete_file(file_name)\r
+                    self.PlaylistsTree.Delete(item)\r
+                    self.Parent.UpdatePlaylistsTreeSelection()\r
diff --git a/panels/plot.py b/panels/plot.py
new file mode 100644 (file)
index 0000000..4ea3243
--- /dev/null
@@ -0,0 +1,153 @@
+#!/usr/bin/env python\r
+\r
+'''\r
+plot.py\r
+\r
+Plot panel for Hooke.\r
+\r
+Copyright 2009 by Dr. Rolf Schmidt (Concordia University, Canada)\r
+\r
+This program is released under the GNU General Public License version 2.\r
+'''\r
+\r
+from matplotlib.backends.backend_wxagg import FigureCanvasWxAgg as FigureCanvas\r
+\r
+from matplotlib.backends.backend_wx import NavigationToolbar2Wx\r
+\r
+from matplotlib.figure import Figure\r
+\r
+import wx\r
+\r
+#there are many comments in here from the demo app\r
+#they should come in handy to expand the functionality in the future\r
+\r
+class HookeCustomToolbar(NavigationToolbar2Wx):\r
+\r
+    def __init__(self, plotCanvas):\r
+        NavigationToolbar2Wx.__init__(self, plotCanvas)\r
+        # add new toolbar buttons\r
+        #glyph_file = 'resources' + os.sep + 'pipette.png'\r
+        #glyph = wx.Image(glyph_file, wx.BITMAP_TYPE_ANY).ConvertToBitmap()\r
+\r
+        #self.AddCheckTool(ON_CUSTOM_PICK, glyph, shortHelp='Select a data point', longHelp='Select a data point')\r
+        #wx.EVT_TOOL(self, ON_CUSTOM_PICK, self.OnSelectPoint)\r
+\r
+        # remove the unwanted button\r
+#        POSITION_OF_CONFIGURE_SUBPLOTS_BTN = 6\r
+#        self.DeleteToolByPos(POSITION_OF_CONFIGURE_SUBPLOTS_BTN)\r
+\r
+    #def OnSelectPoint(self, event):\r
+        #self.Parent.Parent.Parent.pick_active = True\r
+\r
+\r
+#class LineBuilder:\r
+    #def __init__(self, line):\r
+        #self.line = line\r
+        #self.xs = list(line.get_xdata())\r
+        #self.ys = list(line.get_ydata())\r
+        #self.cid = line.figure.canvas.mpl_connect('button_press_event', self)\r
+\r
+    #def __call__(self, event):\r
+        #print 'click', event\r
+        #if event.inaxes != self.line.axes:\r
+            #return\r
+        #self.xs.append(event.xdata)\r
+        #self.ys.append(event.ydata)\r
+        #self.line.set_data(self.xs, self.ys)\r
+        #self.line.figure.canvas.draw()\r
+\r
+\r
+class PlotPanel(wx.Panel):\r
+\r
+    def __init__(self, parent, ID):\r
+        wx.Panel.__init__(self, parent, ID, style=wx.WANTS_CHARS|wx.NO_BORDER, size=(160, 200))\r
+\r
+        self.figure = Figure()\r
+        self.canvas = FigureCanvas(self, -1, self.figure)\r
+        self.SetColor(wx.NamedColor('WHITE'))\r
+\r
+        self.sizer = wx.BoxSizer(wx.VERTICAL)\r
+        self.sizer.Add(self.canvas, 1, wx.LEFT | wx.TOP | wx.GROW)\r
+        self.SetSizer(self.sizer)\r
+        self.Fit()\r
+\r
+        self.display_coordinates = False\r
+\r
+        self.figure.canvas.mpl_connect('button_press_event', self.OnClick)\r
+        self.figure.canvas.mpl_connect('axes_enter_event', self.OnEnterAxes)\r
+        self.figure.canvas.mpl_connect('axes_leave_event', self.OnLeaveAxes)\r
+        self.figure.canvas.mpl_connect('motion_notify_event', self.OnMouseMove)\r
+        self.add_toolbar()  # comment this out for no toolbar\r
+\r
+    def add_toolbar(self):\r
+        self.toolbar = HookeCustomToolbar(self.canvas)\r
+        self.toolbar.Realize()\r
+        if wx.Platform == '__WXMAC__':\r
+            # Mac platform (OSX 10.3, MacPython) does not seem to cope with\r
+            # having a toolbar in a sizer. This work-around gets the buttons\r
+            # back, but at the expense of having the toolbar at the top\r
+            self.SetToolBar(self.toolbar)\r
+        else:\r
+            # On Windows platform, default window size is incorrect, so set\r
+            # toolbar width to figure width.\r
+            tw, th = self.toolbar.GetSizeTuple()\r
+            fw, fh = self.canvas.GetSizeTuple()\r
+            # By adding toolbar in sizer, we are able to put it at the bottom\r
+            # of the frame - so appearance is closer to GTK version.\r
+            # As noted above, doesn't work for Mac.\r
+            self.toolbar.SetSize(wx.Size(fw, th))\r
+            self.sizer.Add(self.toolbar, 0, wx.LEFT | wx.EXPAND)\r
+        # update the axes menu on the toolbar\r
+        self.toolbar.update()\r
+\r
+    def get_figure(self):\r
+        return self.figure\r
+\r
+    def SetColor(self, rgbtuple):\r
+        '''\r
+        Set figure and canvas colours to be the same\r
+        '''\r
+        if not rgbtuple:\r
+            rgbtuple = wx.SystemSettings.GetColour(wx.SYS_COLOUR_BTNFACE).Get()\r
+        col = [c / 255.0 for c in rgbtuple]\r
+        self.figure.set_facecolor(col)\r
+        self.figure.set_edgecolor(col)\r
+        self.canvas.SetBackgroundColour(wx.Colour(*rgbtuple))\r
+\r
+    def SetStatusText(self, text, field=1):\r
+        self.Parent.Parent.statusbar.SetStatusText(text, field)\r
+\r
+    def OnClick(self, event):\r
+        #self.SetStatusText(str(event.xdata))\r
+        #print 'button=%d, x=%d, y=%d, xdata=%f, ydata=%f'%(event.button, event.x, event.y, event.xdata, event.ydata)\r
+        pass\r
+\r
+    def OnEnterAxes(self, event):\r
+        self.display_coordinates = True\r
+\r
+    def OnLeaveAxes(self, event):\r
+        self.display_coordinates = False\r
+        self.SetStatusText('')\r
+\r
+    def OnMouseMove(self, event):\r
+        if event.guiEvent.m_shiftDown:\r
+            self.toolbar.set_cursor(2)\r
+            #print 'hand: ' + str(wx.CURSOR_HAND)\r
+            #print 'cross: ' + str(wx.CURSOR_CROSS)\r
+            #print 'ibeam: ' + str(wx.CURSOR_IBEAM)\r
+            #print 'wait: ' + str(wx.CURSOR_WAIT)\r
+            #print 'hourglass: ' + str(wx.HOURGLASS_CURSOR)\r
+        else:\r
+            self.toolbar.set_cursor(1)\r
+\r
+            #axes = self.figure.axes[0]\r
+            #line, = axes.plot([event.x - 20 , event.x + 20], [event.y - 20, event.y + 20])\r
+\r
+            #line.figure.canvas.draw()\r
+        if self.display_coordinates:\r
+            coordinateString = ''.join([str(event.xdata), ' ', str(event.ydata)])\r
+            #TODO: pretty format\r
+            self.SetStatusText(coordinateString)\r
+\r
+    def OnPaint(self, event):\r
+        self.canvas.draw()\r
diff --git a/panels/propertyeditor.py b/panels/propertyeditor.py
new file mode 100644 (file)
index 0000000..40eecaf
--- /dev/null
@@ -0,0 +1,515 @@
+#!/usr/bin/env python\r
+\r
+'''\r
+propertyeditor.py\r
+\r
+Property editor panel for Hooke.\r
+\r
+Copyright 2009 by Dr. Rolf Schmidt (Concordia University, Canada)\r
+\r
+This program is released under the GNU General Public License version 2.\r
+'''\r
+\r
+import sys\r
+import os.path\r
+\r
+import wx\r
+import wx.propgrid as wxpg\r
+#import wx.stc\r
+from string import split\r
+\r
+#there are many comments and code fragments in here from the demo app\r
+#they should come in handy to expand the functionality in the future\r
+\r
+class Display:\r
+    property_descriptor = []\r
+    def __init__(self):\r
+        pass\r
+\r
+\r
+class ValueObject:\r
+    def __init__(self):\r
+        pass\r
+\r
+\r
+class IntProperty2(wxpg.PyProperty):\r
+    """\\r
+    This is a simple re-implementation of wxIntProperty.\r
+    """\r
+    def __init__(self, label, name = wxpg.LABEL_AS_NAME, value=0):\r
+        wxpg.PyProperty.__init__(self, label, name)\r
+        self.SetValue(value)\r
+\r
+    def GetClassName(self):\r
+        """\\r
+        This is not 100% necessary and in future is probably going to be\r
+        automated to return class name.\r
+        """\r
+        return "IntProperty2"\r
+\r
+    def GetEditor(self):\r
+        return "TextCtrl"\r
+\r
+    def GetValueAsString(self, flags):\r
+        return str(self.GetValue())\r
+\r
+    def PyStringToValue(self, s, flags):\r
+        try:\r
+            v = int(s)\r
+            if self.GetValue() != v:\r
+                return v\r
+        except TypeError:\r
+            if flags & wxpg.PG_REPORT_ERROR:\r
+                wx.MessageBox("Cannot convert '%s' into a number."%s, "Error")\r
+        return False\r
+\r
+    def PyIntToValue(self, v, flags):\r
+        if (self.GetValue() != v):\r
+            return v\r
+\r
+\r
+class PyFilesProperty(wxpg.PyArrayStringProperty):\r
+    def __init__(self, label, name = wxpg.LABEL_AS_NAME, value=[]):\r
+        wxpg.PyArrayStringProperty.__init__(self, label, name, value)\r
+        self.SetValue(value)\r
+\r
+    def OnSetValue(self, v):\r
+        self.value = v\r
+        self.display = ', '.join(self.value)\r
+\r
+    def GetValueAsString(self, argFlags):\r
+        return self.display\r
+\r
+    def PyStringToValue(self, s, flags):\r
+        return [a.strip() for a in s.split(',')]\r
+\r
+    def OnEvent(self, propgrid, ctrl, event):\r
+        if event.GetEventType() == wx.wxEVT_COMMAND_BUTTON_CLICKED:\r
+            # Show dialog to select a string, call DoSetValue and\r
+            # return True, if value changed.\r
+            return True\r
+\r
+        return False\r
+\r
+\r
+class PyObjectPropertyValue:\r
+    """\\r
+    Value type of our sample PyObjectProperty. We keep a simple dash-delimited\r
+    list of string given as argument to constructor.\r
+    """\r
+    def __init__(self, s=None):\r
+        try:\r
+            self.ls = [a.strip() for a in s.split('-')]\r
+        except:\r
+            self.ls = []\r
+\r
+    def __repr__(self):\r
+        return ' - '.join(self.ls)\r
+\r
+\r
+class PyObjectProperty(wxpg.PyProperty):\r
+    """\\r
+    Another simple example. This time our value is a PyObject (NOTE: we can't\r
+    return an arbitrary python object in DoGetValue. It cannot be a simple\r
+    type such as int, bool, double, or string, nor an array or wxObject based.\r
+    Dictionary, None, or any user-specified Python object is allowed).\r
+    """\r
+    def __init__(self, label, name = wxpg.LABEL_AS_NAME, value=None):\r
+        wxpg.PyProperty.__init__(self, label, name)\r
+        self.SetValue(value)\r
+\r
+    def GetClassName(self):\r
+        return self.__class__.__name__\r
+\r
+    def GetEditor(self):\r
+        return "TextCtrl"\r
+\r
+    def GetValueAsString(self, flags):\r
+        return repr(self.GetValue())\r
+\r
+    def PyStringToValue(self, s, flags):\r
+        return PyObjectPropertyValue(s)\r
+\r
+\r
+class ShapeProperty(wxpg.PyEnumProperty):\r
+    """\\r
+    Demonstrates use of OnCustomPaint method.\r
+    """\r
+    def __init__(self, label, name = wxpg.LABEL_AS_NAME, value=-1):\r
+        wxpg.PyEnumProperty.__init__(self, label, name, ['Line','Circle','Rectangle'], [0,1,2], value)\r
+\r
+    def OnMeasureImage(self, index):\r
+        return wxpg.DEFAULT_IMAGE_SIZE\r
+\r
+    def OnCustomPaint(self, dc, rect, paint_data):\r
+        """\\r
+        paint_data.m_choiceItem is -1 if we are painting the control,\r
+        in which case we need to get the drawn item using DoGetValue.\r
+        """\r
+        item = paint_data.m_choiceItem\r
+        if item == -1:\r
+            item = self.DoGetValue()\r
+\r
+        dc.SetPen(wx.Pen(wx.BLACK))\r
+        dc.SetBrush(wx.Brush(wx.BLACK))\r
+\r
+        if item == 0:\r
+            dc.DrawLine(rect.x,rect.y,rect.x+rect.width,rect.y+rect.height)\r
+        elif item == 1:\r
+            half_width = rect.width / 2\r
+            dc.DrawCircle(rect.x+half_width,rect.y+half_width,half_width-3)\r
+        elif item == 2:\r
+            dc.DrawRectangle(rect.x, rect.y, rect.width, rect.height)\r
+\r
+\r
+class LargeImagePickerCtrl(wx.Window):\r
+    """\\r
+    Control created and used by LargeImageEditor.\r
+    """\r
+    def __init__(self):\r
+        pre = wx.PreWindow()\r
+        self.PostCreate(pre)\r
+\r
+    def Create(self, parent, id_, pos, size, style = 0):\r
+        wx.Window.Create(self, parent, id_, pos, size, style | wx.BORDER_SIMPLE)\r
+        img_spc = size[1]\r
+        self.tc = wx.TextCtrl(self, -1, "", (img_spc,0), (2048,size[1]), wx.BORDER_NONE)\r
+        self.SetBackgroundColour(wx.WHITE)\r
+        self.SetBackgroundStyle(wx.BG_STYLE_CUSTOM)\r
+        self.property = None\r
+        self.bmp = None\r
+        self.Bind(wx.EVT_PAINT, self.OnPaint)\r
+\r
+    def OnPaint(self, event):\r
+        dc = wx.BufferedPaintDC(self)\r
+\r
+        whiteBrush = wx.Brush(wx.WHITE)\r
+        dc.SetBackground(whiteBrush)\r
+        dc.Clear()\r
+\r
+        bmp = self.bmp\r
+        if bmp:\r
+            dc.DrawBitmap(bmp, 2, 2)\r
+        else:\r
+            dc.SetPen(wx.Pen(wx.BLACK))\r
+            dc.SetBrush(whiteBrush)\r
+            dc.DrawRectangle(2, 2, 64, 64)\r
+\r
+    def RefreshThumbnail(self):\r
+        """\\r
+        We use here very simple image scaling code.\r
+        """\r
+        if not self.property:\r
+            self.bmp = None\r
+            return\r
+\r
+        path = self.property.DoGetValue()\r
+\r
+        if not os.path.isfile(path):\r
+            self.bmp = None\r
+            return\r
+\r
+        image = wx.Image(path)\r
+        image.Rescale(64, 64)\r
+        self.bmp = wx.BitmapFromImage(image)\r
+\r
+    def SetProperty(self, property):\r
+        self.property = property\r
+        self.tc.SetValue(property.GetDisplayedString())\r
+        self.RefreshThumbnail()\r
+\r
+    def SetValue(self, s):\r
+        self.RefreshThumbnail()\r
+        self.tc.SetValue(s)\r
+\r
+    def GetLastPosition(self):\r
+        return self.tc.GetLastPosition()\r
+\r
+\r
+class LargeImageEditor(wxpg.PyEditor):\r
+    """\\r
+    Double-height text-editor with image in front.\r
+    """\r
+    def __init__(self):\r
+        wxpg.PyEditor.__init__(self)\r
+\r
+    def CreateControls(self, propgrid, property, pos, sz):\r
+        try:\r
+            h = 64 + 6\r
+            x = propgrid.GetSplitterPosition()\r
+            x2 = propgrid.GetClientSize().x\r
+            bw = propgrid.GetRowHeight()\r
+            lipc = LargeImagePickerCtrl()\r
+            if sys.platform == 'win32':\r
+                lipc.Hide()\r
+            lipc.Create(propgrid, wxpg.PG_SUBID1, (x,pos[1]), (x2-x-bw,h))\r
+            lipc.SetProperty(property)\r
+            # Hmmm.. how to have two-stage creation without subclassing?\r
+            #btn = wx.PreButton()\r
+            #pre = wx.PreWindow()\r
+            #self.PostCreate(pre)\r
+            #if sys.platform == 'win32':\r
+            #    btn.Hide()\r
+            #btn.Create(propgrid, wxpg.PG_SUBID2, '...', (x2-bw,pos[1]), (bw,h), wx.WANTS_CHARS)\r
+            btn = wx.Button(propgrid, wxpg.PG_SUBID2, '...', (x2-bw,pos[1]), (bw,h), wx.WANTS_CHARS)\r
+            return (lipc, btn)\r
+        except:\r
+            import traceback\r
+            print traceback.print_exc()\r
+\r
+    def UpdateControl(self, property, ctrl):\r
+        ctrl.SetValue(property.GetDisplayedString())\r
+\r
+    def DrawValue(self, dc, property, rect):\r
+        if not (property.GetFlags() & wxpg.PG_PROP_AUTO_UNSPECIFIED):\r
+            dc.DrawText( property.GetDisplayedString(), rect.x+5, rect.y );\r
+\r
+    def OnEvent(self, propgrid, ctrl, event):\r
+        if not ctrl:\r
+            return False\r
+\r
+        evtType = event.GetEventType()\r
+\r
+        if evtType == wx.wxEVT_COMMAND_TEXT_ENTER:\r
+            if propgrid.IsEditorsValueModified():\r
+                return True\r
+\r
+        elif evtType == wx.wxEVT_COMMAND_TEXT_UPDATED:\r
+            if not property.HasFlag(wxpg.PG_PROP_AUTO_UNSPECIFIED) or not ctrl or \\r
+               ctrl.GetLastPosition() > 0:\r
+\r
+                # We must check this since an 'empty' text event\r
+                # may be triggered when creating the property.\r
+                PG_FL_IN_SELECT_PROPERTY = 0x00100000\r
+                if not (propgrid.GetInternalFlags() & PG_FL_IN_SELECT_PROPERTY):\r
+                    event.Skip();\r
+                    event.SetId(propgrid.GetId());\r
+\r
+                propgrid.EditorsValueWasModified();\r
+\r
+        return False\r
+\r
+\r
+    def CopyValueFromControl(self, property, ctrl):\r
+        tc = ctrl.tc\r
+        res = property.SetValueFromString(tc.GetValue(),0)\r
+        # Changing unspecified always causes event (returning\r
+        # true here should be enough to trigger it).\r
+        if not res and property.IsFlagSet(wxpg.PG_PROP_AUTO_UNSPECIFIED):\r
+            res = True\r
+\r
+        return res\r
+\r
+    def SetValueToUnspecified(self, ctrl):\r
+        ctrl.tc.Remove(0,len(ctrl.tc.GetValue()));\r
+\r
+    def SetControlStringValue(self, ctrl, txt):\r
+        ctrl.SetValue(txt)\r
+\r
+    def OnFocus(self, property, ctrl):\r
+        ctrl.tc.SetSelection(-1,-1)\r
+        ctrl.tc.SetFocus()\r
+\r
+\r
+class PropertyEditor(wx.Panel):\r
+\r
+    def __init__(self, parent):\r
+        # Use the WANTS_CHARS style so the panel doesn't eat the Return key.\r
+        wx.Panel.__init__(self, parent, -1, style=wx.WANTS_CHARS, size=(160, 200))\r
+\r
+        sizer = wx.BoxSizer(wx.VERTICAL)\r
+\r
+        self.pg = wxpg.PropertyGrid(self, style=wxpg.PG_SPLITTER_AUTO_CENTER|wxpg.PG_AUTO_SORT)\r
+\r
+        # Show help as tooltips\r
+        self.pg.SetExtraStyle(wxpg.PG_EX_HELP_AS_TOOLTIPS)\r
+\r
+        #pg.Bind(wxpg.EVT_PG_CHANGED, self.OnPropGridChange)\r
+        #pg.Bind(wxpg.EVT_PG_SELECTED, self.OnPropGridSelect)\r
+        #self.pg.Bind(wxpg.EVT_PG_RIGHT_CLICK, self.OnPropGridRightClick)\r
+\r
+        # Needed by custom image editor\r
+        wx.InitAllImageHandlers()\r
+\r
+        #\r
+        # Let's create a simple custom editor\r
+        #\r
+        # NOTE: Editor must be registered *before* adding a property that uses it.\r
+        self.pg.RegisterEditor(LargeImageEditor)\r
+\r
+        '''\r
+        #\r
+        # Add properties\r
+        #\r
+\r
+        pg.Append( wxpg.PropertyCategory("1 - Basic Properties") )\r
+        pg.Append( wxpg.StringProperty("String",value="Some Text") )\r
+        pg.Append( wxpg.IntProperty("Int",value=100) )\r
+        pg.Append( wxpg.FloatProperty("Float",value=100.0) )\r
+        pg.Append( wxpg.BoolProperty("Bool",value=True) )\r
+        pg.Append( wxpg.BoolProperty("Bool_with_Checkbox",value=True) )\r
+        pg.SetPropertyAttribute("Bool_with_Checkbox", "UseCheckbox", True)\r
+\r
+        pg.Append( wxpg.PropertyCategory("2 - More Properties") )\r
+        pg.Append( wxpg.LongStringProperty("LongString",value="This is a\\nmulti-line string\\nwith\\ttabs\\nmixed\\tin.") )\r
+        pg.Append( wxpg.DirProperty("Dir",value="C:\\Windows") )\r
+        pg.Append( wxpg.FileProperty("File",value="C:\\Windows\\system.ini") )\r
+        pg.Append( wxpg.ArrayStringProperty("ArrayString",value=['A','B','C']) )\r
+\r
+        pg.Append( wxpg.EnumProperty("Enum","Enum",\r
+                                     ['wxPython Rules','wxPython Rocks','wxPython Is The Best'],\r
+                                     [10,11,12],0) )\r
+        pg.Append( wxpg.EditEnumProperty("EditEnum","EditEnumProperty",['A','B','C'],[0,1,2],"Text Not in List") )\r
+\r
+        pg.Append( wxpg.PropertyCategory("3 - Advanced Properties") )\r
+        pg.Append( wxpg.DateProperty("Date",value=wx.DateTime_Now()) )\r
+        pg.Append( wxpg.FontProperty("Font",value=self.GetFont()) )\r
+        pg.Append( wxpg.ColourProperty("Colour",value=self.GetBackgroundColour()) )\r
+        pg.Append( wxpg.SystemColourProperty("SystemColour") )\r
+        pg.Append( wxpg.ImageFileProperty("ImageFile") )\r
+        pg.Append( wxpg.MultiChoiceProperty("MultiChoice",choices=['wxWidgets','QT','GTK+']) )\r
+\r
+        pg.Append( wxpg.PropertyCategory("4 - Additional Properties") )\r
+        pg.Append( wxpg.PointProperty("Point",value=self.GetPosition()) )\r
+        pg.Append( wxpg.SizeProperty("Size",value=self.GetSize()) )\r
+        pg.Append( wxpg.FontDataProperty("FontData") )\r
+        pg.Append( wxpg.IntProperty("IntWithSpin",value=256) )\r
+        pg.SetPropertyEditor("IntWithSpin","SpinCtrl")\r
+        pg.Append( wxpg.DirsProperty("Dirs",value=['C:/Lib','C:/Bin']) )\r
+        pg.SetPropertyHelpString( "String", "String Property help string!" )\r
+        pg.SetPropertyHelpString( "Dirs", "Dirs Property help string!" )\r
+\r
+        pg.SetPropertyAttribute( "File", wxpg.PG_FILE_SHOW_FULL_PATH, 0 )\r
+        pg.SetPropertyAttribute( "File", wxpg.PG_FILE_INITIAL_PATH, "C:\\Program Files\\Internet Explorer" )\r
+        pg.SetPropertyAttribute( "Date", wxpg.PG_DATE_PICKER_STYLE, wx.DP_DROPDOWN|wx.DP_SHOWCENTURY )\r
+\r
+        pg.Append( wxpg.PropertyCategory("5 - Custom Properties") )\r
+        pg.Append( IntProperty2("IntProperty2", value=1024) )\r
+\r
+        pg.Append( ShapeProperty("ShapeProperty", value=0) )\r
+        pg.Append( PyObjectProperty("PyObjectProperty") )\r
+\r
+        pg.Append( wxpg.ImageFileProperty("ImageFileWithLargeEditor") )\r
+        pg.SetPropertyEditor("ImageFileWithLargeEditor", "LargeImageEditor")\r
+\r
+\r
+        pg.SetPropertyClientData( "Point", 1234 )\r
+        if pg.GetPropertyClientData( "Point" ) != 1234:\r
+            raise ValueError("Set/GetPropertyClientData() failed")\r
+\r
+        # Test setting unicode string\r
+        pg.GetPropertyByName("String").SetValue(u"Some Unicode Text")\r
+\r
+        #\r
+        # Test some code that *should* fail (but not crash)\r
+        #try:\r
+            #a_ = pg.GetPropertyValue( "NotARealProperty" )\r
+            #pg.EnableProperty( "NotAtAllRealProperty", False )\r
+            #pg.SetPropertyHelpString( "AgaintNotARealProperty", "Dummy Help String" )\r
+        #except:\r
+            #pass\r
+            #raise\r
+\r
+        '''\r
+        sizer.Add(self.pg, 1, wx.EXPAND)\r
+        self.SetSizer(sizer)\r
+        sizer.SetSizeHints(self)\r
+\r
+        self.SelectedTreeItem = None\r
+\r
+    def GetPropertyValues(self):\r
+        return self.pg.GetPropertyValues()\r
+\r
+    def Initialize(self, properties):\r
+        pg = self.pg\r
+        pg.Clear()\r
+\r
+        if properties:\r
+            for element in properties:\r
+                if element[1]['type'] == 'arraystring':\r
+                    elements = element[1]['elements']\r
+                    if 'value' in element[1]:\r
+                        property_value = element[1]['value']\r
+                    else:\r
+                        property_value = element[1]['default']\r
+                    #retrieve individual strings\r
+                    property_value = split(property_value, ' ')\r
+                    #remove " delimiters\r
+                    values = [value.strip('"') for value in property_value]\r
+                    pg.Append(wxpg.ArrayStringProperty(element[0], value=values))\r
+\r
+                if element[1]['type'] == 'boolean':\r
+                    if 'value' in element[1]:\r
+                        property_value = element[1].as_bool('value')\r
+                    else:\r
+                        property_value = element[1].as_bool('default')\r
+                    property_control = wxpg.BoolProperty(element[0], value=property_value)\r
+                    pg.Append(property_control)\r
+                    pg.SetPropertyAttribute(element[0], 'UseCheckbox', True)\r
+\r
+                #if element[0] == 'category':\r
+                    #pg.Append(wxpg.PropertyCategory(element[1]))\r
+\r
+                if element[1]['type'] == 'color':\r
+                    if 'value' in element[1]:\r
+                        property_value = element[1]['value']\r
+                    else:\r
+                        property_value = element[1]['default']\r
+                    property_value = eval(property_value)\r
+                    pg.Append(wxpg.ColourProperty(element[0], value=property_value))\r
+\r
+                if element[1]['type'] == 'enum':\r
+                    elements = element[1]['elements']\r
+                    if 'value' in element[1]:\r
+                        property_value = element[1]['value']\r
+                    else:\r
+                        property_value = element[1]['default']\r
+                    pg.Append(wxpg.EnumProperty(element[0], element[0], elements, [], elements.index(property_value)))\r
+\r
+                if element[1]['type'] == 'filename':\r
+                    if 'value' in element[1]:\r
+                        property_value = element[1]['value']\r
+                    else:\r
+                        property_value = element[1]['default']\r
+                    pg.Append(wxpg.FileProperty(element[0], value=property_value))\r
+\r
+                if element[1]['type'] == 'float':\r
+                    if 'value' in element[1]:\r
+                        property_value = element[1].as_float('value')\r
+                    else:\r
+                        property_value = element[1].as_float('default')\r
+                    property_control = wxpg.FloatProperty(element[0], value=property_value)\r
+                    pg.Append(property_control)\r
+\r
+                if element[1]['type'] == 'folder':\r
+                    if 'value' in element[1]:\r
+                        property_value = element[1]['value']\r
+                    else:\r
+                        property_value = element[1]['default']\r
+                    pg.Append(wxpg.DirProperty(element[0], value=property_value))\r
+\r
+                if element[1]['type'] == 'integer':\r
+                    if 'value' in element[1]:\r
+                        property_value = element[1].as_int('value')\r
+                    else:\r
+                        property_value = element[1].as_int('default')\r
+                    property_control = wxpg.IntProperty(element[0], value=property_value)\r
+                    if 'maximum' in element[1]:\r
+                        property_control.SetAttribute('Max', element[1].as_int('maximum'))\r
+                    if 'minimum' in element[1]:\r
+                        property_control.SetAttribute('Min', element[1].as_int('minimum'))\r
+                    property_control.SetAttribute('Wrap', True)\r
+                    pg.Append(property_control)\r
+                    pg.SetPropertyEditor(element[0], 'SpinCtrl')\r
+\r
+                if element[1]['type'] == 'string':\r
+                    if 'value' in element[1]:\r
+                        property_value = element[1]['value']\r
+                    else:\r
+                        property_value = element[1]['default']\r
+                    pg.Append(wxpg.StringProperty(element[0], value=property_value))\r
+\r
+        pg.Refresh()\r
+\r
+    def OnReserved(self, event):\r
+        pass\r
diff --git a/panels/results.py b/panels/results.py
new file mode 100644 (file)
index 0000000..4b10f83
--- /dev/null
@@ -0,0 +1,83 @@
+#!/usr/bin/env python\r
+\r
+'''\r
+results.py\r
+\r
+Fitting results panel for Hooke.\r
+\r
+Copyright 2009 by Dr. Rolf Schmidt (Concordia University, Canada)\r
+\r
+This program is released under the GNU General Public License version 2.\r
+'''\r
+\r
+import sys\r
+import wx\r
+from wx.lib.mixins.listctrl import CheckListCtrlMixin\r
+\r
+class CheckListCtrl(wx.ListCtrl, CheckListCtrlMixin):\r
+    def __init__(self, parent):\r
+        wx.ListCtrl.__init__(self, parent, -1, style=wx.LC_REPORT)\r
+        CheckListCtrlMixin.__init__(self)\r
+        self.Bind(wx.EVT_LIST_ITEM_ACTIVATED, self.OnItemActivated)\r
+\r
+    def OnItemActivated(self, evt):\r
+        self.ToggleItem(evt.m_itemIndex)\r
+\r
+\r
+class Results(wx.Panel):\r
+    def __init__(self, parent):\r
+        wx.Panel.__init__(self, parent, -1)\r
+        self.results_list = CheckListCtrl(self)\r
+        sizer = wx.BoxSizer()\r
+        sizer.Add(self.results_list, 1, wx.EXPAND)\r
+        self.SetSizer(sizer)\r
+        self.Bind(wx.EVT_LIST_ITEM_SELECTED, self.OnItemSelected, self.results_list)\r
+        self.Bind(wx.EVT_LIST_ITEM_DESELECTED, self.OnItemDeselected, self.results_list)\r
+\r
+    def _GetWidthInPixels(self, text):\r
+        #TODO:\r
+        #Returns the width of a string in pixels\r
+        #Unfortunately, it does not work terribly well (although it should).\r
+        #Thus, we have to add a bit afterwards.\r
+        #Annoys the heck out of me (me being Rolf).\r
+        font = self.results_list.GetFont()\r
+        dc = wx.WindowDC(self.results_list)\r
+        dc.SetFont(font)\r
+        width, height = dc.GetTextExtent(text)\r
+        return width\r
+\r
+    def ClearResults(self):\r
+        self.results_list.ClearAll()\r
+\r
+    def DisplayResults(self, results):\r
+        self.ClearResults()\r
+        header = results.get_header_as_list()\r
+        self.results_list.InsertColumn(0, 'Show')\r
+        for index, column in enumerate(header):\r
+            self.results_list.InsertColumn(index + 1, column, wx.LIST_FORMAT_RIGHT)\r
+\r
+        for result in results.results:\r
+            done = False\r
+            for index, column in enumerate(results.columns):\r
+                value_str = results.get_pretty_value(column, result.result[column])\r
+                if not done:\r
+                    index_col = self.results_list.InsertStringItem(sys.maxint, '')\r
+                    done = True\r
+                column_width = len(self.results_list.GetColumn(index + 1).GetText())\r
+                value_str = value_str.center(column_width)\r
+                self.results_list.SetStringItem(index_col, index + 1, value_str)\r
+\r
+        for index, result in enumerate(results.results):\r
+            if result.visible:\r
+                #if we use 'CheckItem' then 'UpdatePlot' is called (ie repeated updates)\r
+                self.results_list.SetItemImage(index, 1)\r
+        for index in range(self.results_list.GetColumnCount()):\r
+            column_text = self.results_list.GetColumn(index).GetText()\r
+            column_width = self._GetWidthInPixels(column_text)\r
+            self.results_list.SetColumnWidth(index, column_width + 15)\r
+\r
+    def OnItemSelected(self, evt):\r
+        pass\r
+\r
+    def OnItemDeselected(self, evt):\r
+        pass\r
diff --git a/pca_config.txt b/pca_config.txt
deleted file mode 100644 (file)
index 8eb72a9..0000000
+++ /dev/null
@@ -1,33 +0,0 @@
-1,3,6,7,8,9x15,10,11\r
-0.000000\r
-1,2,3,4,5,6,7,8,9,10,11\r
-debug=false\r
-------------------------------------------\r
-#1 colonne della prima pca\r
-#2 limite filtro della densità (x es: "0.000008"; "0" per calcolo automatico.. 3,242311147)\r
-#3 colonne della secona pca (non usato)\r
-#4 attiva modalità debug (stampa anche immagini/coordinate di pca/density)\r
-------------------------------------------\r
-str(peak_number)+     # non considerato\r
-str(delta_mean)+      # 0\r
-str(delta_median)+    # 1 -\r
-str(force_mean)+      # 2\r
-str(force_median)+    # 3 -\r
-str(first_peak_cl)+   # 4 -\r
-str(last_peak_cl)+    # 5 -\r
-str(max_force)+       # 6\r
-str(min_force)+       # 7\r
-str(max_delta)+       # 8\r
-str(min_delta)+       # 9\r
-str(delta_stdev)+     # 10\r
-str(forces_stdev)+    # 11\r
-str(peaks_diff)+      # 12\r
-------------------------------------------\r
-Lancio di pCluster e pca:\r
- - cd 20080917_4s4wt_10mMtris_all\r
- - genlist *.*\r
- - setconv blindwindow 50\r
- - pcluster pl=0.35\r
-------------------------------------------\r
-Lancio della sola pca\r
- - pca 20080922_gb1x8_tris/pCluster_20090627_1328/coordinate_20080922_gb1x8_tris_blind50.txt
\ No newline at end of file
diff --git a/pcluster.py b/pcluster.py
deleted file mode 100644 (file)
index 5084b83..0000000
+++ /dev/null
@@ -1,735 +0,0 @@
-#!/usr/bin/env python
-
-from mdp import pca
-from libhooke import WX_GOOD, ClickedPoint
-import wxversion
-wxversion.select(WX_GOOD)
-from wx import PostEvent
-import numpy as np
-import scipy as sp
-import copy
-import os.path
-import time
-import libhookecurve as lhc
-import pylab as pyl
-
-import warnings
-warnings.simplefilter('ignore',np.RankWarning)
-
-
-class pclusterCommands:
-    
-    def _plug_init(self):
-        self.clustplot1=None
-        self.clustplot2=None
-
-    def do_pcluster(self,args):
-        '''
-        pCLUSTER
-        (pcluster.py)
-        Automatically measures peaks and extracts informations for further clustering
-        (c)Paolo Pancaldi, Massimo Sandal 2009
-        '''
-        if self.config['hookedir'][0]=='/':
-            slash='/' #a Unix or Unix-like system
-        else:
-            slash='\\'
-        blindw = str(self.convfilt_config['blindwindow'])
-        pclus_dir = "pCluster_blind"+blindw+"_"+time.strftime("%Y%m%d_%H%M")
-        self.my_work_dir = os.getcwd()+slash+pclus_dir+slash
-        self.my_curr_dir = os.path.basename(os.getcwd())
-        os.mkdir(self.my_work_dir)
-        
-        #--Custom persistent length
-        pl_value=None
-        for arg in args.split():
-            #look for a persistent length argument.
-            if 'pl=' in arg:
-                pl_expression=arg.split('=')
-                pl_value=float(pl_expression[1]) #actual value
-            else:
-                pl_value=None
-                
-        #configuration variables
-        min_npks = self.convfilt_config['minpeaks']
-        min_deviation = self.convfilt_config['mindeviation']
-        
-        pclust_filename = "automeasure_"+self.my_curr_dir+"_blind"+blindw+".txt" #raw_input('Automeasure filename? ')
-        realclust_filename = "coordinate_"+self.my_curr_dir+"_blind"+blindw+".txt" #raw_input('Coordinates filename? ')
-        peackforce_filename = "peakforce_"+self.my_curr_dir+"_blind"+blindw+".txt"  #raw_input('Peacks and Forces filename? ')
-        
-        f=open(self.my_work_dir+pclust_filename,'w+')
-        f.write('Analysis started '+time.asctime()+'\n')
-        f.write('----------------------------------------\n')
-        f.write('; Contour length (nm)  ;  Persistence length (nm) ;  Max.Force (pN)  ;  Slope (N/m) ;  Sigma contour (nm) ; Sigma persistence (nm)\n')
-        f.close()
-        
-        f=open(self.my_work_dir+realclust_filename,'w+')
-        f.write('Analysis started '+time.asctime()+'\n')
-        f.write('----------------------------------------\n')
-        f.write('; Peak number ; Mean delta (nm)  ;  Median delta (nm) ;  Mean force (pN)  ;  Median force (pN) ; First peak length (nm) ; Last peak length (nm) ; Max force (pN) ; Min force (pN) ; Max delta (nm) ; Min delta (nm) ; Peaks Diff\n')
-        f.close()
-        
-        f=open(self.my_work_dir+peackforce_filename,'w+')
-        f.write('Analysis started '+time.asctime()+'\n')
-        f.write('----------------------------------------\n')
-        f.write('; Peak number  ;  1 peak Length (nm) ; 1 peak Force (pN) ;  2 peak Length (nm) ; 2 peak Force (pN) ;  3 peak Length (nm) ; 3 peak Force (pN) ;  4 peak Length (nm) ; 4 peak Force (pN) ;  5 peak Length (nm) ; 5 peak Force (pN) ;  6 peak Length (nm) ; 6 peak Force (pN) ;  7 peak Length (nm) ; 7 peak Force (pN) ;  8 peak Length (nm) ; 8 peak Force (pN)\n')
-        f.close()
-        
-        # ------ FUNCTION ------
-        def fit_interval_nm(start_index,plot,nm,backwards):
-            '''
-            Calculates the number of points to fit, given a fit interval in nm
-            start_index: index of point
-            plot: plot to use
-            backwards: if true, finds a point backwards.
-            '''
-            whatset=1 #FIXME: should be decidable
-            x_vect=plot.vectors[1][0]
-            
-            c=0
-            i=start_index
-            start=x_vect[start_index]
-            maxlen=len(x_vect)
-            while abs(x_vect[i]-x_vect[start_index])*(10**9) < nm:
-                if i==0 or i==maxlen-1: #we reached boundaries of vector!
-                    return c
-                if backwards:
-                    i-=1
-                else:
-                    i+=1
-                c+=1
-            return c
-
-        def plot_informations(itplot,pl_value):
-            '''
-            OUR VARIABLES
-            contact_point.absolute_coords              (2.4584142802103689e-007, -6.9647135616234017e-009)
-            peak_point.absolute_coords                 (3.6047748250571423e-008, -7.7142802788854212e-009)
-            other_fit_point.absolute_coords    (4.1666139243838867e-008, -7.3759393477579707e-009)
-            peak_location                                                                              [510, 610, 703, 810, 915, 1103]
-            peak_size                                                                                          [-1.2729111505202212e-009, -9.1632775347399312e-010, -8.1707438353929907e-010, -8.0335812578148904e-010, -8.7483955226387558e-010, -3.6269619757067322e-009]
-            params                                                                                                     [2.2433999931959462e-007, 3.3230248825175678e-010]
-            fit_errors                                                                                 [6.5817195369767644e-010, 2.4415923138871498e-011]
-            '''
-            fit_points=int(self.config['auto_fit_points']) # number of points to fit before the peak maximum <50>
-            
-            T=self.config['temperature'] #temperature of the system in kelvins. By default it is 293 K. <301.0>
-            cindex=self.find_contact_point(itplot[0]) #Automatically find contact point <158, libhooke.ClickedPoint>
-            contact_point=self._clickize(itplot[0].vectors[1][0], itplot[0].vectors[1][1], cindex)
-            self.basepoints=[]
-            base_index_0=peak_location[-1]+fit_interval_nm(peak_location[-1], itplot[0], self.config['auto_right_baseline'],False)
-            self.basepoints.append(self._clickize(itplot[0].vectors[1][0],itplot[0].vectors[1][1],base_index_0))
-            base_index_1=self.basepoints[0].index+fit_interval_nm(self.basepoints[0].index, itplot[0], self.config['auto_left_baseline'],False)
-            self.basepoints.append(self._clickize(itplot[0].vectors[1][0],itplot[0].vectors[1][1],base_index_1))
-            self.basecurrent=self.current.path
-            boundaries=[self.basepoints[0].index, self.basepoints[1].index]
-            boundaries.sort()
-            to_average=itplot[0].vectors[1][1][boundaries[0]:boundaries[1]] #y points to average
-            avg=np.mean(to_average)
-            return fit_points, contact_point, pl_value, T, cindex, avg
-
-        def features_peaks(itplot, peak, fit_points, contact_point, pl_value, T, cindex, avg):
-            '''
-            calculate informations for each peak and add they in 
-            c_lengths, p_lengths, sigma_c_lengths, sigma_p_lengths, forces, slopes
-            '''
-            c_leng=None
-            p_leng=None
-            sigma_c_leng=None
-            sigma_p_leng=None
-            force=None
-            slope=None
-            
-            delta_force=10
-            slope_span=int(self.config['auto_slope_span'])
-            
-            peak_point=self._clickize(itplot[0].vectors[1][0],itplot[0].vectors[1][1],peak)
-            other_fit_point=self._clickize(itplot[0].vectors[1][0],itplot[0].vectors[1][1],peak-fit_points)
-            
-            points=[contact_point, peak_point, other_fit_point]
-            
-            params, yfit, xfit, fit_errors = self.wlc_fit(points, itplot[0].vectors[1][0], itplot[0].vectors[1][1], pl_value, T, return_errors=True)
-            
-            #Measure forces
-            delta_to_measure=itplot[0].vectors[1][1][peak-delta_force:peak+delta_force]
-            y=min(delta_to_measure)
-            #Measure slopes
-            slope=self.linefit_between(peak-slope_span,peak)[0]
-            #check fitted data and, if right, add peak to the measurement
-            if len(params)==1: #if we did choose 1-value fit
-                p_leng=pl_value
-                c_leng=params[0]*(1.0e+9)
-                sigma_p_leng=0
-                sigma_c_leng=fit_errors[0]*(1.0e+9)
-                force = abs(y-avg)*(1.0e+12)
-            else: #2-value fit
-                p_leng=params[1]*(1.0e+9)
-                #check if persistent length makes sense. otherwise, discard peak.
-                if p_leng>self.config['auto_min_p'] and p_leng<self.config['auto_max_p']:
-                    '''
-                    p_lengths.append(p_leng)       
-                    c_lengths.append(params[0]*(1.0e+9))
-                    sigma_c_lengths.append(fit_errors[0]*(1.0e+9))
-                    sigma_p_lengths.append(fit_errors[1]*(1.0e+9))
-                    forces.append(abs(y-avg)*(1.0e+12))
-                    slopes.append(slope)     
-                    '''
-                    c_leng=params[0]*(1.0e+9)
-                    sigma_c_leng=fit_errors[0]*(1.0e+9)
-                    sigma_p_leng=fit_errors[1]*(1.0e+9)
-                    force=abs(y-avg)*(1.0e+12)
-                else:
-                    p_leng=None
-                    slope=None
-            #return c_lengths, p_lengths, sigma_c_lengths, sigma_p_lengths, forces, slopes
-            return  c_leng, p_leng, sigma_c_leng, sigma_p_leng, force, slope
-
-
-        # ------ PROGRAM -------
-        c=0
-        for item in self.current_list:
-            c+=1
-            item.identify(self.drivers)
-            itplot=item.curve.default_plots()
-            flatten=self._find_plotmanip('flatten') #extract flatten plot manipulator
-            itplot[0]=flatten(itplot[0], item, customvalue=1)
-            try:
-                peak_location,peak_size=self.exec_has_peaks(item,min_deviation)
-            except: 
-                #We have troubles with exec_has_peaks (bad curve, whatever).
-                #Print info and go to next cycle.
-                print 'Cannot process ',item.path
-                continue 
-
-            if len(peak_location)==0:
-                print 'No peaks!'
-                continue
-
-            fit_points, contact_point, pl_value, T, cindex, avg = plot_informations(itplot,pl_value)
-            
-            print '\n\nCurve',item.path, 'is',c,'of',len(self.current_list),': found '+str(len(peak_location))+' peaks.'
-
-            #initialize output data vectors
-            c_lengths=[]
-            p_lengths=[]
-            sigma_c_lengths=[]
-            sigma_p_lengths=[]
-            forces=[]
-            slopes=[]
-
-            #loop each peak of my curve
-            for peak in peak_location:
-                c_leng, p_leng, sigma_c_leng, sigma_p_leng, force, slope = features_peaks(itplot, peak, fit_points, contact_point, pl_value, T, cindex, avg)
-                for var, vector in zip([c_leng, p_leng, sigma_c_leng, sigma_p_leng, force, slope],[c_lengths, p_lengths, sigma_c_lengths, sigma_p_lengths, forces, slopes]):
-                    if var is not None:
-                        vector.append(var)
-
-            #FIXME: We need a dictionary here...
-            allvects=[c_lengths, p_lengths, sigma_c_lengths, sigma_p_lengths, forces, slopes]
-            for vect in allvects:
-                if len(vect)==0:
-                    for i in range(len(c_lengths)):
-                        vect.append(0)
-            
-            print 'Measurements for all peaks detected:'
-            print 'contour (nm)', c_lengths
-            print 'sigma contour (nm)',sigma_c_lengths
-            print 'p (nm)',p_lengths
-            print 'sigma p (nm)',sigma_p_lengths
-            print 'forces (pN)',forces
-            print 'slopes (N/m)',slopes
-            
-            '''
-            write automeasure text file
-            '''
-            print 'Saving automatic measurement...'
-            f=open(self.my_work_dir+pclust_filename,'a+')
-            f.write(item.path+'\n')
-            for i in range(len(c_lengths)):
-                f.write(' ; '+str(c_lengths[i])+' ; '+str(p_lengths[i])+' ; '+str(forces[i])+' ; '+str(slopes[i])+' ; '+str(sigma_c_lengths[i])+' ; '+str(sigma_p_lengths[i])+'\n')
-            f.close()
-            
-            peak_number=len(c_lengths)
-            
-            '''
-            write peackforce text file
-            '''
-            print 'Saving automatic measurement...'
-            f=open(self.my_work_dir+peackforce_filename,'a+')
-            f.write(item.path+'\n')
-            peackforce_info = ''
-            for i in range(len(c_lengths)):
-                peackforce_info = peackforce_info + ' ; ' + str(c_lengths[i]) + ' ; ' + str(forces[i])
-            f.write(' ; '+str(peak_number)+peackforce_info+'\n')
-            f.close()
-            
-            '''
-            calculate clustering coordinates
-            '''
-            if peak_number > 1:
-                deltas=[]
-                for i in range(len(c_lengths)-1):
-                    deltas.append(c_lengths[i+1]-c_lengths[i])
-                
-                delta_mean=np.mean(deltas)
-                delta_median=np.median(deltas)
-                
-                force_mean=np.mean(forces)
-                force_median=np.median(forces)
-                
-                first_peak_cl=c_lengths[0]
-                last_peak_cl=c_lengths[-1]
-                
-                max_force=max(forces[:-1])
-                min_force=min(forces)
-                
-                max_delta=max(deltas)
-                min_delta=min(deltas)
-                
-                delta_stdev=np.std(deltas)
-                forces_stdev=np.std(forces[:-1])
-                    
-                peaks_diff=(last_peak_cl-first_peak_cl)/peak_number
-                
-                print 'Coordinates'
-                print 'Peaks',peak_number
-                print 'Mean delta',delta_mean
-                print 'Median delta',delta_median
-                print 'Mean force',force_mean
-                print 'Median force',force_median
-                print 'First peak',first_peak_cl
-                print 'Last peak',last_peak_cl
-                print 'Max force',max_force
-                print 'Min force',min_force
-                print 'Max delta',max_delta
-                print 'Min delta',min_delta
-                print 'Delta stdev',delta_stdev
-                print 'Forces stdev',forces_stdev
-                print 'Peaks difference',peaks_diff
-                
-                '''
-                write clustering coordinates
-                '''
-                f=open(self.my_work_dir+realclust_filename,'a+')
-                f.write(item.path+'\n')
-                f.write(' ; '+str(peak_number)+     # non considerato
-                        ' ; '+str(delta_mean)+      # 0
-                        ' ; '+str(delta_median)+    # 1 -
-                        ' ; '+str(force_mean)+      # 2
-                        ' ; '+str(force_median)+    # 3 -
-                        ' ; '+str(first_peak_cl)+   # 4 -
-                        ' ; '+str(last_peak_cl)+    # 5 -
-                        ' ; '+str(max_force)+       # 6
-                        ' ; '+str(min_force)+       # 7
-                        ' ; '+str(max_delta)+       # 8
-                        ' ; '+str(min_delta)+       # 9
-                        ' ; '+str(delta_stdev)+     # 10
-                        ' ; '+str(forces_stdev)+    # 11
-                        ' ; '+str(peaks_diff)+      # 12
-                        '\n')
-                f.close()
-                
-        # start PCA
-        self.do_pca(pclus_dir+"/"+realclust_filename)
-        
-                
-    def do_pca(self,args):
-        '''
-        PCA -> "pca gaeta_coor_blind50.txt 1,3,6"
-        Automatically measures pca from coordinates filename and shows two interactives plots
-        With the second argument (arbitrary) you can select the columns and the multiplier factor 
-        to use for the pca (for es "1,3*50,6,8x10,9"). Dont use spaces. "*" or "x" are the same thing.
-        Without second argument it reads pca_config.txt file
-        (c)Paolo Pancaldi, Massimo Sandal 2009
-        '''
-        
-        # reads the columns of pca
-        if self.config['hookedir'][0]=='/':
-            slash='/' #a Unix or Unix-like system
-        else:
-            slash='\\'
-        self.my_hooke_dir = self.config['hookedir']+slash
-        #self.my_work_dir = os.getcwd()+slash+"pCluster_"+time.strftime("%Y%m%d_%H%M")+slash
-        #self.my_curr_dir = os.path.basename(os.getcwd())
-        conf=open(self.my_hooke_dir+"pca_config.txt")
-        config = conf.readlines()
-        conf.close()
-        
-        self.plot_myCoord = []          # tiene le coordinate prese direttamente dal file creato con pCluster
-        self.plot_origCoord = []        # tiene le coordinate solo delle colonne scelte e moltiplicate per i valori scelti
-        self.plot_pcaCoord = []         # tiene le due colonne della pca
-        self.plot_pcaCoordTr = []       # tiene le due colonne della pca trasposta
-        self.plot_FiltOrigCoord = []    # tiene le coordinate solo dei punti filtrati per densita
-        self.plot_FiltPaths = []        # tiene i paths dei plot solo dei punti filtrati per densita
-        self.plot_paths = []            # tiene i paths di tutti i plots
-        self.plot_NewPcaCoord = []      # tiene le due colonne della pca filtrate per densita
-        self.plot_NewPcaCoordTr=[]      # tiene le due colonne della pca trasposta filtrate per densita
-        plot_path_temp = ""
-        
-        # prende in inpunt un arg (nome del file) 
-        # e il secondo le colonne su cui lavorare (e' arbitrario, riceve x es "1,2,3")
-        arg = args.split(" ")
-        if arg[0]==args:
-            file_name=args
-        else:
-            file_name=arg[0]
-            config[0] = arg[1]
-        
-        # creo l'array "plot_myCoord" con tutte le coordinate dei plots
-        # e l'array plot_paths con tutti i percorsi dei plots
-        nPlotTot = -3 #tolgo le prime 3 righe iniziali del file
-        f=open(file_name)
-        rows = f.readlines()
-        for row in rows:
-            if row[0]!=" " and row[0]!="":
-                nPlotTot = nPlotTot+1
-                plot_path_temp = row
-            if row[0]==" " and row.find('nan')==-1 and row.find("-1.#IND")==-1:
-                row = row[row.index(";",2)+2:].split(" ; ")    # non considero la prima colonna col #picchi
-                row = [float(i) for i in row]
-                
-                #0:Mean delta, 1:Median delta, 2:Mean force, 3:Median force, 4:First peak length, 5:Last peak length
-                #6:Max delta 7:Min delta 8:Max force 9:Min force 10:Std delta 11:Std force
-                if (row[0]<500 and row[1]<500 and row[2]<500 and row[3]<500 and row[4]<500 and row[5]<500 and row[6]<500 and row[7]<500 and row[8]<500 and row[9]<500 and row[10]<500 and row[11]<500):
-                    if (row[0]>0 and row[1]>0 and row[2]>0 and row[3]>0 and row[4]>0 and row[5]>0 and row[6]>0 and row[7]>0 and row[8]>0 and row[9]>0 and row[10]>0 and row[11]>0):
-                        #row = row[0], row[2], row[3]*3, row[6], row[7]*56, row[8]
-                        self.plot_myCoord.append(row)
-                        self.plot_paths.append(plot_path_temp)
-        f.close()
-        
-        # creo l'array con alcune colonne e pure moltiplicate 
-        for row in self.plot_myCoord:
-            res=[]
-            for cols in config[0].split(","):
-                if cols.find("*")!=-1:
-                    col = int(cols.split("*")[0])
-                    molt = int(cols.split("*")[1])
-                elif cols.find("x")!=-1:
-                    col = int(cols.split("x")[0])
-                    molt = int(cols.split("x")[1])
-                else:
-                    col = int(cols)
-                    molt = 1
-                res.append(row[col]*molt)
-            self.plot_origCoord.append(res)
-        
-        # array convert, calculate PCA, transpose
-        self.plot_origCoord = np.array(self.plot_origCoord,dtype='float')
-        #print self.plot_origCoord.shape
-        self.plot_pcaCoord = pca(self.plot_origCoord, output_dim=2)    #other way -> y = mdp.nodes.PCANode(output_dim=2)(array)
-        self.plot_pcaCoordTr = np.transpose(self.plot_pcaCoord)
-        pca_X=np.array(self.plot_pcaCoordTr[0],dtype='float')
-        pca_Y=np.array(self.plot_pcaCoordTr[1],dtype='float')
-        
-        '''
-        # Start section of testing with good plots                                  # 4 TESTING!
-        Xsyn_1=[]
-        Ysyn_1=[]        
-        Xgb1_1=[]
-        Ygb1_1=[]
-        Xbad_1=[]
-        Ybad_1=[]
-        goodnamefile=open(file_name.replace("coordinate", "good"),'r')
-        goodnames=goodnamefile.readlines()
-        nPlotGood = len(goodnames)-2 #tolgo prima e ultima riga
-        goodnames=[i.split()[0] for i in goodnames[1:]]
-        
-        for index in range(len(self.plot_paths)):
-            if self.plot_paths[index][:-1] in goodnames:
-                Xsyn_1.append(pca_X[index])
-                Ysyn_1.append(pca_Y[index])
-            else:
-                Xbad_1.append(pca_X[index])
-                Ybad_1.append(pca_Y[index])
-        # Stop section of testing with good plots                                   # 4 TESTING!
-        '''
-        
-        # print first plot
-        clustplot1=lhc.PlotObject()
-        clustplot1.add_set(pca_X,pca_Y)
-        #clustplot1.add_set(Xbad_1,Ybad_1) # 4 TESTING!
-        #clustplot1.add_set(Xsyn_1,Ysyn_1) # 4 TESTING!
-        clustplot1.normalize_vectors()
-        clustplot1.styles=['scatter', 'scatter','scatter']
-        clustplot1.colors=[None,'red','green']
-        clustplot1.destination=0
-        self._send_plot([clustplot1])
-        self.clustplot1=clustplot1
-        
-        # density and filer estimation
-        kernel = sp.stats.kde.gaussian_kde(sp.c_[pca_X,pca_Y].T)
-        tallest = 0
-        for i in range(len(pca_X)):
-            kern_value = kernel.evaluate([pca_X[i],pca_Y[i]])
-            if tallest < kern_value:
-                    tallest = float(kern_value)
-        if float(config[1]) == 0:
-            my_filter = float(tallest / 3.242311147)
-        else:
-            my_filter = float(config[1])
-        '''
-        # section useful only for graphic printing
-        xmin = pca_X.min()
-        xmax = pca_X.max()
-        ymin = pca_Y.min()
-        ymax = pca_Y.max()
-        mX, mY = sp.mgrid[xmin:xmax:100j, ymin:ymax:100j]
-        Z = sp.rot90(sp.fliplr(sp.reshape(kernel(sp.c_[mX.ravel(), mY.ravel()].T).T, mX.T.shape)))
-        axis_X = np.linspace(xmin,xmax,num=100)
-        axis_Y = np.linspace(ymin,ymax,num=100)
-        '''
-        
-        # density filtering:
-        # tramite "kernel.evaluate" trovo lo score (altezza) di ogni coordinata e decido se mantenerla o no
-        filtered_pca_X = []
-        filtered_pca_Y = []
-        filtered_PcaCoordTr = []
-        filtered_PcaCoord = []
-        for i in range(len(pca_X)):
-            kern_value = kernel.evaluate([pca_X[i],pca_Y[i]])
-            if kern_value > my_filter:
-                filtered_pca_X.append(pca_X[i])
-                filtered_pca_Y.append(pca_Y[i])
-        filtered_PcaCoordTr.append(filtered_pca_X)
-        filtered_PcaCoordTr.append(filtered_pca_Y)
-        filtered_PcaCoord = np.transpose(filtered_PcaCoordTr)
-        
-        # creo i due array "plot_FiltOrigCoord" e "plot_FiltPaths" contenenti solo i dati filtrati con alta densita
-        for index in range(len(self.plot_pcaCoord)):
-            if self.plot_pcaCoord[index] in filtered_PcaCoord:
-                self.plot_FiltOrigCoord.append(self.plot_myCoord[index])
-                self.plot_FiltPaths.append(self.plot_paths[index])
-        
-        '''
-        # START PCA#2: USELESS!!!
-        
-        # creo l array con alcune colonne e pure moltiplicate
-        temp_coord = []
-        for row in self.plot_FiltOrigCoord:
-            res=[]
-            for cols in config[2].split(","):
-                if cols.find("*")!=-1:
-                    col = int(cols.split("*")[0])
-                    molt = int(cols.split("*")[1])
-                elif cols.find("x")!=-1:
-                    col = int(cols.split("x")[0])
-                    molt = int(cols.split("x")[1])
-                else:
-                    col = int(cols)
-                    molt = 1
-                res.append(row[col]*molt)
-            temp_coord.append(res)
-        self.plot_FiltOrigCoord = temp_coord
-                
-        # ricalcolo la PCA: array convert, calculate PCA, transpose
-        self.plot_FiltOrigCoord = np.array(self.plot_FiltOrigCoord,dtype='float')
-        #print self.plot_FiltOrigCoord.shape
-        self.plot_NewPcaCoord = pca(self.plot_FiltOrigCoord, output_dim=2)     #other way -> y = mdp.nodes.PCANode(output_dim=2)(array)
-        self.plot_NewPcaCoordTr = np.transpose(self.plot_NewPcaCoord)
-        pca_X2=np.array(self.plot_NewPcaCoordTr[0],dtype='float')
-        pca_Y2=np.array(self.plot_NewPcaCoordTr[1],dtype='float')
-        
-        # Start section of testing with good plots                              # 4 TESTING!
-        Xsyn_2=[]
-        Ysyn_2=[]
-        Xbad_2=[]
-        Ybad_2=[]
-        for index in range(len(self.plot_FiltPaths)):
-            if self.plot_FiltPaths[index][:-1] in goodnames:
-                Xsyn_2.append(pca_X2[index])
-                Ysyn_2.append(pca_Y2[index])
-            else:
-                Xbad_2.append(pca_X2[index])
-                Ybad_2.append(pca_Y2[index])
-        
-        # print second plot
-        clustplot2=lhc.PlotObject()
-        #clustplot2.add_set(pca_X2,pca_Y2)
-        clustplot2.add_set(Xbad_2,Ybad_2)                                       # 4 TESTING!
-        clustplot2.add_set(Xsyn_2,Ysyn_2)                                       # 4 TESTING!
-        clustplot2.normalize_vectors()
-        clustplot2.styles=['scatter', 'scatter','scatter']
-        clustplot2.colors=[None,'red','green']
-        clustplot2.destination=1
-        self._send_plot([clustplot2])
-        self.clustplot2=clustplot2
-        '''
-        
-        # PRINT density plot
-        clustplot2=lhc.PlotObject()
-        clustplot2.add_set(filtered_pca_X,filtered_pca_Y)
-        clustplot2.normalize_vectors()
-        clustplot2.styles=['scatter', 'scatter','scatter']
-        clustplot2.colors=[None,'red','green']
-        clustplot2.destination=1
-        self._send_plot([clustplot2])
-        self.clustplot2=clustplot2
-        
-        # printing results
-        config_pca1 = config[0].replace("*", "x").rstrip("\n")
-        config_pca2 = config[2].replace("*", "x").rstrip("\n")
-        print ""
-        print "- START: "+file_name
-        print "Curve totali: ", nPlotTot
-        #print "Curve totali good: ", nPlotGood                                  # 4 TESTING!
-        print "- FILTRO 1: 0-500 e NaN"
-        print "Curve totali rimaste: ", len(self.plot_origCoord)
-        #print 'Curve good rimaste: ', len(Xsyn_1)                               # 4 TESTING!
-        print "- FILTRO 2: PCA:"+config_pca1+" e DENSITA:"+str(my_filter)
-        print "Curve totali rimaste: ", len(self.plot_FiltOrigCoord)
-        #print 'Curve good rimaste: ', len(Xsyn_2)                               # 4 TESTING!
-        print "Piu alta: ", tallest
-        #print "- FILTRO 3: 2'PCA:"+config_pca2
-        print ""
-        
-        # -- exporting coordinates and plot of PCA in debug mode! --
-        if config[3].find("true")!=-1:
-            #1' PCA: save plot and build coordinate s file
-            self.do_export(file_name.replace("coordinate_", "debug_pca1graph_").replace('.txt','_'+config_pca1) + " 0")
-            f = open(file_name.replace("coordinate_", "debug_pca1coor_").replace('.txt','_'+config_pca1+'.txt'),'w')
-            for i in range(len(pca_X)):
-                f.write (str(i) + "\t" + str(pca_X[i]) + "\t" + str(pca_Y[i]) + "\n")
-            f.close()
-            #2' PCA: save plot and build coordinate s file
-            #self.do_export(file_name.replace("coordinate_", "debug_pca2graph_").replace('.txt','_'+config_pca2) + " 1")
-            #f = open(file_name.replace("coordinate_", "debug_pca2coor_").replace('.txt','_'+config_pca2+'.txt'),'w')
-            #for i in range(len(pca_X2)):
-            #    f.write (str(i) + "\t" + str(pca_X2[i]) + "\t" + str(pca_Y2[i]) + "\n")
-            #f.close()
-            #DENSITY: save plot
-            self.do_export(file_name.replace("coordinate_", "debug_densitygraph_").replace('.txt','_'+config_pca1+'_'+str(my_filter).replace(".",",")) + " 1")
-            f = open(file_name.replace("coordinate_", "debug_densitycoor_").replace('.txt','_'+config_pca1+'_'+str(my_filter).replace(".",",")+'.txt'),'w')
-            for i in range(len(filtered_pca_X)):
-                f.write (str(i) + "\t" + str(filtered_pca_X[i]) + "\t" + str(filtered_pca_Y[i]) + "\n")
-            f.close()
-            #ALL GOOD COORDINATES (without NaN and 0<x<500)
-            f = open(file_name.replace("coordinate_", "debug_allgoodcoor_"),'w')
-            for i in range(len(self.plot_myCoord)):
-                for cel in self.plot_myCoord[i]:
-                    f.write (" ; " + str(cel))
-                f.write ("\n")
-            f.close()
-        
-        # pCLUSTER SAVING!!!
-        import shutil
-        pcl_name = file_name.replace("coordinate_", "goodplots_").replace('.txt','_'+config_pca1+'_'+str(my_filter).replace(".",","))
-        if os.path.exists(pcl_name+slash): shutil.rmtree(pcl_name)
-        os.mkdir(pcl_name+slash)
-        f = open(pcl_name+'.txt','w')
-        for i in range(len(self.plot_FiltPaths)):
-            myfile = str(self.plot_FiltPaths[i]).rstrip("\n")
-            f.write (myfile+"\n")
-            shutil.copy2(myfile, pcl_name)
-        f.close()
-        
-        
-    def do_multipca(self,args):
-        '''
-        MULTIPCA -> "multipca gaeta_coor_blind50.txt 3"
-        Automatically multiply the column suggest in second argument for value between 1-100 (step of 2), 
-        measures pca from coordinates filename and save the png plots.
-        (c)Paolo Pancaldi, Massimo Sandal 2009
-        '''
-        # reads the columns of pca
-        conf=open("pca_config.txt")
-        config = conf.readlines() # config[0] = "1,2,3"
-        conf.close()
-        # cycling pca
-        arg = args.split(" ")
-        file_name=arg[0]
-        column=str(arg[1])
-        for i in range(1, 51, 1):
-            self.do_pca(file_name + " " + config[0].replace(column,column+"*"+str(i),1))
-
-    def do_doublepca(self,args):
-        '''
-        DOUBLEPCA -> "doublepca gaeta_coor_blind50.txt"
-        Automatically it launches the pca command for all combinations with two column
-        (c)Paolo Pancaldi, Massimo Sandal 2009
-        '''
-        # cycling pca
-        arg = args.split(" ")
-        file_name=arg[0]
-        for i in range(1, 13):
-            for j in range(1, 13):
-                if i!=j:
-                    self.do_pca(file_name + " " + str(i) + "," + str(j))
-                    
-    def do_triplepca(self,args):
-        '''
-        TRIPLEPCA -> "triplepca gaeta_coor_blind50.txt"
-        Automatically it launches the pca command for all combinations with three column
-        (c)Paolo Pancaldi, Massimo Sandal 2009
-        '''
-        # cycling pca
-        arg = args.split(" ")
-        file_name=arg[0]
-        for i in range(1, 13):
-            for j in range(1, 13):
-                for k in range(1, 13):
-                    if i!=j and i!=k and j!=k:
-                        self.do_pca(file_name + " " + str(i) + "," + str(j) + "," + str(k))
-
-    def do_pclick(self,args):
-        '''
-        It returns id, coordinates and file name of a clicked dot on a PCA graphic
-        '''
-        
-        self._send_plot([self.clustplot1]) #quick workaround for BAD problems in the GUI
-        print 'Click point'
-        point = self._measure_N_points(N=1, whatset=0)
-        indice = point[0].index
-        plot_file = self.plot_paths[indice]
-        dot_coord = self.plot_pcaCoord[indice]
-        print "file: " + str(plot_file).rstrip()
-        print "id: " + str(indice)
-        print "coord: " + str(dot_coord)
-        self.do_genlist(str(plot_file))
-        #self.do_jump(str(plot_file))
-        
-    # indea iniziata e messa da parte...
-    def do_peakforce(self, args):
-        '''
-        peackforce -> "peackforce peackforce_file.txt"
-        Automatically measures peack and force plots
-        (c)Paolo Pancaldi, Massimo Sandal 2009
-        '''
-        
-        # prende in inpunt un arg (nome del file)
-        file_name=args
-        f=open(file_name)
-        
-        # scrivo un file temp
-        g = open('_prove.txt','w')
-        
-        plot_file = '';
-        rows = f.readlines()
-        for row in rows:
-            if row[0]=="/":
-                plot_file = row
-            if row[0]==" " and row.find('nan')==-1 and row.find("-1.#IND")==-1:
-                # FILTRO SUI 7 PICCHI
-                num_pic = int(row.split(" ; ")[1])
-                if num_pic==7:
-                    width_force = row.split(" ; ")
-                    w1 = float(width_force[2]); f1 = float(width_force[3]);
-                    w2 = float(width_force[4]); f2 = float(width_force[5]);
-                    w3 = float(width_force[6]); f3 = float(width_force[7]);
-                    w4 = float(width_force[8]); f4 = float(width_force[9]);
-                    w5 = float(width_force[10]); f5 = float(width_force[11]);
-                    w6 = float(width_force[12]); f6 = float(width_force[13]);
-                    w7 = float(width_force[14]); f7 = float(width_force[15]);
-                    if w1>0 and w1<1000 and w2>0 and w2<1000 and w3>0 and w3<1000 and w4>0 and w4<1000 and w5>0 and w5<1000 and w6>0 and w6<1000 and w7>0 and w7<1000:
-                        score_76 = abs(32 - (w7 - w6))
-                        score_65 = abs(32 - (w6 - w5))
-                        score_54 = abs(32 - (w5 - w4))
-                        score_43 = abs(32 - (w4 - w3))
-                        score_32 = abs(32 - (w3 - w2))
-                        score_21 = abs(32 - (w2 - w1))
-                        writeme = str(score_76) + " --- " + str(row)
-                        g.write(writeme)
-        g.close()
-        f.close()
-        
-        
\ No newline at end of file
diff --git a/picoforcealt.py b/picoforcealt.py
deleted file mode 100644 (file)
index 078430b..0000000
+++ /dev/null
@@ -1,278 +0,0 @@
-#!/usr/bin/env python
-
-'''
-libpicoforce.py
-
-Library for interpreting Picoforce force spectroscopy files. Alternate version
-
-Copyright (C) 2006 Massimo Sandal (University of Bologna, Italy).
-Copyright (C) 2008 Alberto Gomez-Casado (University of Twente, Netherlands).
-
-This program is released under the GNU General Public License version 2.
-'''
-
-import re, struct
-from scipy import arange
-
-import libhookecurve as lhc
-
-__version__='0.0.0.20081706'
-
-
-
-class DataChunk(list):
-    #Dummy class to provide ext and ret methods to the data list.
-    
-    def ext(self):
-        halflen=(len(self)/2)
-        return self[0:halflen]
-        
-    def ret(self):
-        halflen=(len(self)/2)
-        return self[halflen:]
-
-class picoforcealtDriver(lhc.Driver):
-
-    #Construction and other special methods
-    
-    def __init__(self,filename):
-        '''
-        constructor method
-        '''
-        
-        self.textfile=file(filename)
-        self.binfile=file(filename,'rb')
-        
-        #The 0,1,2 data chunks are:
-        #0: D (vs T)
-        #1: Z (vs T)
-        #2: D (vs Z)
-        
-        self.forcechunk=0
-        self.distancechunk=1
-       #TODO eliminate the need to set chunk numbers
-        
-        self.filepath=filename
-        self.debug=True
-        
-        self.filetype='picoforce'
-        self.experiment='smfs'
-    
-    
-            
-    def _get_samples_line(self):
-        '''
-        Gets the samples per line parameters in the file, to understand trigger behaviour.
-        '''
-        self.textfile.seek(0)
-        
-        samps_expr=re.compile(".*Samps")
-        
-        samps_values=[]
-        for line in self.textfile.readlines():
-            if samps_expr.match(line):
-                try:
-                    samps=int(line.split()[2]) #the third word splitted is the offset (in bytes)
-                    samps_values.append(samps)
-                except:
-                    pass
-                
-                #We raise a flag for the fact we meet an offset, otherwise we would take spurious data length arguments.
-                        
-        return int(samps_values[0])
-                    
-    def _get_chunk_coordinates(self):
-        '''
-        This method gets the coordinates (offset and length) of a data chunk in our
-        Picoforce file.
-        
-        It returns a list containing two tuples: 
-        the first element of each tuple is the data_offset, the second is the corresponding 
-        data size.
-        
-        In near future probably each chunk will get its own data structure, with 
-        offset, size, type, etc.
-        '''
-        self.textfile.seek(0)
-        
-        offset_expr=re.compile(".*Data offset")
-        length_expr=re.compile(".*Data length")
-
-        data_offsets=[]
-        data_sizes=[]
-        flag_offset=0
-
-        for line in self.textfile.readlines():
-
-            if offset_expr.match(line):
-                offset=int(line.split()[2]) #the third word splitted is the offset (in bytes)
-                data_offsets.append(offset)
-                #We raise a flag for the fact we meet an offset, otherwise we would take spurious data length arguments.
-                flag_offset=1 
-    
-            #same for the data length
-            if length_expr.match(line) and flag_offset: 
-                size=int(line.split()[2])
-                data_sizes.append(size)
-                #Put down the offset flag until the next offset is met.
-                flag_offset=0
-
-        return zip(data_offsets,data_sizes)
-        
-    def _get_data_chunk(self,whichchunk):
-        '''
-        reads a data chunk and converts it in 16bit signed int.
-        '''
-        offset,size=self._get_chunk_coordinates()[whichchunk]
-        
-        
-        self.binfile.seek(offset)
-        raw_chunk=self.binfile.read(size)
-        
-        my_chunk=[]
-        for data_position in range(0,len(raw_chunk),2):
-            data_unit_bytes=raw_chunk[data_position:data_position+2]
-            #The unpack function converts 2-bytes in a signed int ('h').
-            #we use output[0] because unpack returns a 1-value tuple, and we want the number only
-            data_unit=struct.unpack('h',data_unit_bytes)[0]
-            my_chunk.append(data_unit)                             
-        
-        return DataChunk(my_chunk)
-
-    def _force(self):
-       #returns force vector
-        Kspring=self.get_spring_constant()
-        return DataChunk([(meter*Kspring) for meter in self._deflection()])
-
-    def _deflection(self):
-        #for internal use (feeds _force)
-        voltrange=1
-        z_scale=self._get_Z_scale()
-        deflsensitivity=self.get_deflection_sensitivity()
-        volts=[((float(lsb))*voltrange*z_scale) for lsb in self.data_chunks[self.forcechunk]]    
-        deflect=[volt*deflsensitivity for volt in volts]
-            
-        return deflect
-             
-    
-    def _Z(self):
-        #returns distance vector (calculated instead than from data chunk)        
-        rampsize=self._get_rampsize()
-        sampsline=self._get_samples_line()
-        senszscan=self._get_Z_scan_sens()
-             
-        xstep=senszscan*rampsize/sampsline*10**(-9)
-
-        xext=arange(sampsline*xstep,0,-xstep)
-        xret=arange(sampsline*xstep,0,-xstep)
-         
-        return DataChunk(xext.tolist()+xret.tolist())
-    
-    def _get_Z_scale(self):
-        self.textfile.seek(0)
-        expr=re.compile(".*@4:Z scale")
-        
-        for line in self.textfile.readlines():
-            if expr.match(line):
-                zscale=float((line.split()[5]).strip("() []"))
-                break
-        return zscale
-    
-    def _get_rampsize(self):
-        self.textfile.seek(0)
-        expr=re.compile(".*@4:Ramp size:")
-        
-        for line in self.textfile.readlines():
-            if expr.match(line):
-                zsens=float((line.split()[7]).strip("() []"))
-                break
-        return zsens
-        
-    def _get_Z_scan_sens(self):
-        self.textfile.seek(0)
-        expr=re.compile(".*@Sens. Zsens")
-        
-        for line in self.textfile.readlines():
-            if expr.match(line):
-                zsens=float((line.split()[3]).strip("() []"))
-                break
-        return zsens
-    
-    
-                
-    def get_deflection_sensitivity(self):
-        '''
-        gets deflection sensitivity
-        '''    
-        self.textfile.seek(0)
-        
-        def_sensitivity_expr=re.compile(".*@Sens. DeflSens")
-        
-        for line in self.textfile.readlines():
-            if def_sensitivity_expr.match(line):
-                def_sensitivity=float(line.split()[3])
-                break
-        #return it in SI units (that is: m/V, not nm/V)
-        return def_sensitivity*(10**(-9))
-        
-    def get_spring_constant(self):
-        '''
-        gets spring constant.
-        We actually find *three* spring constant values, one for each data chunk (F/t, Z/t, F/z).
-        They are normally all equal, but we retain all three for future...
-        '''
-        self.textfile.seek(0)
-        
-        springconstant_expr=re.compile(".*Spring Constant")
-        
-        constants=[]
-        
-        for line in self.textfile.readlines():
-            if springconstant_expr.match(line):
-                constants.append(float(line.split()[2]))
-        
-        return constants[0]
-    
-    def is_me(self):
-        '''
-        self-identification of file type magic
-        '''
-        curve_file=file(self.filepath)
-        header=curve_file.read(30)
-        curve_file.close()
-        
-        if header[2:17] == 'Force file list': #header of a picoforce file
-            #here DONT translate chunk
-            self.data_chunks=[self._get_data_chunk(num) for num in [0,1,2]]
-            return True
-        else:
-            return False
-    
-    def close_all(self):
-        '''
-        Explicitly closes all files
-        '''
-        self.textfile.close()
-        self.binfile.close()
-    
-    def default_plots(self):
-        '''
-        creates the default PlotObject
-        '''
-        force=self._force()
-        zdomain=self._Z()
-        samples=self._get_samples_line()
-        main_plot=lhc.PlotObject()
-        main_plot.vectors=[[zdomain.ext()[0:samples], force.ext()[0:samples]],[zdomain.ret()[0:samples], force.ret()[0:samples]]]
-        main_plot.normalize_vectors()
-        main_plot.units=['meters','newton']
-        main_plot.destination=0
-        main_plot.title=self.filepath
-        
-        
-        return [main_plot]
-
-    def deflection(self):
-        #interface for correct plotmanip and others
-        deflectionchunk=DataChunk(self._deflection())
-        return deflectionchunk.ext(),deflectionchunk.ret()
diff --git a/playlists/test.hkp b/playlists/test.hkp
new file mode 100644 (file)
index 0000000..22c7799
--- /dev/null
@@ -0,0 +1,5 @@
+<?xml version="1.0" encoding="utf-8"?>\r
+<playlist>\r
+  <generics pointer="0" />\r
+  <element notes="" path="data/default.000" />\r
+</playlist>
\ No newline at end of file
diff --git a/plugins/__init__.py b/plugins/__init__.py
new file mode 100644 (file)
index 0000000..803f29c
--- /dev/null
@@ -0,0 +1 @@
+#!/usr/bin/env python\r
diff --git a/plugins/autopeak.ini b/plugins/autopeak.ini
new file mode 100644 (file)
index 0000000..d2c5b23
--- /dev/null
@@ -0,0 +1,119 @@
+[autopeak]\r
+    [[auto_fit_nm]]\r
+        default = 5\r
+        minimum = 0\r
+        type = float\r
+        value = 5\r
+    \r
+    [[auto_fit_points]]\r
+        default = 50\r
+        minimum = 0\r
+        type = integer\r
+        value = 50\r
+    \r
+    [[auto_left_baseline]]\r
+        default = 20\r
+        minimum = 0\r
+        type = float\r
+        value = 20\r
+    \r
+    [[auto_max_p]]\r
+        default = 10\r
+        minimum = 0\r
+        type = float\r
+        value = 10\r
+    \r
+    [[auto_min_p]]\r
+        default = 0.005\r
+        minimum = 0\r
+        type = float\r
+        value = 0.005\r
+    \r
+    [[auto_right_baseline]]\r
+        default = 20\r
+        minimum = 0\r
+        type = float\r
+        value = 20\r
+    \r
+    [[auto_slope_span]]\r
+        default = 20\r
+        minimum = 0\r
+        type = integer\r
+        value = 20\r
+    \r
+    [[baseline_clicks]]\r
+        default = automatic\r
+        elements = contact point, automatic, 1 point, 2 points\r
+        type = enum\r
+        value = contact point\r
+    \r
+    [[fit_function]]\r
+        default = wlc\r
+        elements = wlc, fjc, fjcPEG\r
+        type = enum\r
+        value = wlc\r
+    \r
+    [[noauto]]\r
+        default = False\r
+        type = boolean\r
+        value = False\r
+    \r
+    [[noflatten]]\r
+        default = False\r
+        type = boolean\r
+        value = False\r
+    \r
+    [[peak_color]]\r
+        default = black\r
+        type = color\r
+        value = "(255,128,0)"\r
+    \r
+    [[peak_show]]\r
+        default = False\r
+        type = boolean\r
+        value = False\r
+    \r
+    [[peak_size]]\r
+        default = 20\r
+        maximum = 10000\r
+        minimum = 1\r
+        type = integer\r
+        value = 50\r
+    \r
+    [[persistence_length]]\r
+        default = 0.35e-9\r
+        minimum = 0\r
+        type = float\r
+        value = 0.175\r
+    \r
+    [[rebase]]\r
+        default = False\r
+        type = boolean\r
+        value = False\r
+    \r
+    [[reclick]]\r
+        default = False\r
+        type = boolean\r
+        value = False\r
+    \r
+    [[temperature]]\r
+        default = 293\r
+        minimum = 0\r
+        type = float\r
+        value = 293\r
+    \r
+    [[usepl]]\r
+        default = False\r
+        type = boolean\r
+        value = False\r
+    \r
+    [[usepoints]]\r
+        default = False\r
+        type = boolean\r
+        value = False\r
+    \r
+    [[whatset]]\r
+        default = retraction\r
+        elements = extension, retraction\r
+        type = enum\r
+        value = retraction\r
diff --git a/plugins/autopeak.py b/plugins/autopeak.py
new file mode 100644 (file)
index 0000000..6e6d5a2
--- /dev/null
@@ -0,0 +1,358 @@
+#!/usr/bin/env python
+
+'''
+autopeak.py
+
+Automatic peak detection and analysis.
+
+Copyright ???? by ?
+with modifications by Dr. Rolf Schmidt (Concordia University, Canada)
+
+This program is released under the GNU General Public License version 2.
+'''
+
+import lib.libhooke as lh
+import wxversion
+wxversion.select(lh.WX_GOOD)
+
+import copy
+from numpy import mean, RankWarning
+
+import warnings
+warnings.simplefilter('ignore', RankWarning)
+
+#import config
+import lib.plugin
+import lib.results
+
+class autopeakCommands:
+    '''
+    Autopeak carries out force curve fitting with a chosen model:
+        - WLC
+        - FJC
+        - FJC-PEG
+    '''
+
+    def do_autopeak(self, plot=None):
+        '''
+        AUTOPEAK
+        (autopeak.py)
+        Automatically performs a number of analyses on the peaks of the given curve.
+        Currently it automatically:
+        - fits peaks with WLC or FJC function (depending on how the fit_function variable is set)
+        - measures peak maximum forces with a baseline
+        - measures slope in proximity of peak maximum
+        Requires flatten plotmanipulator , fit.py plugin , flatfilts.py plugin with convfilt
+
+        Syntax:
+        autopeak [rebase] [persistence_length=value] [t=value] [noauto] [reclick]
+
+        rebase : Re-asks baseline interval
+
+        persistence_length=[value] : Use a fixed persistent length for the fit. If persistence_length is not given,
+                     the fit will be a 2-variable
+                     fit. DO NOT put spaces between 'persistence_length', '=' and the value.
+                     The value must be in nanometers.
+                     Scientific notation like 0.35 is fine.
+
+        t=[value] : Use a user-defined temperature. The value must be in
+                    kelvins; by default it is 293 K.
+                    DO NOT put spaces between 't', '=' and the value.
+
+        noauto : allows for clicking the contact point by
+                 hand (otherwise it is automatically estimated) the first time.
+                 If subsequent measurements are made, the same contact point
+                 clicked the first time is used
+
+        reclick : redefines by hand the contact point, if noauto has been used before
+                  but the user is unsatisfied of the previously choosen contact point.
+
+        usepoints : fit interval by number of points instead than by nanometers
+
+        noflatten : does not use the "flatten" plot manipulator
+
+        When you first issue the command, it will ask for the filename. If you are giving the filename
+        of an existing file, autopeak will resume it and append measurements to it. If you are giving
+        a new filename, it will create the file and append to it until you close Hooke.
+
+
+        Useful variables (to set with SET command):
+        ---
+        fit_function = type of function to use for elasticity. If "wlc" worm-like chain is used, if "fjc" freely jointed
+                       chain is used
+
+        temperature= temperature of the system for wlc/fjc fit (in K)
+
+        auto_slope_span = number of points on which measure the slope, for slope
+
+        auto_fit_nm = number of nm to fit before the peak maximum, for WLC/FJC (if usepoints false)
+        auto_fit_points = number of points to fit before the peak maximum, for WLC/FJC (if usepoints true)
+
+        baseline_clicks = contact point: no baseline, f=0 at the contact point (whether hand-picked or automatically found)
+                          automatic:     automatic baseline
+                          1 point:       decide baseline with a single click and length defined in auto_left_baseline
+                          2 points:      let user click points of baseline
+        auto_left_baseline = length in nm to use as baseline from the right point (if baseline_clicks = automatic , 1 point)
+        auto_right_baseline = distance in nm of peak-most baseline point from last peak (if baseline_clicks = automatic)
+
+        auto_min_p ; auto_max_p = Minimum and maximum persistence length (if using WLC) or Kuhn length (if using FJC)
+                                  outside of which the peak is automatically discarded (in nm)
+        '''
+
+        #default fit etc. variables
+        auto_fit_nm = self.GetFloatFromConfig('autopeak', 'auto_fit_nm')
+        auto_left_baseline = self.GetFloatFromConfig('autopeak', 'auto_left_baseline')
+        auto_max_p = self.GetFloatFromConfig('autopeak', 'auto_max_p')
+        auto_min_p = self.GetFloatFromConfig('autopeak', 'auto_min_p')
+        auto_right_baseline = self.GetFloatFromConfig('autopeak', 'auto_right_baseline')
+        baseline_clicks = self.GetStringFromConfig('autopeak', 'baseline_clicks')
+        fit_function = self.GetStringFromConfig('autopeak', 'fit_function')
+        fit_points = self.GetIntFromConfig('autopeak', 'auto_fit_points')
+        noauto = self.GetBoolFromConfig('autopeak', 'noauto')
+        #noflatten: if true we do not flatten the curve
+        noflatten = self.GetBoolFromConfig('autopeak', 'noflatten')
+        peak_show = self.GetBoolFromConfig('autopeak', 'peak_show')
+        persistence_length = self.GetFloatFromConfig('autopeak', 'persistence_length')
+        #rebase: redefine the baseline
+        rebase = self.GetBoolFromConfig('autopeak', 'rebase')
+        reclick = self.GetBoolFromConfig('autopeak', 'reclick')
+        slope_span = self.GetIntFromConfig('autopeak', 'auto_slope_span')
+        T = self.GetFloatFromConfig('autopeak', 'temperature')
+        usepl = self.GetBoolFromConfig('autopeak', 'usepl')
+        if not usepl:
+            pl_value = None
+        else:
+            pl_value = persistence_length / 10**9
+        usepoints = self.GetBoolFromConfig('autopeak', 'usepoints')
+        whatset_str = self.GetStringFromConfig('autopeak', 'whatset')
+        if whatset_str == 'extension':
+            whatset = lh.EXTENSION
+        if whatset_str == 'retraction':
+            whatset = lh.RETRACTION
+
+        #TODO: should this be variable?
+        delta_force = 10
+
+        #setup header column labels for results
+        if fit_function == 'wlc':
+            fit_results = lib.results.ResultsWLC()
+            segment_str = 'Persistence length'
+            sigma_segment_str = 'sigma persistence length'
+        elif fit_function == 'fjc' or fit_function == 'fjcPEG':
+            fit_results = lib.results.ResultsFJC()
+            segment_str = 'Kuhn length'
+            sigma_segment_str = 'sigma Kuhn length'
+        else:
+            self.AppendToOutput('Unknown fit function, Please set fit_function as wlc, fjc or fjcPEG')
+            return
+
+        #initialize output data vectors
+        c_lengths = []
+        p_lengths = []
+        sigma_c_lengths = []
+        sigma_p_lengths = []
+        forces = []
+        slopes = []
+
+        #pick up plot
+        if plot is None:
+            plot = copy.deepcopy(self.GetActivePlot())
+        filename = self.GetActiveFile().name
+
+        #apply all active plotmanipulators and add the 'manipulated' data
+        for plotmanipulator in self.plotmanipulators:
+            if self.GetBoolFromConfig('core', 'plotmanipulators', plotmanipulator.name):
+                if plotmanipulator.name == 'flatten':
+                    if not noflatten:
+                        plot = plotmanipulator.method(plot, self.GetActiveFile())
+                else:
+                    plot = plotmanipulator.method(plot, self.GetActiveFile())
+
+        #--Using points instead of nm interval
+        if not usepoints:
+            fit_points = None
+
+        #--Contact point arguments
+        if reclick:
+            contact_point, contact_point_index = self.pickup_contact_point(filename=filename)
+        elif noauto:
+            if self.wlccontact_index is None or self.wlccurrent != filename:
+                contact_point, contact_point_index = self.pickup_contact_point(filename=filename)
+            else:
+                contact_point = self.wlccontact_point
+                contact_point_index = self.wlccontact_index
+        else:
+            #Automatically find contact point
+            cindex = self.find_contact_point(plot)
+            contact_point = self._clickize(plot.curves[lh.RETRACTION].x, plot.curves[lh.EXTENSION].y, cindex)
+
+        #peak_size comes from convolution curve
+        peak_location, peak_size = self.find_current_peaks(plot=plot, noflatten=noflatten)
+
+        if len(peak_location) == 0:
+            self.AppendToOutput('No peaks to fit.')
+            return
+
+        #Pick up force baseline
+        if baseline_clicks == 'contact point':
+            try:
+                avg = plot.curves[lh.RETRACTION].y[contact_point_index]
+            except:
+                avg = plot.curves[lh.RETRACTION].y[cindex]
+
+        if rebase or (self.basecurrent != filename) or self.basepoints is None:
+            if baseline_clicks == 'automatic':
+                self.basepoints = []
+                base_index_0 = peak_location[-1] + self.fit_interval_nm(peak_location[-1], plot.curves[lh.RETRACTION].x, auto_right_baseline, False)
+                self.basepoints.append(self._clickize(plot.curves[lh.RETRACTION].x, plot.curves[lh.RETRACTION].y, base_index_0))
+                base_index_1 = self.basepoints[0].index + self.fit_interval_nm(self.basepoints[0].index, plot.curves[lh.RETRACTION].x, auto_left_baseline, False)
+                self.basepoints.append(self._clickize(plot.curves[lh.RETRACTION].x, plot.curves[lh.RETRACTION].y, base_index_1))
+            if baseline_clicks == '1 point':
+                self.basepoints=self._measure_N_points(N=1, message='Click on 1 point to select the baseline.', whatset=whatset)
+                base_index_1 = self.basepoints[0].index + self.fit_interval_nm(self.basepoints[0].index, plot.curves[lh.RETRACTION].x, auto_left_baseline, False)
+                self.basepoints.append(self._clickize(plot.curves[lh.RETRACTION].x, plot.curves[lh.RETRACTION].y, base_index_1))
+            if baseline_clicks == '2 points':
+                self.basepoints=self._measure_N_points(N=2, message='Click on 2 points to select the baseline.', whatset=whatset)
+        if baseline_clicks != 'contact point':
+            boundaries=[self.basepoints[0].index, self.basepoints[1].index]
+            boundaries.sort()
+            to_average = plot.curves[lh.RETRACTION].y[boundaries[0]:boundaries[1]] #y points to average
+            avg = mean(to_average)
+            self.basecurrent = filename
+
+        x_values = plot.curves[lh.RETRACTION].x
+        y_values = plot.curves[lh.RETRACTION].y
+        for index, peak in enumerate(peak_location):
+            #WLC FITTING
+            #define fit interval
+            if not usepoints:
+                fit_points = self.fit_interval_nm(peak, plot.curves[lh.RETRACTION].x, auto_fit_nm, True)
+            peak_point = self._clickize(x_values, y_values, peak)
+            other_fit_point=self._clickize(x_values, y_values, peak - fit_points)
+
+            #points for the fit
+            points = [contact_point, peak_point, other_fit_point]
+
+            if abs(peak_point.index - other_fit_point.index) < 2:
+                continue
+
+            if fit_function == 'wlc':
+                params, yfit, xfit, fit_errors = self.wlc_fit(points, x_values, y_values, pl_value, T, return_errors=True)
+            elif fit_function == 'fjc':
+                params, yfit, xfit, fit_errors = self.fjc_fit(points, x_values, y_values, pl_value, T, return_errors=True)
+            elif fit_function == 'fjcPEG':
+                params, yfit, xfit, fit_errors = self.fjcPEG_fit(points, x_values, y_values, pl_value, T, return_errors=True)
+
+            #Measure forces
+            delta_to_measure = y_values[peak - delta_force:peak + delta_force]
+            y = min(delta_to_measure)
+            #save force values (pN)
+            #Measure slopes
+            slope = self.linefit_between(peak - slope_span, peak, whatset=lh.RETRACTION)[0]
+
+            #check fitted data and, if right, add peak to the measurement
+            fit_result = lib.results.Result()
+
+            fit_result.result['Contour length'] = params[0]
+            fit_result.result['sigma contour length'] = fit_errors[0]
+            fit_result.result['Rupture force'] = abs(y - avg)
+            fit_result.result['Slope'] = slope
+            active_file = self.GetActiveFile()
+            if active_file.driver.retract_velocity:
+                fit_result.result['Loading rate'] = slope * active_file.driver.retract_velocity
+            else:
+                fit_result.result['Loading rate'] = -1
+            if len(params) == 1: #if we did choose 1-value fit
+                fit_result.result[segment_str] = pl_value
+                fit_result.result[sigma_segment_str] = 0
+
+                p_lengths.append(pl_value)
+                c_lengths.append(params[0]*(1.0e+9))
+                sigma_p_lengths.append(0)
+                sigma_c_lengths.append(fit_errors[0]*(1.0e+9))
+                forces.append(abs(y-avg)*(1.0e+12))
+                slopes.append(slope)
+            else: #2-value fit
+                p_leng = params[1] * (1.0e+9)
+                #check if persistence length makes sense, otherwise discard peak.
+                if p_leng > auto_min_p and p_leng < auto_max_p:
+                    fit_result.result[segment_str] = params[1]
+                    fit_result.result[sigma_segment_str] = fit_errors[1]
+
+                    p_lengths.append(p_leng)
+                    c_lengths.append(params[0]*(1.0e+9))
+                    sigma_c_lengths.append(fit_errors[0]*(1.0e+9))
+                    sigma_p_lengths.append(fit_errors[1]*(1.0e+9))
+                    forces.append(abs(y-avg)*(1.0e+12))
+                    slopes.append(slope)
+                else:
+                    fit_result.result = {}
+
+            if len(fit_result.result) > 0:
+                fit_result.label = fit_function + '_' + str(index)
+                fit_result.title = plot.curves[lh.RETRACTION].title
+                fit_result.units.x = plot.curves[lh.RETRACTION].units.x
+                fit_result.units.y = plot.curves[lh.RETRACTION].units.y
+                fit_result.visible = True
+                fit_result.x = xfit
+                fit_result.y = yfit
+                fit_results.results.append(fit_result)
+
+        if fit_results.results:
+            fit_results.set_multipliers(0)
+            plot = self.GetActivePlot()
+            plot.results[fit_function] = fit_results
+            if peak_show:
+                plugin = lib.plugin.Plugin()
+                plugin.name = 'autopeak'
+                plugin.section = 'autopeak'
+                plugin.prefix = 'peak_'
+                self.do_peaks(plugin=plugin, peak_location=peak_location, peak_size=peak_size)
+            else:
+                self.UpdatePlot()
+
+        else:
+            self.AppendToOutput('No peaks found.')
+
+        #TODO:
+        #self.do_note('autopeak')
+
+    def find_current_peaks(self, plot=None, noflatten=True):
+        if not noflatten:
+            plot_temp = self.plotmanip_flatten(plot, self.GetActiveFile(), customvalue=1)
+        peak_location, peak_size = self.has_peaks(plot_temp)
+        return peak_location, peak_size
+
+    def fit_interval_nm(self, start_index, x_vect, nm, backwards):
+        '''
+        Calculates the number of points to fit, given a fit interval in nm
+        start_index: index of point
+        plot: plot to use
+        backwards: if true, finds a point backwards.
+        '''
+
+        c = 0
+        i = start_index
+        maxlen=len(x_vect)
+        while abs(x_vect[i] - x_vect[start_index]) * (10**9) < nm:
+            if i == 0 or i == maxlen-1: #we reached boundaries of vector!
+                return c
+            if backwards:
+                i -= 1
+            else:
+                i += 1
+            c += 1
+        return c
+
+    def pickup_contact_point(self, filename=''):
+        '''
+        macro to pick up the contact point by clicking
+        '''
+        contact_point = self._measure_N_points(N=1, message='Please click on the contact point.')[0]
+        contact_point_index = contact_point.index
+        self.wlccontact_point = contact_point
+        self.wlccontact_index = contact_point.index
+        self.wlccurrent = filename
+        return contact_point, contact_point_index
+
+
diff --git a/plugins/core.ini b/plugins/core.ini
new file mode 100644 (file)
index 0000000..ac026ec
--- /dev/null
@@ -0,0 +1,52 @@
+[plotmanipulators]\r
+    [[order]]\r
+        default = '"correct", "median", "absvalue", "flatten", "multiplier", "clamp", "threshold", "coincident", "showconvoluted"'\r
+        elements = correct, median, absvalue, flatten, multiplier, clamp, threshold, coincident, showconvoluted\r
+        #elements = correct, median, absvalue, flatten, multiplier, clamp, threshold, coincident, showconvoluted\r
+        type = arraystring\r
+        value = '"correct" "median" "absvalue" "flatten" "multiplier" "clamp" "threshold" "coincident" "showconvoluted"'\r
+    \r
+    [[absvalue]]\r
+        default = False\r
+        type = boolean\r
+        value = False\r
+    \r
+    [[clamp]]\r
+        default = False\r
+        type = boolean\r
+        value = False\r
+    \r
+    [[coincident]]\r
+        default = False\r
+        type = boolean\r
+        value = False\r
+    \r
+    [[correct]]\r
+        default = False\r
+        type = boolean\r
+        value = True\r
+    \r
+    [[flatten]]\r
+        default = False\r
+        type = boolean\r
+        value = True\r
+    \r
+    [[median]]\r
+        default = False\r
+        type = boolean\r
+        value = False\r
+    \r
+    [[multiplier]]\r
+        default = False\r
+        type = boolean\r
+        value = False\r
+    \r
+    [[showconvoluted]]\r
+        default = False\r
+        type = boolean\r
+        value = False\r
+    \r
+    [[threshold]]\r
+        default = False\r
+        type = boolean\r
+        value = False\r
diff --git a/plugins/export.ini b/plugins/export.ini
new file mode 100644 (file)
index 0000000..da8db68
--- /dev/null
@@ -0,0 +1,60 @@
+[fits]\r
+    [[ext]]\r
+        default = txt\r
+        type = string\r
+        value = csv\r
+    \r
+    [[folder]]\r
+        default = ""\r
+        type = folder\r
+        value = R:\Programming\Python\Gui\data\export\r
+    \r
+    [[prefix]]\r
+        default = ""\r
+        type = string\r
+        value = "_fit "\r
+    \r
+    [[separator]]\r
+        default = ","\r
+        type = string\r
+        value = ", "\r
+\r
+[force_curve]\r
+    [[ext]]\r
+        default = txt\r
+        type = string\r
+        value = txt\r
+    \r
+    [[folder]]\r
+        default = ""\r
+        type = folder\r
+        value = R:\Programming\Python\Gui\data\export\r
+    \r
+    [[prefix]]\r
+        default = ""\r
+        type = string\r
+        value = _\r
+    \r
+    [[separator]]\r
+        default = ","\r
+        type = string\r
+        value = ", "\r
+\r
+[overlay]\r
+    [[prefix]]\r
+        default = origin\r
+        type = string\r
+        value = _\r
+\r
+[results]\r
+    [[filename]]\r
+        default = fit export.txt\r
+        type = filename\r
+        value = R:\Programming\Python\Gui\data\export\fit export.txt\r
+    \r
+    [[separator]]\r
+        default = ","\r
+        type = string\r
+        value = ", "\r
+\r
+        \r
diff --git a/plugins/export.py b/plugins/export.py
new file mode 100644 (file)
index 0000000..a111c0d
--- /dev/null
@@ -0,0 +1,211 @@
+#!/usr/bin/env python
+
+'''
+export.py
+
+Export commands for Hooke.
+
+Copyright 2010 by Dr. Rolf Schmidt (Concordia University, Canada)
+
+This program is released under the GNU General Public License version 2.
+'''
+
+import lib.libhooke as lh
+import wxversion
+wxversion.select(lh.WX_GOOD)
+
+import copy
+import os.path
+import time
+import wx
+
+class exportCommands(object):
+    '''
+    Export force curves, fits and results in different formats
+    '''
+
+    def _plug_init(self):
+        pass
+
+    def do_fits(self):#, ext='', folder='', prefix='', separator=''):
+        '''
+        Exports all approach and retraction files in a playlist and
+        all fitting results (if available) in a columnar ASCII format.
+        Please make sure that the number of points in the fit is smaller
+        or equal to the number of points in the approach/retraction.
+        For the time being, exports only one set of results (e.g. WLC
+        or FJC, not both).
+        '''
+
+        ext = self.GetStringFromConfig('export', 'fits', 'ext')
+        folder = self.GetStringFromConfig('export', 'fits', 'folder')
+        prefix = self.GetStringFromConfig('export', 'fits', 'prefix')
+        separator = self.GetStringFromConfig('export', 'fits', 'separator')
+        #TODO: add list for Tab, Space, Comma, Other
+        #add string for Other
+
+        active_file = self.GetActiveFile()
+        plot = self.GetDisplayedPlot()
+
+        #TODO: fix for multiple results
+        #add empty columns before adding new results if necessary
+        if plot is not None:
+            for results_str, results in plot.results.items():
+                for curve in results.results:
+                    output = []
+                    header_str = ''
+                    if curve.visible:
+                        header_str += curve.label + '_x (' + curve.units.x + ')' + separator + curve.label + '_y (' + curve.units.y + ')'
+                        output.append(header_str)
+                        for index, row in enumerate(curve.x):
+                            output.append(separator.join([str(curve.x[index]), str(curve.y[index])]))
+                    if output:
+                        #TODO: add option to replace or add the new file extension
+                        #add option to rename file from default.000 to default_000
+                        filename = os.path.basename(active_file.filename)
+                        filename = ''.join([prefix, filename, '_', curve.label, '.', ext])
+                        filename = os.path.join(folder, filename)
+                        output_file = open(filename, 'w')
+                        output_file.write('\n'.join(output))
+                        output_file.close
+
+    def do_force_curve(self):
+        '''
+        TXT
+        Saves the current curve as a text file
+        Columns are, in order:
+        X1 , Y1 , X2 , Y2 , X3 , Y3 ...
+
+        -------------
+        Syntax: txt [filename] {plot to export}
+        '''
+
+        ext = self.GetStringFromConfig('export', 'force_curve', 'ext')
+        folder = self.GetStringFromConfig('export', 'force_curve', 'folder')
+        prefix = self.GetStringFromConfig('export', 'force_curve', 'prefix')
+        separator = self.GetStringFromConfig('export', 'force_curve', 'separator')
+        #TODO: add list for Tab, Space, Comma, Other
+        #add string for Other
+
+        active_file = self.GetActiveFile()
+        plot = self.GetActivePlot()
+        extension = plot.curves[lh.EXTENSION]
+        retraction = plot.curves[lh.RETRACTION]
+
+        output = []
+        header_str = ''
+        for index, curve in enumerate(plot.curves):
+            header_str += curve.label + '_x (' + curve.units.x + ')' + separator + curve.label + '_y (' + curve.units.y + ')'
+            if index < len(plot.curves) - 1:
+                header_str += separator
+        output.append(header_str)
+        #TODO: add units
+        for index, row in enumerate(extension.x):
+            output.append(separator.join([str(extension.x[index]), str(extension.y[index]), str(retraction.x[index]), str(retraction.y[index])]))
+
+        if output:
+            #TODO: add option to replace or add the new file extension
+            #add option to rename file from default.000 to default_000
+            filename = os.path.basename(active_file.filename)
+            filename = ''.join([prefix, filename, '.', ext])
+            filename = os.path.join(folder, filename)
+            output_file = open(filename, 'w')
+            output_file.write('\n'.join(output))
+            output_file.close
+
+    def do_overlay(self):
+        '''
+        Exports all retraction files in a playlist with the same scale.
+        The files can then be overlaid in a graphing program to see which
+        ones have the same shape.
+        Use this export command only on filtered lists as it takes a long time
+        to complete even with a small number of curves.
+        '''
+        playlist = self.GetActivePlaylist()
+
+        filename_prefix = self.GetStringFromConfig('export', 'overlay', 'prefix')
+
+        differences_x = []
+        differences_y = []
+        number_of_curves = playlist.count
+        message_str = ''.join([str(number_of_curves), ' files to load.\n\n'])
+        progress_dialog = wx.ProgressDialog('Loading', message_str, maximum=number_of_curves, parent=self, style=wx.PD_APP_MODAL|wx.PD_SMOOTH|wx.PD_AUTO_HIDE)
+        for index, current_file in enumerate(playlist.files):
+            current_file.identify(self.drivers)
+            plot = current_file.plot
+
+            plot.raw_curves = copy.deepcopy(plot.curves)
+            #apply all active plotmanipulators and add the 'manipulated' data
+            for plotmanipulator in self.plotmanipulators:
+                if self.GetBoolFromConfig('core', 'plotmanipulators', plotmanipulator.name):
+                    plot = plotmanipulator.method(plot, current_file)
+            #add corrected curves to plot
+            plot.corrected_curves = copy.deepcopy(plot.curves)
+
+            curve = current_file.plot.corrected_curves[lh.RETRACTION]
+            differences_x.append(curve.x[0] - curve.x[-1])
+            differences_y.append(curve.x[0] - curve.y[-1])
+            progress_dialog.Update(index, ''.join([message_str, 'Loading ', str(index + 1), '/', str(number_of_curves)]))
+        progress_dialog.Destroy()
+
+        max_x = max(differences_x)
+        max_y = max(differences_y)
+        message_str = ''.join([str(number_of_curves), ' files to export.\n\n'])
+        for index, current_file in enumerate(playlist.files):
+            curve = current_file.plot.corrected_curves[lh.RETRACTION]
+            first_x = curve.x[0]
+            first_y = curve.y[0]
+            new_x = [x - first_x for x in curve.x]
+            new_y = [y - first_y for y in curve.y]
+            new_x.append(-max_x)
+            new_y.append(-max_y)
+            output_str = ''
+            for row_index, row in enumerate(new_x):
+                output_str += ''.join([str(new_x[row_index]), ', ', str(new_y[row_index]), '\n'])
+
+            if output_str != '':
+                filename = ''.join([filename_prefix, current_file.name])
+                filename = current_file.filename.replace(current_file.name, filename)
+                output_file = open(filename, 'w')
+                output_file.write(output_str)
+                output_file.close
+        progress_dialog.Destroy()
+
+    def do_results(self, filename='', separator=''):
+        '''
+        EXPORTFITS
+        Exports all visible fit results in a playlist into a delimited text file
+        '''
+        if filename == '':
+            filename = self.GetStringFromConfig('export', 'results', 'filename')
+        if separator == '':
+            separator = self.GetStringFromConfig('export', 'results', 'separator')
+
+        playlist = self.GetActivePlaylist()
+        output_str = ''
+        header_str = ''
+        for current_file in playlist.files:
+            if len(current_file.plot.results) > 0:
+                for key in current_file.plot.results.keys():
+                    #if there are different types of fit results in the playlist, the header might have to change
+                    #here, we generate a temporary header and compare it to the current header
+                    #if they are different, the tempeorary header is used
+                    #we get the header from the fit and add the 'filename' column
+                    temporary_header_str = ''.join([current_file.plot.results[key].get_header_as_str(), separator, 'Filename'])
+                    if temporary_header_str != header_str:
+                        header_str = ''.join([current_file.plot.results[key].get_header_as_str(), separator, 'Filename'])
+                        output_str = ''.join([output_str, header_str, '\n'])
+                    for index, result in enumerate(current_file.plot.results[key].results):
+                        if result.visible:
+                            #similar to above, we get the result from the fit and add the filename
+                            line_str = current_file.plot.results[key].get_result_as_string(index)
+                            line_str = ''.join([line_str, separator, current_file.filename])
+                            output_str = ''.join([output_str, line_str, '\n'])
+        if output_str != '':
+            output_str = ''.join(['Analysis started ', time.asctime(), '\n', output_str])
+            output_file = open(filename, 'w')
+            output_file.write(output_str)
+            output_file.close
+        else:
+            dialog = wx.MessageDialog(None, 'No results found, file not saved.', 'Info', wx.OK)
+            dialog.ShowModal()
diff --git a/plugins/fit.ini b/plugins/fit.ini
new file mode 100644 (file)
index 0000000..34df5c1
--- /dev/null
@@ -0,0 +1,35 @@
+[fjc]\r
+    [[temperature]]\r
+        default = 293\r
+        minimum = 0\r
+        type = float\r
+        value = 293\r
+\r
+[fjcPEG]\r
+    [[delta_G]]\r
+        default = 3\r
+        minimum = 0\r
+        type = float\r
+        value = 3\r
+    [[L_helical]]\r
+        default = 0.28\r
+        minimum = 0\r
+        type = float\r
+        value = 0.28\r
+    [[L_planar]]\r
+        default = 0.358\r
+        minimum = 0\r
+        type = float\r
+        value = 0.358\r
+    [[temperature]]\r
+        default = 293\r
+        minimum = 0\r
+        type = float\r
+        value = 293\r
+\r
+[wlc]\r
+    [[temperature]]\r
+        default = 293\r
+        minimum = 0\r
+        type = float\r
+        value = 293\r
diff --git a/plugins/fit.py b/plugins/fit.py
new file mode 100644 (file)
index 0000000..87caa4c
--- /dev/null
@@ -0,0 +1,836 @@
+#!/usr/bin/env python
+
+'''
+fit.py
+
+Force spectroscopy curves basic fitting plugin.
+
+Plugin dependencies:
+procplots.py (plot processing plugin)
+
+Copyright ???? by ?
+with modifications by Dr. Rolf Schmidt (Concordia University, Canada)
+
+This program is released under the GNU General Public License version 2.
+'''
+
+import lib.libhooke as lh
+import wxversion
+wxversion.select(lh.WX_GOOD)
+
+import copy
+from math import exp
+import numpy as np
+import scipy.stats
+import scipy.odr
+
+from lib.libhooke import coth
+
+class fitCommands(object):
+
+    def _plug_init(self):
+        self.wlccurrent=None
+        self.wlccontact_point=None
+        self.wlccontact_index=None
+
+    def wlc_fit(self, clicked_points, xvector, yvector, pl_value, T=293, return_errors=False):
+        '''
+        Worm-like chain model fitting.
+        The function is the simple polynomial worm-like chain as proposed by C.Bustamante, J.F.Marko, E.D.Siggia
+        and S.Smith (Science. 1994 Sep 9;265(5178):1599-600.)
+        '''
+
+        '''
+        clicked_points[0] = contact point (calculated or hand-clicked)
+        clicked_points[1] and [2] are edges of chunk
+        '''
+
+        #STEP 1: Prepare the vectors to apply the fit.
+
+        if pl_value is not None:
+            pl_value=pl_value/(10**9)
+
+        #indexes of the selected chunk
+        first_index=min(clicked_points[1].index, clicked_points[2].index)
+        last_index=max(clicked_points[1].index, clicked_points[2].index)
+
+        #getting the chunk and reverting it
+        xchunk,ychunk=xvector[first_index:last_index],yvector[first_index:last_index]
+        xchunk.reverse()
+        ychunk.reverse()
+        #put contact point at zero and flip around the contact point (the fit wants a positive growth for extension and force)
+        xchunk_corr_up=[-(x-clicked_points[0].graph_coords[0]) for x in xchunk]
+        ychunk_corr_up=[-(y-clicked_points[0].graph_coords[1]) for y in ychunk]
+
+        #make them arrays
+        xchunk_corr_up=scipy.array(xchunk_corr_up)
+        ychunk_corr_up=scipy.array(ychunk_corr_up)
+
+        #STEP 2: actually do the fit
+
+        #Find furthest point of chunk and add it a bit; the fit must converge
+        #from an excess!
+        xchunk_high=max(xchunk_corr_up)
+        xchunk_high+=(xchunk_high/10)
+
+        #Here are the linearized start parameters for the WLC.
+        #[lambd=1/Lo , pii=1/P]
+
+        p0=[(1/xchunk_high),(1/(3.5e-10))]
+        p0_plfix=[(1/xchunk_high)]
+        '''
+        ODR STUFF
+        fixme: remove these comments after testing
+        '''
+
+        def f_wlc(params,x,T=T):
+            '''
+            wlc function for ODR fitting
+            '''
+            lambd,pii=params
+            Kb=(1.38065e-23)
+            therm=Kb*T
+            y=(therm*pii/4.0) * (((1-(x*lambd))**-2) - 1 + (4*x*lambd))
+            return y
+
+        def f_wlc_plfix(params,x,pl_value=pl_value,T=T):
+            '''
+            wlc function for ODR fitting
+            '''
+            lambd=params
+            pii=1/pl_value
+            Kb=(1.38065e-23)
+            therm=Kb*T
+            y=(therm*pii/4.0) * (((1-(x*lambd))**-2) - 1 + (4*x*lambd))
+            return y
+
+        #make the ODR fit
+        realdata=scipy.odr.RealData(xchunk_corr_up,ychunk_corr_up)
+
+        if pl_value:
+            model=scipy.odr.Model(f_wlc_plfix)
+            o = scipy.odr.ODR(realdata, model, p0_plfix)
+        else:
+            model=scipy.odr.Model(f_wlc)
+            o = scipy.odr.ODR(realdata, model, p0)
+
+        o.set_job(fit_type=2)
+        out=o.run()
+        fit_out=[(1/i) for i in out.beta]
+
+        #Calculate fit errors from output standard deviations.
+        #We must propagate the error because we fit the *inverse* parameters!
+        #The error = (error of the inverse)*(value**2)
+        fit_errors=[]
+        for sd,value in zip(out.sd_beta, fit_out):
+            err_real=sd*(value**2)
+            fit_errors.append(err_real)
+
+        def wlc_eval(x, params, pl_value, T):
+            '''
+            Evaluates the WLC function
+            '''
+            if not pl_value:
+                lambd, pii = params
+            else:
+                lambd = params
+
+            if pl_value:
+                pii=1/pl_value
+
+            Kb=(1.38065e-23) #Boltzmann constant
+            therm=Kb*T #so we have thermal energy
+
+            return ((therm*pii / 4.0) * (((1 - (x*lambd))**-2.0) - 1 + (4.0*x*lambd)) )
+
+        #STEP 3: plotting the fit
+
+        #obtain domain to plot the fit - from contact point to last_index plus 20 points
+        thule_index=last_index + 1
+        if thule_index > len(xvector): #for rare cases in which we fit something at the END of whole curve.
+            thule_index = len(xvector)
+        #reverse etc. the domain
+        xfit_chunk=xvector[clicked_points[0].index:thule_index]
+        xfit_chunk.reverse()
+        xfit_chunk_corr_up=[-(x-clicked_points[0].graph_coords[0]) for x in xfit_chunk]
+        xfit_chunk_corr_up=scipy.array(xfit_chunk_corr_up)
+
+        #the fitted curve: reflip, re-uncorrect
+        #x_max = xfit_chunk_corr_up[-1]
+        #x_min = xfit_chunk_corr_up[0]
+        #points_in_fit = 50
+        #increment = (x_max - x_min) / (points_in_fit - 1)
+        #x_help = [x_min + x * increment for x in range(points_in_fit)]
+        #xfit_chunk = [x_min + x * increment for x in range(points_in_fit)]
+        #xfit_chunk.reverse()
+        #x_help = scipy.array(x_help)
+
+        #yfit = wlc_eval(x_help, out.beta, pl_value, T)
+
+        yfit=wlc_eval(xfit_chunk_corr_up, out.beta, pl_value,T)
+        yfit_down=[-y for y in yfit]
+        yfit_corr_down=[y+clicked_points[0].graph_coords[1] for y in yfit_down]
+
+        plot = self.GetActivePlot()
+
+        if return_errors:
+            return fit_out, yfit_corr_down, xfit_chunk, fit_errors
+        else:
+            return fit_out, yfit_corr_down, xfit_chunk, None
+
+    def fjc_fit(self, clicked_points, xvector, yvector, pl_value, T=293, return_errors=False):
+        '''
+        Freely-jointed chain function
+        ref: C.Ray and B.B. Akhremitchev; http://www.chem.duke.edu/~boris/research/force_spectroscopy/fit_efjc.pdf
+        '''
+
+        '''
+        clicked_points[0] = contact point (calculated or hand-clicked)
+        clicked_points[1] and [2] are edges of chunk
+        '''
+
+        #STEP 1: Prepare the vectors to apply the fit.
+        if pl_value is not None:
+            pl_value=pl_value/(10**9)
+
+        #indexes of the selected chunk
+        first_index=min(clicked_points[1].index, clicked_points[2].index)
+        last_index=max(clicked_points[1].index, clicked_points[2].index)
+
+        #getting the chunk and reverting it
+        xchunk,ychunk=xvector[first_index:last_index],yvector[first_index:last_index]
+        xchunk.reverse()
+        ychunk.reverse()
+        #put contact point at zero and flip around the contact point (the fit wants a positive growth for extension and force)
+        xchunk_corr_up=[-(x-clicked_points[0].graph_coords[0]) for x in xchunk]
+        ychunk_corr_up=[-(y-clicked_points[0].graph_coords[1]) for y in ychunk]
+
+        #make them arrays
+        xchunk_corr_up=scipy.array(xchunk_corr_up)
+        ychunk_corr_up=scipy.array(ychunk_corr_up)
+
+
+        #STEP 2: actually do the fit
+
+        #Find furthest point of chunk and add it a bit; the fit must converge
+        #from an excess!
+        xchunk_high=max(xchunk_corr_up)
+        xchunk_high+=(xchunk_high/10)
+
+        #Here are the linearized start parameters for the WLC.
+        #[lambd=1/Lo , pii=1/P]
+
+        p0=[(1/xchunk_high),(1/(3.5e-10))]
+        p0_plfix=[(1/xchunk_high)]
+        '''
+        ODR STUFF
+        fixme: remove these comments after testing
+        '''
+        def x_fjc(params,f,T=T):
+            '''
+            fjc function for ODR fitting
+            '''
+            lambd,pii=params
+            Kb=(1.38065e-23)
+            therm=Kb*T
+
+            #x=(therm*pii/4.0) * (((1-(x*lambd))**-2) - 1 + (4*x*lambd))
+            x=(1/lambd)*(coth(f*(1/pii)/therm) - (therm*pii)/f)
+            return x
+
+        def x_fjc_plfix(params,f,pl_value=pl_value,T=T):
+            '''
+            fjc function for ODR fitting
+            '''
+            lambd=params
+            pii=1/pl_value
+            Kb=(1.38065e-23)
+            therm=Kb*T
+            #y=(therm*pii/4.0) * (((1-(x*lambd))**-2) - 1 + (4*x*lambd))
+            x=(1/lambd)*(coth(f*(1/pii)/therm) - (therm*pii)/f)
+            return x
+
+        #make the ODR fit
+        realdata=scipy.odr.RealData(ychunk_corr_up,xchunk_corr_up)
+        if pl_value:
+            model=scipy.odr.Model(x_fjc_plfix)
+            o = scipy.odr.ODR(realdata, model, p0_plfix)
+        else:
+            model=scipy.odr.Model(x_fjc)
+            o = scipy.odr.ODR(realdata, model, p0)
+
+        o.set_job(fit_type=2)
+        out=o.run()
+        fit_out=[(1/i) for i in out.beta]
+
+        #Calculate fit errors from output standard deviations.
+        #We must propagate the error because we fit the *inverse* parameters!
+        #The error = (error of the inverse)*(value**2)
+        fit_errors=[]
+        for sd,value in zip(out.sd_beta, fit_out):
+            err_real=sd*(value**2)
+            fit_errors.append(err_real)
+
+        def fjc_eval(y, params, pl_value, T):
+            '''
+            Evaluates the FJC function
+            '''
+            if not pl_value:
+                lambd, pii = params
+            else:
+                lambd = params
+
+            if pl_value:
+                pii = 1/pl_value
+
+            Kb = (1.38065e-23) #Boltzmann constant
+            therm = Kb * T #so we have thermal energy
+            #return ( (therm*pii/4.0) * (((1-(x*lambd))**-2.0) - 1 + (4.0*x*lambd)) )
+            return (1 / lambd) * (coth(y * (1 / pii) / therm) - (therm * pii) / y)
+
+
+        #STEP 3: plotting the fit
+
+        #obtain domain to plot the fit - from contact point to last_index plus 20 points
+        thule_index=last_index+10
+        if thule_index > len(xvector): #for rare cases in which we fit something at the END of whole curve.
+            thule_index = len(xvector)
+        #reverse etc. the domain
+        ychunk=yvector[clicked_points[0].index:thule_index]
+
+        if len(ychunk)>0:
+            y_evalchunk=np.linspace(min(ychunk),max(ychunk),100)
+        else:
+            #Empty y-chunk. It happens whenever we set the contact point after a recognized peak,
+            #or other buggy situations. Kludge to live with it now...
+            ychunk=yvector[:thule_index]
+            y_evalchunk=np.linspace(min(ychunk),max(ychunk),100)
+
+        yfit_down=[-y for y in y_evalchunk]
+        yfit_corr_down=[y+clicked_points[0].graph_coords[1] for y in yfit_down]
+        yfit_corr_down=scipy.array(yfit_corr_down)
+
+        #the fitted curve: reflip, re-uncorrect
+        xfit=fjc_eval(yfit_corr_down, out.beta, pl_value,T)
+        xfit=list(xfit)
+        xfit.reverse()
+        xfit_chunk_corr_up=[-(x-clicked_points[0].graph_coords[0]) for x in xfit]
+
+        #xfit_chunk_corr_up=scipy.array(xfit_chunk_corr_up)
+        #deltay=yfit_down[0]-yvector[clicked_points[0].index]
+
+        #This is a terrible, terrible kludge to find the point where it should normalize (and from where it should plot)
+        xxxdists=[]
+        for index in scipy.arange(1,len(xfit_chunk_corr_up),1):
+            xxxdists.append((clicked_points[0].graph_coords[0]-xfit_chunk_corr_up[index])**2)
+        normalize_index=xxxdists.index(min(xxxdists))
+        #End of kludge
+
+        deltay=yfit_down[normalize_index]-clicked_points[0].graph_coords[1]
+        yfit_corr_down=[y-deltay for y in yfit_down]
+
+        if return_errors:
+            #return fit_out, yfit_corr_down, xfit_chunk_corr_up, fit_errors
+            return fit_out, yfit_corr_down[normalize_index+1:], xfit_chunk_corr_up[normalize_index+1:], fit_errors
+        else:
+            #return fit_out, yfit_corr_down, xfit_chunk_corr_up, None
+            return fit_out, yfit_corr_down[normalize_index+1:], xfit_chunk_corr_up[normalize_index+1:], None
+
+    def fjcPEG_fit(self, clicked_points, xvector, yvector, pl_value, T=293, return_errors=False):
+        '''
+        Freely-jointed chain function for PEG-containing molecules
+        ref: C.Ray and B.B. Akhremitchev; http://www.chem.duke.edu/~boris/research/force_spectroscopy/fit_efjc.pdf
+        '''
+
+        '''
+        clicked_points[0] = contact point (calculated or hand-clicked)
+        clicked_points[1] and [2] are edges of chunk
+        '''
+
+        #STEP 1: Prepare the vectors to apply the fit.
+        if pl_value is not None:
+            pl_value=pl_value/(10**9)
+
+        #indexes of the selected chunk
+        first_index=min(clicked_points[1].index, clicked_points[2].index)
+        last_index=max(clicked_points[1].index, clicked_points[2].index)
+
+        #getting the chunk and reverting it
+        xchunk,ychunk=xvector[first_index:last_index],yvector[first_index:last_index]
+        xchunk.reverse()
+        ychunk.reverse()
+        #put contact point at zero and flip around the contact point (the fit wants a positive growth for extension and force)
+        xchunk_corr_up=[-(x-clicked_points[0].graph_coords[0]) for x in xchunk]
+        ychunk_corr_up=[-(y-clicked_points[0].graph_coords[1]) for y in ychunk]
+
+        #make them arrays
+        xchunk_corr_up=scipy.array(xchunk_corr_up)
+        ychunk_corr_up=scipy.array(ychunk_corr_up)
+
+        #STEP 2: actually do the fit
+
+        #Find furthest point of chunk and add it a bit; the fit must converge
+        #from an excess!
+        xchunk_high=max(xchunk_corr_up)
+        xchunk_high+=(xchunk_high/10)
+
+        #Here are the linearized start parameters for the WLC.
+        #[lambd=1/Lo , pii=1/P]
+
+        L_helical = self.GetFloatFromConfig('fit', 'fjcPEG', 'L_helical') #in nm
+        L_planar = self.GetFloatFromConfig('fit', 'fjcPEG', 'L_planar') #in nm
+        delta_G = self.GetFloatFromConfig('fit', 'fjcPEG', 'delta_G') #in Kb*T
+
+        p0=[(1/xchunk_high),(1/(3.5e-10))]
+        p0_plfix=[(1/xchunk_high)]
+        '''
+        ODR STUFF
+        fixme: remove these comments after testing
+        '''
+        def x_fjcPEG(params,f,T=T):
+            '''
+            fjcPEG function for ODR fitting
+            '''
+            lambd,pii=params
+            Kb=(1.38065e-23)
+            therm=Kb*T
+
+            #x=(therm*pii/4.0) * (((1-(x*lambd))**-2) - 1 + (4*x*lambd))
+
+            x=(1/lambd)*(1 / (exp(delta_G) + 1) + (L_helical/L_planar) * (1 / (exp(-delta_G) + 1))) * (coth(f*(1/pii)/therm) - (therm*pii)/f)
+            return x
+
+        def x_fjcPEG_plfix(params,f,pl_value=pl_value,T=T):
+            '''
+            fjcPEG function for ODR fitting
+            '''
+            lambd=params
+            pii=1/pl_value
+            Kb=(1.38065e-23)
+            therm=Kb*T
+            #y=(therm*pii/4.0) * (((1-(x*lambd))**-2) - 1 + (4*x*lambd))
+            x=(1/lambd)*(1 / (exp(delta_G) + 1) + (L_helical/L_planar) * (1 / (exp(-delta_G) + 1))) * (coth(f*(1/pii)/therm) - (therm*pii)/f)
+            return x
+
+        #make the ODR fit
+        realdata=scipy.odr.RealData(ychunk_corr_up,xchunk_corr_up)
+        if pl_value:
+            model=scipy.odr.Model(x_fjcPEG_plfix)
+            o = scipy.odr.ODR(realdata, model, p0_plfix)
+        else:
+            model=scipy.odr.Model(x_fjcPEG)
+            o = scipy.odr.ODR(realdata, model, p0)
+
+        o.set_job(fit_type=2)
+        out=o.run()
+        fit_out=[(1/i) for i in out.beta]
+
+        #Calculate fit errors from output standard deviations.
+        #We must propagate the error because we fit the *inverse* parameters!
+        #The error = (error of the inverse)*(value**2)
+        fit_errors=[]
+        for sd,value in zip(out.sd_beta, fit_out):
+            err_real=sd*(value**2)
+            fit_errors.append(err_real)
+
+        def fjcPEG_eval(y, params, pl_value, T):
+            '''
+            Evaluates the fjcPEG function
+            '''
+            if not pl_value:
+                lambd, pii = params
+            else:
+                lambd = params
+
+            if pl_value:
+                pii = 1/pl_value
+
+            Kb = (1.38065e-23) #Boltzmann constant
+            therm = Kb * T #so we have thermal energy
+            #return ( (therm*pii/4.0) * (((1-(x*lambd))**-2.0) - 1 + (4.0*x*lambd)) )
+            return (1/lambd)*(1 / (exp(delta_G) + 1) + (L_helical/L_planar) * (1 / (exp(-delta_G) + 1))) * (coth(y*(1/pii)/therm) - (therm*pii)/y)
+
+        #STEP 3: plotting the fit
+
+        #obtain domain to plot the fit - from contact point to last_index plus 20 points
+        thule_index=last_index+10
+        if thule_index > len(xvector): #for rare cases in which we fit something at the END of whole curve.
+            thule_index = len(xvector)
+        #reverse etc. the domain
+        ychunk=yvector[clicked_points[0].index:thule_index]
+
+        if len(ychunk)>0:
+            y_evalchunk=np.linspace(min(ychunk),max(ychunk),100)
+        else:
+            #Empty y-chunk. It happens whenever we set the contact point after a recognized peak,
+            #or other buggy situations. Kludge to live with it now...
+            ychunk=yvector[:thule_index]
+            y_evalchunk=np.linspace(min(ychunk),max(ychunk),100)
+
+        yfit_down=[-y for y in y_evalchunk]
+        yfit_corr_down=[y+clicked_points[0].graph_coords[1] for y in yfit_down]
+        yfit_corr_down=scipy.array(yfit_corr_down)
+
+        #the fitted curve: reflip, re-uncorrect
+        xfit=fjcPEG_eval(yfit_corr_down, out.beta, pl_value,T)
+        xfit=list(xfit)
+        xfit.reverse()
+        xfit_chunk_corr_up=[-(x-clicked_points[0].graph_coords[0]) for x in xfit]
+
+        #xfit_chunk_corr_up=scipy.array(xfit_chunk_corr_up)
+        #deltay=yfit_down[0]-yvector[clicked_points[0].index]
+
+        #This is a terrible, terrible kludge to find the point where it should normalize (and from where it should plot)
+        xxxdists=[]
+        for index in scipy.arange(1,len(xfit_chunk_corr_up),1):
+            xxxdists.append((clicked_points[0].graph_coords[0]-xfit_chunk_corr_up[index])**2)
+        normalize_index=xxxdists.index(min(xxxdists))
+        #End of kludge
+
+        deltay=yfit_down[normalize_index]-clicked_points[0].graph_coords[1]
+        yfit_corr_down=[y-deltay for y in yfit_down]
+
+        if return_errors:
+            #return fit_out, yfit_corr_down, xfit_chunk_corr_up, fit_errors
+            return fit_out, yfit_corr_down[normalize_index+1:], xfit_chunk_corr_up[normalize_index+1:], fit_errors
+        else:
+            #return fit_out, yfit_corr_down, xfit_chunk_corr_up, None
+            return fit_out, yfit_corr_down[normalize_index+1:], xfit_chunk_corr_up[normalize_index+1:], None
+
+    def do_wlc(self,args):
+        '''
+        WLC
+        (fit.py plugin)
+
+        See the fit command
+        '''
+        self.fit(args)
+
+    def do_fjc(self,args):
+        '''
+        FJC
+        (fit.py plugin)
+
+        See the fit command
+        '''
+        self.fit(args)
+
+    def do_fjcPEG(self,args):
+        '''
+        fjcPEG
+        (fit.py plugin)
+
+        default values for PEG
+        ----------------------
+        delta_G: 3 Kb*T
+        L_helical: 0.28 nm
+        L_planar: 0.358 nm
+
+        See the fit command for more information
+        '''
+        self.fit(args)
+
+    def fit(self,args):
+        '''
+        FIT
+        (fit.py plugin)
+        Fits an entropic elasticity function to a given chunk of the curve.
+
+        First you have to click a contact point.
+        Then you have to click the two edges of the data you want to fit.
+
+        The fit function depends on the fit_function variable. You can set it with the command
+        "set fit_function wlc" or  "set fit_function fjc" depending on the function you prefer.
+
+        For WLC, the function is the simple polynomial worm-like chain as proposed by
+        C.Bustamante, J.F.Marko, E.D.Siggia and S.Smith (Science. 1994
+        Sep 9;265(5178):1599-600.)
+
+        For FJC, ref:
+        C.Ray and B.B. Akhremitchev; http://www.chem.duke.edu/~boris/research/force_spectroscopy/fit_efjc.pdf
+
+        Arguments:
+        pl=[value] : Use a fixed persistent length (WLC) or Kuhn length (FJC) for the fit. If pl is not given,
+                     the fit will be a 2-variable
+                     fit. DO NOT put spaces between 'pl', '=' and the value.
+                     The value must be in nanometers.
+
+        t=[value] : Use a user-defined temperature. The value must be in
+                    kelvins; by default it is 293 K.
+                    DO NOT put spaces between 't', '=' and the value.
+
+        noauto : allows for clicking the contact point by
+                 hand (otherwise it is automatically estimated) the first time.
+                 If subsequent measurements are made, the same contact point
+                 clicked is used
+
+        reclick : redefines by hand the contact point, if noauto has been used before
+                  but the user is unsatisfied of the previously choosen contact point.
+        ---------
+        Syntax: fit [pl=(value)] [t=value] [noauto]
+        '''
+        pl_value=None
+        T = self.config['fit'].as_float['temperature']
+        for arg in args.split():
+            #look for a persistent length argument.
+            if 'pl=' in arg:
+                pl_expression=arg.split('=')
+                pl_value=float(pl_expression[1]) #actual value
+            #look for a T argument. FIXME: spaces are not allowed between 'pl' and value
+            if ('t=' in arg[0:2]) or ('T=' in arg[0:2]):
+                t_expression=arg.split('=')
+                T=float(t_expression[1])
+
+        #use the currently displayed plot for the fit
+        displayed_plot=self._get_displayed_plot()
+
+        #handle contact point arguments correctly
+        if 'reclick' in args.split():
+            print 'Click contact point'
+            contact_point=self._measure_N_points(N=1, whatset=1)[0]
+            contact_point_index=contact_point.index
+            self.wlccontact_point=contact_point
+            self.wlccontact_index=contact_point.index
+            self.wlccurrent=self.current.path
+        elif 'noauto' in args.split():
+            if self.wlccontact_index is None or self.wlccurrent != self.current.path:
+                print 'Click contact point'
+                contact_point=self._measure_N_points(N=1, whatset=1)[0]
+                contact_point_index=contact_point.index
+                self.wlccontact_point=contact_point
+                self.wlccontact_index=contact_point.index
+                self.wlccurrent=self.current.path
+            else:
+                contact_point=self.wlccontact_point
+                contact_point_index=self.wlccontact_index
+        else:
+            cindex=self.find_contact_point()
+            contact_point=lh.ClickedPoint()
+            contact_point.absolute_coords=displayed_plot.vectors[1][0][cindex], displayed_plot.vectors[1][1][cindex]
+            contact_point.find_graph_coords(displayed_plot.vectors[1][0], displayed_plot.vectors[1][1])
+            contact_point.is_marker=True
+
+        print 'Click edges of chunk'
+        points=self._measure_N_points(N=2, whatset=1)
+        points=[contact_point]+points
+        try:
+            if self.config['fit_function']=='wlc':
+                params, yfit, xfit, fit_errors = self.wlc_fit(points, displayed_plot.vectors[1][0], displayed_plot.vectors[1][1],pl_value,T, return_errors=True )
+                name_of_charlength='Persistent length'
+            elif self.config['fit_function']=='fjc':
+                params, yfit, xfit, fit_errors = self.fjc_fit(points, displayed_plot.vectors[1][0], displayed_plot.vectors[1][1],pl_value,T, return_errors=True )
+                name_of_charlength='Kuhn length'
+            elif self.config['fit_function']=='fjcPEG':
+                params, yfit, xfit, fit_errors = self.fjcPEG_fit(points, displayed_plot.vectors[1][0], displayed_plot.vectors[1][1],pl_value,T, return_errors=True )
+                name_of_charlength='Kuhn length'
+            else:
+                print 'No recognized fit function defined!'
+                print 'Set your fit function to wlc or fjc.'
+                return
+
+        except:
+            print 'Fit not possible. Probably wrong interval -did you click two *different* points?'
+            return
+
+        #FIXME: print "Kuhn length" for FJC
+        print 'Fit function:',self.config['fit_function']
+        print 'Contour length: ',params[0]*(1.0e+9),' nm'
+        to_dump='contour '+self.current.path+' '+str(params[0]*(1.0e+9))+' nm'
+        self.outlet.push(to_dump)
+        if len(params)==2: #if we did choose 2-value fit
+            print name_of_charlength+': ',params[1]*(1.0e+9),' nm'
+            to_dump='persistent '+self.current.path+' '+str(params[1]*(1.0e+9))+' nm'
+            self.outlet.push(to_dump)
+
+        if fit_errors:
+            fit_nm=[i*(10**9) for i in fit_errors]
+            print 'Standard deviation (contour length)', fit_nm[0]
+            if len(fit_nm)>1:
+                print 'Standard deviation ('+name_of_charlength+')', fit_nm[1]
+
+        #add the clicked points in the final PlotObject
+        clickvector_x, clickvector_y=[], []
+        for item in points:
+            clickvector_x.append(item.graph_coords[0])
+            clickvector_y.append(item.graph_coords[1])
+
+        #create a custom PlotObject to gracefully plot the fit along the curves
+
+        fitplot=copy.deepcopy(displayed_plot)
+        fitplot.add_set(xfit,yfit)
+        fitplot.add_set(clickvector_x,clickvector_y)
+
+        #FIXME: this colour/styles stuff must be solved at the root!
+        if fitplot.styles==[]:
+            fitplot.styles=[None,None,None,'scatter']
+        else:
+            fitplot.styles+=[None,'scatter']
+
+        if fitplot.colors==[]:
+            fitplot.colors=[None,None,None,None]
+        else:
+            fitplot.colors+=[None,None]
+
+        self._send_plot([fitplot])
+
+    #TODO: remove 'plot' as parameter
+    def find_contact_point(self, plot=None):
+        '''
+        Finds the contact point on the curve.
+
+        The current algorithm (thanks to Francesco Musiani, francesco.musiani@unibo.it and Massimo Sandal) is:
+        - take care of the PicoForce trigger bug - exclude retraction portions with too high standard deviation
+        - fit the second half of the retraction curve to a line
+        - if the fit is not almost horizontal, take a smaller chunk and repeat
+        - otherwise, we have something horizontal
+        - so take the average of horizontal points and use it as a baseline
+
+        Then, start from the rise of the retraction curve and look at the first point below the
+        baseline.
+
+        FIXME: should be moved, probably to generalvclamp.py
+        '''
+
+        #TODO: pickup current curve?
+        if plot is None:
+            return
+
+        extension = copy.deepcopy(plot.curves[lh.EXTENSION])
+        retraction = copy.deepcopy(plot.curves[lh.RETRACTION])
+        yext = extension.y
+        yret = retraction.y
+        extension, retraction = self.subtract_curves(extension, retraction)
+        xret = retraction.x
+        ydiff = retraction.y
+        #taking care of the picoforce trigger bug: we exclude portions of the curve that have too much
+        #standard deviation. yes, a lot of magic is here.
+        monster=True
+        monlength=len(xret)-int(len(xret)/20)
+        finalength=len(xret)
+        while monster:
+            monchunk=scipy.array(ydiff[monlength:finalength])
+            #TODO: there is a difference between scipy.stats.std and numpy.std: why?
+            #if abs(scipy.stats.std(monchunk)) < 2e-10:
+            if abs(np.std(monchunk)) < 2e-10:
+                monster=False
+            else: #move away from the monster
+                monlength-=int(len(xret)/50)
+                finalength-=int(len(xret)/50)
+        #take half of the thing
+        endlength=int(len(xret)/2)
+        ok=False
+        while not ok:
+            xchunk=yext[endlength:monlength]
+            ychunk=yext[endlength:monlength]
+            regr=scipy.stats.linregress(xchunk,ychunk)[0:2]
+            #we stop if we found an almost-horizontal fit or if we're going too short...
+            #FIXME: 0.1 and 6 here are "magic numbers" (although reasonable)
+            if (abs(regr[1]) > 0.1) and ( endlength < len(xret)-int(len(xret)/6) ) :
+                endlength+=10
+            else:
+                ok=True
+        #ymean=scipy.mean(ychunk) #baseline
+        ymean = np.mean(ychunk) #baseline
+
+        #TODO: check if this works rather than the thing below
+        #for index, point in enumerate(yret):
+            #if point < ymean:
+                #result = index
+        #result = -1
+
+        #find the first point below the calculated baseline
+        index=0
+        point = ymean+1
+        while point > ymean:
+            try:
+                point=yret[index]
+                index+=1
+            except IndexError:
+                #The algorithm didn't find anything below the baseline! It should NEVER happen
+                index=0
+                return index
+
+        return index
+
+    def find_contact_point2(self, debug=False):
+        '''
+        TO BE DEVELOPED IN THE FUTURE
+        Finds the contact point on the curve.
+
+        FIXME: should be moved, probably to generalvclamp.py
+        '''
+
+        #raw_plot=self.current.curve.default_plots()[0]
+        raw_plot=self.plots[0]
+        '''xext=self.plots[0].vectors[0][0]
+        yext=self.plots[0].vectors[0][1]
+        xret2=self.plots[0].vectors[1][0]
+        yret=self.plots[0].vectors[1][1]
+        '''
+        xext=raw_plot.vectors[0][0]
+        yext=raw_plot.vectors[0][1]
+        xret2=raw_plot.vectors[1][0]
+        yret=raw_plot.vectors[1][1]
+
+        first_point=[xext[0], yext[0]]
+        last_point=[xext[-1], yext[-1]]
+
+        #regr=scipy.polyfit(first_point, last_point,1)[0:2]
+        diffx=abs(first_point[0]-last_point[0])
+        diffy=abs(first_point[1]-last_point[1])
+
+        #using polyfit results in numerical errors. good old algebra.
+        a=diffy/diffx
+        b=first_point[1]-(a*first_point[0])
+        baseline=scipy.polyval((a,b), xext)
+
+        ysub=[item-basitem for item,basitem in zip(yext,baseline)]
+
+        contact=ysub.index(min(ysub))
+
+        return xext,ysub,contact
+
+        #now, exploit a ClickedPoint instance to calculate index...
+        dummy=lh.ClickedPoint()
+        dummy.absolute_coords=(x_intercept,y_intercept)
+        dummy.find_graph_coords(xret2,yret)
+
+        if debug:
+            return dummy.index, regr, regr_contact
+        else:
+            return dummy.index
+
+
+
+    #def x_do_contact(self,args):
+        #'''
+        #DEBUG COMMAND to be activated in the future
+        #'''
+        #xext,ysub,contact=self.find_contact_point2(debug=True)
+
+        #contact_plot=self.plots[0]
+        #contact_plot.add_set(xext,ysub)
+        #contact_plot.add_set([xext[contact]],[self.plots[0].vectors[0][1][contact]])
+        ##contact_plot.add_set([first_point[0]],[first_point[1]])
+        ##contact_plot.add_set([last_point[0]],[last_point[1]])
+        #contact_plot.styles=[None,None,None,'scatter']
+        #self._send_plot([contact_plot])
+        #return
+
+        #index,regr,regr_contact=self.find_contact_point2(debug=True)
+        #print regr
+        #print regr_contact
+        #raw_plot=self.current.curve.default_plots()[0]
+        #xret=raw_plot.vectors[0][0]
+        ##nc_line=[(item*regr[0])+regr[1] for item in x_nc]
+        #nc_line=scipy.polyval(regr,xret)
+        #c_line=scipy.polyval(regr_contact,xret)
+
+
+        #contact_plot=self.current.curve.default_plots()[0]
+        #contact_plot.add_set(xret, nc_line)
+        #contact_plot.add_set(xret, c_line)
+        #contact_plot.styles=[None,None,None,None]
+        ##contact_plot.styles.append(None)
+        #contact_plot.destination=1
+        #self._send_plot([contact_plot])
diff --git a/plugins/flatfilts.ini b/plugins/flatfilts.ini
new file mode 100644 (file)
index 0000000..3a6f604
--- /dev/null
@@ -0,0 +1,96 @@
+[convfilt]\r
+    [[blindwindow]]\r
+        default = 20\r
+        maximum = 10000\r
+        minimum = 0\r
+        type = float\r
+        value = 20\r
+    \r
+    [[convolution]]\r
+        default = "[6.0, -1.0, -1.0, -1.0, -1.0, -1.0, -1.0]"\r
+        type = string\r
+        #value = '[6.0, -1.0, -1.0, -1.0, -1.0, -1.0, -1.0]'\r
+        value = "[6.0,-1.0,-1.0,-1.0,-1.0,-1.0,-1.0]"\r
+    \r
+    [[maxcut]]\r
+        default = 0.2\r
+        maximum = 1\r
+        minimum = 0\r
+        type = float\r
+        value = 0.2\r
+        visible = False\r
+    \r
+    [[medianfilter]]\r
+        default = 7\r
+        maximum = 100\r
+        minimum = 0\r
+        type = integer\r
+        value = 2\r
+    \r
+    [[mindeviation]]\r
+        default = 5\r
+        maximum = 100\r
+        minimum = 0\r
+        type = float\r
+        value = 5\r
+    \r
+    [[minpeaks]]\r
+        default = 5\r
+        maximum = 20\r
+        minimum = 0\r
+        type = integer\r
+        value = 5\r
+    \r
+    [[positive]]\r
+        default = False\r
+        type = boolean\r
+        value = False\r
+    \r
+    [[seedouble]]\r
+        default = 10\r
+        maximum = 1000\r
+        minimum = 0\r
+        type = integer\r
+        value = 10\r
+    \r
+    [[stable]]\r
+        default = 0.005\r
+        maximum = 1\r
+        minimum = 0\r
+        type = float\r
+        value = 0.005\r
+\r
+[flatfilt]\r
+    #[[median_filter]]\r
+    #default = 7\r
+    #maximum = 100\r
+    #minimum = 0\r
+    #type = integer\r
+    #value = 7\r
+    \r
+    [[min_npks]]\r
+        default = 4\r
+        maximum = 10000\r
+        minimum = 1\r
+        type = integer\r
+        value = 7\r
+    \r
+    [[min_deviation]]\r
+        default = 9\r
+        maximum = 100\r
+        minimum = 1\r
+        type = float\r
+        value = 10\r
+\r
+[peaks]\r
+    [[color]]\r
+        default = black\r
+        type = color\r
+        value = "(255,0,128)"\r
+    \r
+    [[size]]\r
+        default = 20\r
+        maximum = 10000\r
+        minimum = 1\r
+        type = integer\r
+        value = 50\r
diff --git a/plugins/flatfilts.py b/plugins/flatfilts.py
new file mode 100644 (file)
index 0000000..9ce8a93
--- /dev/null
@@ -0,0 +1,310 @@
+#!/usr/bin/env python
+
+'''
+flatfilts.py
+
+Force spectroscopy files filtering of flat files.
+
+Plugin dependencies:
+procplots.py (plot processing plugin)
+
+Copyright ???? by ?
+with modifications by Dr. Rolf Schmidt (Concordia University, Canada)
+
+This program is released under the GNU General Public License version 2.
+'''
+
+import lib.libhooke as lh
+import wxversion
+wxversion.select(lh.WX_GOOD)
+
+import copy
+from numpy import diff, mean
+
+import lib.peakspot as lps
+import lib.curve
+
+class flatfiltsCommands:
+
+    def do_flatfilt(self):
+        '''
+        FLATFILT
+        (flatfilts.py)
+        Filters out flat (featureless) files of the current playlist,
+        creating a playlist containing only the files with potential
+        features.
+        ------------
+        Syntax:
+        flatfilt [min_npks min_deviation]
+
+        min_npks = minmum number of points over the deviation
+        (default=4)
+
+        min_deviation = minimum signal/noise ratio
+        (default=9)
+
+        If called without arguments, it uses default values, that
+        should work most of the times.
+        '''
+
+        self.AppendToOutput('Processing playlist...')
+        self.AppendToOutput('(Please wait)')
+        features = []
+        playlist = self.GetActivePlaylist()
+        files = playlist.files
+        file_index = 0
+        for current_file in files:
+            file_index += 1
+            try:
+                current_file.identify(self.drivers)
+                notflat = self.has_features(copy.deepcopy(current_file))
+                feature_string = ''
+                if notflat != 1:
+                    if notflat > 0:
+                        feature_string = str(notflat) + ' features'
+                    else:
+                        feature_string = 'no features'
+                else:
+                    feature_string = '1 feature'
+                output_string = ''.join(['Curve ', current_file.name, '(', str(file_index), '/', str(len(files)), '): ', feature_string])
+            except:
+                notflat = False
+                output_string = ''.join(['Curve ', current_file.name, '(', str(file_index), '/', str(len(files)), '): cannot be filtered. Probably unable to retrieve force data from corrupt file.'])
+            self.AppendToOutput(output_string)
+            if notflat:
+                current_file.features = notflat
+                features.append(file_index - 1)
+        if not features:
+            self.AppendToOutput('Found nothing interesting. Check the playlist, could be a bug or criteria could be too stringent.')
+        else:
+            if len(features) < playlist.count:
+                self.AppendToOutput(''.join(['Found ', str(len(features)), ' potentially interesting files.']))
+                self.AppendToOutput('Regenerating playlist...')
+                playlist_filtered = playlist.filter_curves(features)
+                self.AddPlaylist(playlist_filtered, name='flatfilt')
+            else:
+                self.AppendToOutput('No files filtered. Try different filtering criteria.')
+
+    def has_features(self, current_file):
+        '''
+        decides if a curve is flat enough to be rejected from analysis: it sees if there
+        are at least min_npks points that are higher than min_deviation times the absolute value
+        of noise.
+
+        Algorithm original idea by Francesco Musiani, with my tweaks and corrections.
+        '''
+        #TODO: shoudl medianfilter be variable?
+        medianfilter = 7
+        #medianfilter = self.GetIntFromConfig('flatfilts', 'flatfilt', 'median_filter')
+        mindeviation = self.GetIntFromConfig('flatfilts', 'flatfilt', 'min_deviation')
+        minpeaks = self.GetIntFromConfig('flatfilts', 'flatfilt', 'min_npks')
+
+        retvalue = 0
+
+        #we assume the first is the plot with the force curve
+        #do the median to better resolve features from noise
+        flat_curve = self.plotmanip_median(current_file.plot, current_file, customvalue=medianfilter)
+
+        #absolute value of derivate
+        yretdiff = diff(flat_curve.curves[lh.RETRACTION].y)
+        yretdiff = [abs(value) for value in yretdiff]
+        #average of derivate values
+        diffmean = mean(yretdiff)
+        yretdiff.sort()
+        yretdiff.reverse()
+        c_pks = 0
+        for value in yretdiff:
+            if value / diffmean > mindeviation:
+                c_pks += 1
+            else:
+                break
+
+        if c_pks >= minpeaks:
+            retvalue = c_pks
+
+        return retvalue
+
+    ################################################################
+    #-----CONVFILT-------------------------------------------------
+    #-----Convolution-based peak recognition and filtering.
+    #Requires the peakspot.py library
+
+    def has_peaks(self, plot=None):
+        '''
+        Finds peak position in a force curve.
+        FIXME: should be moved to peakspot.py
+        '''
+
+        blindwindow = self.GetFloatFromConfig('flatfilts', 'convfilt', 'blindwindow')
+        #need to convert the string that contains the list into a list
+        convolution = eval(self.GetStringFromConfig('flatfilts', 'convfilt', 'convolution'))
+        maxcut = self.GetFloatFromConfig('flatfilts', 'convfilt', 'maxcut')
+        mindeviation = self.GetFloatFromConfig('flatfilts', 'convfilt', 'mindeviation')
+        positive = self.GetBoolFromConfig('flatfilts', 'convfilt', 'positive')
+        seedouble = self.GetIntFromConfig('flatfilts', 'convfilt', 'seedouble')
+        stable = self.GetFloatFromConfig('flatfilts', 'convfilt', 'stable')
+
+        if plot is None:
+            plot = self.GetActivePlot()
+
+        xret = plot.curves[lh.RETRACTION].x
+        yret = plot.curves[lh.RETRACTION].y
+        #Calculate convolution
+        convoluted = lps.conv_dx(yret, convolution)
+
+        #surely cut everything before the contact point
+        cut_index = self.find_contact_point(plot)
+        #cut even more, before the blind window
+        start_x = xret[cut_index]
+        blind_index = 0
+        for value in xret[cut_index:]:
+            if abs((value) - (start_x)) > blindwindow * (10 ** -9):
+                break
+            blind_index += 1
+        cut_index += blind_index
+        #do the dirty convolution-peak finding stuff
+        noise_level = lps.noise_absdev(convoluted[cut_index:], positive, maxcut, stable)
+        above = lps.abovenoise(convoluted, noise_level, cut_index, mindeviation)
+        peak_location, peak_size = lps.find_peaks(above, seedouble=seedouble)
+        #take the maximum
+        for i in range(len(peak_location)):
+            peak = peak_location[i]
+            maxpk = min(yret[peak - 10:peak + 10])
+            index_maxpk = yret[peak - 10:peak + 10].index(maxpk) + (peak - 10)
+            peak_location[i] = index_maxpk
+
+        return peak_location, peak_size
+
+    def exec_has_peaks(self, item):
+        '''
+        encapsulates has_peaks for the purpose of correctly treating the curve objects in the convfilt loop,
+        to avoid memory leaks
+        '''
+        #TODO: things have changed, check for the memory leak again
+
+        if self.HasPlotmanipulator('plotmanip_flatten'):
+            #If flatten is present, use it for better recognition of peaks...
+            flat_plot = self.plotmanip_flatten(item.plot, item, customvalue=1)
+
+        peak_location, peak_size = self.has_peaks(flat_plot)
+
+        return peak_location, peak_size
+
+    def do_peaks(self, plugin=None, peak_location=None, peak_size=None):
+        '''
+        PEAKS
+        (flatfilts.py)
+        Test command for convolution filter / test.
+        ----
+        Syntax: peaks [deviations]
+        absolute deviation = number of times the convolution signal is above the noise absolute deviation.
+        Default is 5.
+        '''
+
+        if plugin is None:
+            color = self.GetColorFromConfig('flatfilts', 'peaks', 'color')
+            size = self.GetIntFromConfig('flatfilts', 'peaks', 'size')
+        else:
+            color = self.GetColorFromConfig(plugin.name, plugin.section, plugin.prefix + 'color')
+            size = self.GetIntFromConfig(plugin.name, plugin.section, plugin.prefix + 'size')
+
+        plot = self.GetDisplayedPlotCorrected()
+
+        if peak_location is None and peak_size is None:
+            if not self.AppliesPlotmanipulator('flatten'):
+                self.AppendToOutput('The flatten plot manipulator is not loaded. Enabling it could give better results.')
+
+            peak_location, peak_size = self.has_peaks(plot)
+            if len(peak_location) != 1:
+                peak_str = ' peaks.'
+            else:
+                peak_str = ' peak.'
+            self.AppendToOutput('Found ' + str(len(peak_location)) + peak_str)
+
+        if peak_location:
+            xplotted_ret = plot.curves[lh.RETRACTION].x
+            yplotted_ret = plot.curves[lh.RETRACTION].y
+            xgood = [xplotted_ret[index] for index in peak_location]
+            ygood = [yplotted_ret[index] for index in peak_location]
+
+            peaks = lib.curve.Curve()
+            peaks.color = color
+            peaks.size = size
+            peaks.style = 'scatter'
+            peaks.x = xgood
+            peaks.y = ygood
+
+            plot.curves.append(peaks)
+
+            self.UpdatePlot(plot)
+
+    def do_convfilt(self):
+        '''
+        CONVFILT
+        (flatfilts.py)
+        Filters out flat (featureless) files of the current playlist,
+        creating a playlist containing only the files with potential
+        features.
+        ------------
+        Syntax:
+        convfilt [min_npks min_deviation]
+
+        min_npks = minmum number of peaks
+        (to set the default, see convfilt.conf file; CONVCONF and SETCONF commands)
+
+        min_deviation = minimum signal/noise ratio *in the convolution*
+        (to set the default, see convfilt.conf file; CONVCONF and SETCONF commands)
+
+        If called without arguments, it uses default values.
+        '''
+
+        self.AppendToOutput('Processing playlist...')
+        self.AppendToOutput('(Please wait)')
+        minpeaks = self.GetIntFromConfig('flatfilts', 'convfilt', 'minpeaks')
+        features = []
+        playlist = self.GetActivePlaylist()
+
+        files = self.GetActivePlaylist().files
+        file_index = 0
+        for current_file in files:
+            number_of_peaks = 0
+            file_index += 1
+            try:
+                current_file.identify(self.drivers)
+                peak_location, peak_size = self.exec_has_peaks(copy.deepcopy(current_file))
+                number_of_peaks = len(peak_location)
+                if number_of_peaks != 1:
+                    if number_of_peaks > 0:
+                        feature_string = str(number_of_peaks) + ' features'
+                    else:
+                        feature_string = 'no features'
+                else:
+                    feature_string = '1 feature'
+                if number_of_peaks >= minpeaks:
+                    feature_string += '+'
+                output_string = ''.join(['Curve ', current_file.name, '(', str(file_index), '/', str(len(files)), '): ', feature_string])
+            except:
+                peak_location = []
+                peak_size = []
+                output_string = ''.join(['Curve ', current_file.name, '(', str(file_index), '/', str(len(files)), '): cannot be filtered. Probably unable to retrieve force data from corrupt file.'])
+            self.AppendToOutput(output_string)
+            if number_of_peaks >= minpeaks:
+                current_file.peak_location = peak_location
+                current_file.peak_size = peak_size
+                features.append(file_index - 1)
+
+        #Warn that no flattening had been done.
+        if not self.HasPlotmanipulator('plotmanip_flatten'):
+            self.AppendToOutput('Flatten manipulator was not found. Processing was done without flattening.')
+            self.AppendToOutput('Try to enable it in the configuration file for better results.')
+        if not features:
+            self.AppendToOutput('Found nothing interesting. Check the playlist, could be a bug or criteria could be too stringent.')
+        else:
+            if len(features) < playlist.count:
+                self.AppendToOutput(''.join(['Found ', str(len(features)), ' potentially interesting files.']))
+                self.AppendToOutput('Regenerating playlist...')
+                playlist_filtered = playlist.filter_curves(features)
+                self.AddPlaylist(playlist_filtered, name='convfilt')
+            else:
+                self.AppendToOutput('No files filtered. Try different filtering criteria.')
+
diff --git a/plugins/generalvclamp.ini b/plugins/generalvclamp.ini
new file mode 100644 (file)
index 0000000..3d930e9
--- /dev/null
@@ -0,0 +1,67 @@
+[distance]\r
+    [[show_points]]\r
+        default = True\r
+        type = boolean\r
+        value = True\r
+    \r
+    [[whatset]]\r
+        default = retraction\r
+        elements = extension, retraction\r
+        type = enum\r
+        value = retraction\r
+\r
+[force]\r
+    [[whatset]]\r
+        default = retraction\r
+        elements = extension, retraction\r
+        type = enum\r
+        value = retraction\r
+\r
+[forcebase]\r
+    [[max]]\r
+        default = False\r
+        type = boolean\r
+        value = False\r
+    \r
+    [[rebase]]\r
+        default = False\r
+        type = boolean\r
+        value = False\r
+    \r
+    [[whatset]]\r
+        default = retraction\r
+        elements = extension, retraction\r
+        type = enum\r
+        value = retraction\r
+    \r
+    [[baseline]]\r
+        type = none\r
+        value = 1\r
+\r
+[generalvclamp]\r
+    [[flatten]]\r
+        default = True\r
+        type = boolean\r
+        value = True\r
+    \r
+    [[max_cycles]]\r
+        default = 1\r
+        maximum = 100\r
+        minimum = 0\r
+        type = integer\r
+        value = 1\r
+    \r
+    [[force_multiplier]]\r
+        default = 1\r
+        maximum = 100\r
+        minimum = 0\r
+        type = float\r
+        value = 2\r
+\r
+[slope]\r
+    [[fitspan]]\r
+        default = 0\r
+        maximum = 10000\r
+        minimum = 0\r
+        type = integer\r
+        value = 60\r
diff --git a/plugins/generalvclamp.py b/plugins/generalvclamp.py
new file mode 100644 (file)
index 0000000..9f97136
--- /dev/null
@@ -0,0 +1,326 @@
+#!/usr/bin/env python
+
+'''
+generalvclamp.py
+
+Plugin regarding general velocity clamp measurements
+
+Copyright ???? by ?
+with modifications by Dr. Rolf Schmidt (Concordia University, Canada)
+
+This program is released under the GNU General Public License version 2.
+'''
+
+import lib.libhooke as lh
+import wxversion
+wxversion.select(lh.WX_GOOD)
+
+import numpy as np
+import scipy as sp
+
+import warnings
+warnings.simplefilter('ignore', np.RankWarning)
+
+import lib.curve
+
+class generalvclampCommands:
+
+    def _plug_init(self):
+        self.basecurrent = ''
+        self.basepoints = []
+        #TODO: what is self.autofile for?
+        #self.autofile = ''
+
+    def do_distance(self):
+        '''
+        DISTANCE
+        (generalvclamp.py)
+        Measure the distance (in nm) between two points.
+        For a standard experiment this is the delta X distance.
+        For a force clamp experiment this is the delta Y distance (actually becomes
+        an alias of zpiezo)
+        -----------------
+        Syntax: distance
+        '''
+        show_points = self.GetBoolFromConfig('generalvclamp', 'distance', 'show_points')
+        whatset_str = self.GetStringFromConfig('generalvclamp', 'distance', 'whatset')
+        whatset = 'retraction'
+        if whatset_str == 'extension':
+            whatset = lh.EXTENSION
+        if whatset_str == 'retraction':
+            whatset = lh.RETRACTION
+
+        active_file = self.GetActiveFile()
+        plot = self.GetActivePlot()
+        if active_file.driver.experiment == 'clamp':
+            self.AppendToOutput('You wanted to use zpiezo perhaps?')
+            return
+        dx, unitx, dy, unity = self._delta(message='Click 2 points to measure the distance.', show=show_points, whatset=whatset)
+        #TODO: pretty format
+        self.AppendToOutput(str(dx * (10 ** 9)) + ' nm')
+
+    def do_force(self):
+        '''
+        FORCE
+        (generalvclamp.py)
+        Measure the force difference (in pN) between two points
+        ---------------
+        Syntax: force
+        '''
+        whatset_str = self.GetStringFromConfig('generalvclamp', 'force', 'whatset')
+        whatset = 'retraction'
+        if whatset_str == 'extension':
+            whatset = lh.EXTENSION
+        if whatset_str == 'retraction':
+            whatset = lh.RETRACTION
+
+        active_file = self.GetActiveFile()
+        plot = self.GetActivePlot()
+        if active_file.driver.experiment == 'clamp':
+            self.AppendToOutput('This command makes no sense for a force clamp experiment.')
+            return
+        dx, unitx, dy, unity = self._delta(whatset=whatset, message='Click 2 points to measure the force.')
+        #TODO: pretty format
+        self.AppendToOutput(str(dy * (10 ** 12)) + ' pN')
+
+    def do_forcebase(self):
+        '''
+        FORCEBASE
+        (generalvclamp.py)
+        Measures the difference in force (in pN) between a point and a baseline
+        taken 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
+        ------------
+        Syntax: forcebase [rebase]
+                rebase: Forces forcebase to ask again the baseline
+                max: Instead of asking for a point to measure, asks for two points and use
+                     the maximum peak in between
+        '''
+        maxpoint = self.GetBoolFromConfig('generalvclamp', 'forcebase', 'max')
+        rebase = self.GetBoolFromConfig('generalvclamp', 'forcebase', 'rebase')
+        whatset_str = self.GetStringFromConfig('generalvclamp', 'forcebase', 'whatset')
+        whatset = 'retraction'
+        if whatset_str == 'extension':
+            whatset = lh.EXTENSION
+        if whatset_str == 'retraction':
+            whatset = lh.RETRACTION
+        plot = self.GetDisplayedPlotCorrected()
+
+        filename = self.GetActiveFile().name
+        if rebase or (self.basecurrent != filename):
+            self.basepoints = self._measure_N_points(N=2, message='Click on 2 points to select the baseline.', whatset=whatset)
+            self.basecurrent = filename
+
+        if maxpoint:
+            boundpoints = []
+            points = self._measure_N_points(N=2, message='Click 2 points to select the range for maximum detection.', whatset=whatset)
+            boundpoints = [points[0].index, points[1].index]
+            boundpoints.sort()
+            try:
+                y = min(plot.curves[whatset].y[boundpoints[0]:boundpoints[1]])
+            except ValueError:
+                self.AppendToOutput('Chosen interval not valid. Try picking it again. Did you pick the same point as begin and end of the interval?')
+        else:
+            points = self._measure_N_points(N=1, message='Click on the point to measure.', whatset=whatset)
+            y = points[0].graph_coords[1]
+
+        boundaries = [self.basepoints[0].index, self.basepoints[1].index]
+        boundaries.sort()
+        to_average = plot.curves[whatset].y[boundaries[0]:boundaries[1]] #y points to average
+
+        avg = np.mean(to_average)
+        forcebase = abs(y - avg)
+        #TODO: pretty format
+        self.AppendToOutput(str(forcebase * (10 ** 12)) + ' pN')
+\r
+    def plotmanip_multiplier(self, plot, current, customvalue=False):
+        '''
+        Multiplies all the Y values of an SMFS curve by a value stored in the 'force_multiplier'\r
+        configuration variable. Useful for calibrations and other stuff.
+        '''
+
+        #not a smfs curve...
+        if current.driver.experiment != 'smfs':
+            return plot
+
+        force_multiplier = self.GetFloatFromConfig('generalvclamp', 'force_multiplier')
+        if force_multiplier == 1:
+            return plot\r
+
+        plot.curves[lh.EXTENSION].y = [element * force_multiplier for element in plot.curves[lh.EXTENSION].y]
+        plot.curves[lh.RETRACTION].y = [element * force_multiplier for element in plot.curves[lh.RETRACTION].y]
+\r
+        return plot\r
+
+    def plotmanip_flatten(self, plot, current, customvalue=0):
+        '''
+        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
+        given by the configuration file or by the customvalue.
+
+        customvalue = int (>0) --> starts the function even if config says no (default=0)
+        '''
+
+        #not a smfs curve...
+        if current.driver.experiment != 'smfs':
+            return current
+
+        #config is not flatten, and customvalue flag is false too
+        #if (not self.config['generalvclamp']['flatten'].as_bool('value')) and (customvalue == 0):
+        ##TODO: do we need this?
+        #if (not self.GetBoolFromConfig('generalvclamp', 'flatten')) and (customvalue == 0):
+            #return plot
+
+        max_exponent = 12
+        delta_contact = 0
+
+        if customvalue > 0:
+            max_cycles = customvalue
+        else:
+            #Using > 1 usually doesn't help and can give artefacts. However, it could be useful too.
+            max_cycles = self.GetIntFromConfig('generalvclamp', 'max_cycles')
+
+        contact_index = self.find_contact_point(plot)
+
+        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)]
+
+        for i in range(int(max_cycles)):
+            x_ext = plot.curves[lh.EXTENSION].x[contact_index + delta_contact:]
+            y_ext = plot.curves[lh.EXTENSION].y[contact_index + delta_contact:]
+            x_ret = plot.curves[lh.RETRACTION].x[contact_index + delta_contact:]
+            y_ret = plot.curves[lh.RETRACTION].y[contact_index + delta_contact:]
+            for exponent in range(max_exponent):
+                try:
+                    valn[exponent] = sp.polyfit(x_ext, y_ext, exponent)
+                    yrn[exponent] = sp.polyval(valn[exponent], x_ret)
+                    errn[exponent] = sp.sqrt(sum((yrn[exponent] - y_ext) ** 2) / float(len(y_ext)))
+                except Exception, e:
+                    print 'Cannot flatten!'
+                    print e
+                    return current
+
+            best_exponent = errn.index(min(errn))
+
+            #extension
+            ycorr_ext = y_ext - yrn[best_exponent] + y_ext[0] #noncontact part
+            yjoin_ext = np.array(plot.curves[lh.EXTENSION].y[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.curves[lh.RETRACTION].y[0:contact_index + delta_contact]) #contact part
+
+            ycorr_ext = np.concatenate((yjoin_ext, ycorr_ext))
+            ycorr_ret = np.concatenate((yjoin_ret, ycorr_ret))
+
+            plot.curves[lh.EXTENSION].y = list(ycorr_ext)
+            plot.curves[lh.RETRACTION].y = list(ycorr_ret)
+
+        return plot
+
+    #---SLOPE---
+    def do_slope(self):
+        '''
+        SLOPE
+        (generalvclamp.py)
+        Measures the slope of a delimited chunk on the return trace.
+        The chunk can be delimited either by two manual clicks, or have
+        a fixed width, given as an argument.
+        ---------------
+        Syntax: slope [width]
+                The facultative [width] parameter specifies how many
+                points will be considered for the fit. If [width] is
+                specified, only one click will be required.
+        Copyright 2008 by Marco Brucale, Massimo Sandal
+        '''
+
+        fitspan = self.GetIntFromConfig('generalvclamp', 'slope', 'fitspan')
+        # Decides between the two forms of user input
+        #TODO: add an option 'mode' with options 'chunk' and 'point'
+        #TODO: add 'whatset' as option, too
+        if fitspan == 0:
+            # Gets the Xs of two clicked points as indexes on the curve curve vector
+            clickedpoints = []
+            points = self._measure_N_points(N=2, message='Click 2 points to select the chunk.', whatset=1)
+            clickedpoints = [points[0].index, points[1].index]
+            clickedpoints.sort()
+        else:
+            clickedpoints = []
+            points = self._measure_N_points(N=1, message='Click on the leftmost point of the chunk (i.e.usually the peak).', whatset=1)
+            clickedpoints = [points[0].index - fitspan, points[0].index]
+
+        # Calls the function linefit_between
+        parameters = [0, 0, [], []]
+        try:
+            parameters = self.linefit_between(clickedpoints[0], clickedpoints[1])
+        except:
+            self.AppendToOutput('Cannot fit. Did you click the same point twice?')
+            return
+
+        # Outputs the relevant slope parameter
+        #TODO: pretty format with units
+        self.AppendToOutput(''.join(['Slope: ', str(parameters[0])]))
+
+        #TODO: add option to keep previous slope
+        plot = self.GetDisplayedPlotCorrected()
+
+        # Makes a vector with the fitted parameters and sends it to the GUI
+        xtoplot=parameters[2]
+        ytoplot=[]
+        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])
+
+        #add the slope to the plot
+        slope = lib.curve.Curve()
+        slope.color = 'red'
+        slope.label = 'slope'
+        slope.style = 'plot'
+        slope.x = xtoplot
+        slope.y = ytoplot
+
+        #add the clicked points to the plot
+        points = lib.curve.Curve()
+        points.color = 'black'
+        points.label = 'points'
+        points.size = 10
+        points.style = 'scatter'
+        points.x = clickvector_x
+        points.y = clickvector_y
+
+        plot.curves.append(slope)
+        plot.curves.append(points)
+
+        self.UpdatePlot(plot)
+
+    def linefit_between(self, index1, index2, whatset=1):
+        '''
+        Creates two vectors (xtofit, ytofit) slicing out from the
+        curve return trace a portion delimited by the two indeces
+        given as arguments.
+        Then does a least squares linear fit on that slice.
+        Finally returns [0]=the slope, [1]=the intercept of the
+        fitted 1st grade polynomial, and [2,3]=the actual (x,y) vectors
+        used for the fit.
+        Copyright 2008 by Marco Brucale, Massimo Sandal
+        '''
+        # Translates the indeces into two vectors containing the x, y data to fit
+        plot = self.displayed_plot
+        xtofit = plot.corrected_curves[whatset].x[index1:index2]
+        ytofit = plot.corrected_curves[whatset].y[index1:index2]
+
+        # Does the actual linear fitting (simple least squares with numpy.polyfit)
+        linefit = np.polyfit(xtofit, ytofit, 1)
+
+        return (linefit[0], linefit[1], xtofit, ytofit)
+
+
+
diff --git a/plugins/pcluster.ini b/plugins/pcluster.ini
new file mode 100644 (file)
index 0000000..14eeefc
--- /dev/null
@@ -0,0 +1,10 @@
+[pcluster]\r
+auto_fit_nm = 5\r
+auto_fit_points = 50\r
+auto_left_baseline = 20\r
+auto_max_p = 10\r
+auto_min_p = 0.005\r
+auto_right_baseline = 20\r
+auto_slope_span = 20\r
+baseline_clicks = 0\r
+temperature = 301\r
diff --git a/plugins/playlist.ini b/plugins/playlist.ini
new file mode 100644 (file)
index 0000000..10de454
--- /dev/null
@@ -0,0 +1,22 @@
+[genlist]\r
+    [[folder]]\r
+        default = ""\r
+        type = folder\r
+        value = R:\Programming\Python\Gui\data\Ecoil good data set 1 week35_surface251_16.5pNnm\r
+    \r
+    [[filemask]]\r
+        default = *.*\r
+        type = string\r
+        value = *.*\r
+\r
+[loadlist]\r
+    [[filename]]\r
+        default = test.hkp\r
+        type = filename\r
+        value = R:\Programming\Python\Gui\untitled2.hkp\r
+\r
+[savelist]\r
+    [[filename]]\r
+        default = untitled.hkp\r
+        type = filename\r
+        value = R:\Programming\Python\Gui\untitled2.hkp\r
diff --git a/plugins/playlist.py b/plugins/playlist.py
new file mode 100644 (file)
index 0000000..41db26e
--- /dev/null
@@ -0,0 +1,125 @@
+#!/usr/bin/env python
+
+'''
+playlist.py
+
+Playlist commands for Hooke.
+
+Copyright 2010 by Dr. Rolf Schmidt (Concordia University, Canada)
+
+This program is released under the GNU General Public License version 2.
+'''
+
+import lib.libhooke as lh
+import wxversion
+wxversion.select(lh.WX_GOOD)
+
+import glob
+import os.path
+import wx
+
+from lib.playlist import Playlist
+
+class playlistCommands(object):
+    '''
+    Playlist commands to generate, save and load lists of force curves
+    '''
+
+    def _plug_init(self):
+        pass
+
+    def do_genlist(self, filemask='', folder=''):
+        '''
+        GENLIST
+        Generates a file playlist.
+        Note it doesn't *save* it: see savelist for this.
+
+        If [input files] is a directory, it will use all files in the directory for playlist.
+        So:
+        genlist dir
+        genlist dir/
+        genlist dir/*.*
+
+        are all equivalent syntax.
+        ------------
+        Syntax: genlist [input files]
+        '''
+        if filemask == '':
+            filemask = self.GetStringFromConfig('playlist', 'genlist', 'filemask')
+        if folder == '':
+            folder = self.GetStringFromConfig('playlist', 'genlist', 'folder')
+        if os.path.isdir(folder):
+            path = os.path.join(folder, filemask)
+            #expanding correctly the input list with the glob module :)
+            files = glob.glob(path)
+            files.sort()
+            playlist = Playlist()
+            for file_to_add in files:
+                playlist.add_file(file_to_add)
+            if playlist.count > 0:
+                playlist.name = self._GetUniquePlaylistName(os.path.basename(folder))
+                playlist.reset()
+                self.AddToPlaylists(playlist)
+            self.AppendToOutput('Playlist generated.')
+            self.AppendToOutput(playlist.get_status_string())
+        else:
+            self.AppendToOutput(''.join(['Cannot find folder ', folder]))
+
+    def do_loadlist(self, filename=''):
+        '''
+        LOADLIST
+        Loads a file playlist
+        -----------
+        Syntax: loadlist [playlist file]
+        '''
+        #TODO: check for duplicate playlists, ask the user for a unique name
+        #if self.playlist_name in self.playlists:
+        #activate playlist
+
+        if filename == '':
+            filename = self.GetStringFromConfig('playlist', 'loadlist', 'filename')
+
+        #add hkp extension if necessary
+        if not filename.endswith('.hkp'):
+            filename = ''.join([filename, '.hkp'])
+        #prefix with 'hookeDir' if just a filename or a relative path
+        filename = lh.get_file_path(filename)
+        if os.path.isfile(filename):
+            #load playlist
+            playlist_new = Playlist(filename)
+            if playlist_new.count > 0:
+                self.AppendToOutput('Playlist loaded.')
+                self.AddToPlaylists(playlist_new)
+                self.AppendToOutput(playlist_new.get_status_string())
+            else:
+                message = ''.join(['The file ', filename, ' does not contain any valid curve information.'])
+                dialog = wx.MessageDialog(None, message, 'Info', wx.OK)
+                dialog.ShowModal()
+        else:
+            message = ''.join(['File ', filename, ' not found.'])
+            dialog = wx.MessageDialog(None, message, 'Info', wx.OK)
+            dialog.ShowModal()
+
+    def do_savelist(self, filename=''):
+        '''
+        SAVELIST
+        Saves the current file playlist on disk.
+        ------------
+        Syntax: savelist [filename]
+        '''
+
+        if filename == '':
+            filename = self.GetStringFromConfig('playlist', 'savelist', 'filename')
+
+        #autocomplete filename if not specified
+        if not filename.endswith('.hkp'):
+            filename = filename.join(['.hkp'])
+
+        playlist = self.GetActivePlaylist()
+        try:
+            playlist.save(filename)
+            self.AppendToOutput('Playlist saved.')
+        except:
+            self.AppendToOutput('Playlist could not be saved.')
+
+
diff --git a/plugins/plot.ini b/plugins/plot.ini
new file mode 100644 (file)
index 0000000..d3f5a12
--- /dev/null
@@ -0,0 +1 @@
+\r
diff --git a/plugins/plot.py b/plugins/plot.py
new file mode 100644 (file)
index 0000000..beab346
--- /dev/null
@@ -0,0 +1,23 @@
+#!/usr/bin/env python
+
+'''
+plot.py
+
+Plot commands for Hooke.
+
+Copyright 2010 by Dr. Rolf Schmidt (Concordia University, Canada)
+
+This program is released under the GNU General Public License version 2.
+'''
+
+class plotCommands(object):
+    '''
+    Plot commands to replot the original data with fits (if applicable)
+    but without secondary plots (unless they are part of the original data)
+    '''
+
+    def _plug_init(self):
+        pass
+
+    def do_replot(self):
+        self.UpdatePlot()
diff --git a/plugins/procplots.ini b/plugins/procplots.ini
new file mode 100644 (file)
index 0000000..842abb9
--- /dev/null
@@ -0,0 +1,90 @@
+[convplot]\r
+    [[column]]\r
+        default = 1\r
+        maximum = 20\r
+        minimum = 1\r
+        type = integer\r
+        value = 1\r
+    \r
+    [[convolution]]\r
+        default = "[6.0, -1.0, -1.0, -1.0, -1.0, -1.0, -1.0]"\r
+        type = string\r
+        value = "[11.0,-1.0,-1.0,-1.0,-1.0,-1.0,-1.0,-1.0,-1.0,-1.0,-1.0,-1.0]"\r
+    \r
+    [[row]]\r
+        default = 2\r
+        maximum = 20\r
+        minimum = 1\r
+        type = integer\r
+        value = 2\r
+    \r
+    [[whatset]]\r
+        default = retraction\r
+        elements = extension, retraction, both\r
+        type = enum\r
+        value = retraction\r
+\r
+[derivplot]\r
+    [[column]]\r
+        default = 1\r
+        maximum = 20\r
+        minimum = 1\r
+        type = integer\r
+        value = 1\r
+    \r
+    [[row]]\r
+        default = 2\r
+        maximum = 20\r
+        minimum = 1\r
+        type = integer\r
+        value = 2\r
+    \r
+    [[select]]\r
+        default = False\r
+        type = boolean\r
+        value = False\r
+    \r
+    [[whatset]]\r
+        default = retraction\r
+        elements = extension, retraction, both\r
+        type = enum\r
+        value = both\r
+\r
+[fft]\r
+    [[column]]\r
+        default = 1\r
+        maximum = 20\r
+        minimum = 1\r
+        type = integer\r
+        value = 1\r
+    \r
+    [[row]]\r
+        default = 2\r
+        maximum = 20\r
+        minimum = 1\r
+        type = integer\r
+        value = 2\r
+    \r
+    [[select]]\r
+        default = False\r
+        type = boolean\r
+        value = False\r
+    \r
+    [[whatset]]\r
+        default = retraction\r
+        elements = extension, retraction, both\r
+        type = enum\r
+        value = both\r
+\r
+[procplots]\r
+    [[median]]\r
+        default = 0\r
+        maximum = 100\r
+        minimum = 0\r
+        type = integer\r
+        value = 7\r
+    \r
+    [[correct]]\r
+        default = True\r
+        type = boolean\r
+        value = True\r
diff --git a/plugins/procplots.py b/plugins/procplots.py
new file mode 100644 (file)
index 0000000..7324b77
--- /dev/null
@@ -0,0 +1,257 @@
+#!/usr/bin/env python
+
+'''
+procplots.py
+
+Process plots plugin for force curves.
+
+Copyright ???? by ?
+with modifications by Dr. Rolf Schmidt (Concordia University, Canada)
+
+This program is released under the GNU General Public License version 2.
+'''
+
+import lib.libhooke as lh
+import wxversion
+wxversion.select(lh.WX_GOOD)
+
+import copy
+from numpy import arange, diff, fft
+from scipy.signal import medfilt
+
+from lib.peakspot import conv_dx
+
+class procplotsCommands:
+
+    def _plug_init(self):
+        pass
+
+    def do_convplot(self):
+        '''
+        CONVPLOT
+        (procplots.py)
+        Plots the convolution data of the currently displayed force curve retraction.
+        ------------
+        Syntax:
+        convplot
+        '''
+
+        #need to convert the string that contains the list into a list
+        column = self.GetIntFromConfig('procplots', 'convplot', 'column')
+        convolution = eval(self.GetStringFromConfig('procplots', 'convplot', 'convolution'))
+        row = self.GetIntFromConfig('procplots', 'convplot', 'row')
+        whatset_str = self.GetStringFromConfig('procplots', 'convplot', 'whatset')
+        whatset = []
+        if whatset_str == 'extension':
+            whatset = [lh.EXTENSION]
+        if whatset_str == 'retraction':
+            whatset = [lh.RETRACTION]
+        if whatset_str == 'both':
+            whatset = [lh.EXTENSION, lh.RETRACTION]
+
+        #TODO: add option to keep previous derivplot
+        plot = self.GetDisplayedPlotCorrected()
+
+        for index in whatset:
+            conv_curve = copy.deepcopy(plot.curves[index])
+            #Calculate convolution
+            conv_curve.y = conv_dx(plot.curves[index].y, convolution)
+
+            conv_curve.destination.column = column
+            conv_curve.destination.row = row
+            conv_curve.title = 'Convolution'
+            plot.curves.append(conv_curve)
+
+        #warn if no flattening has been done.
+        if not self.AppliesPlotmanipulator('flatten'):
+            self.AppendToOutput('Flatten manipulator was not applied. Processing was done without flattening.')
+            self.AppendToOutput('Enable the flatten plotmanipulator for better results.')
+
+        self.UpdatePlot(plot)
+
+
+    def do_derivplot(self):
+        '''
+        DERIVPLOT
+        (procplots.py plugin)
+        Plots the discrete differentiation of the currently displayed force curve retraction
+        ---------
+        Syntax: derivplot
+        '''
+        column = self.GetIntFromConfig('procplots', 'derivplot', 'column')
+        row = self.GetIntFromConfig('procplots', 'derivplot', 'row')
+        select = self.GetBoolFromConfig('procplots', 'derivplot', 'select')
+        whatset_str = self.GetStringFromConfig('procplots', 'derivplot', 'whatset')
+        whatset = []
+        if whatset_str == 'extension':
+            whatset = [lh.EXTENSION]
+        if whatset_str == 'retraction':
+            whatset = [lh.RETRACTION]
+        if whatset_str == 'both':
+            whatset = [lh.EXTENSION, lh.RETRACTION]
+
+        #TODO: add option to keep previous derivplot
+        plot = self.GetDisplayedPlotCorrected()
+
+        for index in whatset:
+            deriv_curve = copy.deepcopy(plot.curves[index])
+            deriv_curve.x = deriv_curve.x[:-1]
+            deriv_curve.y = diff(deriv_curve.y).tolist()
+
+            deriv_curve.destination.column = column
+            deriv_curve.destination.row = row
+            deriv_curve.title = 'Discrete differentiation'
+            deriv_curve.units.y += ' ' + deriv_curve.units.x + '-1'
+            plot.curves.append(deriv_curve)
+
+        self.UpdatePlot(plot)
+
+    def do_subtplot(self):
+        '''
+        SUBTPLOT
+        (procplots.py plugin)
+        Plots the difference between retraction and extension of the currently displayed curve
+        -------
+        Syntax: subtplot
+        '''
+        #TODO: what is sub_filter supposed to do?
+
+        #TODO: add option to keep previous subtplot
+        plot = self.GetDisplayedPlotCorrected()
+
+        extension = plot.curves[lh.EXTENSION]
+        retraction = plot.curves[lh.RETRACTION]
+
+        extension, retraction = self.subtract_curves(extension, retraction)
+
+        self.UpdatePlot(plot)
+
+    def subtract_curves(self, minuend, subtrahend):
+        '''
+        calculates: difference = minuend - subtrahend
+        (usually:              extension - retraction
+        '''
+
+        #we want the same number of points for minuend and subtrahend
+        #TODO: is this not already done when normalizing in the driver?
+        maxpoints_tot = min(len(minuend.x), len(subtrahend.x))
+        minuend.x = minuend.x[0:maxpoints_tot]
+        minuend.y = minuend.y[0:maxpoints_tot]
+        subtrahend.x = subtrahend.x[0:maxpoints_tot]
+        subtrahend.y = subtrahend.y[0:maxpoints_tot]
+
+        subtrahend.y = [y_subtrahend - y_minuend for y_subtrahend, y_minuend in zip(subtrahend.y, minuend.y)]
+        minuend.y = [0] * len(minuend.x)
+
+        return minuend, subtrahend
+
+#-----PLOT MANIPULATORS
+    def plotmanip_median(self, plot, current, customvalue=False):
+        '''
+        does the median of the y values of a plot
+        '''
+        median_filter = self.GetIntFromConfig('procplots', 'median')
+        if median_filter == 0:
+            return plot
+
+        if float(median_filter) / 2 == int(median_filter) / 2:
+            median_filter += 1
+
+        for curve in plot.curves:
+            curve.y = medfilt(curve.y, median_filter).tolist()
+
+        return plot
+
+    def plotmanip_correct(self, plot, current, customvalue=False):
+        '''
+        does the correction for the deflection for a force spectroscopy curve.
+        Assumes that:
+        - the current plot has a deflection() method that returns a vector of values
+        - the deflection() vector is as long as the X of extension + the X of retraction
+        - plot.vectors[0][0] is the X of extension curve
+        - plot.vectors[1][0] is the X of retraction curve
+
+        FIXME: both this method and the picoforce driver have to be updated, deflection() must return
+        a more sensible data structure!
+        '''
+        #use only for force spectroscopy experiments!
+        if current.driver.experiment != 'smfs':
+            return plot
+
+        if not customvalue:
+            customvalue = self.GetBoolFromConfig('procplots', 'correct')
+        if not customvalue:
+            return plot
+
+        defl_ext, defl_ret = current.driver.deflection()
+
+        plot.curves[lh.EXTENSION].x = [(zpoint - deflpoint) for zpoint,deflpoint in zip(plot.curves[lh.EXTENSION].x, defl_ext)]
+        plot.curves[lh.RETRACTION].x = [(zpoint - deflpoint) for zpoint,deflpoint in zip(plot.curves[lh.RETRACTION].x, defl_ret)]
+
+        return plot
+
+#FFT---------------------------
+    def fft_plot(self, curve, boundaries=[0, -1]):
+        '''
+        calculates the fast Fourier transform for the selected vector in the plot
+        '''
+
+        fftlen = len(curve.y[boundaries[0]:boundaries[1]]) / 2 #need just 1/2 of length
+        curve.x = arange(1, fftlen).tolist()
+
+        try:
+            curve.y = abs(fft(curve.y[boundaries[0]:boundaries[1]])[1:fftlen]).tolist()
+        except TypeError: #we take care of newer NumPy (1.0.x)
+            curve.y = abs(fft.fft(curve.y[boundaries[0]:boundaries[1]])[1:fftlen]).tolist()
+
+        return curve
+
+    def do_fft(self):
+        '''
+        FFT
+        (procplots.py plugin)
+        Plots the fast Fourier transform of the selected plot
+        ---
+        Syntax: fft [top,bottom] [select] [0,1...]
+
+        By default, fft performs the Fourier transform on all the 0-th data set on the
+        top plot.
+
+        [top, bottom]: which plot is the data set to fft (default: top)
+        [select]: you pick up two points on the plot and fft only the segment between
+        [0,1,...]: which data set on the selected plot you want to fft (default: 0)
+        '''
+
+        column = self.GetIntFromConfig('procplots', 'fft', 'column')
+        row = self.GetIntFromConfig('procplots', 'fft', 'row')
+        select = self.GetBoolFromConfig('procplots', 'fft', 'select')
+        whatset_str = self.GetStringFromConfig('procplots', 'fft', 'whatset')
+        whatset = []
+        if whatset_str == 'extension':
+            whatset = [lh.EXTENSION]
+        if whatset_str == 'retraction':
+            whatset = [lh.RETRACTION]
+        if whatset_str == 'both':
+            whatset = [lh.EXTENSION, lh.RETRACTION]
+
+        if select:
+            points = self._measure_N_points(N=2, message='Please select a region by clicking on the start and the end point.', whatset=1)
+            boundaries = [points[0].index, points[1].index]
+            boundaries.sort()
+        else:
+            boundaries = [0, -1]
+
+        #TODO: add option to keep previous FFT
+        plot = self.GetDisplayedPlotCorrected()
+
+        for index in whatset:
+            fft_curve = self.fft_plot(copy.deepcopy(plot.curves[index]), boundaries)
+
+            fft_curve.destination.column = column
+            fft_curve.destination.row = row
+            fft_curve.title = 'FFT'
+            fft_curve.units.x = 'frequency'
+            fft_curve.units.y = 'power'
+            plot.curves.append(fft_curve)
+
+        self.UpdatePlot(plot)
diff --git a/plugins/results.ini b/plugins/results.ini
new file mode 100644 (file)
index 0000000..ef4cea2
--- /dev/null
@@ -0,0 +1,6 @@
+[show_results]\r
+    [[fit_function]]\r
+        default = wlc\r
+        elements = wlc, fjc, fjcPEG\r
+        type = enum\r
+        value = wlc\r
diff --git a/plugins/results.py b/plugins/results.py
new file mode 100644 (file)
index 0000000..8476882
--- /dev/null
@@ -0,0 +1,29 @@
+#!/usr/bin/env python
+
+'''
+results.py
+
+Results commands for Hooke.
+
+Copyright 2010 by Dr. Rolf Schmidt (Concordia University, Canada)
+
+This program is released under the GNU General Public License version 2.
+'''
+
+class resultsCommands(object):
+    '''
+    Results commands to show a certain type of results and to clear results
+    '''
+
+    def _plug_init(self):
+        pass
+    
+    def do_clear_results(self):
+        plot = self.GetActivePlot()
+        if plot is not None:
+            plot.results.clear()
+        self.UpdatePlot()
+
+
+    def do_show_results(self):
+        self.UpdatePlot()
diff --git a/procplots.py b/procplots.py
deleted file mode 100755 (executable)
index f1cc0a3..0000000
+++ /dev/null
@@ -1,251 +0,0 @@
-#!/usr/bin/env python
-
-'''
-PROCPLOTS
-Processed plots plugin for force curves.
-
-Licensed under the GNU GPL version 2
-'''
-from libhooke import WX_GOOD
-import wxversion
-wxversion.select(WX_GOOD)
-
-import wx
-import libhookecurve as lhc
-import numpy as np
-import scipy as sp
-import scipy.signal
-import copy
-
-class procplotsCommands:
-    
-    def _plug_init(self):
-        pass
-               
-    def do_derivplot(self,args):
-        '''
-        DERIVPLOT
-        (procplots.py plugin)
-        Plots the derivate (actually, the discrete differentiation) of the current force curve
-        ---------
-        Syntax: derivplot
-        '''                
-        dplot=self.derivplot_curves()               
-        plot_graph=self.list_of_events['plot_graph']       
-        wx.PostEvent(self.frame,plot_graph(plots=[dplot]))
-        
-    def derivplot_curves(self):
-        '''
-        do_derivplot helper function
-        
-        create derivate plot curves for force curves.
-        '''    
-        dplot=lhc.PlotObject()
-        dplot.vectors=[]       
-        
-        for vector in self.plots[0].vectors:
-            dplot.vectors.append([])
-            dplot.vectors[-1].append(vector[0][:-1])
-            dplot.vectors[-1].append(np.diff(vector[1]))
-        
-        dplot.destination=1
-        dplot.units=self.plots[0].units
-        
-        return dplot        
-            
-    def do_subtplot(self,args):
-        '''
-        SUBTPLOT
-        (procplots.py plugin)
-        Plots the difference between ret and ext current curve
-        -------
-        Syntax: subtplot
-        '''
-        #FIXME: sub_filter and sub_order must be args
-        
-        if len(self.plots[0].vectors) != 2:
-            print 'This command only works on a curve with two different plots.'
-            pass
-        
-        outplot=self.subtract_curves(sub_order=1)
-        
-        plot_graph=self.list_of_events['plot_graph']       
-        wx.PostEvent(self.frame,plot_graph(plots=[outplot]))
-        
-    def subtract_curves(self, sub_order):
-        '''
-        subtracts the extension from the retraction
-        ''' 
-        xext=self.plots[0].vectors[0][0]
-        yext=self.plots[0].vectors[0][1]
-        xret=self.plots[0].vectors[1][0]
-        yret=self.plots[0].vectors[1][1]
-        
-        #we want the same number of points
-        maxpoints_tot=min(len(xext),len(xret))
-        xext=xext[0:maxpoints_tot]
-        yext=yext[0:maxpoints_tot]
-        xret=xret[0:maxpoints_tot]
-        yret=yret[0:maxpoints_tot]
-    
-        if sub_order:
-            ydiff=[yretval-yextval for yretval,yextval in zip(yret,yext)]
-        else: #reverse subtraction (not sure it's useful, but...)
-            ydiff=[yextval-yretval for yextval,yretval in zip(yext,yret)]    
-        
-        outplot=copy.deepcopy(self.plots[0])
-        outplot.vectors[0][0], outplot.vectors[1][0] = xext,xret #FIXME: if I use xret, it is not correct!
-        outplot.vectors[1][1]=ydiff
-        outplot.vectors[0][1]=[0 for item in outplot.vectors[1][0]]
-        
-        return outplot
-
-
-#-----PLOT MANIPULATORS
-    def plotmanip_median(self, plot, current, customvalue=None):
-        '''
-        does the median of the y values of a plot
-        '''
-        if customvalue:
-            median_filter=customvalue
-        else:
-            median_filter=self.config['medfilt']
-         
-        if median_filter==0:
-            return plot
-         
-        if float(median_filter)/2 == int(median_filter)/2:
-            median_filter+=1
-            
-        nplots=len(plot.vectors)
-        c=0
-        while c<nplots:
-            plot.vectors[c][1]=scipy.signal.medfilt(plot.vectors[c][1],median_filter)
-            c+=1
-        
-        return plot
-    
-
-    def plotmanip_correct(self, plot, current, customvalue=None):
-        '''
-        does the correction for the deflection for a force spectroscopy curve.
-        Assumes that:
-        - the current plot has a deflection() method that returns a vector of values
-        - the deflection() vector is as long as the X of extension + the X of retraction
-        - plot.vectors[0][0] is the X of extension curve
-        - plot.vectors[1][0] is the X of retraction curve
-        
-        FIXME: both this method and the picoforce driver have to be updated, deflection() must return
-        a more senseful data structure!
-        '''
-        #use only for force spectroscopy experiments!
-        if current.curve.experiment != 'smfs':
-            return plot
-    
-        if customvalue != None:
-            execute_me=customvalue
-        else:
-            execute_me=self.config['correct']
-        if not execute_me:
-            return plot
-     
-        defl_ext,defl_ret=current.curve.deflection()
-        #halflen=len(deflall)/2
-    
-        plot.vectors[0][0]=[(zpoint-deflpoint) for zpoint,deflpoint in zip(plot.vectors[0][0],defl_ext)]
-        plot.vectors[1][0]=[(zpoint-deflpoint) for zpoint,deflpoint in zip(plot.vectors[1][0],defl_ret)]
-
-        return plot
-    
-    '''
-    def plotmanip_detriggerize(self, plot, current, customvalue=None):
-        #DEPRECATED
-        if self.config['detrigger']==0:
-            return plot
-        
-        cutindex=2
-        startvalue=plot.vectors[0][0][0]
-        
-        for index in range(len(plot.vectors[0][0])-1,2,-2):  
-           if plot.vectors[0][0][index]>startvalue:
-                cutindex=index
-           else:
-                break
-
-        plot.vectors[0][0]=plot.vectors[0][0][:cutindex]
-        plot.vectors[0][1]=plot.vectors[0][1][:cutindex]
-        
-        return plot
-    '''       
-           
-           
-    
-#FFT---------------------------
-    def fft_plot(self, vector):
-        '''
-        calculates the fast Fourier transform for the selected vector in the plot
-        '''
-        fftplot=lhc.PlotObject()
-        fftplot.vectors=[[]]
-               
-        fftlen=len(vector)/2 #need just 1/2 of length
-        fftplot.vectors[-1].append(np.arange(1,fftlen).tolist()) 
-        
-        try:
-            fftplot.vectors[-1].append(abs(np.fft(vector)[1:fftlen]).tolist())
-        except TypeError: #we take care of newer NumPy (1.0.x)
-            fftplot.vectors[-1].append(abs(np.fft.fft(vector)[1:fftlen]).tolist())
-        
-        
-        fftplot.destination=1
-        
-        
-        return fftplot
-        
-    
-    def do_fft(self,args):
-        '''
-        FFT
-        (procplots.py plugin)
-        Plots the fast Fourier transform of the selected plot
-        ---
-        Syntax: fft [top,bottom] [select] [0,1...]
-        
-        By default, fft performs the Fourier transform on all the 0-th data set on the
-        top plot.
-        
-        [top,bottom]: which plot is the data set to fft (default: top)
-        [select]: you pick up two points on the plot and fft only the segment between
-        [0,1,...]: which data set on the selected plot you want to fft (default: 0)
-        '''
-        
-        #args parsing
-        #whatplot = plot to fft
-        #whatset = set to fft in the plot
-        select=('select' in args)
-        if 'top' in args:
-            whatplot=0
-        elif 'bottom' in args:
-            whatplot=1
-        else:
-            whatplot=0
-        whatset=0
-        for arg in args:
-            try:
-                whatset=int(arg)
-            except ValueError:
-                pass
-        
-        if select:
-            points=self._measure_N_points(N=2, whatset=whatset)
-            boundaries=[points[0].index, points[1].index]
-            boundaries.sort()
-            y_to_fft=self.plots[whatplot].vectors[whatset][1][boundaries[0]:boundaries[1]] #y
-        else:
-            y_to_fft=self.plots[whatplot].vectors[whatset][1] #y
-        
-        fftplot=self.fft_plot(y_to_fft)               
-        fftplot.units=['frequency', 'power']
-        plot_graph=self.list_of_events['plot_graph']       
-        wx.PostEvent(self.frame,plot_graph(plots=[fftplot]))
-        
\ No newline at end of file
old mode 100755 (executable)
new mode 100644 (file)
similarity index 100%
rename from hooke.jpg
rename to resources/hooke.jpg
diff --git a/resources/microscope.ico b/resources/microscope.ico
new file mode 100644 (file)
index 0000000..6841f38
Binary files /dev/null and b/resources/microscope.ico differ
diff --git a/superimpose.py b/superimpose.py
deleted file mode 100644 (file)
index fdd0a33..0000000
+++ /dev/null
@@ -1,98 +0,0 @@
-#!/usr/bin/env python
-
-from libhooke import WX_GOOD
-import wxversion
-wxversion.select(WX_GOOD)
-from wx import PostEvent
-
-import libhookecurve as lhc
-from numpy import arange, mean
-
-class superimposeCommands:
-    
-    def _plug_init(self):
-        self.imposed=[]
-    
-    def do_selimpose(self,args):
-        '''
-        SELIMPOSE (superimpose.py plugin)
-        Hand-selects the curve portion to superimpose
-        '''
-        #fixme: set to superimpose should be in args
-        
-        if args=='clear':
-            self.imposed=[]
-            return
-        
-        current_set=1
-        
-        points=self._measure_two_points()
-        boundaries=[points[0].index, points[1].index]
-        boundaries.sort()
-        
-        theplot=self.plots[0]
-        #append the selected section
-        self.imposed.append([])
-        self.imposed[-1].append(theplot.vectors[1][0][boundaries[0]:boundaries[1]]) #x
-        self.imposed[-1].append(theplot.vectors[1][1][boundaries[0]:boundaries[1]]) #y
-        
-        #align X first point
-        self.imposed[-1][0] = [item-self.imposed[-1][0][0] for item in self.imposed[-1][0]]
-        #align Y first point
-        self.imposed[-1][1] = [item-self.imposed[-1][1][0] for item in self.imposed[-1][1]]
-                
-    def do_plotimpose(self,args):
-        '''
-        PLOTIMPOSE (sumperimpose.py plugin)
-        plots superimposed curves
-        '''
-        imposed_object=lhc.PlotObject()
-        imposed_object.vectors=self.imposed
-        print 'Plotting',len(imposed_object.vectors),'imposed curves'
-        
-        imposed_object.normalize_vectors()
-        
-        imposed_object.units=self.plots[0].units
-        imposed_object.title='Imposed curves'
-        imposed_object.destination=1
-        
-        plot_graph=self.list_of_events['plot_graph']       
-        PostEvent(self.frame,plot_graph(plots=[imposed_object]))
-        
-    def do_plotavgimpose(self,args):
-        '''
-        PLOTAVGIMPOSE (superimpose.py plugin)
-        Plots the average of superimposed curves using a running window
-        '''
-        step=(-5*(10**-10))
-        #find extension of each superimposed curve
-        min_x=[]
-        for curve in self.imposed:
-            min_x.append(min(curve[0]))
-            
-        #find minimum extension
-        min_ext_limit=max(min_x)
-        
-        x_avg=arange(step,min_ext_limit,step)
-        y_avg=[]
-        for value in x_avg:
-            to_avg=[]
-            for curve in self.imposed:
-                for xvalue, yvalue in zip(curve[0],curve[1]):
-                    if xvalue >= (value+step) and xvalue <= (value-step):
-                        to_avg.append(yvalue)                                 
-            y_avg.append(mean(to_avg))
-        
-        print 'len x len y'
-        print len(x_avg), len(y_avg)
-        print y_avg
-            
-        avg_object=lhc.PlotObject()
-        avg_object.vectors=[[x_avg, y_avg]]
-        avg_object.normalize_vectors()
-        avg_object.units=self.plots[0].units
-        avg_object.title="Average curve"
-        avg_object.destination=1
-         
-        plot_graph=self.list_of_events['plot_graph']       
-        PostEvent(self.frame,plot_graph(plots=[avg_object]))
\ No newline at end of file
diff --git a/test.hkp b/test.hkp
deleted file mode 100644 (file)
index da648f4..0000000
--- a/test.hkp
+++ /dev/null
@@ -1,5 +0,0 @@
-<?xml version="1.0" ?>
-<playlist>
-<generics pointer="0"/>
-<element notes="" path="default.000"/>
-</playlist>
\ No newline at end of file
diff --git a/tutorial.py b/tutorial.py
deleted file mode 100755 (executable)
index f9f2f33..0000000
+++ /dev/null
@@ -1,538 +0,0 @@
-#!/usr/bin/env python
-
-'''
-TUTORIAL PLUGIN FOR HOOKE
-
-This plugin contains example commands to teach how to write an Hooke plugin, including description of main Hooke
-internals.
-(c)Massimo Sandal 2007
-'''
-
-import libhookecurve as lhc
-
-import numpy as np
-
-'''
-SYNTAX OF DATA TYPE DECLARATION:
-    type = type of object
-    [ type ] = list containing objects of type
-    {typekey:typearg} = dictionary with keys of type typekey and args of type typearg
-    ( type ) = tuple containing objects of type
-'''
-
-
-class tutorialCommands:
-    '''
-    Here we define the class containing all the Hooke commands we want to define
-    in the plugin.
-    
-    Notice the class name!!
-    The syntax is filenameCommands. That is, if your plugin is pluggy.py, your class
-    name is pluggyCommands.
-    
-    Otherwise, the class will be ignored by Hooke.
-    ''' 
-    
-    def _plug_init(self):
-        '''
-        This is the plugin initialization.
-        When Hooke starts and the plugin is loaded, this function is executed.
-        If there is something you need to do when Hooke starts, code it in this function.
-        '''
-        print 'I am the Tutorial plugin initialization!'
-        
-        #Here we initialize a local configuration variable; see plotmanip_absvalue() for explanation.
-        self.config['tutorial_absvalue']=0 
-        pass
-    
-    def do_nothing(self,args):
-        '''
-        This is a boring but working example of an actual Hooke command.
-        A Hooke command is a function of the xxxxCommands class, which is ALWAYS defined
-        this way:
-        
-        def do_nameofcommand(self,args)
-        
-        *do_            is needed to make Hooke understand this function is a command
-        *nameofcommand  is how the command will be called in the Hooke command line.
-        *self           is, well, self
-        *args           is ALWAYS needed (otherwise Hooke will crash executing the command). We will see
-                        later what args is.
-        
-        Note that if you now start Hooke with this plugin activated and you type in the Hooke command
-        line "help nothing" you will see this very text as output. So the help of a command is a
-        string comment below the function definition, like this one.
-        
-        Commands usually return None.
-        '''
-        print 'I am a Hooke command. I do nothing.'
-        
-    def do_printargs(self,args):
-        '''
-        This command prints the args you give to it.
-        args is always a string, that contains everything you write after the command.
-        So if you issue "mycommand blah blah 12345" args is "blah blah 12345".
-        
-        Again, args is needed in the definition even if your command does not use it.
-        '''
-        print 'You gave me those args: '+args
-        
-    def help_tutorial(self):
-        '''
-        This is a help function. 
-        If you want a help function for something that is not a command, you can write a help
-        function like this. Calling "help tutorial" will execute this function.
-        '''
-        print 'You called help_tutorial()'
-        
-    def do_environment(self,args):
-        '''
-        This plugin contains a panoramic of the Hooke command line environment variables,
-        and prints their current value.
-        '''
-        
-        '''self.current_list
-        TYPE: [ libhookecurve.HookeCurve ], len=variable
-        contains the actual playlist of Hooke curve objects.
-        Each HookeCurve object represents a reference to a data file.
-        We will see later in detail how do they work.
-        '''
-        print 'current_list length:',len(self.current_list)
-        print 'current_list 0th:',self.current_list[0]
-        
-        '''self.pointer
-        TYPE: int
-        contains the index of
-        the current curve in the playlist
-        '''
-        print 'pointer: ',self.pointer
-        
-        '''self.current
-        TYPE: libhookecurve.HookeCurve
-        contains the current curve displayed.
-        We will see later how it works.
-        '''
-        print 'current:',self.current
-        
-        '''self.plots
-        TYPE: [ libhookecurve.PlotObject ], len=1,2
-        contains the current default plots.
-        Each PlotObject contains all info needed to display 
-        the plot: apart from the data vectors, the title, destination
-        etc.
-        Usually self.plots[0] is the default topmost plot, self.plots[1] is the
-        accessory bottom plot.
-        '''
-        print 'plots:',self.plots
-        
-        '''self.config
-        TYPE: { string:anything }
-        contains the current Hooke configuration variables, in form of a dictionary.
-        '''
-        print 'config:',self.config
-        
-        '''self.plotmanip
-        TYPE: [ function ]
-        Contains the ordered plot manipulation functions.
-        These functions are called to modify the default plot by default before it is plotted.
-        self.plots contains the plot passed through the plot manipulators.
-        We will see it better later.
-        *YOU SHOULD NEVER MODIFY THAT*
-        '''
-        print 'plotmanip: ',self.plotmanip
-        
-        '''self.drivers
-        TYPE: [ class ]
-        Contains the plot reading drivers.
-        *YOU SHOULD NEVER MODIFY THAT*
-        '''
-        print 'drivers: ',self.drivers
-        
-        '''self.frame
-        TYPE: wx.Frame
-        Contains the wx Frame of the GUI.
-        ***NEVER, EVER TOUCH THAT.***
-        '''
-        print 'frame: ',self.frame
-        
-        '''self.list_of_events
-        TYPE: { string:wx.Event }
-        Contains the wx.Events to communicate with the GUI.
-        Usually not necessary to use it, unless you want
-        to create a GUI plugin.
-        '''
-        print 'list of events:',self.list_of_events
-        
-        '''self.events_from_gui
-        TYPE: Queue.Queue
-        Contains the Queue where data from the GUI is put.
-        Usually not necessary to use it, unless you want
-        to create a GUI plugin.
-        '''
-        print 'events from gui:',self.events_from_gui
-        
-        '''self.playlist_saved
-        TYPE: Int (0/1) ; Boolean
-        Flag that tells if the playlist has been saved or not.
-        '''
-        print 'playlist saved:',self.playlist_saved
-        
-        '''self.playlist_name
-        TYPE: string
-        Name of current playlist
-        '''
-        print 'playlist name:',self.playlist_name
-        
-        '''self.notes_saved
-        TYPE: Int (0/1) ; Boolean
-        Flag that tells if the playlist has been saved or not.
-        '''
-        print 'notes saved:',self.notes_saved
-        
-
-    def do_myfirstplot(self,args):
-        '''
-        In this function, we see how to create a PlotObject and send it to the screen.
-        ***Read the code of PlotObject in libhookecurve.py before!***.
-        '''
-        
-        #We generate some interesting data to plot for this example.
-        xdata1=np.arange(-5,5,0.1)
-        xdata2=np.arange(-5,5,0.1)
-        ydata1=[item**2 for item in xdata1]
-        ydata2=[item**3 for item in xdata2]
-        
-        #Create the object.
-        #The PlotObject class lives in the libhookecurve library.
-        myplot=lhc.PlotObject()
-        '''
-        The *data* of the plot live in the .vectors list. 
-        
-        plot.vectors is a multidimensional array:
-        plot.vectors[0]=set1
-        plot.vectors[1]=set2
-        plot.vectors[2]=sett3
-        etc.
-        
-        2 curves in a x,y plot are:
-        [[[x1],[y1]],[[x2],[y2]]]
-        for example:
-            x1          y1              x2         y2
-        [[[1,2,3,4],[10,20,30,40]],[[3,6,9,12],[30,60,90,120]]]
-        x1 = self.vectors[0][0]
-        y1 = self.vectors[0][1]
-        x2 = self.vectors[1][0]
-        y2 = self.vectors[1][1]
-        '''
-        #Pour 0-th dataset into myplot: 
-        myplot.add_set(xdata1,ydata1)
-        
-        #Pour 1-st dataset into myplot: 
-        myplot.add_set(xdata2,ydata2)
-        
-        #Add units to x and y axes
-        #units=[string, string]
-        myplot.units=['x axis','y axis']
-        
-        #Where do we want the plot? 0=top, 1=bottom
-        myplot.destination=1
-        
-        '''Send it to the GUI.
-        Note that you *have* to encapsulate it into a list, so you
-        have to send [myplot], not simply myplot.
-        
-        You can also send more two plots at once
-        self.send_plot([plot1,plot2])
-        '''
-        self._send_plot([myplot])
-        
-
-    def do_myfirstscatter(self,args):
-        '''
-        How to draw a scatter plot.
-        '''
-        #We generate some interesting data to plot for this example.
-        xdata1=np.arange(-5,5,1)
-        xdata2=np.arange(-5,5,1)
-        ydata1=[item**2 for item in xdata1]
-        ydata2=[item**3 for item in xdata2]
-        
-        myplot=lhc.PlotObject()
-        myplot.add_set(xdata1,ydata1)
-        myplot.add_set(xdata2,ydata2)
-        
-        
-        #Add units to x and y axes
-        myplot.units=['x axis','y axis']
-        
-        #Where do we want the plot? 0=top, 1=bottom
-        myplot.destination=1
-        
-        '''None=standard line plot
-        'scatter'=scatter plot
-        By default, the styles attribute is an empty list. If you
-        want to define a scatter plot, you must define all other
-        plots as None or 'scatter', depending on what you want.
-        
-        Here we define the second set to be plotted as scatter,
-        and the first to be plotted as line.
-        
-        Here we define also the colors to be the default Matplotlib colors
-        '''
-        myplot.styles=[None,'scatter']
-        myplot.colors=[None,None]
-        self._send_plot([myplot])
-        
-
-    def do_clickaround(self,args):
-        '''
-        Here we click two points on the curve and take some parameters from the points
-        we have clicked.
-        '''
-        
-        '''
-        points = self._measure_N_points(N=Int, whatset=Int)
-        *N = number of points to measure(1...n)
-        *whatset = data set to measure (0,1...n)
-        *points = a list of ClickedPoint objects, one for each point requested
-        '''
-        points=self._measure_N_points(N=2,whatset=1)
-        print 'You clicked the following points.'
-        
-        '''
-        These are the absolute coordinates of the
-        point clicked. 
-        [float, float] = x,y
-        '''
-        print 'Absolute coordinates:'
-        print points[0].absolute_coords
-        print points[1].absolute_coords
-        print
-        
-        '''
-        These are the coordinates of the points
-        clicked, remapped on the graph.
-        Hooke looks at the graph point which X
-        coordinate is next to the X coordinate of
-        the point measured, and uses that point
-        as the actual clicked point.
-        [float, float] = x,y
-        '''
-        print 'Coordinates on the graph:'
-        print points[0].graph_coords
-        print points[1].graph_coords
-        print
-        
-        '''
-        These are the indexes of the clicked points
-        on the dataset vector.
-        '''
-        print 'Index of points on the graph:'
-        print points[0].index
-        print points[1].index
-        
-        
-    def help_thedifferentplots(self):
-        '''
-        The *three* different default plots you should be familiar with
-        in Hooke.
-        
-        Each plot contains of course the respective data in their
-        vectors attribute, so here you learn also which data access for
-        each situation.
-        '''
-        print '''
-        1. THE RAW, CURRENT PLOTS
-        
-        self.current
-        ---
-        Contains the current libhookecurve.HookeCurve container object.
-        A HookeCurve object defines only two default attributes:
-        
-        * self.current.path = string
-        The path of the current displayed curve
-        
-        * self.current.curve = libhookecurve.Driver
-        The curve object. This is not only generated by the driver,
-        this IS a driver instance in itself.
-        This means that in self.current.curve you can access the
-        specific driver APIs, if you know them.
-        
-        And defines only one method:
-        * self.current.identify()
-        Fills in the self.current.curve object.
-        See in the cycling tutorial.
-        
-        *****
-        The REAL curve data actually lives in:
-        ---
-        * self.current.curve.default_plots() = [ libhooke.PlotObject ]
-        Contains the raw PlotObject-s, as "spitted out" by the driver, without any
-        intervention.
-        This is as close to the raw data as Hooke gets.
-        
-        One or two plots can be spit out; they are always enclosed in a list.
-        *****
-        
-        Methods of self.current.curve are:
-        ---
-        
-        * self.current.curve.is_me()
-        (Used by identify() only.)
-        
-        * self.current.curve.close_all()
-        Closes all driver open files; see the cycling tutorial.
-        '''
-        
-        print '''
-        2. THE PROCESSED, DEFAULT PLOT
-        
-        The plot that is spitted out by the driver is *not* the usual default plot
-        that is displayed by calling "plot" at the Hooke prompt.
-        
-        This is because the raw, driver-generated plot is usually *processed* by so called
-        *plot processing* functions. We will see in the tutorial how to define
-        them. 
-        
-        For example, in force spectroscopy force curves, raw data are automatically corrected
-        for deflection. Other data can be, say, filtered by default.
-                
-        The default plots are accessible in 
-        self.plots = [ libhooke.PlotObject ]
-        
-        self.plots[0] is usually the topmost plot
-        self.plots[1] is usually the bottom plot (if present)
-        '''
-        
-        print '''
-        3. THE PLOT DISPLAYED RIGHT NOW.
-        
-        Sometimes the plots you are displaying *right now* is different from the previous
-        two. You may have a fit trace, you may have issued some command that spits out
-        a custom plot and you want to rework that, whatever. 
-        
-        You can obtain in any moment the plot currently displayed by Hooke by issuing
-        
-        PlotObject = self._get_displayed_plot(dest)
-        * dest = Int (0/1)
-        dest=0 : top plot
-        dest=1 : bottom plot
-        '''
-    
-    
-    def do_cycling(self,args):
-        '''
-        Here we cycle through our playlist and print some info on the curves we find.
-        Cycling through the playlist needs a bit of care to avoid memory leaks and dangling
-        open files...
-        
-        Look at the source code for more information.
-        '''
-        
-        def things_when_cycling(item):
-            '''
-            We encapsulate here everything has to open the actual curve file.
-            By doing it all here, we avoid to do acrobacies when deleting objects etc.
-            in the main loop: we do the dirty stuff here.
-            '''
-            
-            '''
-            identify()
-        
-            This method looks for the correct driver in self.drivers to use;
-            and puts the curve content in the .curve attribute.
-            Basically, until identify() is called, the HookeCurve object
-            is just an empty shell. When identify() is called (usually by
-            the Hooke plot routine), the HookeCurve object is "filled" with
-            the actual curve.
-            '''
-          
-            item.identify(self.drivers)
-            
-            '''
-            After the identify(), item.curve contains the curve, and item.curve.default_plots() behaves exactly like
-            self.current.curve.default_plots() -but for the given item.
-            '''
-            itplot=item.curve.default_plots()
-            
-            print 'length of X1 vector:',len(itplot[0].vectors[0][0]) #just to show something
-            
-            '''
-            The following three lines are a magic spell you HAVE to do
-            before closing the function.
-            (Otherwise you will be plagued by unpredicatable, system-dependent bugs.)
-            '''
-            item.curve.close_all() #Avoid open files dangling
-            del item.curve #Avoid memory leaks
-            del item #Just be paranoid. Don't ask.
-            
-            return
-        
-        
-        c=0
-        for item in self.current_list:
-            print 'Looking at curve ',c,'of',len(self.current_list)
-            things_when_cycling(item)
-            c+=1
-        
-        return
-        
-            
-        
-    def plotmanip_absvalue(self, plot, current, customvalue=None):
-        '''
-        This function defines a PLOT MANIPULATOR.
-        A plot manipulator is a function that takes a plot in input, does something to the plot
-        and returns the modified plot in output.
-        The function, once plugged, gets automatically called everytime self.plots is updated
-        
-        For example, in force spectroscopy force curves, raw data are automatically corrected
-        for deflection. Other data can be, say, filtered by default.
-        
-        To create and activate a plot manipulator you have to:
-            * Write a function (like this) which name starts with "plotmanip_" (just like commands
-              start with "do_")
-            * The function must support four arguments:
-              self : (as usual)
-              plot : a plot object
-              current : (usually not used, deprecated)
-              customvalue=None : a variable containing custom value(s) you need for your plot manipulators.
-            * The function must return a plot object.
-            * Add an entry in hooke.conf: if your function is "plotmanip_something" you will have
-              to add <something/> in the plotmanips section: example
-            
-            <plotmanips>
-                <detriggerize/>
-                <correct/>
-                <median/>
-                <something/>        
-            </plotmanips>
-            
-            Important: Plot manipulators are *in pipe*: each plot manipulator output becomes the input of the next one.
-            The order in hooke.conf *is the order* in which plot manipulators are connected, so in the example above
-            we have:
-            self.current.curve.default_plots() --> detriggerize --> correct --> median --> something --> self.plots
-        '''
-        
-        '''
-        Here we see what is in a configuration variable to enable/disable the plot manipulator as user will using
-        the Hooke "set" command.
-        Typing "set tutorial_absvalue 0" disables the plot manipulator; typing "set tutorial_absvalue 1" will enable it.
-        '''
-        if not self.config['tutorial_absvalue']:
-            return plot
-        
-        #We do something to the plot, for demonstration's sake
-        #If we needed variables, we would have used customvalue.
-        plot.vectors[0][1]=[abs(i) for i in plot.vectors[0][1]]
-        plot.vectors[1][1]=[abs(i) for i in plot.vectors[1][1]]
-        
-        #Return the plot object.
-        return plot
-            
-        
-#TODO IN TUTORIAL:
-#how to add lines to an existing plot!!
-#peaks
-#configuration files
-#gui plugins
diff --git a/tutorialdriver.py b/tutorialdriver.py
deleted file mode 100644 (file)
index b16512a..0000000
+++ /dev/null
@@ -1,208 +0,0 @@
-#!/usr/bin/env python
-
-'''
-tutorialdriver.py
-
-TUTORIAL DRIVER FOR HOOKE
-
-Example driver to teach how to write a driver for data types.
-(c)Massimo Sandal 2008
-'''
-
-'''
-Here we define a (fake) file format that is read by this driver. The file format is as following:
-
-TUTORIAL_FILE
-PLOT1
-X1
-n1
-n2
-...
-nN
-Y1
-n1
-n2
-...
-nN
-X2
-n1
-n2
-..
-nN
-Y2
-n1
-n2
-..
-nN
-PLOT2
-X1
-...
-Y1
-...
-X2
-...
-Y2
-...
-END
-that is, two plots with two datasets each.
-'''
-
-import libhookecurve as lhc #We need to import this library to define some essential data types
-
-class tutorialdriverDriver(lhc.Driver):
-    '''
-    This is a *generic* driver, not a specific force spectroscopy driver.
-    See the written documentation to see what a force spectroscopy driver must be defined to take into account Hooke facilities.
-    
-    Our driver is a class with the name convention nameofthedriverDriver, where "nameofthedriver" is the filename.
-    The driver must inherit from the parent class lhc.Driver, so the syntax is
-    class nameofthedriverDriver(lhc.Driver)
-    '''
-    def __init__(self, filename):
-        '''
-        THIS METHOD MUST BE DEFINED.
-        The __init__ method MUST call the filename, so that it can open the file.
-        '''
-        self.filename=filename #self.filename can always be useful, and should be defined
-        self.filedata = open(filename,'r') #We open the file
-        '''
-        In this case, we have a data format that is just a list of ASCII values, so we can just divide that in rows, and generate a list
-        with each item being a row.
-        Of course if your data files are binary, or follow a different approach, do whatever you need. :) 
-        '''
-        self.data = list(self.filedata)
-        self.filedata.close() #remember to close the file
-        
-        '''These are two strings that can be used by Hooke commands/plugins to understand what they are looking at. They have no other
-        meaning. They have to be somehow defined however - commands often look for those variables.
-        
-        self.filetype should contain the name of the exact filetype defined by the driver (so that filetype-specific commands can know
-                      if they're dealing with the correct filetype)
-        self.experiment should contain instead the type of data involved (for example, various drivers can be used for force-clamp experiments,
-                      but hooke commands could like to know if we're looking at force clamp data, regardless of their origin, and not other 
-                      kinds of data)
-        
-        Of course, all other variables you like can be defined in the class.
-        '''
-        self.filetype = 'tutorial'
-        self.experiment = 'generic'
-    
-    def is_me(self):
-        '''
-        THIS METHOD MUST BE DEFINED.
-        RETURNS: Boolean (True or False)
-        This method must be an heuristic that looks at the file content and decides if the file can be opened by the driver itself. 
-        It returns True if the file opened can be interpreted by the current driver, False otherwise. 
-        Defining this method allows Hooke to understand what kind of files we're looking at automatically.
-        
-        We have to re-open/re-close the file here.
-        '''
-        
-        myfile=open(self.filename, 'r')
-        headerline=myfile.readlines()[0] #we take the first line
-        myfile.close()
-            
-        '''
-        Here, our "magic fingerprint" is the TUTORIAL_FILE header. Of course, depending on the data file, you can have interesting
-        headers, or patterns, etc. that you can use to guess the data format. What matters is successful recognizing, and returning
-        a boolean (True/False).
-        '''
-        if headerline[:-1]=='TUTORIAL_FILE': #[:-1], otherwise the return character is included in the line
-            return True
-        else:
-            return False
-        
-    def _generate_vectors(self):
-        '''
-        Here we parse the data and generate the raw vectors. This method has only to do with the peculiar file format here, so it's of
-        no big interest (I just wrote it to present a functional driver). 
-        
-        Only thing to remember, it can be nice to call methods that are used only "internally" by the driver (or by plugins) with a
-        "_" prefix, so to have a visual remark. But it's just an advice.
-        '''
-        vectors={'PLOT1':[[],[],[],[]] , 'PLOT2':[[],[],[],[]]}
-        positions={'X1':0,'Y1':1,'X2':2,'Y2':3}
-        whatplot=''
-        pos=0
-        for item in self.data:
-            try:
-                num=float(item)
-                vectors[whatplot][pos].append(num)
-            except ValueError:
-                if item[:-1]=='PLOT1':
-                    whatplot=item[:-1]
-                elif item[:-1]=='PLOT2':
-                    whatplot=item[:-1]
-                elif item[0]=='X' or item[0]=='Y':
-                    pos=positions[item[:-1]]         
-                else:
-                    pass
-        
-        return vectors
-
-    def close_all(self):
-        '''
-        THIS METHOD MUST BE DEFINED.
-        This method is a precaution method that is invoked when cycling to avoid eventually dangling open files.
-        In this method, all file objects defined in the driver must be closed.
-        '''
-        self.filename.close()
-    
-    
-    def default_plots(self):
-        '''
-        THIS METHOD MUST BE DEFINED.
-        RETURNS: [ lhc.PlotObject ] or [ lhc.PlotObject, lhc.PlotObject]
-        
-        This is the method that returns the plots to Hooke.
-        It must return a list with *one* or *two* PlotObjects.
-        
-        See the libhookecurve.py source code to see how PlotObjects are defined and work in detail.
-        '''
-        gen_vectors=self._generate_vectors()
-        
-        #Here we create the main plot PlotObject and initialize its vectors.
-        main_plot=lhc.PlotObject()
-        main_plot.vectors=[]
-        #The same for the other plot.
-        other_plot=lhc.PlotObject()
-        other_plot.vectors=[]
-        
-        '''
-        Now we fill the plot vectors with our data.
-                                                           set 1                           set 2
-        The "correct" shape of the vector is [ [[x1,x2,x3...],[y1,y2,y3...]] , [[x1,x2,x3...],[y1,y2,y3...]] ], so we have to put stuff in this way into it.
-        
-        The add_set() method takes care of this , just use plot.add_set(x,y).
-        '''
-        main_plot.add_set(gen_vectors['PLOT1'][0],gen_vectors['PLOT1'][1])
-        main_plot.add_set(gen_vectors['PLOT1'][2],gen_vectors['PLOT1'][3])
-        
-        other_plot.add_set(gen_vectors['PLOT2'][0],gen_vectors['PLOT2'][1])
-        other_plot.add_set(gen_vectors['PLOT2'][2],gen_vectors['PLOT2'][3])
-                
-        '''
-        normalize_vectors() trims the vectors, so that if two x/y couples are of different lengths, the latest
-        points are trimmed (otherwise we have a python error). Always a good idea to run it, to avoid crashes.
-        '''
-        main_plot.normalize_vectors()
-        other_plot.normalize_vectors()
-        
-        '''
-        Here we define:
-        - units: [string, string], define the measure units of X and Y axes
-        - destination: 0/1 , defines where to plot the plot (0=top, 1=bottom), default=0
-        - title: string , the plot title.
-        
-        for each plot.
-        Again, see libhookecurve.py comments for details.
-        '''
-        main_plot.units=['unit of x','unit of y']
-        main_plot.destination=0
-        main_plot.title=self.filename+' main'
-        
-        other_plot.units=['unit of x','unit of y']
-        other_plot.destination=1
-        other_plot.title=self.filename+' other'
-        
-        return [main_plot, other_plot]
\ No newline at end of file
diff --git a/viewer.py b/viewer.py
deleted file mode 100644 (file)
index 42f4b6d..0000000
--- a/viewer.py
+++ /dev/null
@@ -1,39 +0,0 @@
-#!/usr/bin/env python
-
-'''
-Viewer test case
-
-Copyright (C) 2008 Alberto Gomez-Casado (University of Twente).
-
-This program is released under the GNU General Public License version 2.
-'''
-
-
-import libviewer as lview
-import libinput as linput
-
-class viewerCommands:
-       
-    def _plug_init(self):
-        self.viewerlist=[]
-        #we keep a list of different viewers so it's possible to retrieve different data
-        #or process the same data differently
-               
-
-    def do_vwnew(self,args):
-        #creates a new viewer
-        self.viewerlist.append(lview.Ascii(self.outlet))
-        dt=linput.safeinput('What type of data will this viewer handle? (force/distance/all)',['force', 'distance', 'all']) 
-                    #TODO update types, make a list somewhere?
-        print dt
-        self.viewerlist[-1].setdtype(dt)
-
-
-    def do_vwaction(self,args):
-        '''
-        triggers default action of viewer number n (default 0)
-        '''
-
-        if len(args)==0:
-            args=0
-        self.viewerlist[int(args)].action()
\ No newline at end of file