Skip to content

Introduce validated AtomData container #44

@bjmorgan

Description

@bjmorgan

Summary

atom_data on StructureScene is a plain dict[str, np.ndarray]. Users can bypass set_atom_data() and write directly to the dict with no validation -- wrong-length arrays, non-arrays, and mixed None/numeric object arrays silently enter the system and cause confusing errors downstream during colour resolution.

Proposed changes

  1. AtomData container -- a MutableMapping[str, np.ndarray] that validates on assignment: checks 1-D shape, correct length, and rejects object-dtype arrays containing mixed None + numeric values.

  2. Convert StructureScene from dataclass to hand-rolled class -- the current __setattr__ and __post_init__ overrides fight the dataclass machinery. An explicit __init__ with property setters for view, lattice, and atom_data would be cleaner.

Future consideration

Per-frame atom data (shape (n_frames, n_atoms) in addition to the current (n_atoms,)) for trajectory colouring (e.g. per-frame velocities, charges). The AtomData container should be designed so this can be added without breaking changes.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions