-
Notifications
You must be signed in to change notification settings - Fork 83
/
pymatgen.jl
41 lines (36 loc) · 1.74 KB
/
pymatgen.jl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
# # Creating supercells with pymatgen
#
# The [Pymatgen](https://pymatgen.org/) 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, Si]
positions = [ones(3)/8, -ones(3)/8];
# Next we make a `[2, 2, 2]` supercell using pymatgen
pystruct = pymatgen_structure(lattice, atoms, positions)
pystruct.make_supercell([2, 2, 2])
lattice = load_lattice(pystruct)
positions = load_positions(pystruct)
atoms = fill(Si, length(positions));
# Setup an LDA model and discretize using
# a single k-point and a small `Ecut` of 5 Hartree.
model = model_LDA(lattice, atoms, positions)
basis = PlaneWaveBasis(model; Ecut=5, kgrid=(1, 1, 1))
# Find the ground state using direct minimisation and newton
# (always using SCF is boring ...)
scfres = direct_minimization(basis; tol=1e-3);
ψ, _ = DFTK.select_occupied_orbitals(basis, scfres.ψ, scfres.occupation)
scfres_newton = newton(basis, ψ; tol=1e-12)
#-
scfres_newton.energies