def test_material_get(): mat_ = {'kapton': ('C22H10N2O5', 1.43), 'lead': ('Pb', 11.34), 'aluminum': ('Al', 2.72), 'water': ('H2O', 1.0)} for mname in mat_.keys(): formula, density = get_material(mname) f1 = chemparse(formula) f2 = chemparse(mat_[mname][0]) for k, v in f2.items(): assert v == f1[k] assert_allclose(density, mat_[mname][1], rtol=0.1)
def test_chemparse(): examples = { 'H2O': { 'H': 2, 'O': 1 }, 'Mn(SO4)2(H2O)7': { 'H': 14.0, 'S': 2.0, 'Mn': 1, 'O': 15.0 }, 'Mg(SO4)2': { 'Mg': 1, 'S': 2, 'O': 8 }, 'Mg0.5Fe0.5': { 'Mg': 0.5, 'Fe': 0.5 }, 'CO': { 'C': 1, 'O': 1 } } for formula, cert in examples.items(): ret = chemparse(formula) for elem, quant in cert.items(): v = ret.pop(elem) assert_allclose(v, quant, rtol=1.e3) assert len(ret) == 0
def test_material_find(): mat_ = { 'kapton': ('C22H10N2O5', 1.43, 'polymer'), 'lead': ('Pb', 11.34, 'metal'), 'aluminum': ('Al', 2.72, 'metal'), 'water': ('H2O', 1.0, 'solvent') } for mname, mdat in mat_.items(): mat = find_material(mname) f1 = chemparse(mat.formula) f2 = chemparse(mdat[0]) for k, v in f2.items(): assert v == f1[k] assert_allclose(mat.density, mdat[1], rtol=0.1) assert (mdat[2] in mat.categories) for formula in ('WSO3', 'CdAs140CO3', 'KAs'): out = find_material(formula) assert out == None
def test_material_get(): mat_ = { 'kapton': ('C22H10N2O5', 1.43), 'lead': ('Pb', 11.34), 'aluminum': ('Al', 2.72), 'water': ('H2O', 1.0) } for mname in mat_.keys(): formula, density = get_material(mname) f1 = chemparse(formula) f2 = chemparse(mat_[mname][0]) for k, v in f2.items(): assert v == f1[k] assert_allclose(density, mat_[mname][1], rtol=0.1) for formula, density in mat_.values(): _f, _d = get_material(formula) assert _f == formula assert_allclose(density, _d, rtol=0.1) for formula in ('WSO3', 'CdAs140CO3', 'KAs'): out = get_material(formula) assert out == None
def test_material_mu2(): en = np.linspace(5000, 10000, 21) known_mu = np.array([ 0.04934, 0.04267, 0.03715, 0.03254, 0.02866, 0.02538, 0.02257, 0.02016, 0.01809, 0.01629, 0.01472, 0.01334, 0.01214, 0.01108, 0.01014, 0.00930, 0.00856, 0.00789, 0.00729, 0.00675, 0.00626 ]) mu = material_mu('air', en) assert_allclose(mu, known_mu, rtol=0.05) air_formula, air_density = get_material('air') air_comps = chemparse(air_formula) assert air_comps['Ar'] < 0.013 assert air_comps['Ar'] > 0.007 mu = material_mu('air', en, density=2.0 * air_density) assert_allclose(mu, 2.0 * known_mu, rtol=0.05)