Coverage for /builds/ase/ase/ase/cli/band_structure.py: 92.31%
26 statements
« prev ^ index » next coverage.py v7.5.3, created at 2025-08-02 00:12 +0000
« prev ^ index » next coverage.py v7.5.3, created at 2025-08-02 00:12 +0000
1# fmt: off
3# Note:
4# Try to avoid module level import statements here to reduce
5# import time during CLI execution
6from ase.cli.main import CLIError
9def read_band_structure(filename):
10 from ase.io.jsonio import read_json
11 from ase.spectrum.band_structure import BandStructure
13 bs = read_json(filename)
14 if not isinstance(bs, BandStructure):
15 raise CLIError(f'Expected band structure, but file contains: {bs}')
16 return bs
19def main(args, parser):
20 import matplotlib.pyplot as plt
22 bs = read_band_structure(args.calculation)
23 emin, emax = (float(e) for e in args.range)
24 fig = plt.figure(args.calculation)
25 ax = fig.gca()
27 bs.plot(ax=ax,
28 filename=args.output,
29 emin=emin + bs.reference,
30 emax=emax + bs.reference)
32 if args.output is None:
33 plt.show()
36class CLICommand:
37 """Plot band-structure.
39 Read eigenvalues and k-points from file and plot result from
40 band-structure calculation or interpolate
41 from Monkhorst-Pack sampling to a given path (--path=PATH).
43 Example:
45 $ ase band-structure bandstructure.json -r -10 10
46 """
48 @staticmethod
49 def add_arguments(parser):
50 parser.add_argument('calculation',
51 help='Path to output file(s) from calculation.')
52 parser.add_argument('-o', '--output', help='Write image to a file')
53 parser.add_argument('-r', '--range', nargs=2, default=['-3', '3'],
54 metavar=('emin', 'emax'),
55 help='Default: "-3.0 3.0" '
56 '(in eV relative to Fermi level).')
58 @staticmethod
59 def run(args, parser):
60 main(args, parser)