# 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.

In [1]:
using DFTK

a = 10.263141334305942  # Lattice constant in Bohr
lattice = a / 2 .* [[0 1 1.]; [1 0 1.]; [1 1 0.]]
atoms = [Si => [ones(3)/8, -ones(3)/8]];


Next we make a [2, 2, 2] supercell using pymatgen

In [2]:
pystruct = pymatgen_structure(lattice, atoms)
pystruct.make_supercell([2, 2, 2])
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.

In [3]:
model = model_LDA(lattice, atoms)
basis = PlaneWaveBasis(model, 5, kgrid=(1, 1, 1))

Out[3]:
PlaneWaveBasis (Ecut=5.0, 1 kpoints)

Find the ground state using direct minimisation (always using SCF is boring ...)

In [4]:
scfres = direct_minimization(basis, tol=1e-5);

Iter     Function value   Gradient norm
0     1.121736e+02     1.543532e+00
* time: 0.6848011016845703
1     1.085481e+01     8.940654e-01
* time: 2.0310211181640625
2    -1.228226e+01     9.634674e-01
* time: 2.718388080596924
3    -3.434843e+01     8.233876e-01
* time: 3.668174982070923
4    -4.800090e+01     6.609128e-01
* time: 4.6324169635772705
5    -5.680566e+01     2.845932e-01
* time: 5.593683958053589
6    -5.945220e+01     2.747412e-01
* time: 6.2140419483184814
7    -6.062499e+01     1.031030e-01
* time: 6.88067102432251
8    -6.119585e+01     4.246864e-02
* time: 7.520668983459473
9    -6.147872e+01     3.586425e-02
* time: 8.176743030548096
10    -6.171315e+01     2.937246e-02
* time: 8.81228494644165
11    -6.188294e+01     2.458883e-02
* time: 9.448822021484375
12    -6.200539e+01     2.401420e-02
* time: 10.112662076950073
13    -6.206713e+01     1.945006e-02
* time: 10.76079797744751
14    -6.212006e+01     1.233435e-02
* time: 11.42314100265503
15    -6.214706e+01     1.386318e-02
* time: 12.083470106124878
16    -6.216790e+01     1.299556e-02
* time: 12.715481996536255
17    -6.218216e+01     1.111749e-02
* time: 13.33731198310852
18    -6.219355e+01     7.730938e-03
* time: 13.993356943130493
19    -6.220106e+01     6.446501e-03
* time: 14.626105070114136
20    -6.220724e+01     5.986005e-03
* time: 15.266288995742798
21    -6.221295e+01     5.995300e-03
* time: 15.976226091384888
22    -6.221869e+01     7.461268e-03
* time: 16.59588098526001
23    -6.222413e+01     5.387484e-03
* time: 17.21696710586548
24    -6.222934e+01     6.147206e-03
* time: 17.849141120910645
25    -6.223458e+01     5.137485e-03
* time: 18.507045030593872
26    -6.224012e+01     5.840076e-03
* time: 19.14129400253296
27    -6.224531e+01     5.770205e-03
* time: 19.767625093460083
28    -6.225026e+01     5.031678e-03
* time: 20.40631914138794
29    -6.225440e+01     3.793222e-03
* time: 21.080587148666382
30    -6.225735e+01     3.095922e-03
* time: 21.727144956588745
31    -6.225921e+01     2.731297e-03
* time: 22.379591941833496
32    -6.226032e+01     1.728797e-03
* time: 23.009972095489502
33    -6.226097e+01     1.181067e-03
* time: 23.648182153701782
34    -6.226129e+01     8.241737e-04
* time: 24.296297073364258
35    -6.226147e+01     6.578705e-04
* time: 24.946780920028687
36    -6.226155e+01     5.156948e-04
* time: 25.58837914466858
37    -6.226159e+01     4.375162e-04
* time: 26.22631597518921
38    -6.226162e+01     2.879797e-04
* time: 26.893393993377686
39    -6.226163e+01     2.372885e-04
* time: 27.50838804244995
40    -6.226164e+01     2.254807e-04
* time: 28.134989976882935
41    -6.226165e+01     1.852172e-04
* time: 28.785408973693848
42    -6.226166e+01     1.371360e-04
* time: 29.449342012405396
43    -6.226166e+01     1.055437e-04
* time: 30.081033945083618
44    -6.226166e+01     7.774477e-05
* time: 30.751049041748047
45    -6.226167e+01     5.615661e-05
* time: 31.388726949691772
46    -6.226167e+01     3.651206e-05
* time: 32.03332495689392
47    -6.226167e+01     2.451593e-05
* time: 32.68710207939148
48    -6.226167e+01     1.905260e-05
* time: 33.34993505477905
49    -6.226167e+01     1.193822e-05
* time: 34.00900602340698
50    -6.226167e+01     1.030623e-05
* time: 34.65874195098877
51    -6.226167e+01     8.943683e-06
* time: 35.31452298164368
52    -6.226167e+01     6.612344e-06
* time: 35.996204137802124
53    -6.226167e+01     6.356308e-06
* time: 36.64549994468689
54    -6.226167e+01     4.779317e-06
* time: 37.27297496795654
55    -6.226167e+01     3.616759e-06
* time: 37.9034321308136
56    -6.226167e+01     2.942389e-06
* time: 38.53810906410217
57    -6.226167e+01     1.924942e-06
* time: 39.21419310569763

In [5]:
scfres.energies

Out[5]:
Energy breakdown:
Kinetic             25.7671068
AtomicLocal         -18.8557706
AtomicNonlocal      14.8522671
Ewald               -67.1831486
PspCorrection       -2.3569765
Hartree             4.8485376
Xc                  -19.3336821

total               -62.261666461944