示例#1
0
def bond_features(bond: Chem.rdchem.Bond,
                  distance_path: int = None,
                  distance_3d: int = None) -> List[Union[bool, int, float]]:
    """
    Builds a feature vector for a bond.

    :param bond: A RDKit bond.
    :param distance_path: The topological (path) distance between the atoms in the bond.
    Note: This is always 1 if the atoms are actually bonded and >1 for "virtual" edges between non-bonded atoms.
    :param distance_3d: The bin index of the 3D distance in THREE_D_DISTANCE_BINS.
    :return: A PyTorch tensor containing the bond features.
    """
    if bond is None:
        fbond = [1] + [0] * (BOND_FDIM - 1)
    else:
        bt = bond.GetBondType()
        fbond = [
            0,  # bond is not None
            bt == Chem.rdchem.BondType.SINGLE,
            bt == Chem.rdchem.BondType.DOUBLE,
            bt == Chem.rdchem.BondType.TRIPLE,
            bt == Chem.rdchem.BondType.AROMATIC,
            (bond.GetIsConjugated() if bt is not None else 0),
            (bond.IsInRing() if bt is not None else 0)
        ]
        fbond += onek_encoding_unk(int(bond.GetStereo()), list(range(6)))

    if distance_path is not None:
        fbond += onek_encoding_unk(distance_path, PATH_DISTANCE_BINS)

    if distance_3d is not None:
        fbond += onek_encoding_unk(distance_3d, THREE_D_DISTANCE_BINS)

    return fbond
def get_bond_features(bond: Chem.rdchem.Bond) -> List[Union[bool, int, float]]:
    bond_type = bond.GetBondType()
    features = [
        0,  # bond is not None
        bond_type == Chem.rdchem.BondType.SINGLE,
        bond_type == Chem.rdchem.BondType.DOUBLE,
        bond_type == Chem.rdchem.BondType.TRIPLE,
        bond_type == Chem.rdchem.BondType.AROMATIC,
        (bond.GetIsConjugated() if bond_type is not None else 0),
        (bond.IsInRing() if bond_type is not None else 0)
    ]
    features += one_hot_vector(int(bond.GetStereo()),
                               list(range(6)),
                               extra_category=True)
    return features
示例#3
0
def bond_features(bond: Chem.rdchem.Bond) -> List[Union[bool, int, float]]:
    if bond is None:
        fbond = [1] + [0] * (BOND_FDIM - 1)
    else:
        bt = bond.GetBondType()
        fbond = [
            0,  # bond is not None
            bt == Chem.rdchem.BondType.SINGLE,
            bt == Chem.rdchem.BondType.DOUBLE,
            bt == Chem.rdchem.BondType.TRIPLE,
            bt == Chem.rdchem.BondType.AROMATIC,
            (bond.GetIsConjugated() if bt is not None else 0),
            (bond.IsInRing() if bt is not None else 0)
        ]
        fbond += onek_encoding_unk(int(bond.GetStereo()), list(range(6)))
    return fbond
示例#4
0
def bond_features(bond: Chem.rdchem.Bond) -> List[int]:
    """
    Builds a feature vector for a bond.
    :param bond: A RDKit bond.
    :return: A list containing the bond features.
    """
    assert bond is not None
    bt = bond.GetBondType()
    fbond = [
        0,  # bond is not None
        bt == Chem.rdchem.BondType.SINGLE,
        bt == Chem.rdchem.BondType.DOUBLE,
        bt == Chem.rdchem.BondType.TRIPLE,
        bt == Chem.rdchem.BondType.AROMATIC,
        (bond.GetIsConjugated() if bt is not None else 0),
        (bond.IsInRing() if bt is not None else 0)
    ]
    fbond += onek_encoding_unk(int(bond.GetStereo()), list(range(6)))
    return fbond
示例#5
0
def bond_features(bond: Chem.rdchem.Bond) -> List[Union[bool, int, float]]:
    """
    Builds a feature vector for a bond.

    :param bond: An 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
            bt == Chem.rdchem.BondType.SINGLE,
            bt == Chem.rdchem.BondType.DOUBLE,
            bt == Chem.rdchem.BondType.TRIPLE,
            bt == Chem.rdchem.BondType.AROMATIC,
            (bond.GetIsConjugated() if bt is not None else 0),
            (bond.IsInRing() if bt is not None else 0)
        ]
        fbond += onek_encoding_unk(int(bond.GetStereo()), list(range(6)))
    return fbond
示例#6
0
def get_bond_features(bond: Chem.rdchem.Bond, bt_only: bool = False):
    """Given an bond object, returns a numpy array of features.

    bond can be None, in which case returns default features for a non-bond.
    """
    # Bond features are bond type, conjugacy, and ring-membership
    if bond is None:
        bond_type = onek_unk_encoding(None, BOND_TYPES)
        stereo = [0]
        conj = [0]
        ring = [0]
    else:
        bond_type = onek_unk_encoding(bond.GetBondType(), BOND_TYPES)
        stereo = [int(bond.GetStereo())]
        fstereo = onek_unk_encoding(stereo, BT_STEREO)
        conj = [bond.GetIsConjugated()]
        ring = [bond.IsInRing()]

    if bt_only:
        feature_array = bond_type
    else:
        feature_array = bond_type + fstereo + conj + ring
    return torch.Tensor(feature_array)