def test_CRC_aqueous_thermodynamics(): assert all([checkCAS(i) for i in CRC_aqueous_thermodynamics.index]) # Check CASs match up assert all([CAS_from_any(i) == i for i in CRC_aqueous_thermodynamics.index]) # Check search by formula matches up for formula, CAS in zip(CRC_aqueous_thermodynamics['Formula'], CRC_aqueous_thermodynamics.index): assert pubchem_db.search_CAS(CAS_from_any(formula)).CASs == CAS # Check the MWs match up for CAS, MW_specified in zip(CRC_aqueous_thermodynamics.index, CRC_aqueous_thermodynamics['MW']): c = pubchem_db.search_CAS(CAS) assert_allclose(c.MW, MW_specified, atol=0.05) # Checking names is an option too but of 173, only 162 are unique # and many of the others have names that seem ambiguous for ions which can # have more than one charge assert CRC_aqueous_thermodynamics.index.is_unique assert CRC_aqueous_thermodynamics.shape == (173, 7) Hf_tot = CRC_aqueous_thermodynamics['Hf(aq)'].abs().sum() assert_allclose(Hf_tot, 70592500.0) Gf_tot = CRC_aqueous_thermodynamics['Gf(aq)'].abs().sum() assert_allclose(Gf_tot, 80924000.0) S_tot = CRC_aqueous_thermodynamics['S(aq)'].abs().sum() assert_allclose(S_tot, 17389.9) Cp_tot = CRC_aqueous_thermodynamics['Cp(aq)'].abs().sum() assert_allclose(Cp_tot, 2111.5)
def test_dissociation_reactions(): from thermo.electrochem import electrolyte_dissociation_reactions as df from collections import Counter # Check there's only one dissociation reaction for each product assert len(df['Electrolyte Formula'].values) == len( set(df['Electrolyte Formula'].values)) # Check the chemicals match up with the database for name, CAS, formula in zip(df['Electrolyte name'], df['Electrolyte CAS'], df['Electrolyte Formula']): assert CAS_from_any(CAS) == CAS assert pubchem_db.search_CAS(CAS).formula == serialize_formula(formula) # Check the anions match up with the database for formula, CAS, charge in zip(df['Anion formula'], df['Anion CAS'], df['Anion charge']): assert CAS_from_any(CAS) == CAS assert CAS_from_any(formula) == CAS assert pubchem_db.search_CAS(CAS).charge == charge assert pubchem_db.search_CAS(CAS).formula == serialize_formula(formula) # Check the cations match up with the database for formula, CAS, charge in zip(df['Cation formula'], df['Cation CAS'], df['Cation charge']): assert CAS_from_any(CAS) == CAS assert CAS_from_any(formula) == CAS assert pubchem_db.search_CAS(CAS).charge == charge assert pubchem_db.search_CAS(CAS).formula == serialize_formula(formula) # Check the charges and counts of ions sums to zero for index, row in df.iterrows(): an_charge = row['Anion charge'] an_count = row['Anion count'] cat_charge = row['Cation charge'] cat_count = row['Cation count'] err = an_charge * an_count + cat_charge * cat_count assert err == 0 # Check the reactant counts and product counts sum to be equal and conserve # moles for index, row in df.iterrows(): elec = nested_formula_parser(row['Electrolyte Formula']) cat = nested_formula_parser(row['Cation formula']) cat_count = row['Cation count'] an = nested_formula_parser(row['Anion formula']) an_count = row['Anion count'] product_counter = Counter() for _ in range(cat_count): product_counter.update(cat) for _ in range(an_count): product_counter.update(an) assert dict(product_counter.items()) == elec
def test_Marcus_ion_conductivities(): # Check the CAS numbers are the "canonical" ones assert all([CAS_from_any(i) == i for i in Marcus_ion_conductivities.index]) # Check the charges match up for v, CAS in zip(Marcus_ion_conductivities['Charge'], Marcus_ion_conductivities.index): assert v == charge_from_formula(pubchem_db.search_CAS(CAS).formula) # Even check the formulas work! for formula, CAS in zip(Marcus_ion_conductivities['Formula'], Marcus_ion_conductivities.index): assert pubchem_db.search_CAS(CAS_from_any(formula)).CASs == CAS
def test_dissociation_reactions(): from thermo.electrochem import electrolyte_dissociation_reactions as df from collections import Counter # Check there's only one dissociation reaction for each product assert len(df['Electrolyte Formula'].values) == len(set(df['Electrolyte Formula'].values)) # Check the chemicals match up with the database for name, CAS, formula in zip(df['Electrolyte name'], df['Electrolyte CAS'], df['Electrolyte Formula']): assert CAS_from_any(CAS) == CAS assert pubchem_db.search_CAS(CAS).formula == serialize_formula(formula) # Check the anions match up with the database for formula, CAS, charge in zip(df['Anion formula'], df['Anion CAS'], df['Anion charge']): assert CAS_from_any(CAS) == CAS assert CAS_from_any(formula) == CAS assert pubchem_db.search_CAS(CAS).charge == charge assert pubchem_db.search_CAS(CAS).formula == serialize_formula(formula) # Check the cations match up with the database for formula, CAS, charge in zip(df['Cation formula'], df['Cation CAS'], df['Cation charge']): assert CAS_from_any(CAS) == CAS assert CAS_from_any(formula) == CAS assert pubchem_db.search_CAS(CAS).charge == charge assert pubchem_db.search_CAS(CAS).formula == serialize_formula(formula) # Check the charges and counts of ions sums to zero for index, row in df.iterrows(): an_charge = row['Anion charge'] an_count = row['Anion count'] cat_charge = row['Cation charge'] cat_count = row['Cation count'] err = an_charge*an_count + cat_charge*cat_count assert err == 0 # Check the reactant counts and product counts sum to be equal and conserve # moles for index, row in df.iterrows(): elec = nested_formula_parser(row['Electrolyte Formula']) cat = nested_formula_parser(row['Cation formula']) cat_count = row['Cation count'] an = nested_formula_parser(row['Anion formula']) an_count = row['Anion count'] product_counter = Counter() for _ in range(cat_count): product_counter.update(cat) for _ in range(an_count): product_counter.update(an) assert dict(product_counter.items()) == elec
def test_CRC_ion_conductivities(): # Check CASs match up assert all([CAS_from_any(i) == i for i in CRC_ion_conductivities.index]) # Check search by formula matches up for formula, CAS in zip(CRC_ion_conductivities['Formula'], CRC_ion_conductivities.index): assert pubchem_db.search_CAS(CAS_from_any(formula)).CASs == CAS
def test_McCleskey_data(): # Check the CAS lookups for CAS, d in McCleskey_conductivities.items(): assert pubchem_db.search_CAS(CAS).CASs == CAS # Check the formula lookups for CAS, d in McCleskey_conductivities.items(): assert CAS_from_any(d.Formula) == CAS