Hide keyboard shortcuts

Hot-keys on this page

r m x p   toggle line displays

j k   next/prev highlighted chunk

0   (zero) top of page

1   (one) first highlighted chunk

1# Note: 

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

3# import time during CLI execution 

4from ase.cli.main import CLIError 

5 

6 

7def read_band_structure(filename): 

8 from ase.io.jsonio import read_json 

9 from ase.spectrum.band_structure import BandStructure 

10 

11 bs = read_json(filename) 

12 if not isinstance(bs, BandStructure): 

13 raise CLIError(f'Expected band structure, but file contains: {bs}') 

14 return bs 

15 

16 

17def main(args, parser): 

18 import matplotlib.pyplot as plt 

19 

20 bs = read_band_structure(args.calculation) 

21 emin, emax = (float(e) for e in args.range) 

22 fig = plt.figure(args.calculation) 

23 ax = fig.gca() 

24 

25 bs.plot(ax=ax, 

26 filename=args.output, 

27 emin=emin + bs.reference, 

28 emax=emax + bs.reference) 

29 

30 if args.output is None: 

31 plt.show() 

32 

33 

34class CLICommand: 

35 """Plot band-structure. 

36 

37 Read eigenvalues and k-points from file and plot result from 

38 band-structure calculation or interpolate 

39 from Monkhorst-Pack sampling to a given path (--path=PATH). 

40 

41 Example: 

42 

43 $ ase band-structure bandstructure.json -r -10 10 

44 """ 

45 

46 @staticmethod 

47 def add_arguments(parser): 

48 parser.add_argument('calculation', 

49 help='Path to output file(s) from calculation.') 

50 parser.add_argument('-o', '--output', help='Write image to a file') 

51 parser.add_argument('-r', '--range', nargs=2, default=['-3', '3'], 

52 metavar=('emin', 'emax'), 

53 help='Default: "-3.0 3.0" ' 

54 '(in eV relative to Fermi level).') 

55 

56 @staticmethod 

57 def run(args, parser): 

58 main(args, parser)