aamutils 0.0.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.
- aamutils-0.0.1/.github/workflows/publish-package.yml +49 -0
- aamutils-0.0.1/.github/workflows/test-and-lint.yml +40 -0
- aamutils-0.0.1/.gitignore +162 -0
- aamutils-0.0.1/LICENSE +9 -0
- aamutils-0.0.1/Makefile +20 -0
- aamutils-0.0.1/PKG-INFO +86 -0
- aamutils-0.0.1/README.md +64 -0
- aamutils-0.0.1/aamutils/__init__.py +0 -0
- aamutils-0.0.1/aamutils/__main__.py +18 -0
- aamutils-0.0.1/aamutils/algorithm/__init__.py +0 -0
- aamutils-0.0.1/aamutils/algorithm/aaming.py +124 -0
- aamutils-0.0.1/aamutils/algorithm/ilp.py +150 -0
- aamutils-0.0.1/aamutils/cmd/__init__.py +15 -0
- aamutils-0.0.1/aamutils/cmd/expanding.py +84 -0
- aamutils-0.0.1/aamutils/utils.py +125 -0
- aamutils-0.0.1/benchmarking.py +176 -0
- aamutils-0.0.1/conf.py +31 -0
- aamutils-0.0.1/data/test_dataset.json +1 -0
- aamutils-0.0.1/doc/getting_started.rst +5 -0
- aamutils-0.0.1/doc/reference.rst +12 -0
- aamutils-0.0.1/index.rst +13 -0
- aamutils-0.0.1/lint.sh +6 -0
- aamutils-0.0.1/make.bat +35 -0
- aamutils-0.0.1/pyproject.toml +32 -0
- aamutils-0.0.1/requirements.txt +7 -0
- aamutils-0.0.1/test/__init__.py +0 -0
- aamutils-0.0.1/test/algorithm/__init__.py +0 -0
- aamutils-0.0.1/test/algorithm/test_aaming.py +35 -0
- aamutils-0.0.1/test/algorithm/test_ilp.py +98 -0
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
name: PyPI publish
|
|
2
|
+
|
|
3
|
+
on:
|
|
4
|
+
release:
|
|
5
|
+
types: [published]
|
|
6
|
+
|
|
7
|
+
permissions:
|
|
8
|
+
contents: read
|
|
9
|
+
|
|
10
|
+
jobs:
|
|
11
|
+
build:
|
|
12
|
+
name: Build package
|
|
13
|
+
runs-on: ubuntu-latest
|
|
14
|
+
steps:
|
|
15
|
+
- name: Checkout
|
|
16
|
+
uses: actions/checkout@v3
|
|
17
|
+
- name: Set up Python
|
|
18
|
+
uses: actions/setup-python@v3
|
|
19
|
+
with:
|
|
20
|
+
python-version: '3.x'
|
|
21
|
+
- name: Install dependencies
|
|
22
|
+
run: |
|
|
23
|
+
python -m pip install --upgrade pip
|
|
24
|
+
pip install build
|
|
25
|
+
- name: Build package
|
|
26
|
+
run: python -m build
|
|
27
|
+
- name: Upload artifact
|
|
28
|
+
uses: actions/upload-artifact@v4
|
|
29
|
+
with:
|
|
30
|
+
name: package
|
|
31
|
+
path: dist/
|
|
32
|
+
|
|
33
|
+
publish:
|
|
34
|
+
name: Upload release to PyPI
|
|
35
|
+
needs: build
|
|
36
|
+
runs-on: ubuntu-latest
|
|
37
|
+
environment:
|
|
38
|
+
name: pypi
|
|
39
|
+
url: https://pypi.org/p/aamutils
|
|
40
|
+
permissions:
|
|
41
|
+
id-token: write # IMPORTANT: this permission is mandatory for trusted publishing
|
|
42
|
+
steps:
|
|
43
|
+
- name: Download artifact
|
|
44
|
+
uses: actions/download-artifact@v4
|
|
45
|
+
with:
|
|
46
|
+
name: package
|
|
47
|
+
path: dist/
|
|
48
|
+
- name: Publish package to PyPI
|
|
49
|
+
uses: pypa/gh-action-pypi-publish@release/v1
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
# This workflow will install Python dependencies, run tests and lint with a
|
|
2
|
+
# single version of Python
|
|
3
|
+
# For more information see:
|
|
4
|
+
# https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-python
|
|
5
|
+
|
|
6
|
+
name: Test & Lint
|
|
7
|
+
|
|
8
|
+
on:
|
|
9
|
+
push:
|
|
10
|
+
branches: [ "main", "dev" ]
|
|
11
|
+
pull_request:
|
|
12
|
+
branches: [ "main" ]
|
|
13
|
+
|
|
14
|
+
permissions:
|
|
15
|
+
contents: read
|
|
16
|
+
|
|
17
|
+
jobs:
|
|
18
|
+
build:
|
|
19
|
+
|
|
20
|
+
runs-on: ubuntu-latest
|
|
21
|
+
|
|
22
|
+
steps:
|
|
23
|
+
- uses: actions/checkout@v3
|
|
24
|
+
- name: Set up Python 3.11
|
|
25
|
+
uses: actions/setup-python@v3
|
|
26
|
+
with:
|
|
27
|
+
python-version: "3.11"
|
|
28
|
+
- name: Install dependencies
|
|
29
|
+
run: |
|
|
30
|
+
python -m pip install --upgrade pip
|
|
31
|
+
pip install flake8 pytest
|
|
32
|
+
if [ -f requirements.txt ]; then pip install -r requirements.txt; fi
|
|
33
|
+
- name: Lint with flake8
|
|
34
|
+
run: |
|
|
35
|
+
# stop the build if there are Python syntax errors or undefined names
|
|
36
|
+
flake8 . --count --select=E9,F63,F7,F82 --show-source --statistics
|
|
37
|
+
./lint.sh
|
|
38
|
+
- name: Test with pytest
|
|
39
|
+
run: |
|
|
40
|
+
pytest
|
|
@@ -0,0 +1,162 @@
|
|
|
1
|
+
# ---> Python
|
|
2
|
+
# Byte-compiled / optimized / DLL files
|
|
3
|
+
__pycache__/
|
|
4
|
+
*.py[cod]
|
|
5
|
+
*$py.class
|
|
6
|
+
|
|
7
|
+
# C extensions
|
|
8
|
+
*.so
|
|
9
|
+
|
|
10
|
+
# Distribution / packaging
|
|
11
|
+
.Python
|
|
12
|
+
build/
|
|
13
|
+
develop-eggs/
|
|
14
|
+
dist/
|
|
15
|
+
downloads/
|
|
16
|
+
eggs/
|
|
17
|
+
.eggs/
|
|
18
|
+
lib/
|
|
19
|
+
lib64/
|
|
20
|
+
parts/
|
|
21
|
+
sdist/
|
|
22
|
+
var/
|
|
23
|
+
wheels/
|
|
24
|
+
share/python-wheels/
|
|
25
|
+
*.egg-info/
|
|
26
|
+
.installed.cfg
|
|
27
|
+
*.egg
|
|
28
|
+
MANIFEST
|
|
29
|
+
|
|
30
|
+
# PyInstaller
|
|
31
|
+
# Usually these files are written by a python script from a template
|
|
32
|
+
# before PyInstaller builds the exe, so as to inject date/other infos into it.
|
|
33
|
+
*.manifest
|
|
34
|
+
*.spec
|
|
35
|
+
|
|
36
|
+
# Installer logs
|
|
37
|
+
pip-log.txt
|
|
38
|
+
pip-delete-this-directory.txt
|
|
39
|
+
|
|
40
|
+
# Unit test / coverage reports
|
|
41
|
+
htmlcov/
|
|
42
|
+
.tox/
|
|
43
|
+
.nox/
|
|
44
|
+
.coverage
|
|
45
|
+
.coverage.*
|
|
46
|
+
.cache
|
|
47
|
+
nosetests.xml
|
|
48
|
+
coverage.xml
|
|
49
|
+
*.cover
|
|
50
|
+
*.py,cover
|
|
51
|
+
.hypothesis/
|
|
52
|
+
.pytest_cache/
|
|
53
|
+
cover/
|
|
54
|
+
|
|
55
|
+
# Translations
|
|
56
|
+
*.mo
|
|
57
|
+
*.pot
|
|
58
|
+
|
|
59
|
+
# Django stuff:
|
|
60
|
+
*.log
|
|
61
|
+
local_settings.py
|
|
62
|
+
db.sqlite3
|
|
63
|
+
db.sqlite3-journal
|
|
64
|
+
|
|
65
|
+
# Flask stuff:
|
|
66
|
+
instance/
|
|
67
|
+
.webassets-cache
|
|
68
|
+
|
|
69
|
+
# Scrapy stuff:
|
|
70
|
+
.scrapy
|
|
71
|
+
|
|
72
|
+
# Sphinx documentation
|
|
73
|
+
docs/_build/
|
|
74
|
+
|
|
75
|
+
# PyBuilder
|
|
76
|
+
.pybuilder/
|
|
77
|
+
target/
|
|
78
|
+
|
|
79
|
+
# Jupyter Notebook
|
|
80
|
+
.ipynb_checkpoints
|
|
81
|
+
|
|
82
|
+
# IPython
|
|
83
|
+
profile_default/
|
|
84
|
+
ipython_config.py
|
|
85
|
+
|
|
86
|
+
# pyenv
|
|
87
|
+
# For a library or package, you might want to ignore these files since the code is
|
|
88
|
+
# intended to run in multiple environments; otherwise, check them in:
|
|
89
|
+
# .python-version
|
|
90
|
+
|
|
91
|
+
# pipenv
|
|
92
|
+
# According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control.
|
|
93
|
+
# However, in case of collaboration, if having platform-specific dependencies or dependencies
|
|
94
|
+
# having no cross-platform support, pipenv may install dependencies that don't work, or not
|
|
95
|
+
# install all needed dependencies.
|
|
96
|
+
#Pipfile.lock
|
|
97
|
+
|
|
98
|
+
# poetry
|
|
99
|
+
# Similar to Pipfile.lock, it is generally recommended to include poetry.lock in version control.
|
|
100
|
+
# This is especially recommended for binary packages to ensure reproducibility, and is more
|
|
101
|
+
# commonly ignored for libraries.
|
|
102
|
+
# https://python-poetry.org/docs/basic-usage/#commit-your-poetrylock-file-to-version-control
|
|
103
|
+
#poetry.lock
|
|
104
|
+
|
|
105
|
+
# pdm
|
|
106
|
+
# Similar to Pipfile.lock, it is generally recommended to include pdm.lock in version control.
|
|
107
|
+
#pdm.lock
|
|
108
|
+
# pdm stores project-wide configurations in .pdm.toml, but it is recommended to not include it
|
|
109
|
+
# in version control.
|
|
110
|
+
# https://pdm.fming.dev/#use-with-ide
|
|
111
|
+
.pdm.toml
|
|
112
|
+
|
|
113
|
+
# PEP 582; used by e.g. github.com/David-OConnor/pyflow and github.com/pdm-project/pdm
|
|
114
|
+
__pypackages__/
|
|
115
|
+
|
|
116
|
+
# Celery stuff
|
|
117
|
+
celerybeat-schedule
|
|
118
|
+
celerybeat.pid
|
|
119
|
+
|
|
120
|
+
# SageMath parsed files
|
|
121
|
+
*.sage.py
|
|
122
|
+
|
|
123
|
+
# Environments
|
|
124
|
+
.env
|
|
125
|
+
.venv
|
|
126
|
+
env/
|
|
127
|
+
venv/
|
|
128
|
+
ENV/
|
|
129
|
+
env.bak/
|
|
130
|
+
venv.bak/
|
|
131
|
+
|
|
132
|
+
# Spyder project settings
|
|
133
|
+
.spyderproject
|
|
134
|
+
.spyproject
|
|
135
|
+
|
|
136
|
+
# Rope project settings
|
|
137
|
+
.ropeproject
|
|
138
|
+
|
|
139
|
+
# mkdocs documentation
|
|
140
|
+
/site
|
|
141
|
+
|
|
142
|
+
# mypy
|
|
143
|
+
.mypy_cache/
|
|
144
|
+
.dmypy.json
|
|
145
|
+
dmypy.json
|
|
146
|
+
|
|
147
|
+
# Pyre type checker
|
|
148
|
+
.pyre/
|
|
149
|
+
|
|
150
|
+
# pytype static type analyzer
|
|
151
|
+
.pytype/
|
|
152
|
+
|
|
153
|
+
# Cython debug symbols
|
|
154
|
+
cython_debug/
|
|
155
|
+
|
|
156
|
+
# PyCharm
|
|
157
|
+
# JetBrains specific template is maintained in a separate JetBrains.gitignore that can
|
|
158
|
+
# be found at https://github.com/github/gitignore/blob/main/Global/JetBrains.gitignore
|
|
159
|
+
# and can be added to the global gitignore or merged into this file. For a more nuclear
|
|
160
|
+
# option (not recommended) you can uncomment the following to ignore the entire idea folder.
|
|
161
|
+
#.idea/
|
|
162
|
+
|
aamutils-0.0.1/LICENSE
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2024 Klaus
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
|
6
|
+
|
|
7
|
+
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
|
8
|
+
|
|
9
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
aamutils-0.0.1/Makefile
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
# Minimal makefile for Sphinx documentation
|
|
2
|
+
#
|
|
3
|
+
|
|
4
|
+
# You can set these variables from the command line, and also
|
|
5
|
+
# from the environment for the first two.
|
|
6
|
+
SPHINXOPTS ?=
|
|
7
|
+
SPHINXBUILD ?= sphinx-build
|
|
8
|
+
SOURCEDIR = .
|
|
9
|
+
BUILDDIR = build
|
|
10
|
+
|
|
11
|
+
# Put it first so that "make" without argument is like "make help".
|
|
12
|
+
help:
|
|
13
|
+
@$(SPHINXBUILD) -M help "$(SOURCEDIR)" "$(BUILDDIR)" $(SPHINXOPTS) $(O)
|
|
14
|
+
|
|
15
|
+
.PHONY: help Makefile
|
|
16
|
+
|
|
17
|
+
# Catch-all target: route all unknown targets to Sphinx using the new
|
|
18
|
+
# "make mode" option. $(O) is meant as a shortcut for $(SPHINXOPTS).
|
|
19
|
+
%: Makefile
|
|
20
|
+
@$(SPHINXBUILD) -M $@ "$(SOURCEDIR)" "$(BUILDDIR)" $(SPHINXOPTS) $(O)
|
aamutils-0.0.1/PKG-INFO
ADDED
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
Metadata-Version: 2.3
|
|
2
|
+
Name: aamutils
|
|
3
|
+
Version: 0.0.1
|
|
4
|
+
Summary: Collection of atom-atom-mapping utility functions.
|
|
5
|
+
Project-URL: homepage, https://github.com/klausweinbauer/AAMUtils
|
|
6
|
+
Project-URL: source, https://github.com/klausweinbauer/AAMUtils
|
|
7
|
+
Project-URL: issues, https://github.com/klausweinbauer/AAMUtils/issues
|
|
8
|
+
Author-email: Klaus Weinbauer <klaus@bioinf.uni-leipzig.de>
|
|
9
|
+
License-File: LICENSE
|
|
10
|
+
Classifier: License :: OSI Approved :: MIT License
|
|
11
|
+
Classifier: Operating System :: OS Independent
|
|
12
|
+
Classifier: Programming Language :: Python :: 3
|
|
13
|
+
Requires-Python: >=3.11
|
|
14
|
+
Requires-Dist: fgutils<0.1.0,>=0.0.17
|
|
15
|
+
Requires-Dist: networkx==3.3
|
|
16
|
+
Requires-Dist: numpy<2.0.0,>=1.26.0
|
|
17
|
+
Requires-Dist: pillow==10.3.0
|
|
18
|
+
Requires-Dist: pulp==2.8.0
|
|
19
|
+
Requires-Dist: rdkit==2024.3.1
|
|
20
|
+
Requires-Dist: scipy==1.14.0
|
|
21
|
+
Description-Content-Type: text/markdown
|
|
22
|
+
|
|
23
|
+
# Atom-atom-mapping Utils
|
|
24
|
+
|
|
25
|
+
A collection of atom-atom-mapping utility functions.
|
|
26
|
+
|
|
27
|
+
## Installation
|
|
28
|
+
|
|
29
|
+
TODO
|
|
30
|
+
|
|
31
|
+
## Usage
|
|
32
|
+
|
|
33
|
+
The input is a list of partial atom-atom-maps (AAMs). Data is read line-by-line
|
|
34
|
+
from a text file. Each line should contain one reaction SMILES.
|
|
35
|
+
|
|
36
|
+
Here is a simple example extending the partial AAM to a complete AAM. First
|
|
37
|
+
generate the input data:
|
|
38
|
+
|
|
39
|
+
```bash
|
|
40
|
+
echo "CCC[Cl:1].[N:2]>>CCC[N:2].[Cl:1]" > testinput.txt
|
|
41
|
+
```
|
|
42
|
+
|
|
43
|
+
Next, run AAMUtils to expand the partial AAM.
|
|
44
|
+
|
|
45
|
+
```bash
|
|
46
|
+
python3 ./aamutils/__main__.py expand testinput.txt
|
|
47
|
+
```
|
|
48
|
+
|
|
49
|
+
The output is written to 'testinput_extended.json'.
|
|
50
|
+
|
|
51
|
+
```bash
|
|
52
|
+
cat testinput_extended.json
|
|
53
|
+
```
|
|
54
|
+
|
|
55
|
+
```json
|
|
56
|
+
[
|
|
57
|
+
{
|
|
58
|
+
"input": "CCC[Cl:1].[N:2]>>CCC[N:2].[Cl:1]",
|
|
59
|
+
"expanded_aam": "[Cl:1][CH2:5][CH2:4][CH3:3].[NH3:2]>>[ClH:1].[NH2:2][CH2:5][CH2:4][CH3:3]",
|
|
60
|
+
"ilp_status": "Optimal",
|
|
61
|
+
"optimization_result": 2.0,
|
|
62
|
+
"invalid_reaction_center": false,
|
|
63
|
+
"reaction_edges": 3
|
|
64
|
+
}
|
|
65
|
+
]
|
|
66
|
+
```
|
|
67
|
+
|
|
68
|
+
## Functionality
|
|
69
|
+
Here is an overview of implemented functionallity:
|
|
70
|
+
|
|
71
|
+
- SMILES to graph and graph to SMILES parsing
|
|
72
|
+
- Reaction center validity checks
|
|
73
|
+
- ITS graph generation
|
|
74
|
+
- Expand partial AAM to complete AAM on balanced reactions
|
|
75
|
+
- AAMing based on minimal chemical distance (MCD) for balanced reactions
|
|
76
|
+
|
|
77
|
+
## License
|
|
78
|
+
|
|
79
|
+
This project is licensed under MIT License - see the [License](LICENSE) file
|
|
80
|
+
for details.
|
|
81
|
+
|
|
82
|
+
## Acknowledgments
|
|
83
|
+
|
|
84
|
+
This project has received funding from the European Unions Horizon Europe
|
|
85
|
+
Doctoral Network programme under the Marie-Skłodowska-Curie grant agreement No
|
|
86
|
+
101072930 (TACsy -- Training Alliance for Computational)
|
aamutils-0.0.1/README.md
ADDED
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
# Atom-atom-mapping Utils
|
|
2
|
+
|
|
3
|
+
A collection of atom-atom-mapping utility functions.
|
|
4
|
+
|
|
5
|
+
## Installation
|
|
6
|
+
|
|
7
|
+
TODO
|
|
8
|
+
|
|
9
|
+
## Usage
|
|
10
|
+
|
|
11
|
+
The input is a list of partial atom-atom-maps (AAMs). Data is read line-by-line
|
|
12
|
+
from a text file. Each line should contain one reaction SMILES.
|
|
13
|
+
|
|
14
|
+
Here is a simple example extending the partial AAM to a complete AAM. First
|
|
15
|
+
generate the input data:
|
|
16
|
+
|
|
17
|
+
```bash
|
|
18
|
+
echo "CCC[Cl:1].[N:2]>>CCC[N:2].[Cl:1]" > testinput.txt
|
|
19
|
+
```
|
|
20
|
+
|
|
21
|
+
Next, run AAMUtils to expand the partial AAM.
|
|
22
|
+
|
|
23
|
+
```bash
|
|
24
|
+
python3 ./aamutils/__main__.py expand testinput.txt
|
|
25
|
+
```
|
|
26
|
+
|
|
27
|
+
The output is written to 'testinput_extended.json'.
|
|
28
|
+
|
|
29
|
+
```bash
|
|
30
|
+
cat testinput_extended.json
|
|
31
|
+
```
|
|
32
|
+
|
|
33
|
+
```json
|
|
34
|
+
[
|
|
35
|
+
{
|
|
36
|
+
"input": "CCC[Cl:1].[N:2]>>CCC[N:2].[Cl:1]",
|
|
37
|
+
"expanded_aam": "[Cl:1][CH2:5][CH2:4][CH3:3].[NH3:2]>>[ClH:1].[NH2:2][CH2:5][CH2:4][CH3:3]",
|
|
38
|
+
"ilp_status": "Optimal",
|
|
39
|
+
"optimization_result": 2.0,
|
|
40
|
+
"invalid_reaction_center": false,
|
|
41
|
+
"reaction_edges": 3
|
|
42
|
+
}
|
|
43
|
+
]
|
|
44
|
+
```
|
|
45
|
+
|
|
46
|
+
## Functionality
|
|
47
|
+
Here is an overview of implemented functionallity:
|
|
48
|
+
|
|
49
|
+
- SMILES to graph and graph to SMILES parsing
|
|
50
|
+
- Reaction center validity checks
|
|
51
|
+
- ITS graph generation
|
|
52
|
+
- Expand partial AAM to complete AAM on balanced reactions
|
|
53
|
+
- AAMing based on minimal chemical distance (MCD) for balanced reactions
|
|
54
|
+
|
|
55
|
+
## License
|
|
56
|
+
|
|
57
|
+
This project is licensed under MIT License - see the [License](LICENSE) file
|
|
58
|
+
for details.
|
|
59
|
+
|
|
60
|
+
## Acknowledgments
|
|
61
|
+
|
|
62
|
+
This project has received funding from the European Unions Horizon Europe
|
|
63
|
+
Doctoral Network programme under the Marie-Skłodowska-Curie grant agreement No
|
|
64
|
+
101072930 (TACsy -- Training Alliance for Computational)
|
|
File without changes
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import logging
|
|
2
|
+
|
|
3
|
+
from aamutils.cmd import setup_argparser
|
|
4
|
+
|
|
5
|
+
if __name__ == "__main__":
|
|
6
|
+
logger = logging.getLogger("aamutils")
|
|
7
|
+
ch = logging.StreamHandler()
|
|
8
|
+
ch.setLevel(logging.INFO)
|
|
9
|
+
formatter = logging.Formatter(
|
|
10
|
+
"[%(asctime)s %(levelname)s] %(message)s", datefmt="%y-%m-%d %H:%M:%S"
|
|
11
|
+
)
|
|
12
|
+
ch.setFormatter(formatter)
|
|
13
|
+
logger.setLevel(logging.INFO)
|
|
14
|
+
logger.addHandler(ch)
|
|
15
|
+
|
|
16
|
+
parser = setup_argparser()
|
|
17
|
+
args = parser.parse_args()
|
|
18
|
+
args.func(args)
|
|
File without changes
|
|
@@ -0,0 +1,124 @@
|
|
|
1
|
+
import collections
|
|
2
|
+
import networkx as nx
|
|
3
|
+
|
|
4
|
+
|
|
5
|
+
def _add_its_nodes(ITS, G, H, eta, symbol_key):
|
|
6
|
+
eta_G, eta_G_inv, eta_H, eta_H_inv = eta[0], eta[1], eta[2], eta[3]
|
|
7
|
+
for n, d in G.nodes(data=True):
|
|
8
|
+
n_ITS = eta_G[n]
|
|
9
|
+
n_H = eta_H_inv[n_ITS]
|
|
10
|
+
if n_ITS is not None and n_H is not None:
|
|
11
|
+
ITS.add_node(n_ITS, symbol=d[symbol_key], idx_map=(n, n_H))
|
|
12
|
+
for n, d in H.nodes(data=True):
|
|
13
|
+
n_ITS = eta_H[n]
|
|
14
|
+
n_G = eta_G_inv[n_ITS]
|
|
15
|
+
if n_ITS is not None and n_G is not None and n_ITS not in ITS.nodes:
|
|
16
|
+
ITS.add_node(n_ITS, symbol=d[symbol_key], idx_map=(n_G, n))
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
def _add_its_edges(ITS, G, H, eta, bond_key):
|
|
20
|
+
eta_G, eta_G_inv, eta_H, eta_H_inv = eta[0], eta[1], eta[2], eta[3]
|
|
21
|
+
for n1, n2, d in G.edges(data=True):
|
|
22
|
+
if n1 > n2:
|
|
23
|
+
continue
|
|
24
|
+
e_G = d[bond_key]
|
|
25
|
+
n_ITS1 = eta_G[n1]
|
|
26
|
+
n_ITS2 = eta_G[n2]
|
|
27
|
+
n_H1 = eta_H_inv[n_ITS1]
|
|
28
|
+
n_H2 = eta_H_inv[n_ITS2]
|
|
29
|
+
e_H = None
|
|
30
|
+
if H.has_edge(n_H1, n_H2):
|
|
31
|
+
e_H = H[n_H1][n_H2][bond_key]
|
|
32
|
+
if not ITS.has_edge(n_ITS1, n_ITS2) and n_ITS1 > 0 and n_ITS2 > 0:
|
|
33
|
+
ITS.add_edge(n_ITS1, n_ITS2, bond=(e_G, e_H))
|
|
34
|
+
|
|
35
|
+
for n1, n2, d in H.edges(data=True):
|
|
36
|
+
if n1 > n2:
|
|
37
|
+
continue
|
|
38
|
+
e_H = d[bond_key]
|
|
39
|
+
n_ITS1 = eta_H[n1]
|
|
40
|
+
n_ITS2 = eta_H[n2]
|
|
41
|
+
n_G1 = eta_G_inv[n_ITS1]
|
|
42
|
+
n_G2 = eta_G_inv[n_ITS2]
|
|
43
|
+
if n_G1 is None or n_G2 is None:
|
|
44
|
+
continue
|
|
45
|
+
if not G.has_edge(n_G1, n_G2) and n_ITS1 > 0 and n_ITS2 > 0:
|
|
46
|
+
ITS.add_edge(n_ITS1, n_ITS2, bond=(None, e_H))
|
|
47
|
+
|
|
48
|
+
|
|
49
|
+
def get_its(
|
|
50
|
+
G: nx.Graph, H: nx.Graph, aam_key="aam", symbol_key="symbol", bond_key="bond"
|
|
51
|
+
) -> nx.Graph:
|
|
52
|
+
"""Get the ITS graph of reaction G \u2192 H.
|
|
53
|
+
|
|
54
|
+
:param G: Educt molecular graph.
|
|
55
|
+
:param H: Product molecular graph.
|
|
56
|
+
:param aam_key: (optional) The node label that encodes atom indices on the
|
|
57
|
+
molecular graph.
|
|
58
|
+
:param symbol_key: (optional) The node label that encodes atom symbols on
|
|
59
|
+
the molecular graph.
|
|
60
|
+
:param bond_key: (optional) The edge label that encodes bond order on the
|
|
61
|
+
molecular graph.
|
|
62
|
+
|
|
63
|
+
:returns: Returns the ITS graph.
|
|
64
|
+
"""
|
|
65
|
+
eta_G = collections.defaultdict(lambda: None)
|
|
66
|
+
eta_G_inv = collections.defaultdict(lambda: None)
|
|
67
|
+
eta_H = collections.defaultdict(lambda: None)
|
|
68
|
+
eta_H_inv = collections.defaultdict(lambda: None)
|
|
69
|
+
eta = (eta_G, eta_G_inv, eta_H, eta_H_inv)
|
|
70
|
+
|
|
71
|
+
for n, d in G.nodes(data=True):
|
|
72
|
+
if aam_key in d.keys() and d[aam_key] >= 0:
|
|
73
|
+
eta_G[n] = d[aam_key]
|
|
74
|
+
eta_G_inv[d[aam_key]] = n
|
|
75
|
+
for n, d in H.nodes(data=True):
|
|
76
|
+
if aam_key in d.keys() and d[aam_key] >= 0:
|
|
77
|
+
eta_H[n] = d[aam_key]
|
|
78
|
+
eta_H_inv[d[aam_key]] = n
|
|
79
|
+
|
|
80
|
+
ITS = nx.Graph()
|
|
81
|
+
_add_its_nodes(ITS, G, H, eta, symbol_key)
|
|
82
|
+
_add_its_edges(ITS, G, H, eta, bond_key)
|
|
83
|
+
|
|
84
|
+
return ITS
|
|
85
|
+
|
|
86
|
+
|
|
87
|
+
def get_rc(ITS: nx.Graph, symbol_key="symbol", bond_key="bond") -> nx.Graph:
|
|
88
|
+
"""Get the reaction center (RC) graph from an ITS graph.
|
|
89
|
+
|
|
90
|
+
:param ITS: The ITS graph to get the RC from.
|
|
91
|
+
:param symbol_key: (optional) The node label that encodes atom symbols on
|
|
92
|
+
the molecular graph.
|
|
93
|
+
:param bond_key: (optional) The edge label that encodes bond order on the
|
|
94
|
+
molecular graph.
|
|
95
|
+
|
|
96
|
+
:returns: Returns the reaction center (RC) graph.
|
|
97
|
+
"""
|
|
98
|
+
rc = nx.Graph()
|
|
99
|
+
for n1, n2, d in ITS.edges(data=True):
|
|
100
|
+
edge_label = d[bond_key]
|
|
101
|
+
if edge_label[0] != edge_label[1]:
|
|
102
|
+
rc.add_node(n1, **{symbol_key: ITS.nodes[n1][symbol_key]})
|
|
103
|
+
rc.add_node(n2, **{symbol_key: ITS.nodes[n2][symbol_key]})
|
|
104
|
+
rc.add_edge(n1, n2, **{bond_key: edge_label})
|
|
105
|
+
return rc
|
|
106
|
+
|
|
107
|
+
|
|
108
|
+
def is_rc_valid(RC: nx.Graph, symbol_key="symbol") -> bool:
|
|
109
|
+
"""Checks if a reaction center (RC) graph is valid. A valid RC does not
|
|
110
|
+
mean it is chemically correct. This function only checks the necessary
|
|
111
|
+
structural requirements for a correct RC. A chemically correct RC is always
|
|
112
|
+
valid but a valid RC is not necessarily chemically correct.
|
|
113
|
+
|
|
114
|
+
:param symbol_key: (optional) The node label that encodes atom symbols on
|
|
115
|
+
the molecular graph.
|
|
116
|
+
|
|
117
|
+
:returns: Returns ``True`` if the RC graph is valid, ``False`` otherwise.
|
|
118
|
+
"""
|
|
119
|
+
for n, d in RC.degree():
|
|
120
|
+
if d < 2:
|
|
121
|
+
return False, "Atom {} {} has degree {}.".format(
|
|
122
|
+
n, RC.nodes[n][symbol_key], d
|
|
123
|
+
)
|
|
124
|
+
return True
|