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 import Atoms 

2from ase.io import read 

3from ase.io.jsonio import read_json 

4from ase.dft.kpoints import BandPath 

5from ase.cli.main import CLIError 

6from ase.io.formats import UnknownFileTypeError 

7 

8 

9def plot_reciprocal_cell(path, output=None): 

10 import matplotlib.pyplot as plt 

11 

12 path.plot() 

13 

14 if output: 

15 plt.savefig(output) 

16 else: 

17 plt.show() 

18 

19 

20def read_object(filename): 

21 try: 

22 return read(filename) 

23 except UnknownFileTypeError: 

24 # Probably a bandpath/bandstructure: 

25 return read_json(filename) 

26 

27 

28def obj2bandpath(obj): 

29 if isinstance(obj, BandPath): 

30 print('Object is a band path') 

31 print(obj) 

32 return obj 

33 

34 if isinstance(getattr(obj, 'path', None), BandPath): 

35 print(f'Object contains a bandpath: {obj}') 

36 path = obj.path 

37 print(path) 

38 return path 

39 

40 if isinstance(obj, Atoms): 

41 print(f'Atoms object: {obj}') 

42 print('Determining standard form of Bravais lattice:') 

43 lat = obj.cell.get_bravais_lattice(pbc=obj.pbc) 

44 print(lat.description()) 

45 print('Showing default bandpath') 

46 return lat.bandpath(density=0) 

47 

48 raise CLIError(f'Strange object: {obj}') 

49 

50 

51class CLICommand: 

52 """Show the reciprocal space. 

53 

54 Read unit cell from a file and show a plot of the 1. Brillouin zone. If 

55 the file contains information about k-points, then those can be plotted 

56 too. 

57 

58 Examples: 

59 

60 $ ase build -x fcc Al al.traj 

61 $ ase reciprocal al.traj 

62 """ 

63 

64 @staticmethod 

65 def add_arguments(parser): 

66 add = parser.add_argument 

67 add('name', metavar='input-file', 

68 help='Input file containing unit cell.') 

69 add('output', nargs='?', help='Write plot to file (.png, .svg, ...).') 

70 

71 @staticmethod 

72 def run(args, parser): 

73 obj = read_object(args.name) 

74 path = obj2bandpath(obj) 

75 plot_reciprocal_cell(path, output=args.output)