SmiZip
SmiZip is a compression method for short strings. It was developed in 1998 by Roger Sayle (while at Metaphorics LLC) to compress SMILES strings, and fully described at a Daylight Mug01 presentation in 2001: https://www.daylight.com/meetings/mug01/Sayle/SmiZip/index.htm
This repo is an implementation Noel O’Boyle of the SmiZip algorithm in Python. This work was presented at the 12th RDKit UGM in Mainz in Sep 2023: https://github.com/SoseiHeptares/presentations/blob/main/2023/2023-09-12thRDKitUGM_NoelOBoyle_SmiZip.pdf
Note that the more recent ‘smaz’ (https://github.com/antirez/smaz) short string compression algorithm (2009) is equivalent in concept, but favours a greedy approach over an optimal encoding. This was tweaked for SMILES by Andrew Dalke as ‘smilez’; a Python 3 port by David Lorenzana can be found at https://github.com/davidlorenzana/smilez. Another more recent paper describes ZSMILES (2024, https://arxiv.org/abs/2404.19391), which seems very similar.
Quick start
Install as follows:
pip install smizip
First, let’s download a set of n-grams trained on RDKit canonical SMILES from ChEMBL:
curl https://raw.githubusercontent.com/SoseiHeptares/smizip/main/example-ngrams/rdkit.slow.json -o rdkit.slow.json
Now let’s use this to compress and decompress a .smi file that contains canonical SMILES from RDKit:
smizip -i test.smi -o test.smiz -n rdkit.slow.json smizip -d -i test.smiz -o test.2.smi -n rdkit.slow.json
Note that the expected format of a .smi file is [SMILES][tab][TITLE]\n.
Other example sets of n-grams are available from the GitHub site (https://github.com/SoseiHeptares/smizip/tree/main/example-ngrams). To create your own JSON file of n-grams, you can train on a dataset (find_best_ngrams), or modify an existing JSON (add_char_to_json).
To use from Python:
import json
from smizip import SmiZip
json_file = "rdkit.slow.json"
with open(json_file) as inp:
ngrams = json.load(inp)['ngrams']
zipper = SmiZip(ngrams)
zipped = zipper.zip("c1ccccc1C(=O)Cl") # gives bytes
unzipped = zipper.unzip(zipped)
Note
You should include \n (carraige-return) as a single-character n-gram if you intend to store the zipped representation in a file with lines terminated by \n. Otherwise, the byte value of \n will be assigned to a multi-gram, and zipped SMILES will be generated containing \n.
A similar warning goes for any SMILES termination character in a file. If you expect to store zipped SMILES that terminate in a TAB or SPACE character, you should add these characters as single-character n-grams. Otherwise the zipped representation may contain these and you won’t know which TABs are terminations and which are part of the representation.
Changes
v2.0 (2025-01) : Python API: unchanged. find_best_ngrams.py: new option --non-printable to facilitate encoding into printable ASCII charactersr; --chars is now required (help text provides a reasonable starting point) to force the user to consider the list; if the end of the training .SMI file is reached, the script wraps around to the start; --cr corrected to --lf. compress.py: A better error message is generated if an attempt is made to encode a character not present in the JSON file; support added for .SMI files without titles. Thanks to Adriano Rutz (@adafede) and Charles Tapley Hoyt (@cthoyt) for feedback.
Metadata
Release files for smizip 2.0.1
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| smizip-2.0.1.tar.gz | 12.2 kB | Without provenance | Details for smizip-2.0.1.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| smizip-2.0.1-py3-none-any.whl | Python 3 | none | any | Details for smizip-2.0.1-py3-none-any.whl |
Total release size: 24.9 kB
Release files / smizip-2.0.1.tar.gz
| Download URL | smizip-2.0.1.tar.gz |
|---|---|
| Size | 12.2 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
1ac3b3e56ff6a6f8fc366fe35f250ee5bf6b6749375e0bf7c08a8a6e27c9b21e
|
|
BLAKE2b-256 checksum How to use checksums |
75281e73d1352917bba1ba88b2b4337c7c762fcec6b08677419a6204ecedc80e
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/5.0.0 CPython/3.12.3
|
Release files / smizip-2.0.1-py3-none-any.whl
| Download URL | smizip-2.0.1-py3-none-any.whl |
|---|---|
| Size | 12.7 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
5acc624e6ccda53e839c854c359b7e49a85ae53896a94e774996589ec6993aac
|
|
BLAKE2b-256 checksum How to use checksums |
8ba84a64bcc39ac17a4a5e4aff1ffa27535c64171442ff22309c02c3bfce56d8
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/5.0.0 CPython/3.12.3
|
Security for smizip 2.0.1
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.