utils¶
Utility functions to help the conversion functions along.
Most of these functions rely on the NumPy library.
cell_to_cellpar(cell, radians=False)
¶
Returns the cell parameters [a, b, c, alpha, beta, gamma]
.
Angles are in degrees unless radian=True
is used.
Note
Based on ASE code.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
cell
|
tuple[Vector3D, Vector3D, Vector3D]
|
A Cartesian 3x3 cell. This equates to the
|
required |
radians
|
bool
|
Use radians instead of degrees (default) for angles. |
False
|
Returns:
Type | Description |
---|---|
list[float]
|
The unit cell parameters as a |
Source code in optimade/adapters/structures/utils.py
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 |
|
cellpar_to_cell(cellpar, ab_normal=(0, 0, 1), a_direction=None)
¶
Return a 3x3 cell matrix from cellpar=[a,b,c,alpha,beta,gamma]
.
Angles must be in degrees.
The returned cell is orientated such that a and b
are normal to ab_normal
and a is parallel to the projection of
a_direction
in the a-b plane.
Default a_direction
is (1,0,0), unless this is parallel to
ab_normal
, in which case default a_direction
is (0,0,1).
The returned cell has the vectors va, vb and vc along the rows. The
cell will be oriented such that va and vb are normal to ab_normal
and va will be along the projection of a_direction
onto the a-b
plane.
Example
cell = cellpar_to_cell([1, 2, 4, 10, 20, 30], (0, 1, 1), (1, 2, 3)) np.round(cell, 3) array([[ 0.816, -0.408, 0.408], [ 1.992, -0.13 , 0.13 ], [ 3.859, -0.745, 0.745]])
Note
Direct copy of ASE code.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
cellpar
|
list[float]
|
The unit cell parameters as a Note: The angles must be given in degrees. |
required |
ab_normal
|
tuple[int, int, int]
|
Unit vector normal to the ab-plane. |
(0, 0, 1)
|
a_direction
|
tuple[int, int, int] | None
|
Unit vector defining the a-direction (default: |
None
|
Returns:
Type | Description |
---|---|
list[Vector3D]
|
A Cartesian 3x3 cell. |
list[Vector3D]
|
This should equate to the |
list[Vector3D]
|
|
Source code in optimade/adapters/structures/utils.py
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 |
|
elements_ratios_from_species_at_sites(species_at_sites)
¶
Compute the OPTIMADE elements_ratios
field from species_at_sites
in the case where species_at_sites
refers
to sites wholly occupied by the given elements, e.g., not arbitrary species labels or with partial/mixed occupancy.
Source code in optimade/adapters/structures/utils.py
361 362 363 364 365 366 367 368 369 |
|
fractional_coordinates(cell, cartesian_positions)
¶
Returns fractional coordinates and wraps coordinates to [0,1[
.
Note
Based on ASE code.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
cell
|
tuple[Vector3D, Vector3D, Vector3D]
|
A Cartesian 3x3 cell. This equates to the
|
required |
cartesian_positions
|
list[Vector3D]
|
A list of cartesian atomic positions. This equates to the
|
required |
Returns:
Type | Description |
---|---|
list[Vector3D]
|
A list of fractional coordinates for the atomic positions. |
Source code in optimade/adapters/structures/utils.py
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 |
|
pad_cell(lattice_vectors, padding=None)
¶
Turn any null
/None
values into a float
in given tuple
of
lattice_vectors
.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
lattice_vectors
|
tuple[Vector3D, Vector3D, Vector3D]
|
A 3x3 cartesian cell. This is the
|
required |
padding
|
float | None
|
A value with which |
None
|
Returns:
Type | Description |
---|---|
tuple
|
The possibly redacted/padded |
tuple
|
the value has been redacted/padded or not, i.e., whether it contained |
tuple
|
values. |
Source code in optimade/adapters/structures/utils.py
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 |
|
scaled_cell(cell)
¶
Return a scaled 3x3 cell from cartesian 3x3 cell (lattice_vectors
).
This 3x3 matrix can be used to calculate the fractional coordinates from the cartesian_site_positions.
This is based on PDB's method of calculating SCALE from CRYST data. For more info, see this site.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
cell
|
tuple[Vector3D, Vector3D, Vector3D]
|
A Cartesian 3x3 cell. This equates to the
|
required |
Returns:
Type | Description |
---|---|
tuple[Vector3D, Vector3D, Vector3D]
|
A scaled 3x3 cell. |
Source code in optimade/adapters/structures/utils.py
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 |
|
species_from_species_at_sites(species_at_sites)
¶
When a list of species dictionaries is not provided, this function can be used to infer the species from the provided species_at_sites.
In this use case, species_at_sites is assumed to provide a list of element symbols, and refers to situations with no mixed occupancy, i.e., the constructed species list will contain all unique species with concentration equal to 1 and the species_at_site tag will be used as the chemical symbol.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
species_at_sites
|
list[str]
|
The list found under the species_at_sites field. |
required |
Returns:
Type | Description |
---|---|
list[Species]
|
An OPTIMADE species list. |
Source code in optimade/adapters/structures/utils.py
336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 |
|
unit_vector(x)
¶
Return a unit vector in the same direction as x
.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
x
|
Vector3D
|
A three-dimensional vector. |
required |
Returns:
Type | Description |
---|---|
Vector3D
|
A unit vector in the same direction as |
Source code in optimade/adapters/structures/utils.py
146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 |
|