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 os 

2import shutil 

3import importlib 

4from ase.calculators.calculator import names 

5 

6builtins = {'eam', 'emt', 'ff', 'lj', 'morse', 'tip3p', 'tip4p'} 

7 

8required_envvars = {'abinit': ['ABINIT_PP_PATH'], 

9 'elk': ['ELK_SPECIES_PATH'], 

10 'openmx': ['OPENMX_DFT_DATA_PATH']} 

11 

12default_executables = {'abinit': ['abinit'], 

13 'cp2k': ['cp2k_shell', 'cp2k_shell.psmp', 

14 'cp2k_shell.popt', 'cp2k_shell.ssmp', 

15 'cp2k_shell.sopt'], 

16 'dftb': ['dftb+'], 

17 'elk': ['elk', 'elk-lapw'], 

18 'espresso': ['pw.x'], 

19 'gamess_us': ['rungms'], 

20 'gromacs': ['gmx', 'gmx_d', 'gmx_mpi', 'gmx_mpi_d'], 

21 'lammpsrun': ['lammps', 'lmp', 'lmp_mpi', 'lmp_serial'], 

22 'mopac': ['mopac', 'run_mopac7'], # run_mopac7: debian 

23 'nwchem': ['nwchem'], 

24 'octopus': ['octopus'], 

25 'openmx': ['openmx'], 

26 'psi4': ['psi4'], 

27 'siesta': ['siesta'], 

28 } 

29 

30python_modules = {'gpaw': 'gpaw', 

31 'asap': 'asap3', 

32 'lammpslib': 'lammps'} 

33 

34 

35def get_executable_env_var(name): 

36 return 'ASE_{}_COMMAND'.format(name.upper()) 

37 

38 

39def detect(name): 

40 assert name in names 

41 d = {'name': name} 

42 

43 if name in builtins: 

44 d['type'] = 'builtin' 

45 return d 

46 

47 if name in python_modules: 

48 loader = importlib.find_loader(python_modules[name]) 

49 if loader is not None: 

50 d['type'] = 'python' 

51 d['module'] = python_modules[name] 

52 d['path'] = loader.get_filename() 

53 return d 

54 

55 envvar = get_executable_env_var(name) 

56 if envvar in os.environ: 

57 d['command'] = os.environ[envvar] 

58 d['envvar'] = envvar 

59 d['type'] = 'environment' 

60 return d 

61 

62 if name in default_executables: 

63 commands = default_executables[name] 

64 for command in commands: 

65 fullpath = shutil.which(command) 

66 if fullpath: 

67 d['command'] = command 

68 d['fullpath'] = fullpath 

69 d['type'] = 'which' 

70 return d 

71 

72 

73def detect_calculators(): 

74 configs = {} 

75 for name in names: 

76 result = detect(name) 

77 if result: 

78 configs[name] = result 

79 return configs 

80 

81 

82def format_configs(configs): 

83 messages = [] 

84 for name in names: 

85 config = configs.get(name) 

86 

87 if config is None: 

88 state = 'no' 

89 else: 

90 type = config['type'] 

91 if type == 'builtin': 

92 state = 'yes, builtin: module ase.calculators.{name}' 

93 elif type == 'python': 

94 state = 'yes, python: {module} ▶ {path}' 

95 elif type == 'which': 

96 state = 'yes, shell command: {command} ▶ {fullpath}' 

97 else: 

98 state = 'yes, environment: ${envvar} ▶ {command}' 

99 

100 state = state.format(**config) 

101 

102 messages.append('{:<10s} {}'.format(name, state)) 

103 return messages