Don't specify curve or data block types. See doc/standards.txt.
[hooke.git] / hooke / driver / wtk.py
index a7aec0bef1576a61f308a3b4e1515cc5e9838b5f..031fb80f98a1faa0144abb2e4540633d550cc490 100644 (file)
@@ -2,21 +2,21 @@
 #
 # This file is part of Hooke.
 #
-# Hooke is free software: you can redistribute it and/or
-# modify it under the terms of the GNU Lesser General Public
-# License as published by the Free Software Foundation, either
-# version 3 of the License, or (at your option) any later version.
+# Hooke is free software: you can redistribute it and/or modify it
+# under the terms of the GNU Lesser General Public License as
+# published by the Free Software Foundation, either version 3 of the
+# License, or (at your option) any later version.
 #
-# Hooke is distributed in the hope that it will be useful,
-# but WITHOUT ANY WARRANTY; without even the implied warranty of
-# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-# GNU Lesser General Public License for more details.
+# Hooke is distributed in the hope that it will be useful, but WITHOUT
+# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
+# or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Lesser General
+# Public License for more details.
 #
 # You should have received a copy of the GNU Lesser General Public
 # License along with Hooke.  If not, see
 # <http://www.gnu.org/licenses/>.
 
-"""Hooke driver for W. Trevor King's velocity clamp data format.
+"""Driver for W. Trevor King's velocity clamp data format.
 
 See my related projects:
 
@@ -42,7 +42,6 @@ import time
 import numpy
 
 from .. import curve as curve
-from .. import experiment as experiment
 from ..config import Setting
 from . import Driver as Driver
 
@@ -69,11 +68,13 @@ class WTKDriver (Driver):
             Setting(section=self.setting_section, help=self.__doc__),
             Setting(section=self.setting_section,
                     option='cantilever calibration directory',
-                    value=calibcant_dir,
+                    value=calibcant_dir, type='path',
                     help='Set the directory where cantilever calibration data is stored'),
             ]
 
     def is_me(self, path):
+        if os.path.isdir(path):
+            return False
         if not path.endswith('_unfold'):
             return False
         for p in self._paths(path):
@@ -81,7 +82,7 @@ class WTKDriver (Driver):
                 return False
         return True
 
-    def read(self, path):
+    def read(self, path, info=None):
         approach_path,retract_path,param_path = self._paths(path)
 
         unlabeled_approach_data = numpy.loadtxt(
@@ -96,11 +97,11 @@ class WTKDriver (Driver):
             unlabeled_approach_data, params, 'approach')
         retract = self._scale_block(
             unlabeled_retract_data, params, 'retract')
-        info = {'filetype':'wtk', 'experiment':experiment.VelocityClamp}
+        info = {}
         return ([approach, retract], info)
 
     def _paths(self, path):
-        return (path, path+'_approach', path+'_param')
+        return (path+'_approach', path, path+'_param')
 
     def _read_params(self, param_path):
         params = {}
@@ -134,7 +135,7 @@ class WTKDriver (Driver):
         ret['raw spring constant'] = calibcant_info
         ret['spring constant (N/m)'] = calibcant_info['Cantilever k (N/m)']
         ret['deflection sensitivity (m/V)'] = \
-            1.0/numpy.sqrt(calibcant_info['photoSensitivity**2 (V/nm)**2'])
+            1.0/numpy.sqrt(calibcant_info['photoSensitivity**2 (V/nm)**2']) * 1e-9
 
         # (32768 bits = 2**15 bits = 10 Volts)
         ret['deflection sensitivity (V/bit)'] = 1.0/3276.8
@@ -156,7 +157,7 @@ class WTKDriver (Driver):
         array in SI units.
         """
         ret = curve.Data(
-            shape=data.shape,
+            shape=(data.shape[0], 2),
             dtype=numpy.float,
             info=copy.deepcopy(info)
             )
@@ -185,7 +186,11 @@ class WTKDriver (Driver):
             * info['z piezo sensitivity (m/V)']
             )
 
-        ret[:,d_scol] = (
+        # Leading '-' because deflection voltage increases as the tip
+        # moves away from the surface, but it makes more sense to me
+        # to have it increase as it moves toward the surface (positive
+        # tension on the protein chain).
+        ret[:,d_scol] = -(
             (data[:,d_rcol]
              * info['deflection sensitivity (V/bit)']
              - info['deflection offset (V)'])
@@ -244,7 +249,7 @@ class WTKDriver (Driver):
             if self._calibfile_timestamp(calibfiles[i]) > timestamp:
                 i -= 1
                 break
-        return os.path.join(dir, calibfiles[i])
+        return calibfiles[i]
 
     def _read_cantilever_calibration_file(self, filename):
         ret = {'file': filename}