def render_graph(batt_id): query_path = {'battid': batt_id} result = list(mongo_coll_path.find(query_path)) if result and result[0]['intercalating_paths']: intercalating_paths = result[0]['intercalating_paths'] hops = result[0]['hops'] fss = Structure.from_dict(result[0]['full_sites_struct']) bs = Structure.from_dict(result[0]['base_structure']) graph_result = migration_graph(intercalating_paths, hops, fss, bs) else: print('No intercalating path available') id_discharge = int( list(mongo_coll.find(query_path))[0]['id_discharge']) struct_dict = list(mongo_coll_mat.find({'task_id': id_discharge}))[0]['structure'] graph_result = ctc.StructureMoleculeComponent( Structure.from_dict(struct_dict), static=True) return graph_result.struct_layout
from dash_mp_components import JsonView # import for this example from pymatgen import Structure, Lattice # create Dash app as normal app = dash.Dash() # create the Structure object structure = Structure(Lattice.cubic(4.2), ["Na", "K"], [[0, 0, 0], [0.5, 0.5, 0.5]]) from pymatgen import MPRester # create an input structure as an example structure_component = ctc.StructureMoleculeComponent( MPRester().get_structure_by_material_id("mp-804"), id="structure_in") # and a way to view the transformed structure structure_component_transformed = ctc.StructureMoleculeComponent( MPRester().get_structure_by_material_id("mp-804"), id="structure_out") # and the transformation component itself transformation_component = ctc.AllTransformationsComponent( input_structure_component=structure_component, ) # example layout to demonstrate capabilities of component my_layout = html.Div([ html.H1("TransformationComponent Example"), html.H2("Standard Layout"), transformation_component.layout(), html.H3("Example Input Structure"), structure_component.layout(size="500px"),
# standard Dash imports for callbacks (interactivity) from dash.dependencies import Input, Output, State from dash.exceptions import PreventUpdate from pymatgen import Structure, Lattice app = dash.Dash() # now we give a list of structures to pick from structures = [ Structure(Lattice.cubic(4), ["Na", "Cl"], [[0, 0, 0], [0.5, 0.5, 0.5]]), Structure(Lattice.cubic(5), ["K", "Cl"], [[0, 0, 0], [0.5, 0.5, 0.5]]), ] # we show the first structure by default structure_component = ctc.StructureMoleculeComponent(structures[0]) # and we create a button for user interaction my_button = html.Button("Swap Structure", id="change_structure_button") # now we have two entries in our app layout, # the structure component's layout and the button my_layout = html.Div([structure_component.layout(), my_button]) ctc.register_crystal_toolkit(app=app, layout=my_layout, cache=None) # for the interactivity, we use a standard Dash callback @app.callback( Output(structure_component.id(), "data"), [Input("change_structure_button", "n_clicks")],
import dash from dash import html from dash import dcc from dash.dependencies import Input, Output, State from pymatgen.symmetry.analyzer import SpacegroupAnalyzer import crystal_toolkit.components as ctc SCREENSHOT_PATH = Path.home() / "screenshots" app = dash.Dash() server = app.server structure_component = ctc.StructureMoleculeComponent( show_compass=False, bonded_sites_outside_unit_cell=True, scene_settings={"zoomToFit2D": True}, ) my_layout = html.Div([ structure_component.layout(), dcc.Location(id="url"), html.Div(id="dummy-output") ]) def get_structure_for_mpid(mpid): from pymatgen.ext.matproj import MPRester with MPRester() as mpr: structure = mpr.get_structure_by_material_id(mpid)
def upload_structure(poscar_1, poscar_2): a = StructureMatcher(poscar_1, poscar_2, float(20), float(5)) return ctc.StructureMoleculeComponent(a[1][0])
transformation_component = ctc.AllTransformationsComponent( transformations=[ "SupercellTransformationComponent", "AutoOxiStateDecorationTransformationComponent", "CubicSupercellTransformationComponent", "GrainBoundaryTransformationComponent", "MonteCarloRattleTransformationComponent", "SlabTransformationComponent", "SubstitutionTransformationComponent", ] ) struct_component = ctc.StructureMoleculeComponent( links={"default": transformation_component.id()} ) robocrys_panel = ctc.RobocrysComponent(links={"default": transformation_component.id()}) xrd_panel = ctc.XRayDiffractionPanelComponent( links={"default": transformation_component.id()} ) # pbx_component = ctc.PourbaixDiagramPanelComponent(origin_component=struct_component) # symmetry_panel = ctc.SymmetryPanel(links={"default": struct_component.id()}) localenv_panel = ctc.LocalEnvironmentPanel( links={ "default": struct_component.id(), "graph": struct_component.id("graph"), "display_options": struct_component.id("display_options"), }
import crystal_toolkit.components as ctc # create Dash app as normal app = dash.Dash() # create the Structure object structure = Structure( Lattice.cubic(3.0), ["Ni", "Ti"], [[0, 0, 0], [0.5, 0.5, 0.5]], site_properties={"magmom": [[-2.0, 1.0, 0.0], [1.0, 1.0, -1.0]]}, # site_properties={"magmom": [3.0, -2.0]}, ) # create the Crystal Toolkit component structure_component = ctc.StructureMoleculeComponent(structure, id="struct") # example layout to demonstrate capabilities of component my_layout = html.Div([ html.H1("StructureMoleculeComponent Example"), html.H2("Standard Layout"), structure_component.layout(size="400px"), html.H2("Optional Additional Layouts"), html.H3("Screenshot Layout"), structure_component.screenshot_layout(), html.H3("Options Layout"), structure_component.options_layout(), html.H3("Title Layout"), structure_component.title_layout(), html.H3("Legend Layout"), structure_component.legend_layout(),
# as explained in "preamble" section in documentation import dash from dash import html from dash import dcc import crystal_toolkit.components as ctc # app = dash.Dash(external_stylesheets=['https://cdnjs.cloudflare.com/ajax/libs/bulma/0.7.2/css/bulma.min.css']) app = dash.Dash() # create our crystal structure using pymatgen from pymatgen.core.structure import Structure from pymatgen.core.lattice import Lattice structure = Structure(Lattice.cubic(4.2), ["Na", "K"], [[0, 0, 0], [0.5, 0.5, 0.5]]) # create the Crystal Toolkit component structure_component = ctc.StructureMoleculeComponent(structure, id="hello_structure") # add the component's layout to our app's layout my_layout = html.Div([structure_component.layout()]) # as explained in "preamble" section in documentation ctc.register_crystal_toolkit(app=app, layout=my_layout) if __name__ == "__main__": app.run_server(debug=True, port=8050)
import dash_core_components as dcc import dash_html_components as html from dash.dependencies import Input, Output from dash.exceptions import PreventUpdate import crystal_toolkit.components as ct from pymatgen import Structure from atomate_gui.app import app, collection from atomate_gui.apps.info import InfoApp from atomate_gui.apps.search import SearchApp ct.register_app(app) struct_component = ct.StructureMoleculeComponent() struct_layout = html.Div( [ struct_component.all_layouts["title"], struct_component.all_layouts["legend"], struct_component.all_layouts["options"], struct_component.all_layouts["screenshot"] ], id='visualizer-tools', ) app.layout = html.Div([ dcc.Location(id='url', refresh=False), ct.MPComponent.all_app_stores(), html.Div( id='header', children=html.H1('Materials Searcher.', ), ),
vertices, faces = get_mesh(cc) vertices = vertices pos = [vert for triangle in vertices[faces].tolist() for vert in triangle] add_comp = [ ctc.Scene( "test", contents=[ ctc.Surface(positions=pos), ctc.Arrows(positionPairs=[[[0, 0, 0], [1, 1, 1]]]), ], ) ] struct_component = ctc.StructureMoleculeComponent(cc.structure, scene_additions=add_comp, hide_incomplete_bonds=True # get the data points to plot ) # for a custom-sized component, use `struct_component.struct_layout` and put # it inside a Div of the required size app.layout = html.Div([ ctc.MPComponent.all_app_stores( ), # not required in this minimal example, but usually necessary for interactivity struct_component.standard_layout, ]) if __name__ == "__main__": app.run_server(debug=True)
from fastapi import FastAPI from fastapi.middleware.wsgi import WSGIMiddleware EXTERNAL_STYLESHEETS = [ "./assets/style.css", "./assets/vis.min.css", dbc.themes.BOOTSTRAP, ] # ToDo: Maybe initialize with HKUST STRUCTURE = Structure(Lattice.cubic(4.2), ["Na", "K"], [[0, 0, 0], [0.5, 0.5, 0.5]]) structure_component = ctc.StructureMoleculeComponent( # pylint:disable=invalid-name STRUCTURE, id="structure", bonding_strategy="JmolNN", color_scheme="Jmol", ) dash_app = dash.Dash( # pylint:disable=invalid-name __name__, external_stylesheets=EXTERNAL_STYLESHEETS, meta_tags=[ { "charset": "utf-8" }, { "http-equiv": "X-UA-Compatible", "content": "IE=edge" }, # needed for iframe resizer
from dash.dependencies import Input, Output, State from dash.exceptions import PreventUpdate from pymatgen.core.structure import Structure from pymatgen.core.lattice import Lattice app = dash.Dash() # now we give a list of structures to pick from structures = [ Structure(Lattice.cubic(4), ["Na", "Cl"], [[0, 0, 0], [0.5, 0.5, 0.5]]), Structure(Lattice.cubic(5), ["K", "Cl"], [[0, 0, 0], [0.5, 0.5, 0.5]]), ] # we show the first structure by default structure_component = ctc.StructureMoleculeComponent(structures[0], id="my_structure") # and we create a button for user interaction my_button = html.Button("Swap Structure", id="change_structure_button") # now we have two entries in our app layout, # the structure component's layout and the button my_layout = html.Div([structure_component.layout(), my_button]) ctc.register_crystal_toolkit(app=app, layout=my_layout) # for the interactivity, we use a standard Dash callback @app.callback( Output(structure_component.id(), "data"), [Input("change_structure_button", "n_clicks")],
app.css.config.serve_locally = True app.title = "Crystal Toolkit Example Components" # so that Crystal Toolkit can create callbacks # ctc.register_app(app) # StructureMoleculeComponent example_struct = Structure.from_spacegroup( "P6_3mc", Lattice.hexagonal(3.22, 5.24), ["Ga", "N"], [[1 / 3, 2 / 3, 0], [1 / 3, 2 / 3, 3 / 8]], ) # instantiate a component to view structures struct_component = ctc.StructureMoleculeComponent( example_struct # this is a pymatgen Structure ) # for a custom-sized component, use `struct_component.struct_layout` and put # it inside a Div of the required size app.layout = html.Div([ ctc.MPComponent.all_app_stores( ), # not required in this minimal example, but usually necessary for interactivity struct_component.standard_layout ]) if __name__ == "__main__": app.run_server(debug=True)
# needed for iframe resizer { 'name': 'viewport', 'content': 'width=device-width, initial-scale=1' }, ], ) server = app.server # pylint:disable=invalid-name app.title = 'mofcolorizer' STRUCTURE = Structure(Lattice.cubic(4.2), ['Na', 'K'], [[0, 0, 0], [0.5, 0.5, 0.5]]) structure_component = ctc.StructureMoleculeComponent( # pylint:disable=invalid-name STRUCTURE, id='structure', bonding_strategy='JmolNN', color_scheme='Jmol', ) layout = html.Div( # pylint:disable=invalid-name [ dcc.Store(id='memorystore'), html.Div( [ html.Div( [ html.H1(['MOF', html.I('colorizer')], className='display-3', id='h1'), html.P( 'This model attempts to predict the color of MOFs.', className='lead', ),