Skip to main content

A parser for molecule formula. Nested brackets are supported.

Project description

pymolecule-parser: A parser for a molecule formula that supports nested brackets

pymolecule-parser-test

Installation

pip install pymolecule-parser

Usage

  • pymolecule_parser.parse returns a dictionary of atoms and their numbers. (type: dict[str, int])
from pymolecule_parser import parse

dict_1 = parse("H2O") # {'H': 2, 'O': 1}
dict_2 = parse("3H2O") # {'H': 6, 'O': 3}
dict_3 = parse("H2O2(OH)2") # {'H': 4, 'O': 4}
dict_4 = parse("[Co(NH3)6]Cl3") # {'Co': 1, 'N': 6, 'H': 18, 'Cl': 3}

Options

  • strict_mode
    • If strict_mode is True, the parser expects all atoms in the argument to be from hydrogen (H) to oganeson (Og), otherwise raises an exception
    • If strict_mode is False, the parser parses arguments even if they are not existing atoms if they satisfy the rules for writing atoms (first letter is uppercase, subsequent letters are lowercase)
    • Default: False (non-strict mode)

If you want to use strict mode, please use the following code.

from pymolecule_parser import parse

dict_1 = parse("H2O", strict_mode=True) # {'H': 2, 'O': 1}

Limitations

The following notations are not supported.

  • Ion notations
    • For example, [Cu(NH3)4]2+ is not supported. Use Cu(NH3)4 instead.
  • middle dot ·
    • For example, CuSO4·5H2O is not supported. Use CuSO4(H2O)5 instead.

License

Apache License 2.0

Author

Kohei Noda

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

pymolecule_parser-0.1.0.tar.gz (12.7 kB view details)

Uploaded Source

Built Distribution

pymolecule_parser-0.1.0-py3-none-any.whl (9.0 kB view details)

Uploaded Python 3

File details

Details for the file pymolecule_parser-0.1.0.tar.gz.

File metadata

  • Download URL: pymolecule_parser-0.1.0.tar.gz
  • Upload date:
  • Size: 12.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.1 CPython/3.11.4

File hashes

Hashes for pymolecule_parser-0.1.0.tar.gz
Algorithm Hash digest
SHA256 ec9245a9df8035a7086d0441d2212a87ebc3d119861c581b52d8c19ae94d2725
MD5 1a925f0a094ed6b986dbf367e627c783
BLAKE2b-256 9b3f9e40adbe4dc8ac9b4c58b7829495dd40e925d22545f43772a25d9c45c4d5

See more details on using hashes here.

File details

Details for the file pymolecule_parser-0.1.0-py3-none-any.whl.

File metadata

File hashes

Hashes for pymolecule_parser-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 058f55eec1f729c442cc8c048f72e462d9b94b327531222d729e937dd30dfeac
MD5 1fff94054121d12af8554bb5577fb218
BLAKE2b-256 ead906188e4940be686d2c97c2c32b98c29a7aa3a48986797271e9e59df52fdd

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page