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.114418e+02 1.526206e+00
* time: 0.047692060470581055
1 1.049564e+01 8.605299e-01
* time: 0.14389991760253906
2 -1.134795e+01 1.060693e+00
* time: 0.2367839813232422
3 -3.404157e+01 8.941909e-01
* time: 0.3957839012145996
4 -4.740175e+01 6.439889e-01
* time: 0.5156588554382324
5 -5.702877e+01 2.358206e-01
* time: 0.6330578327178955
6 -5.993787e+01 1.260153e-01
* time: 0.7251260280609131
7 -6.101202e+01 5.559138e-02
* time: 0.8184869289398193
8 -6.138705e+01 6.000568e-02
* time: 0.9138128757476807
9 -6.162523e+01 3.829022e-02
* time: 1.0091838836669922
10 -6.181351e+01 2.763832e-02
* time: 1.1057829856872559
11 -6.196712e+01 2.065320e-02
* time: 1.2032098770141602
12 -6.203423e+01 1.986066e-02
* time: 1.317816972732544
13 -6.210270e+01 1.659723e-02
* time: 1.411789894104004
14 -6.213859e+01 1.367832e-02
* time: 1.5082659721374512
15 -6.217271e+01 1.120699e-02
* time: 1.6009080410003662
16 -6.219195e+01 1.026648e-02
* time: 1.695051908493042
17 -6.220646e+01 8.779729e-03
* time: 1.7879760265350342
18 -6.221666e+01 7.002889e-03
* time: 1.8813378810882568
19 -6.222467e+01 7.553672e-03
* time: 1.974294900894165
20 -6.223173e+01 6.789086e-03
* time: 2.0674619674682617
21 -6.223870e+01 7.977724e-03
* time: 2.1975958347320557
22 -6.224586e+01 6.431757e-03
* time: 2.3457388877868652
23 -6.225236e+01 5.454031e-03
* time: 2.452260971069336
24 -6.225679e+01 3.493221e-03
* time: 2.5463459491729736
25 -6.225909e+01 2.430389e-03
* time: 2.6400208473205566
26 -6.226021e+01 1.673224e-03
* time: 2.7346689701080322
27 -6.226074e+01 1.493230e-03
* time: 2.8290178775787354
28 -6.226104e+01 1.197603e-03
* time: 2.921243906021118
29 -6.226123e+01 8.886174e-04
* time: 3.0136139392852783
30 -6.226137e+01 8.574643e-04
* time: 3.1082520484924316
31 -6.226148e+01 6.646317e-04
* time: 3.2020649909973145
32 -6.226155e+01 5.598096e-04
* time: 3.3101859092712402
33 -6.226160e+01 4.040120e-04
* time: 3.4022579193115234
34 -6.226163e+01 2.922187e-04
* time: 3.4949469566345215
35 -6.226165e+01 2.480550e-04
* time: 3.5875749588012695
36 -6.226166e+01 1.668518e-04
* time: 3.682229995727539
37 -6.226166e+01 1.232849e-04
* time: 3.775825023651123
38 -6.226166e+01 6.498902e-05
* time: 3.869248867034912
39 -6.226166e+01 5.376250e-05
* time: 3.962890863418579
40 -6.226167e+01 4.511735e-05
* time: 4.05699896812439
41 -6.226167e+01 3.597531e-05
* time: 4.1641528606414795
42 -6.226167e+01 2.807706e-05
* time: 4.258270978927612
43 -6.226167e+01 2.550638e-05
* time: 4.352470874786377
44 -6.226167e+01 2.046943e-05
* time: 4.445940971374512
45 -6.226167e+01 1.608685e-05
* time: 4.538280963897705
46 -6.226167e+01 1.207549e-05
* time: 4.630908966064453
47 -6.226167e+01 8.533072e-06
* time: 4.724808931350708
48 -6.226167e+01 7.089667e-06
* time: 4.818917989730835
49 -6.226167e+01 5.092450e-06
* time: 4.914306879043579
50 -6.226167e+01 3.498343e-06
* time: 5.008074998855591scfres.energiesEnergy breakdown:
Kinetic 25.7671069
AtomicLocal -18.8557669
AtomicNonlocal 14.8522634
Ewald -67.1831486
PspCorrection -2.3569765
Hartree 4.8485374
Xc -19.3336822
total -62.261666460080