Coverage for /builds/ase/ase/ase/cli/nebplot.py: 55.00%

20 statements  

« prev     ^ index     » next       coverage.py v7.5.3, created at 2025-08-02 00:12 +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 from ase.gui.images import Images 

41 from ase.mep import NEBTools 

42 

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

44 # if its supplied by checking extensions. 

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

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

47 else: 

48 args.output = 'nebplots.pdf' 

49 

50 images = Images() 

51 images.read(args.filenames) 

52 nebtools = NEBTools(images=images) 

53 nebtools.plot_bands(constant_x=args.constant_x, 

54 constant_y=args.constant_y, 

55 nimages=args.n_images, 

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