Skip to main content

Calculate the Molecular Weight from an arbitrary chemical formula as a string, and process PHREEQC databases into programmable JSON files.

Project description

Background

The molecular weight (MW) can be algebraically calculated from any chemical formula that adheres to chemical conventions.

The ChemMW object of ChemW parses a chemical formula string – which consists of any combination of elements, however sensible or outrageous – and precisely calculates the MW of the chemical formula, based upon the current physical accuracy that is embedded in the periodic_table dictionary of the chemicals module.

The PHREEQdb object of ChemW parses a PHREEQ database via the ChemMW object. The object exports a JSON file that consolidate the elements and minerals, and importantly mineral masses, of the database. This unique application of the ChemMW object has been applied as the pivotal means of predicting the mass of mineral scaling in the ROSSpy module for reverse osmosis research.

The ChemW module is offered with the MIT License. Examples of the module are available in the examples directory of the ChemW GitHub repository. Please submit errors or inaccuracies as GitHub issues so that they may be resolved.

installation

The following command installs ChemW in a command prompt/terminal environment:

pip install chemw

ChemMW

__init__

The data environment, in a Python IDE, is defined:

import chemw
chem_mw = chemw.ChemMW(verbose = False, printing = True)
  • verbose & printing bool: specifies whether troubleshooting information or MW results will be printed, respectively.

mass()

The parameterized data is fitted to the Hill equation, with the following arguments and their default values:

chem_mw.mass(formula)
  • formula str: parameterizes the chemical formula for which the MW is desired. The acceptable formats for the formula are quite broad, which are exemplified in the following formulae:

Example chemical

Format example

C60_H120_O2

Underscores can arbitrarily separate content, since these are ignored by ChemMW.

'Na2.43_Cl_(OH)2_(OH)1.2_(OH)'

An arbitrary number of groups can be distinguished in the chemical formula,

with () denoting the boundaries of the specified group.

'Na2.43Cl(Ca(OH)2)1.2'

Chemical groups can be nested, with differing stoichiometric values.

'Na2.43Cl:2H2O'

Water molecules can be complexed,

with a leading stoichiometric quantity of the complexation.

'Na.96Al.96Si2.04O6:H2O'

Stoichiometry can be any decimal for any atom in a molecule,

and even omit a leading zero.

'Na2SO4:3K2SO4'

Non-water entities can be complexed.

'CaCl2:(MgCl2)2:12H2O'

Multiple complexations can be applied with repeated : separators.

'Ca1.019Na.136K.006Al2.18Si6.82O18:7.33H2O'

The complexity, while remaining within the aforementioned format, is arbitrary.

Accessible content

The ChemMW object retains numerous components that are accessible to the user:

  • mw float: The MW of the parameterized chemical formula.

  • formula str: The original chemical formula as a string.

  • groups int: A numerical counter for the quantity of chemical groups that are

  • group_masses dict: A dictionary for the masses of each nesting level in a molecule.


PHREEQdb

__init__

The data environment, in a Python IDE, is defined:

import chemw
phreeq_db = chemw.PHREEQdb(output_path = None, verbose = False, printing = False)
  • output_path str: optionally specifies an path to where the processed PHREEQ database file will be exported, where None selects the current working directory.

  • verbose & printing bool: optionally specifies whether progress or results of the calculations, respectively, are printed. The former is valuable for troubleshooting while the latter is beneficial for reviewing a readout summary of the calculations.

process()

A PHREEQ database file is processed into a JSON file of the elements and minerals, with their respective formula and MW:

phreeq_db.process(db_path)
  • db_path str: The path to where the .dat PHREEQ database file that will be processed.

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

ChemW-0.0.13.tar.gz (18.9 kB view details)

Uploaded Source

File details

Details for the file ChemW-0.0.13.tar.gz.

File metadata

  • Download URL: ChemW-0.0.13.tar.gz
  • Upload date:
  • Size: 18.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.7.1 importlib_metadata/4.10.1 pkginfo/1.8.2 requests/2.22.0 requests-toolbelt/0.9.1 tqdm/4.36.1 CPython/3.7.4

File hashes

Hashes for ChemW-0.0.13.tar.gz
Algorithm Hash digest
SHA256 57fb11c4a3a76fc29f12ec76b6defa20a55433d45eca942760b90f8aadd7ac48
MD5 00615836f78da272b847f0371ee418a0
BLAKE2b-256 94dce1608fc22776781103687081ee73dc6bc6806fccb82a01fb5a444e030e21

See more details on using hashes here.

Supported by

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