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. To run this example Julia's PyCall package needs to be able to find an installation of pymatgen.

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 k-point and a small Ecut of 5 Hartree.

model = model_LDA(lattice, atoms)
basis = PlaneWaveBasis(model; Ecut=5, kgrid=(1, 1, 1))
PlaneWaveBasis discretization:
    Ecut                 : 5.0 Ha
    fft_size             : (32, 32, 32), 32768 total points
    kgrid type           : Monkhorst-Pack
    kgrid                : [1, 1, 1]
    num. irred. kpoints  : 1

    Discretized Model(lda_xc_teter93, 3D):
        lattice (in Bohr)    : [0         , 10.2631   , 10.2631   ]
                               [10.2631   , 0         , 10.2631   ]
                               [10.2631   , 10.2631   , 0         ]
        unit cell volume     : 2162.1 Bohr³
    
        atoms                : Si₁₆
        atom potentials      : ElementPsp(Si, psp="hgh/lda/si-q4")
    
        num. electrons       : 64
        spin polarization    : none
        temperature          : 0 Ha
    
        terms                : Kinetic()
                               AtomicLocal()
                               AtomicNonlocal()
                               Ewald()
                               PspCorrection()
                               Hartree()
                               Xc(:lda_xc_teter93)

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.113100e+02     1.467254e+00
 * time: 0.03866410255432129
     1     1.055926e+01     9.735594e-01
 * time: 0.1088109016418457
     2    -1.193605e+01     1.009299e+00
 * time: 0.1800529956817627
     3    -3.389001e+01     7.253574e-01
 * time: 0.2888679504394531
     4    -4.722013e+01     5.902442e-01
 * time: 0.39993786811828613
     5    -5.690684e+01     1.982284e-01
 * time: 0.498837947845459
     6    -5.970347e+01     1.399589e-01
 * time: 0.6183640956878662
     7    -6.084889e+01     6.610646e-02
 * time: 0.6889278888702393
     8    -6.133321e+01     3.286300e-02
 * time: 0.7608230113983154
     9    -6.163396e+01     2.841423e-02
 * time: 0.8358259201049805
    10    -6.179795e+01     2.534727e-02
 * time: 0.9108059406280518
    11    -6.196011e+01     2.137768e-02
 * time: 0.987968921661377
    12    -6.205783e+01     1.773667e-02
 * time: 1.06278395652771
    13    -6.211650e+01     1.385073e-02
 * time: 1.1370880603790283
    14    -6.216388e+01     1.369567e-02
 * time: 1.2126779556274414
    15    -6.219156e+01     1.053016e-02
 * time: 1.2896840572357178
    16    -6.221038e+01     7.861450e-03
 * time: 1.404088020324707
    17    -6.222159e+01     6.692037e-03
 * time: 1.4772489070892334
    18    -6.223000e+01     5.983157e-03
 * time: 1.5538179874420166
    19    -6.223646e+01     5.038477e-03
 * time: 1.6260409355163574
    20    -6.224209e+01     6.114816e-03
 * time: 1.6988730430603027
    21    -6.224744e+01     6.218869e-03
 * time: 1.7709128856658936
    22    -6.225226e+01     5.403603e-03
 * time: 1.8411588668823242
    23    -6.225616e+01     3.876282e-03
 * time: 1.9135229587554932
    24    -6.225869e+01     2.741563e-03
 * time: 1.9859790802001953
    25    -6.226001e+01     1.980918e-03
 * time: 2.0649359226226807
    26    -6.226072e+01     1.484300e-03
 * time: 2.1796488761901855
    27    -6.226108e+01     1.012242e-03
 * time: 2.252518892288208
    28    -6.226127e+01     8.870845e-04
 * time: 2.327410936355591
    29    -6.226139e+01     7.022384e-04
 * time: 2.4011430740356445
    30    -6.226148e+01     5.812528e-04
 * time: 2.4760708808898926
    31    -6.226154e+01     4.808654e-04
 * time: 2.554672956466675
    32    -6.226159e+01     4.315478e-04
 * time: 2.6298890113830566
    33    -6.226162e+01     3.491963e-04
 * time: 2.707448959350586
    34    -6.226164e+01     2.486626e-04
 * time: 2.7839109897613525
    35    -6.226165e+01     1.675476e-04
 * time: 2.8613970279693604
    36    -6.226166e+01     1.552213e-04
 * time: 2.9620280265808105
    37    -6.226166e+01     8.361768e-05
 * time: 3.038425922393799
    38    -6.226166e+01     6.570053e-05
 * time: 3.113297939300537
    39    -6.226167e+01     4.560129e-05
 * time: 3.1869280338287354
    40    -6.226167e+01     3.757941e-05
 * time: 3.259445905685425
    41    -6.226167e+01     2.775317e-05
 * time: 3.3367719650268555
    42    -6.226167e+01     2.456661e-05
 * time: 3.4126338958740234
    43    -6.226167e+01     1.803064e-05
 * time: 3.484752893447876
    44    -6.226167e+01     1.632492e-05
 * time: 3.566586971282959
    45    -6.226167e+01     1.440094e-05
 * time: 3.6583669185638428
    46    -6.226167e+01     1.234882e-05
 * time: 3.7604129314422607
    47    -6.226167e+01     8.574435e-06
 * time: 3.83809494972229
    48    -6.226167e+01     5.591537e-06
 * time: 3.912498950958252
    49    -6.226167e+01     3.478756e-06
 * time: 3.985434055328369
    50    -6.226167e+01     2.406260e-06
 * time: 4.0604870319366455
scfres.energies
Energy breakdown (in Ha):
    Kinetic             25.7671067
    AtomicLocal         -18.8557661
    AtomicNonlocal      14.8522633
    Ewald               -67.1831486
    PspCorrection       -2.3569765
    Hartree             4.8485366 
    Xc                  -19.3336818

    total               -62.261666461183