unfolder: Save the timestamp, x-position, and temp under environment/
[unfold-protein.git] / unfold.py
index b1ca6f8340199647627a5fc75f0b6208872d8695..951ad336683084b41779a2602297cd1a622b2698 100755 (executable)
--- a/unfold.py
+++ b/unfold.py
@@ -1,30 +1,32 @@
 #!/usr/bin/env python
 #
-# Copyright (C) 2011 W. Trevor King <wking@drexel.edu>
+# Copyright (C) 2009-2012 W. Trevor King <wking@tremily.us>
 #
 # This file is part of unfold_protein.
 #
-# Unfold_protein 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.
+# unfold_protein is free software: you can redistribute it and/or modify it
+# under the terms of the GNU General Public License as published by the Free
+# Software Foundation, either version 3 of the License, or (at your option) any
+# later version.
 #
-# Unfold_protein 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.
+# unfold_protein 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 General Public License for more
+# details.
 #
-# You should have received a copy of the GNU Lesser General Public
-# License along with unfold_protein.  If not, see
-# <http://www.gnu.org/licenses/>.
+# You should have received a copy of the GNU General Public License along with
+# unfold_protein.  If not, see <http://www.gnu.org/licenses/>.
 
 """Run a mechanical protein unfolding experiment."""
 
 import os
 import os.path
 
-from unfold_protein import __version__ as version
-from unfold_protein.afm import get_afm
+import numpy as _numpy
+
+from pyafm.storage import load_afm as _load_afm
+from pyafm.config import Kelvin as _Kelvin
+from unfold_protein import __version__
 from unfold_protein.unfolder import Unfolder
 from unfold_protein.scan import UnfoldScanner
 import unfold_protein.config as _config
@@ -34,7 +36,7 @@ if __name__ == '__main__':
     from argparse import ArgumentParser
 
     parser = ArgumentParser(
-        description='Play a pure tone', version=version)
+        description=__doc__, version=__version__)
     parser.add_argument(
         '-s', '--song',
         help='Path to a song to play when the experiment is complete')
@@ -42,22 +44,29 @@ if __name__ == '__main__':
     args = parser.parse_args()
 
     unfold_config = _config.UnfoldCycleConfig()
-    unfold_config['temperature'] = _config.TemperatureConfig()
     unfold_config['approach'] = _config.ApproachConfig()
     unfold_config['unfold'] = _config.UnfoldConfig()
+    unfold_config['unfold']['distance'] = 900e-9
     unfold_config['save'] = _config.SaveConfig()
     scan_config = _config.ScanConfig()
     scan_config['velocity'] = _config.VelocityScanConfig()
+    #scan_config['velocity']['unfolding velocities'] = _numpy.array([1e-6])
+    scan_config['velocity']['num loops'] = 500
     scan_config['position'] = _config.PositionScanConfig()
 
-    afm,comedi_device = get_afm(with_temperature=False)
-    unfolder = Unfolder(config=unfold_config, afm=afm)
-    scanner = UnfoldScanner(config=scan_config, unfolder=unfolder)
+    devices = []
     try:
+        afm = _load_afm()
+        afm.load_from_config(devices=devices)
+        afm.piezo.zero()
+        unfolder = Unfolder(config=unfold_config, afm=afm)
+        scanner = UnfoldScanner(config=scan_config, unfolder=unfolder)
         scanner.run()
     finally:
-        scanner.move_far_from_surface()
-        comedi_device.close()
+        afm.move_away_from_surface()
+        afm.piezo.zero()
+        for device in devices:
+            device.close()
         if args.song:
             song = os.path.abspath(os.path.expanduser(args.song))
             os.system("aplay '%s'" % song)