Skip to content

pme

Standalone particle-mesh Ewald electrostatics for small periodic fixtures.

import mlx_atomistic.pme

class PMEConfig
def __init__(mesh_shape: tuple[int, int, int] = (32, 32, 32), alpha: float = 0.35, real_cutoff: float | None = None, assignment_order: int = 2, charge_tolerance: float = 1e-05, deconvolve_assignment: bool = True, background_policy: PMEBackgroundPolicy = 'reject_non_neutral')

Controls for the standalone PME mesh backend.

Parameters

NameTypeDefaultDescription
mesh_shapetuple[int, int, int](32, 32, 32)
alphafloat0.35
real_cutofffloat | NoneNone
assignment_orderint2
charge_tolerancefloat1e-05
deconvolve_assignmentboolTrue
background_policyPMEBackgroundPolicy'reject_non_neutral'
class PMEDiagnostics
def __init__(mesh_shape: tuple[int, int, int], assignment_order: int, alpha: float, real_cutoff: float, net_charge: float, volume: float, charge_grid_sum: float, reciprocal_modes: int, max_charge_grid_abs: float, background_policy: PMEBackgroundPolicy = 'reject_non_neutral', background_energy: float = 0.0, direct_space_policy: str = 'dense', direct_space_representation: str = 'dense', direct_space_pair_count: int | None = None, direct_space_candidate_count: int | None = None, direct_space_fallback_reason: str | None = None, plan_fingerprint: str | None = None, plan_build_count: int = 0, plan_reuse_count: int = 0, plan_setup_seconds: float = 0.0, plan_estimated_resident_bytes: int = 0, plan_backend: str | None = None, plan_device: str | None = None, plan_dtype: str | None = None)

Diagnostics emitted by one standalone PME evaluation.

Parameters

NameTypeDefaultDescription
mesh_shapetuple[int, int, int]
assignment_orderint
alphafloat
real_cutofffloat
net_chargefloat
volumefloat
charge_grid_sumfloat
reciprocal_modesint
max_charge_grid_absfloat
background_policyPMEBackgroundPolicy'reject_non_neutral'
background_energyfloat0.0
direct_space_policystr'dense'
direct_space_representationstr'dense'
direct_space_pair_countint | NoneNone
direct_space_candidate_countint | NoneNone
direct_space_fallback_reasonstr | NoneNone
plan_fingerprintstr | NoneNone
plan_build_countint0
plan_reuse_countint0
plan_setup_secondsfloat0.0
plan_estimated_resident_bytesint0
plan_backendstr | NoneNone
plan_devicestr | NoneNone
plan_dtypestr | NoneNone

Methods

def to_dict() -> dict[str, object]

Return the diagnostics as a plain JSON-serializable dict.

Returns

  • dict[str, object] — The diagnostics fields (mesh shape, alpha, cutoff, net charge, grid sums, direct-space policy, …) as a dict.
class PMEDirectSpacePolicyReport
def __init__(policy: str, representation: str, uses_shared_neighbor_policy: bool, supported: bool, real_cutoff: float, minimum_image_safe: bool, pair_count: int | None = None, compact_pair_count: int | None = None, candidate_count: int | None = None, candidate_waste_count: int | None = None, fallback_reason: str | None = None)

Execution policy selected for PME real/direct-space evaluation.

Parameters

NameTypeDefaultDescription
policystr
representationstr
uses_shared_neighbor_policybool
supportedbool
real_cutofffloat
minimum_image_safebool
pair_countint | NoneNone
compact_pair_countint | NoneNone
candidate_countint | NoneNone
candidate_waste_countint | NoneNone
fallback_reasonstr | NoneNone

Methods

def to_dict() -> dict[str, object]

Return the policy report as a plain JSON-serializable dict.

Returns

  • dict[str, object] — The policy report fields (policy, representation, support, cutoff, pair counts, fallback reason) as a dict.
class PMEExecutionPlan
def __init__(cell: Cell, *, config: PMEConfig | None = None, coulomb_constant: float = 1.0, dtype: object = mx.float32, backend: str = PME_EXECUTION_BACKEND)

Reusable cell-invariant reciprocal state for fixed-cell PME evaluation.

Parameters

NameTypeDefaultDescription
cellCellPeriodic orthorhombic cell whose reciprocal state is planned.
configPMEConfig | NoneNonePME parameters; None uses PMEConfig defaults.
coulomb_constantfloat1.0Coulomb prefactor in the configured unit system.
dtypeobjectmx.float32Reciprocal-array dtype. The current backend supports float32.
backendstrPME_EXECUTION_BACKENDPME execution backend identifier. The current backend is PME_EXECUTION_BACKEND.

Properties

  • diagnostics dict[str, object] — Return JSON-serializable setup and reuse diagnostics for this plan.

Methods

def build(cell: Cell, *, config: PMEConfig | None = None, coulomb_constant: float = 1.0, dtype: object = mx.float32, backend: str = PME_EXECUTION_BACKEND) -> PMEExecutionPlan

Build a reusable PME execution plan.

Parameters

NameTypeDefaultDescription
cellCellPeriodic orthorhombic cell whose reciprocal state is planned.
configPMEConfig | NoneNonePME parameters; None uses PMEConfig defaults.
coulomb_constantfloat1.0Coulomb prefactor in the configured unit system.
dtypeobjectmx.float32Reciprocal-array dtype. The current backend supports float32.
backendstrPME_EXECUTION_BACKENDPME execution backend identifier.

Returns

  • PMEExecutionPlan — A materialized reusable execution plan.
def rebuild(*, cell: Cell | None = None, config: PMEConfig | None = None, coulomb_constant: float | None = None, dtype: object | None = None, backend: str | None = None) -> PMEExecutionPlan

Build a distinct plan after an explicit defining-input change.

Parameters

NameTypeDefaultDescription
cellCell | NoneNoneReplacement cell; None retains the current cell.
configPMEConfig | NoneNoneReplacement configuration; None retains the current config.
coulomb_constantfloat | NoneNoneReplacement Coulomb prefactor; None retains the current value.
dtypeobject | NoneNoneReplacement reciprocal dtype; None retains the current dtype.
backendstr | NoneNoneReplacement execution backend; None retains the current backend.

Returns

  • PMEExecutionPlan — A new materialized execution plan with counters independent of this plan.
def to_dict() -> dict[str, object]

Return the plan diagnostics as a plain JSON-serializable dict.

Returns

  • dict[str, object] — Setup, fingerprint, resident-size, backend, and reuse metadata.
def validate(cell: Cell, *, config: PMEConfig | None = None, coulomb_constant: float | None = None, dtype: object = mx.float32, backend: str = PME_EXECUTION_BACKEND) -> None

Validate that requested PME inputs exactly match this plan.

Parameters

NameTypeDefaultDescription
cellCellCell requested by the evaluation.
configPMEConfig | NoneNoneRequested PME configuration; None uses this plan’s config.
coulomb_constantfloat | NoneNoneRequested Coulomb prefactor; None uses this plan’s value.
dtypeobjectmx.float32Requested reciprocal-array dtype.
backendstrPME_EXECUTION_BACKENDRequested PME execution backend.

Returns

  • None

Raises

  • PMEPlanMismatchError — If any plan-defining input differs.
  • ValueError — If an input is invalid independently of the stored plan.
class PMEPlanMismatchError(ValueError)
def __init__(mismatches: tuple[str, ...], *, expected_fingerprint: str, actual_fingerprint: str)

Raised when a PME execution plan does not match an evaluation request.

Parameters

NameTypeDefaultDescription
mismatchestuple[str, ...]
expected_fingerprintstr
actual_fingerprintstr
def assign_charges_bspline(positions: mx.array, charges: mx.array, cell: Cell, mesh_shape: tuple[int, int, int], *, assignment_order: int = 2) -> mx.array

Assign charges to a periodic mesh with cardinal B-spline weights.

Parameters

NameTypeDefaultDescription
positionsmx.arrayAtomic coordinates, shape (n_atoms, 3).
chargesmx.arrayPer-atom charges, shape (n_atoms,).
cellCellPeriodic orthorhombic cell.
mesh_shapetuple[int, int, int]Reciprocal-space mesh dimensions (nx, ny, nz).
assignment_orderint2Cardinal B-spline order (2 = cloud-in-cell). Defaults to 2.

Returns

  • mx.array — The charge density on the mesh, shape mesh_shape.

Raises

  • ValueError — If the cell is non-orthorhombic or the shapes are invalid.
def assign_charges_cic(positions: mx.array, charges: mx.array, cell: Cell, mesh_shape: tuple[int, int, int]) -> mx.array

Assign charges to a periodic mesh with cloud-in-cell weights.

Parameters

NameTypeDefaultDescription
positionsmx.arrayAtomic coordinates, shape (n_atoms, 3).
chargesmx.arrayPer-atom charges, shape (n_atoms,).
cellCellPeriodic orthorhombic cell.
mesh_shapetuple[int, int, int]Reciprocal-space mesh dimensions (nx, ny, nz).

Returns

  • mx.array — The charge density on the mesh, shape mesh_shape.

Raises

  • ValueError — If the cell is non-orthorhombic or the shapes are invalid.
def normalize_pme_background_policy(value: object) -> PMEBackgroundPolicy

Return a supported PME background-charge policy.

Parameters

NameTypeDefaultDescription
valueobjectPolicy name to normalize.

Returns

  • PMEBackgroundPolicy — A supported normalized policy string.

Raises

  • ValueError — If value is not a supported policy.
def pme_coulomb_direct_space_energy_forces(positions: mx.array, charges: mx.array, cell: Cell, *, coulomb_constant: float = 1.0, config: PMEConfig | None = None, pairs: mx.array | NeighborBlocks | None = None, plan: PMEExecutionPlan | None = None) -> tuple[mx.array, mx.array]

Evaluate only the PME real/direct-space Coulomb energy and forces.

Parameters

NameTypeDefaultDescription
positionsmx.arrayAtomic coordinates, shape (n_atoms, 3).
chargesmx.arrayPer-atom partial charges, shape (n_atoms,); charged systems require the explicit uniform-plasma background policy.
cellCellPeriodic orthorhombic Cell (triclinic is unsupported).
coulomb_constantfloat1.0Coulomb prefactor in the configured unit system. Defaults to 1.0.
configPMEConfig | NoneNonePME parameters; None uses defaults. Defaults to None.
pairsmx.array | NeighborBlocks | NoneNoneOptional real-space pairs or neighbor blocks. Defaults to None.
planPMEExecutionPlan | NoneNoneOptional reusable fixed-cell execution plan. A one-shot plan is built when omitted. Defaults to None.

Returns

  • tuple[mx.array, mx.array] — An (energy, forces) tuple: scalar real-space energy and (n_atoms, 3) forces.

Raises

  • ValueError — If shapes/cell or the configured charge policy are invalid.
def pme_coulomb_energy_forces(positions: mx.array, charges: mx.array, cell: Cell, *, coulomb_constant: float = 1.0, config: PMEConfig | None = None, direct_space_pairs: mx.array | NeighborBlocks | None = None, plan: PMEExecutionPlan | None = None) -> tuple[mx.array, mx.array, dict[str, mx.array | PMEDiagnostics]]

Evaluate neutral orthorhombic Coulomb energy and forces with PME.

Parameters

NameTypeDefaultDescription
positionsmx.arrayAtomic coordinates, shape (n_atoms, 3).
chargesmx.arrayPer-atom partial charges, shape (n_atoms,); charged systems require the explicit uniform-plasma background policy.
cellCellPeriodic orthorhombic Cell (triclinic is unsupported).
coulomb_constantfloat1.0Coulomb prefactor in the configured unit system. Defaults to 1.0.
configPMEConfig | NoneNonePME parameters; None uses defaults. Defaults to None.
direct_space_pairsmx.array | NeighborBlocks | NoneNoneOptional precomputed real-space pairs or neighbor blocks. Defaults to None.
planPMEExecutionPlan | NoneNoneOptional reusable fixed-cell execution plan. A one-shot plan is built when omitted. Defaults to None.

Returns

  • tuple[mx.array, mx.array, dict[str, mx.array | PMEDiagnostics]] — An (energy, forces, components) tuple: scalar total Coulomb energy, (n_atoms, 3) forces, and a components dict including a PMEDiagnostics entry.

Raises

  • ValueError — If shapes are wrong, the cell is non-orthorhombic, or charge is incompatible with the configured background policy.

pme_coulomb_reciprocal_space_energy_forces

Section titled “pme_coulomb_reciprocal_space_energy_forces”
def pme_coulomb_reciprocal_space_energy_forces(positions: mx.array, charges: mx.array, cell: Cell, *, coulomb_constant: float = 1.0, config: PMEConfig | None = None, include_self_correction: bool = True, plan: PMEExecutionPlan | None = None) -> tuple[mx.array, mx.array]

Evaluate PME mesh/reciprocal-space Coulomb forces.

By default the scalar self correction is included so direct-space plus reciprocal-space equals the total PME Coulomb energy.

Parameters

NameTypeDefaultDescription
positionsmx.arrayAtomic coordinates, shape (n_atoms, 3).
chargesmx.arrayPer-atom partial charges, shape (n_atoms,); charged systems require the explicit uniform-plasma background policy.
cellCellPeriodic orthorhombic Cell (triclinic is unsupported).
coulomb_constantfloat1.0Coulomb prefactor in the configured unit system. Defaults to 1.0.
configPMEConfig | NoneNonePME parameters; None uses defaults. Defaults to None.
include_self_correctionboolTrueWhether to add the scalar self-energy correction so direct + reciprocal equals the total. Defaults to True.
planPMEExecutionPlan | NoneNoneOptional reusable fixed-cell execution plan. A one-shot plan is built when omitted. Defaults to None.

Returns

  • tuple[mx.array, mx.array] — An (energy, forces) tuple: scalar reciprocal-space energy and (n_atoms, 3) forces.

Raises

  • ValueError — If shapes/cell or the configured charge policy are invalid.
def pme_coulomb_strain_components(positions: mx.array, charges: mx.array, cell: Cell, *, coulomb_constant: float = 1.0, config: PMEConfig | None = None, direct_space_pairs: mx.array | NeighborBlocks | None = None) -> dict[str, mx.array]

Return cell-differentiable PME components for analytic virials.

This path rebuilds the cell-dependent reciprocal arrays from MLX values so automatic differentiation sees the complete diagonal cell derivative. It is intentionally separate from the reusable fixed-cell execution plan.

Parameters

NameTypeDefaultDescription
positionsmx.arrayMolecularly strained coordinates, shape (n_atoms, 3).
chargesmx.arrayPer-atom partial charges, shape (n_atoms,).
cellCellStrained orthorhombic periodic cell.
coulomb_constantfloat1.0Coulomb prefactor in the configured unit system.
configPMEConfig | NoneNonePME parameters with an explicit real-space cutoff.
direct_space_pairsmx.array | NeighborBlocks | NoneNoneCompact pairs or neighbor blocks held fixed during the infinitesimal strain derivative.

Returns

  • dict[str, mx.array] — Differentiable real, reciprocal, self, and background energies.

Raises

  • ValueError — If the cell, shapes, cutoff, charge policy, or direct-space pair representation is outside the analytic-virial envelope.
def pme_coulomb_strain_energy(positions: mx.array, charges: mx.array, cell: Cell, *, coulomb_constant: float = 1.0, config: PMEConfig | None = None, direct_space_pairs: mx.array | NeighborBlocks | None = None) -> mx.array

Return the complete cell-differentiable PME energy for analytic virials.

Parameters

NameTypeDefaultDescription
positionsmx.arrayMolecularly strained coordinates, shape (n_atoms, 3).
chargesmx.arrayPer-atom partial charges, shape (n_atoms,).
cellCellStrained orthorhombic periodic cell.
coulomb_constantfloat1.0Coulomb prefactor in the configured unit system.
configPMEConfig | NoneNonePME parameters with an explicit real-space cutoff.
direct_space_pairsmx.array | NeighborBlocks | NoneNoneCompact pairs or neighbor blocks held fixed during the infinitesimal strain derivative.

Returns

  • mx.array — The sum of real, reciprocal, self, and background PME energies.
def pme_coulomb_total_energy_forces(positions: mx.array, charges: mx.array, cell: Cell, *, coulomb_constant: float = 1.0, config: PMEConfig | None = None, direct_space_pairs: mx.array | NeighborBlocks | None = None, plan: PMEExecutionPlan | None = None) -> tuple[mx.array, mx.array]

Evaluate neutral orthorhombic Coulomb total energy and forces with PME.

Parameters

NameTypeDefaultDescription
positionsmx.arrayAtomic coordinates, shape (n_atoms, 3).
chargesmx.arrayPer-atom partial charges, shape (n_atoms,); charged systems require the explicit uniform-plasma background policy.
cellCellPeriodic orthorhombic Cell (triclinic is unsupported).
coulomb_constantfloat1.0Coulomb prefactor in the configured unit system. Defaults to 1.0.
configPMEConfig | NoneNonePME parameters; None uses defaults. Defaults to None.
direct_space_pairsmx.array | NeighborBlocks | NoneNoneOptional precomputed real-space pairs or neighbor blocks. Defaults to None.
planPMEExecutionPlan | NoneNoneOptional reusable fixed-cell execution plan. A one-shot plan is built when omitted. Defaults to None.

Returns

  • tuple[mx.array, mx.array] — An (energy, forces) tuple: scalar total Coulomb energy and (n_atoms, 3) forces.

Raises

  • ValueError — If shapes/cell or the configured charge policy are invalid.
def pme_direct_space_policy_report(cell: Cell, *, config: PMEConfig | None = None, pairs: mx.array | NeighborBlocks | None = None, plan: PMEExecutionPlan | None = None) -> dict[str, object]

Report whether PME direct-space can use dense, pair, block, or fallback policy.

Parameters

NameTypeDefaultDescription
cellCellPeriodic orthorhombic cell.
configPMEConfig | NoneNonePME parameters; None uses defaults. Defaults to None.
pairsmx.array | NeighborBlocks | NoneNoneOptional candidate real-space pairs or neighbor blocks to evaluate the policy against. Defaults to None.
planPMEExecutionPlan | NoneNoneOptional plan whose configuration and fixed cell must match. The policy query does not advance its reuse counter. Defaults to None.

Returns

  • dict[str, object] — A PMEDirectSpacePolicyReport dict (selected policy/representation, support, cutoff, and pair-count provenance).

Raises

  • ValueError — If the cell is missing, non-orthorhombic, or has non-positive lengths.
def pme_force_scope_report(scope: str) -> dict[str, object]

Return PME support metadata for a requested force-evaluation scope.

Parameters

NameTypeDefaultDescription
scopestrForce-evaluation scope to query ("total", "components", "direct_space", "reciprocal_space").

Returns

  • dict[str, object] — A ForceScopeReport dict; every PME scope is supported and marked as requiring full-system evaluation.
def pme_platform_readiness_report(*, atom_count: int, charges: object, cell_lengths: object, config: PMEConfig | None, nonbonded_cutoff: float | None, exclusion_count: int, one_four_count: int, explicit_exception_count: int, cell_matrix: object | None = None) -> ReadinessReport

Return PME readiness using the shared platform readiness schema.

Parameters

NameTypeDefaultDescription
atom_countintNumber of atoms in the system.
chargesobjectPer-atom partial charges, shape (atom_count,).
cell_lengthsobjectOrthorhombic box lengths, shape (3,).
configPMEConfig | NonePME parameters; None is reported as a blocker.
nonbonded_cutofffloat | NoneReal-space nonbonded cutoff, cross-checked against the PME cutoff.
exclusion_countintNumber of excluded pairs.
one_four_countintNumber of 1-4 corrected pairs.
explicit_exception_countintNumber of explicit nonbonded exceptions.
cell_matrixobject | NoneNoneOptional full cell matrix for the orthorhombic-envelope check.

Returns

  • ReadinessReport — A ReadinessReport (name "pme", status, blockers, and the remaining checks as metadata).
def pme_readiness_report(*, atom_count: int, charges: object, cell_lengths: object, config: PMEConfig | None, nonbonded_cutoff: float | None, exclusion_count: int, one_four_count: int, explicit_exception_count: int, cell_matrix: object | None = None) -> dict[str, object]

Return fail-closed PME readiness metadata for production run gates.

Parameters

NameTypeDefaultDescription
atom_countintNumber of atoms in the system.
chargesobjectPer-atom partial charges, shape (atom_count,).
cell_lengthsobjectOrthorhombic box lengths, shape (3,).
configPMEConfig | NonePME parameters (mesh, alpha, cutoffs); None is reported as a blocker.
nonbonded_cutofffloat | NoneReal-space nonbonded cutoff, cross-checked against the PME cutoff.
exclusion_countintNumber of excluded pairs.
one_four_countintNumber of 1-4 corrected pairs.
explicit_exception_countintNumber of explicit nonbonded exceptions.
cell_matrixobject | NoneNoneOptional full cell matrix used to assert the orthorhombic execution envelope. None treats valid lengths as orthorhombic.

Returns

  • dict[str, object] — A readiness dict with a "status", a "blockers" list, and the individual boolean checks (neutrality, box, mesh, alpha, cutoff, …).