Utility functions:
This is an overview of various miscellaneous utility functions, useful for different purposes when doing calculations with vitrum.
apply_strain_to_structure(structure, deformations)
Apply strain(s) to input structure and return transformation(s) as list.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
structure
|
.Structure
|
Input structure to apply strain to |
required |
deformations
|
list[.Deformation]
|
A list of deformations to apply independently to the input structure, in anticipation of performing an EOS fit. Deformations should be of the form of a 3x3 matrix, e.g., [[1.2, 0., 0.], [0., 1.2, 0.], [0., 0., 1.2]] or ((1.2, 0., 0.), (0., 1.2, 0.), (0., 0., 1.2)) |
required |
Returns:
| Name | Type | Description |
|---|---|---|
list |
list
|
A list of .TransformedStructure objects corresponding to the list of input deformations. |
Source code in src/vitrum/utility.py
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 | |
correct_atom_types(atoms_list, atom_to_type_map)
Correct the atom types in a list of Atoms objects.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
atoms_list
|
list of Atoms objects
|
The list of Atoms objects to correct. |
required |
atom_to_type_map
|
dict
|
A dictionary mapping atomic numbers to atom types. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
atoms_list |
list of Atoms objects
|
The corrected list of Atoms objects. |
Source code in src/vitrum/utility.py
305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 | |
dimer_checker(atoms, bond_length=2.0, num_allowed=2)
Check for the presence of dimers (e.g., O2, N2, F2, Cl2, Br2, I2) in the structure.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
atoms
|
Atoms
|
The ASE Atoms object to check. |
required |
bond_length
|
float
|
The cutoff distance to define a bond. Defaults to 2.0. |
2.0
|
num_allowed
|
int
|
The maximum number of allowed dimers before returning True. Defaults to 2. |
2
|
Returns:
| Name | Type | Description |
|---|---|---|
bool |
True if the number of dimers exceeds |
Source code in src/vitrum/utility.py
591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 | |
find_min_after_peak(padf)
Find the index of the first local minimum after the first peak in a function. Useful for determining cutoffs from PDFs.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
padf
|
ndarray
|
The probability density function or similar array. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
int |
The index of the minimum. |
Source code in src/vitrum/utility.py
289 290 291 292 293 294 295 296 297 298 299 300 301 302 | |
get_LAMMPS_dump_timesteps(filename)
Retrieves the timesteps from a LAMMPS dump file.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
filename
|
str
|
The path to the LAMMPS dump file. |
required |
Returns:
| Type | Description |
|---|---|
|
List[int]: A list of timesteps extracted from the file. |
Source code in src/vitrum/utility.py
233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 | |
get_average_volume_convex_hull(composition, MP_API_KEY=None)
Get the average volume per atom from the convex hull on Materials Project.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
composition
|
Composition
|
The composition to query. |
required |
MP_API_KEY
|
str
|
Materials Project API Key. |
None
|
Returns:
| Name | Type | Description |
|---|---|---|
float |
Average volume per atom. |
Source code in src/vitrum/utility.py
99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 | |
get_dist(list, cell)
Calculate the pairwise distance matrix for atoms in a periodic simulation box.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
list
|
ndarray
|
Atomic positions (N x 3). |
required |
cell
|
ndarray
|
Cell dimensions (3,). Assumes an orthorhombic cell. |
required |
Returns:
| Type | Description |
|---|---|
|
np.ndarray: Symmetric distance matrix (N x N) containing distances between all atom pairs. |
Source code in src/vitrum/utility.py
441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 | |
get_dist_numba(pos, cell)
Calculate the distance matrix between atoms using Numba for performance.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
pos
|
ndarray
|
Array of atomic positions (N x 3). |
required |
cell
|
ndarray
|
Cell dimensions (3,). Assumes an orthorhombic cell (lx, ly, lz). |
required |
Returns:
| Type | Description |
|---|---|
|
np.ndarray: Symmetric distance matrix (N x N). |
Source code in src/vitrum/utility.py
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 | |
get_high_low_displacement_index(initial_state, current_state, target_atom, percentage=0.25)
Calculates the indices of the atoms with the high and low displacements between an initial and current state.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
initial_state
|
Atoms
|
The initial state of the system. |
required |
current_state
|
Atoms
|
The current state of the system. |
required |
target_atom
|
str or int
|
The chemical symbol or atomic number of the target atom. |
required |
percentage
|
float
|
The percentage of the highest and lowest displacements to consider. Defaults to 0.25. |
0.25
|
Returns:
| Name | Type | Description |
|---|---|---|
list |
A list of two elements, where the first element is the index of the atoms with the highest displacements and the second element is the index of the atoms with the lowest displacements. |
Source code in src/vitrum/utility.py
325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 | |
get_random_packed(composition, target_atoms=100, min_distance=None, radii_scaling=1.0, volume_scaling=1.0, vol_per_atom_source='mp', datatype='ase', db_kwargs=None, density=None, seed=None, side_ratios=[1, 1, 1], **kwargs)
Generate a random packed structure based on the given composition.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
composition
|
(str, dict or Composition)
|
The composition of the structure. |
required |
density
|
float
|
The target density of the structure (in g/cm^3). If not provided, the volume per atom is estimated using the Materials Project API. |
None
|
target_atoms
|
int
|
The target number of atoms in the structure. Defaults to 100. |
100
|
radii_scaling
|
float
|
Scaling factor for the covalent radii of the atoms. Defaults to 1.0. |
1.0
|
volume_scaling
|
float
|
Scaling factor for the volume of the structure. Defaults to 1.0. |
1.0
|
vol_per_atom_source
|
float or str
|
The source for the volume per atom. Can be a float value or one of the following strings: "mp" (Materials Project), "icsd" (Inorganic Crystal Structure Database), "density" (use provided density), "covalent_radius" (estimate from covalent radii), or "convex_hull" (estimate from convex hull). Defaults to "mp". |
'mp'
|
datatype
|
str
|
The type of data to return. Can be "ase" for ASE format or "pymatgen" for pymatgen format. Defaults to "ase". |
'ase'
|
db_kwargs
|
dict
|
Additional keyword arguments for database access. Defaults to None. |
None
|
seed
|
int
|
The seed for random number generation. Defaults to 0. |
None
|
side_ratios
|
list
|
The side ratios for the lattice. Defaults to [1, 1, 1]. |
[1, 1, 1]
|
Returns:
| Name | Type | Description |
|---|---|---|
data |
Atoms or Structure
|
The generated random packed structure. |
Source code in src/vitrum/utility.py
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 | |
get_volume(composition, structure, vol_per_atom_source='mp', db_kwargs=None, density=None, MP_API_KEY=None)
Get the volume of the cell based on the composition and various estimation methods.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
composition
|
Union[Composition, str]
|
The composition of the material. |
required |
structure
|
dict
|
A dictionary mapping element symbols to their count in the structure. |
required |
vol_per_atom_source
|
Union[float, str]
|
Method to estimate volume per atom. Options: - "mp": Use Materials Project (requires API key). - "icsd": Use ICSD database (if available). - "density": Calculate from provided density. - "covalent_radius": Estimate from covalent radii. - "convex_hull": Estimate from convex hull on Materials Project. - float: Directly provide the volume per atom. Defaults to "mp". |
'mp'
|
db_kwargs
|
dict
|
Keyword arguments for database queries. Defaults to None. |
None
|
density
|
float
|
Density in g/cm^3. Required if vol_per_atom_source="density". Defaults to None. |
None
|
MP_API_KEY
|
str
|
Materials Project API key. Defaults to None. |
None
|
Returns:
| Name | Type | Description |
|---|---|---|
float |
The calculated total volume of the cell in Angstrom^3. |
Raises:
| Type | Description |
|---|---|
ValueError
|
If estimating from density but estimates fail, or if an unknown source is provided. |
Source code in src/vitrum/utility.py
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 | |
homogeniety_checker(atoms, grid_density, slide_steps=2, target_species='all', upper_bound=1.5, lower_bound=0.5, box_threshold=0.1, seperated_species_threshold=0.5)
Check the homogeneity of the atomic structure by analyzing atom density in grid boxes.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
atoms
|
Atoms
|
The ASE Atoms object to analyze. |
required |
grid_density
|
tuple or list
|
Number of grid divisions in x, y, z directions (nx, ny, nz). |
required |
slide_steps
|
int
|
Number of steps to slide the grid for averaging. Defaults to 2. |
2
|
target_species
|
str or list
|
Species to check. "all" checks all present species. Defaults to "all". |
'all'
|
upper_bound
|
float
|
Multiplier for average density to consider a box over-dense. Defaults to 1.5. |
1.5
|
lower_bound
|
float
|
Multiplier for average density to consider a box under-dense. Defaults to 0.5. |
0.5
|
box_threshold
|
float
|
Fraction of boxes allowed to be out of bounds before flagging a species. Defaults to 0.1. |
0.1
|
seperated_species_threshold
|
float
|
Fraction of species allowed to be phase separated before the structure is flagged. Defaults to 0.5. |
0.5
|
Returns:
| Name | Type | Description |
|---|---|---|
bool |
True if the structure is considered homogeneous, False otherwise. |
Raises:
| Type | Description |
|---|---|
ValueError
|
If no species are found in the atoms object. |
Source code in src/vitrum/utility.py
499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 | |
pdf(dist_list, volume, rrange=10, nbin=100)
Calculate the pair distribution function (PDF) of a list of distances.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
dist_list
|
ndarray
|
A 2D numpy array of distances. |
required |
volume
|
float
|
The volume of the system. |
required |
rrange
|
float
|
The range of the PDF. Defaults to 10. |
10
|
nbin
|
int
|
The number of bins. Defaults to 100. |
100
|
Returns:
| Name | Type | Description |
|---|---|---|
xval |
ndarray
|
The x values of the PDF. |
pdf |
ndarray
|
The PDF values. |
Source code in src/vitrum/utility.py
379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 | |
r_chi(function_1, function_2, x_min=0, x_max=np.inf, steps=100)
Calculate the Wright coefficient (https://doi.org/10.1016/0022-3093(93)90232-M) between two functions
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
function_1
|
dict
|
Dictionary with keys 'x' and 'y' representing the first function, usually from simulations |
required |
function_2
|
dict
|
Dictionary with keys 'x' and 'y' representing the second function, usually from experimental meassurements. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
rchi |
float
|
Wright coefficient, a measure of similarity between the two functions. |
Source code in src/vitrum/utility.py
462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 | |
unwrap_trajectory(atoms_list)
Unwraps a list of Atoms objects to remove periodic boundary crossings.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
atoms_list
|
list of Atoms objects
|
The list of Atoms objects to unwrap. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
unwrapped_atoms_list |
list of Atoms objects
|
The unwrapped list of Atoms objects. |
Source code in src/vitrum/utility.py
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 | |