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.116056e+02     1.577682e+00
 * time: 1.1378211975097656
     1     1.067926e+01     9.056192e-01
 * time: 3.4663472175598145
     2    -1.131946e+01     9.913793e-01
 * time: 4.098193168640137
     3    -3.422928e+01     8.071643e-01
 * time: 5.055798053741455
     4    -4.742222e+01     6.709342e-01
 * time: 5.96961522102356
     5    -5.682644e+01     2.526858e-01
 * time: 6.927574157714844
     6    -5.965997e+01     2.395867e-01
 * time: 7.567251205444336
     7    -6.084517e+01     9.476527e-02
 * time: 8.205366134643555
     8    -6.139029e+01     4.560247e-02
 * time: 8.831188201904297
     9    -6.170943e+01     3.827996e-02
 * time: 9.455083131790161
    10    -6.192500e+01     2.700223e-02
 * time: 10.125914096832275
    11    -6.204075e+01     2.158195e-02
 * time: 10.784012079238892
    12    -6.211181e+01     1.774832e-02
 * time: 11.405257225036621
    13    -6.215154e+01     1.414801e-02
 * time: 12.036683082580566
    14    -6.217842e+01     9.031055e-03
 * time: 12.667927026748657
    15    -6.219312e+01     9.374259e-03
 * time: 13.337432146072388
    16    -6.220125e+01     7.260930e-03
 * time: 13.966185092926025
    17    -6.220679e+01     6.065130e-03
 * time: 14.614784002304077
    18    -6.221133e+01     4.860673e-03
 * time: 15.235850095748901
    19    -6.221484e+01     5.547721e-03
 * time: 15.860750198364258
    20    -6.221779e+01     6.075807e-03
 * time: 16.480419158935547
    21    -6.222098e+01     6.794110e-03
 * time: 17.095449209213257
    22    -6.222482e+01     7.753124e-03
 * time: 17.739870071411133
    23    -6.222983e+01     7.083213e-03
 * time: 18.404795169830322
    24    -6.223597e+01     7.483704e-03
 * time: 19.03500199317932
    25    -6.224298e+01     6.445161e-03
 * time: 19.662676095962524
    26    -6.224943e+01     5.478181e-03
 * time: 20.288406133651733
    27    -6.225386e+01     4.142099e-03
 * time: 20.92640709877014
    28    -6.225680e+01     3.328107e-03
 * time: 21.536826133728027
    29    -6.225856e+01     3.069448e-03
 * time: 22.15044403076172
    30    -6.225969e+01     2.049515e-03
 * time: 22.78855299949646
    31    -6.226045e+01     1.971888e-03
 * time: 23.426186084747314
    32    -6.226096e+01     1.423891e-03
 * time: 24.046499013900757
    33    -6.226128e+01     9.983403e-04
 * time: 24.702802181243896
    34    -6.226146e+01     6.306647e-04
 * time: 25.391038179397583
    35    -6.226156e+01     5.521364e-04
 * time: 26.038703203201294
    36    -6.226161e+01     3.488896e-04
 * time: 26.68652319908142
    37    -6.226163e+01     2.638166e-04
 * time: 27.37592911720276
    38    -6.226164e+01     2.022540e-04
 * time: 28.031264066696167
    39    -6.226165e+01     1.685627e-04
 * time: 28.688430070877075
    40    -6.226166e+01     1.521105e-04
 * time: 29.304901123046875
    41    -6.226166e+01     1.201817e-04
 * time: 29.969714164733887
    42    -6.226166e+01     1.018231e-04
 * time: 30.629937171936035
    43    -6.226166e+01     6.802097e-05
 * time: 31.27253818511963
    44    -6.226167e+01     5.794624e-05
 * time: 31.889150142669678
    45    -6.226167e+01     4.031288e-05
 * time: 32.5217661857605
    46    -6.226167e+01     3.057493e-05
 * time: 33.18324899673462
    47    -6.226167e+01     2.291599e-05
 * time: 33.831873178482056
    48    -6.226167e+01     1.981268e-05
 * time: 34.49102020263672
    49    -6.226167e+01     1.344139e-05
 * time: 35.15118718147278
    50    -6.226167e+01     1.021034e-05
 * time: 35.78208804130554
    51    -6.226167e+01     1.031079e-05
 * time: 36.43087100982666
    52    -6.226167e+01     7.248659e-06
 * time: 37.0709011554718
    53    -6.226167e+01     6.064941e-06
 * time: 37.69280815124512
    54    -6.226167e+01     5.772119e-06
 * time: 38.350426197052
    55    -6.226167e+01     3.954541e-06
 * time: 38.98163604736328
    56    -6.226167e+01     2.577226e-06
 * time: 39.61007809638977
    57    -6.226167e+01     2.256983e-06
 * time: 40.247496128082275
In [5]:
scfres.energies
Out[5]:
Energy breakdown:
    Kinetic             25.7671066
    AtomicLocal         -18.8557681
    AtomicNonlocal      14.8522652
    Ewald               -67.1831486
    PspCorrection       -2.3569765
    Hartree             4.8485370 
    Xc                  -19.3336820

    total               -62.261666461969