Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Bug]: failure in representing cluster scene with crystal_toolkit #480

Open
2 of 4 tasks
qchempku2017 opened this issue Jul 28, 2024 · 1 comment
Open
2 of 4 tasks
Assignees
Labels
bug Something isn't working triage

Comments

@qchempku2017
Copy link
Collaborator

Email (Optional)

[email protected]

Version

v0.5.4

Which OS(es) are you using?

  • MacOS
  • Windows
  • Linux

What happened?

When trying to visualize a cluster with crystal toolkit, the species fails to render. This issue could arise from pymatgen version change in the same manner as issue #475 .

Code snippet

space.orbits[-1].base_cluster

Log output

---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
File ~\anaconda3\envs\smol\lib\site-packages\crystal_toolkit\components\structure.py:984, in StructureMoleculeComponent._preprocess_input_to_graph(input, bonding_strategy, bonding_strategy_kwargs)
    983         else:
--> 984             graph = MoleculeGraph.with_local_env_strategy(
    985                 input, bonding_strategy, reorder=False
    986             )
    987 except Exception:
    988     # for some reason computing bonds failed, so let's not have any bonds(!)

TypeError: MoleculeGraph.with_local_env_strategy() got an unexpected keyword argument 'reorder'

During handling of the above exception, another exception occurred:

AttributeError                            Traceback (most recent call last)
File ~\anaconda3\envs\smol\lib\site-packages\IPython\core\formatters.py:925, in IPythonDisplayFormatter.__call__(self, obj)
    923 method = get_real_method(obj, self.print_method)
    924 if method is not None:
--> 925     method()
    926     return True

File ~\anaconda3\envs\smol\lib\site-packages\crystal_toolkit\core\jupyter.py:113, in _ipython_display_(self)
    110 from IPython.display import publish_display_data
    112 if any(isinstance(self, x) for x in _JupyterRenderer.registry):
--> 113     return _JupyterRenderer().display(self)
    115 # To be strict here, we could use inspect.signature
    116 # and .return_annotation is either a Scene or a go.Figure respectively
    117 # and also check all .parameters .kind.name have no POSITIONAL_ONLY
    118 # in practice, fairly unlikely this will cause issues without strict checking.
    119 # TODO: This can be removed once a central registry of renderable objects is implemented.
    120 if self.get_scene:

File ~\anaconda3\envs\smol\lib\site-packages\crystal_toolkit\core\jupyter.py:72, in _JupyterRenderer.display(self, obj)
     69 for kls, component in self.registry.items():
     70     if isinstance(obj, kls):
     71         layout = ctl.Block(
---> 72             [component(obj).layout()],
     73             style={"margin-top": "1rem", "margin-left": "1rem"},
     74         )
     75         return self.run(layout)
     77 raise ValueError(f"No component defined for object of type {type(obj)}.")

File ~\anaconda3\envs\smol\lib\site-packages\crystal_toolkit\components\structure.py:208, in StructureMoleculeComponent.__init__(self, struct_or_mol, id, className, scene_additions, bonding_strategy, bonding_strategy_kwargs, color_scheme, color_scale, radius_strategy, unit_cell_choice, draw_image_atoms, bonded_sites_outside_unit_cell, hide_incomplete_bonds, show_compass, scene_settings, group_by_site_property, show_legend, show_settings, show_controls, show_expand_button, show_image_button, show_export_button, show_position_button, **kwargs)
    201 if struct_or_mol:
    202     # graph is cached explicitly, this isn't necessary but is an
    203     # optimization so that graph is only re-generated if bonding
    204     # algorithm changes
    205     struct_or_mol = self._preprocess_structure(
    206         struct_or_mol, unit_cell_choice=unit_cell_choice
    207     )
--> 208     graph = self._preprocess_input_to_graph(
    209         struct_or_mol,
    210         bonding_strategy=bonding_strategy,
    211         bonding_strategy_kwargs=bonding_strategy_kwargs,
    212     )
    213     scene, legend = self.get_scene_and_legend(
    214         graph,
    215         scene_additions=self.initial_data["scene_additions"],
    216         **self.initial_data["display_options"],
    217     )
    218     if hasattr(struct_or_mol, "lattice"):

File ~\anaconda3\envs\smol\lib\site-packages\crystal_toolkit\components\structure.py:992, in StructureMoleculeComponent._preprocess_input_to_graph(input, bonding_strategy, bonding_strategy_kwargs)
    990             graph = StructureGraph.with_empty_graph(input)
    991         else:
--> 992             graph = MoleculeGraph.with_empty_graph(input)
    994 return graph

File ~\anaconda3\envs\smol\lib\site-packages\pymatgen\analysis\graphs.py:1614, in MoleculeGraph.with_empty_graph(cls, molecule, name, edge_weight_name, edge_weight_units)
   1610 graph.add_nodes_from(range(len(molecule)))
   1612 graph_data = json_graph.adjacency_data(graph)
-> 1614 return cls(molecule, graph_data=graph_data)

File ~\anaconda3\envs\smol\lib\site-packages\pymatgen\analysis\graphs.py:1577, in MoleculeGraph.__init__(self, molecule, graph_data)
   1574     if "from_jimage" in d:
   1575         d["from_jimage"] = tuple(d["from_jimage"])
-> 1577 self.set_node_attributes()

File ~\anaconda3\envs\smol\lib\site-packages\pymatgen\analysis\graphs.py:1857, in MoleculeGraph.set_node_attributes(self)
   1855 properties = {}
   1856 for node in self.graph.nodes():
-> 1857     species[node] = self.molecule[node].specie.symbol
   1858     coords[node] = self.molecule[node].coords
   1859     properties[node] = self.molecule[node].properties

File ~\anaconda3\envs\smol\lib\site-packages\pymatgen\core\sites.py:79, in Site.__getattr__(self, attr)
     77 if attr in props:
     78     return props[attr]
---> 79 raise AttributeError(f"{attr=} not found on {type(self).__name__}")

AttributeError: attr='specie' not found on Site

Code of Conduct

  • I agree to follow this project's Code of Conduct
@kamronald
Copy link
Collaborator

Thanks @qchempku2017 for bringing this up. PR #485 fixes this issue

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working triage
Projects
None yet
Development

No branches or pull requests

3 participants