コード例 #1
0
    def balance(self):
        #balances equation
        reaction_list, product_list = self.balanceself()
        try:
            reac, prod = balance_stoichiometry(reaction_list, product_list)
        except:
            return False

        reaction = []  # e.g.["2KCl", ...]
        product = []
        final = ""
        # balances
        for compound in reaction_list:  # appends to reaction
            for k, v in reac.items():
                if k == compound:
                    if v != 1:
                        reaction.append(str(v) + compound)
                    if v == 1:
                        reaction.append(compound)

        for compound in product_list:  # appends to product
            for k, v in prod.items():
                if k == compound:
                    if v != 1:
                        product.append(str(v) + compound)
                    if v == 1:
                        product.append(compound)

        for x in reaction:  # prints from reaction
            if x == reaction[-1]:
                final += x + " == "
            else:
                final += x + " + "

        for x in product:  # prints from product
            if x == product[-1]:
                final += x
            else:
                final += x + " + "
        if "nan" in final:
            return False
        return final
コード例 #2
0
def home(request):
    form = FormulaForm()
    formula = request.POST[
        'formula'] if request.method == 'POST' else 'H2 + O2 -> H2O'
    r = Reaction.from_string(formula)
    reac, prod = balance_stoichiometry({sub
                                        for sub in r.reac},
                                       {sub
                                        for sub in r.prod})
    elr, elp = el(reac, prod)
    rs, ps = weight(reac, prod)
    return render(
        request, 'formula.html', {
            'form': form,
            'balanced': reactionToHtml(reac, prod),
            'rs': rs,
            'ps': ps,
            'elr': elr,
            'elp': elp
        })
コード例 #3
0
def balance_equation(eqn,astex=True):
	if len(eqn.split('<->')) == 1:
	    atype='->'
	else:
	    atype='<->'

	r,p = [s.split(' + ') for s in eqn.split(atype)]
	qs=[{},{}]
	for i in r:
	    qs[0][i]=1
	for i in p:
	    qs[1][i]=1
	qsLatex.append(tex.chemical_equation_latex(qs,atype))

	bal = chempy.balance_stoichiometry(r,p)
	if astex:
		rxnsLatex = tex.chemical_equation_latex(bal,atype)
	else:
		rxnsLatex = tex.chemical_equation_string(bal,atype)
	return rxnsLatex
コード例 #4
0
def balancer():
    print("#######################################")
    print("superbeta")
    print("enter")
    print(
        "enter in format blah blah blah = blah blah blah dont use any numbers it does it for youe xcept like gas ones like h2 uno"
    )
    print("example{'NH4ClO4 + Al = Al2O3 + HCl + H2O + N2")
    print("#######################################")
    lol = input(":")
    lol = lol.replace(" ", "")
    print(lol)
    loll = []
    lolff = []
    lolss = []
    loll = lol.split("=")
    print(loll)
    lolf = loll[0]
    print(lolf)
    lols = loll[1]
    print(lols)
    lolff = lolf.split("+")
    lolss = lols.split("+")
    print(lolff)

    if len(lolff) == 2 and len(lolss) == 1:
        reac, prod = balance_stoichiometry({lolff[0], lolff[1]}, {lolss[0]})
    elif len(lolff) == 2 and len(lolss) == 2:
        reac, prod = balance_stoichiometry({lolff[0], lolff[1]},
                                           {lolss[0], lolss[1]})
    elif len(lolff) == 2 and len(lolss) == 3:
        reac, prod = balance_stoichiometry({lolff[0], lolff[1]},
                                           {lolss[0], lolss[1], lolss[2]})
    elif len(lolff) == 2 and len(lolss) == 4:
        reac, prod = balance_stoichiometry(
            {lolff[0], lolff[1]}, {lolss[0], lolss[1], lolss[2], lolss[3]})
    elif len(lolff) == 3 and len(lolss) == 1:
        reac, prod = balance_stoichiometry({lolff[0], lolff[1], lolff[2]},
                                           {lolss[0]})
    elif len(lolff) == 3 and len(lolss) == 1:
        reac, prod = balance_stoichiometry({lolff[0], lolff[1], lolff[2]},
                                           {lolss[0]})
    else:
        print("error occured with equation: ", lol)
    print("reactants = ", reac)
    print("products = ", prod)
    print("overall : ", reac, " = ", prod)
    main()
コード例 #5
0
ファイル: Solve.py プロジェクト: hmvantol/diatom-dFBA
def calculatePQ(biomass_met, N_source):
    biomass_formula = ''
    reacs = {'H2O'}
    for e in ['C', 'H', 'N', 'O', 'P', 'S', 'Si']:
        if e in biomass_met.elements.keys() and int(
                round(biomass_met.elements[e])) > 0:
            biomass_formula = biomass_formula + e + str(
                int(round(biomass_met.elements[e])))
            if e == 'C':
                reacs.add('CO2')
            elif e == 'P':
                reacs.add('PO4')
            elif e == 'S':
                reacs.add('SO4')
            elif e == 'Si':
                reacs.add('SiO4H4')
            elif e == 'N':
                reacs.add(N_source)

    reac, prod = balance_stoichiometry(reacs, {biomass_formula, 'O2'})

    PQ = (float(prod.get('O2')) / reac.get('CO2'))

    return PQ
コード例 #6
0
def balance():
    reac, prod = balance_stoichiometry({textEntryBox1.get()},
                                       {textEntryBox2.get()})
    x = ("Stoichiometric coefficients:" + "\n" + "Reactants: " + dict(reac) +
         "\n" + "Products: " + dict(prod))
コード例 #7
0
from chempy import balance_stoichiometry  # Main reaction in NASA's booster rockets:
from pprint import pprint
from helper import sigRound, getMolarMass

#Ammonia  chemically reacts with oxygen gas  to produce nitric oxide  and water .
#What mass of water is produced by the reaction of  of oxygen gas?

reac, prod = balance_stoichiometry({'NH3', 'O2'}, {'NO', 'H2O'})

want = 'H2O'
have = {"name": "O2", "mass": 5.6}
sigs = 3

reac = dict(reac)
prod = dict(prod)
everything = {**reac, **prod}

have["moles"] = getMolarMass(have["name"], 6)

molesConsumed = have["mass"] / have["moles"]

resConsumed = molesConsumed * (everything[want] / everything[have["name"]])

moles = resConsumed * getMolarMass(want, 6)

print(moles)
コード例 #8
0
    last_number = 0
    for char in S:
        if '0' <= char <= '9':
            last_number = 10 * last_number + int(char)
        else:
            ans += last_number
            last_number = 0
    return (ans + last_number)


print('{} atoms in reac'.format(find_sum_str(list(all_reac.keys())[0])))

data = []
for i in itertools.combinations(all_prod.keys(), num):
    try:
        reac, prod = balance_stoichiometry(all_reac.keys(), i)
        if (sum(1 for number in prod.values() if number < 0)) == 0:

            E_formation = all_reac[list(all_reac.keys())[0]] * reac[(list(
                reac.keys())[0])]
            reactions = '{} {} ->'.format(reac[list(all_reac.keys())[0]],
                                          list(all_reac.keys())[0])

            for j in prod.keys():
                E_formation -= prod[j] * all_prod[j]
                reactions += ' {} {} +'.format(prod[j], j)

            E_formation = E_formation / (reac[list(
                reac.keys())[0]] * find_sum_str(list(all_reac.keys())[0]))
            data += [[reactions[:len(reactions) - 2], E_formation]]
from chempy import Substance
'''
compound = Substance.from_formula(input("Enter first compound: "))
compound2 = Substance.from_formula(input("Enter second compound: "))

K1, K2, Kw = symbols('K1 K2 Kw')
e1 = Equilibrium(compound.composition, compound2.composition, K1)
e2 = Equilibrium({'O2': 1, 'H2O': 2, 'e-': 4}, {'OH-': 4}, K2)
coeff = Equilibrium.eliminate([e1, e2], 'e-')
redox = e1*coeff[0] + e2*coeff[1]
autoprot = Equilibrium({'H2O': 1}, {'H+': 1, 'OH-': 1}, Kw)
n = redox.cancel(autoprot)
redox2 = redox + n*autoprot
print(redox2)
'''

from chempy import balance_stoichiometry
reac, prod = balance_stoichiometry({'C7H5(NO2)3', 'NH4NO3'},
                                   {'CO', 'H2O', 'N2'})
from pprint import pprint
# pprint(reac)
# {'C7H5(NO2)3': 2, 'NH4NO3': 7}
# >>> pprint(prod)
# {'CO': 14, 'H2O': 19, 'N2': 10}
from chempy import mass_fractions
for fractions in map(mass_fractions, [reac, prod]):
    pprint({k: '{0:.3g} wt%'.format(v * 100) for k, v in fractions.items()})

# ferricyanide = Substance.from_formula('Fe(CN)6-3')
# print(ferricyanide.unicode_name)
# print('%.3f' % ferricyanide.mass)
コード例 #10
0
# Author: David Arroyo Menéndez <*****@*****.**>
# Maintainer: David Arroyo Menéndez <*****@*****.**>

# This file is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 3, or (at your option)
# any later version.

# This file is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.

# You should have received a copy of the GNU General Public License
# along with GNU Emacs; see the file COPYING.  If not, write to
# the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
# Boston, MA 02110-1301 USA,
#!/usr/bin/python
# -*- coding: utf-8 -*-

from chempy import balance_stoichiometry  # Main reaction in NASA's booster rockets:
reac, prod = balance_stoichiometry({'NH4ClO4', 'Al'},
                                   {'Al2O3', 'HCl', 'H2O', 'N2'})
from pprint import pprint
pprint(dict(reac))
pprint(dict(prod))
from chempy import mass_fractions
for fractions in map(mass_fractions, [reac, prod]):
    pprint({k: '{0:.3g} wt%'.format(v * 100) for k, v in fractions.items()})
コード例 #11
0
    return t


def react_ratio(r, p):
    lhalf = [f"({_})" for _ in r.values()]
    lhalf = list(intersperse(':', lhalf))
    rhalf = [f"({_})" for _ in p.values()]
    rhalf = list(intersperse(':', rhalf))
    to_print = lhalf + [':'] + rhalf

    t = " ".join(to_print)
    return t


reac_list = ['P2S3', 'HNO3', 'H2O']
prod_list = ['H3PO4', 'S', 'NO']

a = [formula for formula in reac_list]
b = [formula for formula in prod_list]
reac, prod = cp.balance_stoichiometry(a, b)
reactants, products = dict(reac), dict(prod)

print(string_reaction(reac_list, reactants, prod_list, products))
print(react_ratio(reactants, products))

# n1_mol = r_mass / r_mmass
# n2_mol_real = p_mass / p_mmass
# n2_mol_imag = n1_mol * products['H2O'] / reactants['KMnO4']
# resa = n2_mol_real / n2_mol_imag
# print(resa*100, "%")
コード例 #12
0
from chempy import balance_stoichiometry  # Main reaction in NASA's booster rockets:
from pprint import pprint
from helper import sigRound

reac, prod = balance_stoichiometry({'C8H18', 'O2'}, {'H2O', 'CH3COOH'})

want = 'H2O'
have = {"name": "C8H18", "moles": 2.2}
sigs = 2

reac = dict(reac)
prod = dict(prod)
everything = {**reac, **prod}

moles = everything[want] / everything[have["name"]] * have["moles"]
print(sigRound(moles, sigs))
コード例 #13
0
ファイル: reaction.py プロジェクト: futurelabmx/TallerPython
# FutureLab
# Primer taller de Python

# Balanceo estequiométrico de ecuaciones químicas

from chempy import balance_stoichiometry

reacts, products = balance_stoichiometry({"H2O", "CO2"}, {"C6H12O6", "O2"})
print(dict(reacts))
print(dict(products))
e1 = input('Reagent compound 1: ')
e2 = input('Reagent compound 2: ')
e3 = input('Product compound 1: ')
e4 = input('Product compound 2: ')

s1 = Substance.from_formula(e1)
s2 = Substance.from_formula(e2)
s3 = Substance.from_formula(e3)
s4 = Substance.from_formula(e4)

print(e1, "=", round(s1.molar_mass(), 3))
print(e2, "=", round(s2.molar_mass(), 3))
print(e3, "=", round(s3.molar_mass(), 3))
print(e4, "=", round(s4.molar_mass(), 3))

reac, prod = balance_stoichiometry({e1, e2}, {e3, e4})

pprint(reac)
pprint(prod)

for fractions in map(mass_fractions, [reac, prod]):
    pprint({k: '{0:.3g} wt%'.format(v * 100) for k, v in fractions.items()})

if input("Solve for limiting reagent? (Y/N)") == "N":
    sys.exit()

masse1 = input(f"Grams of {e1}? ")
masse2 = input(f"Grams of {e2}? ")

mole1 = input(f"Moles of {e1}? ")
mole2 = input(f"Moles of {e2}? ")
コード例 #15
0
 def balance_simple_equation(reactants, products):
     #react = chempy.Substance.from_formula(reactants)
     #prod  = chempy.Substance.from_formula(products)
     balanced_reaction = chempy.balance_stoichiometry(reactants, products)
     #print(balanced_reaction)
     EquationBalancer.reply_to_query(balanced_reaction)
コード例 #16
0
from chempy import balance_stoichiometry  # Main reaction in NASA's booster rockets:
from pprint import pprint

reac, prod = balance_stoichiometry({'C8H18', 'O2'}, {'CO2', 'H20'})

print('Reactants:')
pprint(dict(reac))
print('Products:')
pprint(dict(prod))
コード例 #17
0
ファイル: test.py プロジェクト: ZDHades/Chemathstry
# prods = []
# reac = ['NH4ClO4', 'Al']
# reacs = []

# for chem in prod:
#     Name = Substance.from_formula(chem)
#     prods.append(Name.unicode_name)Np
#     # print(Name.unicode_name)
# for chem in reac:
#     Name = Substance.from_formula(chem)
#     reacs.append(Name.unicode_name)
#     # print(Name.unicode_name)
# a, b = balance_stoichiometry(reacs, prods)

# # Learn how backref works

# print(f'{str(reac)[13:-2]}')

# test = (input("test")
# # yeet = Substance.from_formula(test)
# # print(yeet.mass)
# print(test)
solution = []

reac, prod = balance_stoichiometry('not even real shit', 'yeah')
for fractions in map(mass_fractions, [reac, prod]):
    solution.append(
        {k: '{0:.3g} wt%'.format(v * 100)
         for k, v in fractions.items()})

print(solution)
コード例 #18
0
from chempy import balance_stoichiometry
__author__ = 'Kumar Aditya'
reac, prod = balance_stoichiometry({'K2Cr2O7', 'H2SO4'},
                                   {'K2SO4', 'Cr2(SO4)3', 'H2O', 'O2'})
print(reac, prod, "\n")
reac1, prod1 = balance_stoichiometry({'KI', 'KIO3', 'H2SO4'},
                                     {'K2SO4', 'H2O', 'I2'})
print(reac1, prod1)
コード例 #19
0
#!/usr/bin/env python3

# Python Project : Python script to determine stoichiometric ratios of chemical reactions #1
# Handle imports

from chempy import balance_stoichiometry #importing stoichiometry function
from pprint import pprint # importing pretty print

# 1: Welcome to the tool. Is help required?

print('Hello aspiring chemist!')
print('Please input your reactants. Note: values are case sensitive.')
print('E.g. NH4ClO4, Al, H2O...')
reactants = input('Reactants: ')

print('Now please input your products. Note: values are case sensitive.')
products = input('Products: ')

print(reactants)
print(products) #reactants and products printed for verification

# 2 :determine stoichiometric coefficients of main reactions
reac, prod = balance_stoichiometry({'NH4ClO4', 'Al'}, {'Al2O3', 'AlCl3', 'H2O', 'N2'}) # rxn: ammonium perchlorate + aluminum

pprint(dict(reactants))
pprint(dict(products))
hf['H2O']    = -241820
hf['CO2']    = -393520
hf['CH4']    = -274850
hf['C8H18']  = -249910
hf['C2H6']   = -84680
hf['C2H4']   =  52280  
hf['CH3OH']  = -238810 #methanol
hf['C2H5OH'] = -277690 #ethanol
hf['H2']     = 0
hf['N2']     = 0
hf['O2']     = 0

fuel = 'CH4'

#Octane Combustion
reac, prod = balance_stoichiometry({fuel, 'O2'}, {'H2O','CO2'})
reac['N2'] = 3.76*reac['O2']
prod['N2'] = reac['N2']
n_fuel = reac[fuel]
for k in prod.keys(): prod[k] = prod[k]/n_fuel
for k in reac.keys(): reac[k] = reac[k]/n_fuel

out = ""
print
print "The balanced reaction is"
for i in reac.keys(): out += " %.1f %s +" % (reac[i],i)
out = out[:-1]
out += " = "
for i in prod.keys(): out += " %.1f %s +" % (prod[i],i)
out = out[:-1]
print out
コード例 #21
0
                    halfrxns[i][j][k] = halfrxns[i][j][k] * coeffs[i]
                    rxns[i][j][k] = rxns[i][j][k] * coeffs[i]
            halfrxnsStr.append(halfrxns[i])
            rxns[i][j].pop('e-', None)
            rxnsStr.append(rxns[i])

        for i in range(len(halfrxnsStr)):
            halfrxnsLatex.append(chemical_equation_latex(
                halfrxnsStr[i], atype))
            rxnsLatex.append(chemical_equation_latex(rxnsStr[i], atype))

        halfrxnsLatex = ['\n\\\\\n'.join(halfrxnsLatex)]
        rxnsLatex = ['\n\\\\\n'.join(rxnsLatex)]

    else:
        bal = chempy.balance_stoichiometry(r, p)
        rxnsLatex = chemical_equation_latex(bal, atype)

halfrxnsLatex.append('\n\n\n\\end{enumerate}\n\\end{document}')
rxnsLatex.append('\n\n\n\\end{enumerate}\n\\end{document}')
qsLatex.append('\n\n\n\\end{enumerate}\n\\end{document}')

f = open('tex/halfrxns.tex', 'w')
f.write(''.join(halfrxnsLatex))
f.close()

f = open('tex/rxns.tex', 'w')
f.write(''.join(rxnsLatex))
f.close()

f = open('tex/qs.tex', 'w')
コード例 #22
0
def stoic():
    eq = '''NaH2PO4 -> NaPO3 + H2O
    H2CO3 -> H2O + CO2
    BaSO4 + H2SO4 -> Ba(HSO4)2
    CaCO3 -> CaO + CO2
    CaO + H2O -> Ca(OH)2
    H2SO3 -> H2O + SO2
    H3PO4 + Ca(OH)2 -> CaHPO4.2H2O
    NaPO3 + CuO -> NaCuPO4
    SO3 + H2O -> H2SO4
    Be(OH)2 -> BeO + H2O
    BaO + H2O -> Ba(OH)2
    Na2SO3 + S -> Na2S2O3
    SO2 + H2O -> H2SO3
    Li2O + H2O -> LiOH
    Na2HPO4 -> Na4P2O7 + H2O
    H4As2O7 -> As2O5 + H2O
    CaC2 + N2 -> CaCN2 + C
    Mg(OH)2 -> (MgOH)2O + H2O
    HAsO3 -> As2O5 + H2O
    KHSO4 -> K2S2O7 + H2O
    H3PO4 -> H4P2O7 + H2O
    NaCl + NH4HCO3 -> NaHCO3 + NH4Cl
    HAsO2 -> As2O3 + H2O
    UO3 + H2 -> UO2 + H2O
    CdSO4 + H2S -> CdS + H2SO4
    HIO3 -> I2O5 + H2O
    Ca(HCO3)2 -> CaCO3 + CO2 + H2O
    FeS + H2SO4 -> H2S + FeSO4
    (NH4)2SO4 + CaCO3 -> (NH4)2CO3 + CaSO4
    Hg2CO3 -> Hg + HgO + CO2
    CaSO4 -> CaS + O2
    BeF2 + Mg -> MgF2 + Be
    Mg + N2 -> Mg3N2
    SiO2 + Ca(OH)2 -> CaSiO3 + H2O
    K2O + H2O -> KOH
    C + H2O -> CO + H2
    Ca(OH)2 + CO2 -> Ca(HCO3)2
    N2O3 + H2O -> HNO2
    SiO2 + Na2CO3 -> Na2SiO3 + CO2
    BaO2 + H2SO4 -> BaSO4 + H2O2
    Na2Cr2O7 + S -> Cr2O3 + Na2SO4
    Ca(OH)2 + CO2 -> CaCO3 + H2O
    Fe2O3 + SiO2 -> Fe2Si2O7
    CO2 + NH3 + H2O -> NH4HCO3
    Na2O + H2O -> NaOH
    NH4NO3 -> N2O + H2O
    N2O5 + H2O -> HNO3
    CaS + H2O -> Ca(OH)2 + H2S
    Al(OH)3 + NaOH -> NaAlO2 + H2O
    (CuOH)2CO3 -> CuO + CO2 + H2O
    SrBr2 + (NH4)2CO3 -> SrCO3 + NH4Br
    H2O2 -> H2O + O2
    Ca(ClO3)2 -> CaCl2 + O2
    PCl5 + H2O -> POCl3 + HCl
    Zn + KOH -> K2ZnO2 + H2
    Al2O3 + Na2CO3 -> NaAlO2 + CO2
    PCl5 + KNO2 -> NOCl + POCl3 + KCl
    Zn + HCl -> ZnCl2 + H2
    BeO + C + Cl2 -> BeCl2 + CO
    N2 + O2 -> N2O
    BeSO4 + NH4OH -> Be(OH)2 + (NH4)2SO4
    Cu(CN)2 -> CuCN + C2N2
    SiC + Cl2 -> SiCl4 + C
    NH3 + O2 -> HNO3 + H2O
    Fe2(C2O4)3 -> FeC2O4 + CO2
    H2 + O2 -> H2O
    K + Br2 -> KBr
    CO + O2 -> CO2
    HNO2 + O2 -> HNO3
    O2 -> O3
    NaHCO3 -> Na2CO3 + CO2 + H2O
    CO2 + NH3 -> OC(NH2)2 + H2O
    Xe + F2 -> XeF6
    MnS + HCl -> H2S + MnCl2
    CaC2 + H2O -> C2H2 + Ca(OH)2
    ClO2 + H2O -> HClO2 + HClO3
    CuSO4 + KCN -> Cu(CN)2 + K2SO4
    NaOH + FeSO4 -> Na2SO4 + Fe(OH)2
    Ca(OH)2 + H3PO4 -> CaHPO4 + H2O
    PbCrO4 + HNO3 -> Pb(NO3)2 + H2CrO4
    HgO -> Hg + O2
    (CN)2 + NaOH -> NaCN + NaOCN + H2O
    BaCO3 + HNO3 -> Ba(NO3)2 + CO2 + H2O
    H3AsO4 -> As2O5 + H2O
    CaO + C -> CaC2 + CO
    Zn(OH)2 + NaOH -> Na2ZnO2 + H2O
    HNO3 + P2O5 -> N2O5 + HPO3
    UF4 + Mg -> MgF2 + U
    Mn2O3 + Al -> Al2O3 + Mn
    MnO2 + K2CO3 + KNO3 -> K2MnO4 + KNO2 + CO2
    AlN + H2O -> NH3 + Al(OH)3
    Ca3(PO4)2 + H2SO4 -> CaSO4 + Ca(H2PO4)2
    S + N2O -> SO2 + N2
    N2 + H2 -> NH3
    CaCO3 + HCl -> CaCl2 + H2O + CO2
    As2O3 + H2O -> H3AsO3
    Be(OH)2 + NH4HF2 -> (NH4)2BeF4 + H2O
    NaOH + Zn(NO3)2 -> NaNO3 + Zn(OH)2
    MgNH4PO4 -> Mg2P2O7 + NH3 + H2O
    H3PO4 + Ca(OH)2 -> Ca(H2PO4)2 + H2O
    CaS + H2O -> Ca(HS)2 + Ca(OH)2
    Cu + CO2 + O2 + H2O -> CuCO3.Cu(OH)2
    (NH4)2BeF4 -> BeF2 + NH3 + HF
    Sn(OH)2 + NaOH -> Na2SnO2 + H2O
    NH4VO3 -> V2O5 + NH3 + H2O
    H3AsO3 -> As2O3 + H2O
    NaCl + H2SO4 -> Na2SO4 + HCl
    Fe(OH)3 -> Fe2O3 + H2O
    As2O5 + H2O -> H3AsO4
    NaOH + Cl2 -> NaCl + NaClO + H2O
    VO2Cl + NH4OH -> NH4VO3 + NH4Cl + H2O
    B2O3 + H2O -> H3BO3
    CH4 + O2 -> CO2 +H2O
    SiH4 + O2 -> SiO2 + H2O
    TiCl4 + Mg -> MgCl2 + Ti
    Pb(OH)2 + NaOH -> Na2PbO2 + H2O
    Si + NaOH + H2O -> Na2SiO3 + H2
    Si + S8 -> Si2S4
    CaS2 + O2 -> CaS2O3
    Na2SnO3 + H2S -> SnS2 + NaOH + H2O
    Na2S2 + O2 -> Na2S2O3
    (NH4)2Cr2O7 -> Cr2O3 + N2 + H2O
    HCl + K2CO3 -> KCl + H2O + CO2
    KClO3 -> KCl + O2
    Zn + NaOH + H2O -> Na2Zn(OH)4 + H2
    Na2CO3 + HCl -> NaCl + H2O + CO2
    Ca(OH)2 + P4O10 + H2O -> Ca(H2PO4)2
    CaS + H2O + CO2 -> Ca(HCO3)2 + H2S
    Sn(OH)4 + NaOH -> Na2SnO3 + H2O
    Na + H2O -> NaOH + H2
    Ca3(PO4)2 + SiO2 -> CaSiO3 + P2O5
    FeCl3 + NH4OH -> Fe(OH)3 + NH4Cl
    H3PO3 -> H3PO4 + PH3
    AlCl3 + AgNO3 -> AgCl + Al(NO3)3
    KOH + AlCl3 -> KCl + Al(OH)3
    H2SO4 + NaHCO3 -> Na2SO4 + CO2 + H2O
    SiO2 + HF -> SiF4 + H2O
    CaCN2 + H2O -> CaCO3 + NH3
    HCl + HNO3 -> NOCl + Cl2 + H2O
    KClO3 -> KClO4 + KCl
    P4 + O2 -> P2O5
    P4O10 + HCl -> POCl3 + HPO3
    Sb + O2 -> Sb4O6
    NH4Cl + Ca(OH)2 -> CaCl2 + NH3 + H2O
    KBr + Al(ClO4)3 -> AlBr3 + KClO4
    AgNO3 + FeCl3 -> Fe(NO3)3 + AgCl
    Ca3(PO4)2 + H3PO4 -> Ca(H2PO4)2
    POCl3 + H2O -> H3PO4 + HCl
    C2H5OH + O2 -> CO + H2O
    UO2 + HF -> UF4 + H2O
    Ag2S + KCN -> KAg(CN)2 + K2S
    C + SiO2 + Cl2 -> SiCl4 + CO
    PCl3 + H2O -> H3PO3 + HCl
    H3PO4 + (NH4)2MoO4 + HNO3 -> (NH4)3PO4.12MoO3 + NH4NO3 + H2O
    MnO2 + HCl -> MnCl2 + H2O + Cl2
    Fe2O3 + C -> CO + Fe
    PCl5 + P2O5 -> POCl3
    FeO + H3PO4 -> Fe3(PO4)2 + H2O
    Ca(NO3)2 -> CaO + NO2 + O2
    Fe + O2 -> Fe2O3
    Fe2O3 + H2 -> Fe + H2O
    FeSO4 + K3[Fe(CN)6] -> Fe3[Fe(CN)6]2 + K2SO4
    NH3 + O2 -> HNO2 + H2O
    Al + O2 -> Al2O3
    BaCl2 + Al2(SO4)3 -> BaSO4 + AlCl3
    Fe2(SO4)3 + Ba(NO3)2 -> BaSO4 + Fe(NO3)3
    Au2S3 + H2 -> Au + H2S
    Au + HCl + HNO3 -> AuCl3 + NO + H2O
    NiS + O2 -> NiO + SO2
    Al + FeO -> Al2O3 + Fe
    C2H5OH + O2 -> CO2 + H2O
    Na2O2 + H2O -> NaOH + O2
    Fe2O3 + CO -> Fe + CO2
    Pb(NO3)2 -> PbO + NO2 + O2
    Al2(SO4)3 + Ca(OH)2 -> CaSO4 + Al(OH)3
    Au2O3 -> Au + O2
    Ca3(PO4)2 + H2SO4 -> CaSO4 + H3PO4
    SiCl4 + H2O -> H4SiO4 + HCl
    Ca + AlCl3 -> CaCl2 + Al
    FeCl3 + Ca(OH)2 -> CaCl2 + Fe(OH)3
    Al2O3 + C + N2 -> AlN + CO
    NO + NaOH -> NaNO2 + H2O + N2O
    Pb3O4 + HNO3 -> Pb(NO3)2 + PbO2 + H2O
    CuSO4 + KCN -> CuCN + K2SO4 + C2N2
    KO2 + CO2 -> K2CO3 + O2
    P4O6 -> P4 + P2O4
    P4O10 + H2O -> H3PO4
    Al + KOH + H2O -> KAlO2 + H2
    Fe + H2O + O2 -> Fe2O3.H2O
    H3PO4 + HCl -> PCl5 + H2O
    MnO2 + KOH + O2 -> K2MnO4 + H2O
    K2CO3 + C + N2 -> KCN + CO
    PCl5 + H2O -> H3PO4 + HCl
    P4O6 + H2O -> H3PO3
    Al(OH)3 + H2SO4 -> Al2(SO4)3 + H2O
    Fe2(SO4)3 + KOH -> K2SO4 + Fe(OH)3
    Bi(NO3)3 + H2S -> Bi2S3 + HNO3
    V2O5 + HCl -> VOCl3 + H2O
    Cr(OH)3 + H2SO4 -> Cr2(SO4)3 + H2O
    Hg(OH)2 + H3PO4 -> Hg3(PO4)2 + H2O
    Fe + H2O -> Fe3O4 + H2
    Ca3P2 + H2O -> Ca(OH)2 + PH3
    H2SO4 + Al(OH)3 -> Al2(SO4)3 + H2O
    Al(NO3)3 + Na2CO3 -> Al2(CO3)3 + NaNO3
    K2MnO4 + H2SO4 -> KMnO4 + MnO2 + K2SO4 + H2O
    Na3AsO3 + H2S -> As2S3 + NaOH
    Mg3N2 + H2O -> Mg(OH)2 + NH3
    Fe3O4 + H2 -> Fe + H2O
    C2H2 + O2 -> CO2 + H2O
    (NH4)2Cr2O7 -> NH3 + H2O + Cr2O3 + O2
    C3H8 + O2 -> CO2 + H2O
    As + NaOH -> Na3AsO3 + H2
    H3BO3 + Na2CO3 -> Na2B4O7 + CO2 + H2O
    Al + HCl -> AlCl3 + H2
    V2O5 + Ca -> CaO + V
    H3BO3 -> H4B6O11 + H2O
    Na2B4O7 + HCl + H2O -> NaCl + H3BO3
    Pb + Na + C2H5Cl -> Pb(C2H5)4 + NaCl
    C2H3Cl + O2 -> CO2 + H2O + HCl
    CaHPO4.2H2O + NaOH + H2O -> Na2HPO4.12H2O + Ca(OH)2
    Ca3(PO4)2 + SiO2 -> P4O10 + CaSiO3
    Se + NaOH -> Na2Se + Na2SeO3 + H2O
    Al + NaOH + H2O -> NaAl(OH)4 + H2
    K3AsO4 + H2S -> As2S5 + KOH + H2O
    I2 + HNO3 -> HIO3 + NO2 + H2
    Al + NH4ClO4 -> Al2O3 + AlCl3 + NO + H2O
    FeS + O2 -> Fe2O3 + SO2
    Ca3(PO4)2 + C -> Ca3P2 + CO
    FeC2O4⋅2H2O + H2C2O4 + H2O2 + K2C2O4 -> K3[Fe(C2O4)3]⋅3H2O
    MgNH4AsO4.6H2O -> Mg2As2O7 + NH3 + H2O
    H2SO4 + HI -> H2S + I2 + H2O
    U3O8 + HNO3 -> UO2(NO3)2 + NO2 + H2O
    (NH4)3AsS4 + HCl -> As2S5 + H2S + NH4Cl
    Pb3(VO4)2.PbCl2 + HCl -> VO2Cl + PbCl2 + H2O
    NH3 + O2 -> NO + H2O
    Hg2CrO4 -> Cr2O3 + Hg + O2
    Al4C3 + H2O -> CH4 + Al(OH)3
    Ca10F2(PO4)6 + H2SO4 -> Ca(H2PO4)2 + CaSO4 + HF
    Ca5F(PO4)3 + H2SO4 -> Ca(H2PO4)2 + CaSO4 + HF
    UO2(NO3)2.6H2O -> UO3 + NO2 + O2 + H2O
    S8 + O2 -> SO3
    NH3 + NO -> N2 + H2O
    HClO4 + P4O10 -> H3PO4 + Cl2O7
    Au + KCN + O2 + H2O -> K[Au(CN)2] + KOH
    CO2 + H2O -> C6H12O6 + O2
    V2O5 + Al -> Al2O3 + V
    FeS2 + O2 -> Fe2O3 + SO2
    Si2H3 + O2 -> SiO2 + H2O
    P4 + H2O -> H3PO4 + H2
    H2S + Cl2 -> S8 + HCl
    C4H10 + O2 -> CO2 + H2O
    Ca3(PO4)2 + SiO2 + C -> CaSiO3 + P4 + CO
    C6H6 + O2 -> CO2 + H2O
    C10H16 + Cl2 -> C + HCl
    C7H6O2 + O2 -> CO2 + H2O
    C7H16 + O2 -> CO2 + H2O
    C7H10N + O2 -> CO2 + H2O + NO2
    KNO3 + C12H22O11 -> N2 + CO2 + H2O + K2CO3
    K4Fe(CN)6 + KMnO4 + H2SO4 -> KHSO4 + Fe2(SO4)3 + MnSO4 + HNO3 + CO2 + H2O
    K3[Fe(SCN)6] + Na2Cr2O7 + H2SO4 -> Fe(NO3)3 + Cr2(SO4)3 + CO2 + H2O + Na2SO4 + KNO3
    K4[Fe(SCN)6] + K2Cr2O7 + H2SO4 -> Fe2(SO4)3 + Cr2(SO4)3 + CO2 + H2O + K2SO4 + KNO3'''.split(
        '\n')

    q = choice(eq)
    e = q.split('->')
    r = e[0].split('+')
    p = e[1].split('+')
    mass = randint(1, 100)
    reac, prod = balance_stoichiometry(set(r), set(p))
    reacs = list(dict(reac).keys())
    reacVals = list(dict(reac).values())

    prods = list(dict(prod).keys())
    prodVals = list(dict(prod).values())

    try:
        mm0 = Substance.from_formula(str(reacs[0])).molar_mass(u)
        mm1 = Substance.from_formula(str(reacs[1])).molar_mass(u)
        ans = ((((mass / mm0) * reacVals[1]) / reacVals[0]) * mm1) * u.g
    except:
        return redirect(url_for('stoic'))

    return render_template('stoic.html',
                           equation=q,
                           reac=reacs,
                           reacVals=reacVals,
                           prod=prods,
                           prodVal=prodVals,
                           mass=mass,
                           mm0=mm0,
                           mm1=mm1,
                           ans=ans)
コード例 #23
0
 def Balance(self):
     reag, prod = balance_stoichiometry(self.reativos, self.produtos)
     return reag, prod