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 re 

2import ase.io.orca as io 

3from ase.calculators.genericfileio import (CalculatorTemplate, 

4 GenericFileIOCalculator) 

5 

6 

7def get_version_from_orca_header(orca_header): 

8 match = re.search(r'Program Version (\S+)', orca_header, re.M) 

9 return match.group(1) 

10 

11 

12class OrcaProfile: 

13 def __init__(self, argv): 

14 self.argv = argv 

15 

16 def version(self): 

17 # XXX Allow MPI in argv; the version call should not be parallel. 

18 from ase.calculators.genericfileio import read_stdout 

19 stdout = read_stdout([*self.argv, "does_not_exist"]) 

20 return get_version_from_orca_header(stdout) 

21 

22 def run(self, directory, inputfile, outputfile): 

23 from subprocess import check_call 

24 with open(outputfile, 'w') as fd: 

25 check_call(self.argv + [str(inputfile)], stdout=fd, cwd=directory) 

26 

27 

28class OrcaTemplate(CalculatorTemplate): 

29 _label = 'orca' 

30 

31 def __init__(self): 

32 super().__init__(name='orca', 

33 implemented_properties=['energy', 'free_energy', 

34 'forces']) 

35 

36 self.input_file = f'{self._label}.inp' 

37 self.output_file = f'{self._label}.out' 

38 

39 def execute(self, directory, profile) -> None: 

40 profile.run(directory, self.input_file, self.output_file) 

41 

42 def write_input(self, directory, atoms, parameters, properties): 

43 parameters = dict(parameters) 

44 

45 kw = dict(charge=0, mult=1, orcasimpleinput='B3LYP def2-TZVP', 

46 orcablocks='%pal nprocs 1 end') 

47 kw.update(parameters) 

48 

49 io.write_orca(directory / self.input_file, atoms, kw) 

50 

51 def read_results(self, directory): 

52 return io.read_orca_outputs(directory, directory / self.output_file) 

53 

54 

55class ORCA(GenericFileIOCalculator): 

56 """Class for doing Orca calculations. 

57 

58 Example: 

59 

60 calc = Orca(charge=0, mult=1, orcasimpleinput='B3LYP def2-TZVP', 

61 orcablocks='%pal nprocs 16 end') 

62 """ 

63 

64 def __init__(self, *, profile=None, directory='.', **kwargs): 

65 """Construct ORCA-calculator object. 

66 

67 Parameters 

68 ========== 

69 charge: int 

70 

71 mult: int 

72 

73 orcasimpleinput : str 

74 

75 orcablocks: str 

76 

77 

78 Examples 

79 ======== 

80 Use default values: 

81 

82 

83 >>> h = Atoms('H', calculator=Orca(charge=0,mult=1,directory='water', 

84 orcasimpleinput='B3LYP def2-TZVP', 

85 orcablocks='%pal nprocs 16 end') 

86 

87 """ 

88 

89 if profile is None: 

90 profile = OrcaProfile(['orca']) 

91 

92 super().__init__(template=OrcaTemplate(), 

93 profile=profile, directory=directory, 

94 parameters=kwargs)