Composition

Describes an arbitrary elemental composition

class glypy.composition.composition.CComposition

A Composition object stores a chemical composition of a substance. Basically it is a dict object, in which keys are the names of chemical elements and values contain integer numbers of corresponding atoms in a substance.

The main improvement over dict is that Composition objects allow addition and subtraction.

If formula is not specified, the constructor will look at the first positional argument and try to build the object from it. Without positional arguments, a Composition will be constructed directly from keyword arguments.

Parameters
  • formula (str, optional) – A string with a chemical formula. All elements must be present in mass_data.

  • mass_data (dict, optional) – A dict with the masses of chemical elements (the default value is nist_mass). It is used for formulae parsing only.

__getitem__()

x.__getitem__(y) <==> x[y]

__setitem__(key, value, /)

Set self[key] to value.

items() a set-like object providing a view on D's items
keys() a set-like object providing a view on D's keys
values() an object providing a view on D's values
glypy.composition.composition.calculate_mass()

Calculates the monoisotopic mass of a chemical formula or CComposition object.

Parameters
  • composition (CComposition) – A Composition object with the elemental composition of a substance. Exclusive with formula

  • formula (str) – A string describing a chemical composition. Exclusive with composition

  • average (bool, optional) – If True then the average mass is calculated. Note that mass is not averaged for elements with specified isotopes. Default is False.

  • charge (int, optional) – If not 0 then m/z is calculated: the mass is increased by the corresponding number of proton masses and divided by z.

  • mass_data (dict, optional) – A dict with the masses of the chemical elements (the default value is nist_mass).

Returns

mass

Return type

float

glypy.composition.composition.formula(composition)[source]
glypy.composition.composition.most_probable_isotopic_composition(*args, **kwargs)[source]

Calculate the most probable isotopic composition of a chemical formula or Composition object.

For each element, only two most abundant isotopes are considered.

Parameters
  • formula (str, optional) – A string with a chemical formula.

  • composition (Composition, optional) – A Composition object with the elemental composition of a substance.

  • elements_with_isotopes (list of str) – A list of elements to be considered in isotopic distribution (by default, every element has a isotopic distribution).

  • mass_data (dict, optional) – A dict with the masses of chemical elements (.

Returns

out – A tuple with the most probable isotopic composition and its relative abundance.

Return type

tuple (Composition, float)

glypy.composition.composition.isotopic_composition_abundance(*args, **kwargs)[source]

Calculate the relative abundance of a given isotopic composition of a molecule.

Parameters
  • formula (str, optional) – A string with a chemical formula.

  • composition (Composition, optional) – A Composition object with the isotopic composition of a substance.

  • mass_data (dict, optional) – A dict with the masses of chemical elements (the default value is nist_mass).

Returns

relative_abundance – The relative abundance of a given isotopic composition.

Return type

float