molecular-weight-prediction-from-ei-ms
Summary
Use the MWFormer transformer model to directly predict molecular mass from electron ionization mass spectrometry (EI-MS) data by loading a pre-trained model and running forward inference on parsed m/z and intensity spectrum values. This skill enables rapid, direct mass inference without manual spectral interpretation or fragmentation pattern analysis.
When to use
Apply this skill when you have EI-MS spectrum data (m/z and intensity pairs) from a sample and need a direct, model-based prediction of molecular weight. This is most appropriate when you want to leverage transformer-based learned patterns over EI-MS instead of manual spectral interpretation, and when you have access to a pre-trained MWFormer model checkpoint.
When NOT to use
- Input spectrum is from a non-EI ionization source (e.g. ESI, APCI, MALDI) — MWFormer is trained specifically on electron ionization mass spectra.
- Input spectrum is already a processed feature vector or embedding — this skill expects raw or normalized m/z and intensity pairs.
- You have no access to a pre-trained MWFormer model and cannot train one — the skill assumes a trained model is available.
Inputs
- EI-MS spectrum data (m/z and intensity value pairs)
- Pre-trained MWFormer model checkpoint (.pt or .pth file)
- Spectrum configuration or normalization parameters matching model training
Outputs
- Predicted molecular weight (scalar mass value)
- Inference confidence or probability (if model outputs uncertainty)
How to apply
Set up a conda environment with Python 3.9, PyTorch 1.12 with CUDA 11.8 support, and rdkit. Clone the MWFormer repository from GitHub and install dependencies from requirements.txt. Load the pre-trained MWFormer model checkpoint from the repository. Parse your input EI-MS spectrum as m/z and intensity values, then prepare it as a tensor matching the model's expected input format (typically normalized spectrum data). Run forward inference through the MWFormer transformer to generate a direct molecular weight prediction. The output is a single predicted molecular mass value; success is indicated by a numerically valid mass prediction and absence of NaN or out-of-range outputs.
Related tools
- MWFormer (Pre-trained transformer neural network model that accepts EI-MS spectrum tensors and outputs molecular weight predictions) — https://github.com/zhanghailiangcsu/MWFormer
- PyTorch (Deep learning framework used to load the model and execute forward inference) — https://pytorch.org/
- Python (Programming language for environment setup, data parsing, and inference orchestration)
- Anaconda (Environment and dependency manager for Python 3.9 and conda packages (rdkit)) — https://www.anaconda.com
- rdkit (Cheminformatics toolkit (optional utility for validation or post-processing of predicted molecular weights))
Evaluation signals
- Predicted molecular weight is a positive real number within chemically plausible range (e.g. 10–2000 Da for most organic molecules).
- Forward inference completes without NaN, infinity, or runtime errors on valid EI-MS input tensors.
- Spectrum tensor shape and dtype match model input specification (e.g. batch, m/z bins, intensity values).
- Output molecular weight is consistent across multiple runs with identical input (deterministic given fixed model and input).
- If ground-truth molecular weights are available, compare predicted values to known masses; check for systematic bias or outliers beyond expected model error margins.
Limitations
- MWFormer is trained specifically on EI-MS data; it is not expected to generalize to spectra from other ionization methods (ESI, MALDI, APCI, etc.).
- Model performance depends on spectrum quality and preprocessing (normalization, m/z alignment) matching the training protocol — deviations may degrade accuracy.
- No changelog is provided in the repository, making version history and model updates opaque.
- Prediction is a single mass value; the model does not report confidence intervals, uncertainty estimates, or alternative candidates.
- The README does not specify input spectrum dimensions, preprocessing requirements, or acceptable m/z and intensity ranges; users must infer these from example code or model source.
Evidence
- [readme] MWFormer: Direct Prediction of Molecular Mass from Electron lonization Mass Spectrum by Transformer: "MWFormer: Direct Prediction of Molecular Mass from Electron lonization Mass Spectrum by Transformer"
- [other] The MWFormer model accepts electron ionization mass spectrum data as input and outputs a direct prediction of the molecular weight through a forward inference operation.: "The MWFormer model accepts electron ionization mass spectrum data as input and outputs a direct prediction of the molecular weight through a forward inference operation."
- [other] Parse the input EI-MS spectrum data (m/z and intensity values). Prepare the spectrum as a tensor input matching the model's expected input format. Run forward inference through the MWFormer transformer to generate the predicted molecular weight.: "Parse the input EI-MS spectrum data (m/z and intensity values). Prepare the spectrum as a tensor input matching the model's expected input format. Run forward inference through the MWFormer"
- [readme] conda create -n MWFormer python=3.9
conda activate MWFormer
git clone https://github.com/zhanghailiangcsu/MWFormer.git
pip install -r requirements.txt
pip3 install torch torchvision torchaudio --index-url https://download.pytorch.org/whl/cu118
conda install -c conda-forge rdkit: "conda create -n MWFormer python=3.9
conda activate MWFormer
git clone https://github.com/zhanghailiangcsu/MWFormer.git
pip install -r requirements.txt
pip3 install torch torchvision torchaudio"
- [readme] You can download the trained model on Github. Then refer to the example to use the model for prediction, and directly obtain the molecular weight from EI-MS.: "You can download the trained model on Github. Then refer to the example to use the model for prediction, and directly obtain the molecular weight from EI-MS."
1---2name: molecular-weight-prediction-from-ei-ms3description: Use when you have EI-MS spectrum data (m/z and intensity pairs) from a sample and need a direct, model-based prediction of molecular weight.4license: CC-BY-4.05---67# molecular-weight-prediction-from-ei-ms89## Summary1011Use the MWFormer transformer model to directly predict molecular mass from electron ionization mass spectrometry (EI-MS) data by loading a pre-trained model and running forward inference on parsed m/z and intensity spectrum values. This skill enables rapid, direct mass inference without manual spectral interpretation or fragmentation pattern analysis.1213## When to use1415Apply this skill when you have EI-MS spectrum data (m/z and intensity pairs) from a sample and need a direct, model-based prediction of molecular weight. This is most appropriate when you want to leverage transformer-based learned patterns over EI-MS instead of manual spectral interpretation, and when you have access to a pre-trained MWFormer model checkpoint.1617## When NOT to use1819- Input spectrum is from a non-EI ionization source (e.g. ESI, APCI, MALDI) — MWFormer is trained specifically on electron ionization mass spectra.20- Input spectrum is already a processed feature vector or embedding — this skill expects raw or normalized m/z and intensity pairs.21- You have no access to a pre-trained MWFormer model and cannot train one — the skill assumes a trained model is available.2223## Inputs2425- EI-MS spectrum data (m/z and intensity value pairs)26- Pre-trained MWFormer model checkpoint (.pt or .pth file)27- Spectrum configuration or normalization parameters matching model training2829## Outputs3031- Predicted molecular weight (scalar mass value)32- Inference confidence or probability (if model outputs uncertainty)3334## How to apply3536Set up a conda environment with Python 3.9, PyTorch 1.12 with CUDA 11.8 support, and rdkit. Clone the MWFormer repository from GitHub and install dependencies from requirements.txt. Load the pre-trained MWFormer model checkpoint from the repository. Parse your input EI-MS spectrum as m/z and intensity values, then prepare it as a tensor matching the model's expected input format (typically normalized spectrum data). Run forward inference through the MWFormer transformer to generate a direct molecular weight prediction. The output is a single predicted molecular mass value; success is indicated by a numerically valid mass prediction and absence of NaN or out-of-range outputs.3738## Related tools3940- **MWFormer** (Pre-trained transformer neural network model that accepts EI-MS spectrum tensors and outputs molecular weight predictions) — https://github.com/zhanghailiangcsu/MWFormer41- **PyTorch** (Deep learning framework used to load the model and execute forward inference) — https://pytorch.org/42- **Python** (Programming language for environment setup, data parsing, and inference orchestration)43- **Anaconda** (Environment and dependency manager for Python 3.9 and conda packages (rdkit)) — https://www.anaconda.com44- **rdkit** (Cheminformatics toolkit (optional utility for validation or post-processing of predicted molecular weights))4546## Evaluation signals4748- Predicted molecular weight is a positive real number within chemically plausible range (e.g. 10–2000 Da for most organic molecules).49- Forward inference completes without NaN, infinity, or runtime errors on valid EI-MS input tensors.50- Spectrum tensor shape and dtype match model input specification (e.g. batch, m/z bins, intensity values).51- Output molecular weight is consistent across multiple runs with identical input (deterministic given fixed model and input).52- If ground-truth molecular weights are available, compare predicted values to known masses; check for systematic bias or outliers beyond expected model error margins.5354## Limitations5556- MWFormer is trained specifically on EI-MS data; it is not expected to generalize to spectra from other ionization methods (ESI, MALDI, APCI, etc.).57- Model performance depends on spectrum quality and preprocessing (normalization, m/z alignment) matching the training protocol — deviations may degrade accuracy.58- No changelog is provided in the repository, making version history and model updates opaque.59- Prediction is a single mass value; the model does not report confidence intervals, uncertainty estimates, or alternative candidates.60- The README does not specify input spectrum dimensions, preprocessing requirements, or acceptable m/z and intensity ranges; users must infer these from example code or model source.6162## Evidence6364- [readme] MWFormer: Direct Prediction of Molecular Mass from Electron lonization Mass Spectrum by Transformer: "MWFormer: Direct Prediction of Molecular Mass from Electron lonization Mass Spectrum by Transformer"65- [other] The MWFormer model accepts electron ionization mass spectrum data as input and outputs a direct prediction of the molecular weight through a forward inference operation.: "The MWFormer model accepts electron ionization mass spectrum data as input and outputs a direct prediction of the molecular weight through a forward inference operation."66- [other] Parse the input EI-MS spectrum data (m/z and intensity values). Prepare the spectrum as a tensor input matching the model's expected input format. Run forward inference through the MWFormer transformer to generate the predicted molecular weight.: "Parse the input EI-MS spectrum data (m/z and intensity values). Prepare the spectrum as a tensor input matching the model's expected input format. Run forward inference through the MWFormer"67- [readme] conda create -n MWFormer python=3.968conda activate MWFormer69git clone https://github.com/zhanghailiangcsu/MWFormer.git70pip install -r requirements.txt71pip3 install torch torchvision torchaudio --index-url https://download.pytorch.org/whl/cu11872conda install -c conda-forge rdkit: "conda create -n MWFormer python=3.973conda activate MWFormer74git clone https://github.com/zhanghailiangcsu/MWFormer.git75pip install -r requirements.txt76pip3 install torch torchvision torchaudio"77- [readme] You can download the trained model on Github. Then refer to the example to use the model for prediction, and directly obtain the molecular weight from EI-MS.: "You can download the trained model on Github. Then refer to the example to use the model for prediction, and directly obtain the molecular weight from EI-MS."