README: Remove duplicate pyafm target
[unfold-protein.git] / plot-unfold.py
1 #!/usr/bin/env python
2 #
3 # Copyright
4
5 import os.path as _os_path
6
7 import h5py as _h5py
8 import matplotlib as _matplotlib
9 import matplotlib.pyplot as _matplotlib_pyplot
10
11
12 FIGURE = _matplotlib_pyplot.figure()
13
14
15 class BadDataError (ValueError):
16     pass
17
18
19 def convert_to_png(filename):
20     with _h5py.File(filename) as f:
21         png = filename + '.png'
22         if not _os_path.isfile(png):
23             FIGURE.clear()
24             axes = FIGURE.add_subplot(1, 1, 1)
25             axes.hold(True)
26             try:
27                 z = f['approach']['z']
28                 d = f['approach']['deflection']
29             except KeyError, e:
30                 raise BadDataError(e)
31             plot = axes.plot(z, d, '.')
32             try:
33                 z = f['unfold']['z']
34                 d = f['unfold']['deflection']
35             except KeyError, e:
36                 raise BadDataError(e)
37             plot = axes.plot(z, d, '.')
38             axes.autoscale(tight=True)
39             FIGURE.savefig(png)
40
41
42 if __name__ == '__main__': 
43     import sys as _sys
44
45     for filename in _sys.argv[1:]:
46         try:
47             convert_to_png(filename)
48         except BadDataError:
49             print('Error converting {}'.format(filename))