CederGroupHub / smol

Statistical Mechanics on Lattices
https://cedergrouphub.github.io/smol/
Other
65 stars 14 forks source link

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

Open qchempku2017 opened 3 months ago

qchempku2017 commented 3 months ago

Email (Optional)

fengyu_xie@berkeley.edu

Version

v0.5.4

Which OS(es) are you using?

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

kamronald commented 3 months ago

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