File size: 5,523 Bytes
901176a
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
import dash
import dash_mp_components as dmp
from dash import dcc, html

display_columns = [
    "chemical_formula_descriptive",
    "functional",
    "immutable_id",
    "energy",
]

display_names = {
    "chemical_formula_descriptive": "Formula",
    "functional": "Functional",
    "immutable_id": "Material ID",
    "energy": "Energy (eV)",
}


def get_periodic_table(id, table_kwargs, **style_kwargs):

    return html.Div(
        [
            html.H3("Search Materials (eg. 'Ac,Cd,Ge' or 'Ac2CdGe3')"),
            html.Div(
                [
                    dmp.MaterialsInput(
                        allowedInputTypes=[
                            "elements",
                            "formula",
                        ],
                        hidePeriodicTable=False,
                        periodicTableMode="toggle",
                        hideWildcardButton=True,
                        showSubmitButton=True,
                        submitButtonText="Search",
                        type="elements",
                        **table_kwargs,
                        id=id,
                    ),
                ],
                id="materials-input-container",
                style={
                    "width": "100%",
                },
            ),
        ],
        className="container periodic-table",
    )


def get_dropdown(id, options, **style_kwargs):
    return dcc.Dropdown(
        id=id,
        options=options,
        placeholder="Embedder",
        value=None,
        clearable=False,
        style=style_kwargs,
    )


def get_upload_div(id, **style_kwargs):
    return html.Div(
        [
            html.H3("Upload a CIF file"),
            dcc.Upload(
                id=id,
                children=html.Div(
                    [
                        "Drag and Drop or ",
                        html.A("Select a CIF file"),
                    ]
                ),
                style={
                    "width": "100%",
                    "height": "60px",
                    "lineHeight": "60px",
                    "borderWidth": "1px",
                    "borderStyle": "dashed",
                    "borderRadius": "5px",
                    "textAlign": "center",
                    "margin": "10px",
                },
                multiple=False,
            ),
        ],
        className="container",
    )


def get_display_table(id, display_names, display_columns, text, **style_kwargs):

    return html.Div(
        [
            html.Label(
                text,
                style={"margin-bottom": "20px"},
            ),
            dash.dash_table.DataTable(
                id=id,
                columns=[
                    (
                        {
                            "name": display_names[col],
                            "id": col,
                        }
                        if col != "energy"
                        else {
                            "name": display_names[col],
                            "id": col,
                            "type": "numeric",
                            "format": {"specifier": ".2f"},
                        }
                    )
                    for col in display_columns
                ],
                data=[{}],
                style_cell={
                    "fontFamily": "Arial",
                    "padding": "10px",
                    "border": "1px solid #ddd",  # Subtle border for elegance
                    "textAlign": "left",
                    "fontSize": "14px",
                },
                style_header={
                    "backgroundColor": "#f5f5f5",  # Light grey header
                    "fontWeight": "bold",
                    "textAlign": "left",
                    "borderBottom": "2px solid #ddd",
                },
                style_data={
                    "backgroundColor": "#ffffff",
                    "color": "#333333",
                    "borderBottom": "1px solid #ddd",
                },
                style_data_conditional=[
                    {
                        "if": {"state": "active"},
                        "backgroundColor": "#e6f7ff",
                        "border": "1px solid #1890ff",
                    },
                ],
                style_table={
                    "maxHeight": "400px",
                    "overflowX": "auto",
                    "overflowY": "auto",
                },
                style_as_list_view=True,
                row_selectable="single",
                selected_rows=[],
            ),
        ],
        className="container",
    )


def get_materials_display(id, text_materials_div, text_table_div, **style_kwargs):
    return html.Div(
        [
            html.Div(
                [
                    html.Div(
                        text_materials_div,
                        style={"textAlign": "center"},
                    ),
                ],
                id=f"structure-container{id}",
                className="container container-visu",
            ),
            html.Div(
                id=f"properties-container{id}",
                className="container container-table",
                style={"width": "100%"},
                children=[
                    html.Div(
                        text_table_div,
                        style={"textAlign": "center"},
                    ),
                ],
            ),
        ],
        className="container-row",
    )