# thermo.elements module¶

class thermo.elements.PeriodicTable(elements)[source]

Bases: object

Periodic Table object for use in dealing with elements.

Parameters: elements : list[Element] List of Element objects

periodic_table, Element

Notes

Can be checked to sese if an element in in this, can be iterated over, and as a current length of 118 elements.

References

 [R280285] 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
CAS_to_elements
name_to_elements
number_to_elements
symbol_to_elements
thermo.elements.molecular_weight(atoms)[source]

Calculates 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, [-] MW : float Calculated molecular weight [g/mol]

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.

References

 [R281286] RDKit: Open-source cheminformatics; http://www.rdkit.org

Examples

>>> molecular_weight({'H': 12, 'C': 20, 'O': 5}) # DNA
332.30628

thermo.elements.mass_fractions(atoms, MW=None)[source]

Calculates 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] mfracs : dict dictionary of mass fractions of individual atoms, indexed by symbol with proper capitalization, [-]

Notes

Molecular weight is optional, but speeds up the calculation slightly. It is calculated using the function 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.

References

 [R282287] RDKit: Open-source cheminformatics; http://www.rdkit.org

Examples

>>> mass_fractions({'H': 12, 'C': 20, 'O': 5})
{'H': 0.03639798802478244, 'C': 0.7228692758981262, 'O': 0.24073273607709128}

thermo.elements.atom_fractions(atoms)[source]

Calculates 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, [-] afracs : dict dictionary of atomic fractions of individual atoms, indexed by symbol with proper capitalization, [-]

Notes

No actual data on the elements is used, so incorrect or custom compounds would not raise an error.

References

 [R283288] RDKit: Open-source cheminformatics; http://www.rdkit.org

Examples

>>> atom_fractions({'H': 12, 'C': 20, 'O': 5})
{'H': 0.32432432432432434, 'C': 0.5405405405405406, 'O': 0.13513513513513514}

thermo.elements.similarity_variable(atoms, MW=None)[source]

Calculates the similarity variable of an compound, as defined in [R284289]. 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] similarity_variable : float Similarity variable as defined in [R284289], [mol/g]

Notes

Molecular weight is optional, but speeds up the calculation slightly. It is calculated using the function molecular_weight if not specified.

References

 [R284289] (1, 2, 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.

Examples

>>> similarity_variable({'H': 32, 'C': 15})
0.2212654140784498

thermo.elements.atoms_to_Hill(atoms)[source]

Determine the Hill formula of a compound, 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, [-] Hill_formula : str Hill formula, [-]

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.

References

 [R285290] 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.

Examples

>>> atoms_to_Hill({'H': 5, 'C': 2, 'Br': 1})
'C2H5Br'

thermo.elements.simple_formula_parser(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. atoms : dict dictionary of counts of individual atoms, indexed by symbol with proper capitalization, [-]

Notes

Inspiration taken from the thermopyl project, at https://github.com/choderalab/thermopyl.

Examples

>>> simple_formula_parser('CO2')
{'C': 1, 'O': 2}

thermo.elements.nested_formula_parser(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, [-] atoms : dict dictionary of counts of individual atoms, indexed by symbol with proper capitalization, [-]

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(nested_formula_parser('Pd(NH3)4.0001+2'))
{'H': 12.0003, 'N': 4.0001, 'Pd': 1}

thermo.elements.CAS_by_number = ['12385-13-6', '7440-59-7', '7439-93-2', '7440-41-7', '7440-42-8', '7440-44-0', '17778-88-0', '17778-80-2', '14762-94-8', '7440-01-9', '7440-23-5', '7439-95-4', '7429-90-5', '7440-21-3', '7723-14-0', '7704-34-9', '22537-15-1', '7440-37-1', '7440-09-7', '7440-70-2', '7440-20-2', '7440-32-6', '7440-62-2', '7440-47-3', '7439-96-5', '7439-89-6', '7440-48-4', '7440-02-0', '7440-50-8', '7440-66-6', '7440-55-3', '7440-56-4', '7440-38-2', '7782-49-2', '10097-32-2', '7439-90-9', '7440-17-7', '7440-24-6', '7440-65-5', '7440-67-7', '7440-03-1', '7439-98-7', '7440-26-8', '7440-18-8', '7440-16-6', '7440-05-3', '7440-22-4', '7440-43-9', '7440-74-6', '7440-31-5', '7440-36-0', '13494-80-9', '7553-56-2', '7440-63-3', '7440-46-2', '7440-39-3', '7439-91-0', '7440-45-1', '7440-10-0', '7440-00-8', '7440-12-2', '7440-19-9', '7440-53-1', '7440-54-2', '7440-27-9', '7429-91-6', '7440-60-0', '7440-52-0', '7440-30-4', '7440-64-4', '7439-94-3', '7440-58-6', '7440-25-7', '7440-33-7', '7440-15-5', '7440-04-2', '7439-88-5', '7440-06-4', '7440-57-5', '7439-97-6', '7440-28-0', '7439-92-1', '7440-69-9', '7440-08-6', '7440-68-8', '10043-92-2', '7440-73-5', '7440-14-4', '7440-34-8', '7440-29-1', '7440-13-3', '7440-61-1', '7439-99-8', '7440-07-5', '7440-35-9', '7440-51-9', '7440-40-6', '7440-71-3', '7429-92-7', '7440-72-4', '7440-11-1', '10028-14-5', '22537-19-5', '53850-36-5', '53850-35-4', '54038-81-2', '54037-14-8', '54037-57-9', '54038-01-6', '54083-77-1', '54386-24-2', '54084-26-3', '54084-70-7', '54085-16-4', '54085-64-2', '54100-71-9', '54101-14-3', '54144-19-3']

CAS numbers of the elements, indexed by atomic numbers off-by-one up to 118.

thermo.elements.periods = [1, 1, 2, 2, 2, 2, 2, 2, 2, 2, 3, 3, 3, 3, 3, 3, 3, 3, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7]

Periods of the elements, indexed by atomic numbers off-by-one up to 118.

thermo.elements.groups = [1, 18, 1, 2, 13, 14, 15, 16, 17, 18, 1, 2, 13, 14, 15, 16, 17, 18, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 1, 2, None, None, None, None, None, None, None, None, None, None, None, None, None, None, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 1, 2, None, None, None, None, None, None, None, None, None, None, None, None, None, None, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18]

Groups of the elements, indexed by atomic numbers off-by-one up to 118. Lanthanides and Actinides are set to None.

thermo.elements.blocks = {'d': [21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 71, 72, 73, 74, 75, 76, 77, 78, 79, 80, 103, 104, 105, 106, 107, 108, 109, 110, 111, 112], 'f': [57, 58, 59, 60, 61, 62, 63, 64, 65, 66, 67, 68, 69, 70, 89, 90, 91, 92, 93, 94, 95, 96, 97, 98, 99, 100, 101, 102], 'p': [5, 6, 7, 8, 9, 10, 13, 14, 15, 16, 17, 18, 31, 32, 33, 34, 35, 36, 49, 50, 51, 52, 53, 54, 81, 82, 83, 84, 85, 86, 113, 114, 115, 116, 117, 118], 's': [1, 2, 3, 4, 11, 12, 19, 20, 37, 38, 55, 56, 87, 88]}

Blocks of the elements, stored in a dictionary with four keys and lists. Indexed by atomic numbers off-by-one up to 118.

thermo.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. charge : int Charge of the molecule, [faraday]

Examples

>>> charge_from_formula('Br3-')
-1
>>> charge_from_formula('Br3(-)')
-1

thermo.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 nested_formula_parser, [-] formula : str A consistently formatted formula to describe a molecular formula, [-]

Examples

>>> serialize_formula('Pd(NH3)4+3')
'H12N4Pd+3'