コード例 #1
0
def bond_features(bond: Chem.rdchem.Bond) -> List[Union[bool, int, float]]:
    """
    Builds a feature vector for a bond.

    :param bond: A RDKit bond.
    :return: A list containing the bond features.
    """
    if bond is None:
        fbond = [1] + [0] * (BOND_FDIM - 1)
    else:
        bt = bond.GetBondType()
        fbond = [
            0,  # bond is not None
            (bond.IsInRingSize(3) if bt is not None else 0),
            (bond.IsInRingSize(4) if bt is not None else 0),
            (bond.IsInRingSize(5) if bt is not None else 0),
            (bond.IsInRingSize(6) if bt is not None else 0),
            (bond.IsInRingSize(7) if bt is not None else 0),
            (bond.IsInRingSize(8) if bt is not None else 0),
            (bond.IsInRingSize(9) if bt is not None else 0),
            (bond.IsInRingSize(10) if bt is not None else 0),
        ]
    return fbond
def bond_in_member_rings(bond: Chem.rdchem.Bond):
    """
    Show each bond of the molecule is involved in 3, 4, 5, 6, 7, 8 member rings
    """
    vector = [
        0
    ] * 7  # If value is not in the [3, 4, 5, 6, 7, 8], then the final element in the vector is 1.
    for index, member_ring in enumerate(range(3, 9)):
        if bond.IsInRingSize(member_ring):
            vector[index] = 1

    if vector == [0] * 7:
        vector[-1] = 1

    return vector