chemql-python 0.2.1__tar.gz → 1.0.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.
- chemql_python-1.0.0/PKG-INFO +373 -0
- chemql_python-1.0.0/README.md +360 -0
- {chemql_python-0.2.1 → chemql_python-1.0.0}/pyproject.toml +4 -1
- {chemql_python-0.2.1 → chemql_python-1.0.0}/src/chemql/__init__.py +288 -21
- chemql_python-1.0.0/src/chemql_python.egg-info/PKG-INFO +373 -0
- chemql_python-0.2.1/PKG-INFO +0 -309
- chemql_python-0.2.1/README.md +0 -297
- chemql_python-0.2.1/src/chemql_python.egg-info/PKG-INFO +0 -309
- {chemql_python-0.2.1 → chemql_python-1.0.0}/LICENSE +0 -0
- {chemql_python-0.2.1 → chemql_python-1.0.0}/setup.cfg +0 -0
- {chemql_python-0.2.1 → chemql_python-1.0.0}/src/chemql/__main__.py +0 -0
- {chemql_python-0.2.1 → chemql_python-1.0.0}/src/chemql/data/BondEnergies.json +0 -0
- {chemql_python-0.2.1 → chemql_python-1.0.0}/src/chemql/data/MoleculeBonds.json +0 -0
- {chemql_python-0.2.1 → chemql_python-1.0.0}/src/chemql/data/Molecules.json +0 -0
- {chemql_python-0.2.1 → chemql_python-1.0.0}/src/chemql/data/PeriodicTableJSON.json +0 -0
- {chemql_python-0.2.1 → chemql_python-1.0.0}/src/chemql/data/Reactions.json +0 -0
- {chemql_python-0.2.1 → chemql_python-1.0.0}/src/chemql/data/THIRD_PARTY_LICENSES/PeriodicTableJSON.txt +0 -0
- {chemql_python-0.2.1 → chemql_python-1.0.0}/src/chemql/data/THIRD_PARTY_LICENSES/RHEA.txt +0 -0
- {chemql_python-0.2.1 → chemql_python-1.0.0}/src/chemql/html/periodic_table.html +0 -0
- {chemql_python-0.2.1 → chemql_python-1.0.0}/src/chemql_python.egg-info/SOURCES.txt +0 -0
- {chemql_python-0.2.1 → chemql_python-1.0.0}/src/chemql_python.egg-info/dependency_links.txt +0 -0
- {chemql_python-0.2.1 → chemql_python-1.0.0}/src/chemql_python.egg-info/entry_points.txt +0 -0
- {chemql_python-0.2.1 → chemql_python-1.0.0}/src/chemql_python.egg-info/requires.txt +0 -0
- {chemql_python-0.2.1 → chemql_python-1.0.0}/src/chemql_python.egg-info/top_level.txt +0 -0
- {chemql_python-0.2.1 → chemql_python-1.0.0}/tests/test_external_molecule_lookup.py +0 -0
- {chemql_python-0.2.1 → chemql_python-1.0.0}/tests/test_public_api.py +0 -0
- {chemql_python-0.2.1 → chemql_python-1.0.0}/tests/test_reactions.py +0 -0
|
@@ -0,0 +1,373 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: chemql-python
|
|
3
|
+
Version: 1.0.0
|
|
4
|
+
Summary: A chemistry-focused query language and REPL
|
|
5
|
+
Author-email: Mohammad Rakibul Islam <rakibulofficial1017@gmail.com>
|
|
6
|
+
Requires-Python: >=3.10
|
|
7
|
+
Description-Content-Type: text/markdown
|
|
8
|
+
License-File: LICENSE
|
|
9
|
+
Requires-Dist: prompt_toolkit>=3.0
|
|
10
|
+
Provides-Extra: test
|
|
11
|
+
Requires-Dist: pytest>=8.0; extra == "test"
|
|
12
|
+
Dynamic: license-file
|
|
13
|
+
|
|
14
|
+
# ChemQL
|
|
15
|
+
|
|
16
|
+
**ChemQL** is a chemistry-focused query language for searching and
|
|
17
|
+
working with chemical data from Python or an interactive terminal. It
|
|
18
|
+
provides a compact way to query elements, molecules, and chemical
|
|
19
|
+
reactions using filters, logical conditions, sorting, and result
|
|
20
|
+
projections.
|
|
21
|
+
|
|
22
|
+
> Package: `chemql-python`\
|
|
23
|
+
> Python import: `chemql`
|
|
24
|
+
|
|
25
|
+
## Features
|
|
26
|
+
|
|
27
|
+
- Query element, molecule, and reaction datasets.
|
|
28
|
+
- Filter records with comparisons and logical conditions.
|
|
29
|
+
- Match text using wildcard patterns with `like` and case-sensitive
|
|
30
|
+
`like!`.
|
|
31
|
+
- Use `and`, `or`, `not`, and parentheses to combine conditions.
|
|
32
|
+
- Use `likep` for Python regular-expression matching.
|
|
33
|
+
- Combine list results with `union` and `intersection`.
|
|
34
|
+
- Sort, limit, count, and project results with `return`.
|
|
35
|
+
- Look up elements, molecules, and reactions using `findel`,
|
|
36
|
+
`findmol`, and `findre`.
|
|
37
|
+
- Balance chemical equations.
|
|
38
|
+
- Set reaction conditions, including temperature, pressure, and
|
|
39
|
+
catalysts.
|
|
40
|
+
- Use Python expressions and control blocks alongside ChemQL queries.
|
|
41
|
+
- Use ChemQL from the command line or through its Python API.
|
|
42
|
+
|
|
43
|
+
## Installation
|
|
44
|
+
|
|
45
|
+
Install the Python package from PyPI:
|
|
46
|
+
|
|
47
|
+
``` bash
|
|
48
|
+
pip install chemql-python
|
|
49
|
+
```
|
|
50
|
+
|
|
51
|
+
## Quick start
|
|
52
|
+
|
|
53
|
+
Start the interactive terminal:
|
|
54
|
+
|
|
55
|
+
``` bash
|
|
56
|
+
chemql
|
|
57
|
+
```
|
|
58
|
+
|
|
59
|
+
Then try:
|
|
60
|
+
|
|
61
|
+
``` text
|
|
62
|
+
search elements name = "Hydrogen"
|
|
63
|
+
findel "He"
|
|
64
|
+
findmol "H2O"
|
|
65
|
+
search molecules molecular_weight < 20 return name formula molecular_weight
|
|
66
|
+
search reactions reaction_type = "combustion" return name equation
|
|
67
|
+
```
|
|
68
|
+
|
|
69
|
+
Show the built-in command reference from the REPL:
|
|
70
|
+
|
|
71
|
+
``` text
|
|
72
|
+
help
|
|
73
|
+
```
|
|
74
|
+
|
|
75
|
+
## Command-line usage
|
|
76
|
+
|
|
77
|
+
Run a single command with `-c`:
|
|
78
|
+
|
|
79
|
+
``` bash
|
|
80
|
+
chemql -c 'search elements name = "Hydrogen"'
|
|
81
|
+
```
|
|
82
|
+
|
|
83
|
+
Run commands from a file with `-f`:
|
|
84
|
+
|
|
85
|
+
``` bash
|
|
86
|
+
chemql -f queries.chemql
|
|
87
|
+
```
|
|
88
|
+
|
|
89
|
+
Check the installed version:
|
|
90
|
+
|
|
91
|
+
``` bash
|
|
92
|
+
chemql --version
|
|
93
|
+
```
|
|
94
|
+
|
|
95
|
+
A query file can contain multiple ChemQL commands, one per line. Use the
|
|
96
|
+
`//` comment marker for comments and a trailing backslash (`\`) to
|
|
97
|
+
continue a command onto the next line.
|
|
98
|
+
|
|
99
|
+
Example `queries.chemql`:
|
|
100
|
+
|
|
101
|
+
``` text
|
|
102
|
+
// Find lighter molecules
|
|
103
|
+
search molecules molecular_weight < 20 return name formula molecular_weight
|
|
104
|
+
|
|
105
|
+
// Show a subset of the periodic table
|
|
106
|
+
search elements atomic_number > 10 and atomic_number < 20 sort atomic_number desc limit 5
|
|
107
|
+
```
|
|
108
|
+
|
|
109
|
+
## Query language
|
|
110
|
+
|
|
111
|
+
### Data sources
|
|
112
|
+
|
|
113
|
+
ChemQL provides three main sources:
|
|
114
|
+
|
|
115
|
+
Source Contents
|
|
116
|
+
------------- ----------------------------------------------
|
|
117
|
+
`elements` Periodic-table element data
|
|
118
|
+
`molecules` Molecule properties and identifiers
|
|
119
|
+
`reactions` Reaction equations, conditions, and metadata
|
|
120
|
+
|
|
121
|
+
Search a source explicitly:
|
|
122
|
+
|
|
123
|
+
``` text
|
|
124
|
+
search elements
|
|
125
|
+
search molecules
|
|
126
|
+
search reactions
|
|
127
|
+
```
|
|
128
|
+
|
|
129
|
+
You can also use `search all` before a source name, for example:
|
|
130
|
+
|
|
131
|
+
``` text
|
|
132
|
+
search all elements atomic_mass < 100
|
|
133
|
+
```
|
|
134
|
+
|
|
135
|
+
Change the active source in an interactive session with:
|
|
136
|
+
|
|
137
|
+
``` text
|
|
138
|
+
source elements
|
|
139
|
+
source molecules
|
|
140
|
+
source reactions
|
|
141
|
+
```
|
|
142
|
+
|
|
143
|
+
### Filtering
|
|
144
|
+
|
|
145
|
+
Use comparison operators to filter records:
|
|
146
|
+
|
|
147
|
+
Operator Meaning
|
|
148
|
+
---------- ----------------------------------------
|
|
149
|
+
`=` Equal
|
|
150
|
+
`!=` Not equal
|
|
151
|
+
`>` Greater than
|
|
152
|
+
`<` Less than
|
|
153
|
+
`>=` Greater than or equal
|
|
154
|
+
`<=` Less than or equal
|
|
155
|
+
`like` Case-insensitive wildcard match
|
|
156
|
+
`like!` Case-sensitive wildcard match
|
|
157
|
+
`likep` Python regular-expression match
|
|
158
|
+
`has` Check whether a value contains an item
|
|
159
|
+
|
|
160
|
+
Examples:
|
|
161
|
+
|
|
162
|
+
``` text
|
|
163
|
+
search elements atomic_number > 10
|
|
164
|
+
search molecules molecular_weight <= 20
|
|
165
|
+
search molecules name like "*water*"
|
|
166
|
+
search reactions id likep ".*haber(\s*|-|_)process.*"
|
|
167
|
+
```
|
|
168
|
+
|
|
169
|
+
The wildcard matcher supports `*` for a sequence of characters and other
|
|
170
|
+
wildcard tokens supported by ChemQL's pattern matcher. Use `likep` when
|
|
171
|
+
you need regular expressions rather than wildcard patterns.
|
|
172
|
+
|
|
173
|
+
### Logical conditions and parentheses
|
|
174
|
+
|
|
175
|
+
Combine conditions with `and`, `or`, and `not`. Parentheses group
|
|
176
|
+
conditions. Comparison operators and parentheses can be written without
|
|
177
|
+
surrounding spaces.
|
|
178
|
+
|
|
179
|
+
``` text
|
|
180
|
+
search elements name not like "*ium"
|
|
181
|
+
search elements name not like "*ium" and not atomic_mass < 50
|
|
182
|
+
search elements atomic_mass > 50 and (density<10 or boil<100)
|
|
183
|
+
```
|
|
184
|
+
|
|
185
|
+
### Combining query results
|
|
186
|
+
|
|
187
|
+
Use `union` to combine results and `intersection` to keep records
|
|
188
|
+
present in both result lists. Operations are evaluated from left to
|
|
189
|
+
right.
|
|
190
|
+
|
|
191
|
+
``` text
|
|
192
|
+
search elements name not like "*ium" intersection search elements name like "*um"
|
|
193
|
+
```
|
|
194
|
+
|
|
195
|
+
Use the Python API's query-object operators `|` and `&` for union and
|
|
196
|
+
intersection, respectively, when working with `ChemQLQuery` objects.
|
|
197
|
+
|
|
198
|
+
### Sorting, limiting, counting, and returning fields
|
|
199
|
+
|
|
200
|
+
``` text
|
|
201
|
+
search elements sort atomic_number
|
|
202
|
+
search molecules sort molecular_weight desc
|
|
203
|
+
search molecules limit 10
|
|
204
|
+
search molecules count
|
|
205
|
+
search molecules molecular_weight < 20 return name
|
|
206
|
+
search molecules molecular_weight < 20 return name formula molecular_weight
|
|
207
|
+
```
|
|
208
|
+
|
|
209
|
+
- `sort <field> [asc|desc]` sorts results.
|
|
210
|
+
- `limit <number>` limits the number of results.
|
|
211
|
+
- `count` returns the number of matches.
|
|
212
|
+
- `return <field...>` returns only selected fields. One field produces
|
|
213
|
+
a list; multiple fields produce a table-like result.
|
|
214
|
+
- `first` and `last` can be used to select one result.
|
|
215
|
+
|
|
216
|
+
### Find commands
|
|
217
|
+
|
|
218
|
+
``` text
|
|
219
|
+
findel "He"
|
|
220
|
+
findel "Hydrogen"
|
|
221
|
+
|
|
222
|
+
findmol "H2O"
|
|
223
|
+
findmol "Water"
|
|
224
|
+
|
|
225
|
+
findre "Haber process"
|
|
226
|
+
findre "RHEA:10000" return name equation source
|
|
227
|
+
```
|
|
228
|
+
|
|
229
|
+
`findmol` searches the local molecule dataset first and can use external
|
|
230
|
+
chemical-data services when a local match is not found. External lookups
|
|
231
|
+
require an internet connection and may be unavailable if the service is
|
|
232
|
+
down.
|
|
233
|
+
|
|
234
|
+
## Reactions and equation balancing
|
|
235
|
+
|
|
236
|
+
ChemQL includes reaction data and commands for working with reaction
|
|
237
|
+
conditions.
|
|
238
|
+
|
|
239
|
+
``` text
|
|
240
|
+
findre "Haber process"
|
|
241
|
+
balance O2 + H2 -> H2O
|
|
242
|
+
balance O2 + H2 <-> H2O
|
|
243
|
+
```
|
|
244
|
+
|
|
245
|
+
The `->` arrow denotes an irreversible reaction, while `<->` denotes a
|
|
246
|
+
reversible reaction.
|
|
247
|
+
|
|
248
|
+
Set conditions before using `react`:
|
|
249
|
+
|
|
250
|
+
``` text
|
|
251
|
+
set temperature 723K
|
|
252
|
+
set pressure 20265000pa
|
|
253
|
+
set catalysts iron zinc
|
|
254
|
+
conditions
|
|
255
|
+
react N2 3H2
|
|
256
|
+
```
|
|
257
|
+
|
|
258
|
+
Temperature can be supplied in Celsius (`C`), Fahrenheit (`F`), or
|
|
259
|
+
Kelvin (`K`). Pressure supports units such as pascals and bar; the
|
|
260
|
+
available unit conversions depend on the installed version. Preset
|
|
261
|
+
conditions are also available:
|
|
262
|
+
|
|
263
|
+
``` text
|
|
264
|
+
set temperature standard
|
|
265
|
+
set pressure room
|
|
266
|
+
```
|
|
267
|
+
|
|
268
|
+
Use `help` in the terminal for the command reference included with your
|
|
269
|
+
installed version.
|
|
270
|
+
|
|
271
|
+
## Python API
|
|
272
|
+
|
|
273
|
+
Import ChemQL from Python:
|
|
274
|
+
|
|
275
|
+
``` python
|
|
276
|
+
import chemql
|
|
277
|
+
|
|
278
|
+
result = chemql.execute_query_text(
|
|
279
|
+
'search elements name = "Hydrogen"'
|
|
280
|
+
)
|
|
281
|
+
print(result)
|
|
282
|
+
```
|
|
283
|
+
|
|
284
|
+
You can also use `execute_query` for a query string:
|
|
285
|
+
|
|
286
|
+
``` python
|
|
287
|
+
import chemql
|
|
288
|
+
|
|
289
|
+
result = chemql.execute_query('search molecules molecular_weight < 20')
|
|
290
|
+
print(result)
|
|
291
|
+
```
|
|
292
|
+
|
|
293
|
+
The package exposes chemistry data classes and helpers, including
|
|
294
|
+
`Element`, `Molecule`, `Reaction`, `ChemQLError`, `Unknown`,
|
|
295
|
+
`ReturnTable`, and `balance_stoichiometry`.
|
|
296
|
+
|
|
297
|
+
### Query builder API
|
|
298
|
+
|
|
299
|
+
Versions that include the query-builder API also support chaining query
|
|
300
|
+
conditions:
|
|
301
|
+
|
|
302
|
+
``` python
|
|
303
|
+
import chemql
|
|
304
|
+
|
|
305
|
+
x = chemql.search("elements")
|
|
306
|
+
y = x.atomic_mass.condition(lt=10)
|
|
307
|
+
z = y.return_("name")
|
|
308
|
+
|
|
309
|
+
print(z) # The query as text
|
|
310
|
+
print(z.execute()) # Execute the query
|
|
311
|
+
```
|
|
312
|
+
|
|
313
|
+
Query objects can be combined with `|` (union) and `&` (intersection).
|
|
314
|
+
The convenience functions `chemql.union(x, y)` and
|
|
315
|
+
`chemql.intersection(x, y)` are also available in versions that include
|
|
316
|
+
this API.
|
|
317
|
+
|
|
318
|
+
## Hybrid Python
|
|
319
|
+
|
|
320
|
+
ChemQL can execute Python expressions inside square brackets:
|
|
321
|
+
|
|
322
|
+
``` text
|
|
323
|
+
[x = 10]
|
|
324
|
+
[print(x)]
|
|
325
|
+
```
|
|
326
|
+
|
|
327
|
+
It also supports Python control blocks using `[for ...]`, `[if ...]`,
|
|
328
|
+
`[elif ...]`, `[else]`, `[while ...]`, `[break]`, `[continue]`, and
|
|
329
|
+
`[endblock]`.
|
|
330
|
+
|
|
331
|
+
Use `{{ ... }}` to evaluate a ChemQL query and insert its result into
|
|
332
|
+
Python:
|
|
333
|
+
|
|
334
|
+
``` text
|
|
335
|
+
[print({{ search elements atomic_number = 1 }})]
|
|
336
|
+
```
|
|
337
|
+
|
|
338
|
+
Only run Python code and shell commands from sources you trust.
|
|
339
|
+
|
|
340
|
+
## Data and external services
|
|
341
|
+
|
|
342
|
+
ChemQL loads bundled JSON datasets for elements, molecules, reactions,
|
|
343
|
+
molecule bonds, and bond energies. Some molecule lookups may query
|
|
344
|
+
PubChem or other external sources when the local dataset does not
|
|
345
|
+
contain a match.
|
|
346
|
+
|
|
347
|
+
The periodic-table dataset is based on PeriodicTableJSON by
|
|
348
|
+
Bowserinator. Review the dataset's accompanying license and attribution
|
|
349
|
+
requirements when redistributing it or derivative data. The licenses and
|
|
350
|
+
sources for the other bundled datasets should be checked in their
|
|
351
|
+
respective files before redistribution.
|
|
352
|
+
|
|
353
|
+
## Safety note
|
|
354
|
+
|
|
355
|
+
ChemQL's hybrid Python functionality can execute Python code. If your
|
|
356
|
+
installed version supports backtick-wrapped shell commands, those can
|
|
357
|
+
execute operating-system commands as well. Do not run untrusted ChemQL
|
|
358
|
+
scripts or queries.
|
|
359
|
+
|
|
360
|
+
## Development notes
|
|
361
|
+
|
|
362
|
+
- The interactive shell uses `prompt_toolkit`.
|
|
363
|
+
- The command-line interface supports single-command execution (`-c`)
|
|
364
|
+
and file execution (`-f`).
|
|
365
|
+
- Consult the package's source and included `help` output for the
|
|
366
|
+
exact commands and fields supported by your installed version.
|
|
367
|
+
|
|
368
|
+
## License
|
|
369
|
+
|
|
370
|
+
[MIT License](https://github.com/rakibulofficial1017/ChemQL/blob/main/LICENSE)
|
|
371
|
+
|
|
372
|
+
Created by [Mohammad Rakibul Islam](https://github.com/rakibulofficial1017).
|
|
373
|
+
Source code: [rakibulofficial1017/ChemQL](https://github.com/rakibulofficial1017/ChemQL).
|