README: Remove duplicate pyafm target
[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 unfold_protein import __version__
28 import unfold_protein.storage as _storage
29
30
31 if __name__ == '__main__':
32     from argparse import ArgumentParser
33
34     parser = ArgumentParser(
35         description=__doc__, version=__version__)
36     parser.add_argument(
37         '-s', '--song',
38         help='Path to a song to play when the experiment is complete')
39     parser.add_argument(
40         '-S', '--no-stepper-tweaks', dest='stepper_tweaks',
41         action='store_const', const=False, default=True,
42         help=("Don't move the stepper except for the initial approach "
43               "and final retraction"))
44
45     args = parser.parse_args()
46
47     devices = []
48     try:
49         scanner = _storage.load_scanner()
50         scanner.load_from_config(devices=devices)
51         scanner.unfolder.afm.piezo.zero()
52         scanner.run(stepper_tweaks=args.stepper_tweaks)
53     finally:
54         scanner.unfolder.afm.move_away_from_surface()
55         scanner.unfolder.afm.piezo.zero()
56         for device in devices:
57             device.close()
58         if args.song:
59             song = os.path.abspath(os.path.expanduser(args.song))
60             os.system("aplay '%s'" % song)