Skip to main content

Chemical formula parser

Project description

chemparse

Authors: Grayson Boyer and Victor Ignatenko

A lightweight package for parsing chemical formula strings into python dictionaries.

Features

  • Convert a chemical formula string into a python dictionary.
    • example: "CH4" returns {"C":1.0, "H":4.0}
  • Handles fractional stoichiometry.
    • example: "C1.5O3" returns {"C":1.5, "O":3.0}
    • example: "H2e-1O1e-1" returns {"H":0.2, "O":0.1}
  • Handles groups with parentheses.
    • example: "(CH3)2(CH2)4" returns {"C":6.0, "H":14.0}
  • New in 2024: Chemparse now handles nested paretheses!
    • example: "((CH3)2)3" returns {'C': 6, 'H': 18}
  • New in 2024: Chemparse now handles square brackets
    • example: "K4[Fe(SCN)6]" returns {'Fe': 1.0, 'K': 4.0, 'N': 6.0, 'S': 6.0, 'C': 6.0}

Installation

Install chemparse with pip:

$ pip install chemparse

Usage

Import chemparse in python and use the parse_formula function:

import chemparse

print(chemparse.parse_formula("C6H12O6"))

Contribute

Install python

Clone chemparse using git:
git clone https://github.com/gmboyer/chemparse.git

Go to the chemparse directory:
cd chemparse

Install requirements:
pip install -r requirements.txt

Now you are ready to contribute!

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

chemparse-0.3.1.tar.gz (5.5 kB view details)

Uploaded Source

Built Distribution

chemparse-0.3.1-py3-none-any.whl (5.9 kB view details)

Uploaded Python 3

File details

Details for the file chemparse-0.3.1.tar.gz.

File metadata

  • Download URL: chemparse-0.3.1.tar.gz
  • Upload date:
  • Size: 5.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.10.12

File hashes

Hashes for chemparse-0.3.1.tar.gz
Algorithm Hash digest
SHA256 e7ad0b7522b091c27eaca5821ae44142cfff75a9ef71cf7b063106a57ffee337
MD5 cfe4fa1beb3bb8f7a82c6b03261e4561
BLAKE2b-256 cd66cf9523a93c27cb3b6e5479786a55177ccabe9cc4911817c6db7602d5bb03

See more details on using hashes here.

File details

Details for the file chemparse-0.3.1-py3-none-any.whl.

File metadata

  • Download URL: chemparse-0.3.1-py3-none-any.whl
  • Upload date:
  • Size: 5.9 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.10.12

File hashes

Hashes for chemparse-0.3.1-py3-none-any.whl
Algorithm Hash digest
SHA256 be3e3d9aaf197800dd0c2c0f729c97c5473b7a03e0835ed6b46a520b586e5073
MD5 231ed8f3bf492ceb941c8b4daa753a6a
BLAKE2b-256 354b8d361c2c996a8883da1a863bcc9e4808a1075f20078f8eba7d37741beb0a

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