File: random-displacements.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 (243 lines) | stat: -rw-r--r-- 8,994 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
(random_displacements)=
# Random displacements

Phonopy supports generating two types of random displacements.

- Random directions with constant displacement distance
- Random sampling of harmonic oscillator probability densities of phonon modes

In both cases, phonopy generates dataset of displacements of supercells in
`phonopy_disp.yaml`, supercells with displacements, and a perfect supercell. The
number of the supercells with displacements are specified by
{ref}`random_displacements_tag` tag (or `--rd` option) in either case.

Forces on atoms in supercells with displacements are calculated by a force
calculator and force constants are computed by a force constants calculator. As
the force constants calculators, currently {ref}`fc_calculator_symfc_tag` and
{ref}`fc_calculator_alm_tag` are supported.

## Related setting tags

- {ref}`random_displacements_tag` (`--rd`)
- {ref}`random_displacement_temperature_tag` (`--rd-temperature`)
- {ref}`random_seed_tag` (`--random-seed`)
- {ref}`fc_calculator_tag` (`--fc-calc`)
- {ref}`fc_calculator_options_tag` (`--fc-calc-opt`)
- {ref}`fc_calculator_symfc_tag` (`--symfc`)
- {ref}`fc_calculator_alm_tag` (`--alm`)

## Random directions with constant displacement distance

See also {ref}`random_displacements_tag`.

(random_displacements_random_direction_example)=
### Example

An example to generate the random direction diplacements with distance of 0.03
Angstrom in `example/NaCl-rd` directory is as shown below,

```
 % phonopy --rd 10 --dim 2 2 2 --pa auto --amplitude 0.03 -c POSCAR-unitcell
         _
  _ __ | |__   ___  _ __   ___   _ __  _   _
 | '_ \| '_ \ / _ \| '_ \ / _ \ | '_ \| | | |
 | |_) | | | | (_) | | | | (_) || |_) | |_| |
 | .__/|_| |_|\___/|_| |_|\___(_) .__/ \__, |
 |_|                            |_|    |___/
                                      2.20.0

Compiled with OpenMP support (max 10 threads).
Python version 3.11.4
Spglib version 2.1.0

Crystal structure was read from "POSCAR-unitcell".
Unit of length: angstrom
Displacements creation mode
  Number of supercells with random displacements: 10
  Displacement distance: 0.03
Settings:
  Supercell: [2 2 2]
Spacegroup: Fm-3m (225)
Use -v option to watch primitive cell, unit cell, and supercell structures.

"phonopy_disp.yaml" and supercells have been created.

Summary of calculation was written in "phonopy_disp.yaml".
                 _
   ___ _ __   __| |
  / _ \ '_ \ / _` |
 |  __/ | | | (_| |
  \___|_| |_|\__,_|
```

In the generated `phonopy_disp.yaml`, dataset of displacements is stored as follows:

```
% cat phonopy_disp.yaml
...
displacements:
- #    1
  - displacement: # 1
      [  -0.0201336051051884,  0.0137526506253330,  0.0174786311319239 ]
  - displacement: # 2
      [  -0.0176810186962932,  0.0037245664471804, -0.0239480517504424 ]
  - displacement: # 3
      [  -0.0028626950563326, -0.0032145292137935,  0.0296895904139501 ]
  - displacement: # 4
      [   0.0251664434224757,  0.0149681266628547,  0.0065272742908559 ]
  - displacement: # 5
      [  -0.0136393731379345, -0.0226372187886819, -0.0141959087739228 ]
  - displacement: # 6
      [   0.0299122348895043, -0.0003839832933863, -0.0022606991718315 ]
  - displacement: # 7
      [  -0.0265153637733336, -0.0030921513486749, -0.0136884653633881 ]
  - displacement: # 8
      [   0.0284712562630672, -0.0049105574746481, -0.0080792321473599 ]
...
```

where the displacements are given in the Cartesian coordinates. The supercell
with displacements in the VASP interface is found as

```
% cat POSCAR-001
generated by phonopy
1.0
11.3806029523513423 0.0000000000000000 0.0000000000000000
0.0000000000000000 11.3806029523513423 0.0000000000000000
0.0000000000000000 0.0000000000000000 11.3806029523513423
Na Cl
32 32
Direct
0.9982308841465181 0.0012084289982625 0.0015358264588532
0.4984463899873917 0.0003272732088778 0.9978957132718971
0.9997484584016929 0.4997175431541499 0.0026087888786082
0.5022113453503161 0.5013152314271505 0.0005735438023965
0.9988015245593718 0.9980108945999205 0.4987526224371979
0.5026283523829750 0.9999662598462494 0.4998013550616521
0.9976701266282333 0.4997282963511142 0.4987972108841070
0.5025017353107100 0.4995685151748806 0.4992900875128334
...
```

It is easy to verify consistency between them, e.g.,

```python
np.dot(ph.displacements[0], np.linalg.inv(ph.supercell.cell)) + ph.supercell.scaled_positions
```

Once forces on atoms in these supercells with displacements, `FORCE_SETS` can be generated by the usual manner. For the `NaCl-rd` example,

```
% phonopy -f force-calcs/disp-{001..010}/vasprun.xml
```

where `phonopy_disp.yaml` has to be located in the current directory when the
above command is executed. The `FORCE_SETS` file is written in the
{ref}`file_forces_type_2` format. To compute force constants for the type-2
displacements-forces dataset, an external force constants calculator is
necessary, e.g., symfc(https://github.com/symfc/symfc) or ALM
(https://github.com/ttadano/ALM) by

```
% phonopy-load --symfc [OPTIONS]
```

(random_displacements_at_temperatures)=
## Random sampling of harmonic oscillator probability densities of phonon modes

Random displacements corresponding to a specific temperature are generated with
the combination of the {ref}`random_displacements_tag` (`--rd`) and
{ref}`random_displacement_temperature_tag` tags. This is based on the harmonic
phonon approximation. Since each phonon follows the probability density function
of the harmonic oscillator, the random displacements are generated by randomly
sampling the probability density functions of phonons at the commensurate
points. More details are found in the paper “Implementation
strategies in phonopy and phono3py” (see {ref}`citation_of_phonopy`).

### Example

To generate the random displacements in this approach, phonon information is
required. At the first step, phonons at the commensurate points are calculated.
Then, the random displacements are generated in the next step. Since
`phonopy_disp.yaml` is generated by the following command, it is necessary to
rename original `phonopy_disp.yaml` file (e.g., `phonopy_disp_orig.yaml`).
Assuming `FORCE_SETS` for `phonopy_disp_orig.yaml` exists in the current
directory:

```
% phonopy-load phonopy_disp_orig.yaml --rd 1000 --temperature 300
```

will generate 1000 supercells with displacements at 300K.

### Visualization of displacement distance distribution

Distribution of displacement distances may be visualized and checked by a python
script shown below.

Note that if `FORCE_SETS` or `FORCE_CONSTANTS` file exists in
the current directory, those are automatically read by `phonopy.load` function
even if `phonopy_disp.yaml` file contains displacements. So the following script
is recommended to run in an isolated directory, e.g.,

```bash
% mkdir rd && cd rd
% cp ../phonopy_disp.yaml
```

Then opening ipython (or jupiter),

```python
import matplotlib.pyplot as plt
import numpy as np
import phonopy
ph = phonopy.load("phonopy_disp.yaml")
plt.hist(np.linalg.norm(ph.displacements.reshape(-1, 3), axis=1), 100)
plt.show()
```

```{image} NaCl-disp-dist.png
:scale: 50
```

### Another example

In the below, a step-by-step example is presented.

1. Compute supercell force sets in the usual manner with small displacements.
   Generate `FORCE_SETS` in the current directory.
2. Create new directory and copy `FORCE_SETS` and input crystal structure, or
   `phonopy_disp.yaml` to the new directory, then change to the new directory.
3. Using `FORCE_SETS`, generate supercells with random displacements at finite
   temperature using this tag. `phonopy_disp.yaml` is generated at this step.
   Therefore, if `phonopy_disp.yaml` already exists in this directory, it is
   overwritten. The required number of supercells depends on your system and
   also the purpose. It can be 10, or can be 1000.
4. Using those supercells with random displacements, calculate supercell forces
   with some force calculator with VASP, QE, etc.
5. Generate `FORCE_SETS` in this directory, which overwrites previous
   `FORCE_SETS`.
6. Run the force constants calculation, e.g., with symfc. Symfc fits the
   displacement-force dataset stored in `FORCE_SETS` to symmetry adapted force
   constants. Run also phonon calculation. This is done for example,

   ```bash
   phonopy-load -v --symfc --mesh 10 10 10 -p
   ```

   or

   ```bash
   phonopy-load -v --symfc --writefc
   phonopy-load --readfc --mesh 10 10 10 -p
   ```

   Force constants calculated as above contain a part of temperature effect from
   atomic displacements. To even better include the temperature effect, this
   calculation has to be done self-consistently, i.e., it is required to repeat
   the loop over the steps 2-5 until the phonon structure is converged. The
   solution corresponds to a stochastic self-consistent harmonic approximation
   ({ref}`reference_sscha`) approach.

It is also possible to perform the same calculation as above using the phonopy API. ({ref}`phonopy_module`)