minervachem 0.0.3a1__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.
- minervachem-0.0.3a1/.gitattributes +0 -0
- minervachem-0.0.3a1/.github/workflows/deploy-lamel.yml +62 -0
- minervachem-0.0.3a1/.github/workflows/deploy.yml +60 -0
- minervachem-0.0.3a1/.gitignore +12 -0
- minervachem-0.0.3a1/AUTHORS.md +8 -0
- minervachem-0.0.3a1/LICENSE.txt +24 -0
- minervachem-0.0.3a1/NOTICE.md +14 -0
- minervachem-0.0.3a1/PKG-INFO +264 -0
- minervachem-0.0.3a1/README.md +207 -0
- minervachem-0.0.3a1/demos/.gitignore +5 -0
- minervachem-0.0.3a1/demos/1_Obtaining_a_fingerprint.ipynb +875 -0
- minervachem-0.0.3a1/demos/2_Regression_and_visualization.ipynb +827 -0
- minervachem-0.0.3a1/demos/3_Advanced_fitting_and_unseen_bits.ipynb +1198 -0
- minervachem-0.0.3a1/demos/4_PADRE.ipynb +255 -0
- minervachem-0.0.3a1/demos/5_Filtering_substructures_in_fp.ipynb +816 -0
- minervachem-0.0.3a1/demos/benzene_bits.png +0 -0
- minervachem-0.0.3a1/demos/hmodel_interp.png +0 -0
- minervachem-0.0.3a1/demos/hmodel_perf.png +0 -0
- minervachem-0.0.3a1/demos/mcts/1_MCTS_with_RDKit.ipynb +362 -0
- minervachem-0.0.3a1/demos/mcts/2_MCTS_with_MinervaChem.ipynb +254 -0
- minervachem-0.0.3a1/demos/mcts/3_MCTS_experiments.ipynb +395 -0
- minervachem-0.0.3a1/demos/mcts/MCTS Process Flow Diagram.png +0 -0
- minervachem-0.0.3a1/demos/mcts/README.md +37 -0
- minervachem-0.0.3a1/demos/mcts/create_pipeline.py +43 -0
- minervachem-0.0.3a1/demos/process_qm9.py +149 -0
- minervachem-0.0.3a1/demos/reddit_example/README.rst +33 -0
- minervachem-0.0.3a1/demos/reddit_example/ind_benchmark.sl +37 -0
- minervachem-0.0.3a1/demos/reddit_example/reddit_benchmark_out_2026-09-18/benchmark_report.txt +7 -0
- minervachem-0.0.3a1/demos/reddit_example/reddit_benchmark_out_2026-09-18/benchmark_results.csv +1 -0
- minervachem-0.0.3a1/demos/reddit_example/reddit_graphlets_example.py +246 -0
- minervachem-0.0.3a1/demos/reddit_example/reddit_individual_graphs_benchmark.py +262 -0
- minervachem-0.0.3a1/lamel/README.md +54 -0
- minervachem-0.0.3a1/lamel/__init__.py +6 -0
- minervachem-0.0.3a1/lamel/bigsoldb2_preprocessing.ipynb +378 -0
- minervachem-0.0.3a1/lamel/conda_versions_for_lamel_manuscript.txt +26 -0
- minervachem-0.0.3a1/lamel/dataset_loader.py +80 -0
- minervachem-0.0.3a1/lamel/lamel_example.ipynb +184 -0
- minervachem-0.0.3a1/lamel/lamel_learner.py +647 -0
- minervachem-0.0.3a1/lamel/lamel_plotting.py +895 -0
- minervachem-0.0.3a1/lamel/lamel_utilities.py +340 -0
- minervachem-0.0.3a1/lamel/pyproject.toml +17 -0
- minervachem-0.0.3a1/minervachem/__init__.py +1 -0
- minervachem-0.0.3a1/minervachem/correction.py +41 -0
- minervachem-0.0.3a1/minervachem/fingerprinters/__init__.py +21 -0
- minervachem-0.0.3a1/minervachem/fingerprinters/graphletfingerprinter.py +324 -0
- minervachem-0.0.3a1/minervachem/fingerprinters/morganfingerprinter.py +57 -0
- minervachem-0.0.3a1/minervachem/fingerprinters/rdkitfingerprinter.py +58 -0
- minervachem-0.0.3a1/minervachem/graphlet_dags.py +826 -0
- minervachem-0.0.3a1/minervachem/mcts/__init__.py +11 -0
- minervachem-0.0.3a1/minervachem/mcts/sa_score/LICENSE +26 -0
- minervachem-0.0.3a1/minervachem/mcts/sa_score/README.md +21 -0
- minervachem-0.0.3a1/minervachem/mcts/sa_score/__init__.py +5 -0
- minervachem-0.0.3a1/minervachem/mcts/sa_score/fpscores.pkl.gz +0 -0
- minervachem-0.0.3a1/minervachem/mcts/sa_score/sascorer.py +173 -0
- minervachem-0.0.3a1/minervachem/mcts/state.py +364 -0
- minervachem-0.0.3a1/minervachem/mcts/tree.py +304 -0
- minervachem-0.0.3a1/minervachem/mcts/tree_viz.py +214 -0
- minervachem-0.0.3a1/minervachem/networkx_utils.py +277 -0
- minervachem-0.0.3a1/minervachem/padre/README.md +10 -0
- minervachem-0.0.3a1/minervachem/padre/__init__.py +1 -0
- minervachem-0.0.3a1/minervachem/padre/mappers.py +84 -0
- minervachem-0.0.3a1/minervachem/padre/padre.py +114 -0
- minervachem-0.0.3a1/minervachem/plotting.py +380 -0
- minervachem-0.0.3a1/minervachem/regressors.py +349 -0
- minervachem-0.0.3a1/minervachem/scoring.py +30 -0
- minervachem-0.0.3a1/minervachem/sparse_eliminator.py +185 -0
- minervachem-0.0.3a1/minervachem/transformers.py +363 -0
- minervachem-0.0.3a1/minervachem/utils/__init__.py +0 -0
- minervachem-0.0.3a1/minervachem/utils/chemistry.py +98 -0
- minervachem-0.0.3a1/minervachem/utils/misc.py +118 -0
- minervachem-0.0.3a1/minervachem/utils/sparse.py +104 -0
- minervachem-0.0.3a1/minervachem.egg-info/PKG-INFO +264 -0
- minervachem-0.0.3a1/minervachem.egg-info/SOURCES.txt +86 -0
- minervachem-0.0.3a1/minervachem.egg-info/dependency_links.txt +1 -0
- minervachem-0.0.3a1/minervachem.egg-info/requires.txt +35 -0
- minervachem-0.0.3a1/minervachem.egg-info/scm_file_list.json +83 -0
- minervachem-0.0.3a1/minervachem.egg-info/scm_version.json +8 -0
- minervachem-0.0.3a1/minervachem.egg-info/top_level.txt +1 -0
- minervachem-0.0.3a1/package_versions_manuscript.txt +27 -0
- minervachem-0.0.3a1/pyproject.toml +92 -0
- minervachem-0.0.3a1/scripts/run_demo_notebook.sh +121 -0
- minervachem-0.0.3a1/scripts/run_demo_notebooks.sh +210 -0
- minervachem-0.0.3a1/setup.cfg +4 -0
- minervachem-0.0.3a1/test/test_fingerprinters.py +30 -0
- minervachem-0.0.3a1/test/test_hierarchical_regression.py +81 -0
- minervachem-0.0.3a1/test/test_padre.py +125 -0
- minervachem-0.0.3a1/test/test_transformer_internals.py +121 -0
- minervachem-0.0.3a1/uv.lock +2465 -0
|
File without changes
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
name: Publish LAMEL to PyPI
|
|
2
|
+
|
|
3
|
+
on:
|
|
4
|
+
push:
|
|
5
|
+
tags:
|
|
6
|
+
- 'lamel-v[0-9]+.[0-9]+.[0-9]+'
|
|
7
|
+
- 'lamel-v[0-9]+.[0-9]+.[0-9]+a[0-9]+'
|
|
8
|
+
- 'lamel-v[0-9]+.[0-9]+.[0-9]+b[0-9]+'
|
|
9
|
+
- 'lamel-v[0-9]+.[0-9]+.[0-9]+rc[0-9]+'
|
|
10
|
+
|
|
11
|
+
permissions:
|
|
12
|
+
contents: read
|
|
13
|
+
|
|
14
|
+
jobs:
|
|
15
|
+
build:
|
|
16
|
+
name: Build distribution
|
|
17
|
+
runs-on: ubuntu-latest
|
|
18
|
+
|
|
19
|
+
steps:
|
|
20
|
+
- name: Check out repository
|
|
21
|
+
uses: actions/checkout@v6
|
|
22
|
+
|
|
23
|
+
- name: Set up Python
|
|
24
|
+
uses: actions/setup-python@v5
|
|
25
|
+
with:
|
|
26
|
+
python-version: "3.11"
|
|
27
|
+
|
|
28
|
+
- name: Install build tools
|
|
29
|
+
run: python -m pip install --upgrade build
|
|
30
|
+
|
|
31
|
+
- name: Build package
|
|
32
|
+
run: python -m build --outdir dist ./lamel
|
|
33
|
+
|
|
34
|
+
- name: Upload distributions
|
|
35
|
+
uses: actions/upload-artifact@v4
|
|
36
|
+
with:
|
|
37
|
+
name: python-package-distributions
|
|
38
|
+
path: dist/
|
|
39
|
+
|
|
40
|
+
publish:
|
|
41
|
+
name: Publish to PyPI
|
|
42
|
+
needs: build
|
|
43
|
+
runs-on: ubuntu-latest
|
|
44
|
+
|
|
45
|
+
environment:
|
|
46
|
+
name: pypi
|
|
47
|
+
url: https://pypi.org/p/minervachem-lamel
|
|
48
|
+
|
|
49
|
+
permissions:
|
|
50
|
+
id-token: write
|
|
51
|
+
|
|
52
|
+
steps:
|
|
53
|
+
- name: Download distributions
|
|
54
|
+
uses: actions/download-artifact@v5
|
|
55
|
+
with:
|
|
56
|
+
name: python-package-distributions
|
|
57
|
+
path: dist/
|
|
58
|
+
|
|
59
|
+
- name: Publish to PyPI
|
|
60
|
+
uses: pypa/gh-action-pypi-publish@release/v1
|
|
61
|
+
with:
|
|
62
|
+
repository-url: https://test.pypi.org/legacy/
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
name: Publish to PyPI
|
|
2
|
+
|
|
3
|
+
on:
|
|
4
|
+
push:
|
|
5
|
+
tags:
|
|
6
|
+
- 'v[0-9]+.[0-9]+.[0-9]+'
|
|
7
|
+
- 'v[0-9]+.[0-9]+.[0-9]+a[0-9]+'
|
|
8
|
+
- 'v[0-9]+.[0-9]+.[0-9]+b[0-9]+'
|
|
9
|
+
- 'v[0-9]+.[0-9]+.[0-9]+rc[0-9]+'
|
|
10
|
+
|
|
11
|
+
permissions:
|
|
12
|
+
contents: read
|
|
13
|
+
|
|
14
|
+
jobs:
|
|
15
|
+
build:
|
|
16
|
+
name: Build distribution
|
|
17
|
+
runs-on: ubuntu-latest
|
|
18
|
+
|
|
19
|
+
steps:
|
|
20
|
+
- name: Check out repository
|
|
21
|
+
uses: actions/checkout@v6
|
|
22
|
+
|
|
23
|
+
- name: Set up Python
|
|
24
|
+
uses: actions/setup-python@v5
|
|
25
|
+
with:
|
|
26
|
+
python-version: "3.11"
|
|
27
|
+
|
|
28
|
+
- name: Install build tools
|
|
29
|
+
run: python -m pip install --upgrade build
|
|
30
|
+
|
|
31
|
+
- name: Build package
|
|
32
|
+
run: python -m build
|
|
33
|
+
|
|
34
|
+
- name: Upload distributions
|
|
35
|
+
uses: actions/upload-artifact@v4
|
|
36
|
+
with:
|
|
37
|
+
name: python-package-distributions
|
|
38
|
+
path: dist/
|
|
39
|
+
|
|
40
|
+
publish:
|
|
41
|
+
name: Publish to PyPI
|
|
42
|
+
needs: build
|
|
43
|
+
runs-on: ubuntu-latest
|
|
44
|
+
|
|
45
|
+
environment:
|
|
46
|
+
name: pypi
|
|
47
|
+
url: https://pypi.org/p/minervachem
|
|
48
|
+
|
|
49
|
+
permissions:
|
|
50
|
+
id-token: write
|
|
51
|
+
|
|
52
|
+
steps:
|
|
53
|
+
- name: Download distributions
|
|
54
|
+
uses: actions/download-artifact@v5
|
|
55
|
+
with:
|
|
56
|
+
name: python-package-distributions
|
|
57
|
+
path: dist/
|
|
58
|
+
|
|
59
|
+
- name: Publish to PyPI
|
|
60
|
+
uses: pypa/gh-action-pypi-publish@release/v1
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
This program is Open-Source under the BSD-3 License.
|
|
2
|
+
|
|
3
|
+
Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
|
|
4
|
+
1. Redistributions of source code must retain the above copyright notice, this list of conditions and
|
|
5
|
+
the following disclaimer.
|
|
6
|
+
|
|
7
|
+
2.Redistributions in binary form must reproduce the above copyright notice, this list of conditions
|
|
8
|
+
and the following disclaimer in the documentation and/or other materials provided with the
|
|
9
|
+
distribution.
|
|
10
|
+
|
|
11
|
+
3.Neither the name of the copyright holder nor the names of its contributors may be used to endorse
|
|
12
|
+
or promote products derived from this software without specific prior written permission.
|
|
13
|
+
|
|
14
|
+
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
|
|
15
|
+
IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
|
16
|
+
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
|
17
|
+
PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
|
|
18
|
+
CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
|
|
19
|
+
EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
|
20
|
+
PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
|
|
21
|
+
OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
|
|
22
|
+
WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
|
|
23
|
+
OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
|
|
24
|
+
ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
# Third-party notices
|
|
2
|
+
|
|
3
|
+
This project includes a vendored copy of the RDKit Contrib SA Score
|
|
4
|
+
implementation under `minervachem/mcts/sa_score/`.
|
|
5
|
+
|
|
6
|
+
The vendored component consists of `sascorer.py` and `fpscores.pkl.gz`. It is
|
|
7
|
+
based on the RDKit Contrib `SA_Score` implementation and retains its original
|
|
8
|
+
copyright and BSD license terms. See:
|
|
9
|
+
|
|
10
|
+
- `minervachem/mcts/sa_score/LICENSE`
|
|
11
|
+
- `minervachem/mcts/sa_score/README.md`
|
|
12
|
+
|
|
13
|
+
The notice and license apply to the vendored SA Score component and do not
|
|
14
|
+
replace or modify MinervaChem's project license for the rest of the project.
|
|
@@ -0,0 +1,264 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: minervachem
|
|
3
|
+
Version: 0.0.3a1
|
|
4
|
+
Summary: Machine learning for Cheminformatics
|
|
5
|
+
Author-email: Michael Frederick Tynes <mtynes@lanl.gov>
|
|
6
|
+
License: BSD 3-Clause License
|
|
7
|
+
Project-URL: Homepage, https://github.com/lanl/minervachem
|
|
8
|
+
Project-URL: Bug Tracker, https://github.com/lanl/minervachem/issues
|
|
9
|
+
Project-URL: Source Code, https://github.com/lanl/minervachem
|
|
10
|
+
Classifier: Development Status :: 3 - Alpha
|
|
11
|
+
Classifier: Intended Audience :: Science/Research
|
|
12
|
+
Classifier: License :: OSI Approved :: BSD License
|
|
13
|
+
Classifier: Operating System :: OS Independent
|
|
14
|
+
Classifier: Programming Language :: Python :: 3
|
|
15
|
+
Classifier: Topic :: Scientific/Engineering :: Physics
|
|
16
|
+
Classifier: Topic :: Scientific/Engineering :: Chemistry
|
|
17
|
+
Classifier: Topic :: Software Development :: Libraries
|
|
18
|
+
Requires-Python: <3.12,>=3.11
|
|
19
|
+
Description-Content-Type: text/markdown
|
|
20
|
+
License-File: LICENSE.txt
|
|
21
|
+
License-File: NOTICE.md
|
|
22
|
+
License-File: AUTHORS.md
|
|
23
|
+
Requires-Dist: numpy
|
|
24
|
+
Requires-Dist: scipy
|
|
25
|
+
Requires-Dist: pandas
|
|
26
|
+
Requires-Dist: scikit-learn
|
|
27
|
+
Requires-Dist: tqdm
|
|
28
|
+
Requires-Dist: sigfig
|
|
29
|
+
Requires-Dist: matplotlib
|
|
30
|
+
Requires-Dist: pillow
|
|
31
|
+
Requires-Dist: imageio
|
|
32
|
+
Requires-Dist: lightgbm
|
|
33
|
+
Requires-Dist: flaml
|
|
34
|
+
Requires-Dist: networkx
|
|
35
|
+
Requires-Dist: cairosvg
|
|
36
|
+
Requires-Dist: jupyterlab
|
|
37
|
+
Requires-Dist: ipywidgets
|
|
38
|
+
Requires-Dist: seaborn
|
|
39
|
+
Requires-Dist: joblib>=1.3.0
|
|
40
|
+
Requires-Dist: svglib
|
|
41
|
+
Requires-Dist: sparse>=0.13.0
|
|
42
|
+
Requires-Dist: dask
|
|
43
|
+
Requires-Dist: distributed
|
|
44
|
+
Requires-Dist: rdkit<2026.0,>2023.9.6
|
|
45
|
+
Requires-Dist: buhito<1
|
|
46
|
+
Requires-Dist: reportlab
|
|
47
|
+
Requires-Dist: architector
|
|
48
|
+
Provides-Extra: lamel
|
|
49
|
+
Requires-Dist: minervachem-lamel<1.0; extra == "lamel"
|
|
50
|
+
Provides-Extra: dev
|
|
51
|
+
Requires-Dist: pytest<10.0,>=6.2.4; extra == "dev"
|
|
52
|
+
Requires-Dist: coverage<8.0,>=5.5; extra == "dev"
|
|
53
|
+
Requires-Dist: PyTDC; extra == "dev"
|
|
54
|
+
Requires-Dist: setuptools<82,>=61; extra == "dev"
|
|
55
|
+
Requires-Dist: xgboost; extra == "dev"
|
|
56
|
+
Dynamic: license-file
|
|
57
|
+
|
|
58
|
+
# MinervaChem - a python library for cheminformatics and machine learning
|
|
59
|
+
|
|
60
|
+
Minervachem implements Graphlet Fingerprints and other utilities cheminformatics and chemical machine learning.
|
|
61
|
+
|
|
62
|
+
This is an alpha release, so be prepared for breaking changes --
|
|
63
|
+
keep track of what version you are using if you need to maintain consistency.
|
|
64
|
+
|
|
65
|
+
## Installation
|
|
66
|
+
|
|
67
|
+
1. Clone this repo and `cd` into it
|
|
68
|
+
2. `uv sync --all-extras`
|
|
69
|
+
3. Choose one:
|
|
70
|
+
- `source .venv/bin/activate` (Linux / MacOS)
|
|
71
|
+
- `.venv\Scripts\activate.bat` (Windows)
|
|
72
|
+
|
|
73
|
+
### Optional LAMEL add-on
|
|
74
|
+
|
|
75
|
+
LAMEL is maintained as a separate package in this repository. To install it
|
|
76
|
+
alongside MinervaChem from this checkout, run:
|
|
77
|
+
|
|
78
|
+
```sh
|
|
79
|
+
uv sync --extra lamel
|
|
80
|
+
```
|
|
81
|
+
|
|
82
|
+
Published releases support the equivalent pip command:
|
|
83
|
+
|
|
84
|
+
```sh
|
|
85
|
+
pip install "minervachem[lamel]"
|
|
86
|
+
```
|
|
87
|
+
|
|
88
|
+
The add-on is imported separately:
|
|
89
|
+
|
|
90
|
+
```python
|
|
91
|
+
from lamel import MetaLearner
|
|
92
|
+
```
|
|
93
|
+
|
|
94
|
+
# Getting started with `minervachem`
|
|
95
|
+
|
|
96
|
+
We recommend looking through and running the notebooks in the `demos/` directory for a detailed introduction to `minervachem`'s funcitonality.
|
|
97
|
+
|
|
98
|
+
## Running Reddit Demo
|
|
99
|
+
|
|
100
|
+
### Graphlets
|
|
101
|
+
```sh
|
|
102
|
+
uv run python demos/reddit_example/reddit_graphlets_example.py
|
|
103
|
+
```
|
|
104
|
+
|
|
105
|
+
### Benchmark
|
|
106
|
+
```sh
|
|
107
|
+
uv run python demos/reddit_example/reddit_individual_graphs_benchmark.py demos/reddit_example/reddit_graphs_benchmarks
|
|
108
|
+
```
|
|
109
|
+
|
|
110
|
+
## Highlights
|
|
111
|
+
|
|
112
|
+
### Constructing graphlet fingerprints
|
|
113
|
+
|
|
114
|
+
`Fingerprinter` classes provide reusable objects for generating molecular fingerprints, including the graphlet fingerprints described in our manuscript.
|
|
115
|
+
|
|
116
|
+
```python
|
|
117
|
+
from rdkit.Chem import MolFromSmiles, AddHs
|
|
118
|
+
from minervachem.fingerprinters import GraphletFingerprinter
|
|
119
|
+
|
|
120
|
+
# Benzene
|
|
121
|
+
mol = AddHs(MolFromSmiles('c1ccccc1'))
|
|
122
|
+
|
|
123
|
+
# Reusable Fingerprinter object
|
|
124
|
+
fingerprinter = GraphletFingerprinter(max_len=3)
|
|
125
|
+
|
|
126
|
+
# Fingerprints are a map from fragment IDs to fragment counts.
|
|
127
|
+
# The fragments are identified by their number of atoms and a hash.
|
|
128
|
+
fp, bi = fingerprinter(mol)
|
|
129
|
+
print(fp)
|
|
130
|
+
>>> {(3, 10387847931347882557): 6,
|
|
131
|
+
>>> (2, 10630435057451682469): 6,
|
|
132
|
+
>>> (2, 11665740151475091393): 6,
|
|
133
|
+
>>> (3, 14577436124092730684): 12,
|
|
134
|
+
>>> (1, 20784809936286627226): 6,
|
|
135
|
+
>>> (1, 12794648790135253294): 6}
|
|
136
|
+
|
|
137
|
+
# We can visualize the above dictiory with a plotting method
|
|
138
|
+
from minervachem.plotting import plot_fingerprint
|
|
139
|
+
plot_fingerprint(mol, fingerprinter)
|
|
140
|
+
```
|
|
141
|
+

|
|
142
|
+
|
|
143
|
+
### scikit-learn transformers
|
|
144
|
+
|
|
145
|
+
We can quickly construct feature matrices for machine learning from a set of molecules using `minervachem`'s provided `sklearn`-style transformers:
|
|
146
|
+
|
|
147
|
+
```python
|
|
148
|
+
from minervachem.transformers import FingerprintFeaturizer
|
|
149
|
+
|
|
150
|
+
mols = [MolFromSmiles(s) for s in [
|
|
151
|
+
'c1ccccc1',
|
|
152
|
+
'NCNOCOC',
|
|
153
|
+
'CN1C=NC2=C1C(=O)N(C(=O)N2C)C',
|
|
154
|
+
'CNO',
|
|
155
|
+
]]
|
|
156
|
+
|
|
157
|
+
featurizer = FingerprintFeaturizer(
|
|
158
|
+
fingerprinter,
|
|
159
|
+
n_jobs=2 # parallelism for large datasets
|
|
160
|
+
)
|
|
161
|
+
|
|
162
|
+
# FingerprintFeaturizer implements the sklearn transformer API
|
|
163
|
+
feature_matrix = featurizer.fit_transform(mols)
|
|
164
|
+
# which generates sparse integer matrices by default
|
|
165
|
+
feature_matrix
|
|
166
|
+
```
|
|
167
|
+
```
|
|
168
|
+
>>> <4x39 sparse matrix of type '<class 'numpy.int64'>'
|
|
169
|
+
with 44 stored elements in Compressed Sparse Row format>
|
|
170
|
+
```
|
|
171
|
+
|
|
172
|
+
### Building Interpretable Machine Learning Models
|
|
173
|
+
#### Model fitting
|
|
174
|
+
|
|
175
|
+
After constructing a dataset through the methods above, we can use `minervachem` to fit an interpretable ML model.
|
|
176
|
+
|
|
177
|
+
The below is a snippet from the demo notebook which fits a hierarchical linear model with ~6,000 coefficients to ~100,000 molecules from QM9.
|
|
178
|
+
|
|
179
|
+
```python
|
|
180
|
+
import minervachem
|
|
181
|
+
from sklearn.linear_model import Ridge
|
|
182
|
+
from minervachem.regressors import HierarchicalResidualModel
|
|
183
|
+
from minervachem.plotting import parity_plot_train_test
|
|
184
|
+
|
|
185
|
+
|
|
186
|
+
# build a higherarchical residual model
|
|
187
|
+
# using a ridge regressor base model
|
|
188
|
+
base_model = Ridge(fit_intercept=False,
|
|
189
|
+
alpha=1e-5,
|
|
190
|
+
solver='sparse_cg')
|
|
191
|
+
hmodel = HierarchicalResidualModel(regressor=base_model,verbose=1)
|
|
192
|
+
hmodel.fit(X_train,y_train,levels=featurizer.bit_sizes_)
|
|
193
|
+
|
|
194
|
+
# visualize the train and test performance with
|
|
195
|
+
# minervachem's plotting methods
|
|
196
|
+
parity_plot_train_test([X_train, X_test],
|
|
197
|
+
[y_train, y_test],
|
|
198
|
+
hmodel,
|
|
199
|
+
figsize=(12, 4),
|
|
200
|
+
xlab='DFT (kcal/mol)',
|
|
201
|
+
ylab='Linear Model (kcal/mol)',
|
|
202
|
+
title='Hierarchical Model Prediction');
|
|
203
|
+
```
|
|
204
|
+

|
|
205
|
+
|
|
206
|
+
|
|
207
|
+
#### Model interpretations
|
|
208
|
+
Linear models are interpretable, but 6,000 coefficients is too many to look at all at once. (The most accurate models in our manuscript had >100,000 coefficients.) So, we use `minervachem`'s projection methods to visualize atom- or bond-level contributions to model predictions for a set of molecules.
|
|
209
|
+
|
|
210
|
+
First we construct the Directed-Acyclic-Graph (DAG) between molecular graphlets that defines our projection operation:
|
|
211
|
+
|
|
212
|
+
```python
|
|
213
|
+
from minervachem.graphlet_dags import GraphletDAG, draw_projected_coefs
|
|
214
|
+
|
|
215
|
+
# Construct the DAG relating larger graphlets to smaller ones
|
|
216
|
+
# for each molecule
|
|
217
|
+
dags = []
|
|
218
|
+
for mol in mols:
|
|
219
|
+
dag = GraphletDAG(mol,
|
|
220
|
+
fingerprinter=featurizer.fingerprinter, # the fingerprinter that creates the graphlets
|
|
221
|
+
bit_ids=featurizer.bit_ids_, # The bit ids for the features used in the model training
|
|
222
|
+
coef=hmodel.coef_ # The model coefficients as an array.
|
|
223
|
+
)
|
|
224
|
+
dags.append(dag)
|
|
225
|
+
|
|
226
|
+
draw_projected_coefs(dags,
|
|
227
|
+
level=2, # bond-level interpretations (atom-level is 1)
|
|
228
|
+
)
|
|
229
|
+
```
|
|
230
|
+

|
|
231
|
+
|
|
232
|
+
|
|
233
|
+
## Citation
|
|
234
|
+
If you use minervachem in your work, please cite [our paper](https://doi.org/10.26434/chemrxiv-2024-r81c8)
|
|
235
|
+
|
|
236
|
+
```latex
|
|
237
|
+
@article{tynes2024linear,
|
|
238
|
+
title={Linear Graphlet Models for Accurate and Interpretable Cheminformatics},
|
|
239
|
+
author={Tynes, Michael and Taylor, Michael G and Janssen, Jan and Burrill, Daniel J and Perez, Danny and Yang, Ping and Lubbers, Nicholas},
|
|
240
|
+
journal={ChemRxiv preprint},
|
|
241
|
+
doi={10.26434/chemrxiv-2024-r81c8},
|
|
242
|
+
url={dx.doi.org/10.26434/chemrxiv-2024-r81c8},
|
|
243
|
+
year={2024}
|
|
244
|
+
}
|
|
245
|
+
```
|
|
246
|
+
|
|
247
|
+
## Copyright and licensing
|
|
248
|
+
|
|
249
|
+
`minervachem` is released under the BSD-3 License. See LICENSE.txt for the full license.
|
|
250
|
+
|
|
251
|
+
|
|
252
|
+
The copyright to `minervachem` is owned by Triad National Security, LLC
|
|
253
|
+
and is released for open source use as project number O04631.
|
|
254
|
+
|
|
255
|
+
|
|
256
|
+
© 2023. Triad National Security, LLC. All rights reserved.
|
|
257
|
+
This program was produced under U.S. Government contract 89233218CNA000001 for Los Alamos
|
|
258
|
+
National Laboratory (LANL), which is operated by Triad National Security, LLC for the U.S.
|
|
259
|
+
Department of Energy/National Nuclear Security Administration. All rights in the program are.
|
|
260
|
+
reserved by Triad National Security, LLC, and the U.S. Department of Energy/National Nuclear
|
|
261
|
+
Security Administration. The Government is granted for itself and others acting on its behalf a
|
|
262
|
+
nonexclusive, paid-up, irrevocable worldwide license in this material to reproduce, prepare.
|
|
263
|
+
derivative works, distribute copies to the public, perform publicly and display publicly, and to permit.
|
|
264
|
+
others to do so.
|
|
@@ -0,0 +1,207 @@
|
|
|
1
|
+
# MinervaChem - a python library for cheminformatics and machine learning
|
|
2
|
+
|
|
3
|
+
Minervachem implements Graphlet Fingerprints and other utilities cheminformatics and chemical machine learning.
|
|
4
|
+
|
|
5
|
+
This is an alpha release, so be prepared for breaking changes --
|
|
6
|
+
keep track of what version you are using if you need to maintain consistency.
|
|
7
|
+
|
|
8
|
+
## Installation
|
|
9
|
+
|
|
10
|
+
1. Clone this repo and `cd` into it
|
|
11
|
+
2. `uv sync --all-extras`
|
|
12
|
+
3. Choose one:
|
|
13
|
+
- `source .venv/bin/activate` (Linux / MacOS)
|
|
14
|
+
- `.venv\Scripts\activate.bat` (Windows)
|
|
15
|
+
|
|
16
|
+
### Optional LAMEL add-on
|
|
17
|
+
|
|
18
|
+
LAMEL is maintained as a separate package in this repository. To install it
|
|
19
|
+
alongside MinervaChem from this checkout, run:
|
|
20
|
+
|
|
21
|
+
```sh
|
|
22
|
+
uv sync --extra lamel
|
|
23
|
+
```
|
|
24
|
+
|
|
25
|
+
Published releases support the equivalent pip command:
|
|
26
|
+
|
|
27
|
+
```sh
|
|
28
|
+
pip install "minervachem[lamel]"
|
|
29
|
+
```
|
|
30
|
+
|
|
31
|
+
The add-on is imported separately:
|
|
32
|
+
|
|
33
|
+
```python
|
|
34
|
+
from lamel import MetaLearner
|
|
35
|
+
```
|
|
36
|
+
|
|
37
|
+
# Getting started with `minervachem`
|
|
38
|
+
|
|
39
|
+
We recommend looking through and running the notebooks in the `demos/` directory for a detailed introduction to `minervachem`'s funcitonality.
|
|
40
|
+
|
|
41
|
+
## Running Reddit Demo
|
|
42
|
+
|
|
43
|
+
### Graphlets
|
|
44
|
+
```sh
|
|
45
|
+
uv run python demos/reddit_example/reddit_graphlets_example.py
|
|
46
|
+
```
|
|
47
|
+
|
|
48
|
+
### Benchmark
|
|
49
|
+
```sh
|
|
50
|
+
uv run python demos/reddit_example/reddit_individual_graphs_benchmark.py demos/reddit_example/reddit_graphs_benchmarks
|
|
51
|
+
```
|
|
52
|
+
|
|
53
|
+
## Highlights
|
|
54
|
+
|
|
55
|
+
### Constructing graphlet fingerprints
|
|
56
|
+
|
|
57
|
+
`Fingerprinter` classes provide reusable objects for generating molecular fingerprints, including the graphlet fingerprints described in our manuscript.
|
|
58
|
+
|
|
59
|
+
```python
|
|
60
|
+
from rdkit.Chem import MolFromSmiles, AddHs
|
|
61
|
+
from minervachem.fingerprinters import GraphletFingerprinter
|
|
62
|
+
|
|
63
|
+
# Benzene
|
|
64
|
+
mol = AddHs(MolFromSmiles('c1ccccc1'))
|
|
65
|
+
|
|
66
|
+
# Reusable Fingerprinter object
|
|
67
|
+
fingerprinter = GraphletFingerprinter(max_len=3)
|
|
68
|
+
|
|
69
|
+
# Fingerprints are a map from fragment IDs to fragment counts.
|
|
70
|
+
# The fragments are identified by their number of atoms and a hash.
|
|
71
|
+
fp, bi = fingerprinter(mol)
|
|
72
|
+
print(fp)
|
|
73
|
+
>>> {(3, 10387847931347882557): 6,
|
|
74
|
+
>>> (2, 10630435057451682469): 6,
|
|
75
|
+
>>> (2, 11665740151475091393): 6,
|
|
76
|
+
>>> (3, 14577436124092730684): 12,
|
|
77
|
+
>>> (1, 20784809936286627226): 6,
|
|
78
|
+
>>> (1, 12794648790135253294): 6}
|
|
79
|
+
|
|
80
|
+
# We can visualize the above dictiory with a plotting method
|
|
81
|
+
from minervachem.plotting import plot_fingerprint
|
|
82
|
+
plot_fingerprint(mol, fingerprinter)
|
|
83
|
+
```
|
|
84
|
+

|
|
85
|
+
|
|
86
|
+
### scikit-learn transformers
|
|
87
|
+
|
|
88
|
+
We can quickly construct feature matrices for machine learning from a set of molecules using `minervachem`'s provided `sklearn`-style transformers:
|
|
89
|
+
|
|
90
|
+
```python
|
|
91
|
+
from minervachem.transformers import FingerprintFeaturizer
|
|
92
|
+
|
|
93
|
+
mols = [MolFromSmiles(s) for s in [
|
|
94
|
+
'c1ccccc1',
|
|
95
|
+
'NCNOCOC',
|
|
96
|
+
'CN1C=NC2=C1C(=O)N(C(=O)N2C)C',
|
|
97
|
+
'CNO',
|
|
98
|
+
]]
|
|
99
|
+
|
|
100
|
+
featurizer = FingerprintFeaturizer(
|
|
101
|
+
fingerprinter,
|
|
102
|
+
n_jobs=2 # parallelism for large datasets
|
|
103
|
+
)
|
|
104
|
+
|
|
105
|
+
# FingerprintFeaturizer implements the sklearn transformer API
|
|
106
|
+
feature_matrix = featurizer.fit_transform(mols)
|
|
107
|
+
# which generates sparse integer matrices by default
|
|
108
|
+
feature_matrix
|
|
109
|
+
```
|
|
110
|
+
```
|
|
111
|
+
>>> <4x39 sparse matrix of type '<class 'numpy.int64'>'
|
|
112
|
+
with 44 stored elements in Compressed Sparse Row format>
|
|
113
|
+
```
|
|
114
|
+
|
|
115
|
+
### Building Interpretable Machine Learning Models
|
|
116
|
+
#### Model fitting
|
|
117
|
+
|
|
118
|
+
After constructing a dataset through the methods above, we can use `minervachem` to fit an interpretable ML model.
|
|
119
|
+
|
|
120
|
+
The below is a snippet from the demo notebook which fits a hierarchical linear model with ~6,000 coefficients to ~100,000 molecules from QM9.
|
|
121
|
+
|
|
122
|
+
```python
|
|
123
|
+
import minervachem
|
|
124
|
+
from sklearn.linear_model import Ridge
|
|
125
|
+
from minervachem.regressors import HierarchicalResidualModel
|
|
126
|
+
from minervachem.plotting import parity_plot_train_test
|
|
127
|
+
|
|
128
|
+
|
|
129
|
+
# build a higherarchical residual model
|
|
130
|
+
# using a ridge regressor base model
|
|
131
|
+
base_model = Ridge(fit_intercept=False,
|
|
132
|
+
alpha=1e-5,
|
|
133
|
+
solver='sparse_cg')
|
|
134
|
+
hmodel = HierarchicalResidualModel(regressor=base_model,verbose=1)
|
|
135
|
+
hmodel.fit(X_train,y_train,levels=featurizer.bit_sizes_)
|
|
136
|
+
|
|
137
|
+
# visualize the train and test performance with
|
|
138
|
+
# minervachem's plotting methods
|
|
139
|
+
parity_plot_train_test([X_train, X_test],
|
|
140
|
+
[y_train, y_test],
|
|
141
|
+
hmodel,
|
|
142
|
+
figsize=(12, 4),
|
|
143
|
+
xlab='DFT (kcal/mol)',
|
|
144
|
+
ylab='Linear Model (kcal/mol)',
|
|
145
|
+
title='Hierarchical Model Prediction');
|
|
146
|
+
```
|
|
147
|
+

|
|
148
|
+
|
|
149
|
+
|
|
150
|
+
#### Model interpretations
|
|
151
|
+
Linear models are interpretable, but 6,000 coefficients is too many to look at all at once. (The most accurate models in our manuscript had >100,000 coefficients.) So, we use `minervachem`'s projection methods to visualize atom- or bond-level contributions to model predictions for a set of molecules.
|
|
152
|
+
|
|
153
|
+
First we construct the Directed-Acyclic-Graph (DAG) between molecular graphlets that defines our projection operation:
|
|
154
|
+
|
|
155
|
+
```python
|
|
156
|
+
from minervachem.graphlet_dags import GraphletDAG, draw_projected_coefs
|
|
157
|
+
|
|
158
|
+
# Construct the DAG relating larger graphlets to smaller ones
|
|
159
|
+
# for each molecule
|
|
160
|
+
dags = []
|
|
161
|
+
for mol in mols:
|
|
162
|
+
dag = GraphletDAG(mol,
|
|
163
|
+
fingerprinter=featurizer.fingerprinter, # the fingerprinter that creates the graphlets
|
|
164
|
+
bit_ids=featurizer.bit_ids_, # The bit ids for the features used in the model training
|
|
165
|
+
coef=hmodel.coef_ # The model coefficients as an array.
|
|
166
|
+
)
|
|
167
|
+
dags.append(dag)
|
|
168
|
+
|
|
169
|
+
draw_projected_coefs(dags,
|
|
170
|
+
level=2, # bond-level interpretations (atom-level is 1)
|
|
171
|
+
)
|
|
172
|
+
```
|
|
173
|
+

|
|
174
|
+
|
|
175
|
+
|
|
176
|
+
## Citation
|
|
177
|
+
If you use minervachem in your work, please cite [our paper](https://doi.org/10.26434/chemrxiv-2024-r81c8)
|
|
178
|
+
|
|
179
|
+
```latex
|
|
180
|
+
@article{tynes2024linear,
|
|
181
|
+
title={Linear Graphlet Models for Accurate and Interpretable Cheminformatics},
|
|
182
|
+
author={Tynes, Michael and Taylor, Michael G and Janssen, Jan and Burrill, Daniel J and Perez, Danny and Yang, Ping and Lubbers, Nicholas},
|
|
183
|
+
journal={ChemRxiv preprint},
|
|
184
|
+
doi={10.26434/chemrxiv-2024-r81c8},
|
|
185
|
+
url={dx.doi.org/10.26434/chemrxiv-2024-r81c8},
|
|
186
|
+
year={2024}
|
|
187
|
+
}
|
|
188
|
+
```
|
|
189
|
+
|
|
190
|
+
## Copyright and licensing
|
|
191
|
+
|
|
192
|
+
`minervachem` is released under the BSD-3 License. See LICENSE.txt for the full license.
|
|
193
|
+
|
|
194
|
+
|
|
195
|
+
The copyright to `minervachem` is owned by Triad National Security, LLC
|
|
196
|
+
and is released for open source use as project number O04631.
|
|
197
|
+
|
|
198
|
+
|
|
199
|
+
© 2023. Triad National Security, LLC. All rights reserved.
|
|
200
|
+
This program was produced under U.S. Government contract 89233218CNA000001 for Los Alamos
|
|
201
|
+
National Laboratory (LANL), which is operated by Triad National Security, LLC for the U.S.
|
|
202
|
+
Department of Energy/National Nuclear Security Administration. All rights in the program are.
|
|
203
|
+
reserved by Triad National Security, LLC, and the U.S. Department of Energy/National Nuclear
|
|
204
|
+
Security Administration. The Government is granted for itself and others acting on its behalf a
|
|
205
|
+
nonexclusive, paid-up, irrevocable worldwide license in this material to reproduce, prepare.
|
|
206
|
+
derivative works, distribute copies to the public, perform publicly and display publicly, and to permit.
|
|
207
|
+
others to do so.
|