MAGIC — Multi-task Alloy Generator with Integrated Constraints
A lightweight, reproducible deep-learning framework for predicting the mechanical properties of biodegradable magnesium alloys (ultimate tensile strength and yield strength) from composition and processing parameters.
This repository accompanies the manuscript "Deep Learning for Biodegradable Metallic Biomaterials: From Degradation Modeling to Performance Prediction with a Practical Case Study" (Frontiers). The full case-study analysis is provided in the Supplementary Material of that article; this repository contains the cleaned, ready-to-run training code.
- Physics-informed feature engineering — atomic radius mismatch, electronegativity difference, solid-solution strength, compound-forming tendency, and processing-derived strain-rate proxies.
- Multi-task learning — one shared backbone predicts UTS and YS simultaneously, with uncertainty-weighted losses (Kendall et al. 2018).
- SwiGLU residual backbone with per-task attention gating.
- Adaptive composite-training-score (CTS) schedule that shifts the optimisation focus between R² / RMSE / MAE as training progresses.
- Mixup regularisation for the small-data regime (600 alloy entries).
data/DatasetMg_imputed.csv— 600 magnesium-alloy records: 19 named alloying elements (Mg, Mn, Sr, Dy, Al, Ca, Zn, Gd, Nd, Y, Sm, Sn, Ce, Si, La, Cu, Zr, Li, Bi) plus a "Re" column that aggregates remaining rare-earth additions (it is not the element Rhenium) + 5 thermomechanical processing parameters as inputs; UTS and YS (MPa) as targets. Composition values are stored as mass fractions (0--1), not mass percentages.- The data are derived from the public resorbable-magnesium-alloy dataset of Nandal et al. (Materials & Design, 2026, DOI: 10.1016/j.matdes.2026.116060; Zenodo record 17672235, DOI: 10.5281/zenodo.17672235), which contains roughly 410 raw records; after feature-level imputation and partial-record filtering, the working set has 600 entries. The UTS model uses 587 records (13 missing UTS values are dropped); the YS model uses all 600. Magnesium is treated as the residual (1 minus the sum of the other fractions), and entries that do not report an element are imputed to zero.
git clone https://github.com/SHENTongfei/MAGIC.git
cd MAGIC
# Python 3.9+ recommended
pip install -r requirements.txtDependencies: torch, numpy, pandas, scikit-learn.
# Train MAGIC (5-fold CV) and reference classical regressors
python train.pyOutputs:
results/magic_fold*_history.csv— per-epoch training/validation logsresults/magic_fold*_predictions.csv— true vs. predicted values per foldresults/magic_fold*_predictions.csv— reference-model predictionsresults/all_models_summary.csv— 5-fold CV summary tablemodels/magic_best_model.pth— best-fold MAGIC weights
MAGIC/
├── train.py # main training script (MAGIC + reference models)
├── data/
│ └── DatasetMg_imputed.csv
├── requirements.txt
└── README.md
MAGIC predicts pristine as-cast UTS and YS only. It does not predict the post-degradation residual strength, the in-service evolution, the in vitro to in vivo translation, or the alloying effects as causal metallurgical mechanisms. The Pearson correlations and SHAP values it reports describe statistical associations in the present dataset, not causal laws; the same caveats apply to any apparent "effect" of a single alloying element. For in vivo translation, the literature values of mass-loss rate, hydrogen evolution, ion release, polarisation resistance, and EIS-derived rates are not directly comparable, and the present repository does not aggregate them into a single number.
For research use. Contact the corresponding authors for details.
If you use this code or data, please cite the accompanying manuscript and the original dataset:
- Shen et al., Deep Learning for Biodegradable Metallic Biomaterials (2026).
- Nandal, V. et al. Accelerating the design of resorbable magnesium alloys: a machine learning approach to property prediction. Materials & Design, 266, 116060 (2026). DOI: 10.1016/j.matdes.2026.116060