https://github.com/cgohlke/molmass

Molecular mass calculations.

https://github.com/cgohlke/molmass

Science Score: 49.0%

This score indicates how likely this project is to be science-related based on various indicators:

  • CITATION.cff file
  • codemeta.json file
    Found codemeta.json file
  • .zenodo.json file
    Found .zenodo.json file
  • DOI references
    Found 3 DOI reference(s) in README
  • Academic publication links
  • Committers with academic emails
    1 of 2 committers (50.0%) from academic institutions
  • Institutional organization owner
  • JOSS paper metadata
  • Scientific vocabulary similarity
    Low similarity (13.3%) to scientific vocabulary

Keywords

chemistry mass-spectrometry python
Last synced: 6 months ago · JSON representation

Repository

Molecular mass calculations.

Basic Info
Statistics
  • Stars: 64
  • Watchers: 3
  • Forks: 14
  • Open Issues: 1
  • Releases: 9
Topics
chemistry mass-spectrometry python
Created about 6 years ago · Last pushed 6 months ago
Metadata Files
Readme License

README.rst

..
  This file is generated by setup.py

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 `_
:License: BSD-3-Clause
:Version: 2025.9.4
:DOI: `10.5281/zenodo.7135495 `_

Quickstart
----------

Install the molmass package and all dependencies from the
`Python Package Index `_::

    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 `_.

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

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

- `CPython `_ 3.11.9, 3.12.10, 3.13.7, 3.14.0rc
- `Flask `_ 3.1.2 (optional)
- `Pandas `_ 2.3.2 (optional)
- `wxPython `_ 4.2.3 (optional)

Revisions
---------

2025.9.4

- Precompile regex patterns.
- Remove doctest command line option.
- Drop support for Python 3.10, support Python 3.14.

2025.4.14

- Add mass_charge_ratio helper function (#17).
- Drop support for Python 3.9.

2024.10.25

- Fix composition of formula with multiple isotopes of same element (#16).

2024.5.24

- Fix docstring examples not correctly rendered on GitHub.

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.
- Drop 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.
- Drop 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.
- Drop 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.
- Drop 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:

.. code-block:: python

    >>> 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:

.. code-block:: python

    >>> 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))
    ...

Owner

  • Name: Christoph Gohlke
  • Login: cgohlke
  • Kind: user
  • Location: Irvine, California

GitHub Events

Total
  • Create event: 3
  • Issues event: 2
  • Release event: 2
  • Watch event: 8
  • Issue comment event: 2
  • Push event: 2
  • Pull request event: 2
  • Fork event: 3
Last Year
  • Create event: 3
  • Issues event: 2
  • Release event: 2
  • Watch event: 8
  • Issue comment event: 2
  • Push event: 2
  • Pull request event: 2
  • Fork event: 3

Committers

Last synced: about 2 years ago

All Time
  • Total Commits: 82
  • Total Committers: 2
  • Avg Commits per committer: 41.0
  • Development Distribution Score (DDS): 0.354
Past Year
  • Commits: 28
  • Committers: 1
  • Avg Commits per committer: 28.0
  • Development Distribution Score (DDS): 0.0
Top Committers
Name Email Commits
Christoph Gohlke c****e@u****u 53
Christoph Gohlke c****e@c****m 29
Committer Domains (Top 20 + Academic)

Issues and Pull Requests

Last synced: 9 months ago

All Time
  • Total issues: 15
  • Total pull requests: 2
  • Average time to close issues: about 2 months
  • Average time to close pull requests: 11 months
  • Total issue authors: 12
  • Total pull request authors: 2
  • Average comments per issue: 1.47
  • Average comments per pull request: 3.0
  • Merged pull requests: 0
  • Bot issues: 0
  • Bot pull requests: 0
Past Year
  • Issues: 2
  • Pull requests: 1
  • Average time to close issues: 2 days
  • Average time to close pull requests: about 6 hours
  • Issue authors: 2
  • Pull request authors: 1
  • Average comments per issue: 0.5
  • Average comments per pull request: 2.0
  • Merged pull requests: 0
  • Bot issues: 0
  • Bot pull requests: 0
Top Authors
Issue Authors
  • fkromer (3)
  • JosieHong (2)
  • zpincus (1)
  • malikmubeen46 (1)
  • EmersonHernly (1)
  • bjxpolarbear (1)
  • liquidcarbon (1)
  • code4Siddharth (1)
  • oskar-november (1)
  • ginkgog (1)
  • WWilhelmsen (1)
  • gmhhope (1)
Pull Request Authors
  • gkreder (2)
  • n-elie (1)
Top Labels
Issue Labels
question (3) bug (2) enhancement (2) invalid (1)
Pull Request Labels
bug (2) enhancement (1)

Packages

  • Total packages: 2
  • Total downloads:
    • pypi 11,671 last-month
  • Total docker downloads: 10
  • Total dependent packages: 16
    (may contain duplicates)
  • Total dependent repositories: 33
    (may contain duplicates)
  • Total versions: 32
  • Total maintainers: 1
pypi.org: molmass

Molecular mass calculations

  • Versions: 16
  • Dependent Packages: 16
  • Dependent Repositories: 33
  • Downloads: 11,671 Last month
  • Docker Downloads: 10
Rankings
Dependent packages count: 1.0%
Dependent repos count: 2.5%
Docker downloads count: 3.9%
Downloads: 4.1%
Average: 5.3%
Stargazers count: 9.8%
Forks count: 10.2%
Maintainers (1)
Last synced: 6 months ago
proxy.golang.org: github.com/cgohlke/molmass
  • Versions: 16
  • Dependent Packages: 0
  • Dependent Repositories: 0
Rankings
Dependent packages count: 5.4%
Average: 5.6%
Dependent repos count: 5.8%
Last synced: 6 months ago