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.114539e+02 1.430587e+00 * time: 0.5247831344604492 1 1.024311e+01 8.334153e-01 * time: 1.5216341018676758 2 -1.254519e+01 9.970650e-01 * time: 2.002624988555908 3 -3.430072e+01 7.073248e-01 * time: 2.7376530170440674 4 -4.772519e+01 4.926740e-01 * time: 3.4394190311431885 5 -5.696139e+01 1.810241e-01 * time: 4.159497022628784 6 -5.979199e+01 1.216476e-01 * time: 4.6528401374816895 7 -6.087323e+01 5.520677e-02 * time: 5.125286102294922 8 -6.131904e+01 6.750431e-02 * time: 5.5990049839019775 9 -6.159822e+01 3.718037e-02 * time: 6.0738091468811035 10 -6.182628e+01 2.940485e-02 * time: 6.564428091049194 11 -6.198799e+01 1.887401e-02 * time: 7.058311939239502 12 -6.205550e+01 1.520367e-02 * time: 7.528166055679321 13 -6.211748e+01 1.482379e-02 * time: 8.00123906135559 14 -6.214634e+01 1.492738e-02 * time: 8.478723049163818 15 -6.217055e+01 1.005299e-02 * time: 8.973453998565674 16 -6.218478e+01 8.838126e-03 * time: 9.44679307937622 17 -6.219549e+01 8.034873e-03 * time: 9.913613080978394 18 -6.220468e+01 8.387484e-03 * time: 10.390870094299316 19 -6.221232e+01 6.199337e-03 * time: 10.863428115844727 20 -6.221918e+01 5.874854e-03 * time: 11.341961145401001 21 -6.222567e+01 5.406984e-03 * time: 11.814752101898193 22 -6.223214e+01 6.051439e-03 * time: 12.289945125579834 23 -6.223872e+01 4.568955e-03 * time: 12.75903606414795 24 -6.224502e+01 4.160461e-03 * time: 13.237085103988647 25 -6.225009e+01 3.459964e-03 * time: 13.709795951843262 26 -6.225371e+01 3.225724e-03 * time: 14.188549995422363 27 -6.225626e+01 2.822278e-03 * time: 14.658173084259033 28 -6.225802e+01 2.404903e-03 * time: 15.136142015457153 29 -6.225926e+01 2.091743e-03 * time: 15.608386993408203 30 -6.226014e+01 2.002056e-03 * time: 16.084362030029297 31 -6.226073e+01 1.535509e-03 * time: 16.556780099868774 32 -6.226114e+01 1.007901e-03 * time: 17.03136396408081 33 -6.226140e+01 9.148031e-04 * time: 17.50363302230835 34 -6.226154e+01 7.408251e-04 * time: 17.985692977905273 35 -6.226161e+01 5.314072e-04 * time: 18.457988023757935 36 -6.226164e+01 2.945521e-04 * time: 18.93014407157898 37 -6.226165e+01 1.975451e-04 * time: 19.40602397918701 38 -6.226166e+01 2.490960e-04 * time: 19.884570121765137 39 -6.226166e+01 1.555901e-04 * time: 20.37980604171753 40 -6.226166e+01 8.147197e-05 * time: 20.8522789478302 41 -6.226166e+01 6.252579e-05 * time: 21.32368302345276 42 -6.226166e+01 4.878387e-05 * time: 21.801833152770996 43 -6.226167e+01 4.843196e-05 * time: 22.27870202064514 44 -6.226167e+01 5.374429e-05 * time: 22.748577117919922 45 -6.226167e+01 3.082213e-05 * time: 23.219125032424927 46 -6.226167e+01 2.537570e-05 * time: 23.697227001190186 47 -6.226167e+01 2.122288e-05 * time: 24.169100046157837 48 -6.226167e+01 1.503516e-05 * time: 24.644118070602417 49 -6.226167e+01 8.240850e-06 * time: 25.11432409286499 50 -6.226167e+01 5.991688e-06 * time: 25.59366202354431 51 -6.226167e+01 6.028720e-06 * time: 26.064976930618286 52 -6.226167e+01 4.229608e-06 * time: 26.5438129901886
scfres.energies
Energy breakdown: Kinetic 25.7671077 AtomicLocal -18.8557700 AtomicNonlocal 14.8522652 Ewald -67.1831486 PspCorrection -2.3569765 Hartree 4.8485382 Xc -19.3336824 total -62.261666452272