smizip


Namesmizip JSON
Version 2.0.1 PyPI version JSON
download
home_pageNone
SummaryAn implementation of Roger Sayle's SmiZip algorithm for compressing short strings
upload_time2025-02-01 16:43:40
maintainerNone
docs_urlNone
authorNone
requires_pythonNone
licenseMIT License Copyright (c) 2023-2025 Noel O'Boyle Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
keywords chemistry cheminformatics smiles compression zip
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            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:

.. code-block:: 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.

            

Raw data

            {
    "_id": null,
    "home_page": null,
    "name": "smizip",
    "maintainer": null,
    "docs_url": null,
    "requires_python": null,
    "maintainer_email": null,
    "keywords": "chemistry, cheminformatics, SMILES, compression, zip",
    "author": null,
    "author_email": null,
    "download_url": "https://files.pythonhosted.org/packages/75/28/1e73d1352917bba1ba88b2b4337c7c762fcec6b08677419a6204ecedc80e/smizip-2.0.1.tar.gz",
    "platform": null,
    "description": "SmiZip\n======\n\nSmiZip is a compression method for short strings. It was developed in 1998 by\nRoger Sayle (while at Metaphorics LLC) to compress SMILES strings, and\nfully described at a Daylight Mug01 presentation in 2001:\nhttps://www.daylight.com/meetings/mug01/Sayle/SmiZip/index.htm\n\nThis repo is an implementation Noel O'Boyle of the SmiZip algorithm in Python.\nThis work was presented at the 12th RDKit UGM in Mainz in Sep 2023:\nhttps://github.com/SoseiHeptares/presentations/blob/main/2023/2023-09-12thRDKitUGM_NoelOBoyle_SmiZip.pdf\n\nNote that the more recent 'smaz' (https://github.com/antirez/smaz) short string compression algorithm (2009) is equivalent in concept, but\nfavours a greedy approach over an optimal encoding. This was tweaked for SMILES by Andrew Dalke as 'smilez'; a Python 3 port by\nDavid Lorenzana can be found at https://github.com/davidlorenzana/smilez. Another more recent paper describes\nZSMILES (2024, https://arxiv.org/abs/2404.19391), which seems very similar.\n\nQuick start\n-----------\n\nInstall as follows::\n\n   pip install smizip\n\nFirst, let's download a set of n-grams trained on RDKit canonical SMILES from ChEMBL::\n\n  curl https://raw.githubusercontent.com/SoseiHeptares/smizip/main/example-ngrams/rdkit.slow.json -o rdkit.slow.json\n\nNow let's use this to compress and decompress a .smi file that contains canonical SMILES from RDKit::\n\n  smizip    -i test.smi  -o test.smiz  -n rdkit.slow.json\n  smizip -d -i test.smiz -o test.2.smi -n rdkit.slow.json\n\nNote that the expected format of a .smi file is ``[SMILES][tab][TITLE]\\n``.\n\nOther example sets of n-grams are available from the GitHub site (https://github.com/SoseiHeptares/smizip/tree/main/example-ngrams).\nTo create your own JSON file of n-grams, you can train on a dataset (``find_best_ngrams``), or modify\nan existing JSON (``add_char_to_json``).\n\nTo use from Python:\n\n.. code-block:: python\n\n  import json\n  from smizip import SmiZip\n\n  json_file = \"rdkit.slow.json\"\n  with open(json_file) as inp:\n     ngrams = json.load(inp)['ngrams']\n\n  zipper = SmiZip(ngrams)\n  zipped = zipper.zip(\"c1ccccc1C(=O)Cl\") # gives bytes\n  unzipped = zipper.unzip(zipped)\n\nNote\n----\n\nYou 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``.\n\nA 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.\n\nChanges\n-------\n\nv2.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.\n",
    "bugtrack_url": null,
    "license": "MIT License  Copyright (c) 2023-2025 Noel O'Boyle  Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the \"Software\"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:  The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.  THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. ",
    "summary": "An implementation of Roger Sayle's SmiZip algorithm for compressing short strings",
    "version": "2.0.1",
    "project_urls": {
        "Homepage": "https://github.com/baoilleach/smizip"
    },
    "split_keywords": [
        "chemistry",
        " cheminformatics",
        " smiles",
        " compression",
        " zip"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "8ba84a64bcc39ac17a4a5e4aff1ffa27535c64171442ff22309c02c3bfce56d8",
                "md5": "8e2af95b60289a707dc2066d1eccc1a5",
                "sha256": "5acc624e6ccda53e839c854c359b7e49a85ae53896a94e774996589ec6993aac"
            },
            "downloads": -1,
            "filename": "smizip-2.0.1-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "8e2af95b60289a707dc2066d1eccc1a5",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": null,
            "size": 12706,
            "upload_time": "2025-02-01T16:43:38",
            "upload_time_iso_8601": "2025-02-01T16:43:38.120570Z",
            "url": "https://files.pythonhosted.org/packages/8b/a8/4a64bcc39ac17a4a5e4aff1ffa27535c64171442ff22309c02c3bfce56d8/smizip-2.0.1-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "75281e73d1352917bba1ba88b2b4337c7c762fcec6b08677419a6204ecedc80e",
                "md5": "ad22748e332738dfca4d0bdafd296464",
                "sha256": "1ac3b3e56ff6a6f8fc366fe35f250ee5bf6b6749375e0bf7c08a8a6e27c9b21e"
            },
            "downloads": -1,
            "filename": "smizip-2.0.1.tar.gz",
            "has_sig": false,
            "md5_digest": "ad22748e332738dfca4d0bdafd296464",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": null,
            "size": 12223,
            "upload_time": "2025-02-01T16:43:40",
            "upload_time_iso_8601": "2025-02-01T16:43:40.248845Z",
            "url": "https://files.pythonhosted.org/packages/75/28/1e73d1352917bba1ba88b2b4337c7c762fcec6b08677419a6204ecedc80e/smizip-2.0.1.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2025-02-01 16:43:40",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "baoilleach",
    "github_project": "smizip",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": false,
    "lcname": "smizip"
}
        
Elapsed time: 2.17620s