A machine-learning workflow for predicting the most likely nitrogen reaction centre in N-alkylation and N-arylation reactions of poly-nitrogen nucleophiles.
Developed by Alice Oram, AstraZeneca. With contributions from Christoph Bauer, Isabel Arranz and Per-Ola Norrby
Given a molecule SMILES as input, the predictor:
- Validates the input (reactive-nitrogen count, molecular weight, salt, metal, charge).
- Generates 3D coordinates with Corina.
- Converts coordinates to xyz format with OpenBabel.
- Deprotonates (neutral molecules) or optimises (anionic molecules) the structure with CREST / xTB.
- Calculates ionisation potentials for the anionic and neutral forms with Multiwfn.
- Calculates atomic descriptors (proximity shells, partial charges, polarizability) with kallisto.
- Combines the descriptors with RDKit fingerprints and feeds them into a trained XGBoost classifier.
- Outputs the predicted reactive nitrogen and the probability for each nitrogen centre,
and saves a labelled molecule image (
N_alkylation_probability.png).
Install the Python dependencies with:
pip install -r requirements.txtThe workflow requires the following external executables to be available on your system (see Configuration for how to point the code at them):
| Tool | Version tested | Purpose |
|---|---|---|
| Corina | 3.60 | SMILES to 3D mol2 coordinate generation |
| OpenBabel | 3.1.1 | mol2 to xyz format conversion |
| CREST | latest | Deprotonation / reprotonation |
| xTB | latest | Geometry optimisation and molden files |
| Multiwfn | 3.8 (no-GUI) | Ionisation potential calculation |
git clone https://github.com/<your-org>/n-alkylation-arylation.git
cd n-alkylation-arylation
pip install -r requirements.txtAll configurable paths are set in config.py in the repository root.
Edit this file before running the predictor:
# Root directory where per-run sub-folders will be created
WORKING_DIR = "/path/to/your/working/directory"
# Paths to external tool executables
MULTIWFN_EXEC = "/path/to/Multiwfn_noGUI"
CREST_EXEC = "/path/to/crest"
XTB_EXEC = "xtb" # or full path if not on PATH
CORINA_EXEC = "/path/to/corina"
OBABEL_EXEC = "obabel" # or full path if not on PATHAlternatively, each executable path can be overridden with an environment variable
(e.g. export MULTIWFN_EXEC=/path/to/Multiwfn_noGUI).
The trained XGBoost model (model/XGBoost_fp.pkl) and the Multiwfn input file
(util/multiwfn_IP.in) are bundled with the repository and require no additional
configuration.
python main.pyThe script will prompt for:
- Molecule SMILES - the input nitrogen nucleophile.
- Molecule name - used as the run folder name and file prefix.
Example input:
Molecule SMILES: Cc1ccc(NC(=O)c2ccccc2)cc1N
Name the molecule: example_molecule
Output files are written to <WORKING_DIR>/<molecule_name>/:
| File | Description |
|---|---|
<name>.smi |
Input SMILES file for Corina |
<name>.mol2 |
3D structure (Corina) |
<name>.xyz |
xyz coordinates (OpenBabel) |
deprotonated.xyz / xtbopt.xyz |
Optimised anionic structure |
protonated.xyz |
Neutral (re-protonated) structure |
multiwfn_IP_Deprot.out |
Multiwfn output for the anionic form |
multiwfn_IP_Reprot.out |
Multiwfn output for the neutral form |
all_features.csv |
Full feature matrix used for prediction |
N_alkylation_probability.png |
Labelled molecule image with per-nitrogen probabilities |
n-alkylation-arylation/
├── config.py # User-editable configuration (paths, executables)
├── main.py # Main workflow script
├── requirements.txt # Python dependencies
├── model/
│ ├── XGBoost_fp.pkl # Trained XGBoost classifier
│ └── README.md # Model card
├── util/
│ ├── cheminformatics.py # Input validation and visualisation
│ ├── corina_util.py # Corina wrapper
│ ├── fp_util.py # RDKit fingerprint generation
│ ├── kallisto_util.py # Kallisto descriptor calculations
│ ├── multiwfn_IP.in # Multiwfn input commands
│ ├── multiwfn_util.py # Multiwfn wrapper and output parser
│ ├── obabel_util.py # OpenBabel wrapper
│ └── xtb_util.py # xTB / CREST wrapper
└── LICENSE
- Nitrogen indices are taken from the deprotonated structure. If the atom ordering
changes during reprotonation the merge of
IP_anionandIP_neutralonnitrogen_indexmay fail. The functioncheck_atom_index_changeprints a warning when this occurs; a full fix is planned. - The workflow currently stops with an
AssertionError/ValueErrorif any validation check fails. Graceful error recovery is planned. - The model was trained on molecules with MW < 500 g/mol and charge 0 or -1. Predictions outside this domain should be treated with caution.
This project is licensed under the Apache 2.0 License - see the LICENSE file for details.