def convert(cycle, pyroleLike, usedPyroles):
    """cycle, pyroleLike, aromatic=0-> aromatize the cycle
    pyroleLike is a lookup of the pyrole like atoms in the
    cycle.
    return 1 if the cycle was aromatized
           2 if the cycle could not be aromatized"""
    bonds = cycle.bonds
    atoms = cycle.atoms
    initialBondStates = []
    initialAtomStates = []
    _usedPyroles = {}
    for bond in bonds:
        initialBondStates.append((bond, bond.symbol, bond.bondorder, bond.
            bondtype, bond.aromatic, bond.stereo))
        bond.reset(':', bond.bondorder, 4, bond.fixed, bond.stereo)
    aromatized = 1
    for atom in atoms:
        initialAtomStates.append((atom, atom.aromatic))
        atom.aromatic = 1
        nonhydrogens = atom.sumBondOrders() + atom.charge
        for valence in atom.valences:
            neededHydrogens = int(valence - nonhydrogens)
            if neededHydrogens >= 0:
                break
        else:
            if len(cycle) == 5 and atom.handle in pyroleLike:
                _usedPyroles[atom.handle] = 1
            else:
                aromatized = 0
                break
    assert len(_usedPyroles) <= 1, 'Too many used pyroles!'
    cycle.aromatic = aromatized
    if not aromatized:
        for bond, symbol, order, bondtype, aromatic, stereo in initialBondStates:
            bond.reset(symbol, order, bondtype, bond.fixed, stereo)
        for atom, aromatic in initialAtomStates:
            atom.aromatic = aromatic
    else:
        usedPyroles.update(_usedPyroles)
    return aromatized
