14.2. Silicon with LAMMPS#
At a glance
- Goal:
Use LAMMPS instead of a DFT code to calculate the atomic forces of Si (Stillinger-Weber potential), and calculate the lattice thermal conductivity from different unit-cell inputs.
- You will learn:
how to prepare the LAMMPS input files for ALAMODE
how to generate displaced structures with
displace.py --LAMMPShow to build the DFSET files from the LAMMPS forces with
extract.pyhow the unit cell given in the
&cellfield affects the \(k\)-point convergence of the thermal conductivity
- Prerequisites:
The Si tutorial and LAMMPS (e.g.
conda install -c conda-forge lammps).- Example files:
example/Si_LAMMPS- Run time:
run_all.sh runs the whole workflow in about 5 seconds. The denser \(k\) meshes in the last section take up to about 20 minutes each.
Here, we demonstrate how to use ALAMODE together with LAMMPS.
All input files can be found in the example/Si_LAMMPS directory.
Before starting the tutorial, please install LAMMPS. The easiest way is conda install -c conda-forge lammps,
which provides the binary lmp. If you build LAMMPS yourself, the binary may be called lmp_serial or lmp_mpi instead.
The script run_all.sh performs all the steps below: displacement patterns by alm, force calculations by LAMMPS, fitting of the harmonic and cubic force constants, phonon dispersion, and thermal conductivity with the primitive cell and a \(10\times 10\times 10\) mesh. It takes about 5 seconds:
$ LAMMPS=lmp ALAMODE_ROOT=/path/to/alamode bash run_all.sh
The environment variables LAMMPS, ALAMODE_ROOT, ALM, and ANPHON override the default paths
of the binaries, and python3 must provide NumPy and PyYAML.
As a simple example, we calculate phonon dispersion curves of Si using the Stillinger-Weber (SW) potential implemented in LAMMPS. First, you need to make two input files for LAMMPS: in.sw and Si222.lammps (file name is arbitrary, though), in addition to the potential file Si.sw. in.sw is the main input file for LAMMPS, in which the type of the empirical force field is defined as follows:
units metal
atom_style atomic
boundary p p p
read_data tmp.lammps
pair_style sw
pair_coeff * * Si.sw Si
dump 1 all custom 1 XFSET id xu yu zu fx fy fz
dump_modify 1 format float "%20.15f"
run 0
In the file Si222.lammps, the lattice vectors and atomic positions of a relaxed supercell structure are defined as follows:
Si222.lammps (first 30 lines)
# Structure data of Si (2x2x2 conventional)
64 atoms
1 atom types
0.000000 10.800000 xlo xhi
0.000000 10.800000 ylo yhi
0.000000 10.800000 zlo zhi
0.000000 0.000000 0.000000 xy xz yz
Masses
1 28.085
Atoms
1 1 0.000000 0.000000 0.000000
2 1 0.000000 0.000000 5.400000
3 1 0.000000 2.700000 2.700000
4 1 0.000000 2.700000 8.100000
5 1 0.000000 5.400000 0.000000
6 1 0.000000 5.400000 5.400000
7 1 0.000000 8.100000 2.700000
8 1 0.000000 8.100000 8.100000
9 1 1.350000 1.350000 1.350000
10 1 1.350000 1.350000 6.750000
11 1 1.350000 4.050000 4.050000
12 1 1.350000 4.050000 9.450000
13 1 1.350000 6.750000 1.350000
14 1 1.350000 6.750000 6.750000
Next, please generate a set of structure files for displaced configurations using the python script:
$ python displace.py --LAMMPS=Si222.lammps --mag=0.01 --prefix harm -pf si222.pattern_HARMONIC
$ python displace.py --LAMMPS=Si222.lammps --mag=0.04 --prefix cubic -pf si222.pattern_ANHARM3
The pattern files can be generated by the alm code as described here.
The above commands create harm1.lammps and cubic[01-20].lammps structure files.
Then, run the following script and calculate atomic forces for the generated structures.
This should finish in a few seconds.
#!/bin/bash
cp harm1.lammps tmp.lammps
lmp < in.sw > log.lammps
cp XFSET XFSET.harm1
for ((i=1;i<=20;i++))
do
num=`echo $i | awk '{printf("%02d",$1)}'`
cp cubic${num}.lammps tmp.lammps
lmp < in.sw > log.lammps
cp XFSET XFSET.cubic${num}
done
After the force calculations are finished, displacement and force data sets can be generated as follows:
$ python extract.py --LAMMPS=Si222.lammps XFSET.harm1 > DFSET_harmonic
$ python extract.py --LAMMPS=Si222.lammps XFSET.cubic* > DFSET_cubic
Then, using these files and following exactly the same procedure as the Si tutorial,
you can calculate phonons and thermal conductivity of Si using the SW potential.
run_all.sh fits the harmonic IFCs to si222_harm.h5 and then the cubic IFCs to si222_cubic.h5,
keeping the harmonic IFCs fixed (FC2FIX = si222_harm.h5).
Thermal conductivity from different unit cells#
The lattice thermal conductivity \(\kappa\) is a property of the crystal. It does not depend on which unit cell you give to anphon, provided that the Brillouin zone sampling is converged. In practice, however, the choice of the unit cell changes how fast \(\kappa\) converges with respect to the \(k\) mesh. In this section, we compare three choices using si222_cubic.h5 from run_all.sh.
Which unit cell does anphon use?
The &cell field of anphon (see &cell-field) can be omitted when FCSFILE is an HDF5 file.
In that case, anphon uses the primitive cell stored in that file by alm.
If &cell is given, it replaces the stored cell.
It must be the true primitive cell or a supercell of it, such as the conventional cell,
so that the supercell stored in FCSFILE consists of whole copies of it.
In this example, the alm input defines the 64-atom cubic supercell (\(2\times 2\times 2\) conventional cell) and has no PRIMCELL tag.
Therefore, the “primitive cell” stored in si222_cubic.h5 is the 64-atom supercell itself,
and anphon uses this 64-atom cell when &cell is omitted.
To store the true primitive cell, set PRIMCELL in the &general field of the alm input.
Its rows give the primitive lattice vectors in units of the input lattice vectors. Here, we may use:
PRIMCELL = 0 1/4 1/4 1/4 0 1/4 1/4 1/4 0
or PRIMCELL = Auto to detect the primitive cell with spglib.
We use the following three inputs. Apart from their PREFIX, they differ only in the &cell field and in the \(k\) mesh.
&general
PREFIX = si_prim
MODE = kappa
FCSFILE = si222_cubic.h5
/
&cell
10.203
0.0 0.5 0.5
0.5 0.0 0.5
0.5 0.5 0.0
/
&kpoint
2
20 20 20
/
&general
PREFIX = si_conv
MODE = kappa
FCSFILE = si222_cubic.h5
/
&cell
10.203
1.0 0.0 0.0
0.0 1.0 0.0
0.0 0.0 1.0
/
&kpoint
2
10 10 10
/
&general
PREFIX = si_omitted
MODE = kappa
FCSFILE = si222_cubic.h5
/
&kpoint
2
5 5 5
/
Run them in the directory that contains si222_cubic.h5:
$ anphon reference/kappa_prim.in > kappa_prim.log
$ anphon reference/kappa_conv.in > kappa_conv.log
$ anphon reference/kappa_omitted.in > kappa_omitted.log
To test the convergence, change the three numbers in the &kpoint field.
To compare the cells at the same \(k\)-point density, count the \(k\) points per primitive cell:
an \(N\times N\times N\) mesh of the primitive cell has \(N^{3}\),
an \(M\times M\times M\) mesh of the conventional cell (4 primitive cells) has \(4M^{3}\),
and an \(L\times L\times L\) mesh of the 64-atom cell (32 primitive cells) has \(32L^{3}\).
We also repeated the calculations with Gaussian smearing (ISMEAR = 1 with the default EPSILON = 10)
in addition to the default tetrahedron method (ISMEAR = -1); see ISMEAR.
All the calculations include isotope scattering (ISOTOPE = 1, the default).
The following table and figure show \(\kappa_{xx}\) at 300 K (W/mK).
|
\(k\) points per primitive cell |
Tetrahedron ( |
Gaussian ( |
|---|---|---|---|
Primitive, \(10^3\) |
1000 |
412.42 |
394.71 |
Primitive, \(20^3\) |
8000 |
490.76 |
446.41 |
Primitive, \(30^3\) |
27000 |
508.66 |
453.82 |
Primitive, \(40^3\) |
64000 |
518.01 |
456.41 |
Conventional, \(5^3\) |
500 |
377.96 |
385.37 |
Conventional, \(10^3\) |
4000 |
441.02 |
440.15 |
Conventional, \(15^3\) |
13500 |
464.78 |
449.30 |
Conventional, \(20^3\) |
32000 |
480.33 |
453.91 |
Omitted (64-atom), \(5^3\) |
4000 |
444.21 |
440.22 |
kappa_300K_prim.txt,
kappa_300K_conv.txt,
kappa_300K_64atom.txt
Same k points, different cells.
The conventional \(10\times 10\times 10\) mesh and the 64-atom \(5\times 5\times 5\) mesh sample exactly the same
\(k\) points in the Brillouin zone of the primitive cell.
With Gaussian smearing, the two results agree within 0.02% (440.15 and 440.22 W/mK).
Without isotope scattering (ISOTOPE = 0), they agree equally well (526.65 and 526.77 W/mK).
With the tetrahedron method, however, they differ by about 0.7% (441.02 and 444.21 W/mK).
The reason is that the tetrahedron method interpolates each phonon band linearly inside each tetrahedron, band by band in the order of the band index, that is, in the order of increasing frequency. In a larger cell, the bands are folded into a smaller Brillouin zone, and the frequency-sorted bands cross each other much more often, so that a band index no longer follows a single phonon branch. Near such crossings, the linear interpolation is less accurate, so a larger cell tends to need a denser mesh for the same accuracy. This has two consequences in the figure above:
With the tetrahedron method, the conventional cell converges more slowly than the primitive cell. At 32000 \(k\) points per primitive cell, the conventional cell gives 480 W/mK, whereas the primitive cell gives 509 to 518 W/mK at a similar or higher density.
With Gaussian smearing of a fixed width, the band ordering does not enter, and both cells follow essentially the same curve against the \(k\)-point density (456.41 W/mK for the primitive cell and 453.91 W/mK for the conventional cell at the densest meshes).
The smearing width also matters.
At the densest primitive-cell mesh, Gaussian smearing gives 456.41 W/mK, compared with 518.01 W/mK for the tetrahedron method
(which is still increasing slowly).
The fixed width EPSILON = 10 cm-1 broadens the energy conservation of the three-phonon processes and of the isotope scattering,
and this bias does not vanish with a denser mesh alone.
The tetrahedron method has no width parameter,
whereas a Gaussian result must also be converged with respect to EPSILON, together with the \(k\) mesh.
Tip
Use the primitive cell for thermal conductivity calculations, especially with the tetrahedron method.
If
&cellis omitted, anphon uses whatever primitive cell alm stored in the HDF5 file. Check the unit cell in the anphon log, or setPRIMCELLin the alm input so that the true primitive cell is stored.A large unit cell also makes anphon much slower. With 4 MPI processes and 2 OpenMP threads, the 64-atom \(5\times 5\times 5\) run took about 6 minutes, while the conventional \(10\times 10\times 10\) run, which samples the same \(k\) points, took about 30 seconds.