Coverage for /builds/ase/ase/ase/calculators/orca.py : 48.65%

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)
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)
12class OrcaProfile:
13 def __init__(self, argv):
14 self.argv = argv
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)
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)
28class OrcaTemplate(CalculatorTemplate):
29 _label = 'orca'
31 def __init__(self):
32 super().__init__(name='orca',
33 implemented_properties=['energy', 'free_energy',
34 'forces'])
36 self.input_file = f'{self._label}.inp'
37 self.output_file = f'{self._label}.out'
39 def execute(self, directory, profile) -> None:
40 profile.run(directory, self.input_file, self.output_file)
42 def write_input(self, directory, atoms, parameters, properties):
43 parameters = dict(parameters)
45 kw = dict(charge=0, mult=1, orcasimpleinput='B3LYP def2-TZVP',
46 orcablocks='%pal nprocs 1 end')
47 kw.update(parameters)
49 io.write_orca(directory / self.input_file, atoms, kw)
51 def read_results(self, directory):
52 return io.read_orca_outputs(directory, directory / self.output_file)
55class ORCA(GenericFileIOCalculator):
56 """Class for doing Orca calculations.
58 Example:
60 calc = Orca(charge=0, mult=1, orcasimpleinput='B3LYP def2-TZVP',
61 orcablocks='%pal nprocs 16 end')
62 """
64 def __init__(self, *, profile=None, directory='.', **kwargs):
65 """Construct ORCA-calculator object.
67 Parameters
68 ==========
69 charge: int
71 mult: int
73 orcasimpleinput : str
75 orcablocks: str
78 Examples
79 ========
80 Use default values:
83 >>> h = Atoms('H', calculator=Orca(charge=0,mult=1,directory='water',
84 orcasimpleinput='B3LYP def2-TZVP',
85 orcablocks='%pal nprocs 16 end')
87 """
89 if profile is None:
90 profile = OrcaProfile(['orca'])
92 super().__init__(template=OrcaTemplate(),
93 profile=profile, directory=directory,
94 parameters=kwargs)