Scripting interface

The recipes can be called directly as regular python functions making more advanced operations that are not easily done in the terminal easily obtainable:

 1"""Convergence study of silicon band gap."""
 2
 3from asr.gs import main as gs
 4from ase.build import bulk
 5
 6atoms = bulk('Si')
 7
 8densities = [2, 3, 4]
 9cutoffs = [200, 300, 400]
10records = []
11for density in densities:
12    for ecut in cutoffs:
13        record = gs(
14            atoms=atoms,
15            calculator=dict(
16                name='gpaw',
17                kpts=dict(density=density),
18                mode=dict(name='pw', ecut=ecut),
19                txt=None,
20            )
21        )
22        records.append(record)
23
24
25from matplotlib import pyplot as plt
26import numpy as np
27
28data = np.zeros((len(densities), len(cutoffs)))
29for record in records:
30    ecut = record.parameters.calculator['mode']['ecut']
31    density = record.parameters.calculator['kpts']['density']
32    etot = record.result.etot
33    data[cutoffs.index(ecut), densities.index(density)] = etot
34
35
36for i, ecut in enumerate(cutoffs):
37    plt.plot(densities, data[i], label=ecut)
38
39plt.legend()
40plt.ylabel('Total energy (eV)')
41plt.xlabel('K-point density (Å)')
42plt.tight_layout()
43plt.savefig('si-convergence.svg')
44plt.show()
../../../_images/si-convergence.svg

If I run the script again, it will run very quickly, since everything already was calculated.

$ p converge-si.py
asr.gs::main: Found cached record.uid=6a4975cc171b47c28c2fa8f52038d8c2
asr.gs::main: Found cached record.uid=60f2a9bc721d42e8877656fde583155e
asr.gs::main: Found cached record.uid=ac46b78c46b948399c3829d07ce055f8
asr.gs::main: Found cached record.uid=a7977ad9dbda4f9aaedd36566adc75ac
asr.gs::main: Found cached record.uid=4108625786e9412d95ad5382cf630758
asr.gs::main: Found cached record.uid=0b2dd0f3e1e74a67b4ff829224dbec44
asr.gs::main: Found cached record.uid=ee0e6f0b882144638f4d0f29b79b16fb
asr.gs::main: Found cached record.uid=3a5dbf6073414c3f860b6769f89cb8cd
asr.gs::main: Found cached record.uid=67785f4d333f49c996502fb85f430525