Skip to main content

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

Release files for pymolecule-parser 0.1.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for pymolecule-parser 0.1.0
File Size Uploaded
pymolecule_parser-0.1.0.tar.gz 12.7 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for pymolecule-parser 0.1.0
File Interpreter ABI Platform
pymolecule_parser-0.1.0-py3-none-any.whl Python 3 none any Details

Total release size: 21.7 kB

Release files / pymolecule_parser-0.1.0.tar.gz

Download URL pymolecule_parser-0.1.0.tar.gz
Size 12.7 kB
Tags Source
SHA-256 checksum
How to use checksums
ec9245a9df8035a7086d0441d2212a87ebc3d119861c581b52d8c19ae94d2725
BLAKE2b-256 checksum
How to use checksums
9b3f9e40adbe4dc8ac9b4c58b7829495dd40e925d22545f43772a25d9c45c4d5
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.1 CPython/3.11.4

Release files / pymolecule_parser-0.1.0-py3-none-any.whl

Download URL pymolecule_parser-0.1.0-py3-none-any.whl
Size 9.0 kB
Tags Python 3
SHA-256 checksum
How to use checksums
058f55eec1f729c442cc8c048f72e462d9b94b327531222d729e937dd30dfeac
BLAKE2b-256 checksum
How to use checksums
ead906188e4940be686d2c97c2c32b98c29a7aa3a48986797271e9e59df52fdd
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.1 CPython/3.11.4

Release history Release notifications | RSS feed

This release

0.1.0 This release

2 release files

0.0.2

2 release files

0.0.1

2 release files

0.0.0

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page