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.122062e+02     1.546750e+00
 * time: 0.060420989990234375
     1     1.140141e+01     8.831914e-01
 * time: 0.17336511611938477
     2    -1.103387e+01     1.015945e+00
 * time: 0.32265496253967285
     3    -3.367975e+01     7.850911e-01
 * time: 0.4648139476776123
     4    -4.706894e+01     5.800659e-01
 * time: 0.61651611328125
     5    -5.678035e+01     2.454081e-01
 * time: 0.7825629711151123
     6    -5.972271e+01     1.744139e-01
 * time: 0.8919839859008789
     7    -6.088737e+01     6.867233e-02
 * time: 1.0016679763793945
     8    -6.134200e+01     7.063592e-02
 * time: 1.1118590831756592
     9    -6.160829e+01     5.498543e-02
 * time: 1.4407639503479004
    10    -6.182604e+01     3.118406e-02
 * time: 1.5776159763336182
    11    -6.198897e+01     2.275954e-02
 * time: 1.712846040725708
    12    -6.206683e+01     2.421771e-02
 * time: 1.8467631340026855
    13    -6.212263e+01     1.785297e-02
 * time: 1.9802250862121582
    14    -6.215515e+01     1.530212e-02
 * time: 2.520669937133789
    15    -6.217801e+01     1.146817e-02
 * time: 2.634679079055786
    16    -6.219206e+01     9.749816e-03
 * time: 2.7471179962158203
    17    -6.220185e+01     7.358913e-03
 * time: 2.859882116317749
    18    -6.220807e+01     6.273747e-03
 * time: 2.9904720783233643
    19    -6.221237e+01     5.140570e-03
 * time: 3.1007511615753174
    20    -6.221510e+01     4.720431e-03
 * time: 3.2111549377441406
    21    -6.221730e+01     3.944435e-03
 * time: 3.3398239612579346
    22    -6.221947e+01     3.995946e-03
 * time: 3.4495351314544678
    23    -6.222195e+01     4.728595e-03
 * time: 3.557559013366699
    24    -6.222531e+01     5.228908e-03
 * time: 3.6648311614990234
    25    -6.223022e+01     5.747159e-03
 * time: 3.788038969039917
    26    -6.223627e+01     6.212638e-03
 * time: 3.895599126815796
    27    -6.224411e+01     6.180573e-03
 * time: 4.004654169082642
    28    -6.225122e+01     4.727914e-03
 * time: 4.124460935592651
    29    -6.225540e+01     3.743385e-03
 * time: 4.231735944747925
    30    -6.225787e+01     3.093457e-03
 * time: 4.338299989700317
    31    -6.225927e+01     2.461936e-03
 * time: 4.445196151733398
    32    -6.226013e+01     1.923973e-03
 * time: 4.564635992050171
    33    -6.226063e+01     1.377195e-03
 * time: 4.672575950622559
    34    -6.226103e+01     1.400375e-03
 * time: 4.779787063598633
    35    -6.226129e+01     1.095775e-03
 * time: 4.900803089141846
    36    -6.226146e+01     6.933998e-04
 * time: 5.00881814956665
    37    -6.226155e+01     4.795654e-04
 * time: 5.11874794960022
    38    -6.226160e+01     3.654181e-04
 * time: 5.241986989974976
    39    -6.226163e+01     2.599057e-04
 * time: 5.353180170059204
    40    -6.226164e+01     2.107465e-04
 * time: 5.466820001602173
    41    -6.226165e+01     1.967239e-04
 * time: 5.577252149581909
    42    -6.226166e+01     1.495466e-04
 * time: 5.69870400428772
    43    -6.226166e+01     1.451209e-04
 * time: 5.809415102005005
    44    -6.226166e+01     1.061858e-04
 * time: 5.9197399616241455
    45    -6.226166e+01     7.791574e-05
 * time: 6.0438761711120605
    46    -6.226167e+01     6.075404e-05
 * time: 6.1562371253967285
    47    -6.226167e+01     4.483926e-05
 * time: 6.2660510540008545
    48    -6.226167e+01     2.991256e-05
 * time: 6.391174077987671
    49    -6.226167e+01     2.955890e-05
 * time: 6.499559164047241
    50    -6.226167e+01     1.972919e-05
 * time: 6.606780052185059
    51    -6.226167e+01     1.627034e-05
 * time: 6.714291095733643
    52    -6.226167e+01     1.446027e-05
 * time: 6.83467698097229
    53    -6.226167e+01     1.124668e-05
 * time: 6.942202091217041
    54    -6.226167e+01     7.477156e-06
 * time: 7.050029039382935
    55    -6.226167e+01     5.715175e-06
 * time: 7.169749021530151
    56    -6.226167e+01     5.363060e-06
 * time: 7.277385950088501
    57    -6.226167e+01     4.281975e-06
 * time: 7.3858630657196045
    58    -6.226167e+01     3.062070e-06
 * time: 7.50587797164917
scfres.energies
Energy breakdown:
    Kinetic             25.7671064
    AtomicLocal         -18.8557649
    AtomicNonlocal      14.8522625
    Ewald               -67.1831486
    PspCorrection       -2.3569765
    Hartree             4.8485366 
    Xc                  -19.3336818

    total               -62.261666459344