1
+ from __future__ import annotations
2
+
1
3
import re
2
4
import warnings
3
5
from base64 import b64encode
4
6
from collections import OrderedDict
5
7
from itertools import chain , combinations_with_replacement
6
8
from pathlib import Path
7
9
from tempfile import TemporaryDirectory
8
- from typing import Dict , Literal , Optional , Tuple , Union
10
+ from typing import Literal
9
11
10
12
import numpy as np
11
13
from dash import dash_table as dt
29
31
30
32
# TODO: make dangling bonds "stubs"? (fixed length)
31
33
32
- DEFAULTS = {
34
+ DEFAULTS : dict [ str , str | bool ] = {
33
35
"color_scheme" : "VESTA" ,
34
36
"bonding_strategy" : "CrystalNN" ,
35
37
"radius_strategy" : "uniform" ,
@@ -85,16 +87,15 @@ class StructureMoleculeComponent(MPComponent):
85
87
86
88
def __init__ (
87
89
self ,
88
- struct_or_mol : Optional [
89
- Union [Structure , StructureGraph , Molecule , MoleculeGraph ]
90
- ] = None ,
90
+ struct_or_mol : None
91
+ | (Structure | StructureGraph | Molecule | MoleculeGraph ) = None ,
91
92
id : str = None ,
92
93
className : str = "box" ,
93
- scene_additions : Optional [ Scene ] = None ,
94
+ scene_additions : Scene | None = None ,
94
95
bonding_strategy : str = DEFAULTS ["bonding_strategy" ],
95
- bonding_strategy_kwargs : Optional [ dict ] = None ,
96
+ bonding_strategy_kwargs : dict | None = None ,
96
97
color_scheme : str = DEFAULTS ["color_scheme" ],
97
- color_scale : Optional [ str ] = None ,
98
+ color_scale : str | None = None ,
98
99
radius_strategy : str = DEFAULTS ["radius_strategy" ],
99
100
unit_cell_choice : str = DEFAULTS ["unit_cell_choice" ],
100
101
draw_image_atoms : bool = DEFAULTS ["draw_image_atoms" ],
@@ -103,8 +104,8 @@ def __init__(
103
104
],
104
105
hide_incomplete_bonds : bool = DEFAULTS ["hide_incomplete_bonds" ],
105
106
show_compass : bool = DEFAULTS ["show_compass" ],
106
- scene_settings : Optional [ Dict ] = None ,
107
- group_by_site_property : Optional [ str ] = None ,
107
+ scene_settings : dict | None = None ,
108
+ group_by_site_property : str | None = None ,
108
109
show_legend : bool = DEFAULTS ["show_legend" ],
109
110
show_settings : bool = DEFAULTS ["show_settings" ],
110
111
show_controls : bool = DEFAULTS ["show_controls" ],
@@ -907,7 +908,7 @@ def layout(self, size: str = "500px") -> html.Div:
907
908
908
909
@staticmethod
909
910
def _preprocess_structure (
910
- struct_or_mol : Union [ Structure , StructureGraph , Molecule , MoleculeGraph ] ,
911
+ struct_or_mol : Structure | StructureGraph | Molecule | MoleculeGraph ,
911
912
unit_cell_choice : Literal [
912
913
"input" , "primitive" , "conventional" , "reduced_niggli" , "reduced_lll"
913
914
] = "input" ,
@@ -931,10 +932,10 @@ def _preprocess_structure(
931
932
932
933
@staticmethod
933
934
def _preprocess_input_to_graph (
934
- input : Union [ Structure , StructureGraph , Molecule , MoleculeGraph ] ,
935
+ input : Structure | StructureGraph | Molecule | MoleculeGraph ,
935
936
bonding_strategy : str = DEFAULTS ["bonding_strategy" ],
936
- bonding_strategy_kwargs : Optional [ Dict ] = None ,
937
- ) -> Union [ StructureGraph , MoleculeGraph ] :
937
+ bonding_strategy_kwargs : dict | None = None ,
938
+ ) -> StructureGraph | MoleculeGraph :
938
939
939
940
if isinstance (input , Structure ):
940
941
@@ -1007,8 +1008,8 @@ def _preprocess_input_to_graph(
1007
1008
1008
1009
@staticmethod
1009
1010
def _get_struct_or_mol (
1010
- graph : Union [ StructureGraph , MoleculeGraph , Structure , Molecule ]
1011
- ) -> Union [ Structure , Molecule ] :
1011
+ graph : StructureGraph | MoleculeGraph | Structure | Molecule ,
1012
+ ) -> Structure | Molecule :
1012
1013
if isinstance (graph , StructureGraph ):
1013
1014
return graph .structure
1014
1015
elif isinstance (graph , MoleculeGraph ):
@@ -1020,7 +1021,7 @@ def _get_struct_or_mol(
1020
1021
1021
1022
@staticmethod
1022
1023
def get_scene_and_legend (
1023
- graph : Optional [ Union [ StructureGraph , MoleculeGraph ]] ,
1024
+ graph : StructureGraph | MoleculeGraph | None ,
1024
1025
color_scheme = DEFAULTS ["color_scheme" ],
1025
1026
color_scale = None ,
1026
1027
radius_strategy = DEFAULTS ["radius_strategy" ],
@@ -1031,7 +1032,7 @@ def get_scene_and_legend(
1031
1032
scene_additions = None ,
1032
1033
show_compass = DEFAULTS ["show_compass" ],
1033
1034
group_by_site_property = None ,
1034
- ) -> Tuple [Scene , Dict [str , str ]]:
1035
+ ) -> tuple [Scene , dict [str , str ]]:
1035
1036
1036
1037
scene = Scene (name = "StructureMoleculeComponentScene" )
1037
1038
0 commit comments