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

In [2]:
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.

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.117985e+02     1.590923e+00
 * time: 0.3003361225128174
     1     1.069771e+01     8.717298e-01
 * time: 1.7437100410461426
     2    -1.164679e+01     9.936743e-01
 * time: 2.2585911750793457
     3    -3.385612e+01     7.778561e-01
 * time: 3.03285813331604
     4    -4.721433e+01     5.949236e-01
 * time: 3.790621042251587
     5    -5.686587e+01     2.016641e-01
 * time: 4.569359064102173
     6    -5.976898e+01     1.261770e-01
 * time: 5.096089124679565
     7    -6.089150e+01     5.426981e-02
 * time: 5.603931188583374
     8    -6.135051e+01     5.172242e-02
 * time: 6.136151075363159
     9    -6.161883e+01     3.354035e-02
 * time: 6.648972988128662
    10    -6.184550e+01     2.645759e-02
 * time: 7.163583040237427
    11    -6.200032e+01     2.434070e-02
 * time: 7.6688551902771
    12    -6.207016e+01     2.238588e-02
 * time: 8.19186019897461
    13    -6.212313e+01     1.573530e-02
 * time: 8.715403079986572
    14    -6.215300e+01     1.546576e-02
 * time: 9.216012001037598
    15    -6.217512e+01     1.154445e-02
 * time: 9.762562990188599
    16    -6.218861e+01     8.847764e-03
 * time: 10.271372079849243
    17    -6.219859e+01     9.081060e-03
 * time: 10.770211219787598
    18    -6.220620e+01     6.892419e-03
 * time: 11.311005115509033
    19    -6.221225e+01     6.860784e-03
 * time: 11.860688209533691
    20    -6.221770e+01     7.184812e-03
 * time: 12.392791032791138
    21    -6.222322e+01     7.612277e-03
 * time: 12.930358171463013
    22    -6.222924e+01     7.607248e-03
 * time: 13.456943035125732
    23    -6.223590e+01     6.221420e-03
 * time: 13.989214181900024
    24    -6.224277e+01     4.714710e-03
 * time: 14.497457027435303
    25    -6.224872e+01     4.793407e-03
 * time: 15.014835119247437
    26    -6.225334e+01     3.897493e-03
 * time: 15.511803150177002
    27    -6.225624e+01     3.165638e-03
 * time: 16.028808116912842
    28    -6.225806e+01     2.641611e-03
 * time: 16.52856206893921
    29    -6.225930e+01     2.098812e-03
 * time: 17.02904200553894
    30    -6.226023e+01     1.934131e-03
 * time: 17.53640913963318
    31    -6.226077e+01     1.799168e-03
 * time: 18.046457052230835
    32    -6.226113e+01     1.583314e-03
 * time: 18.54521417617798
    33    -6.226136e+01     1.181721e-03
 * time: 19.052999019622803
    34    -6.226150e+01     7.151600e-04
 * time: 19.556361198425293
    35    -6.226159e+01     4.959546e-04
 * time: 20.081027030944824
    36    -6.226163e+01     2.901746e-04
 * time: 20.592272996902466
    37    -6.226164e+01     2.625335e-04
 * time: 21.09120202064514
    38    -6.226165e+01     2.165411e-04
 * time: 21.621711015701294
    39    -6.226166e+01     1.371886e-04
 * time: 22.152387142181396
    40    -6.226166e+01     9.780060e-05
 * time: 22.660459995269775
    41    -6.226166e+01     8.195913e-05
 * time: 23.161694049835205
    42    -6.226166e+01     5.745397e-05
 * time: 23.664014101028442
    43    -6.226167e+01     4.921495e-05
 * time: 24.173158168792725
    44    -6.226167e+01     3.891911e-05
 * time: 24.681730031967163
    45    -6.226167e+01     3.256673e-05
 * time: 25.189527988433838
    46    -6.226167e+01     2.447867e-05
 * time: 25.687406063079834
    47    -6.226167e+01     1.967444e-05
 * time: 26.18551206588745
    48    -6.226167e+01     1.371401e-05
 * time: 26.707045078277588
    49    -6.226167e+01     9.160746e-06
 * time: 27.2188081741333
    50    -6.226167e+01     7.410059e-06
 * time: 27.744413137435913
    51    -6.226167e+01     5.715342e-06
 * time: 28.25138807296753
    52    -6.226167e+01     4.625104e-06
 * time: 28.7817440032959
    53    -6.226167e+01     4.292012e-06
 * time: 29.293106079101562
    54    -6.226167e+01     3.369651e-06
 * time: 29.803954124450684
In [5]:
scfres.energies
Out[5]:
Energy breakdown:
    Kinetic             25.7671077
    AtomicLocal         -18.8557753
    AtomicNonlocal      14.8522699
    Ewald               -67.1831486
    PspCorrection       -2.3569765
    Hartree             4.8485391 
    Xc                  -19.3336827

    total               -62.261666458357