chemcalculator

Subpackages

Submodules

Package Contents

Functions

compute_mass(chemical)

Computes the molar mass of the given chemical compound.

moles_grams_converter(formula, mass, convert_from)

Converts moles to grams or grams to moles

percent_mass(compound, element)

Calculates the percentage mass of an element (or compound) in a compound

Attributes

__version__

chemcalculator.__version__
chemcalculator.compute_mass(chemical)[source]

Computes the molar mass of the given chemical compound.

Parameters

chemical (string) – The molecular formula of the given chemical compound given as a string.

Returns

The molar mass of the given formula in g/mol.

Return type

float

Raises
  • TypeError – Entered value is not a string.

  • ValueError – String contains characters that are not allowed.

  • ValueError – String or subcomponent starts with lowercase letter.

  • ValueError – Chemical compound contains element not in periodic table.

Examples

>>> compute_mass("H2O")
18.01528
>>> compute_mass("C12H22O11")
342.3
>>> compute_mass("Al2(SO4)3")
342.15
>>> compute_mass("(NH4)HS")
51.107
chemcalculator.moles_grams_converter(formula, mass, convert_from)[source]

Converts moles to grams or grams to moles

Parameters
  • formula (string) – the checmical formula for the conversion

  • mass (float) – the mass of molecule that needs to be converted (grams or moles)

  • converter (string) – indicates to convert either “moles” or “grams”

Returns

mass that is converted to either moles or grams

Return type

float

Examples

>>> moles_grams_converter("H2O", 0.05555, "moles")
1.000
>>> moles_grams_converter("H2O", 18.01528, "grams")
1.000
chemcalculator.percent_mass(compound, element)[source]

Calculates the percentage mass of an element (or compound) in a compound

Parameters
  • compound (string) – the chemical formula of the full compound

  • element (string) – the chemical formula of the element or compound of interest

Returns

the percentage mass of the element or compound of interest

Return type

float

Examples

>>> percent_mass("H2O", "O")
88.819
>>> percent_mass("H2O", "H")
5.59
>>> percent_mass("H2O", "H2")
11.181
>>> percent_mass("NaOH", "OH")
42.519