Scattering
The scattering class contains functions for calculating scattering functions of materials, as averaged over a list of Extended ASE Atoms objects.
Included functions:
-
Partial pair distribution function: \(g_{ij}(r)\):
get_partial_pdf- \(g_{ij}(r) = \frac{n_{ij}(r)}{4 \pi r^2 dr \rho_{j}}\)
- \(n_{ij}(r)\) is the number of particles of type \(j\) between distance \(r\) and \(r + dr\) from a particle of type \(i\) and \(\rho_{j} = c_{j} \rho_{0}\).
- \(g_{ij}(r) = \frac{n_{ij}(r)}{4 \pi r^2 dr \rho_{j}}\)
-
Normalized total radial distribution function \(G'(r)\):
get_total_rdf- \(G'(r) = \frac{\sum_{i,j=1}^{n} W_{ij} g_{ij}(r)}{(\sum_{i=1}^{n} c_{i} \bar b_{i})^2}\).
- \(G'(r) = \frac{\sum_{i,j=1}^{n} W_{ij} g_{ij}(r)}{(\sum_{i=1}^{n} c_{i} \bar b_{i})^2}\).
-
Differential correlation function: \(D(r)\):
get_reduced_pdf- \(D(r) = 4 \pi r \rho_{0} [G'(r) - 1]\), where \(\rho_{0}\) is the average number density.
- This function is occasionally referred to as \(G(r)\) (reduced pair distribution function) in literature.
- \(D(r) = 4 \pi r \rho_{0} [G'(r) - 1]\), where \(\rho_{0}\) is the average number density.
-
Total correlation function: \(T(r)\):
get_T_r_pdf- \(T(r) = 4 \pi r\rho_{0} G'(r)\), where \(\rho_{0}\) is the average number density.
- \(T(r) = 4 \pi r\rho_{0} G'(r)\), where \(\rho_{0}\) is the average number density.
-
Partial structure factor: \(A_{ij}(Q)\):
get_partial_structure_factor- \(A_{ij}(Q) = 1 + \rho_{0} \int_{0}^{\infty} 4 \pi r^2 (g_{ij}(r) - 1) L(r) dr\)
- Optional: Lorch function: \(L(r) = \frac{\sin(\pi r / r_{max})}{\pi r / r_{max}}\).
- \(A_{ij}(Q) = 1 + \rho_{0} \int_{0}^{\infty} 4 \pi r^2 (g_{ij}(r) - 1) L(r) dr\)
-
Weighted partial structure factor: \(W_{ij} A_{ij}(Q)\):
get_weighted_partial_structure_factor -
Normalized total-scattering structure factor: \(S(Q)\):
get_structure_factor- \(S(Q) = \frac{\sum_{i,j=1}^{n} W_{ij}A_{ij}(Q)}{(\sum_{i=1}^{n} c_{i} \bar b_{i})^2}\)
- \(S(Q) = \frac{\sum_{i,j=1}^{n} W_{ij}A_{ij}(Q)}{(\sum_{i=1}^{n} c_{i} \bar b_{i})^2}\)
-
Calculate the running coordination number for a specific pair of elements:
get_N_running- \(N(r) = \int_{0}^{r} 4 \pi r^2 \rho_{j} g_{ij}(r) dr\)
- \(N(r) = \int_{0}^{r} 4 \pi r^2 \rho_{j} g_{ij}(r) dr\)
-
For \(G(r)\) and \(S(Q)\), both neutron and X-ray scattering versions are available.
- Weighting factor for neutron diffraction: \(W_{ij} = c_{i} \bar b_{i} c_{j} \bar b_{j}\)
- Weighting factor for X-ray diffraction: \(W_{ij}(Q) = c_{i}f_{i}(Q) c_{j}f_{j}(Q)\)
- Weighting factor for neutron diffraction: \(W_{ij} = c_{i} \bar b_{i} c_{j} \bar b_{j}\)
Calculations are based on 'Keen, David A. "A comparison of various commonly used correlation functions for describing total scattering." Applied Crystallography 34, no. 2 (2001): 172-177.'
Scattering
Class for calculating scattering functions from glass structures.
Source code in src/vitrum/scattering.py
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 | |
__init__(atoms, qmin=0.5, qmax=20.0, rrange=None, nbin=500, neutron_scattering_coef=None, x_ray_scattering_coef=None, disable_progress=False, use_neighborhood=False)
Initializes a new instance of the class with the given atoms.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
atoms
|
Union[List[Atoms], Atoms]
|
A list of Atoms objects or a single Atoms object. |
required |
qmin
|
float
|
The minimum q-value to use. Defaults to 0.5. |
0.5
|
qmax
|
float
|
The maximum q-value to use. Defaults to 20. |
20.0
|
rrange
|
float
|
The range of r-values to use. If None, defaults to min(cell_dim)/2. |
None
|
nbin
|
int
|
The number of bins to use. Defaults to 500. |
500
|
neutron_scattering_coef
|
List[float]
|
A list of custom neutron scattering lengths. Defaults to None. If None, the default coefficients from Neutron News, Vol. 3, No. 3, 1992, pp. 29-37 are used. |
None
|
x_ray_scattering_coef
|
ndarray
|
A list of custom x-ray scattering coefficients. Defaults to None. If None, the default coefficients from International Tables for Crystallography (2006). Vol. C. ch. 6.1, pp. 554-595 are used. |
None
|
disable_progress
|
bool
|
Whether to disable the progress bar. Defaults to False. |
False
|
Source code in src/vitrum/scattering.py
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 | |
calculate_partial_pdfs()
Calculate partial PDFs for all pairs from full distance matrix. Scales as O(N^2) with number of atoms, so may be slow for large systems, can be more efficient when using large cutoffs.
Returns:
| Type | Description |
|---|---|
ndarray
|
np.ndarray: Array of partial PDFs. |
Source code in src/vitrum/scattering.py
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 | |
calculate_partial_pdfs_neighborhood()
Calculate partial PDFs using O(N) neighbor lists
Returns:
| Type | Description |
|---|---|
|
np.ndarray: Array of partial PDFs. |
Source code in src/vitrum/scattering.py
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 | |
get_N_running(pair)
Calculate the running coordination number for a specific pair of elements.
This is the integral of the partial RDF up to distance r: N(r) = Integral(4 * pi * rho_j * g_ij(r) * r^2 dr)
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
pair
|
Tuple[str, str]
|
Tuple of atomic symbols (e.g., ("Si", "O")). |
required |
Returns:
| Type | Description |
|---|---|
ndarray
|
np.ndarray: The running coordination number as a function of r. |
Source code in src/vitrum/scattering.py
444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 | |
get_T_r_pdf(type='neutron', broaden=False)
Calculate the total correlation function T(r).
T(r) = 4 * pi * r * rho_0 * g(r) where rho_0 is the average number density.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
type
|
str
|
The type of scattering ("neutron" or "xray"). Defaults to "neutron". |
'neutron'
|
broaden
|
Union[bool, int, float]
|
Broadening parameter. Defaults to False. |
False
|
Returns:
| Type | Description |
|---|---|
ndarray
|
np.ndarray: The T(r) function values. |
Source code in src/vitrum/scattering.py
420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 | |
get_partial_pdf(pair)
Get the partial probability density function (PDF) of a given pair of target atoms.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
pair
|
Tuple[str, str]
|
A tuple of two elements representing the target atoms. Example: ('Si', 'O') |
required |
Returns:
| Type | Description |
|---|---|
ndarray
|
np.ndarray: An array of shape (nbin,) containing the PDF values. |
Source code in src/vitrum/scattering.py
237 238 239 240 241 242 243 244 245 246 247 | |
get_partial_structure_factor(target_atoms, lorch=False)
Calculate the partial structure factor for a given target atoms within a specified range.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
target_atoms
|
Tuple[str, str]
|
A tuple of two elements representing the target atoms. |
required |
lorch
|
bool
|
If True, apply Lorch correction to the structure factor. |
False
|
Returns:
| Type | Description |
|---|---|
ndarray
|
np.ndarray: An array of shape (nbin,) containing the partial structure factor. |
Source code in src/vitrum/scattering.py
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 | |
get_reduced_pdf(type='neutron', broaden=False)
Get reduced PDF G(r).
Source code in src/vitrum/scattering.py
436 437 438 439 440 441 442 | |
get_structure_factor(type='neutron', lorch=False)
Calculate the total structure factor.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
type
|
str
|
The type of structure factor to calculate. Defaults to "neutron". |
'neutron'
|
lorch
|
bool
|
whether to apply lorch correction. |
False
|
Returns:
| Type | Description |
|---|---|
ndarray
|
np.ndarray: An array of shape (nbin,) containing the total structure factor. |
Source code in src/vitrum/scattering.py
397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 | |
get_total_rdf(type='neutron', broaden=False)
Calculate the total RDF for a given number of bins and range.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
type
|
str
|
The type of structure factor to calculate. Defaults to "neutron". |
'neutron'
|
broaden
|
Union[bool, int, float]
|
If True, apply Gaussian broadening to the RDF. If a number, specify the maximum Q value for broadening. Defaults to False. |
False
|
Returns:
| Type | Description |
|---|---|
ndarray
|
np.ndarray: An array of shape (nbin,) containing the total RDF values. |
Raises:
| Type | Description |
|---|---|
ValueError
|
If type is invalid or broaden is invalid. |
Source code in src/vitrum/scattering.py
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 | |
get_weighted_partial_structure_factors(type='neutron', lorch=False)
Calculate weighted partial structure factors W_ij * S_ij(Q) for all unique element pairs.
Weights follow the same definition as get_structure_factor(): neutron: W_ij = c_ib_i * c_jb_j / (sum_k c_kb_k)^2 xray: W_ij(Q) = c_if_i(Q) * c_jf_j(Q) / (sum_k c_kf_k(Q))^2
Cross terms (i != j) are merged: S_ij = S_ji, so their weights are multiplied by 2 and only one label (e.g. "Si-O") is returned.
The sum of all weighted partials equals get_structure_factor(type=type).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
type
|
str
|
Weighting scheme, "neutron" or "xray". Defaults to "neutron". |
'neutron'
|
lorch
|
bool
|
If True, apply Lorch modification function to reduce truncation ripples. Passed through to get_partial_structure_factor(). Defaults to False. |
False
|
Returns:
| Type | Description |
|---|---|
Tuple[Dict[str, ndarray], ndarray]
|
Tuple[Dict[str, np.ndarray], np.ndarray]: - partials: dict mapping pair label (e.g. "Si-O") to W_ij * S_ij(Q), shape (nbin,). - total_sq: sum of all weighted partials, shape (nbin,). Equivalent to get_structure_factor(type=type). |
Source code in src/vitrum/scattering.py
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 | |
gaussian_broadening(g_r, r, Q_max)
Broaden the RDF using a Gaussian convolution.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
g_r
|
ndarray
|
The RDF values. |
required |
r
|
ndarray
|
The r values. |
required |
Q_max
|
float
|
The maximum Q value. |
required |
Returns:
| Type | Description |
|---|---|
ndarray
|
np.ndarray: Broadened RDF. |
Source code in src/vitrum/scattering.py
19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 | |