Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions crystal_toolkit/renderables/moleculegraph.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,8 @@ def get_molecule_graph_scene(
show_bond_length=show_bond_length,
visualize_bond_orders=visualize_bond_orders,
draw_polyhedra=draw_polyhedra,
edge_weight_name=vis_mol_graph.edge_weight_name,
edge_weight_unit=vis_mol_graph.edge_weight_unit,
)
for scene in site_scene.contents:
primitives[scene.name] += scene.contents
Expand Down
10 changes: 9 additions & 1 deletion crystal_toolkit/renderables/site.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,8 @@ def get_site_scene(
legend: Legend | None = None,
retain_atom_idx: bool = False,
total_repeat_cell_cnt: int = 1,
edge_weight_name: str = "bond order",
edge_weight_unit: str = "",
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

    edge_weight_name_mapping: dict[str, str] = {"weight": "bond order"},

) -> Scene:
"""Get a Scene object for a Site.

Expand All @@ -74,6 +76,8 @@ def get_site_scene(
legend (Legend | None, optional): Defaults to None.
retain_atom_idx (bool, optional): Defaults to False.
total_repeat_cell_cnt (int, optional): Defaults to 1.
edge_weight_name (str, optional): Defaults to "bond order".
edge_weight_unit (str, optional): Defaults to "".

Returns:
Scene: The scene object containing atoms, bonds, polyhedra, magmoms.
Expand Down Expand Up @@ -192,7 +196,11 @@ def get_site_scene(

for idx, connected_site in enumerate(connected_sites):
if show_bond_order and connected_site.weight is not None:
name_cyl = f"bond order:{connected_site.weight:.2f}"
if edge_weight_name is None:
Copy link
Collaborator

@minhsueh minhsueh Feb 20, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

vis_mol_graph.edge_weight_name is "weight", so this modification makes the bond label from "bond order:1.00" to "weight:1.00", as the attached images show.

We might want

if edge_weight_name is None or edge_weight_name == "weight":

to keep the default behavior unchanged. This is also not ideal, as if you want to show "weight", then it will always be "bond order."

Something to think about is using another key-value mapping for better customization
like

                if edge_weight_name is None:
                    edge_weight_name = "bond order"
                edge_weight_name = edge_weight_name_mapping.get(edge_weight_name, edge_weight_name)
                name_cyl = f"{edge_weight_name}:{connected_site.weight:.2f}"
Image Image

edge_weight_name = "bond order"
name_cyl = f"{edge_weight_name}:{connected_site.weight:.2f}"
if edge_weight_unit:
name_cyl += f" ({edge_weight_unit})"

if show_bond_length and connected_site.dist is not None:
name_cyl += f"\nbond length:{connected_site.dist:.3f}"
Expand Down