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.119494e+02     1.938008e+00
 * time: 0.04132986068725586
     1     1.032094e+01     9.458580e-01
 * time: 0.11649394035339355
     2    -1.166418e+01     1.087708e+00
 * time: 0.1941378116607666
     3    -3.392779e+01     8.276433e-01
 * time: 0.3212108612060547
     4    -4.721030e+01     6.820882e-01
 * time: 0.4166989326477051
     5    -5.676974e+01     2.756248e-01
 * time: 0.5125617980957031
     6    -5.954435e+01     2.956990e-01
 * time: 0.5903639793395996
     7    -6.074063e+01     1.366683e-01
 * time: 0.6655778884887695
     8    -6.131347e+01     7.269021e-02
 * time: 0.7416548728942871
     9    -6.159338e+01     3.908759e-02
 * time: 0.8209569454193115
    10    -6.181846e+01     4.260890e-02
 * time: 0.9037258625030518
    11    -6.195798e+01     2.538983e-02
 * time: 0.9975149631500244
    12    -6.205893e+01     2.142104e-02
 * time: 1.0770809650421143
    13    -6.209768e+01     1.708672e-02
 * time: 1.1509878635406494
    14    -6.214242e+01     1.294376e-02
 * time: 1.2262787818908691
    15    -6.216369e+01     1.433722e-02
 * time: 1.301069974899292
    16    -6.218313e+01     8.331633e-03
 * time: 1.3771848678588867
    17    -6.219571e+01     7.092412e-03
 * time: 1.45452880859375
    18    -6.220556e+01     6.656574e-03
 * time: 1.5291709899902344
    19    -6.221359e+01     7.136311e-03
 * time: 1.6025288105010986
    20    -6.222068e+01     6.443396e-03
 * time: 1.6963589191436768
    21    -6.222725e+01     5.637252e-03
 * time: 1.7710988521575928
    22    -6.223356e+01     5.395703e-03
 * time: 1.8476378917694092
    23    -6.223951e+01     5.465407e-03
 * time: 1.9239108562469482
    24    -6.224487e+01     4.977002e-03
 * time: 2.000175952911377
    25    -6.224959e+01     4.350536e-03
 * time: 2.079457998275757
    26    -6.225343e+01     3.555012e-03
 * time: 2.1549479961395264
    27    -6.225615e+01     2.827051e-03
 * time: 2.2292098999023438
    28    -6.225813e+01     2.388642e-03
 * time: 2.3059558868408203
    29    -6.225946e+01     2.316043e-03
 * time: 2.383293867111206
    30    -6.226035e+01     2.249893e-03
 * time: 2.476332902908325
    31    -6.226091e+01     1.355793e-03
 * time: 2.5489490032196045
    32    -6.226126e+01     9.973310e-04
 * time: 2.624591827392578
    33    -6.226146e+01     7.261647e-04
 * time: 2.70143985748291
    34    -6.226156e+01     5.687582e-04
 * time: 2.780200958251953
    35    -6.226162e+01     4.343362e-04
 * time: 2.856545925140381
    36    -6.226164e+01     2.670432e-04
 * time: 2.9305567741394043
    37    -6.226165e+01     1.776371e-04
 * time: 3.008579969406128
    38    -6.226165e+01     1.522649e-04
 * time: 3.0828700065612793
    39    -6.226166e+01     1.291167e-04
 * time: 3.1720399856567383
    40    -6.226166e+01     1.090219e-04
 * time: 3.2479019165039062
    41    -6.226166e+01     8.890872e-05
 * time: 3.3226637840270996
    42    -6.226166e+01     5.855230e-05
 * time: 3.4016518592834473
    43    -6.226167e+01     4.242326e-05
 * time: 3.480693817138672
    44    -6.226167e+01     3.655805e-05
 * time: 3.569145917892456
    45    -6.226167e+01     3.026227e-05
 * time: 3.6421279907226562
    46    -6.226167e+01     1.940240e-05
 * time: 3.718561887741089
    47    -6.226167e+01     1.573941e-05
 * time: 3.798602819442749
    48    -6.226167e+01     1.278380e-05
 * time: 3.8886218070983887
    49    -6.226167e+01     8.923656e-06
 * time: 3.963193893432617
    50    -6.226167e+01     5.973546e-06
 * time: 4.039694786071777
    51    -6.226167e+01     5.235209e-06
 * time: 4.116139888763428
    52    -6.226167e+01     5.044205e-06
 * time: 4.1915459632873535
    53    -6.226167e+01     3.290432e-06
 * time: 4.264716863632202
    54    -6.226167e+01     2.904048e-06
 * time: 4.340412855148315
scfres.energies
Energy breakdown:
    Kinetic             25.7671078
    AtomicLocal         -18.8557714
    AtomicNonlocal      14.8522663
    Ewald               -67.1831486
    PspCorrection       -2.3569765
    Hartree             4.8485387 
    Xc                  -19.3336826

    total               -62.261666460371