mlmolprop 1.9.1__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- mlmolprop-1.9.1/.gitignore +30 -0
- mlmolprop-1.9.1/CITATION.cff +10 -0
- mlmolprop-1.9.1/LICENSE +21 -0
- mlmolprop-1.9.1/PKG-INFO +215 -0
- mlmolprop-1.9.1/README.md +165 -0
- mlmolprop-1.9.1/environment.yml +28 -0
- mlmolprop-1.9.1/examples/data/esol_subset.csv +71 -0
- mlmolprop-1.9.1/examples/quickstart.ipynb +2118 -0
- mlmolprop-1.9.1/pyproject.toml +109 -0
- mlmolprop-1.9.1/src/mlmolprop/__init__.py +92 -0
- mlmolprop-1.9.1/src/mlmolprop/basic.py +154 -0
- mlmolprop-1.9.1/src/mlmolprop/correlation.py +80 -0
- mlmolprop-1.9.1/src/mlmolprop/descriptors.py +279 -0
- mlmolprop-1.9.1/src/mlmolprop/fingerprint.py +172 -0
- mlmolprop-1.9.1/src/mlmolprop/image.py +97 -0
- mlmolprop-1.9.1/src/mlmolprop/importance.py +151 -0
- mlmolprop-1.9.1/src/mlmolprop/model.py +2430 -0
- mlmolprop-1.9.1/src/mlmolprop/molprep.py +224 -0
- mlmolprop-1.9.1/src/mlmolprop/plots.py +117 -0
- mlmolprop-1.9.1/src/mlmolprop/processing.py +512 -0
- mlmolprop-1.9.1/tests/conftest.py +78 -0
- mlmolprop-1.9.1/tests/test_basic.py +164 -0
- mlmolprop-1.9.1/tests/test_correlation.py +130 -0
- mlmolprop-1.9.1/tests/test_descriptors.py +88 -0
- mlmolprop-1.9.1/tests/test_fingerprint.py +84 -0
- mlmolprop-1.9.1/tests/test_image.py +89 -0
- mlmolprop-1.9.1/tests/test_importance.py +105 -0
- mlmolprop-1.9.1/tests/test_model.py +1434 -0
- mlmolprop-1.9.1/tests/test_molprep.py +122 -0
- mlmolprop-1.9.1/tests/test_plots.py +51 -0
- mlmolprop-1.9.1/tests/test_processing.py +721 -0
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
# Byte-compiled / cache
|
|
2
|
+
__pycache__/
|
|
3
|
+
*.py[cod]
|
|
4
|
+
|
|
5
|
+
# Packaging / build artifacts
|
|
6
|
+
*.egg-info/
|
|
7
|
+
build/
|
|
8
|
+
dist/
|
|
9
|
+
*.egg
|
|
10
|
+
|
|
11
|
+
# Virtual environments
|
|
12
|
+
.venv/
|
|
13
|
+
venv/
|
|
14
|
+
env/
|
|
15
|
+
|
|
16
|
+
# Testing / coverage
|
|
17
|
+
.pytest_cache/
|
|
18
|
+
.coverage
|
|
19
|
+
htmlcov/
|
|
20
|
+
|
|
21
|
+
# Editors
|
|
22
|
+
.vscode/
|
|
23
|
+
.idea/
|
|
24
|
+
.DS_Store
|
|
25
|
+
|
|
26
|
+
# Jupyter
|
|
27
|
+
.ipynb_checkpoints/
|
|
28
|
+
|
|
29
|
+
# Example notebook outputs (regenerated by running examples/quickstart.ipynb)
|
|
30
|
+
examples/output/
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
cff-version: 1.2.0
|
|
2
|
+
message: "If you use this software, please cite it as below."
|
|
3
|
+
title: mlmolprop
|
|
4
|
+
version: 1.9.1
|
|
5
|
+
license: MIT
|
|
6
|
+
authors:
|
|
7
|
+
- family-names: Shamsara
|
|
8
|
+
given-names: Jamal
|
|
9
|
+
orcid: "https://orcid.org/0000-0002-6162-6037"
|
|
10
|
+
repository-code: "https://github.com/shamsaraj/mlmolprop"
|
mlmolprop-1.9.1/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Jamal Shamsara
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
mlmolprop-1.9.1/PKG-INFO
ADDED
|
@@ -0,0 +1,215 @@
|
|
|
1
|
+
Metadata-Version: 2.5
|
|
2
|
+
Name: mlmolprop
|
|
3
|
+
Version: 1.9.1
|
|
4
|
+
Summary: Machine learning and cheminformatics toolkit for molecular modeling.
|
|
5
|
+
Project-URL: Homepage, https://github.com/shamsaraj/mlmolprop
|
|
6
|
+
Project-URL: Bug Tracker, https://github.com/shamsaraj/mlmolprop/issues
|
|
7
|
+
Author-email: Jamal Shamsara <jshamsara@yahoo.com>
|
|
8
|
+
License-Expression: MIT
|
|
9
|
+
License-File: LICENSE
|
|
10
|
+
Keywords: cheminformatics,drug-discovery,fingerprints,machine-learning,molecular-descriptors,qsar,rdkit
|
|
11
|
+
Classifier: Development Status :: 5 - Production/Stable
|
|
12
|
+
Classifier: Intended Audience :: Science/Research
|
|
13
|
+
Classifier: Operating System :: OS Independent
|
|
14
|
+
Classifier: Programming Language :: Python :: 3
|
|
15
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
16
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
17
|
+
Classifier: Programming Language :: Python :: 3.13
|
|
18
|
+
Classifier: Topic :: Scientific/Engineering :: Artificial Intelligence
|
|
19
|
+
Classifier: Topic :: Scientific/Engineering :: Bio-Informatics
|
|
20
|
+
Classifier: Topic :: Scientific/Engineering :: Chemistry
|
|
21
|
+
Requires-Python: >=3.11
|
|
22
|
+
Requires-Dist: lime>=0.2
|
|
23
|
+
Requires-Dist: matplotlib>=3.9
|
|
24
|
+
Requires-Dist: numpy>=2.0
|
|
25
|
+
Requires-Dist: pandas>=2.2
|
|
26
|
+
Requires-Dist: rdkit>=2024.3
|
|
27
|
+
Requires-Dist: reportlab>=5.0
|
|
28
|
+
Requires-Dist: scikit-learn>=1.5
|
|
29
|
+
Requires-Dist: scipy>=1.13
|
|
30
|
+
Requires-Dist: svglib>=2.1
|
|
31
|
+
Provides-Extra: all
|
|
32
|
+
Requires-Dist: keras>=3.0; extra == 'all'
|
|
33
|
+
Requires-Dist: rlpycairo>=0.4.0; extra == 'all'
|
|
34
|
+
Requires-Dist: torch>=2.0; extra == 'all'
|
|
35
|
+
Requires-Dist: xgboost>=3.0; extra == 'all'
|
|
36
|
+
Provides-Extra: dl
|
|
37
|
+
Requires-Dist: keras>=3.0; extra == 'dl'
|
|
38
|
+
Requires-Dist: torch>=2.0; extra == 'dl'
|
|
39
|
+
Provides-Extra: image
|
|
40
|
+
Requires-Dist: rlpycairo>=0.4.0; extra == 'image'
|
|
41
|
+
Provides-Extra: test
|
|
42
|
+
Requires-Dist: pytest>=8.0; extra == 'test'
|
|
43
|
+
Provides-Extra: torch
|
|
44
|
+
Requires-Dist: torch>=2.0; extra == 'torch'
|
|
45
|
+
Provides-Extra: viz
|
|
46
|
+
Requires-Dist: graphviz; extra == 'viz'
|
|
47
|
+
Provides-Extra: xgboost
|
|
48
|
+
Requires-Dist: xgboost>=3.0; extra == 'xgboost'
|
|
49
|
+
Description-Content-Type: text/markdown
|
|
50
|
+
|
|
51
|
+
# mlmolprop — Cheminformatics & QSAR Modeling Toolkit
|
|
52
|
+
|
|
53
|
+
**mlmolprop** is a modular Python framework for cheminformatics and QSAR (Quantitative Structure–Activity Relationship) modeling.
|
|
54
|
+
It enables molecular descriptor generation, fingerprint computation, dataset preprocessing, feature selection, and machine learning analysis — all within one workflow.
|
|
55
|
+
|
|
56
|
+
This toolkit integrates **RDKit**, **scikit-learn**, **Keras/PyTorch**, **LIME**, and **matplotlib** to streamline molecular data preparation, model building, and interpretation.
|
|
57
|
+
|
|
58
|
+
---
|
|
59
|
+
|
|
60
|
+
## Project Structure
|
|
61
|
+
|
|
62
|
+
| Module | Description |
|
|
63
|
+
|--------|--------------|
|
|
64
|
+
| **basic.py** | Core statistics helpers for QSAR model evaluation (PRESS, R², Q², RMSE, F-statistic, etc.). |
|
|
65
|
+
| **correlation.py** | Detects and removes highly correlated features from datasets. |
|
|
66
|
+
| **processing.py** | Dataset preprocessing — imputation, scaling, normalization, feature selection, correlation filtering, and train/test splitting. |
|
|
67
|
+
| **fingerprint.py** | Generates molecular fingerprints (ECFP, MACCS, Avalon, RDKit, etc.) using RDKit. |
|
|
68
|
+
| **descriptors.py** | Computes molecular descriptors, merges with activity data, and exports QSAR-ready datasets. |
|
|
69
|
+
| **molprep.py** | Prepares molecular structures (SDF/SMILES): salt removal, 3D embedding, charge calculation, and image generation. |
|
|
70
|
+
| **model.py** | Fits and evaluates regression/classification models (PLS, Random Forest, SVM, MLP, a small Keras deep-learning classifier, etc.). |
|
|
71
|
+
| **importance.py** | Explains model predictions with LIME, and partial dependence plots. |
|
|
72
|
+
| **image.py** | Converts molecule/data images to on-disk artifacts (PNG, CSV, SVG). |
|
|
73
|
+
| **plots.py** | Scatter/histogram/2D-histogram/ROC grid plots of a feature set vs. a target. |
|
|
74
|
+
|
|
75
|
+
---
|
|
76
|
+
|
|
77
|
+
## Installation
|
|
78
|
+
|
|
79
|
+
Clone the repository:
|
|
80
|
+
```bash
|
|
81
|
+
git clone https://github.com/shamsaraj/mlmolprop.git
|
|
82
|
+
cd mlmolprop
|
|
83
|
+
```
|
|
84
|
+
|
|
85
|
+
Create the environment (conda, recommended):
|
|
86
|
+
```bash
|
|
87
|
+
conda env create -f environment.yml
|
|
88
|
+
conda activate mlmolprop
|
|
89
|
+
```
|
|
90
|
+
|
|
91
|
+
Or install directly with pip:
|
|
92
|
+
```bash
|
|
93
|
+
pip install -e .
|
|
94
|
+
```
|
|
95
|
+
|
|
96
|
+
> **Note:** the `dl` extra (`M="dl"` in `Model`/`ModelC`) is built on
|
|
97
|
+
> Keras 3 running on the PyTorch backend -- set `KERAS_BACKEND=torch`
|
|
98
|
+
> before using it. This path is tested and verified to build, train, and
|
|
99
|
+
> predict the same way a TensorFlow backend would (see
|
|
100
|
+
> `tests/test_model.py::test_modelc_dl_actually_trains`). On Intel
|
|
101
|
+
> macOS, `pip install "mlmolprop[dl]"` will pull in PyTorch 2.2.2, the
|
|
102
|
+
> newest version PyPI publishes for that platform -- it predates the
|
|
103
|
+
> PyTorch API Keras 3's torch backend needs and fails to import.
|
|
104
|
+
> conda-forge is recommended for the `dl` extra on that platform
|
|
105
|
+
> instead, which has PyTorch 2.13+.
|
|
106
|
+
|
|
107
|
+
> **Note:** `pip install "mlmolprop[image]"` (needed for
|
|
108
|
+
> `svg_files_to_png()` and `RDimage()`) builds `rlPyCairo`'s `pycairo`
|
|
109
|
+
> dependency from source against a system Cairo install -- there's no
|
|
110
|
+
> prebuilt PyPI wheel on any platform. conda-forge is recommended for
|
|
111
|
+
> this extra instead: `conda install -c conda-forge rlpycairo`.
|
|
112
|
+
|
|
113
|
+
---
|
|
114
|
+
|
|
115
|
+
## Usage Overview
|
|
116
|
+
|
|
117
|
+
### 1. Prepare Molecules
|
|
118
|
+
```python
|
|
119
|
+
from mlmolprop import mol_enumerate
|
|
120
|
+
|
|
121
|
+
molecules = mol_enumerate("input.sdf", "prepared_3d.sdf", "prepared_2d.sdf")
|
|
122
|
+
```
|
|
123
|
+
|
|
124
|
+
### 2. Generate Descriptors
|
|
125
|
+
```python
|
|
126
|
+
from mlmolprop import desc, dataframe
|
|
127
|
+
|
|
128
|
+
desc_data = desc(molecules, source="molecule")
|
|
129
|
+
merged = dataframe(desc_data, "activity.csv", "merged.csv")
|
|
130
|
+
```
|
|
131
|
+
|
|
132
|
+
### 3. Process Dataset
|
|
133
|
+
```python
|
|
134
|
+
from mlmolprop import data_prep
|
|
135
|
+
|
|
136
|
+
result = data_prep("merged.csv", Scaled="on", FS="reg", Cor="on", mod="reg")
|
|
137
|
+
```
|
|
138
|
+
|
|
139
|
+
### 4. Build and Evaluate Models
|
|
140
|
+
```python
|
|
141
|
+
from mlmolprop import Model
|
|
142
|
+
|
|
143
|
+
X_train, y_train, X_test, y_test, v_names = result[:5]
|
|
144
|
+
model_result = Model(X_train, y_train, X_test, y_test, v_names, M="rf")
|
|
145
|
+
print(model_result[0]) # metrics dict
|
|
146
|
+
```
|
|
147
|
+
|
|
148
|
+
---
|
|
149
|
+
|
|
150
|
+
## Example Notebook
|
|
151
|
+
|
|
152
|
+
[`examples/quickstart.ipynb`](https://github.com/shamsaraj/mlmolprop/blob/main/examples/quickstart.ipynb) runs the full pipeline
|
|
153
|
+
above end-to-end against
|
|
154
|
+
[`examples/data/esol_subset.csv`](https://github.com/shamsaraj/mlmolprop/blob/main/examples/data/esol_subset.csv), a
|
|
155
|
+
70-compound sample of the real, measured **ESOL/Delaney aqueous solubility
|
|
156
|
+
dataset**, then goes further:
|
|
157
|
+
|
|
158
|
+
- molecule preparation → descriptors → dataset processing → model training → evaluation
|
|
159
|
+
- algorithm comparison across several regressor types
|
|
160
|
+
- a combined hyperparameter + feature-selection grid search, with a heatmap
|
|
161
|
+
of the results
|
|
162
|
+
- refit and diagnostics (predicted-vs-observed, residuals) for the model
|
|
163
|
+
that actually won the search, not just an arbitrary starting guess
|
|
164
|
+
- feature importance: variable importance + partial dependence
|
|
165
|
+
- LIME: explaining a single molecule's prediction
|
|
166
|
+
- 2D structure depictions, including substructure highlighting
|
|
167
|
+
- a low-dimensional (PCA) map colored by measured activity, and a
|
|
168
|
+
K-means clustering map
|
|
169
|
+
- classification, with confusion matrices for the best-by-CV classifier
|
|
170
|
+
and for a small Keras deep-learning model
|
|
171
|
+
|
|
172
|
+
> **Verified against mlmolprop 1.1.0** -- every cell, including the
|
|
173
|
+
> deep-learning classification cell (`M="dl"`), runs end-to-end with no
|
|
174
|
+
> errors (`jupyter nbconvert --execute`). The DL cell needs the `dl`
|
|
175
|
+
> extra installed; the notebook sets `KERAS_BACKEND=torch` itself, so no
|
|
176
|
+
> manual setup is needed beyond `pip install "mlmolprop[dl]"` (or
|
|
177
|
+
> conda-forge on Intel macOS -- see Installation above).
|
|
178
|
+
|
|
179
|
+
Open it with `jupyter notebook` after installing (the `notebook`/`nbconvert`
|
|
180
|
+
dev tools are included in `environment.yml`).
|
|
181
|
+
|
|
182
|
+
---
|
|
183
|
+
|
|
184
|
+
## Features
|
|
185
|
+
|
|
186
|
+
- Molecular structure preparation (SMILES/SDF), salt removal, 3D embedding
|
|
187
|
+
- Descriptor and fingerprint generation (ECFP, MACCS, Avalon, RDKit, etc.)
|
|
188
|
+
- Data preprocessing: imputation, normalization, scaling, categorical encoding
|
|
189
|
+
- Correlation filtering and variance thresholding
|
|
190
|
+
- Machine learning for regression and classification, including a small Keras MLP
|
|
191
|
+
- Model interpretation via LIME and partial dependence plots
|
|
192
|
+
- Visualization: PCA, ROC, histograms, confusion matrices, clustering
|
|
193
|
+
|
|
194
|
+
---
|
|
195
|
+
|
|
196
|
+
## Example Workflow
|
|
197
|
+
|
|
198
|
+
1. Prepare molecules
|
|
199
|
+
2. Generate descriptors
|
|
200
|
+
3. Process dataset
|
|
201
|
+
4. Train model
|
|
202
|
+
5. Interpret results
|
|
203
|
+
|
|
204
|
+
---
|
|
205
|
+
|
|
206
|
+
## Author
|
|
207
|
+
|
|
208
|
+
**J. Shamsara**
|
|
209
|
+
[GitHub Profile](https://github.com/shamsaraj)
|
|
210
|
+
|
|
211
|
+
---
|
|
212
|
+
|
|
213
|
+
## License
|
|
214
|
+
|
|
215
|
+
This project is licensed under the **MIT License** — see the [LICENSE](https://github.com/shamsaraj/mlmolprop/blob/main/LICENSE) file for details.
|
|
@@ -0,0 +1,165 @@
|
|
|
1
|
+
# mlmolprop — Cheminformatics & QSAR Modeling Toolkit
|
|
2
|
+
|
|
3
|
+
**mlmolprop** is a modular Python framework for cheminformatics and QSAR (Quantitative Structure–Activity Relationship) modeling.
|
|
4
|
+
It enables molecular descriptor generation, fingerprint computation, dataset preprocessing, feature selection, and machine learning analysis — all within one workflow.
|
|
5
|
+
|
|
6
|
+
This toolkit integrates **RDKit**, **scikit-learn**, **Keras/PyTorch**, **LIME**, and **matplotlib** to streamline molecular data preparation, model building, and interpretation.
|
|
7
|
+
|
|
8
|
+
---
|
|
9
|
+
|
|
10
|
+
## Project Structure
|
|
11
|
+
|
|
12
|
+
| Module | Description |
|
|
13
|
+
|--------|--------------|
|
|
14
|
+
| **basic.py** | Core statistics helpers for QSAR model evaluation (PRESS, R², Q², RMSE, F-statistic, etc.). |
|
|
15
|
+
| **correlation.py** | Detects and removes highly correlated features from datasets. |
|
|
16
|
+
| **processing.py** | Dataset preprocessing — imputation, scaling, normalization, feature selection, correlation filtering, and train/test splitting. |
|
|
17
|
+
| **fingerprint.py** | Generates molecular fingerprints (ECFP, MACCS, Avalon, RDKit, etc.) using RDKit. |
|
|
18
|
+
| **descriptors.py** | Computes molecular descriptors, merges with activity data, and exports QSAR-ready datasets. |
|
|
19
|
+
| **molprep.py** | Prepares molecular structures (SDF/SMILES): salt removal, 3D embedding, charge calculation, and image generation. |
|
|
20
|
+
| **model.py** | Fits and evaluates regression/classification models (PLS, Random Forest, SVM, MLP, a small Keras deep-learning classifier, etc.). |
|
|
21
|
+
| **importance.py** | Explains model predictions with LIME, and partial dependence plots. |
|
|
22
|
+
| **image.py** | Converts molecule/data images to on-disk artifacts (PNG, CSV, SVG). |
|
|
23
|
+
| **plots.py** | Scatter/histogram/2D-histogram/ROC grid plots of a feature set vs. a target. |
|
|
24
|
+
|
|
25
|
+
---
|
|
26
|
+
|
|
27
|
+
## Installation
|
|
28
|
+
|
|
29
|
+
Clone the repository:
|
|
30
|
+
```bash
|
|
31
|
+
git clone https://github.com/shamsaraj/mlmolprop.git
|
|
32
|
+
cd mlmolprop
|
|
33
|
+
```
|
|
34
|
+
|
|
35
|
+
Create the environment (conda, recommended):
|
|
36
|
+
```bash
|
|
37
|
+
conda env create -f environment.yml
|
|
38
|
+
conda activate mlmolprop
|
|
39
|
+
```
|
|
40
|
+
|
|
41
|
+
Or install directly with pip:
|
|
42
|
+
```bash
|
|
43
|
+
pip install -e .
|
|
44
|
+
```
|
|
45
|
+
|
|
46
|
+
> **Note:** the `dl` extra (`M="dl"` in `Model`/`ModelC`) is built on
|
|
47
|
+
> Keras 3 running on the PyTorch backend -- set `KERAS_BACKEND=torch`
|
|
48
|
+
> before using it. This path is tested and verified to build, train, and
|
|
49
|
+
> predict the same way a TensorFlow backend would (see
|
|
50
|
+
> `tests/test_model.py::test_modelc_dl_actually_trains`). On Intel
|
|
51
|
+
> macOS, `pip install "mlmolprop[dl]"` will pull in PyTorch 2.2.2, the
|
|
52
|
+
> newest version PyPI publishes for that platform -- it predates the
|
|
53
|
+
> PyTorch API Keras 3's torch backend needs and fails to import.
|
|
54
|
+
> conda-forge is recommended for the `dl` extra on that platform
|
|
55
|
+
> instead, which has PyTorch 2.13+.
|
|
56
|
+
|
|
57
|
+
> **Note:** `pip install "mlmolprop[image]"` (needed for
|
|
58
|
+
> `svg_files_to_png()` and `RDimage()`) builds `rlPyCairo`'s `pycairo`
|
|
59
|
+
> dependency from source against a system Cairo install -- there's no
|
|
60
|
+
> prebuilt PyPI wheel on any platform. conda-forge is recommended for
|
|
61
|
+
> this extra instead: `conda install -c conda-forge rlpycairo`.
|
|
62
|
+
|
|
63
|
+
---
|
|
64
|
+
|
|
65
|
+
## Usage Overview
|
|
66
|
+
|
|
67
|
+
### 1. Prepare Molecules
|
|
68
|
+
```python
|
|
69
|
+
from mlmolprop import mol_enumerate
|
|
70
|
+
|
|
71
|
+
molecules = mol_enumerate("input.sdf", "prepared_3d.sdf", "prepared_2d.sdf")
|
|
72
|
+
```
|
|
73
|
+
|
|
74
|
+
### 2. Generate Descriptors
|
|
75
|
+
```python
|
|
76
|
+
from mlmolprop import desc, dataframe
|
|
77
|
+
|
|
78
|
+
desc_data = desc(molecules, source="molecule")
|
|
79
|
+
merged = dataframe(desc_data, "activity.csv", "merged.csv")
|
|
80
|
+
```
|
|
81
|
+
|
|
82
|
+
### 3. Process Dataset
|
|
83
|
+
```python
|
|
84
|
+
from mlmolprop import data_prep
|
|
85
|
+
|
|
86
|
+
result = data_prep("merged.csv", Scaled="on", FS="reg", Cor="on", mod="reg")
|
|
87
|
+
```
|
|
88
|
+
|
|
89
|
+
### 4. Build and Evaluate Models
|
|
90
|
+
```python
|
|
91
|
+
from mlmolprop import Model
|
|
92
|
+
|
|
93
|
+
X_train, y_train, X_test, y_test, v_names = result[:5]
|
|
94
|
+
model_result = Model(X_train, y_train, X_test, y_test, v_names, M="rf")
|
|
95
|
+
print(model_result[0]) # metrics dict
|
|
96
|
+
```
|
|
97
|
+
|
|
98
|
+
---
|
|
99
|
+
|
|
100
|
+
## Example Notebook
|
|
101
|
+
|
|
102
|
+
[`examples/quickstart.ipynb`](https://github.com/shamsaraj/mlmolprop/blob/main/examples/quickstart.ipynb) runs the full pipeline
|
|
103
|
+
above end-to-end against
|
|
104
|
+
[`examples/data/esol_subset.csv`](https://github.com/shamsaraj/mlmolprop/blob/main/examples/data/esol_subset.csv), a
|
|
105
|
+
70-compound sample of the real, measured **ESOL/Delaney aqueous solubility
|
|
106
|
+
dataset**, then goes further:
|
|
107
|
+
|
|
108
|
+
- molecule preparation → descriptors → dataset processing → model training → evaluation
|
|
109
|
+
- algorithm comparison across several regressor types
|
|
110
|
+
- a combined hyperparameter + feature-selection grid search, with a heatmap
|
|
111
|
+
of the results
|
|
112
|
+
- refit and diagnostics (predicted-vs-observed, residuals) for the model
|
|
113
|
+
that actually won the search, not just an arbitrary starting guess
|
|
114
|
+
- feature importance: variable importance + partial dependence
|
|
115
|
+
- LIME: explaining a single molecule's prediction
|
|
116
|
+
- 2D structure depictions, including substructure highlighting
|
|
117
|
+
- a low-dimensional (PCA) map colored by measured activity, and a
|
|
118
|
+
K-means clustering map
|
|
119
|
+
- classification, with confusion matrices for the best-by-CV classifier
|
|
120
|
+
and for a small Keras deep-learning model
|
|
121
|
+
|
|
122
|
+
> **Verified against mlmolprop 1.1.0** -- every cell, including the
|
|
123
|
+
> deep-learning classification cell (`M="dl"`), runs end-to-end with no
|
|
124
|
+
> errors (`jupyter nbconvert --execute`). The DL cell needs the `dl`
|
|
125
|
+
> extra installed; the notebook sets `KERAS_BACKEND=torch` itself, so no
|
|
126
|
+
> manual setup is needed beyond `pip install "mlmolprop[dl]"` (or
|
|
127
|
+
> conda-forge on Intel macOS -- see Installation above).
|
|
128
|
+
|
|
129
|
+
Open it with `jupyter notebook` after installing (the `notebook`/`nbconvert`
|
|
130
|
+
dev tools are included in `environment.yml`).
|
|
131
|
+
|
|
132
|
+
---
|
|
133
|
+
|
|
134
|
+
## Features
|
|
135
|
+
|
|
136
|
+
- Molecular structure preparation (SMILES/SDF), salt removal, 3D embedding
|
|
137
|
+
- Descriptor and fingerprint generation (ECFP, MACCS, Avalon, RDKit, etc.)
|
|
138
|
+
- Data preprocessing: imputation, normalization, scaling, categorical encoding
|
|
139
|
+
- Correlation filtering and variance thresholding
|
|
140
|
+
- Machine learning for regression and classification, including a small Keras MLP
|
|
141
|
+
- Model interpretation via LIME and partial dependence plots
|
|
142
|
+
- Visualization: PCA, ROC, histograms, confusion matrices, clustering
|
|
143
|
+
|
|
144
|
+
---
|
|
145
|
+
|
|
146
|
+
## Example Workflow
|
|
147
|
+
|
|
148
|
+
1. Prepare molecules
|
|
149
|
+
2. Generate descriptors
|
|
150
|
+
3. Process dataset
|
|
151
|
+
4. Train model
|
|
152
|
+
5. Interpret results
|
|
153
|
+
|
|
154
|
+
---
|
|
155
|
+
|
|
156
|
+
## Author
|
|
157
|
+
|
|
158
|
+
**J. Shamsara**
|
|
159
|
+
[GitHub Profile](https://github.com/shamsaraj)
|
|
160
|
+
|
|
161
|
+
---
|
|
162
|
+
|
|
163
|
+
## License
|
|
164
|
+
|
|
165
|
+
This project is licensed under the **MIT License** — see the [LICENSE](https://github.com/shamsaraj/mlmolprop/blob/main/LICENSE) file for details.
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
# Reproducible dev environment: conda env create -f environment.yml
|
|
2
|
+
name: mlmolprop
|
|
3
|
+
channels:
|
|
4
|
+
- conda-forge
|
|
5
|
+
dependencies:
|
|
6
|
+
- python=3.12
|
|
7
|
+
- numpy=2.5
|
|
8
|
+
- pandas=3.0
|
|
9
|
+
- matplotlib=3.10
|
|
10
|
+
- scikit-learn=1.9
|
|
11
|
+
- scipy=1.18
|
|
12
|
+
- rdkit=2025.09
|
|
13
|
+
- reportlab=5.0
|
|
14
|
+
- rlpycairo=0.4.0
|
|
15
|
+
- svglib=2.1
|
|
16
|
+
- keras=3.15
|
|
17
|
+
- pytorch=2.13
|
|
18
|
+
- xgboost=3.4
|
|
19
|
+
- lime=0.2
|
|
20
|
+
# dev tools
|
|
21
|
+
- ruff=0.16
|
|
22
|
+
- black=26.5
|
|
23
|
+
- pytest=9.1
|
|
24
|
+
- notebook=7.6
|
|
25
|
+
- nbconvert=7.17
|
|
26
|
+
- pip
|
|
27
|
+
- pip:
|
|
28
|
+
- -e .
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
name,smiles,measured_logS
|
|
2
|
+
1_2_3_4_tetrachlorobenzene,Clc1ccc(Cl)c(Cl)c1Cl,-4.57
|
|
3
|
+
1_2_benzenediol,Oc1ccccc1O,0.62
|
|
4
|
+
1_4_dichlorobenzene,Clc1ccc(Cl)cc1,-3.27
|
|
5
|
+
1_nonyne,CCCCCCCC#C,-4.24
|
|
6
|
+
2_2_4_trimethylpentane,CC(C)CC(C)(C)C,-4.74
|
|
7
|
+
2_3_4_5_pcb,Clc1ccc(Cl)c(c1)c2ccc(Cl)c(Cl)c2,-7.25
|
|
8
|
+
2_4_6_trimethylphenol,Cc1cc(C)c(O)c(C)c1,-2.05
|
|
9
|
+
2_4_dimethyl_3_pentanone,CC(C)C(=O)C(C)C,-1.3
|
|
10
|
+
2_chloronapthalene,Clc1ccc2ccccc2c1,-4.14
|
|
11
|
+
2_ethyl_2_hexanal,CCCC=C(CC)C=O,-2.46
|
|
12
|
+
2_methylphenanthrene,Cc1ccc2c(ccc3ccccc32)c1,-5.84
|
|
13
|
+
2_phenoxyethanol,OCCOc1ccccc1,-0.7
|
|
14
|
+
3_methylphenol,Cc1cccc(O)c1,-0.68
|
|
15
|
+
4_heptanol,CCCC(O)CCC,-1.4
|
|
16
|
+
5_fluorouracil,Fc1c[nH]c(=O)[nH]c1=O,-1.077
|
|
17
|
+
9_anthrol,c3ccc2c(O)c1ccccc1cc2c3,-4.73
|
|
18
|
+
ancymidol,COc1ccc(cc1)C(O)(C2CC2)c3cncnc3,-2.596
|
|
19
|
+
benfuracarb,CCOC(=O)CCN(SN(C)C(=O)Oc1cccc2CC(C)(C)Oc21)C(C)C,-4.71
|
|
20
|
+
benzonitrile,N#Cc1ccccc1,-1.0
|
|
21
|
+
benzothiazole,c2ccc1scnc1c2,-1.5
|
|
22
|
+
butachlor,CCCCOCN(C(=O)CCl)c1c(CC)cccc1CC,-4.19
|
|
23
|
+
carbanilide,O=C(Nc1ccccc1)Nc2ccccc2,-3.15
|
|
24
|
+
chloropham,CC(C)OC(=O)Nc1cccc(Cl)c1,-3.38
|
|
25
|
+
chlorquinox,c2(Cl)c(Cl)c(Cl)c1nccnc1c2(Cl),-5.43
|
|
26
|
+
citral,CC(C)=CCCC(C)=CC(=O),-2.06
|
|
27
|
+
clonazepam,Clc1ccccc1C2=NCC(=O)Nc3ccc(cc23)N(=O)=O,-3.499
|
|
28
|
+
cycloheptyl_5_spirobarbituric_acid,O=C2NC(=O)C1(CCCCCC1)C(=O)N2,-3.168
|
|
29
|
+
ddt,Clc1ccc(cc1)C(c2ccc(Cl)cc2)C(Cl)(Cl)Cl,-7.15
|
|
30
|
+
deoxycorticosterone,CC12CCC3C(CCC4=CC(=O)CCC34C)C2CCC1C(=O)CO,-3.45
|
|
31
|
+
diazinon,CCOP(=S)(OCC)Oc1cc(C)nc(n1)C(C)C,-3.64
|
|
32
|
+
dibenzothiophene,c1ccc2c(c1)sc3ccccc23,-4.38
|
|
33
|
+
diisooctyl_phthalate,c1(C(=O)OCCCCCC(C)(C))c(C(=O)OCCCCCC(C)(C))cccc1,-6.637
|
|
34
|
+
estradiol,CC12CCC3C(CCc4cc(O)ccc34)C2CCC1O,-5.03
|
|
35
|
+
estrone,CC12CCC3C(CCc4cc(O)ccc34)C2CCC1=O,-3.955
|
|
36
|
+
ethinyl_estradiol,CC34CCC1C(CCc2cc(O)ccc12)C3CCC4(O)C#C,-4.3
|
|
37
|
+
fenarimol,OC(c1ccc(Cl)cc1)(c2cncnc2)c3ccccc3Cl,-4.38
|
|
38
|
+
fenfuram,Cc1occc1C(=O)Nc2ccccc2,-3.3
|
|
39
|
+
fludrocortisone,CC34CC(O)C1(F)C(CCC2=CC(=O)CCC12C)C3CCC4(O)C(=O)CO,-3.43
|
|
40
|
+
fluoranthene,c1ccc2c(c1)c3cccc4cccc2c34,-6.0
|
|
41
|
+
hexacosane,CCCCCCCCCCCCCCCCCCCCCCCCCC,-8.334
|
|
42
|
+
hydrocortisone,CC12CC(O)C3C(CCC4=CC(=O)CCC34C)C2CCC1(O)C(=O)CO,-3.09
|
|
43
|
+
iodofenphos,COP(=S)(OC)Oc1cc(Cl)c(I)cc1Cl,-6.62
|
|
44
|
+
isoproturon,CC(C)c1ccc(NC(=O)N(C)C)cc1,-3.536
|
|
45
|
+
isoquinoline,c1ccc2cnccc2c1,-1.45
|
|
46
|
+
linalool,CC(C)=CCCC(O)(C)C=C,-1.99
|
|
47
|
+
malonic_acid_diethylester,CCOC(=O)CC(=O)OCC,-0.82
|
|
48
|
+
metalaxyl,COCC(=O)N(C(C)C(=O)OC)c1c(C)cccc1C,-1.601
|
|
49
|
+
methoprene,COC(C)(C)CCCC(C)CC=CC(C)=CC(=O)OC(C)C,-5.19
|
|
50
|
+
methoproptryne,COCCCNc1nc(NC(C)C)nc(SC)n1,-2.928
|
|
51
|
+
minoxidil,Nc1cc(nc(N)n1=O)N2CCCCC2,-1.989
|
|
52
|
+
n_methylaniline,CNc1ccccc1,-1.28
|
|
53
|
+
nerol,CC(C)=CCC/C(C)=C\CO,-2.46
|
|
54
|
+
nifuroxime,ON=Cc1ccc(o1)N(=O)=O,-2.19
|
|
55
|
+
nitrapyrin,Clc1cccc(n1)C(Cl)(Cl)Cl,-3.76
|
|
56
|
+
o_nitrotoluene,Cc1ccccc1N(=O)=O,-2.33
|
|
57
|
+
o_xylene,Cc1ccccc1C,-2.8
|
|
58
|
+
oxadiazon,CC(C)Oc1cc(c(Cl)cc1Cl)n2nc(oc2=O)C(C)(C)C,-5.696
|
|
59
|
+
p_cresol,Cc1ccc(O)cc1,-0.73
|
|
60
|
+
p_t_butylphenol,CC(C)(C)c1ccc(O)cc1,-2.41
|
|
61
|
+
perfluidone,Cc1cc(ccc1NS(=O)(=O)C(F)(F)F)S(=O)(=O)c2ccccc2,-3.8
|
|
62
|
+
phenothrin,CC(C)=CC3C(C(=O)OCc2cccc(Oc1ccccc1)c2)C3(C)C,-5.24
|
|
63
|
+
picene,c1ccc2c(c1)ccc3c2ccc4c5ccccc5ccc43,-7.87
|
|
64
|
+
prasterone,CC34CCC1C(CC=C2CC(O)CCC12C)C3CCC4=O,-4.12
|
|
65
|
+
primidone,CCC1(C(=O)NCNC1=O)c2ccccc2,-2.64
|
|
66
|
+
probarbital,CCC1(C(C)C)C(=O)NC(=O)NC1=O,-2.21
|
|
67
|
+
rotenone,COc5cc4OCC3Oc2c1CC(Oc1ccc2C(=O)C3c4cc5OC)C(C)=C,-4.42
|
|
68
|
+
santonin,CC3C2CCC1(C)C=CC(=O)C(=C1C2OC3=O)C,-3.09
|
|
69
|
+
teflubenzuron,Fc1cccc(F)c1C(=O)NC(=O)Nc2cc(Cl)c(F)c(Cl)c2F,-7.28
|
|
70
|
+
triamterene,Nc3nc(N)c2nc(c1ccccc1)c(N)nc2n3,-2.404
|
|
71
|
+
uracil,O=c1cc[nH]c(=O)[nH]1,-1.488
|