Skip to content
Open
6 changes: 5 additions & 1 deletion config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ notebooks:
- uncertainties==3.1.6
- ase==3.25.0
- ipywidgets
- plotly>=5.18
- plotly==5.24.1
- nbformat>=4.2.0
- emfs:/drive/packages/pymatgen-2024.4.13-py3-none-any.whl
- emfs:/drive/packages/spglib-2.0.2-py3-none-any.whl
Expand Down Expand Up @@ -53,6 +53,10 @@ notebooks:
packages_pyodide:
- mat3ra-standata
# - mat3ra-notebooks-utils[utils_standata]
- name: analyze_convex_hull
packages_pyodide:
- tqdm
- palettable
Comment on lines +56 to +59

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🗄️ Data Integrity & Integration | 🟠 Major | ⚡ Quick win

🧩 Analysis chain

🏁 Script executed:

#!/bin/bash
set -euo pipefail

echo "== config.yml (relevant sections) =="
python3 - <<'PY'
from pathlib import Path
p = Path('config.yml')
text = p.read_text().splitlines()
for i, line in enumerate(text, 1):
    if 'packages_pyodide' in line or 'analyze_convex_hull' in line or 'plotly' in line or 'default:' in line or 'made' in line:
        start = max(1, i-5)
        end = min(len(text), i+8)
        print(f"\n-- lines {start}-{end} around line {i} --")
        for j in range(start, end+1):
            print(f"{j:4}: {text[j-1]}")
PY

echo
echo "== search for install logic and plotly usage =="
rg -n "re\.search\(cfg\.get\(\"name\"\)|notebook_name_pattern|packages_pyodide|plot_convex_hull|import plotly|from plotly|plotly" -S .

Repository: mat3ra/api-examples

Length of output: 20125


Add plotly to analyze_convex_hull's Pyodide packages.
other/materials_designer/workflows/analyze_convex_hull.ipynb calls plot_convex_hull, and that helper imports Plotly. config.yml:56-59 only installs tqdm and palettable for this notebook; the plotly==5.24.1 pin under made won’t apply here, and default.packages_pyodide doesn’t include Plotly.

Proposed fix
   - name: analyze_convex_hull
     packages_pyodide:
       - tqdm
       - palettable
+      - plotly==5.24.1
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
- name: analyze_convex_hull
packages_pyodide:
- tqdm
- palettable
- name: analyze_convex_hull
packages_pyodide:
- tqdm
- palettable
- plotly==5.24.1
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@config.yml` around lines 56 - 59, The analyze_convex_hull notebook
environment is missing Plotly in its Pyodide package list, so plot_convex_hull
can fail when the notebook imports it. Update the analyze_convex_hull entry in
config.yml by adding plotly to packages_pyodide alongside tqdm and palettable,
since the made pin and default.packages_pyodide do not apply here. Use the
analyze_convex_hull notebook config block to locate the change.

- name: api
packages_pyodide:
- annotated_types>=0.6.0
Expand Down
201 changes: 201 additions & 0 deletions other/materials_designer/create_solid_solution.ipynb
Original file line number Diff line number Diff line change
@@ -0,0 +1,201 @@
{
"cells": [
{
"cell_type": "markdown",
"id": "0",
"metadata": {},
"source": [
"# Create Solid Solution (Mixed Stoichiometry)\n",
"\n",
"Create a solid solution by partially substituting one element with another\n",
"(e.g., Hf₁₋ₓZrₓO₂). Automatically determines optimal supercell size to achieve\n",
"the target concentration.\n",
"\n",
"<h2 style=\"color:green\">Usage</h2>\n",
"\n",
"1. Make sure to select Input Materials (in the outer runtime) before running the notebook.\n",
"1. Set parameters in cell 1.1. below.\n",
"1. Click \"Run\" > \"Run All\" to run all cells.\n",
"1. Scroll down to view results.\n",
"\n",
"## Notes\n",
"\n",
"1. For more information, see [Introduction](Introduction.ipynb)"
]
},
{
"cell_type": "markdown",
"id": "1",
"metadata": {},
"source": [
"## 1. Prepare the Environment\n",
"### 1.1. Set solid solution parameters"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "2",
"metadata": {},
"outputs": [],
"source": [
"SOURCE_ELEMENT = \"Ni\" # Element to partially replace\n",
"TARGET_ELEMENT = \"Co\" # Replacement element\n",
"CONCENTRATION = 0.5 # Fraction of SOURCE_ELEMENT sites to replace (0–1)\n",
"\n",
"# Site selection: \"random\" or \"uniform\" (Farthest Point Sampling for even spacing)\n",
"SITE_SELECTION_METHOD = \"uniform\"\n",
"\n",
"# Random seed for reproducible site selection\n",
"SEED = 0\n",
"\n",
"# Tolerance for matching target concentration (smaller = larger supercell)\n",
"TOLERANCE = 0.01"
]
},
{
"cell_type": "markdown",
"id": "3",
"metadata": {},
"source": [
"### 1.2. Install Packages\n",
"The step executes only in Pyodide environment. For other environments, the packages should be installed via `pip install` (see [README](../../README.ipynb))."
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "4",
"metadata": {},
"outputs": [],
"source": [
"from mat3ra.notebooks_utils.packages import install_packages\n",
"\n",
"await install_packages(\"made\")"
]
},
{
"cell_type": "markdown",
"id": "5",
"metadata": {},
"source": [
"### 1.3. Get input materials"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "6",
"metadata": {},
"outputs": [],
"source": [
"from mat3ra.notebooks_utils.material import get_materials\n",
"\n",
"materials = get_materials(globals())"
]
},
Comment on lines +92 to +96

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🩺 Stability & Availability | 🟠 Major | ⚡ Quick win

Guard against empty/missing input materials before indexing.

get_materials(globals()) can legitimately return an empty list (e.g., no materials selected and none found in the uploads folder, per load_materials_from_folder fallback), in which case materials[0] at line 114 raises an unguarded IndexError with no actionable message. Also note only the first material is ever processed/exported — any additional selected materials are silently discarded without notice.

🛡️ Proposed fix
 from mat3ra.made.tools.helpers import create_solid_solution
 
-unit_cell = materials[0]
+if not materials:
+    raise ValueError("No input materials found. Select a material before running this notebook.")
+if len(materials) > 1:
+    print(f"Warning: {len(materials)} materials selected; only the first one will be used.")
+unit_cell = materials[0]
 solid_solution = create_solid_solution(

Also applies to: 111-136

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@other/materials_designer/create_solid_solution.ipynb` around lines 92 - 96,
Guard the material selection flow in create_solid_solution.ipynb before using
materials[0]: get_materials(globals()) can return an empty list, so add an
explicit empty-check and fail with a clear message instead of allowing an
IndexError. Also handle the case where multiple materials are returned by either
validating that exactly one material is selected or explicitly
documenting/selecting the intended first item in the solid-solution setup logic.
Keep the fix centered around the materials variable and the downstream
indexing/processing block that uses materials[0].

{
"cell_type": "markdown",
"id": "7",
"metadata": {},
"source": [
"## 2. Create Solid Solution"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "8",
"metadata": {},
"outputs": [],
"source": [
"from mat3ra.made.tools.helpers import create_solid_solution\n",
"\n",
"unit_cell = materials[0]\n",
"solid_solution = create_solid_solution(\n",
" material=unit_cell,\n",
" source_element=SOURCE_ELEMENT,\n",
" target_element=TARGET_ELEMENT,\n",
" concentration=CONCENTRATION,\n",
" seed=SEED,\n",
" tolerance=TOLERANCE,\n",
" site_selection_method=SITE_SELECTION_METHOD,\n",
")\n",
"\n",
"from collections import Counter\n",
"composition = Counter(solid_solution.basis.elements.values)\n",
"n_cation = composition.get(SOURCE_ELEMENT, 0) + composition.get(TARGET_ELEMENT, 0)\n",
"actual_fraction = composition.get(TARGET_ELEMENT, 0) / n_cation if n_cation else 0\n",
"\n",
"print(f\"Unit cell: {unit_cell.name}\")\n",
"print(f\"Composition: {dict(composition)}\")\n",
"print(f\"Total atoms: {sum(composition.values())}\")\n",
"print(f\"Requested concentration: {CONCENTRATION}\")\n",
"print(f\"Actual concentration: {actual_fraction:.4f}\")\n",
"print(f\"Site selection method: {SITE_SELECTION_METHOD}\")"
]
},
{
"cell_type": "markdown",
"id": "9",
"metadata": {},
"source": [
"## 3. Visualize Result(s)"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "10",
"metadata": {},
"outputs": [],
"source": [
"from mat3ra.notebooks_utils.ipython.entity.material.visualize import visualize_materials as visualize\n",
"\n",
"visualize(\n",
" {\"material\": solid_solution, \"title\": f\"Solid Solution: {dict(composition)}\"}, viewer=\"wave\")"
]
},
{
"cell_type": "markdown",
"id": "11",
"metadata": {},
"source": [
"## 4. Pass data to the outside runtime"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "12",
"metadata": {},
"outputs": [],
"source": [
"from mat3ra.notebooks_utils.material import set_materials\n",
"\n",
"set_materials([solid_solution])"
]
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbformat_minor": 5,
"pygments_lexer": "ipython3",
"version": "3.11.2"
}
Comment on lines +186 to +197

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🗄️ Data Integrity & Integration | 🟡 Minor | ⚡ Quick win

Remove stray nbformat_minor key nested inside language_info.

"nbformat_minor": 5 at line 194 is duplicated inside language_info, where it doesn't belong per the nbformat metadata schema (it's already correctly set at the top level, line 200). Likely a leftover from the metadata-append step.

🧹 Proposed fix
    "file_extension": ".py",
    "mimetype": "text/x-python",
    "name": "python",
-   "nbformat_minor": 5,
    "pygments_lexer": "ipython3",
    "version": "3.11.2"
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbformat_minor": 5,
"pygments_lexer": "ipython3",
"version": "3.11.2"
}
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"pygments_lexer": "ipython3",
"version": "3.11.2"
}
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@other/materials_designer/create_solid_solution.ipynb` around lines 186 - 197,
Remove the stray nbformat_minor entry from the notebook metadata nested under
language_info in create_solid_solution.ipynb; keep the top-level nbformat_minor
setting only. Update the language_info JSON object so it contains only
language/runtime fields like codemirror_mode, file_extension, mimetype, name,
pygments_lexer, and version, without the duplicated nbformat_minor key.

},
"nbformat": 4,
"nbformat_minor": 5
}
10 changes: 7 additions & 3 deletions other/materials_designer/workflows/Introduction.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@
"### 4.2. Band Structure\n",
"#### [4.2.1. Band Structure / Band Structure + DOS.](band_structure.ipynb)\n",
"#### [4.2.2. Band Structure (HSE).](band_structure_hse.ipynb)\n",
"#### 4.2.3. Band Structure (Magnetic). *(to be added)*\n",
"#### [4.2.3. Band Structure (Magnetic).](band_structure_magn.ipynb)\n",
"#### 4.2.4. Band Structure (Spin-Orbit Coupling). *(to be added)*\n",
"\n",
"\n",
Expand All @@ -71,8 +71,12 @@
"### 6.5. Defect Energy\n",
"#### 6.5.1. Defect formation energy. *(to be added)*\n",
"\n",
"### 6.6. Formation Energy\n",
"#### 6.6.1. Compound formation energy. *(to be added)*\n",
"### 6.6. Phase Stability\n",
"#### [6.6.1. Formation Energies and Convex Hull.](analyze_convex_hull.ipynb)\n",
"#### [6.6.2. Phase Diagram.](generate_phase_diagram.ipynb)\n",
"\n",
"### 6.7. Formation Energy\n",
"#### 6.7.1. Compound formation energy. *(to be added)*\n",
"\n",
"\n",
"## 7. Chemistry\n",
Expand Down
Loading
Loading