1
- from pathlib import Path
2
-
3
- from tempfile import TemporaryDirectory
4
-
5
- from base64 import b64encode
6
-
7
- import json
8
- import os
9
1
import re
10
- import sys
11
2
import warnings
3
+ from base64 import b64encode
12
4
from collections import OrderedDict
13
5
from itertools import chain , combinations_with_replacement
14
- from pymatgen .io .vasp .sets import MPRelaxSet
6
+ from pathlib import Path
7
+ from tempfile import TemporaryDirectory
15
8
from typing import Dict , Optional , Tuple , Union
16
9
17
- import dash
18
- from dash import dash_table as dt
19
10
import numpy as np
20
- from dash .dependencies import Input , Output , State , MATCH
11
+ from dash import dash_table as dt
12
+ from dash .dependencies import Input , Output , State
21
13
from dash .exceptions import PreventUpdate
22
14
from dash_mp_components import CrystalToolkitScene
15
+ from emmet .core .settings import EmmetSettings
23
16
from pymatgen .analysis .graphs import MoleculeGraph , StructureGraph
24
17
from pymatgen .analysis .local_env import NearNeighbors
25
18
from pymatgen .core .composition import Composition
26
19
from pymatgen .core .periodic_table import DummySpecie
27
20
from pymatgen .core .structure import Molecule , Structure
21
+ from pymatgen .io .vasp .sets import MPRelaxSet
28
22
from pymatgen .symmetry .analyzer import SpacegroupAnalyzer
29
- from emmet .core .settings import EmmetSettings
30
23
31
24
from crystal_toolkit .core .legend import Legend
32
25
from crystal_toolkit .core .mpcomponent import MPComponent
33
26
from crystal_toolkit .core .scene import Scene
34
- from crystal_toolkit .helpers .layouts import *
27
+ from crystal_toolkit .helpers .layouts import H2 , Field , dcc , html
35
28
from crystal_toolkit .settings import SETTINGS
36
29
37
30
try :
56
49
"show_expand_button" : True ,
57
50
"show_image_button" : True ,
58
51
"show_export_button" : True ,
59
- "show_position_button" : True
52
+ "show_position_button" : True ,
60
53
}
61
54
62
55
@@ -256,7 +249,7 @@ def generate_callbacks(self, app, cache):
256
249
app .clientside_callback (
257
250
"""
258
251
function (bonding_strategy, custom_cutoffs_rows, unit_cell_choice) {
259
-
252
+
260
253
const bonding_strategy_kwargs = {}
261
254
if (bonding_strategy === 'CutOffDictNN') {
262
255
const cut_off_dict = []
@@ -265,7 +258,7 @@ def generate_callbacks(self, app, cache):
265
258
})
266
259
bonding_strategy_kwargs.cut_off_dict = cut_off_dict
267
260
}
268
-
261
+
269
262
return {
270
263
bonding_strategy: bonding_strategy,
271
264
bonding_strategy_kwargs: bonding_strategy_kwargs,
@@ -299,7 +292,7 @@ def generate_callbacks(self, app, cache):
299
292
app .clientside_callback (
300
293
"""
301
294
function (colorScheme, radiusStrategy, drawOptions, displayOptions) {
302
-
295
+
303
296
const newDisplayOptions = Object.assign({}, displayOptions);
304
297
newDisplayOptions.color_scheme = colorScheme
305
298
newDisplayOptions.radius_strategy = radiusStrategy
@@ -462,7 +455,7 @@ def download_image(image_data_timestamp, image_data, data):
462
455
spgrp = struct_or_mol .get_space_group_info ()[0 ]
463
456
else :
464
457
spgrp = ""
465
- request_filename = "{ }-{}-crystal-toolkit.png". format ( formula , spgrp )
458
+ request_filename = f" { formula } -{ spgrp } -crystal-toolkit.png"
466
459
467
460
return {
468
461
"content" : image_data [len ("data:image/png;base64," ) :],
@@ -628,7 +621,7 @@ def get_font_color(hex_code):
628
621
legend_elements ,
629
622
id = self .id ("legend" ),
630
623
style = {"display" : "flex" },
631
- className = "buttons"
624
+ className = "buttons" ,
632
625
)
633
626
634
627
def _make_title (self , legend ):
@@ -761,7 +754,9 @@ def _sub_layouts(self):
761
754
),
762
755
html .Div (
763
756
[
764
- html .Label ("Change bonding algorithm: " , className = "mpc-label" ),
757
+ html .Label (
758
+ "Change bonding algorithm: " , className = "mpc-label"
759
+ ),
765
760
bonding_algorithm ,
766
761
bonding_algorithm_custom_cutoffs ,
767
762
]
@@ -786,15 +781,20 @@ def _sub_layouts(self):
786
781
html .Div (
787
782
dcc .Dropdown (
788
783
options = [
789
- {"label" : "Ionic" , "value" : "specified_or_average_ionic" },
784
+ {
785
+ "label" : "Ionic" ,
786
+ "value" : "specified_or_average_ionic" ,
787
+ },
790
788
{"label" : "Covalent" , "value" : "covalent" },
791
789
{"label" : "Van der Waals" , "value" : "van_der_waals" },
792
790
{
793
791
"label" : f"Uniform ({ Legend .uniform_radius } Å)" ,
794
792
"value" : "uniform" ,
795
793
},
796
794
],
797
- value = self .initial_data ["display_options" ]["radius_strategy" ],
795
+ value = self .initial_data ["display_options" ][
796
+ "radius_strategy"
797
+ ],
798
798
clearable = False ,
799
799
persistence = SETTINGS .PERSISTENCE ,
800
800
persistence_type = SETTINGS .PERSISTENCE_TYPE ,
@@ -875,10 +875,7 @@ def _sub_layouts(self):
875
875
struct_layout = html .Div (
876
876
[
877
877
CrystalToolkitScene (
878
- [
879
- options_layout ,
880
- legend_layout
881
- ],
878
+ [options_layout , legend_layout ],
882
879
id = self .id ("scene" ),
883
880
className = self .className ,
884
881
data = self .initial_data ["scene" ],
@@ -893,7 +890,7 @@ def _sub_layouts(self):
893
890
** self .scene_kwargs ,
894
891
),
895
892
dcc .Download (id = self .id ("download-image" )),
896
- dcc .Download (id = self .id ("download-structure" ))
893
+ dcc .Download (id = self .id ("download-structure" )),
897
894
]
898
895
)
899
896
@@ -906,7 +903,7 @@ def _sub_layouts(self):
906
903
907
904
def layout (self , size : str = "500px" ) -> html .Div :
908
905
"""
909
- :param size: a CSS string specifying width/height of Div
906
+ :param size: a CSS dimension specifying width/height of Div
910
907
:return: A html.Div containing the 3D structure or molecule
911
908
"""
912
909
return html .Div (
@@ -946,7 +943,7 @@ def _preprocess_input_to_graph(
946
943
947
944
if isinstance (input , Structure ):
948
945
949
- # ensure fractional co-ordinates are normalized to be in [0,1)
946
+ # ensure fractional coordinates are normalized to be in [0,1)
950
947
# (this is actually not guaranteed by Structure)
951
948
try :
952
949
input = input .as_dict (verbosity = 0 )
@@ -988,10 +985,10 @@ def _preprocess_input_to_graph(
988
985
(x [0 ], x [1 ]): x [2 ]
989
986
for x in bonding_strategy_kwargs ["cut_off_dict" ]
990
987
}
991
- bonding_strategy = StructureMoleculeComponent . available_bonding_strategies [
992
- bonding_strategy
993
- ](
994
- ** bonding_strategy_kwargs
988
+ bonding_strategy = (
989
+ StructureMoleculeComponent . available_bonding_strategies [
990
+ bonding_strategy
991
+ ]( ** bonding_strategy_kwargs )
995
992
)
996
993
try :
997
994
with warnings .catch_warnings ():
0 commit comments