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

1# Note: 

2# Try to avoid module level import statements here to reduce 

3# import time during CLI execution 

4 

5 

6class CLICommand: 

7 """Print information about files or system. 

8 

9 Without any filename(s), informations about the ASE installation will be 

10 shown (Python version, library versions, ...). 

11 

12 With filename(s), the file format will be determined for each file. 

13 """ 

14 

15 @staticmethod 

16 def add_arguments(parser): 

17 parser.add_argument('filename', nargs='*', 

18 help='Name of file to determine format for.') 

19 parser.add_argument('-v', '--verbose', action='store_true', 

20 help='Show more information about files.') 

21 parser.add_argument('--formats', action='store_true', 

22 help='List file formats known to ASE.') 

23 parser.add_argument('--calculators', action='store_true', 

24 help='List calculators known to ASE ' 

25 'and whether they appear to be installed.') 

26 

27 @staticmethod 

28 def run(args): 

29 from ase.io.formats import filetype, ioformats, UnknownFileTypeError 

30 from ase.io.ulm import print_ulm_info 

31 from ase.io.bundletrajectory import print_bundletrajectory_info 

32 

33 if not args.filename: 

34 print_info() 

35 if args.formats: 

36 print() 

37 print_formats() 

38 if args.calculators: 

39 print() 

40 from ase.calculators.autodetect import (detect_calculators, 

41 format_configs) 

42 configs = detect_calculators() 

43 print('Calculators:') 

44 for message in format_configs(configs): 

45 print(' {}'.format(message)) 

46 print() 

47 print('Available: {}'.format(','.join(sorted(configs)))) 

48 return 

49 

50 n = max(len(filename) for filename in args.filename) + 2 

51 nfiles_not_found = 0 

52 for filename in args.filename: 

53 try: 

54 format = filetype(filename) 

55 except FileNotFoundError: 

56 format = '?' 

57 description = 'No such file' 

58 nfiles_not_found += 1 

59 except UnknownFileTypeError: 

60 format = '?' 

61 description = '?' 

62 else: 

63 if format in ioformats: 

64 description = ioformats[format].description 

65 else: 

66 description = '?' 

67 

68 print('{:{}}{} ({})'.format(filename + ':', n, 

69 description, format)) 

70 if args.verbose: 

71 if format == 'traj': 

72 print_ulm_info(filename) 

73 elif format == 'bundletrajectory': 

74 print_bundletrajectory_info(filename) 

75 

76 raise SystemExit(nfiles_not_found) 

77 

78 

79def print_info(): 

80 import platform 

81 import sys 

82 from ase.dependencies import all_dependencies 

83 

84 versions = [('platform', platform.platform()), 

85 ('python-' + sys.version.split()[0], sys.executable)] 

86 

87 for name, path in versions + all_dependencies(): 

88 print('{:24} {}'.format(name, path)) 

89 

90 

91def print_formats(): 

92 from ase.io.formats import ioformats 

93 

94 print('Supported formats:') 

95 for fmtname in sorted(ioformats): 

96 fmt = ioformats[fmtname] 

97 

98 infos = [fmt.modes, 'single' if fmt.single else 'multi'] 

99 if fmt.isbinary: 

100 infos.append('binary') 

101 if fmt.encoding is not None: 

102 infos.append(fmt.encoding) 

103 infostring = '/'.join(infos) 

104 

105 moreinfo = [infostring] 

106 if fmt.extensions: 

107 moreinfo.append('ext={}'.format('|'.join(fmt.extensions))) 

108 if fmt.globs: 

109 moreinfo.append('glob={}'.format('|'.join(fmt.globs))) 

110 

111 print(' {} [{}]: {}'.format(fmt.name, 

112 ', '.join(moreinfo), 

113 fmt.description))