Esempio n. 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
Esempio n. 2
0
def bond_features(bond: Chem.rdchem.Bond,
                  args) -> List[Union[bool, int, float]]:
    """
    Builds a feature vector for a bond.

    :param bond: A RDKit bond.
    :return: A list containing the bond features.
    """
    bond_fdim = get_bond_fdim(args)

    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)
        ]
        # if args.chiral_features:
        #     fbond += onek_encoding_unk(int(bond.GetStereo()), list(range(6))) # remove global cis/trans tags
    return fbond
Esempio n. 3
0
def getBondFeatures(b: Chem.rdchem.Bond):
    return [
        b.GetBeginAtomIdx(),
        b.GetEndAtomIdx(),
        b.GetBondTypeAsDouble(),
        int(b.GetIsAromatic()),
        int(b.GetIsConjugated())
    ]
Esempio n. 4
0
def get_path_bond_feature(bond: Chem.rdchem.Bond):
    """Given a rdkit bond object, returns the bond features for that bond.

    When the given input is none, returns a 0-vector"""
    if bond is None:
        return torch.zeros(N_BOND_FEATS)
    else:
        bond_type = onek_unk_encoding(bond.GetBondType(), BOND_TYPES)
        conj = [int(bond.GetIsConjugated())]
        ring = [int(bond.IsInRing())]

        return torch.Tensor(bond_type + conj + ring)
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
Esempio n. 6
0
def get_bond_features(bond:Chem.rdchem.Bond) -> np.ndarray:
    "Concats all bond features together and returns numpy array of bools"
    
    potential_bond_types_list = [Chem.rdchem.BondType.SINGLE,
                                 Chem.rdchem.BondType.DOUBLE,
                                 Chem.rdchem.BondType.TRIPLE,
                                 Chem.rdchem.BondType.AROMATIC]
    
    encoded_bond_type_list = one_of_k(bond.GetBondType(),
                                      potential_bond_types_list)
    
    feature_vector = np.array(encoded_bond_type_list + 
                              [bond.GetIsConjugated()] +
                              [bond.IsInRing()])
    
    return feature_vector
Esempio n. 7
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
Esempio n. 8
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
Esempio n. 9
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)
        conj = [0]
        ring = [0]
    else:
        bond_type = onek_unk_encoding(bond.GetBondType(), BOND_TYPES)
        conj = [int(bond.GetIsConjugated())]
        ring = [int(bond.IsInRing())]

    if bt_only:
        feature_array = bond_type
    else:
        feature_array = bond_type + conj + ring
    return torch.Tensor(feature_array)
Esempio n. 10
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