Skip to content

graphchem.preprocessing.bond_to_str

Convert an RDKit Bond object to a string representation.

The string representation includes various properties of the bond, including bond type, conjugation, stereochemistry, ring size, and connected atom symbols.

Parameters

bond : rdkit.Chem.Bond An RDKit Bond object representing a single bond in a molecule.

Returns

str A string representation of the bond, including its properties.

Examples

from rdkit import Chem mol = Chem.MolFromSmiles('C=C') bond = mol.GetBondWithIndices(0, 1) bond_to_str(bond) "(DOUBLE, False, NONE, None, ['C', 'C'])"

Source code in graphchem/preprocessing/features.py
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
def bond_to_str(bond: "rdkit.Chem.Bond") -> str:
    """
    Convert an RDKit Bond object to a string representation.

    The string representation includes various properties of the bond,
    including bond type, conjugation, stereochemistry, ring size, and
    connected atom symbols.

    Parameters
    ----------
    bond : rdkit.Chem.Bond
        An RDKit Bond object representing a single bond in a molecule.

    Returns
    -------
    str
        A string representation of the bond, including its properties.

    Examples
    --------
    >>> from rdkit import Chem
    >>> mol = Chem.MolFromSmiles('C=C')
    >>> bond = mol.GetBondWithIndices(0, 1)
    >>> bond_to_str(bond)
    "(DOUBLE, False, NONE, None, ['C', 'C'])"
    """
    return str((
        bond.GetBondType(),
        bond.GetIsConjugated(),
        bond.GetStereo(),
        get_ring_size(bond),
        [sorted([bond.GetBeginAtom().GetSymbol(),
                 bond.GetEndAtom().GetSymbol()])]
    ))