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.124047e+02     1.737400e+00
 * time: 0.32975101470947266
     1     1.147245e+01     9.971894e-01
 * time: 0.9734299182891846
     2    -1.185201e+01     1.146212e+00
 * time: 1.6162528991699219
     3    -3.405299e+01     8.478540e-01
 * time: 2.5707290172576904
     4    -4.788802e+01     5.422578e-01
 * time: 3.558837890625
     5    -5.703640e+01     1.982005e-01
 * time: 4.513926982879639
     6    -5.988251e+01     1.238123e-01
 * time: 5.156991958618164
     7    -6.096547e+01     4.988828e-02
 * time: 5.802771091461182
     8    -6.136353e+01     6.542123e-02
 * time: 6.447550058364868
     9    -6.165793e+01     4.359152e-02
 * time: 7.093203067779541
    10    -6.184484e+01     2.789609e-02
 * time: 7.734643936157227
    11    -6.198482e+01     2.341974e-02
 * time: 8.409734010696411
    12    -6.204149e+01     1.785325e-02
 * time: 9.075021982192993
    13    -6.210474e+01     1.932644e-02
 * time: 9.721519947052002
    14    -6.214301e+01     1.490344e-02
 * time: 10.366554021835327
    15    -6.218434e+01     1.230935e-02
 * time: 11.009927988052368
    16    -6.221139e+01     1.014416e-02
 * time: 11.654330015182495
    17    -6.223125e+01     8.339056e-03
 * time: 12.29921293258667
    18    -6.224238e+01     5.401059e-03
 * time: 12.950536966323853
    19    -6.224919e+01     4.703271e-03
 * time: 13.594547986984253
    20    -6.225274e+01     4.103427e-03
 * time: 14.239856958389282
    21    -6.225516e+01     4.233050e-03
 * time: 14.90433406829834
    22    -6.225714e+01     3.235470e-03
 * time: 15.578716039657593
    23    -6.225877e+01     2.730045e-03
 * time: 16.22347402572632
    24    -6.225995e+01     2.091242e-03
 * time: 16.867334127426147
    25    -6.226071e+01     1.685623e-03
 * time: 17.542109966278076
    26    -6.226118e+01     1.366643e-03
 * time: 18.1875319480896
    27    -6.226141e+01     9.610386e-04
 * time: 18.83926510810852
    28    -6.226152e+01     6.695567e-04
 * time: 19.484133005142212
    29    -6.226158e+01     6.125197e-04
 * time: 20.129208087921143
    30    -6.226161e+01     4.704108e-04
 * time: 20.788333892822266
    31    -6.226163e+01     3.498887e-04
 * time: 21.434444904327393
    32    -6.226164e+01     2.428016e-04
 * time: 22.077675104141235
    33    -6.226165e+01     2.056124e-04
 * time: 22.722400903701782
    34    -6.226166e+01     1.634893e-04
 * time: 23.366693019866943
    35    -6.226166e+01     1.559492e-04
 * time: 24.01104712486267
    36    -6.226166e+01     1.021431e-04
 * time: 24.654725074768066
    37    -6.226166e+01     6.181674e-05
 * time: 25.29987096786499
    38    -6.226167e+01     4.508613e-05
 * time: 25.974488019943237
    39    -6.226167e+01     3.426573e-05
 * time: 26.637224912643433
    40    -6.226167e+01     2.567285e-05
 * time: 27.281688928604126
    41    -6.226167e+01     1.983255e-05
 * time: 27.925527095794678
    42    -6.226167e+01     1.356490e-05
 * time: 28.570449113845825
    43    -6.226167e+01     1.086126e-05
 * time: 29.2172269821167
    44    -6.226167e+01     8.579451e-06
 * time: 29.863539934158325
    45    -6.226167e+01     8.079630e-06
 * time: 30.507451057434082
    46    -6.226167e+01     6.953052e-06
 * time: 31.1516330242157
    47    -6.226167e+01     4.839637e-06
 * time: 31.82818102836609
    48    -6.226167e+01     4.386304e-06
 * time: 32.485554933547974
    49    -6.226167e+01     3.666303e-06
 * time: 33.125221967697144
scfres.energies
Energy breakdown:
    Kinetic             25.7671061
    AtomicLocal         -18.8557676
    AtomicNonlocal      14.8522653
    Ewald               -67.1831486
    PspCorrection       -2.3569765
    Hartree             4.8485367 
    Xc                  -19.3336818

    total               -62.261666460327