def fmap_to_graphmap(G, H, f):
    """
    Takes source and target Graphs and a numeric map (list) from homsearch_interface, returns G-H-vertex map.
    Vertices assigned -1 are given None
    """

    # Work for Sage and NetworkX
    try:
        Gvs = G.vertices()
    except AttributeError:
        Gvs = G.nodes()
    try:
        Hvs = H.vertices()
    except AttributeError:
        Hvs = H.nodes()

    gf = {}
    for v in range(len(f)):
        fv = f[v]
        if fv >= 0:
            gf[Gvs[v]] = Hvs[fv]
        else:
            gf[Gvs[v]] = None
    return gf