Coverage for /builds/kinetik161/ase/ase/gui/ag.py: 56.00%

50 statements  

« prev     ^ index     » next       coverage.py v7.2.7, created at 2023-12-10 11:04 +0000

1# Copyright 2008, 2009 

2# CAMd (see accompanying license files for details). 

3import warnings 

4 

5 

6class CLICommand: 

7 """ASE's graphical user interface. 

8 

9 ASE-GUI. See the online manual 

10 (https://wiki.fysik.dtu.dk/ase/ase/gui/gui.html) 

11 for more information. 

12 """ 

13 

14 @staticmethod 

15 def add_arguments(parser): 

16 add = parser.add_argument 

17 add('filenames', nargs='*', 

18 help='Files to open. Append @SLICE to a filename to pick ' 

19 'a subset of images from that file. See --image-number ' 

20 'for SLICE syntax.') 

21 add('-n', '--image-number', metavar='SLICE', default=':', 

22 help='Pick individual image or slice from each of the files. ' 

23 'SLICE can be a number or a Python slice-like expression ' 

24 'such as :STOP, START:STOP, or START:STOP:STEP, ' 

25 'where START, STOP, and STEP are integers. ' 

26 'Indexing counts from 0. ' 

27 'Negative numbers count backwards from last image. ' 

28 'Using @SLICE syntax for a filename overrides this option ' 

29 'for that file.') 

30 add('-r', '--repeat', 

31 default='1', 

32 help='Repeat unit cell. Use "-r 2" or "-r 2,3,1".') 

33 add('-R', '--rotations', default='', 

34 help='Examples: "-R -90x", "-R 90z,-30x".') 

35 add('-o', '--output', metavar='FILE', 

36 help='Write configurations to FILE.') 

37 add('-g', '--graph', 

38 # TRANSLATORS: EXPR abbreviates 'expression' 

39 metavar='EXPR', 

40 help='Plot x,y1,y2,... graph from configurations or ' 

41 'write data to sdtout in terminal mode. Use the ' 

42 'symbols: i, s, d, fmax, e, ekin, A, R, E and F. See ' 

43 'https://wiki.fysik.dtu.dk/ase/ase/gui/gui.html' 

44 '#plotting-data for more details.') 

45 add('-t', '--terminal', 

46 action='store_true', 

47 default=False, 

48 help='Run in terminal window - no GUI.') 

49 add('--interpolate', 

50 type=int, metavar='N', 

51 help='Interpolate N images between 2 given images.') 

52 add('-b', '--bonds', 

53 action='store_true', 

54 default=False, 

55 help='Draw bonds between atoms.') 

56 add('-s', '--scale', dest='radii_scale', metavar='FLOAT', 

57 default=None, type=float, 

58 help='Scale covalent radii.') 

59 

60 @staticmethod 

61 def run(args): 

62 from ase.atoms import Atoms 

63 from ase.gui.images import Images 

64 

65 images = Images() 

66 

67 if args.filenames: 

68 images.read(args.filenames, args.image_number) 

69 else: 

70 images.initialize([Atoms()]) 

71 

72 if args.interpolate: 

73 images.interpolate(args.interpolate) 

74 

75 if args.repeat != '1': 

76 r = args.repeat.split(',') 

77 if len(r) == 1: 

78 r = 3 * r 

79 images.repeat_images([int(c) for c in r]) 

80 

81 if args.radii_scale: 

82 images.scale_radii(args.radii_scale) 

83 

84 if args.output is not None: 

85 warnings.warn('You should be using "ase convert ..." instead!') 

86 images.write(args.output, rotations=args.rotations) 

87 args.terminal = True 

88 

89 if args.terminal: 

90 if args.graph is not None: 

91 data = images.graph(args.graph) 

92 for line in data.T: 

93 for x in line: 

94 print(x, end=' ') 

95 print() 

96 else: 

97 import os 

98 

99 from ase.gui.gui import GUI 

100 

101 backend = os.environ.get('MPLBACKEND', '') 

102 if backend == 'module://ipykernel.pylab.backend_inline': 

103 # Jupyter should not steal our windows 

104 del os.environ['MPLBACKEND'] 

105 

106 gui = GUI(images, args.rotations, args.bonds, args.graph) 

107 gui.run()