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.113146e+02     1.482029e+00
 * time: 0.6992490291595459
     1     1.071696e+01     9.491443e-01
 * time: 2.0883591175079346
     2    -1.138461e+01     1.105409e+00
 * time: 2.7834880352020264
     3    -3.402291e+01     7.557699e-01
 * time: 3.7636759281158447
     4    -4.737597e+01     5.889780e-01
 * time: 4.72720193862915
     5    -5.702895e+01     2.395512e-01
 * time: 5.724928140640259
     6    -5.997158e+01     1.423997e-01
 * time: 6.382604122161865
     7    -6.101207e+01     4.509268e-02
 * time: 7.047425031661987
     8    -6.138645e+01     7.900208e-02
 * time: 7.70560097694397
     9    -6.164324e+01     3.691503e-02
 * time: 8.371928930282593
    10    -6.184017e+01     2.181680e-02
 * time: 9.027969121932983
    11    -6.199117e+01     1.860231e-02
 * time: 9.675604104995728
    12    -6.205072e+01     1.413046e-02
 * time: 10.32085394859314
    13    -6.211534e+01     1.254323e-02
 * time: 10.997547149658203
    14    -6.214511e+01     1.100218e-02
 * time: 11.646201133728027
    15    -6.217208e+01     1.091474e-02
 * time: 12.295642137527466
    16    -6.218551e+01     9.631001e-03
 * time: 12.983865022659302
    17    -6.219571e+01     5.656886e-03
 * time: 13.659446954727173
    18    -6.220390e+01     5.718823e-03
 * time: 14.337074041366577
    19    -6.221136e+01     6.371978e-03
 * time: 15.02285099029541
    20    -6.221893e+01     6.282631e-03
 * time: 15.67647910118103
    21    -6.222698e+01     7.315006e-03
 * time: 16.324023962020874
    22    -6.223520e+01     5.775908e-03
 * time: 16.97357201576233
    23    -6.224282e+01     5.021471e-03
 * time: 17.62908697128296
    24    -6.224905e+01     3.926381e-03
 * time: 18.28337597846985
    25    -6.225315e+01     3.139243e-03
 * time: 18.93023109436035
    26    -6.225580e+01     2.709913e-03
 * time: 19.57584500312805
    27    -6.225757e+01     2.588291e-03
 * time: 20.22026515007019
    28    -6.225883e+01     2.323200e-03
 * time: 20.874036073684692
    29    -6.225978e+01     1.891179e-03
 * time: 21.515499114990234
    30    -6.226048e+01     1.552824e-03
 * time: 22.15497612953186
    31    -6.226097e+01     1.223349e-03
 * time: 22.803460121154785
    32    -6.226129e+01     9.028444e-04
 * time: 23.46927809715271
    33    -6.226148e+01     5.939061e-04
 * time: 24.12806510925293
    34    -6.226158e+01     4.062811e-04
 * time: 24.76841711997986
    35    -6.226162e+01     3.446942e-04
 * time: 25.433179140090942
    36    -6.226164e+01     2.826078e-04
 * time: 26.087186098098755
    37    -6.226165e+01     1.826809e-04
 * time: 26.742758989334106
    38    -6.226166e+01     1.157633e-04
 * time: 27.40966510772705
    39    -6.226166e+01     1.074701e-04
 * time: 28.08142399787903
    40    -6.226166e+01     8.527162e-05
 * time: 28.737993955612183
    41    -6.226166e+01     7.168839e-05
 * time: 29.389981985092163
    42    -6.226166e+01     5.570573e-05
 * time: 30.032937049865723
    43    -6.226167e+01     4.743906e-05
 * time: 30.715852975845337
    44    -6.226167e+01     3.627797e-05
 * time: 31.37617802619934
    45    -6.226167e+01     2.334269e-05
 * time: 32.021677017211914
    46    -6.226167e+01     1.744620e-05
 * time: 32.67348909378052
    47    -6.226167e+01     1.050806e-05
 * time: 33.37345314025879
    48    -6.226167e+01     6.450375e-06
 * time: 34.009320974349976
    49    -6.226167e+01     4.948902e-06
 * time: 34.661309003829956
    50    -6.226167e+01     4.413429e-06
 * time: 35.31855010986328
In [5]:
scfres.energies
Out[5]:
Energy breakdown:
    Kinetic             25.7671053
    AtomicLocal         -18.8557599
    AtomicNonlocal      14.8522599
    Ewald               -67.1831486
    PspCorrection       -2.3569765
    Hartree             4.8485343 
    Xc                  -19.3336809

    total               -62.261666454116