Add ensemble trajectory overlay and examples#45
Open
iribirii wants to merge 1 commit intoaligfellow:mainfrom
Open
Add ensemble trajectory overlay and examples#45iribirii wants to merge 1 commit intoaligfellow:mainfrom
iribirii wants to merge 1 commit intoaligfellow:mainfrom
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
xyzrender.ensemblemodule and API that builds an ensembleMoleculefrom a multi-frame XYZ trajectory by RMSD-aligning all frames onto a reference frame using the Kabsch algorithm (index-based atom pairing).--ensembleflag for trajectory overlays, including additional validation (mutually exclusive with--overlay,--gif-ts,--gif-trj, and stdin input) and support for rotation GIFs that spin the pre-built ensemble graph._build_ensemble_molecule, document the ensemble feature in the README and CLI reference, and include static and rotating ensemble figures for the triphenylbenzol trajectory.Details
Core logic
src/xyzrender/ensemble.pyimplements:align(frames, reference_frame=0)to align all frames fromload_trajectory_frames()onto a chosen reference frame via Kabsch, with shape and symbol consistency checks.merge_graphs(reference_graph, aligned_positions)to replicate the reference graph per conformer, addmolecule_indexattributes to nodes/edges, avoidoverlay/bond_color_override, and apply a small per-conformer z-nudge to prevent SVG z-fighting._build_ensemble_molecule(...)inapi.py:bond_ordervalues on the reference graph to 1 (render-time single bonds).ensemble.align+ensemble.merge_graphs, wrapped in aMolecule.Public API
ensemble(...) -> SVGResultinapi.py:render().mo,dens,esp,nci) for ensembles.hy=True(unlesshy/no_hyexplicitly overridden).bo=False(ignore bond orders by default, though explicitbois still respected).__init__.pynow exportsensembleforfrom xyzrender import ensemble.CLI
--ensembleflag in the “overlay / ensemble” group:--overlay,--overlay-color,--gif-ts, and--gif-trj.--ensembleis set, the CLI callsapi.ensemble(...)instead ofrender(...).--ensemble --gif-rot, builds the ensemble once via_build_ensemble_molecule(...)and passes it torender_gif(...)so the GIF shows the ensemble, not just a single frame.Docs and examples
README.md:docs/source/cli_reference.md:--ensembleflag under “Structural overlay”.examples/images/triphenylbenzol_ensemble.svgexamples/images/triphenylbenzol_ensemble.gifexamples/structures/triphenylbenzol.xyz.Tests
tests/test_ensemble.py:_write_multiframe_xyz(...)helper to generate small test trajectories.test_build_ensemble_molecule:molecule_indexlabelling, and absence ofoverlay/bond_color_overrideattributes.test_ensemble_api_returns_svg:ensemble(...)writes a valid SVG and returns anSVGResult.