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
See also
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/17582946333 
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, []
Returns: 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: Opensource 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]
Returns: 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: Opensource 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, []
Returns: 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: Opensource 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]
Returns: 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. 12 (June 25, 2008): 5160. 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, []
Returns: 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): 47894. 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.
Returns: 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, []
Returns: 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
= ['12385136', '7440597', '7439932', '7440417', '7440428', '7440440', '17778880', '17778802', '14762948', '7440019', '7440235', '7439954', '7429905', '7440213', '7723140', '7704349', '22537151', '7440371', '7440097', '7440702', '7440202', '7440326', '7440622', '7440473', '7439965', '7439896', '7440484', '7440020', '7440508', '7440666', '7440553', '7440564', '7440382', '7782492', '10097322', '7439909', '7440177', '7440246', '7440655', '7440677', '7440031', '7439987', '7440268', '7440188', '7440166', '7440053', '7440224', '7440439', '7440746', '7440315', '7440360', '13494809', '7553562', '7440633', '7440462', '7440393', '7439910', '7440451', '7440100', '7440008', '7440122', '7440199', '7440531', '7440542', '7440279', '7429916', '7440600', '7440520', '7440304', '7440644', '7439943', '7440586', '7440257', '7440337', '7440155', '7440042', '7439885', '7440064', '7440575', '7439976', '7440280', '7439921', '7440699', '7440086', '7440688', '10043922', '7440735', '7440144', '7440348', '7440291', '7440133', '7440611', '7439998', '7440075', '7440359', '7440519', '7440406', '7440713', '7429927', '7440724', '7440111', '10028145', '22537195', '53850365', '53850354', '54038812', '54037148', '54037579', '54038016', '54083771', '54386242', '54084263', '54084707', '54085164', '54085642', '54100719', '54101143', '54144193']¶ CAS numbers of the elements, indexed by atomic numbers offbyone 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 offbyone 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 offbyone 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 offbyone 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.
Returns: 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 consistentlyformatted formula. This is necessary for handling usersupplied 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, []
Returns: formula : str
A consistently formatted formula to describe a molecular formula, []
Examples
>>> serialize_formula('Pd(NH3)4+3') 'H12N4Pd+3'