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

1import platform 

2import sys 

3 

4from ase.dependencies import all_dependencies 

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

6from ase.io.ulm import print_ulm_info 

7from ase.io.bundletrajectory import print_bundletrajectory_info 

8 

9 

10class CLICommand: 

11 """Print information about files or system. 

12 

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

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

15 

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

17 """ 

18 

19 @staticmethod 

20 def add_arguments(parser): 

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

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

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

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

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

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

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

28 help='List calculators known to ASE ' 

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

30 

31 @staticmethod 

32 def run(args): 

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 versions = [('platform', platform.platform()), 

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

82 

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

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

85 

86 

87def print_formats(): 

88 print('Supported formats:') 

89 for fmtname in sorted(ioformats): 

90 fmt = ioformats[fmtname] 

91 

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

93 if fmt.isbinary: 

94 infos.append('binary') 

95 if fmt.encoding is not None: 

96 infos.append(fmt.encoding) 

97 infostring = '/'.join(infos) 

98 

99 moreinfo = [infostring] 

100 if fmt.extensions: 

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

102 if fmt.globs: 

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

104 

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

106 ', '.join(moreinfo), 

107 fmt.description))