def r_2(comps: 'list(Compound)', is_input): """`iSiMe + (`iAcOx_, `iAcNox_, `iAcCo_) -> `iSaNo + `H2`""" react: str if is_input: iAc = Compound("HCl") iSiMe = Compound("Zn") if len(comps) == 1: if "iAc" in comps[0].comp_type: iAc = comps[0] else: iSiMe = comps[0] else: if "iAc" in comps[0].comp_type: iAc = comps[0] iSiMe = comps[1] else: iAc = comps[1] iSiMe = comps[0] if iAc.formula.value == "HNO3": return "" me = list(iSiMe.formula.consist.keys())[0].name me_oxs = get_me_oxs(me) if me_oxs == 0: return "" if is_me_activer("H", 1, me, me_oxs): return "" (an, an_oxs) = iAc_oxs(iAc.formula) iSaNo = Compound(iSaNo_create(me, me_oxs, an, an_oxs)) react = f"{iSiMe} + {iAc} -> {iSaNo} + H2" else: iSaNo = Compound("ZnCl2") if len(comps) == 1: if "iSa" in comps[0].comp_type: iSaNo = comps[0] else: if "iSa" in comps[0].comp_type: iSaNo = comps[0] else: iSaNo = comps[1] ((me, me_oxs), (an, an_oxs)) = iSa_oxs(iSaNo.formula) iSiMe = Compound(me) if is_me_activer("H", 1, me, me_oxs): return "" iAc = Compound(iAc_create(an, an_oxs)) if iAc == Compound("HNO3"): return "" react = f"{iSiMe} + {iAc} -> {iSaNo} + H2" return Reaction(react)
def r_5(comps: 'list(Compound)', is_input): """`iSiMe + `HNO3` -> `iSaNo + `AmmNO3` + `iWa""" react: str if is_input: iSiMe = Compound("Mg") if len(comps) == 1: if "iSi" in comps[0].comp_type: iSiMe = comps[0] else: if "iSi" in comps[0].comp_type: iSiMe = comps[0] else: iSiMe = comps[1] me = list(iSiMe.formula.consist.keys())[0].name if me in ["Au", "Pt"]: return "" me_oxs = get_me_oxs(me) if me_oxs == 0: return "" if is_me_activer("H", 1, me, me_oxs): return "" iSaNo = Compound(iSaNo_create(me, me_oxs, "NO3", 1)) react = f"{iSiMe} + HNO3 -> {iSaNo} + AmmNO3 + H2O" else: iSaNo = Compound("Mg(NO3)2") if len(comps) == 1: if "iSaNo" in comps[0].comp_type: iSaNo = comps[0] elif len(comps) == 2: if "iSaNo" in comps[0].comp_type: iSaNo = comps[0] elif "iSaNo" in comps[1].comp_type: iSaNo = comps[1] else: if "iSaNo" in comps[0].comp_type: iSaNo = comps[0] elif "iSaNo" in comps[1].comp_type: iSaNo = comps[1] else: iSaNo = comps[2] ((me, me_oxs), (an, an_oxs)) = iSa_oxs(iSaNo.formula) if an != "NO3": return "" if me in ["Au", "Pt"]: return "" if is_me_activer("H", 1, me, me_oxs): return "" iSiMe = Compound(simple(me)) react = f"{iSiMe} + HNO3 -> {iSaNo} + AmmNO3 + H2O" return Reaction(react)
def r_3(comps: 'list(Compound)', is_input): """`iSaNo -> `iSiMe + `iSiNme""" react: str me: str me_oxs: int if is_input: iSaNo = comps[0] if len(iSaNo.formula.consist) > 2: return "" ((me, me_oxs), (nme, _)) = iSa_oxs(iSaNo.formula) iSiMe = Compound(simple(me)) iSiNme = Compound(simple(nme)) react = f"{iSaNo} -> {iSiMe} + {iSiNme}" else: iSiMe = Compound("Na") iSiNme = Compound("Cl2") if len(comps) == 1: if "iSiMe" in comps[0].comp_type: iSiMe = comps[0] else: iSiNme = comps[0] else: if "iSiMe" in comps[0].comp_type: iSiMe = comps[0] iSiNme = comps[1] else: iSiMe = comps[1] iSiNme = comps[0] me = list(iSiMe.formula.consist.keys())[0].name me_oxs = get_me_oxs(me) if me_oxs == 0: return "" nme = list(iSiNme.formula.consist.keys())[0].name if nme in ["O", "H"]: return "" nme_oxs = get_nme_oxs(nme) if nme_oxs == 0: return "" iSaNo = Compound(iSaNo_create(me, me_oxs, nme, nme_oxs)) if "iSa" not in iSaNo.comp_type: return "" react = f"{iSaNo} -> {iSiMe} + {iSiNme}" if not is_me_activer("Al", 3, me, me_oxs) or me == "Al": return Reaction(react, "te- ") else: return Reaction(react, "e- ")
def r_1(comps: 'list(Compound)', is_input): """`iSiMe + `H2SO4` -> `iSaNo + `SO2` + `iWa""" react: str if is_input: iSiMe = Compound("Cu") if len(comps) == 1: if "iSi" in comps[0].comp_type: iSiMe = comps[0] else: if "iSi" in comps[0].comp_type: iSiMe = comps[0] else: iSiMe = comps[1] me = list(iSiMe.formula.consist.keys())[0].name if me in ["Au", "Pt"]: return "" me_oxs = get_me_oxs(me) if me_oxs == 0: return "" iSaNo = Compound(iSaNo_create(me, me_oxs, "SO4", 2)) react = f"{iSiMe} + H2SO4 -> {iSaNo} + SO2 + H2O" else: iSaNo = Compound("CuSO4") if len(comps) == 1: if "iSaNo" in comps[0].comp_type: iSaNo = comps[0] elif len(comps) == 2: if "iSaNo" in comps[0].comp_type: iSaNo = comps[0] elif "iSaNo" in comps[1].comp_type: iSaNo = comps[1] else: if "iSaNo" in comps[0].comp_type: iSaNo = comps[0] elif "iSaNo" in comps[1].comp_type: iSaNo = comps[1] else: iSaNo = comps[2] ((me, me_oxs), (an, an_oxs)) = iSa_oxs(iSaNo.formula) if an != "SO4": return "" if me in ["Au", "Pt"]: return "" iSiMe = Compound(simple(me)) react = f"{iSiMe} + H2SO4 -> {iSaNo} + SO2 + H2O" return Reaction(react)
def r_3(comps: 'list(Compound)', is_input): """`iSaNo -> `iSiMe + `NO2` + `O2`""" react: str if is_input: iSaNO3 = comps[0] ((me, me_oxs), (an, an_oxs)) = iSa_oxs(iSaNO3.formula) if an != "NO3": return "" if is_me_activer(me, me_oxs, "Cu", 2) or me == "Cu": return "" iSiMe = Compound(simple(me)) react = f"{iSaNO3} -> {iSiMe} + NO2 + O2" else: iSiMe = Compound("Ag") if len(comps) == 1: if "iSiMe" in comps[0].comp_type: iSiMe = comps[0] elif len(comps) == 2: if "iSiMe" in comps[0].comp_type: iSiMe = comps[0] elif "iSiMe" in comps[1].comp_type: iSiMe = comps[1] else: if "iSiMe" in comps[0].comp_type: iSiMe = comps[0] elif "iSiMe" in comps[1].comp_type: iSiMe = comps[1] else: iSiMe = comps[2] me = list(iSiMe.formula.consist.keys())[0].name me_oxs = get_me_oxs(me) if me_oxs == 0: return "" if is_me_activer(me, me_oxs, "Cu", 2) or me == "Cu": return "" iSaNO3 = Compound(iSaNo_create(me, me_oxs, "NO3", 1)) react = f"{iSaNO3} -> {iSiMe} + NO2 + O2" return Reaction(react, "t ")
def r_4(comps: 'list(Compound)', is_input): """`iSiMe + `iWa -> `iBaAlk + `H2`""" react: str if is_input: iSiMe = Compound("Na") if len(comps) == 1: if "iSi" in comps[0].comp_type: iSiMe = comps[0] else: if "iSi" in comps[0].comp_type: iSiMe = comps[0] else: iSiMe = comps[1] me = list(iSiMe.formula.consist.keys())[0].name me_oxs = get_me_oxs(me) if me_oxs == 0: return "" iBaAlk = Compound(iBa_create(me, me_oxs)) if "iBaAlk" not in iBaAlk.comp_type: return "" react = f"{iSiMe} + H2O -> {iBaAlk} + H2" else: iBaAlk = Compound("NaOH") if len(comps) == 1: if "iBa" in comps[0].comp_type: iBaAlk = comps[0] else: if "iBa" in comps[0].comp_type: iBaAlk = comps[0] else: iBaAlk = comps[1] (me, _) = iBa_oxs(iBaAlk.formula) iSiMe = Compound(simple(me)) react = f"{iSiMe} + H2O -> {iBaAlk} + H2" return Reaction(react)
def r_3(comps: 'list(Compound)', is_input): """`iBaAlk + `iSiMe + `iWa -> `iSaCo + `H2`""" react: str if is_input: iBaAlk = Compound("NaOH") iSiMe = Compound("Al") if len(comps) == 1: if "iBa" in comps[0].comp_type: iBaAlk = comps[0] elif "iSi" in comps[0].comp_type: iSiMe = comps[0] elif len(comps) == 2: if "iBa" in comps[0].comp_type: iBaAlk = comps[0] elif "iBa" in comps[1].comp_type: iBaAlk = comps[1] if "iSi" in comps[0].comp_type: iSiMe = comps[0] elif "iSi" in comps[1].comp_type: iSiMe = comps[1] else: if "iBa" in comps[0].comp_type: iBaAlk = comps[0] if "iSi" in comps[1].comp_type: iSiMe = comps[1] else: iSiMe = comps[2] elif "iBa" in comps[1].comp_type: iBaAlk = comps[1] if "iSi" in comps[0].comp_type: iSiMe = comps[0] else: iSiMe = comps[2] else: iBaAlk = comps[2] if "iSi" in comps[0].comp_type: iSiMe = comps[0] else: iSiMe = comps[1] (me, me_oxs) = iBa_oxs(iBaAlk.formula) ame = list(iSiMe.formula.consist.keys())[0].name ame_oxs = get_me_oxs(ame) if ame_oxs == 0: return "" iOxAm = Compound(iOx_create(ame, ame_oxs)) if iOxAm.comp_type != "iOxAm": return "" coo = coord(ame, ame_oxs)[0] if ame == "Al": coo = 4 kat = [(me, me_oxs, 1)] an = [(ame, ame_oxs, 1), ("OH", -1, coo)] iSaCo = Compound(iSaCo_create(kat, an)) react = f"{iBaAlk} + {iSiMe} + H2O -> {iSaCo} + H2" else: iSaCo = Compound("Na[Al(OH)4]") if len(comps) == 1: if "iSa" in comps[0].comp_type: iSaCo = comps[0] else: if "iSa" in comps[0].comp_type: iSaCo = comps[0] else: iSaCo = comps[1] ((me, me_oxs), (cpx, _)) = iSa_oxs(iSaCo.formula) [(ame, ame_oxs, _), an, oh, neu] = iSaCo_in(cpx[1:-1]) if oh[0] != "OH" or an[0] != None or neu[0] != None: return "" iOxAm = Compound(iOx_create(ame, ame_oxs)) if iOxAm.comp_type != "iOxAm": return "" iBaAlk = Compound(iBa_create(me, me_oxs)) iSiMe = Compound(simple(ame)) react = f"{iBaAlk} + {iSiMe} + H2O -> {iSaCo} + H2" return Reaction(react)
def r_4(comps: 'list(Compound)', is_input): """`iSiMe + `iSaAc -> `iSiMe + `iSaNo + (`iAcOx_, `iAcNox_)""" react: str if is_input: iSiMe1 = Compound("Mg") iSaAc = Compound("Cu(HSO4)2") if len(comps) == 1: if "iSi" in comps[0].comp_type: iSiMe1 = comps[0] me = list(iSiMe1.formula.consist.keys())[0].name me_oxs = get_me_oxs(me) if me_oxs == 0: return "" if is_me_activer("Cu", 2, me, me_oxs): return "" else: iSaAc = comps[0] ((me, me_oxs), _) = iSa_oxs(iSaAc.formula) else: if "iSi" in comps[0].comp_type: iSiMe1 = comps[0] iSaAc = comps[1] else: iSiMe1 = comps[1] iSaAc = comps[0] me1 = list(iSiMe1.formula.consist.keys())[0].name me1_oxs = get_me_oxs(me1) if me1_oxs == 0: return "" ((me2, me2_oxs), (an, an_oxs)) = iSa_oxs(iSaAc.formula) if not is_me_activer(me1, me1_oxs, me2, me2_oxs): return "" if not is_me_activer("Na", 1, me1, me1_oxs): return "" iSiMe2 = Compound(simple(me2)) iSaNo = Compound(iSaNo_create(me1, me1_oxs, an, an_oxs)) iAc = Compound(iAc_create(an, an_oxs)) react = f"{iSiMe1} + {iSaAc} -> {iSiMe2} + {iSaNo} + {iAc}" else: iSiMe2 = Compound("Cu") iSaNo = Compound("MgSO4") iAc = Compound("H2SO4") if len(comps) == 1: if "iSi" in comps[0].comp_type: iSiMe2 = comps[0] me = list(iSiMe2.formula.consist.keys())[0].name me_oxs = get_me_oxs(me) if me_oxs == 0: return "" elif "iSa" in comps[0].comp_type: iSaNo = comps[0] ((me, me_oxs), (an, an_oxs)) = iSa_oxs(iSaNo.formula) iAc = Compound(iAc_create(an, an_oxs)) if is_me_activer("Cu", 2, me, me_oxs): return "" if me == "Cu": iSiMe = Compound("Ag") else: iAc = comps[0] (an, an_oxs) = iAc_oxs(iAc.formula) iSaNo = Compound(iSaNo_create("Zn", 2, an, an_oxs)) elif len(comps) == 2: for i in range(0, 2): for j in range(0, 2): if "iSi" in comps[i].comp_type and "iSa" in comps[ j].comp_type: iSiMe = comps[i] iSaNo = comps[j] ((me, me_oxs), (an, an_oxs)) = iSa_oxs(iSaNo.formula) iAc = Compound(iAc_create(an, an_oxs)) break if "iSi" in comps[i].comp_type and "iAc" in comps[ j].comp_type: iSiMe = comps[i] iAc = comps[j] (an, an_oxs) = iAc_oxs(iAc.formula) iSaNo = Compound(iSaNo_create("Mg", 2, an, an_oxs)) break if "iSa" in comps[i].comp_type and "iAc" in comps[ j].comp_type: iSaNo = comps[i] iAc = comps[j] ((me, me_oxs), (an, an_oxs)) = iSa_oxs(iSaNo.formula) if me == "Cu": iSiMe = Compound("Ag") break else: if "iSi" in comps[0].comp_type: iSiMe2 = comps[0] if "iSa" in comps[1].comp_type: iSaNo = comps[1] iAc = comps[2] else: iSaNo = comps[2] iAc = comps[1] elif "iSa" in comps[0].comp_type: iSaNo = comps[0] if "iSi" in comps[1].comp_type: iSiMe2 = comps[1] iAc = comps[2] else: iSiMe2 = comps[2] iAc = comps[1] elif "iAc" in comps[0].comp_type: iAc = comps[0] if "iSi" in comps[1].comp_type: iSiMe2 = comps[1] iSaNo = comps[2] else: iSiMe2 = comps[2] iSaNo = comps[1] me2 = list(iSiMe2.formula.consist.keys())[0].name me2_oxs = get_me_oxs(me2) if me2_oxs == 0: return "" ((me1, me1_oxs), (an1, an1_oxs)) = iSa_oxs(iSaNo.formula) (an2, an2_oxs) = iAc_oxs(iAc.formula) if an1 != an2: return "" if an1_oxs == 1: return "" if not is_me_activer(me1, me1_oxs, me2, me2_oxs): return "" if not is_me_activer("Na", 1, me1, me1_oxs): return "" iSiMe1 = Compound(simple(me1)) iSaAc = Compound(iSaAc_create(me2, me2_oxs, an1, an1_oxs)) react = f"{iSiMe1} + {iSaAc} -> {iSiMe2} + {iSaNo} + {iAc}" return Reaction(react)
def r_6(comps: 'list(Compound)', is_input): """`iSaNo + `iWa -> `iSiMe + `iAcOx + `O2`""" react: str if is_input: iSaNo = Compound("ZnSO4") if len(comps) == 1: if "iSa" in comps[0].comp_type: iSaNo = comps[0] else: if "iSa" in comps[0].comp_type: iSaNo = comps[0] else: iSaNo = comps[1] ((me, me_oxs), (an, an_oxs)) = iSa_oxs(iSaNo.formula) if not is_me_activer("Al", 3, me, me_oxs) or me == "Al": return "" if is_me_activer("H", 1, me, me_oxs): return "" iSiMe = Compound(simple(me)) iAcOx = Compound(iAc_create(an, an_oxs)) if "iAcNox" in iAcOx.comp_type: return "" react = f"{iSaNo} + H2O -> {iSiMe} + {iAcOx} + O2" else: iSiMe = Compound("Zn") iAcOx = Compound("H2SO4") if len(comps) == 1: if "iSiMe" in comps[0].comp_type: iSiMe = comps[0] elif "iAc" in comps[0].comp_type: iAcOx = comps[0] elif len(comps) == 2: if "iSiMe" in comps[0].comp_type: iSiMe = comps[0] if "iAc" in comps[0].comp_type: iAcOx = comps[1] elif "iSiMe" in comps[1].comp_type: iSiMe = comps[1] if "iAc" in comps[0].comp_type: iAcOx = comps[0] else: if "iAc" in comps[0].comp_type: iAcOx = comps[0] else: iAcOx = comps[1] else: if "iSiMe" in comps[0].comp_type: iSiMe = comps[0] if "iAc" in comps[0].comp_type: iAcOx = comps[1] else: iAcOx = comps[2] if "iSiMe" in comps[1].comp_type: iSiMe = comps[1] if "iAc" in comps[0].comp_type: iAcOx = comps[0] else: iAcOx = comps[2] if "iSiMe" in comps[2].comp_type: iSiMe = comps[2] if "iAc" in comps[0].comp_type: iAcOx = comps[0] else: iAcOx = comps[1] me = list(iSiMe.formula.consist.keys())[0].name me_oxs = get_me_oxs(me) if me_oxs == 0: return "" if not is_me_activer("Al", 3, me, me_oxs) or me == "Al": return "" if is_me_activer("H", 1, me, me_oxs): return "" (an, an_oxs) = iAc_oxs(iAcOx.formula) iSaNo = Compound(iSaNo_create(me, me_oxs, an, an_oxs)) react = f"{iSaNo} + H2O -> {iSiMe} + {iAcOx} + O2" return Reaction(react, "e- ")
def r_4(comps: 'list(Compound)', is_input): """`iSaNo -> `iSiMe + `iOxAc + `O2`""" react: str if is_input: iSaNo = comps[0] ((me, _), (an, an_oxs)) = iSa_oxs(iSaNo.formula) iAc = Compound(iAc_create(an, an_oxs)) if "iAcNox" in iAc.comp_type: return "" (nme, nme_oxs) = iAc_el_oxs(iAc.formula) if nme == "N": return "" iSiMe = Compound(simple(me)) iOxAc = Compound(iOx_create(nme, nme_oxs)) react = f"{iSaNo} -> {iSiMe} + {iOxAc} + O2" else: iSiMe = Compound("Na") iOxAc = Compound("SO3") if len(comps) == 1: if "iSiMe" in comps[0].comp_type: iSiMe = comps[0] elif "iOx" in comps[0].comp_type: iOxAc = comps[0] elif len(comps) == 2: if "iSiMe" in comps[0].comp_type: iSiMe = comps[0] if "iOx" in comps[1].comp_type: iOxAc = comps[1] elif "iSiMe" in comps[1].comp_type: iSiMe = comps[1] if "iOx" in comps[0].comp_type: iOxAc = comps[0] else: if "iOx" in comps[0].comp_type: iOxAc = comps[0] elif "iOx" in comps[1].comp_type: iOxAc = comps[1] else: if "iSiMe" in comps[0].comp_type: iSiMe = comps[0] if "iOx" in comps[1].comp_type: iOxAc = comps[1] else: iOxAc = comps[2] elif "iSiMe" in comps[1].comp_type: iSiMe = comps[1] if "iOx" in comps[0].comp_type: iOxAc = comps[0] else: iOxAc = comps[2] else: iSiMe = comps[2] if "iOx" in comps[0].comp_type: iOxAc = comps[0] else: iOxAc = comps[1] me = list(iSiMe.formula.consist.keys())[0].name me_oxs = get_me_oxs(me) if me_oxs == 0: return "" (nme, nme_oxs) = iOx_oxs(iOxAc.formula) if nme == "N": return "" iAcOx = Compound(iAc_el_create(nme, nme_oxs)) (an, an_oxs) = iAc_oxs(iAcOx.formula) iSaNo = Compound(iSaNo_create(me, me_oxs, an, an_oxs)) react = f"{iSaNo} -> {iSiMe} + {iOxAc} + O2" return Reaction(react, "te- ")