cholla-chem 0.2.0__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.
- cholla_chem-0.2.0/LICENSE +21 -0
- cholla_chem-0.2.0/PKG-INFO +170 -0
- cholla_chem-0.2.0/README.md +142 -0
- cholla_chem-0.2.0/cholla_chem/__init__.py +31 -0
- cholla_chem-0.2.0/cholla_chem/cli.py +136 -0
- cholla_chem-0.2.0/cholla_chem/datafiles/__init__.py +0 -0
- cholla_chem-0.2.0/cholla_chem/datafiles/chemical_name_tokens.json +1 -0
- cholla_chem-0.2.0/cholla_chem/datafiles/name_dicts/__init__.py +0 -0
- cholla_chem-0.2.0/cholla_chem/datafiles/name_dicts/manual_name_dict.json +1247 -0
- cholla_chem-0.2.0/cholla_chem/datafiles/opsin-cli-2.8.0-jar-with-dependencies.jar +0 -0
- cholla_chem-0.2.0/cholla_chem/main.py +865 -0
- cholla_chem-0.2.0/cholla_chem/name_manipulation/__init__.py +0 -0
- cholla_chem-0.2.0/cholla_chem/name_manipulation/manipulate_names.py +85 -0
- cholla_chem-0.2.0/cholla_chem/name_manipulation/name_correction/__init__.py +0 -0
- cholla_chem-0.2.0/cholla_chem/name_manipulation/name_correction/build_flashtext_ocr_map.py +311 -0
- cholla_chem-0.2.0/cholla_chem/name_manipulation/name_correction/correction_strategies.py +807 -0
- cholla_chem-0.2.0/cholla_chem/name_manipulation/name_correction/dataclasses.py +191 -0
- cholla_chem-0.2.0/cholla_chem/name_manipulation/name_correction/name_corrector.py +361 -0
- cholla_chem-0.2.0/cholla_chem/name_manipulation/name_correction/regexes.py +58 -0
- cholla_chem-0.2.0/cholla_chem/name_manipulation/name_correction/scoring.py +244 -0
- cholla_chem-0.2.0/cholla_chem/name_manipulation/name_correction/validators.py +85 -0
- cholla_chem-0.2.0/cholla_chem/name_manipulation/peptide_shorthand_handler.py +363 -0
- cholla_chem-0.2.0/cholla_chem/name_manipulation/split_names.py +145 -0
- cholla_chem-0.2.0/cholla_chem/name_manipulation/unicode_normalization.py +22 -0
- cholla_chem-0.2.0/cholla_chem/resolvers/__init__.py +0 -0
- cholla_chem-0.2.0/cholla_chem/resolvers/chemspipy_resolver.py +45 -0
- cholla_chem-0.2.0/cholla_chem/resolvers/cirpy_resolver.py +43 -0
- cholla_chem-0.2.0/cholla_chem/resolvers/inorganic_resolver/__init__.py +0 -0
- cholla_chem-0.2.0/cholla_chem/resolvers/inorganic_resolver/inorganic_resolver.py +856 -0
- cholla_chem-0.2.0/cholla_chem/resolvers/inorganic_resolver/inorganic_resolver_tokens.py +5206 -0
- cholla_chem-0.2.0/cholla_chem/resolvers/manual_resolver.py +67 -0
- cholla_chem-0.2.0/cholla_chem/resolvers/opsin_resolver/__init__.py +0 -0
- cholla_chem-0.2.0/cholla_chem/resolvers/opsin_resolver/opsin_resolver.py +232 -0
- cholla_chem-0.2.0/cholla_chem/resolvers/pubchem_resolver/__init__.py +0 -0
- cholla_chem-0.2.0/cholla_chem/resolvers/pubchem_resolver/pubchem_resolver.py +510 -0
- cholla_chem-0.2.0/cholla_chem/resolvers/structural_formula_resolver/__init__.py +0 -0
- cholla_chem-0.2.0/cholla_chem/resolvers/structural_formula_resolver/structural_formula_resolver.py +1436 -0
- cholla_chem-0.2.0/cholla_chem/resolvers/structural_formula_resolver/structural_formula_resolver_tokens.py +305 -0
- cholla_chem-0.2.0/cholla_chem/smiles_selector.py +254 -0
- cholla_chem-0.2.0/cholla_chem/types.py +26 -0
- cholla_chem-0.2.0/cholla_chem/utils/__init__.py +0 -0
- cholla_chem-0.2.0/cholla_chem/utils/chem_utils.py +92 -0
- cholla_chem-0.2.0/cholla_chem/utils/constants.py +792 -0
- cholla_chem-0.2.0/cholla_chem/utils/file_utils.py +168 -0
- cholla_chem-0.2.0/cholla_chem/utils/logging_config.py +146 -0
- cholla_chem-0.2.0/cholla_chem/utils/string_utils.py +98 -0
- cholla_chem-0.2.0/cholla_chem.egg-info/PKG-INFO +170 -0
- cholla_chem-0.2.0/cholla_chem.egg-info/SOURCES.txt +66 -0
- cholla_chem-0.2.0/cholla_chem.egg-info/dependency_links.txt +1 -0
- cholla_chem-0.2.0/cholla_chem.egg-info/entry_points.txt +2 -0
- cholla_chem-0.2.0/cholla_chem.egg-info/not-zip-safe +1 -0
- cholla_chem-0.2.0/cholla_chem.egg-info/requires.txt +6 -0
- cholla_chem-0.2.0/cholla_chem.egg-info/top_level.txt +6 -0
- cholla_chem-0.2.0/pyproject.toml +60 -0
- cholla_chem-0.2.0/requirements.txt +6 -0
- cholla_chem-0.2.0/scripts/__init__.py +0 -0
- cholla_chem-0.2.0/scripts/build_flashtext_ocr_maps.py +67 -0
- cholla_chem-0.2.0/setup.cfg +4 -0
- cholla_chem-0.2.0/tests/test_chemspipy_resolver.py +245 -0
- cholla_chem-0.2.0/tests/test_cirpy_resolver.py +72 -0
- cholla_chem-0.2.0/tests/test_main.py +387 -0
- cholla_chem-0.2.0/tests/test_manual_resolver.py +92 -0
- cholla_chem-0.2.0/tests/test_ocr_map_consistency.py +93 -0
- cholla_chem-0.2.0/tests/test_opsin_resolver.py +385 -0
- cholla_chem-0.2.0/tests/test_pubchem_resolver.py +382 -0
- cholla_chem-0.2.0/tests/test_smiles_selector.py +206 -0
- cholla_chem-0.2.0/tests/test_split_name_name_manipulation.py +89 -0
- cholla_chem-0.2.0/tests/test_structural_formula_resolver.py +164 -0
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2025 De Novo Chem
|
|
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.
|
|
@@ -0,0 +1,170 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: cholla_chem
|
|
3
|
+
Version: 0.2.0
|
|
4
|
+
Summary: Name-to-SMILES conversion
|
|
5
|
+
Author-email: De Novo Chem Team <carson.britt@denovochem.com>
|
|
6
|
+
Project-URL: Homepage, https://github.com/denovochem/cholla_chem
|
|
7
|
+
Classifier: Programming Language :: Python :: 3
|
|
8
|
+
Classifier: Programming Language :: Python :: 3.10
|
|
9
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
10
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
11
|
+
Classifier: Programming Language :: Python :: 3.13
|
|
12
|
+
Classifier: License :: OSI Approved :: MIT License
|
|
13
|
+
Classifier: Operating System :: OS Independent
|
|
14
|
+
Classifier: Development Status :: 3 - Alpha
|
|
15
|
+
Classifier: Intended Audience :: Developers
|
|
16
|
+
Classifier: Intended Audience :: Science/Research
|
|
17
|
+
Classifier: Topic :: Software Development :: Libraries
|
|
18
|
+
Requires-Python: >=3.10
|
|
19
|
+
Description-Content-Type: text/markdown
|
|
20
|
+
License-File: LICENSE
|
|
21
|
+
Requires-Dist: loguru~=0.7.0
|
|
22
|
+
Requires-Dist: cirpy~=1.0.0
|
|
23
|
+
Requires-Dist: chemspipy~=2.0.0
|
|
24
|
+
Requires-Dist: rdkit>=2025.9.3
|
|
25
|
+
Requires-Dist: levenshtein
|
|
26
|
+
Requires-Dist: flashtext
|
|
27
|
+
Dynamic: license-file
|
|
28
|
+
|
|
29
|
+
# cholla_chem
|
|
30
|
+
[](https://github.com/denovochem/cholla_chem/releases)
|
|
31
|
+
[](https://gitHub.com/denovochem/cholla_chem/graphs/commit-activity)
|
|
32
|
+
[](https://github.com/denovochem/cholla_chem/blob/main/LICENSE)
|
|
33
|
+
[](https://github.com/denovochem/cholla_chem/actions/workflows/tests.yml)
|
|
34
|
+
[](https://github.com/denovochem/cholla_chem/actions/workflows/docs.yml)
|
|
35
|
+
[](https://colab.research.google.com/github/denovochem/cholla_chem/blob/main/examples/example_notebook.ipynb)
|
|
36
|
+
|
|
37
|
+
This library is used for performant, comprehensive, and customizable name-to-SMILES conversions.
|
|
38
|
+
|
|
39
|
+
This library can use the following existing name-to-SMILES resolvers:
|
|
40
|
+
- [OPSIN](https://github.com/dan2097/opsin) using code adapted from [py2opsin](https://github.com/JacksonBurns/py2opsin)
|
|
41
|
+
- [PubChem](https://pubchem.ncbi.nlm.nih.gov/) using code adapted from [PubChemPy](https://github.com/mcs07/PubChemPy)
|
|
42
|
+
- [CIRpy](https://github.com/mcs07/CIRpy)
|
|
43
|
+
- [ChemSpiPy](https://github.com/mcs07/ChemSpiPy)
|
|
44
|
+
|
|
45
|
+
This library also implements the following new resolvers:
|
|
46
|
+
- Manually curated dataset of common names not correctly resolved by other resolvers (e.g. 'NaH')
|
|
47
|
+
- Structural formula resolver (e.g. 'CH3CH2CH2COOH')
|
|
48
|
+
- Inorganic shorthand resolver (e.g. '[Cp*RhCl2]2')
|
|
49
|
+
|
|
50
|
+
|
|
51
|
+
The following string editing/manipulation strategies may be applied to compounds to assist with name-to-SMILES resolution:
|
|
52
|
+
- String sanitization for special characters and mojibake encoding errors
|
|
53
|
+
- Name correction for OCR errors, typos, pagination errors, etc.
|
|
54
|
+
- Splitting compounds on common delimiters (useful for mixtures of compounds, e.g. 'BH3•THF')
|
|
55
|
+
- Peptide shorthand expansion (e.g. 'cyclo(Asp-Arg-Val-Tyr-Ile-His-Pro-Phe)' -> 'cyclo(l-aspartyl-l-arginyl-l-valyl-l-tyrosyl-l-isoleucyl-l-histidyl-l-prolyl-l-phenylalanyl)')
|
|
56
|
+
|
|
57
|
+
|
|
58
|
+
When resolvers disagree on the SMILES for a given compound, a variety of SMILES selection methods can be employed to determine the "best" SMILES for a given compound name. See the documentation for more details.
|
|
59
|
+
|
|
60
|
+
## Installation
|
|
61
|
+
|
|
62
|
+
Install cholla_chem with pip directly from this repo:
|
|
63
|
+
|
|
64
|
+
```shell
|
|
65
|
+
pip install git+https://github.com/denovochem/cholla_chem.git
|
|
66
|
+
```
|
|
67
|
+
|
|
68
|
+
## Basic usage
|
|
69
|
+
Resolve chemical names to SMILES by passing a string or a list of strings:
|
|
70
|
+
```pycon
|
|
71
|
+
from cholla_chem import resolve_compounds_to_smiles
|
|
72
|
+
|
|
73
|
+
resolved_smiles = resolve_compounds_to_smiles(compounds_list=['aspirin'])
|
|
74
|
+
|
|
75
|
+
"{'aspirin': 'CC(=O)Oc1ccccc1C(=O)O'}"
|
|
76
|
+
```
|
|
77
|
+
|
|
78
|
+
See detailed information including which resolver returned which SMILES with detailed_name_dict=True:
|
|
79
|
+
```pycon
|
|
80
|
+
from cholla_chem import resolve_compounds_to_smiles
|
|
81
|
+
|
|
82
|
+
resolved_smiles = resolve_compounds_to_smiles(
|
|
83
|
+
compounds_list=['2-acetyloxybenzoic acid'],
|
|
84
|
+
detailed_name_dict=True
|
|
85
|
+
)
|
|
86
|
+
|
|
87
|
+
"{'2-acetyloxybenzoic acid': {
|
|
88
|
+
'SMILES': 'CC(=O)Oc1ccccc1C(=O)O',
|
|
89
|
+
'SMILES_source': ['pubchem_default', 'opsin_default'],
|
|
90
|
+
'SMILES_dict': {
|
|
91
|
+
'CC(=O)Oc1ccccc1C(=O)O': ['pubchem_default', 'opsin_default']
|
|
92
|
+
},
|
|
93
|
+
'additional_info': {}
|
|
94
|
+
}}"
|
|
95
|
+
```
|
|
96
|
+
|
|
97
|
+
## Advanced usage
|
|
98
|
+
Many aspects of the name-to-SMILES resolution process can be customized, including the resolvers that are used, the configuration of those resolvers, and the strategy used to pick the best SMILES.
|
|
99
|
+
|
|
100
|
+
In this example, we resolve chemical names with OPSIN, PubChem, and CIRPy, and use a custom consensus weighting approach to pick the best SMILES:
|
|
101
|
+
```pycon
|
|
102
|
+
from cholla_chem import (
|
|
103
|
+
OpsinNameResolver,
|
|
104
|
+
PubChemNameResolver,
|
|
105
|
+
CIRpyNameResolver,
|
|
106
|
+
resolve_compounds_to_smiles,
|
|
107
|
+
)
|
|
108
|
+
|
|
109
|
+
opsin_resolver = OpsinNameResolver(
|
|
110
|
+
resolver_name='opsin',
|
|
111
|
+
resolver_weight=4
|
|
112
|
+
)
|
|
113
|
+
pubchem_resolver = PubChemNameResolver(
|
|
114
|
+
resolver_name='pubchem',
|
|
115
|
+
resolver_weight=3
|
|
116
|
+
)
|
|
117
|
+
cirpy_resolver = CIRpyNameResolver(
|
|
118
|
+
resolver_name='cirpy',
|
|
119
|
+
resolver_weight=2
|
|
120
|
+
)
|
|
121
|
+
|
|
122
|
+
resolved_smiles = resolve_compounds_to_smiles(
|
|
123
|
+
compounds_list=['2-acetyloxybenzoic acid'],
|
|
124
|
+
resolvers_list=[opsin_resolver, pubchem_resolver, cirpy_resolver],
|
|
125
|
+
smiles_selection_mode='weighted',
|
|
126
|
+
detailed_name_dict=True
|
|
127
|
+
)
|
|
128
|
+
|
|
129
|
+
"{'2-acetyloxybenzoic acid': {
|
|
130
|
+
'SMILES': 'CC(=O)Oc1ccccc1C(=O)O',
|
|
131
|
+
'SMILES_source': ['opsin', 'pubchem', 'cirpy'],
|
|
132
|
+
'SMILES_dict': {
|
|
133
|
+
'CC(=O)Oc1ccccc1C(=O)O': ['opsin', 'pubchem', 'cirpy']
|
|
134
|
+
},
|
|
135
|
+
'additional_info': {}
|
|
136
|
+
}}"
|
|
137
|
+
```
|
|
138
|
+
|
|
139
|
+
## Command line interface
|
|
140
|
+
|
|
141
|
+
cholla_chem can be used as a command line tool. The command line interface can resolve single chemical names directly from the command line or read from a file.
|
|
142
|
+
|
|
143
|
+
Resolve compounds directly from the command line:
|
|
144
|
+
```bash
|
|
145
|
+
cholla-chem "aspirin"
|
|
146
|
+
```
|
|
147
|
+
|
|
148
|
+
Resolve compounds from a file:
|
|
149
|
+
```bash
|
|
150
|
+
cholla-chem --input names.txt --output results.tsv
|
|
151
|
+
```
|
|
152
|
+
|
|
153
|
+
See help for more options:
|
|
154
|
+
```bash
|
|
155
|
+
cholla-chem --help
|
|
156
|
+
```
|
|
157
|
+
|
|
158
|
+
See documentation for more details.
|
|
159
|
+
|
|
160
|
+
## Documentation
|
|
161
|
+
Full documentation is available [here](https://denovochem.github.io/cholla_chem/)
|
|
162
|
+
|
|
163
|
+
## Contributing
|
|
164
|
+
|
|
165
|
+
- Feature ideas and bug reports are welcome on the Issue Tracker.
|
|
166
|
+
- Fork the [source code](https://github.com/denovochem/cholla_chem) on GitHub, make changes and file a pull request.
|
|
167
|
+
|
|
168
|
+
## License
|
|
169
|
+
|
|
170
|
+
cholla_chem is licensed under the [MIT license](https://github.com/denovochem/cholla_chem/blob/main/LICENSE).
|
|
@@ -0,0 +1,142 @@
|
|
|
1
|
+
# cholla_chem
|
|
2
|
+
[](https://github.com/denovochem/cholla_chem/releases)
|
|
3
|
+
[](https://gitHub.com/denovochem/cholla_chem/graphs/commit-activity)
|
|
4
|
+
[](https://github.com/denovochem/cholla_chem/blob/main/LICENSE)
|
|
5
|
+
[](https://github.com/denovochem/cholla_chem/actions/workflows/tests.yml)
|
|
6
|
+
[](https://github.com/denovochem/cholla_chem/actions/workflows/docs.yml)
|
|
7
|
+
[](https://colab.research.google.com/github/denovochem/cholla_chem/blob/main/examples/example_notebook.ipynb)
|
|
8
|
+
|
|
9
|
+
This library is used for performant, comprehensive, and customizable name-to-SMILES conversions.
|
|
10
|
+
|
|
11
|
+
This library can use the following existing name-to-SMILES resolvers:
|
|
12
|
+
- [OPSIN](https://github.com/dan2097/opsin) using code adapted from [py2opsin](https://github.com/JacksonBurns/py2opsin)
|
|
13
|
+
- [PubChem](https://pubchem.ncbi.nlm.nih.gov/) using code adapted from [PubChemPy](https://github.com/mcs07/PubChemPy)
|
|
14
|
+
- [CIRpy](https://github.com/mcs07/CIRpy)
|
|
15
|
+
- [ChemSpiPy](https://github.com/mcs07/ChemSpiPy)
|
|
16
|
+
|
|
17
|
+
This library also implements the following new resolvers:
|
|
18
|
+
- Manually curated dataset of common names not correctly resolved by other resolvers (e.g. 'NaH')
|
|
19
|
+
- Structural formula resolver (e.g. 'CH3CH2CH2COOH')
|
|
20
|
+
- Inorganic shorthand resolver (e.g. '[Cp*RhCl2]2')
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
The following string editing/manipulation strategies may be applied to compounds to assist with name-to-SMILES resolution:
|
|
24
|
+
- String sanitization for special characters and mojibake encoding errors
|
|
25
|
+
- Name correction for OCR errors, typos, pagination errors, etc.
|
|
26
|
+
- Splitting compounds on common delimiters (useful for mixtures of compounds, e.g. 'BH3•THF')
|
|
27
|
+
- Peptide shorthand expansion (e.g. 'cyclo(Asp-Arg-Val-Tyr-Ile-His-Pro-Phe)' -> 'cyclo(l-aspartyl-l-arginyl-l-valyl-l-tyrosyl-l-isoleucyl-l-histidyl-l-prolyl-l-phenylalanyl)')
|
|
28
|
+
|
|
29
|
+
|
|
30
|
+
When resolvers disagree on the SMILES for a given compound, a variety of SMILES selection methods can be employed to determine the "best" SMILES for a given compound name. See the documentation for more details.
|
|
31
|
+
|
|
32
|
+
## Installation
|
|
33
|
+
|
|
34
|
+
Install cholla_chem with pip directly from this repo:
|
|
35
|
+
|
|
36
|
+
```shell
|
|
37
|
+
pip install git+https://github.com/denovochem/cholla_chem.git
|
|
38
|
+
```
|
|
39
|
+
|
|
40
|
+
## Basic usage
|
|
41
|
+
Resolve chemical names to SMILES by passing a string or a list of strings:
|
|
42
|
+
```pycon
|
|
43
|
+
from cholla_chem import resolve_compounds_to_smiles
|
|
44
|
+
|
|
45
|
+
resolved_smiles = resolve_compounds_to_smiles(compounds_list=['aspirin'])
|
|
46
|
+
|
|
47
|
+
"{'aspirin': 'CC(=O)Oc1ccccc1C(=O)O'}"
|
|
48
|
+
```
|
|
49
|
+
|
|
50
|
+
See detailed information including which resolver returned which SMILES with detailed_name_dict=True:
|
|
51
|
+
```pycon
|
|
52
|
+
from cholla_chem import resolve_compounds_to_smiles
|
|
53
|
+
|
|
54
|
+
resolved_smiles = resolve_compounds_to_smiles(
|
|
55
|
+
compounds_list=['2-acetyloxybenzoic acid'],
|
|
56
|
+
detailed_name_dict=True
|
|
57
|
+
)
|
|
58
|
+
|
|
59
|
+
"{'2-acetyloxybenzoic acid': {
|
|
60
|
+
'SMILES': 'CC(=O)Oc1ccccc1C(=O)O',
|
|
61
|
+
'SMILES_source': ['pubchem_default', 'opsin_default'],
|
|
62
|
+
'SMILES_dict': {
|
|
63
|
+
'CC(=O)Oc1ccccc1C(=O)O': ['pubchem_default', 'opsin_default']
|
|
64
|
+
},
|
|
65
|
+
'additional_info': {}
|
|
66
|
+
}}"
|
|
67
|
+
```
|
|
68
|
+
|
|
69
|
+
## Advanced usage
|
|
70
|
+
Many aspects of the name-to-SMILES resolution process can be customized, including the resolvers that are used, the configuration of those resolvers, and the strategy used to pick the best SMILES.
|
|
71
|
+
|
|
72
|
+
In this example, we resolve chemical names with OPSIN, PubChem, and CIRPy, and use a custom consensus weighting approach to pick the best SMILES:
|
|
73
|
+
```pycon
|
|
74
|
+
from cholla_chem import (
|
|
75
|
+
OpsinNameResolver,
|
|
76
|
+
PubChemNameResolver,
|
|
77
|
+
CIRpyNameResolver,
|
|
78
|
+
resolve_compounds_to_smiles,
|
|
79
|
+
)
|
|
80
|
+
|
|
81
|
+
opsin_resolver = OpsinNameResolver(
|
|
82
|
+
resolver_name='opsin',
|
|
83
|
+
resolver_weight=4
|
|
84
|
+
)
|
|
85
|
+
pubchem_resolver = PubChemNameResolver(
|
|
86
|
+
resolver_name='pubchem',
|
|
87
|
+
resolver_weight=3
|
|
88
|
+
)
|
|
89
|
+
cirpy_resolver = CIRpyNameResolver(
|
|
90
|
+
resolver_name='cirpy',
|
|
91
|
+
resolver_weight=2
|
|
92
|
+
)
|
|
93
|
+
|
|
94
|
+
resolved_smiles = resolve_compounds_to_smiles(
|
|
95
|
+
compounds_list=['2-acetyloxybenzoic acid'],
|
|
96
|
+
resolvers_list=[opsin_resolver, pubchem_resolver, cirpy_resolver],
|
|
97
|
+
smiles_selection_mode='weighted',
|
|
98
|
+
detailed_name_dict=True
|
|
99
|
+
)
|
|
100
|
+
|
|
101
|
+
"{'2-acetyloxybenzoic acid': {
|
|
102
|
+
'SMILES': 'CC(=O)Oc1ccccc1C(=O)O',
|
|
103
|
+
'SMILES_source': ['opsin', 'pubchem', 'cirpy'],
|
|
104
|
+
'SMILES_dict': {
|
|
105
|
+
'CC(=O)Oc1ccccc1C(=O)O': ['opsin', 'pubchem', 'cirpy']
|
|
106
|
+
},
|
|
107
|
+
'additional_info': {}
|
|
108
|
+
}}"
|
|
109
|
+
```
|
|
110
|
+
|
|
111
|
+
## Command line interface
|
|
112
|
+
|
|
113
|
+
cholla_chem can be used as a command line tool. The command line interface can resolve single chemical names directly from the command line or read from a file.
|
|
114
|
+
|
|
115
|
+
Resolve compounds directly from the command line:
|
|
116
|
+
```bash
|
|
117
|
+
cholla-chem "aspirin"
|
|
118
|
+
```
|
|
119
|
+
|
|
120
|
+
Resolve compounds from a file:
|
|
121
|
+
```bash
|
|
122
|
+
cholla-chem --input names.txt --output results.tsv
|
|
123
|
+
```
|
|
124
|
+
|
|
125
|
+
See help for more options:
|
|
126
|
+
```bash
|
|
127
|
+
cholla-chem --help
|
|
128
|
+
```
|
|
129
|
+
|
|
130
|
+
See documentation for more details.
|
|
131
|
+
|
|
132
|
+
## Documentation
|
|
133
|
+
Full documentation is available [here](https://denovochem.github.io/cholla_chem/)
|
|
134
|
+
|
|
135
|
+
## Contributing
|
|
136
|
+
|
|
137
|
+
- Feature ideas and bug reports are welcome on the Issue Tracker.
|
|
138
|
+
- Fork the [source code](https://github.com/denovochem/cholla_chem) on GitHub, make changes and file a pull request.
|
|
139
|
+
|
|
140
|
+
## License
|
|
141
|
+
|
|
142
|
+
cholla_chem is licensed under the [MIT license](https://github.com/denovochem/cholla_chem/blob/main/LICENSE).
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
"""cholla_chem initialization."""
|
|
2
|
+
|
|
3
|
+
from cholla_chem.main import (
|
|
4
|
+
ChemicalNameResolver,
|
|
5
|
+
ChemSpiPyResolver,
|
|
6
|
+
CIRpyNameResolver,
|
|
7
|
+
InorganicShorthandNameResolver,
|
|
8
|
+
ManualNameResolver,
|
|
9
|
+
OpsinNameResolver,
|
|
10
|
+
PubChemNameResolver,
|
|
11
|
+
StructuralFormulaNameResolver,
|
|
12
|
+
resolve_compounds_to_smiles,
|
|
13
|
+
)
|
|
14
|
+
from cholla_chem.name_manipulation.name_correction.dataclasses import CorrectorConfig
|
|
15
|
+
from cholla_chem.name_manipulation.name_correction.name_corrector import (
|
|
16
|
+
ChemNameCorrector,
|
|
17
|
+
)
|
|
18
|
+
|
|
19
|
+
__all__ = [
|
|
20
|
+
"resolve_compounds_to_smiles",
|
|
21
|
+
"ChemSpiPyResolver",
|
|
22
|
+
"ChemicalNameResolver",
|
|
23
|
+
"ManualNameResolver",
|
|
24
|
+
"OpsinNameResolver",
|
|
25
|
+
"PubChemNameResolver",
|
|
26
|
+
"StructuralFormulaNameResolver",
|
|
27
|
+
"CIRpyNameResolver",
|
|
28
|
+
"InorganicShorthandNameResolver",
|
|
29
|
+
"ChemNameCorrector",
|
|
30
|
+
"CorrectorConfig",
|
|
31
|
+
]
|
|
@@ -0,0 +1,136 @@
|
|
|
1
|
+
import argparse
|
|
2
|
+
from typing import Optional, Sequence
|
|
3
|
+
|
|
4
|
+
from cholla_chem.main import resolve_compounds_to_smiles
|
|
5
|
+
from cholla_chem.utils.file_utils import read_names_from_file, write_results
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
def build_parser() -> argparse.ArgumentParser:
|
|
9
|
+
"""
|
|
10
|
+
Build a parser for the CLI.
|
|
11
|
+
|
|
12
|
+
Returns:
|
|
13
|
+
argparse.ArgumentParser: A parser object
|
|
14
|
+
"""
|
|
15
|
+
p = argparse.ArgumentParser(prog="cholla-chem")
|
|
16
|
+
p.add_argument("names", nargs="*", type=str, help="Chemical names to resolve")
|
|
17
|
+
p.add_argument("--input", "-i", type=str, help="Text file with one name per line")
|
|
18
|
+
p.add_argument(
|
|
19
|
+
"--input-format",
|
|
20
|
+
type=str,
|
|
21
|
+
default=None,
|
|
22
|
+
choices=["txt", "csv", "tsv"],
|
|
23
|
+
help="Optional override for input format (otherwise inferred from file extension)",
|
|
24
|
+
)
|
|
25
|
+
p.add_argument(
|
|
26
|
+
"--input-column",
|
|
27
|
+
type=str,
|
|
28
|
+
default="name",
|
|
29
|
+
help="Column name to read from CSV/TSV inputs (default: name)",
|
|
30
|
+
)
|
|
31
|
+
p.add_argument(
|
|
32
|
+
"--output", "-o", type=str, help="Write results to a file (default: stdout)"
|
|
33
|
+
)
|
|
34
|
+
p.add_argument(
|
|
35
|
+
"--output-format",
|
|
36
|
+
type=str,
|
|
37
|
+
default=None,
|
|
38
|
+
choices=["json", "csv", "tsv", "smi", "txt"],
|
|
39
|
+
help="Optional override for output format (otherwise inferred from output file extension)",
|
|
40
|
+
)
|
|
41
|
+
p.add_argument(
|
|
42
|
+
"--smiles-selection-mode",
|
|
43
|
+
default="weighted",
|
|
44
|
+
type=str,
|
|
45
|
+
help="Smiles selection mode",
|
|
46
|
+
)
|
|
47
|
+
p.add_argument(
|
|
48
|
+
"--detailed-name-dict",
|
|
49
|
+
default=False,
|
|
50
|
+
type=bool,
|
|
51
|
+
help="Whether to return a detailed name dictionary",
|
|
52
|
+
)
|
|
53
|
+
p.add_argument("--batch-size", default=500, type=int, help="Batch size")
|
|
54
|
+
p.add_argument(
|
|
55
|
+
"--normalize-unicode",
|
|
56
|
+
default=True,
|
|
57
|
+
type=bool,
|
|
58
|
+
help="Whether to normalize unicode",
|
|
59
|
+
)
|
|
60
|
+
p.add_argument(
|
|
61
|
+
"--split-names-to-solve",
|
|
62
|
+
default=True,
|
|
63
|
+
type=bool,
|
|
64
|
+
help="Whether to split names to solve",
|
|
65
|
+
)
|
|
66
|
+
p.add_argument(
|
|
67
|
+
"--resolve-peptide-shorthand",
|
|
68
|
+
default=True,
|
|
69
|
+
type=bool,
|
|
70
|
+
help="Whether to resolve peptide shorthand",
|
|
71
|
+
)
|
|
72
|
+
p.add_argument(
|
|
73
|
+
"--attempt-name-correction",
|
|
74
|
+
default=True,
|
|
75
|
+
type=bool,
|
|
76
|
+
help="Whether to attempt name correction",
|
|
77
|
+
)
|
|
78
|
+
p.add_argument(
|
|
79
|
+
"--internet-connection-available",
|
|
80
|
+
default=True,
|
|
81
|
+
type=bool,
|
|
82
|
+
help="Whether an internet connection is available",
|
|
83
|
+
)
|
|
84
|
+
return p
|
|
85
|
+
|
|
86
|
+
|
|
87
|
+
def main(argv: Optional[Sequence[str]] = None) -> int:
|
|
88
|
+
"""
|
|
89
|
+
Main entry point for the CLI.
|
|
90
|
+
|
|
91
|
+
Resolve compound names to SMILES strings.
|
|
92
|
+
|
|
93
|
+
Args:
|
|
94
|
+
argv: Optional sequence of command-line arguments
|
|
95
|
+
|
|
96
|
+
Returns:
|
|
97
|
+
int: Exit code (0 for success, non-zero for failure)
|
|
98
|
+
"""
|
|
99
|
+
parser = build_parser()
|
|
100
|
+
args = parser.parse_args(argv)
|
|
101
|
+
|
|
102
|
+
names = list(args.names)
|
|
103
|
+
if args.input:
|
|
104
|
+
names.extend(
|
|
105
|
+
read_names_from_file(
|
|
106
|
+
args.input,
|
|
107
|
+
input_format=args.input_format,
|
|
108
|
+
input_column=args.input_column,
|
|
109
|
+
)
|
|
110
|
+
)
|
|
111
|
+
|
|
112
|
+
if not names:
|
|
113
|
+
parser.error("Provide names as arguments or via --input")
|
|
114
|
+
|
|
115
|
+
if args.output_format != "json" and args.detailed_name_dict:
|
|
116
|
+
parser.error("--detailed-name-dict can only be used with JSON output format")
|
|
117
|
+
|
|
118
|
+
results = resolve_compounds_to_smiles(
|
|
119
|
+
names,
|
|
120
|
+
smiles_selection_mode=args.smiles_selection_mode,
|
|
121
|
+
detailed_name_dict=args.detailed_name_dict,
|
|
122
|
+
batch_size=args.batch_size,
|
|
123
|
+
normalize_unicode=args.normalize_unicode,
|
|
124
|
+
split_names_to_solve=args.split_names_to_solve,
|
|
125
|
+
resolve_peptide_shorthand=args.resolve_peptide_shorthand,
|
|
126
|
+
attempt_name_correction=args.attempt_name_correction,
|
|
127
|
+
internet_connection_available=args.internet_connection_available,
|
|
128
|
+
)
|
|
129
|
+
|
|
130
|
+
write_results(
|
|
131
|
+
results,
|
|
132
|
+
output_path=args.output,
|
|
133
|
+
output_format=args.output_format,
|
|
134
|
+
)
|
|
135
|
+
|
|
136
|
+
return 0
|
|
File without changes
|