molmass


Namemolmass JSON
Version 2024.5.24 PyPI version JSON
download
home_pagehttps://www.cgohlke.com
SummaryMolecular mass calculations
upload_time2024-05-23 19:53:21
maintainerNone
docs_urlNone
authorChristoph Gohlke
requires_python>=3.9
licenseBSD
keywords
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            Molecular mass calculations
===========================

Molmass is a Python library, console script, and web application to calculate
the molecular mass (average, nominal, and isotopic pure), the elemental
composition, and the mass distribution spectrum of a molecule given by its
chemical formula, relative element weights, or sequence.

Calculations are based on the isotopic composition of the elements. Mass
deficiency due to chemical bonding is not taken into account.

The library includes a database of physicochemical and descriptive properties
of the chemical elements.

:Author: `Christoph Gohlke <https://www.cgohlke.com>`_
:License: BSD 3-Clause
:Version: 2024.5.24
:DOI: `10.5281/zenodo.7135495 <https://doi.org/10.5281/zenodo.7135495>`_

Quickstart
----------

Install the molmass package and all dependencies from the
`Python Package Index <https://pypi.org/project/molmass/>`_::

    python -m pip install -U "molmass[all]"

Print the console script usage::

    python -m molmass --help

Run the web application::

    python -m molmass --web

The molmass library is documented via docstrings.

See `Examples`_ for using the programming interface.

Source code and support are available on
`GitHub <https://github.com/cgohlke/molmass>`_.

Requirements
------------

This revision was tested with the following requirements and dependencies
(other versions may work):

- `CPython <https://www.python.org>`_ 3.9.13, 3.10.11, 3.11.9, 3.12.3
- `Flask <https://pypi.org/project/Flask/>`_ 3.0.3 (optional)
- `Pandas <https://pypi.org/project/pandas/>`_ 2.2.2 (optional)
- `wxPython <https://pypi.org/project/wxPython/>`_ 4.2.1 (optional)

Revisions
---------

2024.5.24

- Fix GitHub not correctly rendering docstring examples.

2024.5.10

- Add options to disable parsing groups, oligos, fractions, arithmetic (#14).
- Add Formula.expanded property.

2023.8.30

- Fix linting issues.
- Add py.typed marker.
- Remove support for Python 3.8.

2023.4.10

- Support rdkit-style ionic charges (#11, #12).
- Enable multiplication without addition in from_string.

2022.12.9

- Fix split_charge formula with trailing ]] (#11).

2022.10.18

- Several breaking changes.
- Add experimental support for ion charges (#5).
- Change Element, Isotope, and Particle to dataclass (breaking).
- Change types of Spectrum and Composition (breaking).
- Add functions to export Spectrum and Composition as Pandas DataFrames.
- Replace lazyattr with functools.cached_property.
- Rename molmass_web to web (breaking).
- Change output of web application (breaking).
- Run web application using Flask if installed.
- Add options to specify URL of web application and not opening web browser.
- Convert to Google style docstrings.
- Add type hints.
- Remove support for Python 3.7.

2021.6.18

- Add Particle types to elements (#5).
- Fix molmass_web failure on WSL2 (#9).
- Fix elements_gui layout issue.
- Remove support for Python 3.6.

2020.6.10

- Fix elements_gui symbol size on WSL2.
- Support wxPython 4.1.

2020.1.1

- Update elements atomic weights and isotopic compositions from NIST.
- Move element descriptions into separate module.
- Remove support for Python 2.7 and 3.5.

2018.8.15

- Move modules into molmass package.

2018.5.29

- Add option to start web interface from console.
- Separate styles from content and use CSS flex layout in molmass_web.

2018.5.25

- Style and docstring fixes.
- Make from_fractions output deterministic.
- Accept Flask request.args in molmass_web.
- Style and template changes in molmass_web.

2016.2.25

- Fix some elements ionization energies.

2005.x.x

- Initial release.

Examples
--------

Calculate the molecular mass, elemental composition, and mass distribution of
a molecule from its chemical formula:

>>> from molmass import Formula
>>> f = Formula('C8H10N4O2')  # Caffeine
>>> f
Formula('C8H10N4O2')
>>> f.formula  # hill notation
'C8H10N4O2'
>>> f.empirical
'C4H5N2O'
>>> f.mass  # average mass
194.1909...
>>> f.nominal_mass  # == f.isotope.massnumber
194
>>> f.monoisotopic_mass  # == f.isotope.mass
194.0803...
>>> f.atoms
24
>>> f.charge
0
>>> f.composition().dataframe()
         Count  Relative mass  Fraction
Element...
C            8      96.085920  0.494801
H           10      10.079410  0.051905
N            4      56.026812  0.288514
O            2      31.998810  0.164780
>>> f.spectrum(min_intensity=0.01).dataframe()
             Relative mass  Fraction  Intensity %         m/z
Mass number...
194             194.080376  0.898828   100.000000  194.080376
195             195.082873  0.092625    10.305100  195.082873
196             196.084968  0.008022     0.892492  196.084968
197             197.087214  0.000500     0.055681  197.087214

Access physicochemical and descriptive properties of the chemical elements:

>>> from molmass import ELEMENTS, Element
>>> e = ELEMENTS['C']
>>> e
Element(
    6, 'C', 'Carbon',
    group=14, period=2, block='p', series=1,
    mass=12.01074, eleneg=2.55, eleaffin=1.262118,
    covrad=0.77, atmrad=0.91, vdwrad=1.7,
    tboil=5100.0, tmelt=3825.0, density=3.51,
    eleconfig='[He] 2s2 2p2',
    oxistates='4*, 2, -4*',
    ionenergy=(
        11.2603, 24.383, 47.877, 64.492, 392.077,
        489.981,
    ),
    isotopes={
        12: Isotope(12.0, 0.9893, 12),
        13: Isotope(13.00335483507, 0.0107, 13),
    },
)
>>> e.number
6
>>> e.symbol
'C'
>>> e.name
'Carbon'
>>> e.description
'Carbon is a member of group 14 of the periodic table...'
>>> e.eleconfig
'[He] 2s2 2p2'
>>> e.eleconfig_dict
{(1, 's'): 2, (2, 's'): 2, (2, 'p'): 2}
>>> str(ELEMENTS[6])
'Carbon'
>>> len(ELEMENTS)
109
>>> sum(e.mass for e in ELEMENTS)
14693.181589001...
>>> for e in ELEMENTS:
...     e.validate()
...     e = eval(repr(e))
...

            

Raw data

            {
    "_id": null,
    "home_page": "https://www.cgohlke.com",
    "name": "molmass",
    "maintainer": null,
    "docs_url": null,
    "requires_python": ">=3.9",
    "maintainer_email": null,
    "keywords": null,
    "author": "Christoph Gohlke",
    "author_email": "cgohlke@cgohlke.com",
    "download_url": "https://files.pythonhosted.org/packages/0a/1a/31d0b556c578551beb3a41ef972cfbaec938ca8f9f0442a119782edb8807/molmass-2024.5.24.tar.gz",
    "platform": "any",
    "description": "Molecular mass calculations\r\n===========================\r\n\r\nMolmass is a Python library, console script, and web application to calculate\r\nthe molecular mass (average, nominal, and isotopic pure), the elemental\r\ncomposition, and the mass distribution spectrum of a molecule given by its\r\nchemical formula, relative element weights, or sequence.\r\n\r\nCalculations are based on the isotopic composition of the elements. Mass\r\ndeficiency due to chemical bonding is not taken into account.\r\n\r\nThe library includes a database of physicochemical and descriptive properties\r\nof the chemical elements.\r\n\r\n:Author: `Christoph Gohlke <https://www.cgohlke.com>`_\r\n:License: BSD 3-Clause\r\n:Version: 2024.5.24\r\n:DOI: `10.5281/zenodo.7135495 <https://doi.org/10.5281/zenodo.7135495>`_\r\n\r\nQuickstart\r\n----------\r\n\r\nInstall the molmass package and all dependencies from the\r\n`Python Package Index <https://pypi.org/project/molmass/>`_::\r\n\r\n    python -m pip install -U \"molmass[all]\"\r\n\r\nPrint the console script usage::\r\n\r\n    python -m molmass --help\r\n\r\nRun the web application::\r\n\r\n    python -m molmass --web\r\n\r\nThe molmass library is documented via docstrings.\r\n\r\nSee `Examples`_ for using the programming interface.\r\n\r\nSource code and support are available on\r\n`GitHub <https://github.com/cgohlke/molmass>`_.\r\n\r\nRequirements\r\n------------\r\n\r\nThis revision was tested with the following requirements and dependencies\r\n(other versions may work):\r\n\r\n- `CPython <https://www.python.org>`_ 3.9.13, 3.10.11, 3.11.9, 3.12.3\r\n- `Flask <https://pypi.org/project/Flask/>`_ 3.0.3 (optional)\r\n- `Pandas <https://pypi.org/project/pandas/>`_ 2.2.2 (optional)\r\n- `wxPython <https://pypi.org/project/wxPython/>`_ 4.2.1 (optional)\r\n\r\nRevisions\r\n---------\r\n\r\n2024.5.24\r\n\r\n- Fix GitHub not correctly rendering docstring examples.\r\n\r\n2024.5.10\r\n\r\n- Add options to disable parsing groups, oligos, fractions, arithmetic (#14).\r\n- Add Formula.expanded property.\r\n\r\n2023.8.30\r\n\r\n- Fix linting issues.\r\n- Add py.typed marker.\r\n- Remove support for Python 3.8.\r\n\r\n2023.4.10\r\n\r\n- Support rdkit-style ionic charges (#11, #12).\r\n- Enable multiplication without addition in from_string.\r\n\r\n2022.12.9\r\n\r\n- Fix split_charge formula with trailing ]] (#11).\r\n\r\n2022.10.18\r\n\r\n- Several breaking changes.\r\n- Add experimental support for ion charges (#5).\r\n- Change Element, Isotope, and Particle to dataclass (breaking).\r\n- Change types of Spectrum and Composition (breaking).\r\n- Add functions to export Spectrum and Composition as Pandas DataFrames.\r\n- Replace lazyattr with functools.cached_property.\r\n- Rename molmass_web to web (breaking).\r\n- Change output of web application (breaking).\r\n- Run web application using Flask if installed.\r\n- Add options to specify URL of web application and not opening web browser.\r\n- Convert to Google style docstrings.\r\n- Add type hints.\r\n- Remove support for Python 3.7.\r\n\r\n2021.6.18\r\n\r\n- Add Particle types to elements (#5).\r\n- Fix molmass_web failure on WSL2 (#9).\r\n- Fix elements_gui layout issue.\r\n- Remove support for Python 3.6.\r\n\r\n2020.6.10\r\n\r\n- Fix elements_gui symbol size on WSL2.\r\n- Support wxPython 4.1.\r\n\r\n2020.1.1\r\n\r\n- Update elements atomic weights and isotopic compositions from NIST.\r\n- Move element descriptions into separate module.\r\n- Remove support for Python 2.7 and 3.5.\r\n\r\n2018.8.15\r\n\r\n- Move modules into molmass package.\r\n\r\n2018.5.29\r\n\r\n- Add option to start web interface from console.\r\n- Separate styles from content and use CSS flex layout in molmass_web.\r\n\r\n2018.5.25\r\n\r\n- Style and docstring fixes.\r\n- Make from_fractions output deterministic.\r\n- Accept Flask request.args in molmass_web.\r\n- Style and template changes in molmass_web.\r\n\r\n2016.2.25\r\n\r\n- Fix some elements ionization energies.\r\n\r\n2005.x.x\r\n\r\n- Initial release.\r\n\r\nExamples\r\n--------\r\n\r\nCalculate the molecular mass, elemental composition, and mass distribution of\r\na molecule from its chemical formula:\r\n\r\n>>> from molmass import Formula\r\n>>> f = Formula('C8H10N4O2')  # Caffeine\r\n>>> f\r\nFormula('C8H10N4O2')\r\n>>> f.formula  # hill notation\r\n'C8H10N4O2'\r\n>>> f.empirical\r\n'C4H5N2O'\r\n>>> f.mass  # average mass\r\n194.1909...\r\n>>> f.nominal_mass  # == f.isotope.massnumber\r\n194\r\n>>> f.monoisotopic_mass  # == f.isotope.mass\r\n194.0803...\r\n>>> f.atoms\r\n24\r\n>>> f.charge\r\n0\r\n>>> f.composition().dataframe()\r\n         Count  Relative mass  Fraction\r\nElement...\r\nC            8      96.085920  0.494801\r\nH           10      10.079410  0.051905\r\nN            4      56.026812  0.288514\r\nO            2      31.998810  0.164780\r\n>>> f.spectrum(min_intensity=0.01).dataframe()\r\n             Relative mass  Fraction  Intensity %         m/z\r\nMass number...\r\n194             194.080376  0.898828   100.000000  194.080376\r\n195             195.082873  0.092625    10.305100  195.082873\r\n196             196.084968  0.008022     0.892492  196.084968\r\n197             197.087214  0.000500     0.055681  197.087214\r\n\r\nAccess physicochemical and descriptive properties of the chemical elements:\r\n\r\n>>> from molmass import ELEMENTS, Element\r\n>>> e = ELEMENTS['C']\r\n>>> e\r\nElement(\r\n    6, 'C', 'Carbon',\r\n    group=14, period=2, block='p', series=1,\r\n    mass=12.01074, eleneg=2.55, eleaffin=1.262118,\r\n    covrad=0.77, atmrad=0.91, vdwrad=1.7,\r\n    tboil=5100.0, tmelt=3825.0, density=3.51,\r\n    eleconfig='[He] 2s2 2p2',\r\n    oxistates='4*, 2, -4*',\r\n    ionenergy=(\r\n        11.2603, 24.383, 47.877, 64.492, 392.077,\r\n        489.981,\r\n    ),\r\n    isotopes={\r\n        12: Isotope(12.0, 0.9893, 12),\r\n        13: Isotope(13.00335483507, 0.0107, 13),\r\n    },\r\n)\r\n>>> e.number\r\n6\r\n>>> e.symbol\r\n'C'\r\n>>> e.name\r\n'Carbon'\r\n>>> e.description\r\n'Carbon is a member of group 14 of the periodic table...'\r\n>>> e.eleconfig\r\n'[He] 2s2 2p2'\r\n>>> e.eleconfig_dict\r\n{(1, 's'): 2, (2, 's'): 2, (2, 'p'): 2}\r\n>>> str(ELEMENTS[6])\r\n'Carbon'\r\n>>> len(ELEMENTS)\r\n109\r\n>>> sum(e.mass for e in ELEMENTS)\r\n14693.181589001...\r\n>>> for e in ELEMENTS:\r\n...     e.validate()\r\n...     e = eval(repr(e))\r\n...\r\n",
    "bugtrack_url": null,
    "license": "BSD",
    "summary": "Molecular mass calculations",
    "version": "2024.5.24",
    "project_urls": {
        "Bug Tracker": "https://github.com/cgohlke/molmass/issues",
        "Homepage": "https://www.cgohlke.com",
        "Source Code": "https://github.com/cgohlke/molmass"
    },
    "split_keywords": [],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "ac6050392174a6db67a49ac7ee40f835297846c4d9d139664507010e68c9f354",
                "md5": "20fe1639b316dd1508af08aae9cdea26",
                "sha256": "e1f3443ccaa0ce0946544d76bc460d70a901e04cebc9db324f079f0bc00f8aeb"
            },
            "downloads": -1,
            "filename": "molmass-2024.5.24-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "20fe1639b316dd1508af08aae9cdea26",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.9",
            "size": 75212,
            "upload_time": "2024-05-23T19:53:19",
            "upload_time_iso_8601": "2024-05-23T19:53:19.328761Z",
            "url": "https://files.pythonhosted.org/packages/ac/60/50392174a6db67a49ac7ee40f835297846c4d9d139664507010e68c9f354/molmass-2024.5.24-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "0a1a31d0b556c578551beb3a41ef972cfbaec938ca8f9f0442a119782edb8807",
                "md5": "b8807c8a7248c923d85c973483b50d61",
                "sha256": "583492ac061f2d20a0badfa174dd5f7ff8d0e4927005578cc656abaac94552f8"
            },
            "downloads": -1,
            "filename": "molmass-2024.5.24.tar.gz",
            "has_sig": false,
            "md5_digest": "b8807c8a7248c923d85c973483b50d61",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.9",
            "size": 76083,
            "upload_time": "2024-05-23T19:53:21",
            "upload_time_iso_8601": "2024-05-23T19:53:21.233199Z",
            "url": "https://files.pythonhosted.org/packages/0a/1a/31d0b556c578551beb3a41ef972cfbaec938ca8f9f0442a119782edb8807/molmass-2024.5.24.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2024-05-23 19:53:21",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "cgohlke",
    "github_project": "molmass",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": false,
    "lcname": "molmass"
}
        
Elapsed time: 0.67984s