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.117217e+02     1.554660e+00
 * time: 0.33743715286254883
     1     1.037440e+01     8.445414e-01
 * time: 2.0049779415130615
     2    -1.121620e+01     1.050138e+00
 * time: 2.6005420684814453
     3    -3.365296e+01     7.568869e-01
 * time: 3.4959909915924072
     4    -4.687883e+01     5.976787e-01
 * time: 4.335353136062622
     5    -5.666685e+01     2.447570e-01
 * time: 5.179017066955566
     6    -5.968828e+01     1.751791e-01
 * time: 5.786386013031006
     7    -6.091866e+01     7.503765e-02
 * time: 6.357948064804077
     8    -6.140836e+01     4.214580e-02
 * time: 6.929265022277832
     9    -6.170223e+01     3.050503e-02
 * time: 7.494722127914429
    10    -6.186184e+01     2.905012e-02
 * time: 8.066959142684937
    11    -6.195899e+01     2.449689e-02
 * time: 8.634283065795898
    12    -6.203424e+01     1.852507e-02
 * time: 9.224688053131104
    13    -6.209407e+01     1.388328e-02
 * time: 9.836359024047852
    14    -6.213035e+01     1.130053e-02
 * time: 10.40229606628418
    15    -6.215933e+01     1.133585e-02
 * time: 10.9671790599823
    16    -6.217571e+01     1.045204e-02
 * time: 11.524045944213867
    17    -6.218826e+01     6.789764e-03
 * time: 12.096714973449707
    18    -6.219707e+01     5.088749e-03
 * time: 12.673727035522461
    19    -6.220342e+01     4.741353e-03
 * time: 13.232939958572388
    20    -6.220711e+01     3.966608e-03
 * time: 13.791857957839966
    21    -6.220980e+01     3.217921e-03
 * time: 14.341202020645142
    22    -6.221183e+01     3.713416e-03
 * time: 14.895869970321655
    23    -6.221337e+01     3.541477e-03
 * time: 15.484123945236206
    24    -6.221477e+01     3.923583e-03
 * time: 16.072870016098022
    25    -6.221642e+01     4.739538e-03
 * time: 16.629889965057373
    26    -6.221864e+01     4.948514e-03
 * time: 17.2029390335083
    27    -6.222205e+01     5.584813e-03
 * time: 17.772813081741333
    28    -6.222672e+01     6.290839e-03
 * time: 18.32461714744568
    29    -6.223297e+01     6.753165e-03
 * time: 18.867797136306763
    30    -6.224191e+01     6.664647e-03
 * time: 19.42405605316162
    31    -6.224791e+01     5.113193e-03
 * time: 20.027765035629272
    32    -6.225248e+01     4.318983e-03
 * time: 20.620769023895264
    33    -6.225589e+01     3.248387e-03
 * time: 21.202458143234253
    34    -6.225830e+01     2.695153e-03
 * time: 21.76774311065674
    35    -6.225985e+01     1.909121e-03
 * time: 22.357434034347534
    36    -6.226068e+01     1.449971e-03
 * time: 22.9448561668396
    37    -6.226108e+01     1.314802e-03
 * time: 23.522701025009155
    38    -6.226130e+01     1.033844e-03
 * time: 24.083203077316284
    39    -6.226143e+01     9.213379e-04
 * time: 24.65206503868103
    40    -6.226152e+01     6.745619e-04
 * time: 25.208940982818604
    41    -6.226157e+01     4.911401e-04
 * time: 25.765687942504883
    42    -6.226160e+01     3.851921e-04
 * time: 26.34597396850586
    43    -6.226163e+01     2.693366e-04
 * time: 26.944262981414795
    44    -6.226164e+01     3.039109e-04
 * time: 27.50420093536377
    45    -6.226165e+01     1.799834e-04
 * time: 28.06168293952942
    46    -6.226166e+01     1.485859e-04
 * time: 28.60861301422119
    47    -6.226166e+01     1.109399e-04
 * time: 29.174752950668335
    48    -6.226166e+01     8.379470e-05
 * time: 29.727829933166504
    49    -6.226166e+01     6.141098e-05
 * time: 30.343456983566284
    50    -6.226167e+01     4.013468e-05
 * time: 30.941395044326782
    51    -6.226167e+01     3.271851e-05
 * time: 31.5614230632782
    52    -6.226167e+01     2.981469e-05
 * time: 32.13159894943237
    53    -6.226167e+01     2.416664e-05
 * time: 32.726853132247925
    54    -6.226167e+01     1.946377e-05
 * time: 33.33831214904785
    55    -6.226167e+01     1.495429e-05
 * time: 33.89467906951904
    56    -6.226167e+01     1.272462e-05
 * time: 34.49176907539368
    57    -6.226167e+01     9.765012e-06
 * time: 35.09361815452576
    58    -6.226167e+01     7.903498e-06
 * time: 35.6646511554718
    59    -6.226167e+01     5.222971e-06
 * time: 36.243205070495605
    60    -6.226167e+01     4.097512e-06
 * time: 36.815184116363525
    61    -6.226167e+01     3.169586e-06
 * time: 37.388116121292114
    62    -6.226167e+01     2.049678e-06
 * time: 37.96784806251526
In [5]:
scfres.energies
Out[5]:
Energy breakdown:
    Kinetic             25.7671066
    AtomicLocal         -18.8557679
    AtomicNonlocal      14.8522650
    Ewald               -67.1831486
    PspCorrection       -2.3569765
    Hartree             4.8485369 
    Xc                  -19.3336819

    total               -62.261666461562