kups.core.unitcell
¶
Periodic unit cell representations for molecular simulations.
Defines a UnitCell protocol and two concrete implementations with minimal stored data:
- TriclinicUnitCell: 6 DOF (lower-triangular elements)
- OrthorhombicUnitCell: 3 DOF (lengths)
All derived quantities (lattice vectors, volume, inverse) are computed on demand
from the stored parameters. Lattice vectors follow row convention:
r_real = r_frac @ lattice_vectors.
BoundaryCondition
¶
Bases: Protocol
Trait: knows how to handle spatial boundaries.
Any simulation domain satisfies this — from vacuum (identity wrap) to fully periodic unit cells. Code that only needs wrapping accepts this.
Source code in src/kups/core/unitcell.py
CoordinateSpace
¶
Bases: Enum
Enumeration for coordinate systems.
Attributes:
| Name | Type | Description |
|---|---|---|
REAL |
Cartesian coordinates in Angstroms |
|
FRACTIONAL |
Scaled coordinates in [0, 1) relative to lattice vectors |
Source code in src/kups/core/unitcell.py
OrthorhombicUnitCell
¶
Bases: Sliceable
Orthogonal unit cell with 3 degrees of freedom.
Exploits the diagonal structure for cheaper volume, inverse, and wrap operations compared to the general triclinic path.
Attributes:
| Name | Type | Description |
|---|---|---|
lengths |
Array
|
Box side lengths |
Source code in src/kups/core/unitcell.py
TriclinicMap
¶
TriclinicUnitCell
¶
Bases: Sliceable
General triclinic unit cell with 6 degrees of freedom.
Stores the 6 independent elements of the lower-triangular lattice matrix. Lattice vectors are a linear function of these parameters, making them suitable for gradient-based optimization.
Attributes:
| Name | Type | Description |
|---|---|---|
tril |
Array
|
Lower-triangular elements |
Example
Source code in src/kups/core/unitcell.py
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 | |
from_lengths_and_angles(lengths, angles)
classmethod
¶
Construct from crystallographic parameters.
Builds the lower-triangular lattice matrix from lengths and angles, then stores the 6 independent elements.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
lengths
|
Array
|
Lattice lengths |
required |
angles
|
Array
|
Lattice angles |
required |
Returns:
| Type | Description |
|---|---|
TriclinicUnitCell
|
TriclinicUnitCell with tril derived from the parameters. |
Source code in src/kups/core/unitcell.py
from_matrix(vecs)
classmethod
¶
Construct from a lower-triangular lattice matrix.
Extracts the 6 independent elements from the lower triangle.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
vecs
|
Array
|
Lower-triangular lattice vectors as rows, shape |
required |
Returns:
| Type | Description |
|---|---|
TriclinicUnitCell
|
TriclinicUnitCell with the 6 independent elements. |
Source code in src/kups/core/unitcell.py
UnitCell
¶
Bases: BoundaryCondition, Protocol
3D lattice geometry with boundary behavior. Extends BoundaryCondition.
Adds lattice vectors, volume, and other geometric properties to the base boundary condition trait. Ewald, neighbor lists, and stress calculations require this.
Source code in src/kups/core/unitcell.py
Vacuum
¶
Non-periodic domain with no lattice geometry.
Satisfies BoundaryCondition but not UnitCell. Wrap is identity.
Source code in src/kups/core/unitcell.py
make_supercell(cell, multiplicities, to_replicate, to_shift)
¶
Replicate a unit cell, clamping non-periodic axes to 1.
Source code in src/kups/core/unitcell.py
min_multiplicity(cell, cutoff)
¶
Minimum supercell replication per axis for a given cutoff.
Returns 1 for non-periodic axes (no replication needed).
Source code in src/kups/core/unitcell.py
to_lower_triangular(vecs)
¶
Convert arbitrary lattice vectors to lower-triangular form via QR decomposition.
Decomposes the input into a lower-triangular matrix (the canonical cell representation) and an orthogonal rotation that maps coordinates from the original frame into the triclinic frame.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
vecs
|
Array
|
Lattice vectors as rows of a 3x3 matrix, shape |
required |
Returns:
| Type | Description |
|---|---|
tuple[Array, TriclinicMap]
|
Tuple of (lower_triangular_vectors, coordinate_rotation_fn):
- lower_triangular_vectors: Lower-triangular 3x3 lattice matrix.
- coordinate_rotation_fn: Maps |