Closed exenGT closed 11 months ago
Hi,
I tried to run crystaltoolkit_relax_viewer.ipynb in the "examples" folder, but running the last cell gives this error:
--------------------------------------------------------------------------- ValueError Traceback (most recent call last) Cell In[11], line 17 11 if "struct_layout" not in vars(): 12 # don't create layout twice because it causes duplicate 13 # ID errors when restarting Dash app in Jupyter notebook 14 struct_comp = ctc.StructureMoleculeComponent( 15 id="structure", struct_or_mol=structure 16 ) ---> 17 struct_layout = struct_comp.layout() 20 step_size = max(1, len(trajectory) // 20) # ensure slider has max 20 steps 21 slider = dcc.Slider( 22 id="slider", min=0, max=len(trajectory) - 1, step=step_size, updatemode="drag" 23 ) File ~/miniconda3/envs/chem/lib/python3.9/site-packages/crystal_toolkit/components/structure.py:896, in StructureMoleculeComponent.layout(self, size) 886 def layout(self, size: str = "500px") -> html.Div: 887 """Get the layout for this component. 888 889 Args: (...) 893 html.Div: A html.Div containing the 3D structure or molecule 894 """ 895 return html.Div( --> 896 self._sub_layouts["struct"], style={"width": size, "height": size} 897 ) File ~/miniconda3/envs/chem/lib/python3.9/site-packages/crystal_toolkit/components/structure.py:851, in StructureMoleculeComponent._sub_layouts(self) 847 options_layout = None 849 if self.show_legend: 850 legend_layout = html.Div( --> 851 self._make_legend(self._initial_data["legend_data"]), 852 id=self.id("legend_container"), 853 ) 854 else: 855 legend_layout = None File ~/miniconda3/envs/chem/lib/python3.9/site-packages/crystal_toolkit/components/structure.py:592, in StructureMoleculeComponent._make_legend(self, legend) 585 c = tuple(int(hex_code[1:][i : i + 2], 16) for i in (0, 2, 4)) 586 return ( 587 "black" 588 if 1 - (c[0] * 0.299 + c[1] * 0.587 + c[2] * 0.114) / 255 < 0.5 589 else "white" 590 ) --> 592 legend_colors = { 593 k: self._legend.get_color(Species(k)) 594 for k, v in legend["composition"].items() 595 } 597 legend_elements = [ 598 html.Span( 599 html.Span( (...) 605 for name, color in legend_colors.items() 606 ] 608 return html.Div( 609 legend_elements, 610 id=self.id("legend"), 611 style={"display": "flex"}, 612 className="buttons", 613 ) File ~/miniconda3/envs/chem/lib/python3.9/site-packages/crystal_toolkit/components/structure.py:593, in <dictcomp>(.0) 585 c = tuple(int(hex_code[1:][i : i + 2], 16) for i in (0, 2, 4)) 586 return ( 587 "black" 588 if 1 - (c[0] * 0.299 + c[1] * 0.587 + c[2] * 0.114) / 255 < 0.5 589 else "white" 590 ) 592 legend_colors = { --> 593 k: self._legend.get_color(Species(k)) 594 for k, v in legend["composition"].items() 595 } 597 legend_elements = [ 598 html.Span( 599 html.Span( (...) 605 for name, color in legend_colors.items() 606 ] 608 return html.Div( 609 legend_elements, 610 id=self.id("legend"), 611 style={"display": "flex"}, 612 className="buttons", 613 ) File ~/miniconda3/envs/chem/lib/python3.9/site-packages/pymatgen/core/periodic_table.py:1077, in Species.__init__(self, symbol, oxidation_state, properties) 1049 def __init__( 1050 self, 1051 symbol: str, 1052 oxidation_state: float | None = 0.0, 1053 properties: dict | None = None, 1054 ): 1055 """ 1056 Initializes a Species. 1057 (...) 1075 Properties are now checked when comparing two Species for equality. 1076 """ -> 1077 self._el = Element(symbol) 1078 self._oxi_state = oxidation_state 1079 self._properties = properties or {} File ~/miniconda3/envs/chem/lib/python3.9/enum.py:384, in EnumMeta.__call__(cls, value, names, module, qualname, type, start) 359 """ 360 Either returns an existing member, or creates a new enum class. 361 (...) 381 `type`, if set, will be mixed in as the first base class. 382 """ 383 if names is None: # simple value lookup --> 384 return cls.__new__(cls, value) 385 # otherwise, functional API: we're creating a new Enum type 386 return cls._create_( 387 value, 388 names, (...) 392 start=start, 393 ) File ~/miniconda3/envs/chem/lib/python3.9/enum.py:702, in Enum.__new__(cls, value) 700 ve_exc = ValueError("%r is not a valid %s" % (value, cls.__qualname__)) 701 if result is None and exc is None: --> 702 raise ve_exc 703 elif exc is None: 704 exc = TypeError( 705 'error in %s._missing_: returned %r instead of None or a valid member' 706 % (cls.__name__, result) 707 ) ValueError: 'Li+' is not a valid Element
I think it is related to the presence of oxidation state in the cif file. Is this the expected behavior? If not, how should it be fixed?
Thanks, JW
I can't repro. Maybe try
pip install -U pymatgen crystal-toolkit
After updating, everything works as expected! Closing this issue now.
Hi,
I tried to run crystaltoolkit_relax_viewer.ipynb in the "examples" folder, but running the last cell gives this error:
I think it is related to the presence of oxidation state in the cif file. Is this the expected behavior? If not, how should it be fixed?
Thanks, JW