1
1
import itertools
2
2
from multiprocessing import cpu_count
3
+ from warnings import warn
3
4
4
- from dash import dcc
5
- from dash import html
6
5
import plotly .express as px
7
- from dash import callback_context
6
+ from dash import callback_context , dcc , html
8
7
from dash .dependencies import Input , Output
9
8
from dash .exceptions import PreventUpdate
10
- from dash_mp_components import GraphComponent
11
- from dscribe .descriptors import SOAP
12
- from dscribe .kernels import REMatchKernel
13
- from pymatgen .ext .matproj import MPRester
9
+ import dash_mp_components as mpc
14
10
from pymatgen .analysis .chemenv .coordination_environments .chemenv_strategies import (
15
11
SimplestChemenvStrategy ,
16
12
)
23
19
from pymatgen .analysis .chemenv .coordination_environments .structure_environments import (
24
20
LightStructureEnvironments ,
25
21
)
26
- from pymatgen .analysis .graphs import MoleculeGraph
27
- from pymatgen .analysis .graphs import StructureGraph
28
- from pymatgen .analysis .local_env import cn_opt_params , LocalStructOrderParams
22
+ from pymatgen .analysis .graphs import MoleculeGraph , StructureGraph
23
+ from pymatgen .analysis .local_env import LocalStructOrderParams , cn_opt_params
29
24
from pymatgen .core .structure import Molecule , Structure
25
+ from pymatgen .ext .matproj import MPRester
30
26
from pymatgen .io .ase import AseAtomsAdaptor
31
27
from pymatgen .symmetry .analyzer import SpacegroupAnalyzer
32
- from pymatgen .util .string import unicodeify_species , unicodeify
28
+ from pymatgen .util .string import unicodeify , unicodeify_species
33
29
from sklearn .preprocessing import normalize
34
30
35
31
from crystal_toolkit .components .structure import StructureMoleculeComponent
36
32
from crystal_toolkit .core .legend import Legend
37
33
from crystal_toolkit .core .panelcomponent import PanelComponent
38
34
from crystal_toolkit .helpers .layouts import (
39
- get_data_list ,
40
- Columns ,
41
- Column ,
42
- get_tooltip ,
43
- cite_me ,
44
- Loading ,
45
35
H5 ,
36
+ Column ,
37
+ Columns ,
46
38
Label ,
39
+ Loading ,
40
+ cite_me ,
41
+ get_data_list ,
42
+ get_tooltip ,
47
43
)
48
44
45
+ try :
46
+ from dscribe .descriptors import SOAP
47
+ from dscribe .kernels import REMatchKernel
48
+ except ImportError :
49
+ warn (
50
+ "Using dscribe SOAP and REMatchKernel requires the dscribe package "
51
+ "which was made optional since it in turn requires numba and numba "
52
+ "was a common source of installation issues."
53
+ )
54
+ SOAP = None
55
+
49
56
50
57
def _get_local_order_parameters (structure_graph , n ):
51
58
"""
@@ -530,6 +537,9 @@ def update_soap_analysis(struct, all_kwargs):
530
537
531
538
if not struct :
532
539
raise PreventUpdate
540
+
541
+ if not SOAP :
542
+ return mpc .Markdown ("This feature will not work unless `dscribe` is installed on the server." )
533
543
534
544
struct = self .from_data (struct )
535
545
kwargs = self .reconstruct_kwargs_from_state (callback_context .inputs )
@@ -563,7 +573,7 @@ def _get_all_structs_from_elements(elements):
563
573
564
574
with MPRester () as mpr :
565
575
docs = mpr .query (
566
- {"chemsys" : {"$in" : all_chemsyses }}, ["task_id" , "structure" ],
576
+ {"chemsys" : {"$in" : all_chemsyses }}, ["task_id" , "structure" ]
567
577
)
568
578
structs .update ({d ["task_id" ]: d ["structure" ] for d in docs })
569
579
return structs
@@ -577,6 +587,10 @@ def update_soap_similarities(struct, all_kwargs):
577
587
if not struct :
578
588
raise PreventUpdate
579
589
590
+ if not SOAP :
591
+ return mpc .Markdown ("This feature will not work unless `dscribe` is installed on the server." )
592
+
593
+
580
594
structs = {"input" : self .from_data (struct )}
581
595
kwargs = self .reconstruct_kwargs_from_state (callback_context .inputs )
582
596
@@ -706,7 +720,7 @@ def update_bondinggraph_analysis(graph, display_options):
706
720
}
707
721
708
722
return html .Div (
709
- [GraphComponent (graph = graph_data , options = options )],
723
+ [mpc . GraphComponent (graph = graph_data , options = options )],
710
724
style = {"width" : "65vmin" , "height" : "65vmin" },
711
725
)
712
726
0 commit comments