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.113626e+02     1.688492e+00
 * time: 0.06653594970703125
     1     1.061494e+01     8.383523e-01
 * time: 0.20032501220703125
     2    -1.231791e+01     9.397075e-01
 * time: 0.31930994987487793
     3    -3.446849e+01     7.867414e-01
 * time: 0.4946107864379883
     4    -4.797597e+01     5.600861e-01
 * time: 0.6413478851318359
     5    -5.707639e+01     2.026357e-01
 * time: 0.8089280128479004
     6    -5.990771e+01     1.070011e-01
 * time: 0.9277830123901367
     7    -6.091463e+01     5.670240e-02
 * time: 1.066187858581543
     8    -6.128227e+01     7.526146e-02
 * time: 1.1794898509979248
     9    -6.159498e+01     3.066035e-02
 * time: 1.309664011001587
    10    -6.180681e+01     2.928217e-02
 * time: 1.4212968349456787
    11    -6.196479e+01     2.115795e-02
 * time: 1.5343959331512451
    12    -6.203068e+01     1.881786e-02
 * time: 1.6603269577026367
    13    -6.209738e+01     1.656227e-02
 * time: 1.784369945526123
    14    -6.213312e+01     1.400108e-02
 * time: 1.9138689041137695
    15    -6.216676e+01     1.034780e-02
 * time: 2.0288329124450684
    16    -6.218433e+01     8.216062e-03
 * time: 2.1430490016937256
    17    -6.219515e+01     7.082853e-03
 * time: 2.2788867950439453
    18    -6.220190e+01     4.754843e-03
 * time: 2.395519971847534
    19    -6.220574e+01     4.608312e-03
 * time: 2.523131847381592
    20    -6.220812e+01     3.831272e-03
 * time: 2.642453908920288
    21    -6.220991e+01     4.536398e-03
 * time: 2.768810987472534
    22    -6.221159e+01     4.904682e-03
 * time: 2.886356830596924
    23    -6.221329e+01     5.741350e-03
 * time: 2.997919797897339
    24    -6.221489e+01     6.324111e-03
 * time: 3.1242458820343018
    25    -6.221678e+01     7.520310e-03
 * time: 3.239766836166382
    26    -6.221952e+01     8.913873e-03
 * time: 3.3685078620910645
    27    -6.222368e+01     8.954819e-03
 * time: 3.4784889221191406
    28    -6.222946e+01     1.051615e-02
 * time: 3.589751958847046
    29    -6.223790e+01     9.505445e-03
 * time: 3.7188618183135986
    30    -6.224636e+01     7.445640e-03
 * time: 3.8289008140563965
    31    -6.225162e+01     5.809530e-03
 * time: 3.950305938720703
    32    -6.225549e+01     3.861959e-03
 * time: 4.060954809188843
    33    -6.225773e+01     3.272649e-03
 * time: 4.184387922286987
    34    -6.225929e+01     2.948304e-03
 * time: 4.294290781021118
    35    -6.226020e+01     2.856186e-03
 * time: 4.402800798416138
    36    -6.226082e+01     1.391821e-03
 * time: 4.524720907211304
    37    -6.226118e+01     1.137291e-03
 * time: 4.635044813156128
    38    -6.226137e+01     9.243818e-04
 * time: 4.755850791931152
    39    -6.226148e+01     9.200714e-04
 * time: 4.8672709465026855
    40    -6.226155e+01     5.299681e-04
 * time: 4.97767186164856
    41    -6.226159e+01     4.709818e-04
 * time: 5.10063099861145
    42    -6.226161e+01     3.983221e-04
 * time: 5.21090292930603
    43    -6.226163e+01     3.727919e-04
 * time: 5.336044788360596
    44    -6.226165e+01     3.056308e-04
 * time: 5.446676969528198
    45    -6.226165e+01     2.092604e-04
 * time: 5.5632898807525635
    46    -6.226166e+01     1.301549e-04
 * time: 5.683104991912842
    47    -6.226166e+01     9.127704e-05
 * time: 5.793879985809326
    48    -6.226166e+01     8.498485e-05
 * time: 5.919159889221191
    49    -6.226166e+01     6.589377e-05
 * time: 6.028597831726074
    50    -6.226167e+01     6.242508e-05
 * time: 6.148559808731079
    51    -6.226167e+01     5.072878e-05
 * time: 6.257500886917114
    52    -6.226167e+01     3.918140e-05
 * time: 6.367019891738892
    53    -6.226167e+01     3.062024e-05
 * time: 6.489784002304077
    54    -6.226167e+01     2.265124e-05
 * time: 6.599891901016235
    55    -6.226167e+01     1.490920e-05
 * time: 6.721367835998535
    56    -6.226167e+01     1.117404e-05
 * time: 6.8319549560546875
    57    -6.226167e+01     8.071362e-06
 * time: 6.953524827957153
    58    -6.226167e+01     7.848610e-06
 * time: 7.062186002731323
    59    -6.226167e+01     5.983594e-06
 * time: 7.1725850105285645
    60    -6.226167e+01     4.562187e-06
 * time: 7.292176008224487
    61    -6.226167e+01     3.029653e-06
 * time: 7.402575969696045
    62    -6.226167e+01     2.559153e-06
 * time: 7.522832870483398
scfres.energies
Energy breakdown:
    Kinetic             25.7671065
    AtomicLocal         -18.8557681
    AtomicNonlocal      14.8522654
    Ewald               -67.1831486
    PspCorrection       -2.3569765
    Hartree             4.8485366 
    Xc                  -19.3336818

    total               -62.261666461441