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
1from pathlib import Path
3from ase.io import write
4from ase.io.elk import ElkReader
5from ase.calculators.calculator import FileIOCalculator
6from ase.calculators.abc import GetOutputsMixin
9class ELK(FileIOCalculator, GetOutputsMixin):
10 command = 'elk > elk.out'
11 implemented_properties = ['energy', 'forces']
12 ignored_changes = {'pbc'}
13 discard_results_on_any_change = True
15 def __init__(self, **kwargs):
16 """Construct ELK calculator.
18 The keyword arguments (kwargs) can be one of the ASE standard
19 keywords: 'xc', 'kpts' and 'smearing' or any of ELK'
20 native keywords.
21 """
23 super().__init__(**kwargs)
25 def write_input(self, atoms, properties=None, system_changes=None):
26 FileIOCalculator.write_input(self, atoms, properties, system_changes)
28 parameters = dict(self.parameters)
29 if 'forces' in properties:
30 parameters['tforce'] = True
32 directory = Path(self.directory)
33 write(directory / 'elk.in', atoms, parameters=parameters,
34 format='elk-in')
36 def read_results(self):
37 from ase.outputs import Properties
38 reader = ElkReader(self.directory)
39 dct = dict(reader.read_everything())
41 converged = dct.pop('converged')
42 if not converged:
43 raise RuntimeError('Did not converge')
45 # (Filter results thorugh Properties for error detection)
46 props = Properties(dct)
47 self.results = dict(props)
49 def _outputmixin_get_results(self):
50 return self.results