Composition¶
Describes an arbitrary elemental composition
-
class
glypy.composition.composition.
PComposition
(*args, **kwargs)[source]¶ Bases:
collections.defaultdict
Represent arbitrary elemental compositions
-
__init__
(*args, **kwargs)[source]¶ 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.
-
-
glypy.composition.composition.
_make_isotope_string
(element_name, isotope_num)[source]¶ Form a string label for an isotope.
-
glypy.composition.composition.
_parse_isotope_string
(label)[source]¶ Parse an string with an isotope label and return the element name and the isotope number.
>>> _parse_isotope_string('C') ('C', 0) >>> _parse_isotope_string('C[12]') ('C', 12)
-
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 : float
The relative abundance of a given isotopic composition.
-
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
, optionalA
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: tuple (
Composition
, float)A tuple with the most probable isotopic composition and its relative abundance.
-
glypy.composition.composition.
pcalculate_mass
(composition=None, formula=None, average=False, charge=None, mass_data=None)[source]¶ Calculates the monoisotopic mass of a chemical formula or Composition object.
Parameters: composition : Composition, optional
A Composition object with the elemental composition of a substance.
average : bool, optional
If
True
then the average mass is calculated. Note that mass is not averaged for elements with specified isotopes. Default isFalse
.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 : float
-
glypy.composition.composition.
Composition
¶ alias of
CComposition
-
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 isFalse
.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 : float