コード例 #1
0
    def Match(self, mol, flg=True):
        # Find all the hetero-aromatic atoms
        hetero_atoms = [atom for atom in mol.GetAtoms(_is_hetereo_aromatic)]
        if len(hetero_atoms) < 2:
            # The caller just needs an iterable
            return hetero_atoms

        # There are at least two hetero-aromatic atoms.
        # Are there multiple ring systems?
        num_aromatic_systems, parts = OEDetermineAromaticRingSystems(mol)
        assert num_aromatic_systems >= 1
        # Are there hetero-atoms in different systems?
        atom_components = set(parts[atom.GetIdx()] for atom in hetero_atoms)
        if len(atom_components) > 1:
            return (1, 2)

        # The answer now is "at least one". But are there two?

        # All of the hetero-aromatic atoms are in the same ring system
        # This is the best answer I could think of, and it only works
        # with the OEChem toolkit: remove one of the bonds, re-find
        # the rings, and see if there's still an aromatic hetero-atom.
        hetero_atom = hetero_atoms[0]

        for bond in hetero_atom.GetBonds(OEIsAromaticBond()):
            newmol = OEGraphMol(mol)
            newmol_bond = newmol.GetBond(OEHasBondIdx(bond.GetIdx()))
            newmol.DeleteBond(newmol_bond)
            OEFindRingAtomsAndBonds(newmol)

            for atom in mol.GetAtoms(_is_hetereo_aromatic):
                return (1, 2)

        return (1, )
コード例 #2
0
def save_profile_as_sd(mol: oechem.OEGraphMol):
    oechem.OEDeleteSDData(mol, TOTAL_STRAIN_TAG)
    oechem.OESetSDData(mol, TOTAL_STRAIN_TAG, '')  # place holder

    oechem.OEDeleteSDData(mol, NUM_TORSION_PROFILES_TAG)
    oechem.OESetSDData(mol, NUM_TORSION_PROFILES_TAG, '')

    oechem.OEDeleteSDData(mol, NUM_LOW_CONFIDENCE_TORSIONS_TAG)
    oechem.OESetSDData(mol, NUM_LOW_CONFIDENCE_TORSIONS_TAG, '')

    strain_arr = np.zeros(1)
    strain_arr_high_conf_preds = np.zeros(1)

    num_torsion_profiles = 0
    num_low_confidence_torsions = 0

    can_torsions = get_canonical_torsions(mol)
    for num, can_torsion in enumerate(can_torsions):
        bond = mol.GetBond(can_torsion.b, can_torsion.c)
        if bond is not None and bond.HasData(ENERGY_PROFILE_TAG):
            num_torsion_profiles += 1
            bond_strains = bond.GetData(STRAIN_TAG)
            profile_offset = bond.GetData(PROFILE_OFFSET_TAG)
            if profile_offset < OFFSET_THRESHOLD and (
                    not bond.HasData(SKIP_TORSION_TAG)):
                strain_arr_high_conf_preds += np.array(bond_strains)

            strain_arr += np.array(bond_strains)

            offset = bond.GetData(PROFILE_OFFSET_TAG)
            profile_str = bond.GetData(ENERGY_PROFILE_TAG)
            pred_confidence_value = HIGH_PREDICTION_CONFIDENCE_TAG
            if offset > OFFSET_THRESHOLD or bond.HasData(SKIP_TORSION_TAG):
                profile_str = 'LOW CONFIDENCE - ' + profile_str
                pred_confidence_value = LOW_PREDICTION_CONFIDENCE_TAG
                num_low_confidence_torsions += 1

            #tor_atoms_str = bond.GetData(TORSION_ATOMS_FRAGMENT_TAG)
            #tor_atoms_str_list = tor_atoms_str.split(':')
            #a_idx, b_idx, c_idx, d_idx = list(map(int, tor_atoms_str_list[0].split()))

            tor_atoms_str1 = bond.GetData(TORSION_ATOMS_FRAGMENT_TAG)
            ca, cb, cc, cd = list(map(int, tor_atoms_str1.split()))

            apStr = "{}:{}:{}:{}".format(ca + 1, cb + 1, cc + 1, cd + 1)

            atom_ca = mol.GetAtom(oechem.OEHasAtomIdx(ca))
            atom_cb = mol.GetAtom(oechem.OEHasAtomIdx(cb))
            atom_cc = mol.GetAtom(oechem.OEHasAtomIdx(cc))
            atom_cd = mol.GetAtom(oechem.OEHasAtomIdx(cd))
            angle_float = oechem.OEGetTorsion(mol, atom_ca, atom_cb, atom_cc,
                                              atom_cd) * oechem.Rad2Deg

            sd_tag1 = 'TORSION_%s_ATOMS' % (num + 1)
            sd_tag2 = 'TORSION_%d_TORSIONNET_%s' % (num + 1,
                                                    ENERGY_PROFILE_TAG)
            sd_tag3 = 'TORSION_%d_TORSIONNET_PRED_CONFIDENCE' % (num + 1)
            sd_tag4 = 'TORSION_%d_TORSIONNET_PROFILE_OFFSET' % (num + 1)

            oechem.OEDeleteSDData(mol, sd_tag1)
            oechem.OEDeleteSDData(mol, sd_tag2)
            oechem.OEDeleteSDData(mol, sd_tag3)
            oechem.OEDeleteSDData(mol, sd_tag4)

            oechem.OESetSDData(mol, sd_tag1, apStr)
            oechem.OESetSDData(mol, sd_tag2, profile_str)

            sd_tag6 = 'TORSION_%d_%s' % ((num + 1), STRAIN_TAG)
            oechem.OEDeleteSDData(mol, sd_tag6)
            oechem.OESetSDData(mol, sd_tag6, '%.1f' % bond_strains)

            angle = '%.1f' % angle_float
            sd_tag5 = 'TORSION_%d_ANGLE' % (num + 1)
            oechem.OEDeleteSDData(mol, sd_tag5)
            oechem.OESetSDData(mol, sd_tag5, angle)
            oechem.OESetSDData(mol, sd_tag3, pred_confidence_value)
            oechem.OESetSDData(mol, sd_tag4, '%.2f' % offset)

    strain_str = '%.1f' % strain_arr_high_conf_preds[0]
    oechem.OESetSDData(mol, TOTAL_STRAIN_TAG, strain_str)
    oechem.OESetSDData(mol, NUM_TORSION_PROFILES_TAG,
                       str(num_torsion_profiles))
    oechem.OESetSDData(mol, NUM_LOW_CONFIDENCE_TORSIONS_TAG,
                       str(num_low_confidence_torsions))

    reorder_sd_props(mol)

    return mol