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.125911e+02     1.525967e+00
 * time: 0.12418484687805176
     1     1.049991e+01     8.494469e-01
 * time: 1.3621690273284912
     2    -1.159584e+01     9.483355e-01
 * time: 1.4972529411315918
     3    -3.425352e+01     7.672246e-01
 * time: 1.6563358306884766
     4    -4.775584e+01     5.856345e-01
 * time: 1.8102929592132568
     5    -5.710598e+01     1.818976e-01
 * time: 1.9553618431091309
     6    -5.994199e+01     1.047006e-01
 * time: 2.063232898712158
     7    -6.092462e+01     5.137782e-02
 * time: 2.1780569553375244
     8    -6.128413e+01     6.349415e-02
 * time: 2.284824848175049
     9    -6.160034e+01     3.152810e-02
 * time: 2.3999478816986084
    10    -6.181510e+01     3.105613e-02
 * time: 2.509462833404541
    11    -6.198184e+01     2.546497e-02
 * time: 2.625082015991211
    12    -6.205229e+01     1.856098e-02
 * time: 2.733719825744629
    13    -6.211792e+01     1.606201e-02
 * time: 2.8498919010162354
    14    -6.214760e+01     1.275702e-02
 * time: 2.958559989929199
    15    -6.217195e+01     9.134015e-03
 * time: 3.073585033416748
    16    -6.218532e+01     7.292027e-03
 * time: 3.1806910037994385
    17    -6.219444e+01     5.764162e-03
 * time: 3.296627998352051
    18    -6.220192e+01     5.681678e-03
 * time: 3.403770923614502
    19    -6.220775e+01     5.668839e-03
 * time: 3.5197649002075195
    20    -6.221309e+01     5.309899e-03
 * time: 3.6282379627227783
    21    -6.221820e+01     5.776277e-03
 * time: 3.745347023010254
    22    -6.222302e+01     5.410443e-03
 * time: 3.8540198802948
    23    -6.222770e+01     4.896717e-03
 * time: 3.9701650142669678
    24    -6.223244e+01     5.392468e-03
 * time: 4.077096939086914
    25    -6.223738e+01     6.031050e-03
 * time: 4.190784931182861
    26    -6.224245e+01     5.399637e-03
 * time: 4.296944856643677
    27    -6.224776e+01     4.623977e-03
 * time: 4.411518812179565
    28    -6.225258e+01     4.337564e-03
 * time: 4.5186848640441895
    29    -6.225631e+01     3.732390e-03
 * time: 4.632485866546631
    30    -6.225871e+01     3.222261e-03
 * time: 4.739543914794922
    31    -6.226010e+01     1.855397e-03
 * time: 4.854583024978638
    32    -6.226085e+01     1.432820e-03
 * time: 4.962090015411377
    33    -6.226122e+01     8.833632e-04
 * time: 5.077169895172119
    34    -6.226141e+01     7.075809e-04
 * time: 5.183765888214111
    35    -6.226152e+01     5.882029e-04
 * time: 5.296957015991211
    36    -6.226157e+01     5.312981e-04
 * time: 5.403264999389648
    37    -6.226160e+01     3.702924e-04
 * time: 5.516979932785034
    38    -6.226162e+01     3.316695e-04
 * time: 5.6229188442230225
    39    -6.226164e+01     2.331762e-04
 * time: 5.736721992492676
    40    -6.226165e+01     1.718310e-04
 * time: 5.84497594833374
    41    -6.226165e+01     1.397688e-04
 * time: 5.959794998168945
    42    -6.226166e+01     1.073398e-04
 * time: 6.0674638748168945
    43    -6.226166e+01     8.604418e-05
 * time: 6.18156886100769
    44    -6.226167e+01     7.017600e-05
 * time: 6.291604042053223
    45    -6.226167e+01     4.531269e-05
 * time: 6.411808967590332
    46    -6.226167e+01     3.241455e-05
 * time: 6.5217509269714355
    47    -6.226167e+01     2.671917e-05
 * time: 6.638278007507324
    48    -6.226167e+01     2.031523e-05
 * time: 6.749023914337158
    49    -6.226167e+01     1.593705e-05
 * time: 6.869117021560669
    50    -6.226167e+01     1.319095e-05
 * time: 6.979424953460693
    51    -6.226167e+01     1.208381e-05
 * time: 7.097939968109131
    52    -6.226167e+01     8.001873e-06
 * time: 7.208675861358643
    53    -6.226167e+01     7.325072e-06
 * time: 7.327240943908691
    54    -6.226167e+01     4.489385e-06
 * time: 7.437652826309204
    55    -6.226167e+01     3.397383e-06
 * time: 7.557163953781128
    56    -6.226167e+01     1.898473e-06
 * time: 7.667959928512573
    57    -6.226167e+01     1.444281e-06
 * time: 7.787178993225098
In [5]:
scfres.energies
Out[5]:
Energy breakdown:
    Kinetic             25.7671067
    AtomicLocal         -18.8557659
    AtomicNonlocal      14.8522630
    Ewald               -67.1831486
    PspCorrection       -2.3569765
    Hartree             4.8485369 
    Xc                  -19.3336819

    total               -62.261666462732