pymolecule-parser: A parser for a molecule formula that supports nested brackets
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_modeisTrue, the parser expects all atoms in the argument to be from hydrogen (H) to oganeson (Og), otherwise raises an exception - If
strict_modeisFalse, 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
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. UseCu(NH3)4instead.
- For example,
- middle dot
·- For example,
CuSO4·5H2Ois not supported. UseCuSO4(H2O)5instead.
- For example,
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)
| File | Size | Uploaded | |
|---|---|---|---|
| pymolecule_parser-0.1.0.tar.gz | 12.7 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| 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
|