chemql-python 0.2.2__tar.gz → 1.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.
Files changed (27) hide show
  1. chemql_python-1.0.1/PKG-INFO +443 -0
  2. chemql_python-1.0.1/README.md +430 -0
  3. {chemql_python-0.2.2 → chemql_python-1.0.1}/pyproject.toml +4 -1
  4. {chemql_python-0.2.2 → chemql_python-1.0.1}/src/chemql/__init__.py +425 -21
  5. chemql_python-1.0.1/src/chemql_python.egg-info/PKG-INFO +443 -0
  6. chemql_python-0.2.2/PKG-INFO +0 -309
  7. chemql_python-0.2.2/README.md +0 -297
  8. chemql_python-0.2.2/src/chemql_python.egg-info/PKG-INFO +0 -309
  9. {chemql_python-0.2.2 → chemql_python-1.0.1}/LICENSE +0 -0
  10. {chemql_python-0.2.2 → chemql_python-1.0.1}/setup.cfg +0 -0
  11. {chemql_python-0.2.2 → chemql_python-1.0.1}/src/chemql/__main__.py +0 -0
  12. {chemql_python-0.2.2 → chemql_python-1.0.1}/src/chemql/data/BondEnergies.json +0 -0
  13. {chemql_python-0.2.2 → chemql_python-1.0.1}/src/chemql/data/MoleculeBonds.json +0 -0
  14. {chemql_python-0.2.2 → chemql_python-1.0.1}/src/chemql/data/Molecules.json +0 -0
  15. {chemql_python-0.2.2 → chemql_python-1.0.1}/src/chemql/data/PeriodicTableJSON.json +0 -0
  16. {chemql_python-0.2.2 → chemql_python-1.0.1}/src/chemql/data/Reactions.json +0 -0
  17. {chemql_python-0.2.2 → chemql_python-1.0.1}/src/chemql/data/THIRD_PARTY_LICENSES/PeriodicTableJSON.txt +0 -0
  18. {chemql_python-0.2.2 → chemql_python-1.0.1}/src/chemql/data/THIRD_PARTY_LICENSES/RHEA.txt +0 -0
  19. {chemql_python-0.2.2 → chemql_python-1.0.1}/src/chemql/html/periodic_table.html +0 -0
  20. {chemql_python-0.2.2 → chemql_python-1.0.1}/src/chemql_python.egg-info/SOURCES.txt +0 -0
  21. {chemql_python-0.2.2 → chemql_python-1.0.1}/src/chemql_python.egg-info/dependency_links.txt +0 -0
  22. {chemql_python-0.2.2 → chemql_python-1.0.1}/src/chemql_python.egg-info/entry_points.txt +0 -0
  23. {chemql_python-0.2.2 → chemql_python-1.0.1}/src/chemql_python.egg-info/requires.txt +0 -0
  24. {chemql_python-0.2.2 → chemql_python-1.0.1}/src/chemql_python.egg-info/top_level.txt +0 -0
  25. {chemql_python-0.2.2 → chemql_python-1.0.1}/tests/test_external_molecule_lookup.py +0 -0
  26. {chemql_python-0.2.2 → chemql_python-1.0.1}/tests/test_public_api.py +0 -0
  27. {chemql_python-0.2.2 → chemql_python-1.0.1}/tests/test_reactions.py +0 -0
@@ -0,0 +1,443 @@
1
+ Metadata-Version: 2.4
2
+ Name: chemql-python
3
+ Version: 1.0.1
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
+ ## Upgrading the package or switching versions
52
+
53
+ If your chemql-python version is >=1.0.1, you can simply run
54
+ ```bash
55
+ chemql --upgrade
56
+ ```
57
+ Or to switch versions to for example 0.2.2
58
+ ```bash
59
+ chemql --upgrade 0.2.2
60
+ ```
61
+ However if you do not have chemql-python version >=1.0.1
62
+ ```bash
63
+ pip install --upgrade chemql-python
64
+ ```
65
+ Or to switch versions to for example 0.2.2
66
+ ```bash
67
+ pip install --force-reinstall chemql-python==0.2.2
68
+ ```
69
+
70
+ ## Quick start
71
+
72
+ Start the interactive terminal:
73
+
74
+ ``` bash
75
+ chemql
76
+ ```
77
+
78
+ Then try:
79
+
80
+ ``` text
81
+ search elements name = "Hydrogen"
82
+ findel "He"
83
+ findmol "H2O"
84
+ search molecules molecular_weight < 20 return name formula molecular_weight
85
+ search reactions reaction_type = "combustion" return name equation
86
+ ```
87
+
88
+ Show the built-in command reference from the REPL:
89
+
90
+ ``` text
91
+ help
92
+ ```
93
+
94
+ ## Command-line usage
95
+
96
+ Run a single command with `-c`:
97
+
98
+ ``` bash
99
+ chemql -c 'search elements name = "Hydrogen"'
100
+ ```
101
+
102
+ Run commands from a file with `-f`:
103
+
104
+ ``` bash
105
+ chemql -f queries.chemql
106
+ ```
107
+
108
+ Check the installed version:
109
+
110
+ ``` bash
111
+ chemql --version
112
+ ```
113
+
114
+ A query file can contain multiple ChemQL commands, one per line. Use the
115
+ `//` comment marker for comments and a trailing backslash (`\`) to
116
+ continue a command onto the next line.
117
+
118
+ Example `queries.chemql`:
119
+
120
+ ``` text
121
+ // Find lighter molecules
122
+ search molecules molecular_weight < 20 return name formula molecular_weight
123
+
124
+ // Show a subset of the periodic table
125
+ search elements atomic_number > 10 and atomic_number < 20 sort atomic_number desc limit 5
126
+ ```
127
+
128
+ ## Query language
129
+
130
+ ### Data sources
131
+
132
+ ChemQL provides three main sources:
133
+
134
+ Source Contents
135
+ ------------- ----------------------------------------------
136
+ `elements` Periodic-table element data
137
+ `molecules` Molecule properties and identifiers
138
+ `reactions` Reaction equations, conditions, and metadata
139
+
140
+ Search a source explicitly:
141
+
142
+ ``` text
143
+ search elements
144
+ search molecules
145
+ search reactions
146
+ ```
147
+
148
+ You can also use `search all` before a source name, for example:
149
+
150
+ ``` text
151
+ search all elements atomic_mass < 100
152
+ ```
153
+
154
+ Change the active source in an interactive session with:
155
+
156
+ ``` text
157
+ source elements
158
+ source molecules
159
+ source reactions
160
+ ```
161
+
162
+ ### Filtering
163
+
164
+ Use comparison operators to filter records:
165
+
166
+ Operator Meaning
167
+ ---------- ----------------------------------------
168
+ `=` Equal
169
+ `!=` Not equal
170
+ `>` Greater than
171
+ `<` Less than
172
+ `>=` Greater than or equal
173
+ `<=` Less than or equal
174
+ `like` Case-insensitive wildcard match
175
+ `like!` Case-sensitive wildcard match
176
+ `likep` Python regular-expression match
177
+ `has` Check whether a value contains an item
178
+
179
+ Examples:
180
+
181
+ ``` text
182
+ search elements atomic_number > 10
183
+ search molecules molecular_weight <= 20
184
+ search molecules name like "*water*"
185
+ search reactions id likep ".*haber(\s*|-|_)process.*"
186
+ ```
187
+
188
+ The wildcard matcher supports `*` for a sequence of characters and other
189
+ wildcard tokens supported by ChemQL's pattern matcher. Use `likep` when
190
+ you need regular expressions rather than wildcard patterns.
191
+
192
+ ### Logical conditions and parentheses
193
+
194
+ Combine conditions with `and`, `or`, and `not`. Parentheses group
195
+ conditions. Comparison operators and parentheses can be written without
196
+ surrounding spaces.
197
+
198
+ ``` text
199
+ search elements name not like "*ium"
200
+ search elements name not like "*ium" and not atomic_mass < 50
201
+ search elements atomic_mass > 50 and (density<10 or boil<100)
202
+ ```
203
+
204
+ ### Combining query results
205
+
206
+ Use `union` to combine results and `intersection` to keep records
207
+ present in both result lists. Operations are evaluated from left to
208
+ right.
209
+
210
+ ``` text
211
+ search elements name not like "*ium" intersection search elements name like "*um"
212
+ ```
213
+
214
+ Use the Python API's query-object operators `|` and `&` for union and
215
+ intersection, respectively, when working with `ChemQLQuery` objects.
216
+
217
+ ### Sorting, limiting, counting, and returning fields
218
+
219
+ ``` text
220
+ search elements sort atomic_number
221
+ search molecules sort molecular_weight desc
222
+ search molecules limit 10
223
+ search molecules count
224
+ search molecules molecular_weight < 20 return name
225
+ search molecules molecular_weight < 20 return name formula molecular_weight
226
+ ```
227
+
228
+ - `sort <field> [asc|desc]` sorts results.
229
+ - `limit <number>` limits the number of results.
230
+ - `count` returns the number of matches.
231
+ - `return <field...>` returns only selected fields. One field produces
232
+ a list; multiple fields produce a table-like result.
233
+ - `first` and `last` can be used to select one result.
234
+
235
+ ### Find commands
236
+
237
+ ``` text
238
+ findel "He"
239
+ findel "Hydrogen"
240
+
241
+ findmol "H2O"
242
+ findmol "Water"
243
+
244
+ findre "Haber process"
245
+ findre "RHEA:10000" return name equation source
246
+ ```
247
+
248
+ `findmol` searches the local molecule dataset first and can use external
249
+ chemical-data services when a local match is not found. External lookups
250
+ require an internet connection and may be unavailable if the service is
251
+ down.
252
+
253
+ ## Reactions and equation balancing
254
+
255
+ ChemQL includes reaction data and commands for working with reaction
256
+ conditions.
257
+
258
+ ``` text
259
+ findre "Haber process"
260
+ balance O2 + H2 -> H2O
261
+ balance O2 + H2 <-> H2O
262
+ ```
263
+
264
+ The `->` arrow denotes an irreversible reaction, while `<->` denotes a
265
+ reversible reaction.
266
+
267
+ Set conditions before using `react`:
268
+
269
+ ``` text
270
+ set temperature 723K
271
+ set pressure 20265000pa
272
+ set catalysts iron zinc
273
+ conditions
274
+ react N2 3H2
275
+ ```
276
+
277
+ Temperature can be supplied in Celsius (`C`), Fahrenheit (`F`), or
278
+ Kelvin (`K`). Pressure supports units such as pascals and bar; the
279
+ available unit conversions depend on the installed version. Preset
280
+ conditions are also available:
281
+
282
+ ``` text
283
+ set temperature standard
284
+ set pressure room
285
+ ```
286
+
287
+ Use `help` in the terminal for the command reference included with your
288
+ installed version.
289
+
290
+ ## Python API
291
+
292
+ Import ChemQL from Python:
293
+
294
+ ``` python
295
+ import chemql
296
+
297
+ result = chemql.execute_query_text(
298
+ 'search elements name = "Hydrogen"'
299
+ )
300
+ print(result)
301
+ ```
302
+
303
+ You can also use `execute_query` for a query string:
304
+
305
+ ``` python
306
+ import chemql
307
+
308
+ result = chemql.execute_query('search molecules molecular_weight < 20')
309
+ print(result)
310
+ ```
311
+
312
+ The package exposes chemistry data classes and helpers, including
313
+ `Element`, `Molecule`, `Reaction`, `ChemQLError`, `Unknown`,
314
+ `ReturnTable`, and `balance_stoichiometry`.
315
+
316
+ ### Query builder API
317
+
318
+ Versions that include the query-builder API also support chaining query
319
+ conditions:
320
+
321
+ ``` python
322
+ import chemql
323
+
324
+ x = chemql.search("elements")
325
+ y = x.atomic_mass.condition(lt=10)
326
+ z = y.return_("name")
327
+
328
+ print(z) # The query as text
329
+ print(z.execute()) # Execute the query
330
+ ```
331
+
332
+ Query objects can be combined with `|` (union) and `&` (intersection).
333
+ The convenience functions `chemql.union(x, y)` and
334
+ `chemql.intersection(x, y)` are also available in versions that include
335
+ this API.
336
+
337
+ ## Hybrid Python
338
+
339
+ ChemQL can execute Python expressions inside square brackets:
340
+
341
+ ``` text
342
+ [x = 10]
343
+ [print(x)]
344
+ ```
345
+
346
+ It also supports Python control blocks using `[for ...]`, `[if ...]`,
347
+ `[elif ...]`, `[else]`, `[while ...]`, `[break]`, `[continue]`, and
348
+ `[endblock]`.
349
+
350
+ Use `{{ ... }}` to evaluate a ChemQL query and insert its result into
351
+ Python:
352
+
353
+ ``` text
354
+ [print({{ search elements atomic_number = 1 }})]
355
+ ```
356
+
357
+ Only run Python code and shell commands from sources you trust.
358
+
359
+ ## Shell Commands
360
+
361
+ ChemQL supports executing system shell commands by enclosing them in backticks (`` ` ``). Commands execute in a **persistent shell session**, allowing shell state to be preserved between commands.
362
+
363
+ **Syntax**
364
+
365
+ ```chemql
366
+ `command`
367
+ ```
368
+
369
+ **Examples**
370
+
371
+ Execute system commands:
372
+
373
+ ```chemql
374
+ `whoami`
375
+ `dir`
376
+ `echo Hello`
377
+ ```
378
+
379
+ Change the working directory:
380
+
381
+ ```chemql
382
+ `cd ..`
383
+ `cd ~`
384
+ `dir`
385
+ ```
386
+
387
+ The working directory persists between commands.
388
+
389
+ Environment variables and other shell state can also persist between commands, depending on the shell being used.
390
+
391
+ **Platform support**
392
+
393
+ - **Linux:** Bash
394
+ - **macOS:** Bash
395
+ - **Windows:** Command Prompt (`cmd.exe`)
396
+
397
+ PowerShell is not supported by the current implementation.
398
+
399
+ **How it works**
400
+
401
+ ChemQL maintains a persistent shell process and sends commands to it sequentially. Command output is captured and displayed in the ChemQL interface, allowing shell state to persist throughout the session.
402
+
403
+ **Notes**
404
+
405
+ - Commands must be enclosed in backticks to be interpreted as shell commands rather than ChemQL statements.
406
+ - Shell syntax differs between operating systems. Use commands appropriate for your platform.
407
+ - Commands run with the permissions of the process running ChemQL and may modify files or affect your system.
408
+ - Interactive terminal programs and commands requiring direct terminal input may not work correctly because the shell uses pipes rather than a real terminal.
409
+
410
+ ## Data and external services
411
+
412
+ ChemQL loads bundled JSON datasets for elements, molecules, reactions,
413
+ molecule bonds, and bond energies. Some molecule lookups may query
414
+ PubChem or other external sources when the local dataset does not
415
+ contain a match.
416
+
417
+ The periodic-table dataset is based on PeriodicTableJSON by
418
+ Bowserinator. Review the dataset's accompanying license and attribution
419
+ requirements when redistributing it or derivative data. The licenses and
420
+ sources for the other bundled datasets should be checked in their
421
+ respective files before redistribution.
422
+
423
+ ## Safety note
424
+
425
+ ChemQL's hybrid Python functionality can execute Python code. If your
426
+ installed version supports backtick-wrapped shell commands, those can
427
+ execute operating-system commands as well. Do not run untrusted ChemQL
428
+ scripts or queries.
429
+
430
+ ## Development notes
431
+
432
+ - The interactive shell uses `prompt_toolkit`.
433
+ - The command-line interface supports single-command execution (`-c`)
434
+ and file execution (`-f`).
435
+ - Consult the package's source and included `help` output for the
436
+ exact commands and fields supported by your installed version.
437
+
438
+ ## License
439
+
440
+ [MIT License](https://github.com/rakibulofficial1017/ChemQL/blob/main/LICENSE)
441
+
442
+ Created by [Mohammad Rakibul Islam](https://github.com/rakibulofficial1017).
443
+ Source code: [rakibulofficial1017/ChemQL](https://github.com/rakibulofficial1017/ChemQL).