Skip to content

Support changing atoms in trajectory #80

Description

@utf

I'm trying to use hofmann to render a trajectory from a diffusion model. At the beginning all atoms are masked (for this I'm used Og at the atom type) and during the trajectory they are progressively unmasked and become a different atom type.

I've tried rendering this with hofmann but get the error:

ValueError                                Traceback (most recent call last)
Cell In[30], [line 1](vscode-notebook-cell:?execution_count=30&line=1)
----> [1](vscode-notebook-cell:?execution_count=30&line=1) scene = StructureScene.from_ase(traj)
      2 scene.render_animation("output.gif")

File ~/opt/miniconda3/envs/py313/lib/python3.13/site-packages/hofmann/model/structure_scene.py:253, in StructureScene.from_ase(cls, atoms, bond_specs, polyhedra, centre_atom, atom_styles, title, view, atom_data)
    202 """Create a StructureScene from ASE ``Atoms`` object(s).
    203 
    204 For periodic systems, fractional coordinates are wrapped to
   (...)    249     :func:`hofmann.construction.scene_builders.from_ase`
    250 """
    251 from hofmann.construction.scene_builders import from_ase
--> [253](https://file+.vscode-resource.vscode-cdn.net/Users/alexganose/Library/CloudStorage/OneDrive-ImperialCollegeLondon/Notebooks/2026/hoffman/~/opt/miniconda3/envs/py313/lib/python3.13/site-packages/hofmann/model/structure_scene.py:253) return from_ase(
    254     atoms, bond_specs, polyhedra=polyhedra,
    255     centre_atom=centre_atom,
    256     atom_styles=atom_styles, title=title, view=view,
    257     atom_data=atom_data,
    258 )

File ~/opt/miniconda3/envs/py313/lib/python3.13/site-packages/hofmann/construction/scene_builders.py:180, in from_ase(atoms, bond_specs, polyhedra, centre_atom, atom_styles, title, view, atom_data)
    174     raise ValueError(
    175         f"all Atoms in a trajectory must have the same number "
    176         f"of atoms. Frame 0 has {len(first)} but frame {i} "
    177         f"has {len(a)}."
    178     )
    179 if a.get_chemical_symbols() != species:
--> [180](https://file+.vscode-resource.vscode-cdn.net/Users/alexganose/Library/CloudStorage/OneDrive-ImperialCollegeLondon/Notebooks/2026/hoffman/~/opt/miniconda3/envs/py313/lib/python3.13/site-packages/hofmann/construction/scene_builders.py:180)     raise ValueError(
    181         f"all Atoms in a trajectory must have the same "
    182         f"species. Frame 0 has {species} but frame {i} has "
    183         f"{a.get_chemical_symbols()}."
    184     )
    185 frame_periodic = a.pbc.any() and a.cell.rank == 3
    186 if frame_periodic != periodic:

ValueError: all Atoms in a trajectory must have the same species. Frame 0 has ['Og', 'Og', 'Ts', 'Ts', 'Lv', 'Lv'] but frame 31 has ['Tb', 'Tb', 'Ts', 'Ts', 'Lv', 'Lv'].

Is there a reason why atom types cannot differ during a trajectory? I'm not plotting any octahedra or bonds.

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