atomlib.cell
Crystallographic unit cell.
This module defines HasCell
and the concrete Cell
,
the core types for dealing with crystallographic unit cells and
their associated coordinate frames.
CoordinateFrame
module-attribute
CoordinateFrame: TypeAlias = Literal[
"cell",
"cell_frac",
"cell_box",
"ortho",
"ortho_frac",
"ortho_box",
"linear",
"local",
"global",
]
A coordinate frame to use.
cell
: Real-space units along crystal axescell_frac
: Fraction of unit cellscell_box
: Fraction of cell boxortho
: Real-space units along orthogonal cellortho_frac
: Fraction of orthogonal cellortho_box
: Fraction of orthogonal boxlinear
: Angstroms in local coordinate system (without affine transformation)local
: Angstroms in local coordinate system (with affine transformation)global
: Angstroms in global coordinate system (with all transformations)
For more information, see the documentation at Coordinate systems,
or the example notebook at examples/coords.ipynb
.
HasCell
Source code in atomlib/cell.py
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 |
|
affine
property
affine: AffineTransform3D
Affine transformation. Holds transformation from 'ortho' to 'local' coordinates, including rotation away from the standard crystal orientation.
ortho
property
ortho: LinearTransform3D
Orthogonalization transformation. Skews but does not scale the crystal axes to cartesian axes.
metric
property
metric: LinearTransform3D
Cell metric tensor
Returns the dot product between every combination of basis vectors.
:math:\mathbf{a} \cdot \mathbf{b} = a_i M_ij b_j
pbc
property
Flags indicating the presence of periodic boundary conditions along each axis.
ortho_size
property
Return size of orthogonal unit cell.
Equivalent to the diagonal of the orthogonalization matrix.
box_size
property
Return size of the cell box.
Equivalent to self.n_cells * self.cell_size
.
get_cell
abstractmethod
get_cell() -> Cell
with_cell
abstractmethod
get_transform
get_transform(
frame_to: Optional[CoordinateFrame] = None,
frame_from: Optional[CoordinateFrame] = None,
) -> AffineTransform3D
In the two-argument form, get the transform to frame_to
from frame_from
.
In the one-argument form, get the transform from local coordinates to 'frame'.
Source code in atomlib/cell.py
corners
corners(frame: CoordinateFrame = 'local') -> ndarray
bbox_cell
bbox_cell(frame: CoordinateFrame = 'local') -> BBox3D
Return the bounding box of the cell box in the given coordinate system.
is_orthogonal
is_orthogonal_in_local
Returns whether this cell is orthogonal and aligned with the local coordinate system.
Source code in atomlib/cell.py
to_ortho
to_ortho() -> AffineTransform3D
transform_cell
transform_cell(
transform: AffineTransform3D,
frame: CoordinateFrame = "local",
) -> HasCellT
Apply the given transform to the unit cell, and return a new Cell
.
The transform is applied in coordinate frame 'frame'.
Orthogonal and affine transformations are applied to the affine matrix component,
while skew and scaling is applied to the orthogonalization matrix/cell_size.
Source code in atomlib/cell.py
strain_orthogonal
strain_orthogonal() -> HasCellT
Orthogonalize using strain.
Strain is applied such that the x-axis remains fixed, and the y-axis remains in the xy plane. For small displacements, no hydrostatic strain is applied (volume is conserved).
Source code in atomlib/cell.py
repeat
Tile the cell by n
in each dimension.
Source code in atomlib/cell.py
explode
explode() -> HasCellT
Materialize repeated cells as one supercell.
Source code in atomlib/cell.py
explode_z
explode_z() -> HasCellT
Materialize repeated cells as one supercell in z.
Source code in atomlib/cell.py
crop
crop(
x_min: float = -inf,
x_max: float = inf,
y_min: float = -inf,
y_max: float = inf,
z_min: float = -inf,
z_max: float = inf,
*,
frame: CoordinateFrame = "local"
) -> HasCellT
Crop self
to the given extents. For a non-orthogonal
cell, this must be specified in cell coordinates. This
function implicity explode
s the cell as well.
Source code in atomlib/cell.py
change_transform
change_transform(
transform: AffineTransform3D,
frame_to: Optional[CoordinateFrame] = None,
frame_from: Optional[CoordinateFrame] = None,
) -> AffineTransform3D
change_transform(
transform: Transform3D,
frame_to: Optional[CoordinateFrame] = None,
frame_from: Optional[CoordinateFrame] = None,
) -> Transform3D
change_transform(
transform: Transform3D,
frame_to: Optional[CoordinateFrame] = None,
frame_from: Optional[CoordinateFrame] = None,
) -> Transform3D
Coordinate-change a transformation from frame_from
into frame_to
.
Source code in atomlib/cell.py
assert_equal
assert_equal(other: Any)
Source code in atomlib/cell.py
Cell
dataclass
Bases: HasCell
Internal class for representing the coordinate systems of a crystal.
The overall transformation from crystal coordinates to real-space coordinates is
is split into four transformations, applied from bottom to top. First is n_cells
,
which scales from fractions of a unit cell to fractions of a supercell. Next is
cell_size
, which scales to real-space units. ortho
is an orthogonalization
matrix, a det = 1 upper-triangular matrix which transforms crystal axes to
an orthogonal coordinate system. Finally, affine
contains any remaining
transformations to the local coordinate system, which atoms are stored in.
Source code in atomlib/cell.py
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 |
|
affine
property
affine: AffineTransform3D
Affine transformation. Holds transformation from 'ortho' to 'local' coordinates, including rotation away from the standard crystal orientation.
ortho
property
ortho: LinearTransform3D
Orthogonalization transformation. Skews but does not scale the crystal axes to cartesian axes.
metric
property
metric: LinearTransform3D
Cell metric tensor
Returns the dot product between every combination of basis vectors.
:math:\mathbf{a} \cdot \mathbf{b} = a_i M_ij b_j
pbc
property
Flags indicating the presence of periodic boundary conditions along each axis.
ortho_size
property
Return size of orthogonal unit cell.
Equivalent to the diagonal of the orthogonalization matrix.
box_size
property
Return size of the cell box.
Equivalent to self.n_cells * self.cell_size
.
get_transform
get_transform(
frame_to: Optional[CoordinateFrame] = None,
frame_from: Optional[CoordinateFrame] = None,
) -> AffineTransform3D
In the two-argument form, get the transform to frame_to
from frame_from
.
In the one-argument form, get the transform from local coordinates to 'frame'.
Source code in atomlib/cell.py
corners
corners(frame: CoordinateFrame = 'local') -> ndarray
bbox_cell
bbox_cell(frame: CoordinateFrame = 'local') -> BBox3D
Return the bounding box of the cell box in the given coordinate system.
is_orthogonal
is_orthogonal_in_local
Returns whether this cell is orthogonal and aligned with the local coordinate system.
Source code in atomlib/cell.py
to_ortho
to_ortho() -> AffineTransform3D
transform_cell
transform_cell(
transform: AffineTransform3D,
frame: CoordinateFrame = "local",
) -> HasCellT
Apply the given transform to the unit cell, and return a new Cell
.
The transform is applied in coordinate frame 'frame'.
Orthogonal and affine transformations are applied to the affine matrix component,
while skew and scaling is applied to the orthogonalization matrix/cell_size.
Source code in atomlib/cell.py
strain_orthogonal
strain_orthogonal() -> HasCellT
Orthogonalize using strain.
Strain is applied such that the x-axis remains fixed, and the y-axis remains in the xy plane. For small displacements, no hydrostatic strain is applied (volume is conserved).
Source code in atomlib/cell.py
repeat
Tile the cell by n
in each dimension.
Source code in atomlib/cell.py
explode
explode() -> HasCellT
Materialize repeated cells as one supercell.
Source code in atomlib/cell.py
explode_z
explode_z() -> HasCellT
Materialize repeated cells as one supercell in z.
Source code in atomlib/cell.py
crop
crop(
x_min: float = -inf,
x_max: float = inf,
y_min: float = -inf,
y_max: float = inf,
z_min: float = -inf,
z_max: float = inf,
*,
frame: CoordinateFrame = "local"
) -> HasCellT
Crop self
to the given extents. For a non-orthogonal
cell, this must be specified in cell coordinates. This
function implicity explode
s the cell as well.
Source code in atomlib/cell.py
change_transform
change_transform(
transform: AffineTransform3D,
frame_to: Optional[CoordinateFrame] = None,
frame_from: Optional[CoordinateFrame] = None,
) -> AffineTransform3D
change_transform(
transform: Transform3D,
frame_to: Optional[CoordinateFrame] = None,
frame_from: Optional[CoordinateFrame] = None,
) -> Transform3D
change_transform(
transform: Transform3D,
frame_to: Optional[CoordinateFrame] = None,
frame_from: Optional[CoordinateFrame] = None,
) -> Transform3D
Coordinate-change a transformation from frame_from
into frame_to
.
Source code in atomlib/cell.py
assert_equal
assert_equal(other: Any)
Source code in atomlib/cell.py
get_cell
get_cell() -> Cell
with_cell
from_unit_cell
staticmethod
from_unit_cell(
cell_size: VecLike,
cell_angle: Optional[VecLike] = None,
n_cells: Optional[VecLike] = None,
pbc: Optional[VecLike] = None,
)
Source code in atomlib/cell.py
from_ortho
staticmethod
from_ortho(
ortho: AffineTransform3D,
n_cells: Optional[VecLike] = None,
pbc: Optional[VecLike] = None,
)
Source code in atomlib/cell.py
cell_to_ortho
cell_to_ortho(
cell_size: VecLike, cell_angle: Optional[VecLike] = None
) -> LinearTransform3D
Get orthogonalization transform from unit cell parameters (which turns fractional cell coordinates into real-space coordinates). .
Source code in atomlib/cell.py
ortho_to_cell
ortho_to_cell(
ortho: LinearTransform3D,
) -> Tuple[Vec3, Vec3]
Get unit cell parameters (cell_size, cell_angle)
from orthogonalization transform.
Source code in atomlib/cell.py
plane_to_zone
plane_to_zone(
metric: LinearTransform3D,
plane: VecLike,
reduce: bool = True,
) -> Vec3
Return the zone axis associated with a given crystallographic plane.
If reduce
is True
, call reduce_vec
before returning. Otherwise,
return a unit vector.
Source code in atomlib/cell.py
zone_to_plane
zone_to_plane(
metric: LinearTransform3D,
zone: VecLike,
reduce: bool = True,
) -> Vec3
Return the crystallographic plane associated with a given zone axis.
If reduce
is True, call reduce_vec
before returning. Otherwise,
return a unit vector.