root / ase / gui / ag.py @ 1
Historique | Voir | Annoter | Télécharger (4,7 ko)
1 |
#!/usr/bin/env python
|
---|---|
2 |
|
3 |
# Copyright 2008, 2009
|
4 |
# CAMd (see accompanying license files for details).
|
5 |
|
6 |
from optparse import OptionParser, SUPPRESS_HELP |
7 |
import ase.gui.gtkexcepthook |
8 |
#ase.gui.gtkexcepthook.feedback = "schiotz@fysik.dtu.dk"
|
9 |
#ase.gui.gtkexcepthook.smtphost = "mail.fysik.dtu.dk"
|
10 |
|
11 |
def build_parser(): |
12 |
parser = OptionParser(usage='%prog [options] [file[, file2, ...]]',
|
13 |
version='%prog 0.1',
|
14 |
description='See the online manual ' +
|
15 |
'(https://wiki.fysik.dtu.dk/ase/ase/gui.html) ' +
|
16 |
'for more information.')
|
17 |
parser.add_option('-n', '--image-number', |
18 |
default=':', metavar='NUMBER', |
19 |
help='Pick image(s) from trajectory. NUMBER can be a '
|
20 |
'single number (use a negative number to count from '
|
21 |
'the back) or a range: start:stop:step, where the '
|
22 |
'":step" part can be left out - default values are '
|
23 |
'0:nimages:1.')
|
24 |
parser.add_option('-u', '--show-unit-cell', type='int', |
25 |
default=1, metavar='I', |
26 |
help="0: Don't show unit cell. 1: Show unit cell. "
|
27 |
'2: Show all of unit cell.')
|
28 |
parser.add_option('-r', '--repeat', |
29 |
default='1',
|
30 |
help='Repeat unit cell. Use "-r 2" or "-r 2,3,1".')
|
31 |
parser.add_option('-R', '--rotations', default='', |
32 |
help='Examples: "-R -90x", "-R 90z,-30x".')
|
33 |
parser.add_option('-o', '--output', metavar='FILE', |
34 |
help='Write configurations to FILE.')
|
35 |
parser.add_option('-g', '--graph', |
36 |
metavar='EXPR',
|
37 |
help='Plot x,y1,y2,... graph from configurations or '
|
38 |
'write data to sdtout in terminal mode. Use the '
|
39 |
'symbols: i, s, d, fmax, e, ekin, A, R, E and F. See '
|
40 |
'https://wiki.fysik.dtu.dk/ase/ase/gui.html#plotting-data '
|
41 |
'for more details.')
|
42 |
parser.add_option('-t', '--terminal', |
43 |
action='store_true',
|
44 |
default=False,
|
45 |
help='Run in terminal window - no GUI.')
|
46 |
parser.add_option('--aneb',
|
47 |
action='store_true',
|
48 |
default=False,
|
49 |
help='Read ANEB data.')
|
50 |
parser.add_option('--interpolate',
|
51 |
type='int', metavar='N', |
52 |
help='Interpolate N images between 2 given images.')
|
53 |
parser.add_option('-b', '--bonds', |
54 |
action='store_true',
|
55 |
default=False,
|
56 |
help='Draw bonds between atoms.')
|
57 |
#parser.add_option('--read-pickled-data-from-file',
|
58 |
# type='string', help=SUPPRESS_HELP)
|
59 |
return parser
|
60 |
|
61 |
def main(): |
62 |
parser = build_parser() |
63 |
opt, args = parser.parse_args() |
64 |
|
65 |
try:
|
66 |
import ase |
67 |
except ImportError: |
68 |
import sys |
69 |
from os.path import dirname, join, pardir |
70 |
sys.path.append(join(dirname(__file__), pardir)) |
71 |
|
72 |
from ase.gui.images import Images |
73 |
from ase.atoms import Atoms |
74 |
|
75 |
def run(opt, args): |
76 |
images = Images() |
77 |
|
78 |
if opt.aneb:
|
79 |
opt.image_number = '-1'
|
80 |
|
81 |
if len(args) > 0: |
82 |
from ase.io import string2index |
83 |
images.read(args, string2index(opt.image_number)) |
84 |
else:
|
85 |
images.initialize([Atoms()]) |
86 |
|
87 |
if opt.interpolate:
|
88 |
images.interpolate(opt.interpolate) |
89 |
|
90 |
if opt.aneb:
|
91 |
images.aneb() |
92 |
|
93 |
if opt.repeat != '1': |
94 |
r = opt.repeat.split(',')
|
95 |
if len(r) == 1: |
96 |
r = 3 * r
|
97 |
images.repeat_images([int(c) for c in r]) |
98 |
|
99 |
if opt.output is not None: |
100 |
images.write(opt.output, rotations=opt.rotations, |
101 |
show_unit_cell=opt.show_unit_cell) |
102 |
opt.terminal = True
|
103 |
|
104 |
if opt.terminal:
|
105 |
if opt.graph is not None: |
106 |
data = images.graph(opt.graph) |
107 |
for line in data.T: |
108 |
for x in line: |
109 |
print x,
|
110 |
print
|
111 |
else:
|
112 |
from ase.gui.gui import GUI |
113 |
gui = GUI(images, opt.rotations, opt.show_unit_cell, opt.bonds) |
114 |
gui.run(opt.graph) |
115 |
|
116 |
import traceback |
117 |
|
118 |
try:
|
119 |
run(opt, args) |
120 |
except KeyboardInterrupt: |
121 |
pass
|
122 |
except Exception: |
123 |
traceback.print_exc() |
124 |
print """ |
125 |
An exception occurred! Please report the issue to
|
126 |
ase-developers@listserv.fysik.dtu.dk - thanks! Please also report this if
|
127 |
it was a user error, so that a better error message can be provided
|
128 |
next time."""
|