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

1from ase.io.jsonio import read_json 

2from ase.spectrum.band_structure import BandStructure 

3from ase.cli.main import CLIError 

4 

5 

6def read_band_structure(filename): 

7 bs = read_json(filename) 

8 if not isinstance(bs, BandStructure): 

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

10 return bs 

11 

12 

13def main(args, parser): 

14 import matplotlib.pyplot as plt 

15 bs = read_band_structure(args.calculation) 

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

17 fig = plt.gcf() 

18 fig.canvas.set_window_title(args.calculation) 

19 ax = fig.gca() 

20 bs.plot(ax=ax, 

21 filename=args.output, 

22 emin=emin + bs.reference, 

23 emax=emax + bs.reference) 

24 if args.output is None: 

25 plt.show() 

26 

27 

28class CLICommand: 

29 """Plot band-structure. 

30 

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

32 band-structure calculation or interpolate 

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

34 

35 Example: 

36 

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

38 """ 

39 

40 @staticmethod 

41 def add_arguments(parser): 

42 parser.add_argument('calculation', 

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

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

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

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

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

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

49 

50 @staticmethod 

51 def run(args, parser): 

52 main(args, parser)