Creating supercells with pymatgen
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.116165e+02 1.595093e+00 * time: 0.33286309242248535 1 1.078797e+01 9.156955e-01 * time: 0.9872231483459473 2 -1.256763e+01 1.027741e+00 * time: 1.6302480697631836 3 -3.463739e+01 8.034406e-01 * time: 2.5624701976776123 4 -4.839493e+01 5.524822e-01 * time: 3.5049710273742676 5 -5.727998e+01 2.241591e-01 * time: 4.4793291091918945 6 -6.004665e+01 1.170688e-01 * time: 5.133910179138184 7 -6.108703e+01 4.551192e-02 * time: 5.7683281898498535 8 -6.145780e+01 6.834985e-02 * time: 6.420022010803223 9 -6.173709e+01 2.848334e-02 * time: 7.05745005607605 10 -6.191684e+01 2.481016e-02 * time: 7.704214096069336 11 -6.204338e+01 1.747306e-02 * time: 8.329638004302979 12 -6.209183e+01 1.318350e-02 * time: 8.96438717842102 13 -6.213959e+01 1.253855e-02 * time: 9.60030221939087 14 -6.216126e+01 1.178414e-02 * time: 10.264870166778564 15 -6.217901e+01 7.905081e-03 * time: 10.914113998413086 16 -6.218937e+01 8.512158e-03 * time: 11.572018146514893 17 -6.219799e+01 6.994166e-03 * time: 12.196112155914307 18 -6.220582e+01 8.828663e-03 * time: 12.826184034347534 19 -6.221289e+01 1.069237e-02 * time: 13.451451063156128 20 -6.222010e+01 8.963827e-03 * time: 14.083791017532349 21 -6.222751e+01 7.772847e-03 * time: 14.745863199234009 22 -6.223492e+01 5.076025e-03 * time: 15.486841201782227 23 -6.224185e+01 5.212701e-03 * time: 16.12724804878235 24 -6.224773e+01 4.344925e-03 * time: 16.806361198425293 25 -6.225192e+01 3.753493e-03 * time: 17.43653702735901 26 -6.225485e+01 2.844808e-03 * time: 18.069733142852783 27 -6.225694e+01 2.704612e-03 * time: 18.71946120262146 28 -6.225845e+01 2.781474e-03 * time: 19.376253128051758 29 -6.225963e+01 2.216590e-03 * time: 20.00806713104248 30 -6.226046e+01 1.803127e-03 * time: 20.645143032073975 31 -6.226099e+01 1.130028e-03 * time: 21.769846200942993 32 -6.226131e+01 8.939546e-04 * time: 22.42209506034851 33 -6.226149e+01 6.091373e-04 * time: 23.06603217124939 34 -6.226158e+01 4.862607e-04 * time: 23.68917417526245 35 -6.226162e+01 2.906594e-04 * time: 24.319064140319824 36 -6.226164e+01 2.455024e-04 * time: 24.956881999969482 37 -6.226165e+01 2.291226e-04 * time: 25.694447994232178 38 -6.226165e+01 1.646022e-04 * time: 26.32555913925171 39 -6.226166e+01 1.312532e-04 * time: 26.99914813041687 40 -6.226166e+01 1.165505e-04 * time: 27.626201152801514 41 -6.226166e+01 8.940316e-05 * time: 28.25730800628662 42 -6.226166e+01 8.340269e-05 * time: 28.89611315727234 43 -6.226167e+01 6.053050e-05 * time: 29.56021213531494 44 -6.226167e+01 4.171746e-05 * time: 30.193737030029297 45 -6.226167e+01 2.133918e-05 * time: 30.84687614440918 46 -6.226167e+01 1.495607e-05 * time: 31.479637145996094 47 -6.226167e+01 9.295868e-06 * time: 32.128427028656006 48 -6.226167e+01 6.786965e-06 * time: 32.7562141418457 49 -6.226167e+01 7.795683e-06 * time: 33.41126203536987 50 -6.226167e+01 6.297562e-06 * time: 34.109955072402954 51 -6.226167e+01 5.727451e-06 * time: 34.768179178237915 52 -6.226167e+01 4.335905e-06 * time: 35.461162090301514 53 -6.226167e+01 3.264202e-06 * time: 36.11816906929016 54 -6.226167e+01 2.526422e-06 * time: 36.75604605674744 55 -6.226167e+01 1.679104e-06 * time: 37.40198016166687 56 -6.226167e+01 1.260257e-06 * time: 38.03555417060852
scfres.energies
Energy breakdown: Kinetic 25.7671064 AtomicLocal -18.8557670 AtomicNonlocal 14.8522645 Ewald -67.1831486 PspCorrection -2.3569765 Hartree 4.8485366 Xc -19.3336818 total -62.261666462800