Convert molecule to RDMol

def to_rdmol(mol):
    """Convert molecule to RDMol"""
    rwmol = Chem.RWMol(Chem.MolFromSmiles(''))
    key_to_idx = {}
    bond_type = {1: Chem.BondType.SINGLE,
                 2: Chem.BondType.DOUBLE,
                 3: Chem.BondType.TRIPLE}
    conf = Chem.Conformer(rwmol.GetNumAtoms())
    for k, a in mol.atoms_iter():
        i = rwmol.AddAtom(Chem.Atom(atom_number(a.symbol)))
        key_to_idx[k] = i
        conf.SetAtomPosition(i, a.coords)
    rwmol.AddConformer(conf)
    for u, v, b in mol.bonds_iter():
        ui = key_to_idx[u]
        vi = key_to_idx[v]
        rwmol.AddBond(ui, vi, bond_type[b.order])
    Chem.GetSSSR(rwmol)  # Ring recognition is required for fingerprint
    rwmol.UpdatePropertyCache(strict=False)
    return rwmol.GetMol()