Coverage for ase/cli/nebplot.py: 50.00%
22 statements
« prev ^ index » next coverage.py v7.16.2, created at 2026-11-27 15:21 +0000
« prev ^ index » next coverage.py v7.16.2, created at 2026-11-27 15:21 +0000
1# Note:
2# Try to avoid module level import statements here to reduce
3# import time during CLI execution
6class CLICommand:
7 """Analyze NEB trajectories by making band plots.
9 One file:
11 ase nebplot neb.traj
13 Multiple files:
15 ase nebplot neb1.traj neb2.traj
17 Specify output:
19 ase nebplot neb1.traj neb2.traj myfile.pdf
20 """
22 @staticmethod
23 def add_arguments(parser):
24 add = parser.add_argument
25 add(
26 'filenames',
27 nargs='+',
28 help='one or more trajectory files to analyze',
29 )
30 add(
31 'output',
32 nargs='?',
33 help='optional name of output file, default=nebplots.pdf',
34 )
35 add(
36 '--nimages',
37 dest='n_images',
38 type=int,
39 default=None,
40 help='number of images per band, guessed if not supplied',
41 )
42 add(
43 '--share-x',
44 dest='constant_x',
45 action='store_true',
46 help='use a single x axis scale for all plots',
47 )
48 add(
49 '--share-y',
50 dest='constant_y',
51 action='store_true',
52 help='use a single y axis scale for all plots',
53 )
55 @staticmethod
56 def run(args, parser):
57 import matplotlib
59 matplotlib.use('Agg') # headless operation
60 from ase.gui.images import Images
61 from ase.mep import NEBTools
63 # Nothing will ever be stored in args.output; need to manually find
64 # if its supplied by checking extensions.
65 if args.filenames[-1].endswith('.pdf'):
66 args.output = args.filenames.pop(-1)
67 else:
68 args.output = 'nebplots.pdf'
70 images = Images()
71 images.read(args.filenames)
72 nebtools = NEBTools(images=images)
73 nebtools.plot_bands(
74 constant_x=args.constant_x,
75 constant_y=args.constant_y,
76 nimages=args.n_images,
77 label=args.output[:-4],
78 )