minervachem 0.0.1a2__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.
Files changed (88) hide show
  1. minervachem-0.0.1a2/.gitattributes +0 -0
  2. minervachem-0.0.1a2/.github/workflows/deploy-lamel.yml +60 -0
  3. minervachem-0.0.1a2/.github/workflows/deploy.yml +60 -0
  4. minervachem-0.0.1a2/.gitignore +12 -0
  5. minervachem-0.0.1a2/AUTHORS.md +8 -0
  6. minervachem-0.0.1a2/LICENSE.txt +24 -0
  7. minervachem-0.0.1a2/NOTICE.md +14 -0
  8. minervachem-0.0.1a2/PKG-INFO +243 -0
  9. minervachem-0.0.1a2/README.md +186 -0
  10. minervachem-0.0.1a2/demos/.gitignore +5 -0
  11. minervachem-0.0.1a2/demos/1_Obtaining_a_fingerprint.ipynb +875 -0
  12. minervachem-0.0.1a2/demos/2_Regression_and_visualization.ipynb +827 -0
  13. minervachem-0.0.1a2/demos/3_Advanced_fitting_and_unseen_bits.ipynb +1198 -0
  14. minervachem-0.0.1a2/demos/4_PADRE.ipynb +255 -0
  15. minervachem-0.0.1a2/demos/5_Filtering_substructures_in_fp.ipynb +816 -0
  16. minervachem-0.0.1a2/demos/benzene_bits.png +0 -0
  17. minervachem-0.0.1a2/demos/hmodel_interp.png +0 -0
  18. minervachem-0.0.1a2/demos/hmodel_perf.png +0 -0
  19. minervachem-0.0.1a2/demos/mcts/1_MCTS_with_RDKit.ipynb +362 -0
  20. minervachem-0.0.1a2/demos/mcts/2_MCTS_with_MinervaChem.ipynb +254 -0
  21. minervachem-0.0.1a2/demos/mcts/3_MCTS_experiments.ipynb +395 -0
  22. minervachem-0.0.1a2/demos/mcts/MCTS Process Flow Diagram.png +0 -0
  23. minervachem-0.0.1a2/demos/mcts/README.md +37 -0
  24. minervachem-0.0.1a2/demos/mcts/create_pipeline.py +43 -0
  25. minervachem-0.0.1a2/demos/process_qm9.py +149 -0
  26. minervachem-0.0.1a2/demos/reddit_example/README.rst +33 -0
  27. minervachem-0.0.1a2/demos/reddit_example/ind_benchmark.sl +37 -0
  28. minervachem-0.0.1a2/demos/reddit_example/reddit_benchmark_out_2026-09-18/benchmark_report.txt +7 -0
  29. minervachem-0.0.1a2/demos/reddit_example/reddit_benchmark_out_2026-09-18/benchmark_results.csv +1 -0
  30. minervachem-0.0.1a2/demos/reddit_example/reddit_graphlets_example.py +246 -0
  31. minervachem-0.0.1a2/demos/reddit_example/reddit_individual_graphs_benchmark.py +262 -0
  32. minervachem-0.0.1a2/lamel/README.md +54 -0
  33. minervachem-0.0.1a2/lamel/__init__.py +6 -0
  34. minervachem-0.0.1a2/lamel/bigsoldb2_preprocessing.ipynb +378 -0
  35. minervachem-0.0.1a2/lamel/conda_versions_for_lamel_manuscript.txt +26 -0
  36. minervachem-0.0.1a2/lamel/dataset_loader.py +80 -0
  37. minervachem-0.0.1a2/lamel/lamel_example.ipynb +184 -0
  38. minervachem-0.0.1a2/lamel/lamel_learner.py +647 -0
  39. minervachem-0.0.1a2/lamel/lamel_plotting.py +895 -0
  40. minervachem-0.0.1a2/lamel/lamel_utilities.py +340 -0
  41. minervachem-0.0.1a2/lamel/pyproject.toml +37 -0
  42. minervachem-0.0.1a2/minervachem/__init__.py +1 -0
  43. minervachem-0.0.1a2/minervachem/correction.py +41 -0
  44. minervachem-0.0.1a2/minervachem/fingerprinters/__init__.py +21 -0
  45. minervachem-0.0.1a2/minervachem/fingerprinters/graphletfingerprinter.py +324 -0
  46. minervachem-0.0.1a2/minervachem/fingerprinters/morganfingerprinter.py +57 -0
  47. minervachem-0.0.1a2/minervachem/fingerprinters/rdkitfingerprinter.py +58 -0
  48. minervachem-0.0.1a2/minervachem/graphlet_dags.py +826 -0
  49. minervachem-0.0.1a2/minervachem/mcts/__init__.py +11 -0
  50. minervachem-0.0.1a2/minervachem/mcts/sa_score/LICENSE +26 -0
  51. minervachem-0.0.1a2/minervachem/mcts/sa_score/README.md +21 -0
  52. minervachem-0.0.1a2/minervachem/mcts/sa_score/__init__.py +5 -0
  53. minervachem-0.0.1a2/minervachem/mcts/sa_score/fpscores.pkl.gz +0 -0
  54. minervachem-0.0.1a2/minervachem/mcts/sa_score/sascorer.py +173 -0
  55. minervachem-0.0.1a2/minervachem/mcts/state.py +364 -0
  56. minervachem-0.0.1a2/minervachem/mcts/tree.py +304 -0
  57. minervachem-0.0.1a2/minervachem/mcts/tree_viz.py +214 -0
  58. minervachem-0.0.1a2/minervachem/networkx_utils.py +277 -0
  59. minervachem-0.0.1a2/minervachem/padre/README.md +10 -0
  60. minervachem-0.0.1a2/minervachem/padre/__init__.py +1 -0
  61. minervachem-0.0.1a2/minervachem/padre/mappers.py +84 -0
  62. minervachem-0.0.1a2/minervachem/padre/padre.py +114 -0
  63. minervachem-0.0.1a2/minervachem/plotting.py +380 -0
  64. minervachem-0.0.1a2/minervachem/regressors.py +349 -0
  65. minervachem-0.0.1a2/minervachem/scoring.py +30 -0
  66. minervachem-0.0.1a2/minervachem/sparse_eliminator.py +185 -0
  67. minervachem-0.0.1a2/minervachem/transformers.py +363 -0
  68. minervachem-0.0.1a2/minervachem/utils/__init__.py +0 -0
  69. minervachem-0.0.1a2/minervachem/utils/chemistry.py +98 -0
  70. minervachem-0.0.1a2/minervachem/utils/misc.py +118 -0
  71. minervachem-0.0.1a2/minervachem/utils/sparse.py +104 -0
  72. minervachem-0.0.1a2/minervachem.egg-info/PKG-INFO +243 -0
  73. minervachem-0.0.1a2/minervachem.egg-info/SOURCES.txt +86 -0
  74. minervachem-0.0.1a2/minervachem.egg-info/dependency_links.txt +1 -0
  75. minervachem-0.0.1a2/minervachem.egg-info/requires.txt +35 -0
  76. minervachem-0.0.1a2/minervachem.egg-info/scm_file_list.json +83 -0
  77. minervachem-0.0.1a2/minervachem.egg-info/scm_version.json +8 -0
  78. minervachem-0.0.1a2/minervachem.egg-info/top_level.txt +1 -0
  79. minervachem-0.0.1a2/package_versions_manuscript.txt +27 -0
  80. minervachem-0.0.1a2/pyproject.toml +92 -0
  81. minervachem-0.0.1a2/scripts/run_demo_notebook.sh +121 -0
  82. minervachem-0.0.1a2/scripts/run_demo_notebooks.sh +210 -0
  83. minervachem-0.0.1a2/setup.cfg +4 -0
  84. minervachem-0.0.1a2/test/test_fingerprinters.py +30 -0
  85. minervachem-0.0.1a2/test/test_hierarchical_regression.py +81 -0
  86. minervachem-0.0.1a2/test/test_padre.py +125 -0
  87. minervachem-0.0.1a2/test/test_transformer_internals.py +121 -0
  88. minervachem-0.0.1a2/uv.lock +2465 -0
File without changes
@@ -0,0 +1,60 @@
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
@@ -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,12 @@
1
+ **/__pycache__/*
2
+ build/*
3
+ **/data/*
4
+ **/.DS_Store
5
+ **/.hypothesis/*
6
+ **/*.egg-info
7
+ **/*.idea/*
8
+ **/.ipynb_checkpoints/*
9
+ **/*.pkl
10
+ .gitattributes
11
+ .env
12
+ logs
@@ -0,0 +1,8 @@
1
+
2
+ Michael Tynes (U. Chicago, LANL, ANL)
3
+ Nicholas Lubbers (LANL)
4
+ Michael Taylor (LANL)
5
+
6
+
7
+
8
+
@@ -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,243 @@
1
+ Metadata-Version: 2.4
2
+ Name: minervachem
3
+ Version: 0.0.1a2
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
+
70
+ ## Optional Add-ons
71
+ * [LAMEL](https://github.com/random-logic/minervachem/tree/main/lamel#readme)
72
+
73
+ # Getting started with `minervachem`
74
+
75
+ We recommend looking through and running the notebooks in the `demos/` directory for a detailed introduction to `minervachem`'s funcitonality.
76
+
77
+ ## Running Reddit Demo
78
+
79
+ ### Graphlets
80
+ ```sh
81
+ uv run python demos/reddit_example/reddit_graphlets_example.py
82
+ ```
83
+
84
+ ### Benchmark
85
+ ```sh
86
+ uv run python demos/reddit_example/reddit_individual_graphs_benchmark.py demos/reddit_example/reddit_graphs_benchmarks
87
+ ```
88
+
89
+ ## Highlights
90
+
91
+ ### Constructing graphlet fingerprints
92
+
93
+ `Fingerprinter` classes provide reusable objects for generating molecular fingerprints, including the graphlet fingerprints described in our manuscript.
94
+
95
+ ```python
96
+ from rdkit.Chem import MolFromSmiles, AddHs
97
+ from minervachem.fingerprinters import GraphletFingerprinter
98
+
99
+ # Benzene
100
+ mol = AddHs(MolFromSmiles('c1ccccc1'))
101
+
102
+ # Reusable Fingerprinter object
103
+ fingerprinter = GraphletFingerprinter(max_len=3)
104
+
105
+ # Fingerprints are a map from fragment IDs to fragment counts.
106
+ # The fragments are identified by their number of atoms and a hash.
107
+ fp, bi = fingerprinter(mol)
108
+ print(fp)
109
+ >>> {(3, 10387847931347882557): 6,
110
+ >>> (2, 10630435057451682469): 6,
111
+ >>> (2, 11665740151475091393): 6,
112
+ >>> (3, 14577436124092730684): 12,
113
+ >>> (1, 20784809936286627226): 6,
114
+ >>> (1, 12794648790135253294): 6}
115
+
116
+ # We can visualize the above dictiory with a plotting method
117
+ from minervachem.plotting import plot_fingerprint
118
+ plot_fingerprint(mol, fingerprinter)
119
+ ```
120
+ ![A plot of the molecular graphlets of benzene up to size 3 atoms, their counts, and their identifiers](https://raw.githubusercontent.com/lanl/minervachem/main/demos/benzene_bits.png)
121
+
122
+ ### scikit-learn transformers
123
+
124
+ We can quickly construct feature matrices for machine learning from a set of molecules using `minervachem`'s provided `sklearn`-style transformers:
125
+
126
+ ```python
127
+ from minervachem.transformers import FingerprintFeaturizer
128
+
129
+ mols = [MolFromSmiles(s) for s in [
130
+ 'c1ccccc1',
131
+ 'NCNOCOC',
132
+ 'CN1C=NC2=C1C(=O)N(C(=O)N2C)C',
133
+ 'CNO',
134
+ ]]
135
+
136
+ featurizer = FingerprintFeaturizer(
137
+ fingerprinter,
138
+ n_jobs=2 # parallelism for large datasets
139
+ )
140
+
141
+ # FingerprintFeaturizer implements the sklearn transformer API
142
+ feature_matrix = featurizer.fit_transform(mols)
143
+ # which generates sparse integer matrices by default
144
+ feature_matrix
145
+ ```
146
+ ```
147
+ >>> <4x39 sparse matrix of type '<class 'numpy.int64'>'
148
+ with 44 stored elements in Compressed Sparse Row format>
149
+ ```
150
+
151
+ ### Building Interpretable Machine Learning Models
152
+ #### Model fitting
153
+
154
+ After constructing a dataset through the methods above, we can use `minervachem` to fit an interpretable ML model.
155
+
156
+ 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.
157
+
158
+ ```python
159
+ import minervachem
160
+ from sklearn.linear_model import Ridge
161
+ from minervachem.regressors import HierarchicalResidualModel
162
+ from minervachem.plotting import parity_plot_train_test
163
+
164
+
165
+ # build a higherarchical residual model
166
+ # using a ridge regressor base model
167
+ base_model = Ridge(fit_intercept=False,
168
+ alpha=1e-5,
169
+ solver='sparse_cg')
170
+ hmodel = HierarchicalResidualModel(regressor=base_model,verbose=1)
171
+ hmodel.fit(X_train,y_train,levels=featurizer.bit_sizes_)
172
+
173
+ # visualize the train and test performance with
174
+ # minervachem's plotting methods
175
+ parity_plot_train_test([X_train, X_test],
176
+ [y_train, y_test],
177
+ hmodel,
178
+ figsize=(12, 4),
179
+ xlab='DFT (kcal/mol)',
180
+ ylab='Linear Model (kcal/mol)',
181
+ title='Hierarchical Model Prediction');
182
+ ```
183
+ ![Hierarchical model performance](https://raw.githubusercontent.com/lanl/minervachem/main/demos/hmodel_perf.png)
184
+
185
+
186
+ #### Model interpretations
187
+ 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.
188
+
189
+ First we construct the Directed-Acyclic-Graph (DAG) between molecular graphlets that defines our projection operation:
190
+
191
+ ```python
192
+ from minervachem.graphlet_dags import GraphletDAG, draw_projected_coefs
193
+
194
+ # Construct the DAG relating larger graphlets to smaller ones
195
+ # for each molecule
196
+ dags = []
197
+ for mol in mols:
198
+ dag = GraphletDAG(mol,
199
+ fingerprinter=featurizer.fingerprinter, # the fingerprinter that creates the graphlets
200
+ bit_ids=featurizer.bit_ids_, # The bit ids for the features used in the model training
201
+ coef=hmodel.coef_ # The model coefficients as an array.
202
+ )
203
+ dags.append(dag)
204
+
205
+ draw_projected_coefs(dags,
206
+ level=2, # bond-level interpretations (atom-level is 1)
207
+ )
208
+ ```
209
+ ![Hierarhcical model interpretation](https://raw.githubusercontent.com/lanl/minervachem/main/demos/hmodel_interp.png)
210
+
211
+
212
+ ## Citation
213
+ If you use minervachem in your work, please cite [our paper](https://doi.org/10.26434/chemrxiv-2024-r81c8)
214
+
215
+ ```latex
216
+ @article{tynes2024linear,
217
+ title={Linear Graphlet Models for Accurate and Interpretable Cheminformatics},
218
+ author={Tynes, Michael and Taylor, Michael G and Janssen, Jan and Burrill, Daniel J and Perez, Danny and Yang, Ping and Lubbers, Nicholas},
219
+ journal={ChemRxiv preprint},
220
+ doi={10.26434/chemrxiv-2024-r81c8},
221
+ url={dx.doi.org/10.26434/chemrxiv-2024-r81c8},
222
+ year={2024}
223
+ }
224
+ ```
225
+
226
+ ## Copyright and licensing
227
+
228
+ `minervachem` is released under the BSD-3 License. See LICENSE.txt for the full license.
229
+
230
+
231
+ The copyright to `minervachem` is owned by Triad National Security, LLC
232
+ and is released for open source use as project number O04631.
233
+
234
+
235
+ © 2023. Triad National Security, LLC. All rights reserved.
236
+ This program was produced under U.S. Government contract 89233218CNA000001 for Los Alamos
237
+ National Laboratory (LANL), which is operated by Triad National Security, LLC for the U.S.
238
+ Department of Energy/National Nuclear Security Administration. All rights in the program are.
239
+ reserved by Triad National Security, LLC, and the U.S. Department of Energy/National Nuclear
240
+ Security Administration. The Government is granted for itself and others acting on its behalf a
241
+ nonexclusive, paid-up, irrevocable worldwide license in this material to reproduce, prepare.
242
+ derivative works, distribute copies to the public, perform publicly and display publicly, and to permit.
243
+ others to do so.
@@ -0,0 +1,186 @@
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
+
13
+ ## Optional Add-ons
14
+ * [LAMEL](https://github.com/random-logic/minervachem/tree/main/lamel#readme)
15
+
16
+ # Getting started with `minervachem`
17
+
18
+ We recommend looking through and running the notebooks in the `demos/` directory for a detailed introduction to `minervachem`'s funcitonality.
19
+
20
+ ## Running Reddit Demo
21
+
22
+ ### Graphlets
23
+ ```sh
24
+ uv run python demos/reddit_example/reddit_graphlets_example.py
25
+ ```
26
+
27
+ ### Benchmark
28
+ ```sh
29
+ uv run python demos/reddit_example/reddit_individual_graphs_benchmark.py demos/reddit_example/reddit_graphs_benchmarks
30
+ ```
31
+
32
+ ## Highlights
33
+
34
+ ### Constructing graphlet fingerprints
35
+
36
+ `Fingerprinter` classes provide reusable objects for generating molecular fingerprints, including the graphlet fingerprints described in our manuscript.
37
+
38
+ ```python
39
+ from rdkit.Chem import MolFromSmiles, AddHs
40
+ from minervachem.fingerprinters import GraphletFingerprinter
41
+
42
+ # Benzene
43
+ mol = AddHs(MolFromSmiles('c1ccccc1'))
44
+
45
+ # Reusable Fingerprinter object
46
+ fingerprinter = GraphletFingerprinter(max_len=3)
47
+
48
+ # Fingerprints are a map from fragment IDs to fragment counts.
49
+ # The fragments are identified by their number of atoms and a hash.
50
+ fp, bi = fingerprinter(mol)
51
+ print(fp)
52
+ >>> {(3, 10387847931347882557): 6,
53
+ >>> (2, 10630435057451682469): 6,
54
+ >>> (2, 11665740151475091393): 6,
55
+ >>> (3, 14577436124092730684): 12,
56
+ >>> (1, 20784809936286627226): 6,
57
+ >>> (1, 12794648790135253294): 6}
58
+
59
+ # We can visualize the above dictiory with a plotting method
60
+ from minervachem.plotting import plot_fingerprint
61
+ plot_fingerprint(mol, fingerprinter)
62
+ ```
63
+ ![A plot of the molecular graphlets of benzene up to size 3 atoms, their counts, and their identifiers](https://raw.githubusercontent.com/lanl/minervachem/main/demos/benzene_bits.png)
64
+
65
+ ### scikit-learn transformers
66
+
67
+ We can quickly construct feature matrices for machine learning from a set of molecules using `minervachem`'s provided `sklearn`-style transformers:
68
+
69
+ ```python
70
+ from minervachem.transformers import FingerprintFeaturizer
71
+
72
+ mols = [MolFromSmiles(s) for s in [
73
+ 'c1ccccc1',
74
+ 'NCNOCOC',
75
+ 'CN1C=NC2=C1C(=O)N(C(=O)N2C)C',
76
+ 'CNO',
77
+ ]]
78
+
79
+ featurizer = FingerprintFeaturizer(
80
+ fingerprinter,
81
+ n_jobs=2 # parallelism for large datasets
82
+ )
83
+
84
+ # FingerprintFeaturizer implements the sklearn transformer API
85
+ feature_matrix = featurizer.fit_transform(mols)
86
+ # which generates sparse integer matrices by default
87
+ feature_matrix
88
+ ```
89
+ ```
90
+ >>> <4x39 sparse matrix of type '<class 'numpy.int64'>'
91
+ with 44 stored elements in Compressed Sparse Row format>
92
+ ```
93
+
94
+ ### Building Interpretable Machine Learning Models
95
+ #### Model fitting
96
+
97
+ After constructing a dataset through the methods above, we can use `minervachem` to fit an interpretable ML model.
98
+
99
+ 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.
100
+
101
+ ```python
102
+ import minervachem
103
+ from sklearn.linear_model import Ridge
104
+ from minervachem.regressors import HierarchicalResidualModel
105
+ from minervachem.plotting import parity_plot_train_test
106
+
107
+
108
+ # build a higherarchical residual model
109
+ # using a ridge regressor base model
110
+ base_model = Ridge(fit_intercept=False,
111
+ alpha=1e-5,
112
+ solver='sparse_cg')
113
+ hmodel = HierarchicalResidualModel(regressor=base_model,verbose=1)
114
+ hmodel.fit(X_train,y_train,levels=featurizer.bit_sizes_)
115
+
116
+ # visualize the train and test performance with
117
+ # minervachem's plotting methods
118
+ parity_plot_train_test([X_train, X_test],
119
+ [y_train, y_test],
120
+ hmodel,
121
+ figsize=(12, 4),
122
+ xlab='DFT (kcal/mol)',
123
+ ylab='Linear Model (kcal/mol)',
124
+ title='Hierarchical Model Prediction');
125
+ ```
126
+ ![Hierarchical model performance](https://raw.githubusercontent.com/lanl/minervachem/main/demos/hmodel_perf.png)
127
+
128
+
129
+ #### Model interpretations
130
+ 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.
131
+
132
+ First we construct the Directed-Acyclic-Graph (DAG) between molecular graphlets that defines our projection operation:
133
+
134
+ ```python
135
+ from minervachem.graphlet_dags import GraphletDAG, draw_projected_coefs
136
+
137
+ # Construct the DAG relating larger graphlets to smaller ones
138
+ # for each molecule
139
+ dags = []
140
+ for mol in mols:
141
+ dag = GraphletDAG(mol,
142
+ fingerprinter=featurizer.fingerprinter, # the fingerprinter that creates the graphlets
143
+ bit_ids=featurizer.bit_ids_, # The bit ids for the features used in the model training
144
+ coef=hmodel.coef_ # The model coefficients as an array.
145
+ )
146
+ dags.append(dag)
147
+
148
+ draw_projected_coefs(dags,
149
+ level=2, # bond-level interpretations (atom-level is 1)
150
+ )
151
+ ```
152
+ ![Hierarhcical model interpretation](https://raw.githubusercontent.com/lanl/minervachem/main/demos/hmodel_interp.png)
153
+
154
+
155
+ ## Citation
156
+ If you use minervachem in your work, please cite [our paper](https://doi.org/10.26434/chemrxiv-2024-r81c8)
157
+
158
+ ```latex
159
+ @article{tynes2024linear,
160
+ title={Linear Graphlet Models for Accurate and Interpretable Cheminformatics},
161
+ author={Tynes, Michael and Taylor, Michael G and Janssen, Jan and Burrill, Daniel J and Perez, Danny and Yang, Ping and Lubbers, Nicholas},
162
+ journal={ChemRxiv preprint},
163
+ doi={10.26434/chemrxiv-2024-r81c8},
164
+ url={dx.doi.org/10.26434/chemrxiv-2024-r81c8},
165
+ year={2024}
166
+ }
167
+ ```
168
+
169
+ ## Copyright and licensing
170
+
171
+ `minervachem` is released under the BSD-3 License. See LICENSE.txt for the full license.
172
+
173
+
174
+ The copyright to `minervachem` is owned by Triad National Security, LLC
175
+ and is released for open source use as project number O04631.
176
+
177
+
178
+ © 2023. Triad National Security, LLC. All rights reserved.
179
+ This program was produced under U.S. Government contract 89233218CNA000001 for Los Alamos
180
+ National Laboratory (LANL), which is operated by Triad National Security, LLC for the U.S.
181
+ Department of Energy/National Nuclear Security Administration. All rights in the program are.
182
+ reserved by Triad National Security, LLC, and the U.S. Department of Energy/National Nuclear
183
+ Security Administration. The Government is granted for itself and others acting on its behalf a
184
+ nonexclusive, paid-up, irrevocable worldwide license in this material to reproduce, prepare.
185
+ derivative works, distribute copies to the public, perform publicly and display publicly, and to permit.
186
+ others to do so.
@@ -0,0 +1,5 @@
1
+ /qm9_processed.csv
2
+ /qm9_data_files/
3
+ /data/
4
+ *.log
5
+