{
"cells": [
{
"cell_type": "markdown",
"id": "ba904ebb-c42c-4469-872f-dbf0f8cef3c8",
"metadata": {},
"source": [
"Making Predictions with GlassPy\n",
"===============================\n",
"\n",
"**Author:** Daniel R. Cassar\n",
"\n"
]
},
{
"cell_type": "markdown",
"id": "ccfd5b68-f4dd-45e4-a546-b82f25695a68",
"metadata": {},
"source": [
"## Introduction\n",
"\n"
]
},
{
"cell_type": "markdown",
"id": "f10f97ca-d23f-4d9a-8b60-72043f1c1764",
"metadata": {},
"source": [
"GlassPy provides three prediction models: `GlassNet`, `VITRIFY`, and `ViscNet`.\n",
"\n",
"- `GlassNet` is a multitask deep neural network that predicts 85 glass properties and the temperature dependence of viscosity.\n",
"- `VITRIFY` is a classification model that estimates the probability of a given composition forming a glass.\n",
"- `ViscNet` is a physics-informed deep neural network designed specifically to predict the temperature dependence of viscosity.\n",
"\n",
"All three models were trained on data from the SciGlass database.\n",
"\n"
]
},
{
"cell_type": "markdown",
"id": "af4db9cb-1101-490b-87ae-434940df1459",
"metadata": {},
"source": [
"## GlassNet basic usage\n",
"\n"
]
},
{
"cell_type": "markdown",
"id": "908d76f4-c680-4fb1-9dd8-ff5504a59dc2",
"metadata": {},
"source": [
"Below is a minimal example of how to load and use the GlassNet model.\n",
"\n"
]
},
{
"cell_type": "code",
"execution_count": 1,
"id": "e7647470-9e5b-4a63-9113-3c5408301cb0",
"metadata": {},
"outputs": [
{
"data": {
"text/html": [
"
\n",
"\n",
"
\n",
" \n",
" \n",
" | \n",
" T0 | \n",
" T1 | \n",
" T2 | \n",
" T3 | \n",
" T4 | \n",
" T5 | \n",
" T6 | \n",
" T7 | \n",
" T8 | \n",
" T9 | \n",
" ... | \n",
" Cp1673K | \n",
" TMaxGrowthVelocity | \n",
" MaxGrowthVelocity | \n",
" CrystallizationPeak | \n",
" CrystallizationOnset | \n",
" SurfaceTensionAboveTg | \n",
" SurfaceTension1173K | \n",
" SurfaceTension1473K | \n",
" SurfaceTension1573K | \n",
" SurfaceTension1673K | \n",
"
\n",
" \n",
" \n",
" \n",
" | 0 | \n",
" 1612.586818 | \n",
" 1286.966695 | \n",
" 1187.265614 | \n",
" 1070.224145 | \n",
" 968.06795 | \n",
" 901.811624 | \n",
" 859.579252 | \n",
" 825.204682 | \n",
" 782.490883 | \n",
" 759.993951 | \n",
" ... | \n",
" 1717.653045 | \n",
" 1040.284178 | \n",
" -6.241866 | \n",
" 937.262437 | \n",
" 788.40385 | \n",
" 0.316586 | \n",
" 0.3044 | \n",
" 0.321539 | \n",
" 0.318579 | \n",
" 0.319566 | \n",
"
\n",
" \n",
"
\n",
"
1 rows × 85 columns
\n",
"
"
],
"text/plain": [
" T0 T1 T2 T3 T4 T5 \\\n",
"0 1612.586818 1286.966695 1187.265614 1070.224145 968.06795 901.811624 \n",
"\n",
" T6 T7 T8 T9 ... Cp1673K \\\n",
"0 859.579252 825.204682 782.490883 759.993951 ... 1717.653045 \n",
"\n",
" TMaxGrowthVelocity MaxGrowthVelocity CrystallizationPeak \\\n",
"0 1040.284178 -6.241866 937.262437 \n",
"\n",
" CrystallizationOnset SurfaceTensionAboveTg SurfaceTension1173K \\\n",
"0 788.40385 0.316586 0.3044 \n",
"\n",
" SurfaceTension1473K SurfaceTension1573K SurfaceTension1673K \n",
"0 0.321539 0.318579 0.319566 \n",
"\n",
"[1 rows x 85 columns]"
]
},
"execution_count": 1,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"from glasspy.predict import GlassNet\n",
"\n",
"model = GlassNet()\n",
"composition = \"Li2O(SiO2)2\"\n",
"predictions = model.predict(composition)\n",
"\n",
"predictions"
]
},
{
"cell_type": "markdown",
"id": "cf662bde-e8ff-4a62-8a51-04e77a51872c",
"metadata": {},
"source": [
"A composition can also be defined using a dictionary.\n",
"\n"
]
},
{
"cell_type": "code",
"execution_count": 2,
"id": "4c41d59c-1161-49fd-bbac-8da67fe05619",
"metadata": {},
"outputs": [
{
"data": {
"text/html": [
"\n",
"\n",
"
\n",
" \n",
" \n",
" | \n",
" T0 | \n",
" T1 | \n",
" T2 | \n",
" T3 | \n",
" T4 | \n",
" T5 | \n",
" T6 | \n",
" T7 | \n",
" T8 | \n",
" T9 | \n",
" ... | \n",
" Cp1673K | \n",
" TMaxGrowthVelocity | \n",
" MaxGrowthVelocity | \n",
" CrystallizationPeak | \n",
" CrystallizationOnset | \n",
" SurfaceTensionAboveTg | \n",
" SurfaceTension1173K | \n",
" SurfaceTension1473K | \n",
" SurfaceTension1573K | \n",
" SurfaceTension1673K | \n",
"
\n",
" \n",
" \n",
" \n",
" | 0 | \n",
" 1612.586818 | \n",
" 1286.966695 | \n",
" 1187.265614 | \n",
" 1070.224145 | \n",
" 968.06795 | \n",
" 901.811624 | \n",
" 859.579252 | \n",
" 825.204682 | \n",
" 782.490883 | \n",
" 759.993951 | \n",
" ... | \n",
" 1717.653045 | \n",
" 1040.284178 | \n",
" -6.241866 | \n",
" 937.262437 | \n",
" 788.40385 | \n",
" 0.316586 | \n",
" 0.3044 | \n",
" 0.321539 | \n",
" 0.318579 | \n",
" 0.319566 | \n",
"
\n",
" \n",
"
\n",
"
1 rows × 85 columns
\n",
"
"
],
"text/plain": [
" T0 T1 T2 T3 T4 T5 \\\n",
"0 1612.586818 1286.966695 1187.265614 1070.224145 968.06795 901.811624 \n",
"\n",
" T6 T7 T8 T9 ... Cp1673K \\\n",
"0 859.579252 825.204682 782.490883 759.993951 ... 1717.653045 \n",
"\n",
" TMaxGrowthVelocity MaxGrowthVelocity CrystallizationPeak \\\n",
"0 1040.284178 -6.241866 937.262437 \n",
"\n",
" CrystallizationOnset SurfaceTensionAboveTg SurfaceTension1173K \\\n",
"0 788.40385 0.316586 0.3044 \n",
"\n",
" SurfaceTension1473K SurfaceTension1573K SurfaceTension1673K \n",
"0 0.321539 0.318579 0.319566 \n",
"\n",
"[1 rows x 85 columns]"
]
},
"execution_count": 2,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"composition = {\n",
" \"SiO2\": 2,\n",
" \"Li2O\": 1,\n",
"}\n",
"predictions = model.predict(composition)\n",
"\n",
"predictions"
]
},
{
"cell_type": "markdown",
"id": "4ecc9e9d-214a-4fab-b7ff-78bba64f3004",
"metadata": {},
"source": [
"GlassNet also accepts `pandas` DataFrames as input. Note that each row represents a material and that only columns related to chemical composition can be present in the DataFrame.\n",
"\n"
]
},
{
"cell_type": "code",
"execution_count": 3,
"id": "49cb9218-6913-4dfb-9b3e-28e970b7bce0",
"metadata": {},
"outputs": [
{
"data": {
"text/html": [
"\n",
"\n",
"
\n",
" \n",
" \n",
" | \n",
" Li2O | \n",
" Na2O | \n",
" SiO2 | \n",
"
\n",
" \n",
" \n",
" \n",
" | 0 | \n",
" 1 | \n",
" 0 | \n",
" 2 | \n",
"
\n",
" \n",
" | 1 | \n",
" 0 | \n",
" 1 | \n",
" 2 | \n",
"
\n",
" \n",
" | 2 | \n",
" 1 | \n",
" 1 | \n",
" 2 | \n",
"
\n",
" \n",
"
\n",
"
"
],
"text/plain": [
" Li2O Na2O SiO2\n",
"0 1 0 2\n",
"1 0 1 2\n",
"2 1 1 2"
]
},
"execution_count": 3,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"import pandas as pd\n",
"\n",
"data = [\n",
" [1, 0, 2],\n",
" [0, 1, 2],\n",
" [1, 1, 2],\n",
"]\n",
"\n",
"df = pd.DataFrame(data, columns=[\"Li2O\", \"Na2O\", \"SiO2\"])\n",
"df"
]
},
{
"cell_type": "code",
"execution_count": 4,
"id": "e0b62145-9078-4685-b371-e6f18f99dde6",
"metadata": {},
"outputs": [
{
"data": {
"text/html": [
"\n",
"\n",
"
\n",
" \n",
" \n",
" | \n",
" T0 | \n",
" T1 | \n",
" T2 | \n",
" T3 | \n",
" T4 | \n",
" T5 | \n",
" T6 | \n",
" T7 | \n",
" T8 | \n",
" T9 | \n",
" ... | \n",
" Cp1673K | \n",
" TMaxGrowthVelocity | \n",
" MaxGrowthVelocity | \n",
" CrystallizationPeak | \n",
" CrystallizationOnset | \n",
" SurfaceTensionAboveTg | \n",
" SurfaceTension1173K | \n",
" SurfaceTension1473K | \n",
" SurfaceTension1573K | \n",
" SurfaceTension1673K | \n",
"
\n",
" \n",
" \n",
" \n",
" | 0 | \n",
" 1612.586818 | \n",
" 1286.966759 | \n",
" 1187.265614 | \n",
" 1070.224201 | \n",
" 968.067993 | \n",
" 901.811569 | \n",
" 859.579252 | \n",
" 825.204682 | \n",
" 782.490883 | \n",
" 759.993951 | \n",
" ... | \n",
" 1717.653120 | \n",
" 1040.284178 | \n",
" -6.241865 | \n",
" 937.262560 | \n",
" 788.403850 | \n",
" 0.316586 | \n",
" 0.304400 | \n",
" 0.321539 | \n",
" 0.318579 | \n",
" 0.319566 | \n",
"
\n",
" \n",
" | 1 | \n",
" 1700.171170 | \n",
" 1521.813466 | \n",
" 1287.576204 | \n",
" 1130.354623 | \n",
" 1036.780176 | \n",
" 955.844950 | \n",
" 911.027803 | \n",
" 848.791035 | \n",
" 810.406750 | \n",
" 782.243953 | \n",
" ... | \n",
" 1482.022135 | \n",
" 1058.443194 | \n",
" -6.394961 | \n",
" 963.434464 | \n",
" 905.734703 | \n",
" 0.279031 | \n",
" 0.310337 | \n",
" 0.290839 | \n",
" 0.287974 | \n",
" 0.272271 | \n",
"
\n",
" \n",
" | 2 | \n",
" 1457.627094 | \n",
" 1246.016165 | \n",
" 1114.455164 | \n",
" 987.722016 | \n",
" 934.740619 | \n",
" 861.280868 | \n",
" 794.972760 | \n",
" 769.729834 | \n",
" 730.195119 | \n",
" 700.667308 | \n",
" ... | \n",
" 1751.036502 | \n",
" 1082.912718 | \n",
" -5.101020 | \n",
" 875.732689 | \n",
" 820.388535 | \n",
" 0.299141 | \n",
" 0.308964 | \n",
" 0.319907 | \n",
" 0.321466 | \n",
" 0.294990 | \n",
"
\n",
" \n",
"
\n",
"
3 rows × 85 columns
\n",
"
"
],
"text/plain": [
" T0 T1 T2 T3 T4 \\\n",
"0 1612.586818 1286.966759 1187.265614 1070.224201 968.067993 \n",
"1 1700.171170 1521.813466 1287.576204 1130.354623 1036.780176 \n",
"2 1457.627094 1246.016165 1114.455164 987.722016 934.740619 \n",
"\n",
" T5 T6 T7 T8 T9 ... \\\n",
"0 901.811569 859.579252 825.204682 782.490883 759.993951 ... \n",
"1 955.844950 911.027803 848.791035 810.406750 782.243953 ... \n",
"2 861.280868 794.972760 769.729834 730.195119 700.667308 ... \n",
"\n",
" Cp1673K TMaxGrowthVelocity MaxGrowthVelocity CrystallizationPeak \\\n",
"0 1717.653120 1040.284178 -6.241865 937.262560 \n",
"1 1482.022135 1058.443194 -6.394961 963.434464 \n",
"2 1751.036502 1082.912718 -5.101020 875.732689 \n",
"\n",
" CrystallizationOnset SurfaceTensionAboveTg SurfaceTension1173K \\\n",
"0 788.403850 0.316586 0.304400 \n",
"1 905.734703 0.279031 0.310337 \n",
"2 820.388535 0.299141 0.308964 \n",
"\n",
" SurfaceTension1473K SurfaceTension1573K SurfaceTension1673K \n",
"0 0.321539 0.318579 0.319566 \n",
"1 0.290839 0.287974 0.272271 \n",
"2 0.319907 0.321466 0.294990 \n",
"\n",
"[3 rows x 85 columns]"
]
},
"execution_count": 4,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"predictions = model.predict(df)\n",
"\n",
"predictions"
]
},
{
"cell_type": "markdown",
"id": "93f9f6e2-5beb-4ac7-98c4-30f684bbf63b",
"metadata": {},
"source": [
"GlassNet can also predict viscosity and the MYEGA viscosity equation parameters.\n",
"\n"
]
},
{
"cell_type": "code",
"execution_count": 5,
"id": "9021f4d9-47c6-4df5-9a57-81091a27d41c",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"array([3.53501871, 4.40572086, 2.83984945])"
]
},
"execution_count": 5,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"predictions = model.predict_log10_viscosity(\n",
" T=1000,\n",
" composition=df,\n",
")\n",
"\n",
"predictions"
]
},
{
"cell_type": "code",
"execution_count": 6,
"id": "13515495-1066-4765-912a-6b5774a408a1",
"metadata": {},
"outputs": [
{
"data": {
"text/html": [
"\n",
"\n",
"
\n",
" \n",
" \n",
" | \n",
" log10_eta_infinity (Pa.s) | \n",
" Tg_MYEGA (K) | \n",
" fragility | \n",
"
\n",
" \n",
" \n",
" \n",
" | 0 | \n",
" -1.222603 | \n",
" 701.790333 | \n",
" 42.844319 | \n",
"
\n",
" \n",
" | 1 | \n",
" -1.660096 | \n",
" 710.677354 | \n",
" 35.863589 | \n",
"
\n",
" \n",
" | 2 | \n",
" -1.494931 | \n",
" 647.762409 | \n",
" 40.367431 | \n",
"
\n",
" \n",
"
\n",
"
"
],
"text/plain": [
" log10_eta_infinity (Pa.s) Tg_MYEGA (K) fragility\n",
"0 -1.222603 701.790333 42.844319\n",
"1 -1.660096 710.677354 35.863589\n",
"2 -1.494931 647.762409 40.367431"
]
},
"execution_count": 6,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"viscosity_parameters = model.viscosity_parameters(df)\n",
"\n",
"viscosity_parameters"
]
},
{
"cell_type": "markdown",
"id": "bac99c66-8ae5-42c2-aab0-86f8747312e1",
"metadata": {},
"source": [
"## VITRIFY base usage\n",
"\n"
]
},
{
"cell_type": "markdown",
"id": "374cf723-3818-4ebc-99c5-50a2597d91b8",
"metadata": {},
"source": [
"Below is a minimal example of how to load and use the VITRIFY model. Like GlassNet, VITRIFY accepts strings, dictionaries, and `pandas` DataFrames as input. It returns `1` if the composition is predicted to form a glass under typical laboratory conditions, or `0` otherwise.\n",
"\n"
]
},
{
"cell_type": "code",
"execution_count": 7,
"id": "f2ed18c2-54d3-4afd-ab57-03f7346e3380",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"array([1, 1, 1], dtype=int64)"
]
},
"execution_count": 7,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"from glasspy.predict import VITRIFY\n",
"\n",
"model = VITRIFY()\n",
"predictions = model.predict(df)\n",
"\n",
"predictions"
]
},
{
"cell_type": "markdown",
"id": "7635f095-4b3d-484d-bf77-8485f119c7d4",
"metadata": {},
"source": [
"You can also retrieve the probability that the composition will form a glass, as estimated by the model.\n",
"\n"
]
},
{
"cell_type": "code",
"execution_count": 8,
"id": "4fcadcb0-8502-4389-86a5-c36c44fdc3cb",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"array([0.96919906, 0.99467885, 0.73446614])"
]
},
"execution_count": 8,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"probabilities = model.predict_proba_glass(df)\n",
"\n",
"probabilities"
]
},
{
"cell_type": "markdown",
"id": "2134f33a-bb00-4875-96ac-db609d2d5be3",
"metadata": {},
"source": [
"## ViscNet basic usage\n",
"\n"
]
},
{
"cell_type": "markdown",
"id": "9fc05e13-01d3-4e99-a167-8cd6e05cdb90",
"metadata": {},
"source": [
"ViscNet is used similarly to GlassNet. However, since GlassNet outperforms ViscNet on viscosity prediction, using GlassNet is generally recommended for that task. The minimal example below demonstrates how to load and use ViscNet.\n",
"\n"
]
},
{
"cell_type": "code",
"execution_count": 9,
"id": "ead9eec3-c10e-489b-ba4c-c665d2be37fc",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"array([5.197888 , 5.6581345, 6.0721517], dtype=float32)"
]
},
"execution_count": 9,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"from glasspy.predict import ViscNet\n",
"\n",
"model = ViscNet()\n",
"log10_viscosity = model.predict(T=1000, composition=df)\n",
"\n",
"log10_viscosity"
]
},
{
"cell_type": "code",
"execution_count": 10,
"id": "0954d492-b012-4052-9589-f1a4b2b7ad35",
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"[34.436737 29.760372 34.16933 ]\n"
]
}
],
"source": [
"fragility = model.predict_fragility(df)\n",
"\n",
"print(fragility)"
]
},
{
"cell_type": "code",
"execution_count": 11,
"id": "13d3a8e7-443c-452b-8798-071b752ce0c3",
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"[748.3823 739.4691 788.51385]\n"
]
}
],
"source": [
"Tg = model.predict_Tg(df)\n",
"\n",
"print(Tg)"
]
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3 (ipykernel)",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.14.3"
},
"org": null
},
"nbformat": 4,
"nbformat_minor": 5
}