chemql-python 1.6.4__tar.gz → 1.6.5__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 (42) hide show
  1. {chemql_python-1.6.4 → chemql_python-1.6.5}/PKG-INFO +278 -16
  2. {chemql_python-1.6.4 → chemql_python-1.6.5}/README.md +277 -15
  3. {chemql_python-1.6.4 → chemql_python-1.6.5}/pyproject.toml +1 -1
  4. {chemql_python-1.6.4 → chemql_python-1.6.5}/src/chemql/__init__.py +88 -17
  5. {chemql_python-1.6.4 → chemql_python-1.6.5}/src/chemql/codecql.py +84 -35
  6. {chemql_python-1.6.4 → chemql_python-1.6.5}/src/chemql/highlighting.py +51 -8
  7. {chemql_python-1.6.4 → chemql_python-1.6.5}/src/chemql/stdlib/math.cql +2 -0
  8. {chemql_python-1.6.4 → chemql_python-1.6.5}/src/chemql_python.egg-info/PKG-INFO +278 -16
  9. {chemql_python-1.6.4 → chemql_python-1.6.5}/tests/test_public_api.py +15 -0
  10. {chemql_python-1.6.4 → chemql_python-1.6.5}/tests/test_reactions.py +15 -0
  11. {chemql_python-1.6.4 → chemql_python-1.6.5}/LICENSE +0 -0
  12. {chemql_python-1.6.4 → chemql_python-1.6.5}/setup.cfg +0 -0
  13. {chemql_python-1.6.4 → chemql_python-1.6.5}/src/chemql/__main__.py +0 -0
  14. {chemql_python-1.6.4 → chemql_python-1.6.5}/src/chemql/build.py +0 -0
  15. {chemql_python-1.6.4 → chemql_python-1.6.5}/src/chemql/colors.json +0 -0
  16. {chemql_python-1.6.4 → chemql_python-1.6.5}/src/chemql/data/BondEnergies.json +0 -0
  17. {chemql_python-1.6.4 → chemql_python-1.6.5}/src/chemql/data/MoleculeBonds.json +0 -0
  18. {chemql_python-1.6.4 → chemql_python-1.6.5}/src/chemql/data/Molecules.json +0 -0
  19. {chemql_python-1.6.4 → chemql_python-1.6.5}/src/chemql/data/PeriodicTableJSON.json +0 -0
  20. {chemql_python-1.6.4 → chemql_python-1.6.5}/src/chemql/data/Reactions.json +0 -0
  21. {chemql_python-1.6.4 → chemql_python-1.6.5}/src/chemql/data/THIRD_PARTY_LICENSES/PeriodicTableJSON.txt +0 -0
  22. {chemql_python-1.6.4 → chemql_python-1.6.5}/src/chemql/data/THIRD_PARTY_LICENSES/RHEA.txt +0 -0
  23. {chemql_python-1.6.4 → chemql_python-1.6.5}/src/chemql/html/periodic_table.html +0 -0
  24. {chemql_python-1.6.4 → chemql_python-1.6.5}/src/chemql/stdlib/README.md +0 -0
  25. {chemql_python-1.6.4 → chemql_python-1.6.5}/src/chemql/stdlib/collections.cql +0 -0
  26. {chemql_python-1.6.4 → chemql_python-1.6.5}/src/chemql/stdlib/datetime.cql +0 -0
  27. {chemql_python-1.6.4 → chemql_python-1.6.5}/src/chemql/stdlib/decimal.cql +0 -0
  28. {chemql_python-1.6.4 → chemql_python-1.6.5}/src/chemql/stdlib/fractions.cql +0 -0
  29. {chemql_python-1.6.4 → chemql_python-1.6.5}/src/chemql/stdlib/json.cql +0 -0
  30. {chemql_python-1.6.4 → chemql_python-1.6.5}/src/chemql/stdlib/math/statistics.cql +0 -0
  31. {chemql_python-1.6.4 → chemql_python-1.6.5}/src/chemql/stdlib/pathlib.cql +0 -0
  32. {chemql_python-1.6.4 → chemql_python-1.6.5}/src/chemql/stdlib/random.cql +0 -0
  33. {chemql_python-1.6.4 → chemql_python-1.6.5}/src/chemql/stdlib/text.cql +0 -0
  34. {chemql_python-1.6.4 → chemql_python-1.6.5}/src/chemql_python.egg-info/SOURCES.txt +0 -0
  35. {chemql_python-1.6.4 → chemql_python-1.6.5}/src/chemql_python.egg-info/dependency_links.txt +0 -0
  36. {chemql_python-1.6.4 → chemql_python-1.6.5}/src/chemql_python.egg-info/entry_points.txt +0 -0
  37. {chemql_python-1.6.4 → chemql_python-1.6.5}/src/chemql_python.egg-info/requires.txt +0 -0
  38. {chemql_python-1.6.4 → chemql_python-1.6.5}/src/chemql_python.egg-info/top_level.txt +0 -0
  39. {chemql_python-1.6.4 → chemql_python-1.6.5}/tests/test_codecql.py +0 -0
  40. {chemql_python-1.6.4 → chemql_python-1.6.5}/tests/test_external_molecule_lookup.py +0 -0
  41. {chemql_python-1.6.4 → chemql_python-1.6.5}/tests/test_stdlib.py +0 -0
  42. {chemql_python-1.6.4 → chemql_python-1.6.5}/tests/test_structured_types.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: chemql-python
3
- Version: 1.6.4
3
+ Version: 1.6.5
4
4
  Summary: A chemistry-focused query language and REPL
5
5
  Author-email: Mohammad Rakibul Islam <rakibulofficial1017@gmail.com>
6
6
  Requires-Python: >=3.10
@@ -22,15 +22,20 @@ CodecQL is the terminal text editor distributed with ChemQL. It edits
22
22
  source files, provides syntax highlighting, and supports configurable
23
23
  highlighting profiles for multiple file extensions.
24
24
 
25
- > **Version represented by this documentation:** ChemQL `1.6.4`; CodecQL
26
- > `0.0.11`.
25
+ > **Version represented by this documentation:** ChemQL `1.6.5`; CodecQL
26
+ > `0.0.12`.
27
27
  >
28
28
  > This README documents the implementation represented by the
29
29
  > accompanying source files. Some advanced syntax is intentionally
30
30
  > described at a high level; use the built-in `help` system for the
31
31
  > authoritative in-app reference.
32
32
 
33
- ------------------------------------------------------------------------
33
+ ChemQL is designed for chemistry-aware exploration without giving up the
34
+ reach of Python. You can query packaged datasets, calculate formula
35
+ properties, balance reactions, work with structured values, load a small
36
+ standard library, and drop into Python when the language itself is not the
37
+ right tool. CodecQL is the companion terminal editor with ChemQL-aware
38
+ highlighting, search, undo/redo, and an integrated run terminal.
34
39
 
35
40
  ## Contents
36
41
 
@@ -72,9 +77,7 @@ command.
72
77
 
73
78
  The ChemQL runtime imports `prompt_toolkit` for the interactive prompt.
74
79
  The editor uses Python's standard library and ANSI terminal escape
75
- sequences. On Windows it attempts to initialize ANSI support with
76
- `colorama`, and falls back to enabling virtual-terminal processing when
77
- `colorama` is unavailable.
80
+ sequences.
78
81
 
79
82
  Install ChemQL using the distribution method provided by the project. If
80
83
  installing from a local source checkout, install the project from its
@@ -233,9 +236,7 @@ unset answer
233
236
  Definitions are expanded using an `@NAME` reference:
234
237
 
235
238
  ``` text
236
- define MAX {
237
- 100
238
- }
239
+ define MAX 100
239
240
  ```
240
241
 
241
242
  Use the definition as:
@@ -248,11 +249,19 @@ Definitions are maintained in the current ChemQL session. The
248
249
  preprocessor performs one literal substitution pass; replacement text is
249
250
  not recursively expanded.
250
251
 
252
+ Macros are expanded using an `@NAME{arguments if any}` reference:
253
+ ```
254
+ define double{}
255
+ \1 * 2 // this \1 means the first argument
256
+ enddefine
257
+ ```
258
+
251
259
  Macros use a block form and are invoked by name according to the macro
252
260
  syntax supported by the interpreter. Use `help{syntax}` and the in-app
253
261
  completion/help facilities for the exact forms supported by your
254
262
  installed version.
255
263
 
264
+ Current definitions can be viewed via `definitions` and `macros` for macros.
256
265
  ### Embedded Python
257
266
 
258
267
  A single-line Python statement or expression can be placed inside square
@@ -291,7 +300,8 @@ See `help{syntax}` and the query examples shipped with the project.
291
300
  ### Control flow
292
301
 
293
302
  ChemQL supports block-oriented control-flow constructs including `if`,
294
- `elif`, `else`, `for`, and `while`. Closing markers are explicit:
303
+ `elif`, `else`, `for`, and `while`. Indentation in chemql is optional.
304
+ Closing markers are explicit:
295
305
 
296
306
  ``` text
297
307
  if condition
@@ -313,7 +323,7 @@ while condition
313
323
  endwhile
314
324
  ```
315
325
 
316
- `break` and `continue` are also recognized control keywords.
326
+ `break` and `continue`/`skip` are also recognized control keywords.
317
327
 
318
328
  ### Functions
319
329
 
@@ -327,7 +337,13 @@ A minimal illustrative shape:
327
337
 
328
338
  ``` text
329
339
  func greet
330
- return "Hello"
340
+ return "Hello, \1"
341
+ endfunc
342
+
343
+ // the equivalent of the above code using the global variable arguments is
344
+
345
+ func greet
346
+ return "Hello " + arguments[0]
331
347
  endfunc
332
348
  ```
333
349
 
@@ -350,7 +366,7 @@ Declarations are closed with their corresponding terminators, such as
350
366
 
351
367
  Example declaration shape:
352
368
 
353
- ``` text
369
+ ```
354
370
  struct Point
355
371
  x
356
372
  y
@@ -358,7 +374,22 @@ endstruct
358
374
  ```
359
375
 
360
376
  Enum members can receive automatically generated values when values are
361
- omitted.
377
+ omitted unless it is required via the `required` keyword or a trailing exclamation mark.
378
+
379
+ Example:
380
+
381
+ ```
382
+ struct Fruit
383
+ name
384
+ required price
385
+ weight!
386
+ color = "Red" // default values
387
+ endstruct
388
+
389
+ Fruit{price=1.23} // Error, required weight
390
+ Fruit{price=1.23, weight=2.3} // name is None and color is "Red"
391
+ ```
392
+
362
393
 
363
394
  ### Namespaces
364
395
 
@@ -482,6 +513,9 @@ namespaces:
482
513
  `datetime` Dates, times, timestamps, and date arithmetic
483
514
  `json` JSON serialization, parsing, and type inspection
484
515
  `random` Pseudorandom values and sequence sampling
516
+ `decimal` Base-10 decimal arithmetic and quantization
517
+ `fractions` Exact rational arithmetic
518
+ `pathlib` Safe path inspection and UTF-8 text operations
485
519
 
486
520
  Ask ChemQL for a package's documented members:
487
521
 
@@ -490,11 +524,28 @@ help{stdlib}
490
524
  help{math}
491
525
  help{math::statistics}
492
526
  help{text}
527
+ help{decimal}
528
+ help{fractions::create}
493
529
  ```
494
530
 
495
531
  A function can be documented individually when its help entry is
496
532
  registered:
497
533
 
534
+ ```
535
+
536
+ Standard-library packages are loaded explicitly. Loading a package exposes
537
+ its public members under the package namespace; unloaded namespaces should
538
+ not be treated as globally available. For example:
539
+
540
+ ``` text
541
+ load decimal
542
+ decimal::add{"0.1", "0.2"} // 0.3 exactly
543
+
544
+ load fractions
545
+ fractions::add{"1/3", "1/6"} // 1/2
546
+
547
+ load pathlib
548
+ pathlib::write_text{"results.txt", "ChemQL"}
498
549
  ``` text
499
550
  help{math::sqrt}
500
551
  ```
@@ -533,6 +584,79 @@ The available data sources and query fields are defined by the ChemQL
533
584
  package/data files. Use the interactive prompt's completion and
534
585
  `help{chemistry}` for the current details.
535
586
 
587
+ ### Packaged datasets and provenance
588
+
589
+ The runtime ships data under [`src/chemql/data/`](src/chemql/data/):
590
+
591
+ | File | Used for |
592
+ | --- | --- |
593
+ | `PeriodicTableJSON.json` | Element metadata, periodic-table lookups, and `search elements` |
594
+ | `Molecules.json` | Molecule names, formulas, identifiers, and physical properties |
595
+ | `Reactions.json` | Curated reaction records used by `findre`, `search reactions`, and `react` |
596
+ | `MoleculeBonds.json` | Molecular connectivity and bond information |
597
+ | `BondEnergies.json` | Bond-energy data for reaction/energy analysis |
598
+
599
+ Molecule properties use reference conditions documented in
600
+ [`src/chemql/data/README.md`](src/chemql/data/README.md). Missing or
601
+ uncertain source values remain `null`; they are not inferred merely to make
602
+ a record look complete. Reaction records may have unknown direction,
603
+ conditions, or phases. Rhea-derived records retain their source links and
604
+ the applicable third-party license text is included in
605
+ `data/THIRD_PARTY_LICENSES/`.
606
+
607
+ ### Query examples
608
+
609
+ The query language supports source selection, filtering, projection,
610
+ ordering, and limiting. Exact field availability depends on the selected
611
+ source:
612
+
613
+ ``` text
614
+ search elements
615
+ search elements name like "*oxygen*" sort atomic_number asc
616
+ search molecules formula like "*H2O*" limit 10
617
+ search reactions reaction_type like "*synthesis*" return id name equation
618
+ findel O
619
+ findmol "water"
620
+ findre RHEA:10000
621
+ ```
622
+
623
+ Common query operators include `like`, `like!`, `likep`, `has`, `sort`,
624
+ `limit`, `count`, `first`, `last`, `union`, and `intersection`. Use
625
+ `source`, `return`, and `view` to inspect or shape results. The command
626
+ completion and `help{syntax}` are safer than guessing a field name when
627
+ working with a new dataset.
628
+
629
+ ### Reaction conditions and balancing
630
+
631
+ Reaction state is session-local. Configure it before matching or reacting:
632
+
633
+ ``` text
634
+ set temperature 723K
635
+ set pressure 20265000Pa
636
+ set catalysts iron
637
+ conditions
638
+ react N2 3H2
639
+ ```
640
+
641
+ Temperature accepts Kelvin, Celsius, and Fahrenheit values (`K`, `C`, `F`)
642
+ plus the aliases `standard` and `room`. Pressure accepts Pa, bar, and
643
+ common aliases such as `atm`, `kPa`, `MPa`, `hPa`, `torr`, `mmHg`, and `psi`
644
+ plus `standard` and `room`. Catalysts can be replaced with `set`, appended
645
+ with `add catalyst`, or removed with `remove catalyst`.
646
+
647
+ Balance equations directly:
648
+
649
+ ``` text
650
+ balance H2 + O2 -> H2O
651
+ balance Ca(OH)2 + H3PO4 -> Ca3(PO4)2 + H2O
652
+ balance H2 + O2 <-> H2O
653
+ ```
654
+
655
+ The balancer returns minimal integer coefficients and preserves reaction
656
+ direction. `->` creates a directed reaction, `<->` creates a reversible
657
+ reaction, and an unknown direction remains an undirected equation. Comments
658
+ after a balance expression can annotate direction intent.
659
+
536
660
  ## Package management
537
661
 
538
662
  ChemQL provides package-management subcommands:
@@ -586,7 +710,7 @@ The package manager also supports upgrading ChemQL itself:
586
710
 
587
711
  ``` bash
588
712
  chemql --upgrade
589
- chemql --upgrade 1.6.4
713
+ chemql --upgrade 1.6.5
590
714
  ```
591
715
 
592
716
  Use `--force` only when you understand that it bypasses normal
@@ -603,6 +727,55 @@ Use square-bracket blocks for Python statements and expressions. Use
603
727
  `[[[ ... ]]]` for multiline Python. This is the intended boundary
604
728
  between ChemQL's command/query syntax and general Python code.
605
729
 
730
+ ### Calling ChemQL from Python
731
+
732
+ The package exposes a small, stable query-oriented API:
733
+
734
+ ```python
735
+ import chemql
736
+
737
+ water = chemql.find_molecule("H2O")
738
+ reaction = chemql.balance_stoichiometry(["H2", "O2"], ["H2O"])
739
+ result = chemql.execute_query_text('molar_mass{"H2O"}')
740
+ ```
741
+
742
+ The public exports include:
743
+
744
+ | Export | Purpose |
745
+ | --- | --- |
746
+ | `execute_query(query)` | Execute a tokenized query/command |
747
+ | `execute_query_text(text)` | Execute ChemQL source text |
748
+ | `search(source)` | Query a packaged data source |
749
+ | `find_molecule(value)` | Find a molecule in the bundled local dataset |
750
+ | `find_reaction(value)` | Find a reaction by identifier or searchable value |
751
+ | `search_reactions(**criteria)` | Search reaction records by fields |
752
+ | `balance_stoichiometry(reactants, products, reversible=None)` | Balance a reaction and return a `Reaction` |
753
+ | `Element`, `Molecule`, `Reaction` | Chemistry result types |
754
+ | `ReturnTable`, `Unknown` | Query result/support types |
755
+ | `ChemQLError` and built-in error classes | Explicit runtime failures |
756
+
757
+ `chemql.__version__` contains the installed runtime version. Query results
758
+ may be a scalar, list, dictionary-like record, chemistry object, `None`, or
759
+ an `Unknown` value depending on the operation. Errors are raised rather
760
+ than silently converted into successful-looking results.
761
+
762
+ ### External molecule lookup
763
+
764
+ The Python `find_molecule` API reads the bundled local dataset. The
765
+ interactive `findmol` command adds an external fallback path, including
766
+ PubChem and NIST-backed lookups, when network access is available. External
767
+ lookups are best-effort: a missing network service or unknown compound
768
+ returns no match, not a fabricated molecule. Applications that require
769
+ reproducibility should prefer records present in `src/chemql/data/` and
770
+ handle a missing result explicitly.
771
+
772
+ ### Importing ChemQL packages from Python
773
+
774
+ ChemQL package source is intended to be loaded by the ChemQL runtime. For
775
+ Python applications, keep the query boundary explicit and use
776
+ `execute_query_text` or a separately tested wrapper instead of relying on
777
+ private interpreter state.
778
+
606
779
  ## Help and errors
607
780
 
608
781
  The interactive help system is the quickest way to discover the exact
@@ -632,6 +805,95 @@ Other errors can include `SyntaxError`, `NameError`, and
632
805
 
633
806
  ------------------------------------------------------------------------
634
807
 
808
+ ## Development
809
+
810
+ ChemQL requires Python 3.10 or newer. From this directory, a typical
811
+ development setup is:
812
+
813
+ ``` bash
814
+ python -m venv .venv
815
+ # Linux/macOS:
816
+ source .venv/bin/activate
817
+ # Windows PowerShell:
818
+ # .venv\Scripts\Activate.ps1
819
+ python -m pip install --upgrade pip
820
+ python -m pip install -e ".[test]"
821
+ ```
822
+
823
+ Run the package's test suite with:
824
+
825
+ ``` bash
826
+ python -m pytest
827
+ ```
828
+
829
+ The tests cover the public query API, formula and reaction handling,
830
+ external molecule fallback behavior, structured types and inheritance,
831
+ standard-library packages, CLI behavior, and CodecQL editing interactions.
832
+ When changing packaged data or syntax, run the full suite rather than only
833
+ an isolated test because interpreter state and data-loading behavior are
834
+ shared across several tests.
835
+
836
+ Build distribution artifacts with:
837
+
838
+ ``` bash
839
+ python -m pip install build
840
+ python -m build
841
+ ```
842
+
843
+ The generated wheel and source archive are written to `dist/`. Do not
844
+ manually edit generated metadata under `src/chemql_python.egg-info/`.
845
+
846
+ ### Source-checkout launcher
847
+
848
+ When dependencies are installed but the project is not installed, the
849
+ [`scripts/chemql`](scripts/chemql) launcher runs the package directly from
850
+ `src/`:
851
+
852
+ ``` bash
853
+ ./scripts/chemql --version
854
+ ./scripts/chemql -f examples/script.cql
855
+ ```
856
+
857
+ On Windows, use an installed console script or invoke `python -m chemql`
858
+ with `PYTHONPATH=src`.
859
+
860
+ ## Design and operational notes
861
+
862
+ - ChemQL function calls use braces (`name{...}`), while embedded Python
863
+ uses square brackets. This keeps the language boundary explicit.
864
+ - Definitions, functions, macros, variables, loaded packages, reaction
865
+ conditions, and execution history are session state. Start a fresh
866
+ process when a clean environment is important.
867
+ - File built-ins use current process permissions and default to UTF-8.
868
+ - External molecule lookup requires network access and should not be used
869
+ as the sole source for a reproducible scientific workflow.
870
+ - ANSI output can be disabled with `--no-ansi`, which is useful for logs
871
+ and automated comparisons.
872
+ - Package install, upload, and upgrade commands can modify the local
873
+ environment. Prefer an isolated virtual environment.
874
+
875
+ ## Compatibility and support boundaries
876
+
877
+ ChemQL is tested against Python `>=3.10` and depends on
878
+ `prompt_toolkit>=3.0` and `rich>=13.7`. CodecQL uses terminal capabilities
879
+ for raw key input, ANSI styling, and optional system clipboard integration.
880
+ Clipboard support is opportunistic; the editor retains an internal
881
+ clipboard when no platform utility is available.
882
+
883
+ The highlighting loader validates regex profiles, but the current renderer
884
+ applies keyword profiles through its identifier-highlighting path. Treat
885
+ regex profile validation as supported configuration behavior, not as a
886
+ guarantee that every regex rule is rendered in every token context.
887
+
888
+ ## License and data attribution
889
+
890
+ The project code is distributed under the [MIT License](LICENSE).
891
+ Chemistry datasets can have their own provenance and licensing terms.
892
+ Review [`src/chemql/data/README.md`](src/chemql/data/README.md) and the
893
+ license files in
894
+ [`src/chemql/data/THIRD_PARTY_LICENSES/`](src/chemql/data/THIRD_PARTY_LICENSES/)
895
+ before redistributing packaged data.
896
+
635
897
  # CodecQL
636
898
 
637
899
  CodecQL is a terminal-based text editor intended for ChemQL source