unfolder: Save the timestamp, x-position, and temp under environment/
[unfold-protein.git] / unfold.py
1 #!/usr/bin/env python
2 #
3 # Copyright (C) 2009-2012 W. Trevor King <wking@tremily.us>
4 #
5 # This file is part of unfold_protein.
6 #
7 # unfold_protein is free software: you can redistribute it and/or modify it
8 # under the terms of the GNU General Public License as published by the Free
9 # Software Foundation, either version 3 of the License, or (at your option) any
10 # later version.
11 #
12 # unfold_protein is distributed in the hope that it will be useful, but WITHOUT
13 # ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
14 # FOR A PARTICULAR PURPOSE.  See the GNU General Public License for more
15 # details.
16 #
17 # You should have received a copy of the GNU General Public License along with
18 # unfold_protein.  If not, see <http://www.gnu.org/licenses/>.
19
20 """Run a mechanical protein unfolding experiment."""
21
22 import os
23 import os.path
24
25 import numpy as _numpy
26
27 from pyafm.storage import load_afm as _load_afm
28 from pyafm.config import Kelvin as _Kelvin
29 from unfold_protein import __version__
30 from unfold_protein.unfolder import Unfolder
31 from unfold_protein.scan import UnfoldScanner
32 import unfold_protein.config as _config
33
34
35 if __name__ == '__main__':
36     from argparse import ArgumentParser
37
38     parser = ArgumentParser(
39         description=__doc__, version=__version__)
40     parser.add_argument(
41         '-s', '--song',
42         help='Path to a song to play when the experiment is complete')
43
44     args = parser.parse_args()
45
46     unfold_config = _config.UnfoldCycleConfig()
47     unfold_config['approach'] = _config.ApproachConfig()
48     unfold_config['unfold'] = _config.UnfoldConfig()
49     unfold_config['unfold']['distance'] = 900e-9
50     unfold_config['save'] = _config.SaveConfig()
51     scan_config = _config.ScanConfig()
52     scan_config['velocity'] = _config.VelocityScanConfig()
53     #scan_config['velocity']['unfolding velocities'] = _numpy.array([1e-6])
54     scan_config['velocity']['num loops'] = 500
55     scan_config['position'] = _config.PositionScanConfig()
56
57     devices = []
58     try:
59         afm = _load_afm()
60         afm.load_from_config(devices=devices)
61         afm.piezo.zero()
62         unfolder = Unfolder(config=unfold_config, afm=afm)
63         scanner = UnfoldScanner(config=scan_config, unfolder=unfolder)
64         scanner.run()
65     finally:
66         afm.move_away_from_surface()
67         afm.piezo.zero()
68         for device in devices:
69             device.close()
70         if args.song:
71             song = os.path.abspath(os.path.expanduser(args.song))
72             os.system("aplay '%s'" % song)