Coverage for /builds/kinetik161/ase/ase/cli/band_structure.py: 92.31%
26 statements
« prev ^ index » next coverage.py v7.2.7, created at 2023-12-10 11:04 +0000
« prev ^ index » next coverage.py v7.2.7, created at 2023-12-10 11:04 +0000
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
7def read_band_structure(filename):
8 from ase.io.jsonio import read_json
9 from ase.spectrum.band_structure import BandStructure
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
17def main(args, parser):
18 import matplotlib.pyplot as plt
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()
25 bs.plot(ax=ax,
26 filename=args.output,
27 emin=emin + bs.reference,
28 emax=emax + bs.reference)
30 if args.output is None:
31 plt.show()
34class CLICommand:
35 """Plot band-structure.
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).
41 Example:
43 $ ase band-structure bandstructure.json -r -10 10
44 """
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).')
56 @staticmethod
57 def run(args, parser):
58 main(args, parser)