kups.core.utils.position
¶
Utilities for computing particle positions and center of mass in periodic systems.
This module provides functions for handling particle positions under periodic boundary conditions, including center-of-mass calculations for indexed particle groups.
center_of_mass(particles, unitcells)
¶
Compute center of mass for indexed particle groups.
Calculates the center of mass for each group of particles defined by group index, properly handling periodic boundary conditions. The computation ensures that wrapped particles are unwrapped relative to a reference particle in each group before averaging.
Warning
Assumes each molecular structure is smaller than half the unit cell size. Molecules spanning more than half the box may yield incorrect results.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
particles
|
Table[ParticleId, P]
|
Indexed particles, optionally supporting |
required |
unitcells
|
UnitCell
|
Unit cell(s) defining periodic boundary conditions. Must have one unit cell per group. |
required |
Returns:
| Type | Description |
|---|---|
Array
|
Shape |
Source code in src/kups/core/utils/position.py
to_absolute_positions(particles, unitcells, 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, applying
periodic boundary conditions.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
particles
|
Table[ParticleId, P]
|
Indexed particles with relative positions and group index. |
required |
unitcells
|
UnitCell
|
Unit cell(s) defining periodic boundaries. |
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, unitcells, 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, properly accounting for periodic boundary conditions.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
particles
|
Table[ParticleId, P]
|
Indexed particles with position and group index data. Supports
|
required |
unitcells
|
UnitCell
|
Unit cell(s) defining periodic boundaries. |
required |
center_of_masses
|
Array | None
|
Optional precomputed centers of mass. If |
None
|
Returns:
| Type | Description |
|---|---|
Array
|
Shape |