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; Ecut=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.120796e+02     1.490719e+00
 * time: 0.3194890022277832
     1     1.111638e+01     8.174485e-01
 * time: 0.9518349170684814
     2    -1.138542e+01     9.216282e-01
 * time: 1.5859220027923584
     3    -3.366205e+01     6.718189e-01
 * time: 2.566580057144165
     4    -4.697848e+01     4.798522e-01
 * time: 3.5446650981903076
     5    -5.673494e+01     2.169162e-01
 * time: 4.511012077331543
     6    -5.974713e+01     1.241683e-01
 * time: 5.1481781005859375
     7    -6.090220e+01     4.960279e-02
 * time: 5.7853569984436035
     8    -6.134827e+01     5.588887e-02
 * time: 6.422502040863037
     9    -6.159206e+01     3.248818e-02
 * time: 7.0652759075164795
    10    -6.180435e+01     2.595388e-02
 * time: 7.70350193977356
    11    -6.194776e+01     2.405296e-02
 * time: 8.341612100601196
    12    -6.202099e+01     2.004355e-02
 * time: 9.013633966445923
    13    -6.209155e+01     1.649897e-02
 * time: 9.6542809009552
    14    -6.213229e+01     1.632445e-02
 * time: 10.291821002960205
    15    -6.216657e+01     1.004240e-02
 * time: 10.925688028335571
    16    -6.218414e+01     8.964603e-03
 * time: 11.560282945632935
    17    -6.219657e+01     7.818241e-03
 * time: 12.198904991149902
    18    -6.220551e+01     7.161034e-03
 * time: 12.8351309299469
    19    -6.221276e+01     6.176978e-03
 * time: 13.472670078277588
    20    -6.221953e+01     5.683519e-03
 * time: 14.124213933944702
    21    -6.222618e+01     6.388651e-03
 * time: 14.759774923324585
    22    -6.223290e+01     6.264784e-03
 * time: 15.398128032684326
    23    -6.223965e+01     5.545115e-03
 * time: 16.064460039138794
    24    -6.224612e+01     5.026752e-03
 * time: 16.712337017059326
    25    -6.225134e+01     3.960175e-03
 * time: 17.351584911346436
    26    -6.225502e+01     4.283962e-03
 * time: 18.02029800415039
    27    -6.225718e+01     3.332956e-03
 * time: 18.661309003829956
    28    -6.225848e+01     3.164931e-03
 * time: 19.312525033950806
    29    -6.225947e+01     2.018276e-03
 * time: 19.980161905288696
    30    -6.226026e+01     1.366189e-03
 * time: 20.618047952651978
    31    -6.226079e+01     1.307096e-03
 * time: 21.254677057266235
    32    -6.226116e+01     9.964867e-04
 * time: 21.892165899276733
    33    -6.226140e+01     8.478696e-04
 * time: 22.529939889907837
    34    -6.226154e+01     6.052538e-04
 * time: 23.16715693473816
    35    -6.226160e+01     4.551706e-04
 * time: 23.818445920944214
    36    -6.226164e+01     2.882659e-04
 * time: 24.45527195930481
    37    -6.226165e+01     1.842265e-04
 * time: 25.092397928237915
    38    -6.226166e+01     1.493282e-04
 * time: 25.729401111602783
    39    -6.226166e+01     1.256379e-04
 * time: 26.364933967590332
    40    -6.226166e+01     7.636068e-05
 * time: 27.00313711166382
    41    -6.226166e+01     6.850130e-05
 * time: 27.641321897506714
    42    -6.226166e+01     5.608737e-05
 * time: 28.284477949142456
    43    -6.226167e+01     4.293610e-05
 * time: 28.945791959762573
    44    -6.226167e+01     3.013842e-05
 * time: 29.58295512199402
    45    -6.226167e+01     2.954166e-05
 * time: 30.279453992843628
    46    -6.226167e+01     1.794961e-05
 * time: 30.926713943481445
    47    -6.226167e+01     1.715009e-05
 * time: 31.564747095108032
    48    -6.226167e+01     1.190987e-05
 * time: 32.201854944229126
    49    -6.226167e+01     9.703870e-06
 * time: 32.83958101272583
    50    -6.226167e+01     8.450053e-06
 * time: 33.478419065475464
    51    -6.226167e+01     6.216426e-06
 * time: 34.13772797584534
    52    -6.226167e+01     4.378934e-06
 * time: 34.805152893066406
    53    -6.226167e+01     3.192002e-06
 * time: 35.4492290019989
    54    -6.226167e+01     2.980237e-06
 * time: 36.08622694015503
scfres.energies
Energy breakdown:
    Kinetic             25.7671075
    AtomicLocal         -18.8557715
    AtomicNonlocal      14.8522669
    Ewald               -67.1831486
    PspCorrection       -2.3569765
    Hartree             4.8485382 
    Xc                  -19.3336824

    total               -62.261666460765