chemql-python 1.6.6__tar.gz → 1.6.8__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 (48) hide show
  1. chemql_python-1.6.8/PKG-INFO +943 -0
  2. chemql_python-1.6.8/README.md +929 -0
  3. {chemql_python-1.6.6 → chemql_python-1.6.8}/pyproject.toml +3 -1
  4. {chemql_python-1.6.6 → chemql_python-1.6.8}/src/chemql/__init__.py +171 -25
  5. {chemql_python-1.6.6 → chemql_python-1.6.8}/src/chemql/codecql.py +126 -23
  6. chemql_python-1.6.8/src/chemql/codecql_gui_core.py +870 -0
  7. chemql_python-1.6.8/src/chemql/codecqlx.py +1541 -0
  8. chemql_python-1.6.8/src/chemql/highlighting.json +950 -0
  9. chemql_python-1.6.8/src/chemql_python.egg-info/PKG-INFO +943 -0
  10. {chemql_python-1.6.6 → chemql_python-1.6.8}/src/chemql_python.egg-info/SOURCES.txt +3 -0
  11. {chemql_python-1.6.6 → chemql_python-1.6.8}/src/chemql_python.egg-info/entry_points.txt +1 -0
  12. {chemql_python-1.6.6 → chemql_python-1.6.8}/tests/test_structured_types.py +82 -0
  13. chemql_python-1.6.6/PKG-INFO +0 -677
  14. chemql_python-1.6.6/README.md +0 -663
  15. chemql_python-1.6.6/src/chemql_python.egg-info/PKG-INFO +0 -677
  16. {chemql_python-1.6.6 → chemql_python-1.6.8}/LICENSE +0 -0
  17. {chemql_python-1.6.6 → chemql_python-1.6.8}/setup.cfg +0 -0
  18. {chemql_python-1.6.6 → chemql_python-1.6.8}/src/chemql/__main__.py +0 -0
  19. {chemql_python-1.6.6 → chemql_python-1.6.8}/src/chemql/build.py +0 -0
  20. {chemql_python-1.6.6 → chemql_python-1.6.8}/src/chemql/colors.json +0 -0
  21. {chemql_python-1.6.6 → chemql_python-1.6.8}/src/chemql/data/BondEnergies.json +0 -0
  22. {chemql_python-1.6.6 → chemql_python-1.6.8}/src/chemql/data/MoleculeBonds.json +0 -0
  23. {chemql_python-1.6.6 → chemql_python-1.6.8}/src/chemql/data/Molecules.json +0 -0
  24. {chemql_python-1.6.6 → chemql_python-1.6.8}/src/chemql/data/PeriodicTableJSON.json +0 -0
  25. {chemql_python-1.6.6 → chemql_python-1.6.8}/src/chemql/data/Reactions.json +0 -0
  26. {chemql_python-1.6.6 → chemql_python-1.6.8}/src/chemql/data/THIRD_PARTY_LICENSES/PeriodicTableJSON.txt +0 -0
  27. {chemql_python-1.6.6 → chemql_python-1.6.8}/src/chemql/data/THIRD_PARTY_LICENSES/RHEA.txt +0 -0
  28. {chemql_python-1.6.6 → chemql_python-1.6.8}/src/chemql/highlighting.py +0 -0
  29. {chemql_python-1.6.6 → chemql_python-1.6.8}/src/chemql/html/periodic_table.html +0 -0
  30. {chemql_python-1.6.6 → chemql_python-1.6.8}/src/chemql/stdlib/README.md +0 -0
  31. {chemql_python-1.6.6 → chemql_python-1.6.8}/src/chemql/stdlib/collections.cql +0 -0
  32. {chemql_python-1.6.6 → chemql_python-1.6.8}/src/chemql/stdlib/datetime.cql +0 -0
  33. {chemql_python-1.6.6 → chemql_python-1.6.8}/src/chemql/stdlib/decimal.cql +0 -0
  34. {chemql_python-1.6.6 → chemql_python-1.6.8}/src/chemql/stdlib/fractions.cql +0 -0
  35. {chemql_python-1.6.6 → chemql_python-1.6.8}/src/chemql/stdlib/json.cql +0 -0
  36. {chemql_python-1.6.6 → chemql_python-1.6.8}/src/chemql/stdlib/math/statistics.cql +0 -0
  37. {chemql_python-1.6.6 → chemql_python-1.6.8}/src/chemql/stdlib/math.cql +0 -0
  38. {chemql_python-1.6.6 → chemql_python-1.6.8}/src/chemql/stdlib/pathlib.cql +0 -0
  39. {chemql_python-1.6.6 → chemql_python-1.6.8}/src/chemql/stdlib/random.cql +0 -0
  40. {chemql_python-1.6.6 → chemql_python-1.6.8}/src/chemql/stdlib/text.cql +0 -0
  41. {chemql_python-1.6.6 → chemql_python-1.6.8}/src/chemql_python.egg-info/dependency_links.txt +0 -0
  42. {chemql_python-1.6.6 → chemql_python-1.6.8}/src/chemql_python.egg-info/requires.txt +0 -0
  43. {chemql_python-1.6.6 → chemql_python-1.6.8}/src/chemql_python.egg-info/top_level.txt +0 -0
  44. {chemql_python-1.6.6 → chemql_python-1.6.8}/tests/test_codecql.py +0 -0
  45. {chemql_python-1.6.6 → chemql_python-1.6.8}/tests/test_external_molecule_lookup.py +0 -0
  46. {chemql_python-1.6.6 → chemql_python-1.6.8}/tests/test_public_api.py +0 -0
  47. {chemql_python-1.6.6 → chemql_python-1.6.8}/tests/test_reactions.py +0 -0
  48. {chemql_python-1.6.6 → chemql_python-1.6.8}/tests/test_stdlib.py +0 -0
@@ -0,0 +1,943 @@
1
+ Metadata-Version: 2.4
2
+ Name: chemql-python
3
+ Version: 1.6.8
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
+ Requires-Dist: rich>=13.7
11
+ Provides-Extra: test
12
+ Requires-Dist: pytest>=8.0; extra == "test"
13
+ Dynamic: license-file
14
+
15
+ # ChemQL & CodecQL
16
+
17
+ > A Python-embedded query language and terminal toolchain for chemistry data — with a purpose-built editor, package manager, and standard library.
18
+
19
+ ChemQL is a small language for querying, computing with, and simulating chemistry data (elements, molecules, reactions), layered on a Python runtime. It ships with an interactive REPL, a terminal editor (CodecQL), a desktop editor (CodecQLX), a type system (structs, records, enums), namespaces, modules, a macro/preprocessor system, a package manager, and a standard library.
20
+
21
+ - **Distribution name:** `chemql-python`
22
+ - **Import / CLI name:** `chemql`
23
+ - **Language version:** `1.6.8` (per `chemql.__version__`)
24
+ - **Editor version:** `codecql 0.1.1`
25
+ - **GUI Editor version:** `CodecQLX 1.0.0`
26
+ - **Python import / CLI name:** `chemql`
27
+ - **Author:** Mohammad Rakibul Islam
28
+ - **Minimum Python:** **3.12+** (verified with `vermin`)
29
+ - **Registry:** `https://chemqlreg.pythonanywhere.com/`
30
+
31
+ > ⚠️ **Safety:** ChemQL executes embedded Python (`[ ... ]`, `[[[ ... ]]]`) and real shell commands (`` ` ... ` ``, ` ``` ` blocks) with the permissions of the running process. Only run code and packages you trust.
32
+
33
+ ---
34
+
35
+ ## Install
36
+
37
+ ```bash
38
+ pip install chemql-python
39
+ ```
40
+
41
+ Verify:
42
+
43
+ ```bash
44
+ chemql --version
45
+ ```
46
+
47
+ Python **3.12+** is required. The project's minimum version is checked with [`vermin`](https://github.com/netromdk/vermin).
48
+
49
+ ---
50
+
51
+ ## Quick start
52
+
53
+ ```text
54
+ $ chemql
55
+ Type help or ? for help
56
+ >>> search elements name like "Hydrogen"
57
+ H (Hydrogen)
58
+ >>> search molecules molecular_weight < 20 sort molecular_weight
59
+ H₂ (Hydrogen)
60
+ >>> balance H2 + O2 -> H2O
61
+ 2 H₂ + O₂ → 2 H₂O
62
+ >>> let water = {{ findmol "Water" }}
63
+ >>> water.smiles
64
+ O
65
+ >>> findmol "caffeine" return name formula molecular_weight
66
+ ```
67
+
68
+ Non-interactive:
69
+
70
+ ```bash
71
+ chemql -c 'search elements symbol = "Fe" return name symbol number'
72
+ chemql -f script.cql
73
+ chemql -f script.cql -o out.txt # ANSI-stripped output to a file
74
+ chemql --no-ansi
75
+ chemql --suppress-warnings
76
+ ```
77
+
78
+ Open a file in the bundled editor:
79
+
80
+ ```bash
81
+ chemql edit script.cql
82
+ ```
83
+
84
+ ---
85
+
86
+ ## Core commands
87
+
88
+ | Command | Purpose |
89
+ |---|---|
90
+ | `search [first\|last\|all] <source> <conditions> [ops] [return fields]` | Query a data source |
91
+ | `source <elements\|molecules\|reactions>` | Set the default source |
92
+ | `findel <name-or-symbol> [return …]` | Element lookup |
93
+ | `findmol <name-or-formula> [return …]` | Molecule lookup (local → PubChem → ChemSpider → NIST) |
94
+ | `findre <name-or-id> [return …]` | Reaction lookup (local → Rhea → Chempirical) |
95
+ | `balance <reactants> ->\|<-> <products>` | Balance a chemical equation |
96
+ | `react <coefficients><molecules…>` | Match a stored reaction under current conditions |
97
+ | `set temperature\|pressure\|catalysts <value>` | Set reaction conditions |
98
+ | `add\|remove catalyst "<name>"` | Modify the catalyst list |
99
+ | `conditions` | Show current T / P / catalysts |
100
+ | `let <name> = <expr>` / `unset <name>` / `variables` | Bind, remove, list variables |
101
+ | `define NAME <value>` / `@NAME` | Object-like macro |
102
+ | `define NAME{} … enddefine` / `@NAME{…}` | Function-like macro |
103
+ | `definitions` / `macros` / `remove definition\|macro NAME` | Inspect / remove |
104
+ | `func NAME … endfunc` | Define a function |
105
+ | `static func Type.method … endfunc` | Static method |
106
+ | `struct` / `record` / `enum` … `end*` | Define types |
107
+ | `namespace NAME … endnamespace` | Group declarations with visibility |
108
+ | `load <pkg> [as <alias>]` / `load <member> from <pkg> [as <alias>]` | Load packages |
109
+ | `help [topic]` / `?` | Help |
110
+ | `dump [all\|good\|bad] [queries\|results] FILE` | Export execution history |
111
+ | `view` | Open the periodic-table viewer in a browser |
112
+ | `clear` / `version` / `exit` | Misc |
113
+
114
+ ---
115
+
116
+ ## Query syntax
117
+
118
+ **Sources:** `elements`, `molecules`, `reactions`.
119
+
120
+ **Operators:**
121
+
122
+ | Operator | Meaning |
123
+ |---|---|
124
+ | `=` `!=` `>` `<` `>=` `<=` | Comparison (type-converted against the field) |
125
+ | `like` | Case-insensitive wildcard match |
126
+ | `like!` | Case-sensitive wildcard match |
127
+ | `likep` | Regex match |
128
+ | `has` | Nested containment (exact for `molecule` fields) |
129
+ | `and` `or` `not` `( )` | Boolean logic |
130
+
131
+ **`like` wildcard language** (not SQL):
132
+
133
+ | Token | Matches |
134
+ |---|---|
135
+ | `*` | Any characters |
136
+ | `%` | Digits only |
137
+ | `&` | Letters only |
138
+ | `_` | Any single character |
139
+ | `#` | A single digit |
140
+ | `?` | A single letter |
141
+ | `\` | Escape |
142
+
143
+ **Result operations:** `sort FIELD [asc|desc]`, `limit N`, `count`, `return FIELD …`, and set ops `union` / `intersection`.
144
+
145
+ Examples:
146
+
147
+ ```chemql
148
+ search elements number > 10 and number < 20 return name symbol
149
+ search molecules molecular_weight < 50 sort molecular_weight limit 10
150
+ search reactions reversible = true return name equation source
151
+ search elements name like "H*"
152
+ ```
153
+
154
+ ---
155
+
156
+ ## Chemistry features
157
+
158
+ ### Data
159
+
160
+ Bundled JSON under `chemql/data/`:
161
+
162
+ | File | Purpose |
163
+ |---|---|
164
+ | `PeriodicTableJSON.json` | Element metadata (number, symbol, mass, category, phase, …) |
165
+ | `Molecules.json` | Molecule records: formula, IUPAC name, SMILES, CID, mp/bp/density/state |
166
+ | `Reactions.json` | Curated reactions, plus Rhea imports (see provenance) |
167
+ | `MoleculeBonds.json` | Bond connectivity per molecule |
168
+ | `BondEnergies.json` | Bond energy table used for ΔH estimates |
169
+
170
+ Reference conditions are °C at 1 atm (mp/bp), g/cm³ at 25 °C (density), and `state` at 25 °C / 1 atm.
171
+
172
+ ### External lookups
173
+
174
+ `findmol` and `findre` fall back to public APIs when local data misses:
175
+
176
+ - **Molecules:** PubChem → ChemSpider (needs `CHEMSPIDER_API_KEY`) → NIST WebBook
177
+ - **Reactions:** Rhea → Chempirical
178
+
179
+ `search` itself stays **local** (offline-safe).
180
+
181
+ ### Balancing
182
+
183
+ `balance` builds an element × species matrix and solves it with exact `Fraction` Gaussian elimination, returning smallest-integer coefficients. It fails clearly when the balance is not unique.
184
+
185
+ ### Reaction simulation
186
+
187
+ `react` matches the supplied reactants (forward, or reverse for reversible reactions) against `REACTIONS`, gated by current conditions:
188
+
189
+ - Temperature tolerance: **±5 K**
190
+ - Pressure tolerance: **±5 %**
191
+ - Catalysts: required set must be a **subset** of available
192
+
193
+ ### Chemistry built-ins
194
+
195
+ | Built-in | Description |
196
+ |---|---|
197
+ | `element{symbol, field?}` | Periodic-table lookup |
198
+ | `count_atoms{formula, symbol}` | Atoms of one element in a formula (handles nested parentheses) |
199
+ | `molar_mass{formula}` | Molar mass |
200
+ | `empirical_formula{formula}` | Reduced formula |
201
+
202
+ ---
203
+
204
+ ## Type system
205
+
206
+ ### Structs — mutable, methods, inheritance
207
+
208
+ ```chemql
209
+ struct Fruit
210
+ name!
211
+ weight = 1.0
212
+ endstruct
213
+
214
+ struct Apple from Fruit
215
+ appletype
216
+ endstruct
217
+
218
+ func Fruit.talk
219
+ if this.weight is not None
220
+ return "I am a " + this.name
221
+ endif
222
+ return "I am a " + this.name
223
+ endfunc
224
+ ```
225
+
226
+ - `name!` or `required name` — required field
227
+ - `name = value` — optional with default (`None` if omitted)
228
+ - `required` / `!` **cannot** be combined with `=` (rejected at `endstruct`)
229
+ - Field ordering is normalized automatically
230
+ - Subclass field redeclaration overrides or strips the default
231
+ - `func Type.method` — instance method (`this`); `static func` — static
232
+ - Structs can inherit from **structs, records, or Python classes**
233
+
234
+ ### Records — immutable, positional, trailing defaults
235
+
236
+ ```chemql
237
+ record Point
238
+ x
239
+ y
240
+ z = 0
241
+ endrecord
242
+ ```
243
+
244
+ - Every field is required unless it has a default
245
+ - Defaulted fields must be **trailing** (rejected otherwise)
246
+ - Instances are **immutable** (`can't set attribute`)
247
+ - Elementwise operator overloading (`+ - * / // % **`, unary `-`, `abs`)
248
+ - Records inherit **only** from records
249
+ - No in-language methods (hybrid-Python only)
250
+
251
+ ### Enums — named singletons with payloads
252
+
253
+ ```chemql
254
+ enum Level
255
+ low = 25
256
+ mid = 50
257
+ high = 75
258
+ endenum
259
+ ```
260
+
261
+ - Auto-numbering starts at `1` when `=` is omitted
262
+ - `Level::low::value` → `25`; `Level::low::name` → `"low"`
263
+ - Equality is **identity-based** (`Level::low == 25` is `False`)
264
+ - Members cannot be reassigned
265
+ - Enums inherit from enums; **no methods**
266
+
267
+ ### Summary
268
+
269
+ | | mutable | defaults | methods | inheritance |
270
+ |---|---|---|---|---|
271
+ | **struct** | yes | required / optional / defaulted | yes (incl. static) | structs, records, Python classes |
272
+ | **record** | no | trailing only | no (hybrid only) | records only |
273
+ | **enum** | no | auto-increment | no | enums only |
274
+
275
+ ---
276
+
277
+ ## Namespaces & visibility
278
+
279
+ ```chemql
280
+ namespace foo
281
+ public let x = 10
282
+ private let y = 20
283
+ let z = 30 // private by default
284
+ endnamespace
285
+ ```
286
+
287
+ - **Default visibility is private** for namespace members
288
+ - `public` / `private` applies to `let`, `func`, `struct`, `record`, `enum`, `namespace`
289
+ - Reading a private member raises an error mentioning it is set to private
290
+ - Code inside the namespace can access its own private members
291
+ - Missing members produce a distinct "no attribute" error
292
+
293
+ ---
294
+
295
+ ## Modules
296
+
297
+ `.cql` files can be loaded as packages:
298
+
299
+ ```chemql
300
+ // foo.cql
301
+ public func isEven
302
+ return \1 % 2 == 0
303
+ endfunc
304
+ ```
305
+
306
+ ```chemql
307
+ // bar.cql
308
+ load foo
309
+ foo::isEven{3}
310
+
311
+ load isEven from foo
312
+ isEven{4}
313
+ ```
314
+
315
+ - `load pkg` → `pkg::name` access; only `public` members
316
+ - `load member from pkg [as alias]` → import one member
317
+ - Cross-module private access raises `PermissionError`
318
+ - Packages live in `./`, `~/.chemql/packages/<name>/<version>/`, or `chemql/stdlib/`
319
+ - Override root with `CHEMQL_PACKAGE_DIR`
320
+
321
+ ---
322
+
323
+ ## Functions, arguments, macros
324
+
325
+ ```chemql
326
+ func square
327
+ return \1 * \1
328
+ endfunc
329
+ ```
330
+
331
+ **Two access forms:**
332
+
333
+ - `\1`, `\2`, … — 1-indexed positional placeholders, **substituted textually** (works inside strings; `\10` = tenth argument, greedy `\d+`)
334
+ - `arguments` — a per-call `list` of positional arguments, `arguments[0]` indexed from 0, **function scope only**
335
+
336
+ > ⚠️ `arguments` is not available in macro bodies — macros get `\N` only.
337
+
338
+ ### Definitions (object-like)
339
+
340
+ ```chemql
341
+ define MAX 9
342
+ @MAX * 9 // 81
343
+ print("2@MAX") // "29"
344
+ ```
345
+
346
+ - `@NAME` expands textually, including inside strings
347
+ - One name slot shared with macros; **definitions win** on collision
348
+ - `remove definition NAME` (or `remove definition @NAME`)
349
+
350
+ ### Macros (function-like)
351
+
352
+ ```chemql
353
+ define MAX{}
354
+ \1 if \1 > \2 else \2
355
+ enddefine
356
+
357
+ @MAX{1, 3} // 3
358
+ ```
359
+
360
+ - Body uses `\N`; `arguments` is **not** available
361
+ - Macros may expand other macros (multi-pass)
362
+ - `remove macro NAME`
363
+
364
+ > **Gotcha:** defining `NAME{}` while `NAME = value` exists makes the macro unreachable until `remove definition NAME`.
365
+
366
+ ---
367
+
368
+ ## Control flow
369
+
370
+ ```chemql
371
+ if x > 10
372
+ let y = "big"
373
+ elif x > 5
374
+ let y = "medium"
375
+ else
376
+ let y = "small"
377
+ endif
378
+
379
+ for i in range(3)
380
+ print(i)
381
+ endfor
382
+
383
+ while i < 5
384
+ let i = i + 1
385
+ endwhile
386
+ ```
387
+
388
+ - `break` / `continue` / `skip` (alias for continue)
389
+ - Bracketed Python-style blocks also accepted: `[for …] … [endblock]`
390
+
391
+ ---
392
+
393
+ ## Error handling
394
+
395
+ ```chemql
396
+ risk
397
+ signal "Something went wrong"
398
+ fix
399
+ let handled = error
400
+ cleanup
401
+ let finished = true
402
+ endrisk
403
+ ```
404
+
405
+ - `signal "msg"` raises a recoverable ChemQL signal
406
+ - `warn "msg"` sets `warnings` and prints (suppress with `--suppress-warnings`)
407
+ - `error` holds the last error type (or `None` after success)
408
+
409
+ ---
410
+
411
+ ## Python integration
412
+
413
+ Inline expression:
414
+
415
+ ```chemql
416
+ [1 + 2 * 3] // 7
417
+ [x * 2]
418
+ ```
419
+
420
+ Multiline Python block:
421
+
422
+ ```chemql
423
+ [[[
424
+ for x in range(3):
425
+ print(x)
426
+ ]]]
427
+ ```
428
+
429
+ Embedded queries inside Python:
430
+
431
+ ```chemql
432
+ let m = [len({{ search molecules molecular_weight < 20 }})]
433
+ ```
434
+
435
+ Attribute access, `{{ }}` queries, and `::` namespace paths are rewritten before evaluation.
436
+
437
+ > **Safety reminder:** all of the above runs with your user's permissions.
438
+
439
+ ---
440
+
441
+ ## Shell integration
442
+
443
+ Inline:
444
+
445
+ ```chemql
446
+ `ls -la`
447
+ ```
448
+
449
+ Multiline:
450
+
451
+ ````
452
+ ```bash
453
+ cd /tmp
454
+ ls
455
+ ```
456
+ ````
457
+
458
+ - **POSIX:** persistent Bash via a PTY with a unique prompt handshake
459
+ - **Windows:** persistent PowerShell request/marker loop
460
+ - `clear` / `cls` bypass the shell
461
+
462
+ ---
463
+
464
+ ## CodecQL — the terminal editor
465
+
466
+ **A small terminal editor built for ChemQL.** Syntax highlighting, inline suggestions, a built-in terminal pane, and one-key execution — nothing to configure to get started.
467
+
468
+ | | |
469
+ |---|---|
470
+ | Version | 0.1.1 |
471
+ | Ships with | `chemql-python` |
472
+ | Files | `.cql` (ChemQL), `.py`, `cqlpackage.json` / `cqlpackage.toml`, and any plain-text file |
473
+
474
+ ### Starting CodecQL
475
+
476
+ ```bash
477
+ chemql edit FILE # open (or create) a file
478
+ python -m chemql.codecql FILE # equivalent
479
+ chemql edit --main-highlighting # edit the highlighting.json shipped with the package
480
+ chemql edit --local-highlighting # edit ./highlighting.json (created as {} if missing)
481
+ chemql edit --version
482
+ ```
483
+
484
+ If your installation also registers a `codecql` console script, `codecql FILE` accepts the same options.
485
+
486
+ Opening a path that does not exist starts an empty buffer; it is created on the first save.
487
+
488
+ **Requirements:** the same as ChemQL (Python 3.12+), plus a terminal that understands ANSI escape sequences and 256 colours. On Windows, `colorama` is used when installed; otherwise virtual-terminal mode is enabled directly. Copying to the system clipboard needs one of `clip` (Windows), `clip.exe` (WSL), `pbcopy` (macOS), or `wl-copy` / `xclip` / `xsel` (Linux).
489
+
490
+ ### Key bindings
491
+
492
+ | Key | Action |
493
+ |---|---|
494
+ | `Ctrl+S` | Save |
495
+ | `Ctrl+Q` | Quit. With unsaved changes, press it a second time to quit without saving |
496
+ | `Ctrl+Z` / `Ctrl+Y` | Undo / redo (last 200 edits) |
497
+ | `Ctrl+F` | Search |
498
+ | `Ctrl+R` | Save, then run the file |
499
+ | `Ctrl+T` | Open a terminal pane |
500
+ | `Tab` | Accept the inline suggestion; with none showing, insert a tab |
501
+ | `Enter` | New line, keeping the current indentation |
502
+ | Arrow keys, `Home`, `End` | Move |
503
+ | `Shift` + movement | Select |
504
+ | `Ctrl`/`Alt` + `←` `→` | Move by word |
505
+ | `Ctrl` + `↑` `↓` | Scroll the view without moving the text |
506
+ | `Backspace`, `Delete` | Delete a character, or the selection |
507
+ | `Ctrl+Backspace` / `Alt+Backspace` | Delete the word to the left |
508
+ | `Ctrl+Delete` / `Alt+Delete` | Delete the word to the right |
509
+ | `Ctrl+C` / `Ctrl+Insert` | Copy the selection (editor + system clipboard when available). It does **not** quit |
510
+ | `Ctrl+X` | Cut the selection |
511
+ | `Ctrl+V` / `Shift+Insert` | Paste the editor's clipboard |
512
+
513
+ Pasting from your terminal or OS clipboard also works: CodecQL enables bracketed paste, so multi-line pastes arrive as a single insertion.
514
+
515
+ **Auto-indent.** After a line that opens a block (`func`, `define NAME{}`, `struct`, `record`, `enum`, `namespace`, `if`, `elif`, `else`, `for`, `while`) or ends in a `\` continuation, the next line is indented with a tab. Pressing Enter after `endnamespace` removes one level of indentation. Other `end...` keywords do not dedent automatically.
516
+
517
+ **Status bar and footer.** The bar shows the file name, `Ln`/`Col`, the line count, `Unsaved` when the buffer is dirty, and search status. The footer shows messages and a reminder of the main shortcuts.
518
+
519
+ ### Search
520
+
521
+ Press `Ctrl+F` and type; matches are highlighted as you type.
522
+
523
+ | Key | Action |
524
+ |---|---|
525
+ | `Enter`, `↓`, `→` | Next match |
526
+ | `↑`, `←` | Previous match |
527
+ | `Esc`, `Ctrl+C` | Close search |
528
+
529
+ A plain query is a **literal, case-insensitive** search. Add a flag prefix followed by `:` to change that:
530
+
531
+ | Flag | Meaning |
532
+ |---|---|
533
+ | `r` | Treat the query as a regular expression |
534
+ | `l` | Treat the query as literal text (the default; cannot be combined with `r`) |
535
+ | `w` | Match whole words only |
536
+ | `i` | Ignore case |
537
+
538
+ Once any flag is given, matching becomes case-sensitive unless `i` is included.
539
+
540
+ ```text
541
+ water literal, case-insensitive
542
+ l:Water literal, case-sensitive
543
+ r:^search\s regular expression, case-sensitive
544
+ ri:^search\s regular expression, case-insensitive
545
+ wi:set whole word "set", case-insensitive
546
+ ```
547
+
548
+ An invalid regular expression is reported in the status bar.
549
+
550
+ ### Running code and the terminal pane
551
+
552
+ **`Ctrl+R`** saves the file (if it has unsaved changes) and runs the command configured for its extension. The default for `.cql` is:
553
+
554
+ ```text
555
+ chemql -f $absoluteName
556
+ ```
557
+
558
+ `$absoluteName` is replaced by the shell-quoted absolute path. Set your own with `run-command` in `highlighting.json`; the bundled configuration also runs `.py` files with `python -u` and `.rs` files with `cargo run`. The file must have a name before it can be run.
559
+
560
+ **`Ctrl+T`** opens a plain terminal without running anything.
561
+
562
+ | Platform | Behaviour |
563
+ |---|---|
564
+ | Linux, macOS, WSL | A pane opens in the bottom third of the screen running your `$SHELL` (`-i`). `Ctrl+↑` / `Ctrl+↓` resize it. `Ctrl+T`, `Ctrl+Q` or `Esc` closes it and returns to the editor. |
565
+ | Windows Terminal | The command runs in a new split pane beside the editor. Close it by exiting the shell. |
566
+ | Other Windows consoles | The command runs in a separate console window. |
567
+
568
+ ### Syntax highlighting
569
+
570
+ What is coloured depends on the file:
571
+
572
+ | File | Highlighting |
573
+ |---|---|
574
+ | `.cql` | Comments (`//`, `#`), strings, numbers (including units such as `25C`, `1atm`), chemical formulas (`H2O`, `NaCl`), operators, delimiters (`{{ }}`, `[[[ ]]]`, brackets), commands, control keywords, word operators (`and`, `like`, `sort`, ...), sources, reaction conditions, field names, Python built-ins, `True`/`False`/`None`, and the name after `enum`/`struct`/`record`/`namespace` |
575
+ | `.py` | Python keywords, built-ins and constants, plus comments, strings, numbers and operators |
576
+ | `cqlpackage.json`, `cqlpackage.toml` | Keys, strings, numbers, booleans, TOML tables and comments |
577
+ | anything else | Comments, strings, numbers, operators and delimiters only |
578
+
579
+ Highlighting is purely lexical and line-based: it never changes the file. Extensions are matched case-insensitively.
580
+
581
+ ### Inline suggestions
582
+
583
+ While you type at the **end of a line**, CodecQL shows a grey "ghost" completion. Press `Tab` to accept it. Suggestions are context-aware: they depend on what comes before the cursor on the line (and, for queries, on the most recent `source` command above it).
584
+
585
+ ```text
586
+ se| -> search
587
+ search | -> search elements
588
+ search elements na| -> search elements name
589
+ search elements atomic_mass | -> search elements atomic_mass >
590
+ search elements phase = | -> search elements phase = "Gas"
591
+ ```
592
+
593
+ Suggestions are driven entirely by the `suggestions` rules in `highlighting.json`, so you can change or extend them without touching Python. They are only offered when the cursor is at the end of the line and nothing is selected.
594
+
595
+ ### Configuration: `highlighting.json`
596
+
597
+ CodecQL loads configuration from two places, in this order:
598
+
599
+ 1. `highlighting.json` in the package directory (`chemql edit --main-highlighting` opens it)
600
+ 2. `highlighting.json` in the current working directory (`chemql edit --local-highlighting` opens it)
601
+
602
+ > **Each extension's profile is replaced as a whole.** If the local file defines `".cql"`, it completely replaces the main file's `.cql` profile, including its `run-command` and `suggestions`. Copy what you want to keep.
603
+
604
+ #### Profile format
605
+
606
+ The top level maps file extensions to profiles. A leading dot is added if you omit it, and extensions are lower-cased.
607
+
608
+ ```json
609
+ {
610
+ ".cql": {
611
+ "run-command": "chemql -f $absoluteName",
612
+ "rules": [],
613
+ "suggestions": []
614
+ },
615
+ ".py": {
616
+ "run-command": "python -u $absoluteName",
617
+ "rules": []
618
+ }
619
+ }
620
+ ```
621
+
622
+ | Field | Description |
623
+ |---|---|
624
+ | `run-command` | Command run by `Ctrl+R`. `$absoluteName` is replaced by the quoted path. |
625
+ | `rules` | Highlighting rules (below). |
626
+ | `suggestions` | Suggestion rules (below). |
627
+
628
+ An older format, where an extension maps directly to a list of rules, is still accepted. Unknown profile fields and duplicate extensions are rejected, and a configuration error is reported when the file is loaded.
629
+
630
+ #### Highlighting rules
631
+
632
+ ```json
633
+ {
634
+ "name": "my-keywords",
635
+ "type": "keywords",
636
+ "values": ["alpha", "beta"],
637
+ "style": "keyword"
638
+ }
639
+ ```
640
+
641
+ | Field | Description |
642
+ |---|---|
643
+ | `name` | Non-empty label |
644
+ | `type` | `keywords` or `regex` |
645
+ | `values` | For `keywords`: a non-empty list of words. Matching is case-insensitive |
646
+ | `pattern`, `case_sensitive` | For `regex`: a valid regular expression, and whether it is case-sensitive (default `true`) |
647
+ | `style` | A style string, below |
648
+
649
+ Rules are checked in order and the first matching keyword wins. A keyword rule takes priority over CodecQL's built-in categories for that extension, so with an empty `rules` list for `.cql` the built-in ChemQL highlighting applies unchanged.
650
+
651
+ > ⚠️ Currently only `keywords` rules affect how text is drawn. `regex` rules are validated but **not yet applied**.
652
+
653
+ **Style strings** combine space-separated parts:
654
+
655
+ | Part | Effect |
656
+ |---|---|
657
+ | `keyword` `command` `operator` `string` `comment` `number` `constant` `type` `source` `condition` `property` `builtin` | A colour from the current theme |
658
+ | `bold` `dim` `italic` `underline` `reverse` `strike` | Text attributes |
659
+ | `#rrggbb` | 24-bit foreground colour |
660
+ | `bg:#rrggbb` | 24-bit background colour |
661
+
662
+ ```json
663
+ "style": "bold #ff8800"
664
+ ```
665
+
666
+ An unknown part is an error, so stick to this list.
667
+
668
+ #### Example: highlighting a new language
669
+
670
+ ```json
671
+ {
672
+ ".toml": {
673
+ "run-command": "cat $absoluteName",
674
+ "rules": [
675
+ {"name": "booleans", "type": "keywords", "values": ["true", "false"], "style": "constant"}
676
+ ]
677
+ }
678
+ }
679
+ ```
680
+
681
+ ### Suggestion rules in depth
682
+
683
+ A suggestion rule says: *when the text before the cursor looks like this, offer these completions.*
684
+
685
+ ```json
686
+ {
687
+ "name": "second-word",
688
+ "pattern": "(?:^|;|\\{\\{)\\s*search\\s+$",
689
+ "min-prefix": 0,
690
+ "suggestions": ["elements", "molecules", "reactions"]
691
+ }
692
+ ```
693
+
694
+ | Field | Description |
695
+ |---|---|
696
+ | `name` | Unique, non-empty. Used by `$name$` references |
697
+ | `pattern` | Regular expression, searched **case-insensitively** in the *context* (below) |
698
+ | `suggestions` | Non-empty list of completions |
699
+ | `min-prefix` | Minimum number of characters already typed in the current word before the rule applies (default `0`) |
700
+
701
+ #### How a rule is chosen
702
+
703
+ 1. The line up to the cursor is split into a **prefix** (the run of non-whitespace characters just before the cursor) and a **context** (everything before that prefix, including whitespace).
704
+ 2. Rules are tried **in order**. The **first** rule whose pattern matches the context wins, and no later rule is consulted, even if the winner offers nothing for the current prefix.
705
+ 3. From the winner's `suggestions`, the first entry that starts with the prefix (case-insensitively) and is longer than it is chosen. The untyped remainder is shown as ghost text, and `Tab` inserts it.
706
+
707
+ Practical consequences:
708
+
709
+ - **Order matters. Put specific rules before general ones.** A broad rule placed early will shadow everything after it.
710
+ - **Anchor with `$`.** To mean "the cursor follows this word", end the pattern with `\s+$`. The context always ends with the whitespace before the prefix.
711
+ - **Prefixes are whitespace-delimited.** In `help{ab`, the prefix is the whole `help{ab`, so completions after punctuation without a space are not possible. Design completions around spaces.
712
+ - **A suggestion may contain spaces.** `"{{ search elements"` is offered once the prefix is `{`, and it is inserted as a whole.
713
+ - **Use `min-prefix: 1` for free-form positions**, so a ghost does not appear (and `Tab` still inserts a tab) before you have typed anything.
714
+ - **Remember JSON escaping.** Every regex backslash is doubled: `\s` is written `"\\s"`.
715
+
716
+ #### References
717
+
718
+ | Syntax | In a `pattern` | In a `suggestions` entry |
719
+ |---|---|---|
720
+ | `$rule-name$` | Replaced by an alternation of that rule's suggestions, e.g. `(?:search\|source\|...)` | Replaced by all of that rule's suggestions |
721
+ | `$active-source-fields$` | *(not supported)* | Field names of the active source: the source in the current `search` statement if it names one, otherwise the most recent `source` command above the line. Empty if there is none |
722
+ | `$query-start-options$` | *(not supported)* | The active source's fields, or the three sources when there is no active source |
723
+ | `$query-operators$` | *(not supported)* | `= != > < >= <= like like! likep has and or sort limit count return first last` |
724
+
725
+ A `$rule-name$` reference must point at a rule defined **earlier** in the list, which also rules out cycles. References are expanded one level: a referenced rule's own `$...$` entries are not expanded further.
726
+
727
+ #### Reference-only rules
728
+
729
+ A rule whose pattern is `(?!)` can never match, so it never fires. The bundled configuration uses this to hold named lists, such as all field names or all operators, which later rules splice into their patterns and suggestions:
730
+
731
+ ```json
732
+ { "name": "operators", "pattern": "(?!)", "min-prefix": 0,
733
+ "suggestions": ["=", "!=", ">", "<", ">=", "<=", "like", "like!", "likep", "has"] }
734
+ ```
735
+
736
+ A later rule can then recognise "a field name followed by an operator" with `\\s(?:$all-fields$)\\s+(?:$operators$)\\s+$`.
737
+
738
+ #### Testing a rule
739
+
740
+ The engine is plain Python, so you can try rules without opening the editor:
741
+
742
+ ```python
743
+ from chemql.highlighting import HighlightProfiles
744
+
745
+ profiles = HighlightProfiles("highlighting.json")
746
+ line = "search elements atomic_mass "
747
+ suffix = profiles.get_suggestion_suffix("x.cql", line, len(line), previous_lines=[])
748
+ print(line + suffix) # search elements atomic_mass >
749
+ ```
750
+
751
+ `previous_lines` supplies the lines above, which is how the active `source` is found.
752
+
753
+ ### What the bundled rules complete
754
+
755
+ The shipped `highlighting.json` defines about 70 rules for `.cql`. In summary:
756
+
757
+ | Context | Suggests |
758
+ |---|---|
759
+ | Start of a line, or after `;` (after 1 character) | Every ChemQL command and block keyword |
760
+ | After `{{` | Query commands (`search`, `findel`, `findmol`, `findre`, ...) |
761
+ | `search ` | Sources, `first`/`last`/`all`, and the active source's fields |
762
+ | `search SOURCE ` | That source's fields, plus `not`, `sort`, `limit`, `count` |
763
+ | After a field | Operators that suit its type: numeric (`>` `<` `=` ...), text (`like` `=` `has` ...), collection (`has`), boolean (`=` `!=`) |
764
+ | After `not` | Operators, or fields when negating a whole condition |
765
+ | After an operator | Known values for `phase`, `category`, `block`, `state` and `reversible` |
766
+ | After a complete condition | `and`, `or`, `sort`, `limit`, `count`, `return`, `union`, `intersection` |
767
+ | After `and`, `or`, `not`, `(` | Fields |
768
+ | After `sort`, `limit` | Fields, `asc`/`desc`, then `limit`/`count`/`return`; common limits |
769
+ | After `return` | Fields |
770
+ | After `union` / `intersection` | `search elements` / `molecules` / `reactions` |
771
+ | `findel`, `findmol`, `findre` | `return`, then that source's fields |
772
+ | `balance` | `+`, `->`, `<->` as appropriate |
773
+ | `set`, `add`, `remove` | Settings, `catalyst`, common temperature, pressure and catalyst values |
774
+ | `source`, `list`, `dump`, `help`, `load`, `install` | Their arguments, including standard-library modules and built-in names |
775
+ | `let` | `=`, then query, built-in and constant starters |
776
+ | `public`, `private`, `static`, `struct`, `record` | Declaration keywords, `from` |
777
+ | `for` | `in`, then `range(` or a query |
778
+
779
+ Value suggestions for `phase`, `category` and `block` reflect the standard periodic-table dataset. If your data uses different spellings, adjust the `value-...` rules.
780
+
781
+ ### Colours: `colors.json`
782
+
783
+ CodecQL reads its theme from `colors.json` next to `codecql.py`. If the file is missing, a built-in palette is used.
784
+
785
+ ```json
786
+ {
787
+ "syntax": {
788
+ "comment": {"ansi256": 244},
789
+ "string": {"ansi256": 114},
790
+ "number": {"ansi256": 179},
791
+ "formula": {"ansi256": 117},
792
+ "operator": {"ansi256": 213},
793
+ "delimiter": {"ansi256": 250},
794
+ "command": {"ansi256": 81},
795
+ "keyword": {"ansi256": 141},
796
+ "constant": {"ansi256": 215},
797
+ "type": {"ansi256": 150},
798
+ "source": {"ansi256": 110},
799
+ "condition": {"ansi256": 180},
800
+ "property": {"ansi256": 116},
801
+ "builtin": {"ansi256": 222}
802
+ },
803
+ "ui": {
804
+ "line_numbers": {"ansi256": 244},
805
+ "status_background": {"ansi256": 24, "channel": "background"},
806
+ "status_foreground": {"ansi256": 255}
807
+ }
808
+ }
809
+ ```
810
+
811
+ Each entry needs an `ansi256` number from 0 to 255, and an optional `channel` of `foreground` (default) or `background`. If you provide the file, include **every** category shown above.
812
+
813
+ ### CodecQL known limitations
814
+
815
+ - Files are saved with `\n` line endings and **no trailing newline**.
816
+ - Inline suggestions appear only when the cursor is at the end of the line.
817
+ - `regex` highlighting rules are validated but **not yet applied**.
818
+ - Auto-dedent applies only after `endnamespace`.
819
+ - One file per session: there are no tabs or split editors.
820
+ - Tabs are drawn four columns wide.
821
+ - CodecQL's Windows Backspace / Ctrl+Backspace are intentionally inverted relative to POSIX.
822
+
823
+ ## CodecQLX — the desktop editor
824
+
825
+ **CodecQLX** is the Tkinter desktop editor for ChemQL. It complements the
826
+ terminal-based CodecQL with a multi-file workspace, graphical diagnostics,
827
+ ChemQL-aware tools, and configurable themes.
828
+
829
+ ### Starting CodecQLX
830
+
831
+ ```bash
832
+ codecqlx FILE_OR_FOLDER ...
833
+ python -m chemql.codecqlx FILE_OR_FOLDER ...
834
+ codecqlx --version
835
+ ```
836
+
837
+ Paths are optional. A new empty file is opened when no path is supplied;
838
+ files and folders passed on the command line are opened in the editor. The
839
+ `codecqlx` command is installed with `chemql-python`.
840
+
841
+ CodecQLX uses Python's standard-library Tkinter GUI toolkit. On Linux, install
842
+ the platform Tk package if it is not already available (for example,
843
+ `python3-tk` on Debian/Ubuntu). The optional ChemQL panels are disabled when
844
+ the `chemql` package cannot be imported.
845
+
846
+ ### Features
847
+
848
+ - Syntax highlighting and context-aware autocomplete for `.cql` files
849
+ - Hoverable diagnostics, gutter markers, a Problems panel, and an overview ruler
850
+ - File tree sidebar with multiple editor tabs
851
+ - Query Console that executes ChemQL in-process and displays table or card results
852
+ - Interactive Periodic Table lookup
853
+ - Balance Equation panel
854
+ - Find and replace, bookmarks, zoom controls, and run-file/run-selection actions
855
+ - Dark and light themes, font settings, autocomplete/minimap toggles, and
856
+ per-token color preferences
857
+
858
+ Use **View** to toggle the file tree, Chemistry panel, and bottom panels.
859
+ CodecQLX stores its preferences in `.codecql_gui/settings.json` under the
860
+ user profile (`%APPDATA%` on Windows).
861
+
862
+ ### Keyboard shortcuts
863
+
864
+ | Key | Action |
865
+ |---|---|
866
+ | `Ctrl+N` / `Ctrl+O` | New file / open file |
867
+ | `Ctrl+Shift+O` | Open folder |
868
+ | `Ctrl+S` / `Ctrl+Shift+S` | Save / save as |
869
+ | `Ctrl+W` | Close tab |
870
+ | `Ctrl+F` | Find and replace |
871
+ | `Ctrl+R` / `Ctrl+Shift+R` | Run file / run selection |
872
+ | `Tab` / `Enter` | Accept the selected autocomplete suggestion |
873
+ | `Up` / `Down` / `Esc` | Navigate or dismiss autocomplete |
874
+ | `Ctrl+F2` / `F2` / `Shift+F2` | Toggle / next / previous bookmark |
875
+ | `Ctrl+=` / `Ctrl+-` / `Ctrl+0` | Zoom in / out / reset |
876
+
877
+ ---
878
+
879
+ ## Standard library
880
+
881
+ Load with `load <pkg>`; call as `<pkg>::name{…}`.
882
+
883
+ | Package | Purpose |
884
+ |---|---|
885
+ | `math` | Constants, trigonometry, logarithms, number theory |
886
+ | `math::statistics` | Mean, median, mode, variance, standard deviation, quantiles |
887
+ | `text` | String transforms, splitting/joining, regex helpers |
888
+ | `collections` | Uniqueness, flattening, pairing, frequency counts, product |
889
+ | `datetime` | Dates, timestamps, local/UTC time, date arithmetic |
890
+ | `json` | JSON encode/decode helpers |
891
+ | `random` | Pseudo-random numbers and sequence sampling |
892
+ | `decimal` | Base-10 decimal arithmetic and quantization |
893
+ | `fractions` | Exact rational numbers and fraction arithmetic |
894
+ | `pathlib` | Path inspection and UTF-8 text file operations |
895
+
896
+ `help{stdlib}` lists them; `help{math}` and `help{math::sqrt}` document each.
897
+
898
+ ---
899
+
900
+ ## Built-in functions
901
+
902
+ General: `abs round min max sum len type str int float bool upper lower contains replace split join first last unique sort reversed read_text read_lines read_json read_csv write_text write_csv write_json file_exists list_files help`
903
+
904
+ Chemistry: `element count_atoms molar_mass empirical_formula`
905
+
906
+ `help` with a topic is documented from `_BUILTIN_HELP`.
907
+
908
+ ---
909
+
910
+ ## Package manager
911
+
912
+ ```bash
913
+ chemql install <name> [--version V]
914
+ chemql upgrade <name> [--version V]
915
+ chemql uninstall <name>
916
+ chemql list
917
+ chemql search <query>
918
+ chemql info <name>
919
+ chemql build # requires cqlpackage.json / cqlpackage.toml
920
+ chemql upload # publish to the registry
921
+ chemql init [name] [-d dir]
922
+ ```
923
+
924
+ Inside the REPL: `install <name> [--version V]`.
925
+
926
+ Package layout:
927
+
928
+ ```
929
+ ~/.chemql/packages/<name>/<version>/
930
+ ```
931
+
932
+ ## License and attribution
933
+
934
+ [MIT License](https://github.com/rakibulofficial1017/ChemQL/blob/main/LICENSE)
935
+
936
+ Created by [Mohammad Rakibul Islam](https://github.com/rakibulofficial1017).
937
+ Source code: [rakibulofficial1017/ChemQL](https://github.com/rakibulofficial1017/ChemQL).
938
+
939
+ ------------------------------------------------------------------------
940
+
941
+ For the command reference that matches your installed build, type `help`
942
+ inside ChemQL. Use `list all` to inspect fields available in your
943
+ bundled datasets.