kups.core.utils.position
¶
Utilities for computing particle positions and center of mass.
Functions in this module honor the cell's per-axis periodic mask via
cell.wrap — periodic axes fold into the primary cell, non-periodic
axes pass through unchanged. The same code path covers fully-periodic
crystals, vacuum clusters, and slab / wire geometries.
center_of_mass(particles, cells)
¶
Compute center of mass for indexed particle groups.
Calculates the center of mass for each group of particles defined by
group index, honoring the cell's per-axis periodic mask. The
computation ensures that wrapped particles are unwrapped relative to a
reference particle in each group before averaging.
Warning
On periodic axes, assumes each molecular structure is smaller than half the cell size. Structures spanning more than half the box may yield incorrect results.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
particles
|
Table[ParticleId, P]
|
Indexed particles, optionally supporting |
required |
cells
|
Cell
|
Cell(s) carrying lattice geometry and per-axis periodicity. Must have one cell per group. |
required |
Returns:
| Type | Description |
|---|---|
Array
|
Shape |
Source code in src/kups/core/utils/position.py
to_absolute_positions(particles, cells, center_of_masses)
¶
Calculate absolute positions from relative positions and group COMs.
Inverse operation of to_relative_positions. Converts positions defined
relative to group centers of mass back to absolute coordinates, honoring
the cell's per-axis periodic mask via wrap (identity on
non-periodic axes).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
particles
|
Table[ParticleId, P]
|
Indexed particles with relative positions and group index. |
required |
cells
|
Cell
|
Cell(s) carrying lattice geometry and per-axis periodicity. |
required |
center_of_masses
|
Array
|
Centers of mass for each group, shape |
required |
Returns:
| Type | Description |
|---|---|
Array
|
Shape |
Source code in src/kups/core/utils/position.py
to_relative_positions(particles, cells, center_of_masses=None)
¶
Calculate particle positions relative to their group's center of mass.
Transforms absolute particle positions to positions relative to each
group's center of mass, honoring the cell's per-axis periodic mask
(periodic axes wrap; non-periodic axes pass through unchanged).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
particles
|
Table[ParticleId, P]
|
Indexed particles with position and group index data. Supports
|
required |
cells
|
Cell
|
Cell(s) carrying lattice geometry and per-axis periodicity. |
required |
center_of_masses
|
Array | None
|
Optional precomputed centers of mass. If |
None
|
Returns:
| Type | Description |
|---|---|
Array
|
Shape |