First Calculations
The examples below run one molecular and one periodic CIDER calculation. The complete PySCF and GPAW guides cover numerical choices, properties, and restarts.
Molecule with PySCF
The packaged CIDER26XC molecular model uses the normal PySCF molecular and SCF objects:
1#!/usr/bin/env python
2"""Closed-shell molecular CIDER26XC calculation in PySCF."""
3
4import argparse
5
6from pyscf import dft, gto
7
8from ciderpress.pyscf.dft import make_cider_calc
9
10MODELS = ("CIDER26XCCHEM", "CIDER26XCCHEMD4", "CIDER26XCSURFSCI")
11
12
13def main():
14 parser = argparse.ArgumentParser()
15 parser.add_argument("--model", choices=MODELS, default="CIDER26XCCHEM")
16 args = parser.parse_args()
17
18 mol = gto.M(
19 atom="""
20 O 0.000000 0.000000 0.117790
21 H 0.000000 0.755453 -0.471161
22 H 0.000000 -0.755453 -0.471161
23 """,
24 basis="def2-tzvp",
25 charge=0,
26 spin=0,
27 )
28
29 base = dft.RKS(mol)
30 base.grids.level = 3
31 mf = make_cider_calc(base, args.model)
32 mf = mf.density_fit(auxbasis="def2-universal-jfit")
33 mf.conv_tol = 1e-9
34 mf.max_cycle = 200
35 energy = mf.kernel()
36
37 if not mf.converged:
38 raise RuntimeError("CIDER SCF did not converge")
39
40 print(f"model = {args.model}")
41 print(f"total energy = {energy:.12f} Ha")
42 if hasattr(mf, "e_vdw_expected"):
43 print(f"SCF/base energy = {mf.e_tot_base:.12f} Ha")
44 print(f"expected dispersion = {mf.e_vdw_expected:.12f} Ha")
45 print(f"dispersion adjustment = {mf.e_vdw_delta:.12f} Ha")
46
47
48if __name__ == "__main__":
49 main()
Run it from the repository root with:
python examples/pyscf/production_calc.py --model CIDER26XCCHEM
The example raises RuntimeError when the SCF does not converge. It prints
the base, expected dispersion, and adjustment terms for every CIDER26XC
model. With CIDER26XCCHEMD4 they show how the final total was assembled;
CIDER26XCCHEM and CIDER26XCSURFSCI print zero for the dispersion
entries.
Exchange-only model with PySCF
Packaged CIDER23X and CIDER24X are exchange functionals. The following example supplies the PBE0/CIDER surrogate composition:
1#!/usr/bin/env python
2"""Run a packaged CIDER23X or CIDER24X exchange model with PySCF."""
3
4import argparse
5
6from pyscf import dft, gto
7
8from ciderpress.dft.model_utils import CIDER23X_MODELS, CIDER24X_MODELS
9from ciderpress.pyscf.dft import make_cider_calc
10
11MODELS = CIDER23X_MODELS + CIDER24X_MODELS
12
13
14def main():
15 parser = argparse.ArgumentParser()
16 parser.add_argument("--model", choices=MODELS, default="CIDER23X_NL_MGGA_DTR")
17 args = parser.parse_args()
18
19 mol = gto.M(
20 atom="H 0 0 0; H 0 0 0.74",
21 basis="def2-svp",
22 charge=0,
23 spin=0,
24 )
25
26 base = dft.RKS(mol)
27 base.grids.level = 3
28 mf = make_cider_calc(
29 base,
30 args.model,
31 xmix=0.25,
32 xkernel="GGA_X_PBE",
33 ckernel="GGA_C_PBE",
34 )
35 mf = mf.density_fit(auxbasis="def2-universal-jfit")
36 mf.conv_tol = 1e-9
37 mf.max_cycle = 200
38 energy = mf.kernel()
39
40 if not mf.converged:
41 raise RuntimeError("CIDER SCF did not converge")
42 print(f"model = {args.model}")
43 print(f"total energy = {energy:.12f} Ha")
44
45
46if __name__ == "__main__":
47 main()
The explicit xmix, xkernel, and ckernel arguments define the
surrogate-hybrid composition.
For CIDER24X, install ciderpress[cider24] and select the corresponding name.
Periodic solid with GPAW
The periodic example first writes a full PBE checkpoint and then restarts it with CIDER26XCSURFSCI:
1#!/usr/bin/env python
2"""PBE-seeded periodic CIDER26XCSURFSCI calculation in classic GPAW."""
3
4from ase.build import bulk
5from ase.parallel import parprint
6from gpaw import GPAW, PW, Mixer
7
8from ciderpress.gpaw.calculator import CiderGPAW, get_cider_functional
9
10
11def main():
12 atoms = bulk("Si")
13 atoms.calc = GPAW(
14 xc="PBE",
15 mode=PW(400),
16 kpts={"size": (4, 4, 4), "gamma": False},
17 occupations={"name": "fermi-dirac", "width": 0.1},
18 mixer=Mixer(0.05, 5, 50),
19 convergence={
20 "energy": 1e-5,
21 "density": 1e-5,
22 "eigenstates": 1e-3,
23 "bands": "occupied",
24 },
25 parallel={"augment_grids": True},
26 txt="si_pbe.txt",
27 )
28 atoms.get_potential_energy()
29 # The production models are meta-GGAs and need the wavefunctions to
30 # reconstruct the kinetic-energy density after restart.
31 atoms.calc.write("si_pbe.gpw", mode="all")
32
33 xc = get_cider_functional(
34 "CIDER26XCSURFSCI",
35 xmix=1.0,
36 xkernel=None,
37 ckernel=None,
38 pasdw_store_funcs=False,
39 )
40 calc = CiderGPAW(
41 restart="si_pbe.gpw",
42 xc=xc,
43 mixer=Mixer(0.05, 5, 50),
44 occupations={"name": "fermi-dirac", "width": 0.1},
45 maxiter=500,
46 parallel={"augment_grids": True},
47 txt="si_cider.txt",
48 )
49 atoms = calc.get_atoms()
50 atoms.calc = calc
51 energy = atoms.get_potential_energy()
52 calc.write("si_cider.gpw", mode="all")
53 parprint(f"CIDER26XCSURFSCI energy = {energy:.12f} eV")
54
55
56if __name__ == "__main__":
57 main()
Run GPAW examples with the MPI launcher and rank count appropriate for the installed GPAW build, for example:
mpirun -np 4 python examples/gpaw/production_calc.py
Continue with Molecular Calculations with PySCF or Periodic and Isolated Calculations with GPAW; Handling SCF Convergence Issues gives concrete restart settings for difficult SCF calculations.