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