File: qe.md

package info (click to toggle)
phonopy 2.48.0-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 29,556 kB
  • sloc: python: 44,403; xml: 12,080; ansic: 3,227; cpp: 525; sh: 213; makefile: 20
file content (460 lines) | stat: -rw-r--r-- 14,243 bytes parent folder | download
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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
(qe_interface)=
# Quantum ESPRESSO (QE) & phonopy calculation

Quantum ESPRESSO package itself has a set of the phonon calculation
system. But the document here explains how to calculate phonons using
phonopy, i.e., using the finite displacement and supercell approach.

## Supported QE-PW tags

Currently QE-PW tags that phonopy can read are shown below.  Only
`ibrav = 0` type representation of crystal structure is supported.
More tags may be supported on request.

```
nat, ntyp, celldm(1), ATOMIC_SPECIES, ATOMIC_POSITIONS, CELL_PARAMETERS
```

Chemical symbols with natural number for `ATOMIC_SPECIES` like `Xn` (`n>0`),
e.g.. `Fe1`, can be used. The formats of `X_*` and `X-*` are not supported. When
this extended symbol is used, masses of all atoms including usual chemical
symbols are read from QE structure file. Otherwise, masses of respective
chemical symbols implemented in phonopy are used. Note that when using the
extended symbol, if the unit cell of QE structure file is not a primitive cell,
and the primitive cell is defined by the transformation matrix (`PRIMITIVE_AXES`
tag or `--pa` option), atoms with the extended symbols in the unit cell have to
be mapped properly to those in the primitive cell.

## How to run

The procedure of QE-phonopy calculation is shown below using the
NaCl example found in `example/NaCl-QE` directory.

1) Read a QE-PW input file and create supercells with
   {ref}`qe_mode` option:

   ```bash
   % phonopy --qe -d --dim="2 2 2" -c NaCl.in
   ```

   In this example, 2x2x2 supercells are created. `supercell.in` and
   `supercell-xxx.in` (`xxx` are numbers) give the perfect
   supercell and supercells with displacements, respectively. In the
   case of the NaCl example, two files `supercell-001.in` and
   `supercell-002.in` are created. In these supercell files, lines
   only relevant to crystal structures are
   given. `phonopy_disp.yaml` is also generated, which contains
   information about supercell and displacements.

2) To make QE-PW input files, necessary setting information is added to
   `supercell-xxx.in` files, e.g., by:

   ```bash
   % for i in {001,002};do cat header.in supercell-$i.in >| NaCl-$i.in; done
   ```

   where `header.in` is specially made for this NaCl example and
   this file is found in `example/NaCl-QE` directory. This
   setting is of course dependent on systems and has to be written for
   each interested system. Note that supercells with displacements
   must not be relaxed in the force calculations, because atomic
   forces induced by a small atomic displacement are what we need for
   phonon calculation.

   Then QE-PW supercell calculations are executed to obtain force on
   atoms, e.g., as follows:

   ```bash
   % pw.x -i NaCl-001.in |& tee NaCl-001.out
   % pw.x -i NaCl-002.in |& tee NaCl-002.out
   ```

3) To create `FORCE_SETS`, that is used by phonopy,
   the following phonopy command is executed:

   ```bash
   % phonopy -f NaCl-001.out NaCl-002.out
   ```

   Here `.out` files are the saved text files of standard outputs of the
   QE-PW calculations. If more supercells with displacements were
   created in the step 1, all `.out` files are given in the above
   command. To run this command, `phonopy_disp.yaml` has to be located in
   the current directory because the information on atomic
   displacements stored in `phonopy_disp.yaml` are used to generate
   `FORCE_SETS`. See some more detail at
   {ref}`qe_force_sets_option`.

4) Now post-process of phonopy is ready to run. The unit cell file
   used in the step 1 has to be specified but `FORCE_SETS` is
   automatically read. Examples of post-process are shown below.

   ```
   % phonopy-load -p --config band.conf
           _
     _ __ | |__   ___  _ __   ___   _ __  _   _
    | '_ \| '_ \ / _ \| '_ \ / _ \ | '_ \| | | |
    | |_) | | | | (_) | | | | (_) || |_) | |_| |
    | .__/|_| |_|\___/|_| |_|\___(_) .__/ \__, |
    |_|                            |_|    |___/
                                         2.47.1

   -------------------------[time 2026-01-16 08:09:24]-------------------------
   Compiled with OpenMP support (max 10 threads).
   Running in phonopy.load mode.
   Python version 3.13.3
   Spglib version 2.7.0

   "band.conf" was read as phonopy configuration file.
   Calculator interface: qe
   Crystal structure was read from "phonopy_disp.yaml".
   Unit of length: au
   Band structure mode
   Settings:
     Supercell: [2 2 2]
     Primitive matrix:
       [0.  0.5 0.5]
       [0.5 0.  0.5]
       [0.5 0.5 0. ]
   Spacegroup: Fm-3m (225)
   Number of symmetry operations in supercell: 1536
   Use -v option to watch primitive cell, unit cell, and supercell structures.

   NAC params were read from "BORN".
   Displacement-force dataset was read from "FORCE_SETS".
   -------------------------------- Symfc start -------------------------------
   Symfc version 1.6.0 (https://github.com/symfc/symfc)
   Citation: A. Seko and A. Togo, Phys. Rev. B, 110, 214302 (2024)
   Computing [2] order force constants.
   Increase log-level to watch detailed symfc log.
   --------------------------------- Symfc end --------------------------------
   Max drift of force constants: -0.00000000 (yy) -0.00000000 (yy)
   Max drift after symmetrization by symfc projector: -0.00000000 (yy) -0.00000000 (yy)

   Reciprocal space paths in reduced coordinates:
   [ 0.000  0.000  0.000] --> [ 0.500  0.000  0.000]
   [ 0.500  0.000  0.000] --> [ 0.500  0.500  0.000]
   [ 0.500  0.500  0.000] --> [ 0.000  0.000  0.000]
   [ 0.000  0.000  0.000] --> [ 0.500  0.500  0.500]

   Summary of calculation was written in "phonopy.yaml".
   -------------------------[time 2026-01-16 08:09:27]-------------------------
                    _
      ___ _ __   __| |
     / _ \ '_ \ / _` |
    |  __/ | | | (_| |
     \___|_| |_|\__,_|
   ```

   ```{image} NaCl-pwscf-band.png
   :width: 50%
   ```

   `--qe -c NaCl.in` is specific for the QE-phonopy
   calculation but the other settings are totally common among calculator
   interfaces such as

   ```
   % phonopy --qe -c NaCl.in --dim="2 2 2" [other-OPTIONS] [setting-file]
   ```

   For settings and command options, see
   {ref}`setting_tags` and {ref}`command_options`, respectively, and
   for examples, see {ref}`examples_link`.

### Non-analytical term correction (Optional)

To activate non-analytical term correction, {ref}`born_file` is
required. This file contains the information of Born effective charge
and dielectric constant. These physical values are also obtained from
the PW (`pw.x`) & PH (`ph.x`) codes in Quantum ESPRESSO
package. There are two steps. The first step is usual self-consistent
field (SCF) calculation
by and the second step is running its response function calculations
under DFPT.

For the SCF calculation, the input file `NaCl.in` looks like:

```
 &control
    calculation = 'scf'
    tprnfor = .true.
    tstress = .true.
    pseudo_dir = '/home/togo/espresso/pseudo/'
 /
 &system
    ibrav = 0
    nat = 8
    ntyp = 2
    ecutwfc = 70.0
 /
 &electrons
    diagonalization = 'david'
    conv_thr = 1.0d-9
 /
ATOMIC_SPECIES
 Na  22.98976928 Na.pbe-spn-kjpaw_psl.0.2.UPF
 Cl  35.453      Cl.pbe-n-kjpaw_psl.0.1.UPF
ATOMIC_POSITIONS crystal
 Na   0.0000000000000000  0.0000000000000000  0.0000000000000000
 Na   0.0000000000000000  0.5000000000000000  0.5000000000000000
 Na   0.5000000000000000  0.0000000000000000  0.5000000000000000
 Na   0.5000000000000000  0.5000000000000000  0.0000000000000000
 Cl   0.5000000000000000  0.5000000000000000  0.5000000000000000
 Cl   0.5000000000000000  0.0000000000000000  0.0000000000000000
 Cl   0.0000000000000000  0.5000000000000000  0.0000000000000000
 Cl   0.0000000000000000  0.0000000000000000  0.5000000000000000
CELL_PARAMETERS angstrom
 5.6903014761756712 0 0
 0 5.6903014761756712 0
 0 0 5.6903014761756712
K_POINTS automatic
 8 8 8 1 1 1
```

where more the k-point mesh numbers are specified. This may be exectued as:

```bash
% pw.x -i NaCl.in |& tee NaCl.out
```

Many files whose names stating with `pwscf` should be created. These
are used for the next calculation. The input file for the response
function calculations, `NaCl.ph.in`, is
created as follows:

```
 &inputph
  tr2_ph = 1.0d-14,
  epsil = .true.
 /
0 0 0
```

Similary `ph.x` is executed:

```bash
% ph.x -i NaCl.ph.in |& tee NaCl.ph.out
```

Finally the Born effective charges and dielectric constant are obtained in the
output file `NaCl.ph.out`. The `BORN` file has to be created following the
`BORN` format ({ref}`born_file`). The `BORN` file for this NaCl calculation
would be something like below:

```
default value
2.472958201 0 0 0 2.472958201 0 0 0 2.472958201
1.105385 0 0 0 1.105385 0 0 0 1.105385
-1.105385 0 0 0 -1.105385 0 0 0 -1.105385
```

This `BORN` file can be made using `phonopy-qe-born` command.

```bash
% phonopy-qe-born NaCl.in NaCl.ph.out | tee BORN
```

Once this is made, the non-analytical term correction is included
just adding the `--nac` option as follows:

```bash
% phonopy-load -p --config band.conf
```

```{image} NaCl-pwscf-band-NAC.png
:width: 50%
```

(qe_q2r)=
## Using `q2r.x` to create phonopy force constants file

**Experimental**

Using PW, PH, and Q2R, we can obtain supercell force constants that can be used
for phonopy. But we may need some treatment before running Q2R. See
{ref}`qe_nac`.

 `NaCl.in`
```
 &control
    calculation = 'scf'
    restart_mode='from_scratch',
    tprnfor = .true.
    tstress = .true.
    prefix='NaCl',
    pseudo_dir = '/home/togo/code/q-e-qe-7.5/pseudo'
    outdir='.'
 /
 &system
    ibrav = 0
    nat = 2
    ntyp = 2
    ecutwfc = 70.0
 /
 &electrons
    diagonalization = 'david'
    !mixing_beta = 0.7
    conv_thr = 1.0d-12
 /
ATOMIC_SPECIES
 Na  22.98976928 Na.pbe-spn-kjpaw_psl.0.2.UPF
 Cl  35.453      Cl.pbe-n-kjpaw_psl.0.1.UPF
ATOMIC_POSITIONS crystal
 Na   0.0000000000000000  0.0000000000000000  0.0000000000000000
 Cl   0.5000000000000000  0.5000000000000000  0.5000000000000000
CELL_PARAMETERS angstrom
0 2.8451507380878356 2.8451507380878356
2.8451507380878356 0 2.8451507380878356
2.8451507380878356 2.8451507380878356 0
K_POINTS automatic
8 8 8 0 0 0
```
and `NaCl.ph.in`
```
phonons of NaCl
 &inputph
  tr2_ph=1.0d-16,
  prefix='NaCl',
  ldisp=.true.,
  nq1=4, nq2=4, nq3=4
  amass(1)=22.98976928,
  amass(2)=35.453,
  outdir='.',
  fildyn='NaCl.dyn',
 /
```

The PH calculation can be peformed for each q-point independently, e.g.,
```
phonons of NaCl
 &inputph
  tr2_ph=1.0d-16,
  prefix='NaCl',
  ldisp=.true.,
  nq1=4, nq2=4, nq3=4
  amass(1)=22.98976928,
  amass(2)=35.453,
  outdir='.',
  fildyn='NaCl.dyn',
  start_q=1
  last_q=1
 /
 ```

The output file at the Gamma point calculated this way contains the Born
effective charges and dielectric constant if the crystal is an insulator. These
are unnecessary for phonopy. Therefore, the `NaCl.dyn1` file should be replaced
with `NaCl.dyn`, which is calculated using the following input:

```
phonons of NaCl
 &inputph
  tr2_ph=1.0d-16,
  prefix='NaCl',
  epsil=.false.,
  outdir='.',
  fildyn='NaCl.dyn',
 /
0.0 0.0 0.0
```

Then having all `NaCl.dyn1`, ..., files, `NaCl.fc` for phonopy can be generated
using Q2R.

A parser of `q2r.x` output is implemented experimentally. Currently command-line
user interface is not prepared. Using the following script, the force constants
file readable by phonopy is created.

```python
#!/usr/bin/env python

import sys
from phonopy.interface.qe import read_pwscf, PH_Q2R

primcell_filename = sys.argv[1]
q2r_filename = sys.argv[2]
cell, _ = read_pwscf(primcell_filename)
q2r = PH_Q2R(q2r_filename)
q2r.run(cell)
q2r.save()
```

Saving this script as `make_fc_q2r.py`, this is used as, e.g.,

```bash
% python make_fc_q2r.py NaCl.in NaCl.fc
```

This gives `phonopy_params_q2r.yaml` file that contains supercell force
constants.

(qe_nac)=
### Non-analytical term correction

The treatment of non-analytical term correction (NAC) differs between phonopy
and QE. For insulators, QE automatically calculates the dielectric constant and
Born effective charges during PH calculations when the q-point mesh sampling
mode is enabled (`ldisp = .true.`). These data are written to the Gamma point
dynamical matrix file (typically the `.dyn1` file). When running `q2r.x`, this
program reads these files including the dielectric constant and Born effective
charges, and writes the real-space force constants (with QE's NAC treatment
applied) to the Q2R output file. However, this differs from what phonopy
expects. Therefore, the dielectric constant and Born effective charges data must
be manually removed from the Gamma point dynamical matrix file before running
`q2r.x`. Alternatively, performing a Gamma point-only phonon calculation with
`epsil = .false.` generates a dynamical matrix file without the dielectric
constant and Born effective charges data. This Gamma point-only file can then
replace the original Gamma point file, allowing `q2r.x` to be run for phonopy
without modification.

<!-- #### Creating BORN file

If the `q2r.x` output contains dielectric constant and Born
effective charges, the following script can generate `BORN` format
text.

```python
#!/usr/bin/env python

import sys
import numpy as np
from phonopy.structure.symmetry import elaborate_borns_and_epsilon
from phonopy.interface.qe import read_pwscf, PH_Q2R

primcell_filename = sys.argv[1]
q2r_filename = sys.argv[2]
cell, _ = read_pwscf(primcell_filename)
q2r = PH_Q2R(q2r_filename)
q2r.run(cell, parse_fc=False)
if q2r.epsilon is not None:
    borns, epsilon, _ = elaborate_borns_and_epsilon(
        cell,
        q2r.borns,
        q2r.epsilon,
        supercell_matrix=np.diag(q2r.dimension),
        symmetrize_tensors=True)
    print("default")
    print(("%13.8f" * 9) % tuple(epsilon.ravel()))
    for z in borns:
        print(("%13.8f" * 9) % tuple(z.ravel()))
```

Saving this script as `make_born_q2r.py`,

```bash
% python make_born_q2r.py NaCl.in NaCl.fc > BORN
``` -->

#### NaCl example

NaCl example is found at
<https://github.com/phonopy/phonopy/tree/master/example/NaCl-QE-q2r>.

```bash
% phonopy-load phonopy_params_q2r.yaml --band="0 0 0  1/2 0 0  1/2 1/2 0  0 0 0  1/2 1/2 1/2" -p
```

```{image} NaCl-q2r-band-NAC.png
:width: 50%
```