Skip to content

Commit

Permalink
Merge pull request #121 from Exabyte-io/feature/SOF-7351
Browse files Browse the repository at this point in the history
Feature/SOF-7351 update: show images of materials
  • Loading branch information
VsevolodX committed May 7, 2024
2 parents adbdf32 + 18dd9b6 commit 9aeadce
Show file tree
Hide file tree
Showing 6 changed files with 317 additions and 27 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -134,15 +134,15 @@
"cell_type": "code",
"outputs": [],
"source": [
"from utils.jupyterlite import get_data\n",
"from mat3ra.made.material import Material\n",
"from utils.jupyterlite import get_data\n",
"\n",
"from utils.visualize import visualize_materials as visualize\n",
"\n",
"# Get the list of input materials and load them into `materials_in` variable\n",
"get_data(\"materials_in\", globals())\n",
"materials = [] \n",
"for material_config in globals()[\"materials_in\"]:\n",
" print(material_config, \"\\n\")\n",
" materials.append(Material(material_config))"
"materials = list(map(Material, globals()[\"materials_in\"]))\n",
"visualize(materials, repetitions=[1,1,1], rotation=\"0x\")"
],
"metadata": {
"collapsed": false
Expand Down Expand Up @@ -274,15 +274,35 @@
"# Could be either the termination as tuple, e.g. `('Ni_P6/mmm_1', 'C_C2/m_2')` or its index: `0`\n",
"termination_or_its_index = 0\n",
"# select the first interface with the lowest strain and the smallest number of atoms\n",
"interfaces_slice_range_or_index = 0\n",
"interfaces_slice_range_or_index = slice(0,1)\n",
"selected_interfaces = interface_data_holder.get_interfaces_as_materials(termination_or_its_index, interfaces_slice_range_or_index)"
]
},
{
"cell_type": "markdown",
"source": [
"### 6.2. Visualize the selected interface(s)"
],
"metadata": {
"collapsed": false
}
},
{
"cell_type": "code",
"outputs": [],
"source": [
"visualize(selected_interfaces, repetitions=[1,1,1], rotation=\"0x\")"
],
"metadata": {
"collapsed": false
},
"execution_count": null
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"### 6.2. Pass data to the outside runtime\n"
"### 6.3. Pass data to the outside runtime\n"
]
},
{
Expand All @@ -292,7 +312,6 @@
"outputs": [],
"source": [
"from utils.jupyterlite import set_data\n",
"\n",
"set_data(\"materials\", selected_interfaces)"
]
}
Expand Down
81 changes: 81 additions & 0 deletions other/materials_designer/uploads/0-Ni.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
{
"name": "Ni, Nickel, FCC (Fm-3m) 3D (Bulk), mp-23",
"lattice": {
"a": 2.478974,
"b": 2.478974,
"c": 2.478974,
"alpha": 60,
"beta": 60,
"gamma": 60,
"units": {
"length": "angstrom",
"angle": "degree"
},
"type": "FCC",
"vectors": {
"a": [
2.146854,
0,
1.239487
],
"b": [
0.7156182,
2.024074,
1.239487
],
"c": [
0,
0,
2.478974
],
"alat": 1,
"units": "angstrom"
}
},
"basis": {
"elements": [
{
"id": 0,
"value": "Ni"
}
],
"coordinates": [
{
"id": 0,
"value": [
0,
0,
0
]
}
],
"units": "crystal",
"cell": [
[
2.146854,
0,
1.239487
],
[
0.7156182,
2.024074,
1.239487
],
[
0,
0,
2.478974
]
],
"constraints": []
},
"external": {
"id": "mp-23",
"source": "Materials Project",
"doi": "10.17188/1199153",
"url": "https://next-gen.materialsproject.org/materials/mp-23",
"origin": true
},
"isNonPeriodic": false,
"isUpdated": true
}
96 changes: 96 additions & 0 deletions other/materials_designer/uploads/1-Graphene.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
{
"name": "Graphene",
"basis": {
"elements": [
{
"id": 0,
"value": "C"
},
{
"id": 1,
"value": "C"
}
],
"coordinates": [
{
"id": 0,
"value": [
0,
0,
0
]
},
{
"id": 1,
"value": [
0.333333,
0.666667,
0
]
}
],
"units": "crystal",
"cell": [
[
2.467291,
0,
0
],
[
-1.2336454999,
2.1367366845,
0
],
[
0,
0,
20
]
],
"constraints": []
},
"lattice": {
"a": 2.467291,
"b": 2.467291,
"c": 20,
"alpha": 90,
"beta": 90,
"gamma": 120,
"units": {
"length": "angstrom",
"angle": "degree"
},
"type": "HEX",
"vectors": {
"a": [
2.467291,
0,
0
],
"b": [
-1.233645,
2.136737,
0
],
"c": [
0,
0,
20
],
"alat": 1,
"units": "angstrom"
}
},
"isNonPeriodic": false,
"external": {
"id": "mp-1040425",
"source": "materials project",
"doi": "10.17188/1405723",
"url": "https://next-gen.materialsproject.org/materials/mp-1040425/",
"origin": true
},
"metadata": {},
"schemaVersion": "2022.8.16",
"isDefault": false,
"_id": ""
}
1 change: 1 addition & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ dependencies = [
"pandas>=1.5.3",
"pymatgen>=2024.4.13",
"mat3ra-made>=2024.5.3.post0",
"mat3ra-utils"
]

[project.optional-dependencies]
Expand Down
37 changes: 18 additions & 19 deletions utils/plot.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from typing import Dict, Union

import plotly.graph_objs as go
from mat3ra.made.tools.build.interface import InterfaceDataHolder
from mat3ra.made.tools.build.interface import InterfaceDataHolder, StrainModes


def plot_strain_vs_atoms(interface_data_holder: InterfaceDataHolder, settings: Dict[str, Union[str, int]]):
Expand All @@ -12,32 +12,31 @@ def plot_strain_vs_atoms(interface_data_holder: InterfaceDataHolder, settings: D
interface_data_holder (InterfaceDataHolder): The interface data holder object.
settings (Dict[str, Union[str, int]]): The settings for the plot.
"""
sorted_interfaces = interface_data_holder.interfaces
sorted_interfaces = interface_data_holder.get_interfaces_for_termination(0)

data = []
for termination, interfaces in sorted_interfaces.items():
for index, interface in enumerate(interfaces):
strain_percentage = interface.get_mean_abs_strain() * 100
num_sites = interface.num_sites

hover_text = f"Index: {index}<br>Strain: {strain_percentage:.2f}%<br>Atoms: {num_sites}"

trace = go.Scatter(
x=[strain_percentage],
y=[num_sites],
text=[hover_text],
mode="markers",
hoverinfo="text",
name=f"Index: {index}",
)
data.append(trace)
for index, interface in enumerate(sorted_interfaces):
strain_percentage = interface.interface_properties[StrainModes.mean_abs_strain] * 100
num_sites = interface.num_sites

hover_text = f"Index: {index}<br>Strain: {strain_percentage:.2f}%<br>Atoms: {num_sites}"

trace = go.Scatter(
x=[strain_percentage],
y=[num_sites],
text=[hover_text],
mode="markers",
hoverinfo="text",
name=f"Index: {index}",
)
data.append(trace)

layout = go.Layout(
xaxis=dict(title="Strain (%)", type=settings["X_SCALE"]),
yaxis=dict(title="Number of atoms", type=settings["Y_SCALE"]),
hovermode="closest",
height=settings["HEIGHT"],
legend_title_text="Interfaces Index Range",
legend_title_text="Interfaces Indices",
)

fig = go.Figure(data=data, layout=layout)
Expand Down
Loading

0 comments on commit 9aeadce

Please sign in to comment.