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.111196e+02     1.484812e+00
 * time: 0.07368183135986328
     1     1.136166e+01     9.065097e-01
 * time: 1.4496738910675049
     2    -1.137165e+01     1.025719e+00
 * time: 1.5349669456481934
     3    -3.387718e+01     7.177525e-01
 * time: 1.6498589515686035
     4    -4.739144e+01     5.533646e-01
 * time: 1.7811799049377441
     5    -5.689811e+01     2.142668e-01
 * time: 1.8838248252868652
     6    -5.982392e+01     1.276920e-01
 * time: 1.9609968662261963
     7    -6.091988e+01     6.044469e-02
 * time: 2.0345218181610107
     8    -6.130942e+01     7.088004e-02
 * time: 2.1386940479278564
     9    -6.159165e+01     4.432823e-02
 * time: 2.215906858444214
    10    -6.178953e+01     3.363145e-02
 * time: 2.2921929359436035
    11    -6.195361e+01     2.054222e-02
 * time: 2.3701369762420654
    12    -6.202657e+01     2.093181e-02
 * time: 2.4503068923950195
    13    -6.210541e+01     1.703304e-02
 * time: 2.5299389362335205
    14    -6.214450e+01     1.435507e-02
 * time: 2.607374906539917
    15    -6.218015e+01     1.251250e-02
 * time: 2.6828818321228027
    16    -6.219914e+01     9.087920e-03
 * time: 2.75805401802063
    17    -6.221289e+01     7.784274e-03
 * time: 2.8424508571624756
    18    -6.222249e+01     6.244302e-03
 * time: 2.9251890182495117
    19    -6.222974e+01     6.200834e-03
 * time: 3.005741834640503
    20    -6.223600e+01     5.844353e-03
 * time: 3.0851519107818604
    21    -6.224189e+01     5.530477e-03
 * time: 3.168797016143799
    22    -6.224768e+01     5.648878e-03
 * time: 3.25154185295105
    23    -6.225285e+01     4.847949e-03
 * time: 3.3295350074768066
    24    -6.225665e+01     3.834625e-03
 * time: 3.4085748195648193
    25    -6.225890e+01     2.977767e-03
 * time: 3.5058019161224365
    26    -6.226015e+01     2.105438e-03
 * time: 3.578939914703369
    27    -6.226077e+01     1.345757e-03
 * time: 3.6580729484558105
    28    -6.226110e+01     1.020734e-03
 * time: 3.7417349815368652
    29    -6.226129e+01     9.759721e-04
 * time: 3.8296430110931396
    30    -6.226141e+01     8.171239e-04
 * time: 3.9238739013671875
    31    -6.226149e+01     7.647032e-04
 * time: 4.010051965713501
    32    -6.226155e+01     6.069915e-04
 * time: 4.085798978805542
    33    -6.226160e+01     3.981924e-04
 * time: 4.161531925201416
    34    -6.226163e+01     3.449342e-04
 * time: 4.245488882064819
    35    -6.226165e+01     2.292712e-04
 * time: 4.321305990219116
    36    -6.226166e+01     2.495890e-04
 * time: 4.401867866516113
    37    -6.226166e+01     1.117296e-04
 * time: 4.479991912841797
    38    -6.226166e+01     8.732202e-05
 * time: 4.564880847930908
    39    -6.226166e+01     6.555517e-05
 * time: 4.655396938323975
    40    -6.226167e+01     6.608910e-05
 * time: 4.731441020965576
    41    -6.226167e+01     4.922998e-05
 * time: 4.810605049133301
    42    -6.226167e+01     4.180363e-05
 * time: 4.898624897003174
    43    -6.226167e+01     3.304705e-05
 * time: 4.976557970046997
    44    -6.226167e+01     2.649407e-05
 * time: 5.052386045455933
    45    -6.226167e+01     2.157395e-05
 * time: 5.132324934005737
    46    -6.226167e+01     1.642571e-05
 * time: 5.216400861740112
    47    -6.226167e+01     1.051455e-05
 * time: 5.304497957229614
    48    -6.226167e+01     6.376436e-06
 * time: 5.3940348625183105
    49    -6.226167e+01     5.436638e-06
 * time: 5.469815015792847
    50    -6.226167e+01     4.178595e-06
 * time: 5.546497821807861
In [5]:
scfres.energies
Out[5]:
Energy breakdown:
    Kinetic             25.7671065
    AtomicLocal         -18.8557655
    AtomicNonlocal      14.8522630
    Ewald               -67.1831486
    PspCorrection       -2.3569765
    Hartree             4.8485365 
    Xc                  -19.3336818

    total               -62.261666459150