The Pymatgen python library allows to setup
solid-state calculations using a flexible set of classes as well as an API
to an online data base of structures. Its Structure
and Lattice
objects are directly supported by the DFTK load_atoms
and load_lattice
functions, such that DFTK may be readily used to run calculation on systems
defined in pymatgen. Using the pymatgen_structure
function a conversion
from DFTK to pymatgen structures is also possible. In the following we
use this to create a silicon supercell and find its LDA ground state
using direct minimisation.
First we setup the silicon lattice in DFTK.
using DFTK
a = 10.263141334305942 # Lattice constant in Bohr
lattice = a / 2 .* [[0 1 1.]; [1 0 1.]; [1 1 0.]]
Si = ElementPsp(:Si, psp=load_psp("hgh/lda/Si-q4"))
atoms = [Si => [ones(3)/8, -ones(3)/8]];
Next we make a [2, 2, 2]
supercell using pymatgen
pystruct = pymatgen_structure(lattice, atoms)
pystruct.make_supercell([2, 2, 2])
lattice = load_lattice(pystruct)
atoms = [Si => [s.frac_coords for s in pystruct.sites]];
Setup an LDA model and discretize using
a single kpoint and a small Ecut
of 5 Hartree.
model = model_LDA(lattice, atoms)
basis = PlaneWaveBasis(model, 5, kgrid=(1, 1, 1))
PlaneWaveBasis (Ecut=5.0, 1 kpoints)
Find the ground state using direct minimisation (always using SCF is boring ...)
scfres = direct_minimization(basis, tol=1e-5);
Iter Function value Gradient norm 0 1.127014e+02 1.645968e+00 * time: 0.3686330318450928 1 1.016898e+01 9.779359e-01 * time: 2.30930495262146 2 -1.274010e+01 1.060000e+00 * time: 2.9797821044921875 3 -3.424456e+01 9.063216e-01 * time: 3.9657609462738037 4 -4.784768e+01 6.961946e-01 * time: 4.9306581020355225 5 -5.684164e+01 2.601375e-01 * time: 5.850058078765869 6 -5.965884e+01 2.301717e-01 * time: 6.458002090454102 7 -6.082223e+01 7.272457e-02 * time: 7.060070991516113 8 -6.131443e+01 7.199065e-02 * time: 7.695044040679932 9 -6.159552e+01 7.445760e-02 * time: 8.311662912368774 10 -6.182426e+01 3.323727e-02 * time: 8.909193992614746 11 -6.199562e+01 2.444121e-02 * time: 9.509629011154175 12 -6.208239e+01 1.602704e-02 * time: 10.084341049194336 13 -6.213631e+01 1.305628e-02 * time: 10.656018018722534 14 -6.217527e+01 1.290848e-02 * time: 11.235458135604858 15 -6.219647e+01 1.301033e-02 * time: 11.877615928649902 16 -6.221011e+01 1.031842e-02 * time: 12.54397201538086 17 -6.221963e+01 8.750053e-03 * time: 13.215595960617065 18 -6.222718e+01 8.129040e-03 * time: 13.878691911697388 19 -6.223367e+01 8.170635e-03 * time: 14.550910949707031 20 -6.223978e+01 6.587503e-03 * time: 15.217262029647827 21 -6.224576e+01 5.693267e-03 * time: 15.881163120269775 22 -6.225114e+01 4.800431e-03 * time: 16.548346042633057 23 -6.225541e+01 3.905803e-03 * time: 17.22310495376587 24 -6.225822e+01 2.712837e-03 * time: 17.892516136169434 25 -6.225982e+01 2.370160e-03 * time: 18.559180974960327 26 -6.226064e+01 1.733738e-03 * time: 19.22860813140869 27 -6.226107e+01 1.106682e-03 * time: 19.903645038604736 28 -6.226129e+01 9.816521e-04 * time: 20.57332706451416 29 -6.226142e+01 8.017122e-04 * time: 21.24421501159668 30 -6.226150e+01 8.347308e-04 * time: 21.888670921325684 31 -6.226155e+01 5.681335e-04 * time: 22.433687925338745 32 -6.226159e+01 4.205032e-04 * time: 22.981791019439697 33 -6.226162e+01 3.245611e-04 * time: 23.544081926345825 34 -6.226164e+01 2.339688e-04 * time: 24.08035111427307 35 -6.226165e+01 1.870522e-04 * time: 24.59943413734436 36 -6.226166e+01 1.522725e-04 * time: 25.13187599182129 37 -6.226166e+01 1.075790e-04 * time: 25.66346001625061 38 -6.226166e+01 8.723233e-05 * time: 26.193289041519165 39 -6.226167e+01 5.359562e-05 * time: 26.72635293006897 40 -6.226167e+01 4.295576e-05 * time: 27.294842004776 41 -6.226167e+01 4.193195e-05 * time: 27.819143056869507 42 -6.226167e+01 3.210610e-05 * time: 28.348798990249634 43 -6.226167e+01 2.634071e-05 * time: 28.87254500389099 44 -6.226167e+01 2.114358e-05 * time: 29.408798933029175 45 -6.226167e+01 1.536237e-05 * time: 29.928049087524414 46 -6.226167e+01 1.145162e-05 * time: 30.509958028793335 47 -6.226167e+01 7.755517e-06 * time: 31.051834106445312 48 -6.226167e+01 4.785824e-06 * time: 31.591071128845215 49 -6.226167e+01 3.233530e-06 * time: 32.10446310043335 50 -6.226167e+01 2.540508e-06 * time: 32.6425359249115
scfres.energies
Energy breakdown: Kinetic 25.7671073 AtomicLocal -18.8557662 AtomicNonlocal 14.8522624 Ewald -67.1831486 PspCorrection -2.3569765 Hartree 4.8485374 Xc -19.3336822 total -62.261666461071