def __init__(self, reference: str = None, target_s: str = None): ''' Setup of the SuCOS scoring class. If you do not set reference or target_s, you will have to feed them as rdkit mol objects to each class method/function. Sets: self.reference: an rdkit mol object of the reference mol self.target_s: a list of rdkit mol objects for the target mols :param reference: an sdf or mol file containing the reference (hit) molecule :param target_s: an sdf or mol file containing one or multiple molecules to compare against reference ''' self.fdef = AllChem.BuildFeatureFactory( os.path.join(RDConfig.RDDataDir, 'BaseFeatures.fdef')) self.fmParams = {} for k in self.fdef.GetFeatureFamilies(): self.fparams = FeatMaps.FeatMapParams() self.fmParams[k] = self.fparams self.keep = ('Donor', 'Acceptor', 'NegIonizable', 'PosIonizable', 'ZnBinder', 'Aromatic', 'Hydrophobe', 'LumpedHydrophobe') if reference: refs = Chem.SDMolSupplier(reference, sanitize=True) self.reference = [x for x in refs if x][0] if target_s: tgts = Chem.SDMolSupplier(target_s, sanitize=True) self.target_s = [x for x in tgts if x]
def donor_acceptor(mol): fdef = AllChem.BuildFeatureFactory( os.path.join(RDConfig.RDDataDir, 'BaseFeatures.fdef')) mol_feat = fdef.GetFeaturesForMol(mol) idx = [atom_feat.GetAtomIds()[0] for atom_feat in mol_feat] mol_idx = [atom.GetIdx() for atom in mol.GetAtoms()] k = list(range(mol.GetNumAtoms())) a = [i for i in mol_idx if i not in idx] for i, atom_feat in zip(idx, mol_feat): k[i] = atom_feat.GetFamily() for i in a: k[i] = "None" return k
def show_pharmacophore(sdf_path, keep=keep, fdf_dir=os.path.join(os.path.dirname(__file__), 'defined_BaseFeatures.fdef')): template_mol = [m for m in Chem.SDMolSupplier(sdf_path)][0] fdef = AllChem.BuildFeatureFactory(fdf_dir) prob_feats = fdef.GetFeaturesForMol(template_mol) prob_feats = [f for f in prob_feats if f.GetFamily() in keep] # prob_points = [list(x.GetPos()) for x in prob_feats] for i, feat in enumerate(prob_feats): atomids = feat.GetAtomIds() print("pharamcophore index:{0}; feature:{1}; type:{2}; atom id:{3}". format(i, feat.GetFamily(), feat.GetType(), atomids)) display( Draw.MolToImage(template_mol, highlightAtoms=list(atomids), highlightColor=[0, 1, 0], useSVG=True))
Publication: https://doi.org/10.26434/chemrxiv.8100203.v1 """ from __future__ import print_function import argparse, os, sys, gzip import numpy as np from rdkit import Chem, rdBase, RDConfig from rdkit.Chem import AllChem, rdShapeHelpers from rdkit.Chem.FeatMaps import FeatMaps import utils ### start function definitions ######################################### # Setting up the features to use in FeatureMap fdef = AllChem.BuildFeatureFactory(os.path.join(RDConfig.RDDataDir, 'BaseFeatures.fdef')) fmParams = {} for k in fdef.GetFeatureFamilies(): fparams = FeatMaps.FeatMapParams() fmParams[k] = fparams keep = ('Donor', 'Acceptor', 'NegIonizable', 'PosIonizable', 'ZnBinder', 'Aromatic', 'Hydrophobe', 'LumpedHydrophobe') def filterFeature(f): result = f.GetFamily() in keep # TODO - nothing ever seems to be filtered. Is this expected? if not result: utils.log("Filtered out feature type", f.GetFamily()) return result
import os from rdkit import Chem from rdkit.Chem import AllChem, rdShapeHelpers from rdkit.Chem.FeatMaps import FeatMaps from rdkit import RDConfig # Set up features to use in FeatureMap fdefName = os.path.join(RDConfig.RDDataDir, 'BaseFeatures.fdef') fdef = AllChem.BuildFeatureFactory(fdefName) fmParams = {} for k in fdef.GetFeatureFamilies(): fparams = FeatMaps.FeatMapParams() fmParams[k] = fparams keep = ('Donor', 'Acceptor', 'NegIonizable', 'PosIonizable', 'ZnBinder', 'Aromatic', 'Hydrophobe', 'LumpedHydrophobe') def get_FeatureMapScore(query_mol, ref_mol): featLists = [] for m in [query_mol, ref_mol]: rawFeats = fdef.GetFeaturesForMol(m) # filter that list down to only include the ones we're intereted in featLists.append([f for f in rawFeats if f.GetFamily() in keep]) fms = [ FeatMaps.FeatMap(feats=x, weights=[1] * len(x), params=fmParams) for x in featLists ] fms[0].scoreMode = FeatMaps.FeatMapScoreMode.Best fm_score = fms[0].ScoreFeats(featLists[1]) / min(fms[0].GetNumFeatures(),