elements¶
This module includes elemental data taken from 1 and 2, and functions to calculate molecular properties from elemental data.
References
- 1(1,2)
N M O’Boyle, M Banck, C A James, C Morley, T Vandermeersch, and G R Hutchison. “Open Babel: An open chemical toolbox.” J. Cheminf. (2011), 3, 33. DOI:10.1186/1758-2946-3-33
- 2
RDKit: Open-source cheminformatics; http://www.rdkit.org
- 3
Laštovka, Václav, Nasser Sallamie, and John M. Shaw. “A Similarity Variable for Estimating the Heat Capacity of Solid Organic Compounds: Part I. Fundamentals.” Fluid Phase Equilibria 268, no. 1-2 (June 25, 2008): 51-60. doi:10.1016/j.fluid.2008.03.019.
- 4
Hill, Edwin A.”“ON A SYSTEM OF INDEXING CHEMICAL LITERATURE; ADOPTED BY THE CLASSIFICATION DIVISION OF THE U. S. PATENT OFFICE.1.” Journal of the American Chemical Society 22, no. 8 (August 1, 1900): 478-94. doi:10.1021/ja02046a005.
-
class
thermosteam.properties.elements.
PeriodicTable
(elements)[source]¶ Periodic Table object for use in dealing with elements.
- Parameters
elements (Iterable[Element]) – List of Element objects
Notes
Has a length of 118 elements.
See also
periodic_table
,Element
-
thermosteam.properties.elements.
compute_molecular_weight
(atoms)[source]¶ Return molecular weight of a molecule given a dictionary of its atoms and their counts, in the format {symbol: count}.
\[MW = \sum_i n_i MW_i\]- Parameters
atoms (dict) – dictionary of counts of individual atoms, indexed by symbol with proper capitalization, [-]
- Returns
MW – Calculated molecular weight [g/mol]
- Return type
float
Notes
Elemental data is from rdkit, with CAS numbers added. An exception is raised if an incorrect element symbol is given. Elements up to 118 are supported, as are deutreium and tritium.
Examples
>>> compute_molecular_weight({'H': 12, 'C': 20, 'O': 5}) # DNA 332.30628
-
thermosteam.properties.elements.
compute_mass_fractions
(atoms, MW=None)[source]¶ Return the mass fractions of each element in a compound, given a dictionary of its atoms and their counts, in the format {symbol: count}.
\[w_i = \frac{n_i MW_i}{\sum_i n_i MW_i}\]- Parameters
atoms (dict) – dictionary of counts of individual atoms, indexed by symbol with proper capitalization, [-]
MW (float, optional) – Molecular weight, [g/mol]
- Returns
mfracs – dictionary of mass fractions of individual atoms, indexed by symbol with proper capitalization, [-]
- Return type
dict
Notes
Molecular weight is optional, but speeds up the calculation slightly. It is calculated using the function compute_molecular_weight if not specified.
Elemental data is from rdkit, with CAS numbers added. An exception is raised if an incorrect element symbol is given. Elements up to 118 are supported.
Examples
>>> compute_mass_fractions({'H': 12, 'C': 20, 'O': 5}) {'H': 0.03639798802478244, 'C': 0.7228692758981262, 'O': 0.24073273607709128}
-
thermosteam.properties.elements.
compute_atom_fractions
(atoms)[source]¶ Return the atomic fractions of each element in a compound, given a dictionary of its atoms and their counts, in the format {symbol: count}.
\[a_i = \frac{n_i}{\sum_i n_i}\]- Parameters
atoms (dict) – dictionary of counts of individual atoms, indexed by symbol with proper capitalization, [-]
- Returns
afracs – dictionary of atomic fractions of individual atoms, indexed by symbol with proper capitalization, [-]
- Return type
dict
Notes
No actual data on the elements is used, so incorrect or custom compounds would not raise an error.
Examples
>>> compute_atom_fractions({'H': 12, 'C': 20, 'O': 5}) {'H': 0.32432432432432434, 'C': 0.5405405405405406, 'O': 0.13513513513513514}
-
thermosteam.properties.elements.
compute_similarity_variable
(atoms, MW=None)[source]¶ Return the similarity variable of an compound, as defined in 3. Currently only applied for certain heat capacity estimation routines.
\[\alpha = \frac{N}{MW} = \frac{\sum_i n_i}{\sum_i n_i MW_i}\]- Parameters
atoms (dict) – dictionary of counts of individual atoms, indexed by symbol with proper capitalization, [-]
MW (float, optional) – Molecular weight, [g/mol]
- Returns
compute_similarity_variable – Similarity variable as defined in 1, [mol/g]
- Return type
float
Notes
Molecular weight is optional, but speeds up the calculation slightly. It is calculated using the function compute_molecular_weight if not specified.
Examples
>>> compute_similarity_variable({'H': 32, 'C': 15}) 0.2212654140784498
-
thermosteam.properties.elements.
atoms_to_Hill
(atoms)[source]¶ Determine the Hill formula of a compound as in 4, given a dictionary of its atoms and their counts, in the format {symbol: count}.
- Parameters
atoms (dict) – dictionary of counts of individual atoms, indexed by symbol with proper capitalization, [-]
- Returns
Hill_formula – Hill formula, [-]
- Return type
str
Notes
The Hill system is as follows:
If the chemical has ‘C’ in it, this is listed first, and then if it has ‘H’ in it as well as ‘C’, then that goes next. All elements are sorted alphabetically afterwards, including ‘H’ if ‘C’ is not present. All elements are followed by their count, unless it is 1.
Examples
>>> atoms_to_Hill({'H': 5, 'C': 2, 'Br': 1}) 'C2H5Br'
-
thermosteam.properties.elements.
parse_simple_formula
(formula)[source]¶ Basic formula parser, primarily for obtaining element counts from formulas as formated in PubChem. Handles formulas with integer counts, but no brackets, no hydrates, no charges, no isotopes, and no group multipliers.
Strips charges from the end of a formula first. Accepts repeated chemical units. Performs no sanity checking that elements are actually elements. As it uses regular expressions for matching, errors are mostly just ignored.
- Parameters
formula (str) – Formula string, very simply formats only.
- Returns
atoms – dictionary of counts of individual atoms, indexed by symbol with proper capitalization, [-]
- Return type
dict
Notes
Inspiration taken from the thermopyl project, at https://github.com/choderalab/thermopyl.
Examples
>>> parse_simple_formula('CO2') {'C': 1, 'O': 2}
-
thermosteam.properties.elements.
parse_nested_formula
(formula, check=True)[source]¶ Improved formula parser which handles braces and their multipliers, as well as rational element counts.
Strips charges from the end of a formula first. Accepts repeated chemical units. Performs no sanity checking that elements are actually elements. As it uses regular expressions for matching, errors are mostly just ignored.
- Parameters
formula (str) – Formula string, very simply formats only.
check (bool) – If check is True, a simple check will be performed to determine if a formula is not a formula and an exception will be raised if it is not, [-]
- Returns
atoms – dictionary of counts of individual atoms, indexed by symbol with proper capitalization, [-]
- Return type
dict
Notes
Inspired by the approach taken by CrazyMerlyn on a reddit DailyProgrammer challenge, at https://www.reddit.com/r/dailyprogrammer/comments/6eerfk/20170531_challenge_317_intermediate_counting/
Examples
>>> pprint(parse_nested_formula('Pd(NH3)4.0001+2')) {'H': 12.0003, 'N': 4.0001, 'Pd': 1}
-
thermosteam.properties.elements.
charge_from_formula
(formula)[source]¶ Basic formula parser to determine the charge from a formula - given that the charge is already specified as one element of the formula.
Performs no sanity checking that elements are actually elements.
- Parameters
formula (str) – Formula string, very simply formats only, ending in one of ‘+x’, ‘-x’, n*’+’, or n*’-‘ or any of them surrounded by brackets but always at the end of a formula.
- Returns
charge – Charge of the molecule, [faraday]
- Return type
int
Notes
Examples
>>> charge_from_formula('Br3-') -1 >>> charge_from_formula('Br3(-)') -1
-
thermosteam.properties.elements.
serialize_formula
(formula)[source]¶ Basic formula serializer to construct a consistently-formatted formula. This is necessary for handling user-supplied formulas, which are not always well formatted.
Performs no sanity checking that elements are actually elements.
- Parameters
formula (str) – Formula string as parseable by the method parse_nested_formula, [-]
- Returns
formula – A consistently formatted formula to describe a molecular formula, [-]
- Return type
str
Examples
>>> serialize_formula('Pd(NH3)4+3') 'H12N4Pd+3'