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. To run this example Julia's PyCall
package
needs to be able to find an installation of pymatgen
.
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]];
┌ Warning: `vendor()` is deprecated, use `BLAS.get_config()` and inspect the output instead │ caller = npyinitialize() at numpy.jl:67 └ @ PyCall /home/runner/.julia/packages/PyCall/3fwVL/src/numpy.jl:67
Setup an LDA model and discretize using
a single k-point and a small Ecut
of 5 Hartree.
model = model_LDA(lattice, atoms)
basis = PlaneWaveBasis(model; Ecut=5, kgrid=(1, 1, 1))
PlaneWaveBasis discretization: Ecut : 5.0 Ha fft_size : (32, 32, 32) kgrid type : Monkhorst-Pack kgrid : [1, 1, 1] num. irred. kpoints : 1 Discretized Model(lda_xc_teter93, 3D): lattice (in Bohr) : [0 , 10.2631 , 10.2631 ] [10.2631 , 0 , 10.2631 ] [10.2631 , 10.2631 , 0 ] unit cell volume : 2162.1 Bohr³ atoms : Si₁₆ atom potentials : ElementPsp(Si, psp=hgh/lda/si-q4) num. electrons : 64 spin polarization : none temperature : 0 Ha terms : Kinetic(1) AtomicLocal() AtomicNonlocal() Ewald() PspCorrection() Hartree(1) Xc([:lda_xc_teter93], 1, nothing)
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.127665e+02 1.606264e+00 * time: 0.6813020706176758 1 1.102113e+01 9.131531e-01 * time: 1.9149129390716553 2 -1.220498e+01 1.003073e+00 * time: 2.5312600135803223 3 -3.431502e+01 7.718194e-01 * time: 3.4145729541778564 4 -4.808367e+01 5.306985e-01 * time: 4.330345153808594 5 -5.708626e+01 1.905927e-01 * time: 5.2445759773254395 6 -5.987112e+01 1.060438e-01 * time: 5.848098993301392 7 -6.090861e+01 5.019898e-02 * time: 6.447036027908325 8 -6.129330e+01 5.690215e-02 * time: 7.047147035598755 9 -6.159423e+01 3.711250e-02 * time: 7.6310529708862305 10 -6.180460e+01 2.781044e-02 * time: 8.25081992149353 11 -6.196505e+01 1.742607e-02 * time: 8.833728075027466 12 -6.202623e+01 1.612862e-02 * time: 9.419173955917358 13 -6.208966e+01 1.361778e-02 * time: 10.022592067718506 14 -6.212275e+01 1.399923e-02 * time: 10.64862608909607 15 -6.215683e+01 1.274281e-02 * time: 11.240405082702637 16 -6.218055e+01 1.113331e-02 * time: 11.818444013595581 17 -6.219644e+01 7.867465e-03 * time: 12.443083047866821 18 -6.220863e+01 6.479617e-03 * time: 13.03515911102295 19 -6.221581e+01 7.018942e-03 * time: 13.640233993530273 20 -6.222156e+01 8.555744e-03 * time: 14.274359941482544 21 -6.222693e+01 8.129904e-03 * time: 14.878632068634033 22 -6.223305e+01 6.875692e-03 * time: 15.519186019897461 23 -6.223939e+01 6.258161e-03 * time: 16.127515077590942 24 -6.224536e+01 5.625647e-03 * time: 16.754805088043213 25 -6.225068e+01 4.487478e-03 * time: 17.370190143585205 26 -6.225468e+01 3.762597e-03 * time: 17.985623121261597 27 -6.225731e+01 2.608814e-03 * time: 18.609884023666382 28 -6.225884e+01 2.552003e-03 * time: 19.22965097427368 29 -6.225982e+01 1.754205e-03 * time: 19.824806928634644 30 -6.226047e+01 1.777548e-03 * time: 20.458758115768433 31 -6.226090e+01 1.375625e-03 * time: 21.07746696472168 32 -6.226118e+01 1.029226e-03 * time: 21.656898975372314 33 -6.226139e+01 8.291170e-04 * time: 22.243086099624634 34 -6.226152e+01 5.685170e-04 * time: 22.854833126068115 35 -6.226159e+01 4.788458e-04 * time: 23.467275142669678 36 -6.226163e+01 3.158293e-04 * time: 24.047385931015015 37 -6.226165e+01 2.020799e-04 * time: 24.682228088378906 38 -6.226166e+01 1.715368e-04 * time: 25.28341794013977 39 -6.226166e+01 1.022627e-04 * time: 25.914152145385742 40 -6.226166e+01 8.447038e-05 * time: 26.54927897453308 41 -6.226166e+01 7.183904e-05 * time: 27.177632093429565 42 -6.226166e+01 6.062900e-05 * time: 27.8263840675354 43 -6.226167e+01 4.902286e-05 * time: 28.424849033355713 44 -6.226167e+01 3.748563e-05 * time: 29.03422999382019 45 -6.226167e+01 3.233952e-05 * time: 29.61795997619629 46 -6.226167e+01 2.514306e-05 * time: 30.203439950942993 47 -6.226167e+01 1.679244e-05 * time: 30.83185911178589 48 -6.226167e+01 1.195956e-05 * time: 31.44237995147705 49 -6.226167e+01 1.100932e-05 * time: 32.03841805458069 50 -6.226167e+01 6.349492e-06 * time: 32.65385413169861 51 -6.226167e+01 4.615798e-06 * time: 33.2709641456604 52 -6.226167e+01 4.007953e-06 * time: 33.85377311706543 53 -6.226167e+01 3.444816e-06 * time: 34.46028804779053
scfres.energies
Energy breakdown (in Ha): Kinetic 25.7671068 AtomicLocal -18.8557675 AtomicNonlocal 14.8522645 Ewald -67.1831486 PspCorrection -2.3569765 Hartree 4.8485369 Xc -19.3336819 total -62.261666457831