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.117808e+02 1.591249e+00 * time: 0.7865450382232666 1 1.035355e+01 8.078999e-01 * time: 3.126711130142212 2 -1.171575e+01 9.795259e-01 * time: 3.775221109390259 3 -3.390619e+01 7.183295e-01 * time: 4.741167068481445 4 -4.722593e+01 5.366174e-01 * time: 5.678085088729858 5 -5.681434e+01 2.068873e-01 * time: 6.659291982650757 6 -5.963103e+01 2.067385e-01 * time: 7.287919998168945 7 -6.081118e+01 1.143088e-01 * time: 7.953727960586548 8 -6.136379e+01 3.800089e-02 * time: 8.594083070755005 9 -6.164838e+01 3.106858e-02 * time: 9.21233606338501 10 -6.183710e+01 2.835819e-02 * time: 9.87421202659607 11 -6.198324e+01 1.982930e-02 * time: 10.513626098632812 12 -6.206414e+01 1.770723e-02 * time: 11.146723985671997 13 -6.210657e+01 1.326357e-02 * time: 11.759362936019897 14 -6.214022e+01 1.526538e-02 * time: 12.390202045440674 15 -6.215959e+01 1.409654e-02 * time: 13.023843050003052 16 -6.217459e+01 1.033879e-02 * time: 13.641917943954468 17 -6.218621e+01 7.473256e-03 * time: 14.27443814277649 18 -6.219713e+01 7.132136e-03 * time: 14.883433103561401 19 -6.220589e+01 6.768825e-03 * time: 15.50546407699585 20 -6.221423e+01 7.258585e-03 * time: 16.128148078918457 21 -6.222246e+01 6.904639e-03 * time: 16.75717306137085 22 -6.223107e+01 6.534517e-03 * time: 17.379055976867676 23 -6.223934e+01 6.995409e-03 * time: 18.00904107093811 24 -6.224612e+01 5.280502e-03 * time: 18.628047943115234 25 -6.225090e+01 4.236397e-03 * time: 19.26680302619934 26 -6.225416e+01 3.363594e-03 * time: 19.886415004730225 27 -6.225642e+01 2.944093e-03 * time: 20.521027088165283 28 -6.225803e+01 2.652824e-03 * time: 21.144922971725464 29 -6.225923e+01 2.081159e-03 * time: 21.77125906944275 30 -6.226017e+01 1.578960e-03 * time: 22.396016120910645 31 -6.226081e+01 1.304900e-03 * time: 23.02215003967285 32 -6.226117e+01 1.185979e-03 * time: 23.647971153259277 33 -6.226141e+01 8.746444e-04 * time: 24.271350145339966 34 -6.226153e+01 7.261449e-04 * time: 24.886434078216553 35 -6.226160e+01 4.518534e-04 * time: 25.499990940093994 36 -6.226163e+01 2.699016e-04 * time: 26.114582061767578 37 -6.226165e+01 2.261945e-04 * time: 26.740800142288208 38 -6.226165e+01 1.673752e-04 * time: 27.365198135375977 39 -6.226166e+01 1.514545e-04 * time: 27.972344160079956 40 -6.226166e+01 1.172625e-04 * time: 28.625244140625 41 -6.226166e+01 1.089467e-04 * time: 29.265701055526733 42 -6.226166e+01 8.707583e-05 * time: 29.902117013931274 43 -6.226167e+01 5.438479e-05 * time: 30.57490301132202 44 -6.226167e+01 4.061397e-05 * time: 31.20841693878174 45 -6.226167e+01 3.040673e-05 * time: 31.843623161315918 46 -6.226167e+01 2.978088e-05 * time: 32.46531796455383 47 -6.226167e+01 1.555779e-05 * time: 33.11745500564575 48 -6.226167e+01 8.877464e-06 * time: 33.74287295341492 49 -6.226167e+01 6.362570e-06 * time: 34.383244037628174 50 -6.226167e+01 6.041436e-06 * time: 34.993189096450806 51 -6.226167e+01 5.224231e-06 * time: 35.60582995414734 52 -6.226167e+01 4.282362e-06 * time: 36.230628967285156 53 -6.226167e+01 3.401168e-06 * time: 36.84134912490845 54 -6.226167e+01 2.934874e-06 * time: 37.46035695075989
scfres.energies
Energy breakdown: Kinetic 25.7671073 AtomicLocal -18.8557639 AtomicNonlocal 14.8522605 Ewald -67.1831486 PspCorrection -2.3569765 Hartree 4.8485368 Xc -19.3336819 total -62.261666459256