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.
Notice that PlaneWaveBasis
defaults to just using the Γ
-point
if no k
-point options are provided.
model = model_LDA(lattice, atoms)
basis = PlaneWaveBasis(model, 5)
# 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.122868e+02 1.591442e+00 * time: 0.09169983863830566 1 1.034146e+01 8.903759e-01 * time: 0.9666829109191895 2 -1.160161e+01 1.041350e+00 * time: 1.1044797897338867 3 -3.379781e+01 7.880703e-01 * time: 1.2724599838256836 4 -4.714581e+01 6.419166e-01 * time: 1.433424949645996 5 -5.668637e+01 2.768249e-01 * time: 1.5870769023895264 6 -5.942955e+01 3.386544e-01 * time: 1.7011888027191162 7 -6.058871e+01 1.656004e-01 * time: 1.8242418766021729 8 -6.111174e+01 1.023647e-01 * time: 1.937182903289795 9 -6.148871e+01 4.077687e-02 * time: 2.0513648986816406 10 -6.169761e+01 4.554744e-02 * time: 2.1729519367218018 11 -6.188435e+01 2.354294e-02 * time: 2.288400888442993 12 -6.198753e+01 1.895439e-02 * time: 2.4079599380493164 13 -6.204582e+01 1.455635e-02 * time: 2.521263837814331 14 -6.209189e+01 1.400400e-02 * time: 2.641704797744751 15 -6.212415e+01 1.279348e-02 * time: 2.7572858333587646 16 -6.214867e+01 1.087641e-02 * time: 2.8802378177642822 17 -6.216559e+01 9.768889e-03 * time: 2.9957900047302246 18 -6.217919e+01 9.324364e-03 * time: 3.1191158294677734 19 -6.218921e+01 8.955926e-03 * time: 3.233973979949951 20 -6.219689e+01 7.396120e-03 * time: 3.3544678688049316 21 -6.220303e+01 5.983746e-03 * time: 3.4685349464416504 22 -6.220874e+01 5.034526e-03 * time: 3.590500831604004 23 -6.221433e+01 5.181561e-03 * time: 3.7051568031311035 24 -6.221965e+01 6.202330e-03 * time: 3.8283169269561768 25 -6.222473e+01 5.906698e-03 * time: 3.942812919616699 26 -6.223010e+01 5.517008e-03 * time: 4.064507007598877 27 -6.223595e+01 5.120018e-03 * time: 4.17920184135437 28 -6.224182e+01 4.634973e-03 * time: 4.298946857452393 29 -6.224728e+01 5.019787e-03 * time: 4.4124109745025635 30 -6.225173e+01 4.696140e-03 * time: 4.535491943359375 31 -6.225501e+01 4.494168e-03 * time: 4.6485888957977295 32 -6.225754e+01 3.099913e-03 * time: 4.788537979125977 33 -6.225937e+01 1.970348e-03 * time: 4.901090860366821 34 -6.226039e+01 1.839028e-03 * time: 5.014235973358154 35 -6.226101e+01 1.165937e-03 * time: 5.134499788284302 36 -6.226132e+01 1.063717e-03 * time: 5.247635841369629 37 -6.226147e+01 6.759418e-04 * time: 5.368165016174316 38 -6.226155e+01 4.637716e-04 * time: 5.482270002365112 39 -6.226159e+01 3.835974e-04 * time: 5.604346990585327 40 -6.226161e+01 3.497294e-04 * time: 5.719130992889404 41 -6.226163e+01 2.737936e-04 * time: 5.841850996017456 42 -6.226164e+01 2.223302e-04 * time: 5.956017017364502 43 -6.226165e+01 1.777827e-04 * time: 6.07542085647583 44 -6.226166e+01 1.755788e-04 * time: 6.19088888168335 45 -6.226166e+01 1.164287e-04 * time: 6.310043811798096 46 -6.226166e+01 9.458051e-05 * time: 6.422841787338257 47 -6.226167e+01 6.018696e-05 * time: 6.543136835098267 48 -6.226167e+01 4.532846e-05 * time: 6.654995918273926 49 -6.226167e+01 3.242965e-05 * time: 6.77505898475647 50 -6.226167e+01 2.010567e-05 * time: 6.887465953826904 51 -6.226167e+01 1.847513e-05 * time: 7.007351875305176 52 -6.226167e+01 1.364269e-05 * time: 7.120943784713745 53 -6.226167e+01 1.186426e-05 * time: 7.240108966827393 54 -6.226167e+01 9.617010e-06 * time: 7.352358818054199 55 -6.226167e+01 9.420541e-06 * time: 7.473395824432373 56 -6.226167e+01 5.707880e-06 * time: 7.587816953659058 57 -6.226167e+01 4.969161e-06 * time: 7.707031011581421 58 -6.226167e+01 3.175725e-06 * time: 7.818588018417358
scfres.energies
Energy breakdown: Kinetic 25.7671076 AtomicLocal -18.8557704 AtomicNonlocal 14.8522656 Ewald -67.1831486 PspCorrection -2.3569765 Hartree 4.8485384 Xc -19.3336825 total -62.261666459437