Coverage for ase / cli / nebplot.py: 50.00%

22 statements  

« prev     ^ index     » next       coverage.py v7.14.0, created at 2026-05-21 15:52 +0000

1# fmt: off 

2 

3# Note: 

4# Try to avoid module level import statements here to reduce 

5# import time during CLI execution 

6 

7 

8class CLICommand: 

9 """Analyze NEB trajectories by making band plots. 

10 

11 One file: 

12 

13 ase nebplot neb.traj 

14 

15 Multiple files: 

16 

17 ase nebplot neb1.traj neb2.traj 

18 

19 Specify output: 

20 

21 ase nebplot neb1.traj neb2.traj myfile.pdf 

22 """ 

23 

24 @staticmethod 

25 def add_arguments(parser): 

26 add = parser.add_argument 

27 add('filenames', nargs='+', 

28 help='one or more trajectory files to analyze') 

29 add('output', nargs='?', 

30 help='optional name of output file, default=nebplots.pdf') 

31 add('--nimages', dest='n_images', type=int, default=None, 

32 help='number of images per band, guessed if not supplied') 

33 add('--share-x', dest='constant_x', action='store_true', 

34 help='use a single x axis scale for all plots') 

35 add('--share-y', dest='constant_y', action='store_true', 

36 help='use a single y axis scale for all plots') 

37 

38 @staticmethod 

39 def run(args, parser): 

40 import matplotlib 

41 matplotlib.use('Agg') # headless operation 

42 from ase.gui.images import Images 

43 from ase.mep import NEBTools 

44 

45 # Nothing will ever be stored in args.output; need to manually find 

46 # if its supplied by checking extensions. 

47 if args.filenames[-1].endswith('.pdf'): 

48 args.output = args.filenames.pop(-1) 

49 else: 

50 args.output = 'nebplots.pdf' 

51 

52 images = Images() 

53 images.read(args.filenames) 

54 nebtools = NEBTools(images=images) 

55 nebtools.plot_bands(constant_x=args.constant_x, 

56 constant_y=args.constant_y, 

57 nimages=args.n_images, 

58 label=args.output[:-4])