def __init__(self, lig_feature, env_feature):
        ftype_names = {
            Pharm.FeatureType.H_BOND_ACCEPTOR: 'HBA',
            Pharm.FeatureType.H_BOND_DONOR: 'HBD',
            Pharm.FeatureType.POS_IONIZABLE: 'PI',
            Pharm.FeatureType.NEG_IONIZABLE: 'NI',
            Pharm.FeatureType.AROMATIC: 'AR',
            Pharm.FeatureType.HYDROPHOBIC: 'H',
            Pharm.FeatureType.X_VOLUME: 'XV'
        }

        lig_feature_type = ftype_names[Pharm.getType(lig_feature)]
        lig_residue_code = Biomol.getResidueCode(
            Pharm.getSubstructure(lig_feature).atoms[0])
        lig_residue_number = Biomol.getResidueSequenceNumber(
            Pharm.getSubstructure(lig_feature).atoms[0])
        lig_residue_chain = Biomol.getChainID(
            Pharm.getSubstructure(lig_feature).atoms[0])

        env_feature_type = ftype_names[Pharm.getType(env_feature)]
        env_residue_code = Biomol.getResidueCode(
            Pharm.getSubstructure(env_feature).atoms[0])
        env_residue_number = Biomol.getResidueSequenceNumber(
            Pharm.getSubstructure(env_feature).atoms[0])
        env_residue_chain = Biomol.getChainID(
            Pharm.getSubstructure(env_feature).atoms[0])

        self.interaction_type = '{}-{}'.format(lig_feature_type,
                                               env_feature_type)
        self.lig_residue = '{}_{}_{}'.format(lig_residue_code,
                                             lig_residue_number,
                                             lig_residue_chain)
        self.env_residue = '{}_{}_{}'.format(env_residue_code,
                                             env_residue_number,
                                             env_residue_chain)

        atoms = []
        for atom in Pharm.getSubstructure(lig_feature).atoms:
            key_atom = '{}:{}'.format(Chem.getSymbol(atom),
                                      Biomol.getSerialNumber(atom))
            atoms.append(key_atom)

        self.lig_atom = sorted(atoms, key=lambda k: int(k.split(':')[1]))

        atoms = []
        for atom in Pharm.getSubstructure(env_feature).atoms:
            key_atom = '{}:{}'.format(Chem.getSymbol(atom),
                                      Biomol.getSerialNumber(atom))
            atoms.append(key_atom)

        self.env_atom = sorted(atoms, key=lambda k: int(k.split(':')[1]))
示例#2
0
def encodePhaInfo2(surface, pha, invert=False):
    types = [-1, -1, -1, 0, 1, 2, 3, -1, -1, -1, -1, -1]
    invertedTypes = [-1, -1, -1, 1, 0, 3, 2, -1, -1, -1, -1, -1]
    typeCount = 4
    encoding = np.full((len(surface), typeCount), np.inf)
    count = 0
    for feature in pha:
        count = count + 1
        featureType = Pharm.getType(feature)
        if invert:
            index = invertedTypes[featureType]
        else:
            index = types[featureType]
        if index < 0:
            continue
        featureCoords = np.array(Chem.get3DCoordinates(feature))
        for i in range(len(surface)):
            pt = surface[i]
            dist = np.linalg.norm(pt - featureCoords)
            encoding[i][index] = min(encoding[i][index], dist)
    print(count)
    for enc in encoding:
        minV = 0
        for i in range(typeCount):
            if enc[minV] > enc[i]:
                minV = i
        # minDist = enc[minV]
        for i in range(typeCount):
            enc[i] = 0
        # if minDist < 20:
        enc[minV] = 1
    return encoding
示例#3
0
def outputInteractions(lig_pharm, env_pharm, interactions, df_constructor):
    i = 0

    interaction_at_ts = dict()

    for lig_ftr in lig_pharm:
        if Pharm.hasSubstructure(lig_ftr) == False:
            continue
        elif ftype_names[Pharm.getType(lig_ftr)] == 'XV':
            continue
        elif len(interactions.getValues(lig_ftr)) < 1:
            continue
        ligand_key = generate_key(lig_ftr)
        print 'Ligand feature : ' + str(ligand_key) + ' interacts with: '

        env_ftrs = interactions.getValues(lig_ftr)
        if df_constructor.has_key(ligand_key):
            dic_of_env_key = df_constructor[ligand_key]
        else:
            dic_of_env_key = {}

        dic_of_env_key_at_ts = {}
        for env_ftr in env_ftrs:
            if Pharm.hasSubstructure(env_ftr) == False:
                continue
            elif ftype_names[Pharm.getType(lig_ftr)] == 'XV':
                continue
            env_key = generate_key(env_ftr)
            if dic_of_env_key.has_key(env_key):
                dic_of_env_key_at_ts[env_key] = 1
                dic_of_env_key[env_key] += 1
            else:
                dic_of_env_key[env_key] = 1
                dic_of_env_key_at_ts[env_key] = 1

            print ' - ' + str(env_key)

        df_constructor[ligand_key] = dic_of_env_key
        interaction_at_ts[ligand_key] = dic_of_env_key_at_ts

    return df_constructor, interaction_at_ts
示例#4
0
def create_pha_spheres(pha, radius=0.5):
    colors = [[1, 1, 1], [1, 1, 1], [1, 1, 1], [0, 1, 1], [0, 1, 0], [1, 0, 1],
              [1, 1, 0], [1, 1, 1], [1, 1, 1], [1, 1, 1], [1, 1, 1], [1, 1, 1]]
    vis_list = []
    for feature in pha:
        featureType = Pharm.getType(feature)
        featureCoords = np.array(Chem.get3DCoordinates(feature))
        mesh_sphere = o3d.geometry.TriangleMesh.create_sphere(radius=radius)
        mesh_sphere.compute_vertex_normals()
        mesh_sphere.paint_uniform_color(np.array(colors[featureType]))
        mesh_sphere.translate(featureCoords)
        vis_list.append(mesh_sphere)
    return vis_list
def calculateStandardProperties(mol):
    standardProperties = {
        'nrAcceptors': [],
        'nrDonors': [],
        # 'nrRings': [],
        'nrRotBonds': [],
        'molWeight': [],
        'nrHeavyAtoms': [],
        'cLogP': [],
        'TPSA': [],
    }

    try:
        iter(mol)
    except:
        mol = [mol]

    for m in mol:
        Chem.calcTopologicalDistanceMatrix(m, True)

        p = getPharmacophore(m)
        hba, hbd = 0, 0
        for f in p:
            if Pharm.getType(f) == Pharm.FeatureType.H_BOND_ACCEPTOR:
                hba += 1
            elif Pharm.getType(f) == Pharm.FeatureType.H_BOND_DONOR:
                hbd += 1

        standardProperties['nrAcceptors'].append(hba)
        standardProperties['nrDonors'].append(hbd)
        standardProperties['molWeight'].append(Chem.calcExplicitMass(m))
        standardProperties['nrHeavyAtoms'].append(Chem.getHeavyAtomCount(m))
        standardProperties['cLogP'].append(Chem.calcXLogP(m))
        standardProperties['TPSA'].append(Chem.calcTPSA(m))
        standardProperties['nrRotBonds'].append(
            Chem.getRotatableBondCount(m, False, False))

    return standardProperties
示例#6
0
 def _generateNodes(self, pha):
     ''' 
     PRIVATE METHOD
     generates the nodes of the graph \n
     Input \n
     pha (CDPL BasicPharmacophore): pha the graph is based on
     '''
     index_counter = 0
     for feature in pha:
         node = PhaNode()
         node.feature_type = self._getAllowedSet(Pharm.getType(feature),
                                                 ELEM_LIST)
         node.coords[0] = round(Chem.get3DCoordinates(feature)[0], 6)
         node.coords[1] = round(Chem.get3DCoordinates(feature)[1], 6)
         node.coords[2] = round(Chem.get3DCoordinates(feature)[2], 6)
         node.index = index_counter
         index_counter += 1
         self.nodes.append(node)
示例#7
0
def encodePhaInfo(surface, pha, invert=False):
    types = [3, 4, 5, 6]
    invertedTypes = [4, 3, 6, 5]
    encoding = np.zeros((len(surface), len(types)))
    for feature in pha:
        featureType = Pharm.getType(feature)
        if featureType not in types:
            continue
        featureCoords = np.array(Chem.get3DCoordinates(feature))
        for i in range(len(surface)):
            pt = surface[i]
            dist = np.linalg.norm(pt - featureCoords)
            if invert:
                index = invertedTypes.index(featureType)
            else:
                index = types.index(featureType)
            encoding[i][index] = max(encoding[i][index], 1 / (1 + dist))
    return encoding
示例#8
0
        def generate_key(ftr):
            first_atom = Pharm.getSubstructure(ftr).atoms[0]
            base = str(ftype_names[Pharm.getType(ftr)]) + '[' + str(
                Biomol.getResidueCode(first_atom)) + '_' + str(
                    Biomol.getResidueSequenceNumber(first_atom)) + '_' + str(
                        Biomol.getChainID(first_atom))
            atoms_list = []
            for a in Pharm.getSubstructure(ftr).atoms:
                if Biomol.hasSerialNumber(a) == False:
                    continue

                atom_id = str(Biomol.getSerialNumber(a))
                atoms_list.append(atom_id)

            atom_key = ""
            for k in sorted(atoms_list, key=natural_sort_key, reverse=True):
                atom_key += '_' + k

            key = base + atom_key + ']'
            return key
示例#9
0
        def generate_ph(pdb, key):

            ifs = Base.FileIOStream(pdb, 'r')
            tlc = self.ligand_3_letter_code
            pdb_reader = Biomol.PDBMoleculeReader(ifs)
            pdb_mol = Chem.BasicMolecule()

            print '- Reading input: ', pdb, ' ...'

            if not pdb_reader.read(pdb_mol):
                print '!! Could not read input molecule'
                return

            print '- Processing macromolecule', pdb, ' ...'

            i = 0

            while i < pdb_mol.getNumBonds():
                bond = pdb_mol.getBond(i)

                if Chem.isMetal(bond.atoms[0]) or Chem.isMetal(bond.atoms[1]):
                    pdb_mol.removeBond(i)
                else:
                    i += 1

            Chem.calcImplicitHydrogenCounts(pdb_mol, True)
            Chem.perceiveHybridizationStates(pdb_mol, True)
            Chem.makeHydrogenComplete(pdb_mol)
            Chem.setAtomSymbolsFromTypes(pdb_mol, False)
            Chem.calcImplicitHydrogenCounts(pdb_mol, True)
            Biomol.setHydrogenResidueSequenceInfo(pdb_mol, False)
            Chem.setRingFlags(pdb_mol, True)
            Chem.setAromaticityFlags(pdb_mol, True)
            Chem.generateHydrogen3DCoordinates(pdb_mol, True)
            ligand = Chem.Fragment()

            print '- Extracting ligand ', tlc, ' ...'

            for atom in pdb_mol.atoms:
                if Biomol.getResidueCode(atom) == tlc:
                    Biomol.extractResidueSubstructure(atom, pdb_mol, ligand,
                                                      False)
                    break

            if ligand.numAtoms == 0:
                print '!! Could not find ligand', tlc, 'in input file'
                return

            Chem.perceiveSSSR(ligand, True)

            lig_env = Chem.Fragment()

            Biomol.extractEnvironmentResidues(ligand, pdb_mol, lig_env, 7.0)
            Chem.perceiveSSSR(lig_env, True)
            print '- Constructing pharmacophore ...'
            lig_pharm = Pharm.BasicPharmacophore()
            env_pharm = Pharm.BasicPharmacophore()
            pharm_gen = Pharm.DefaultPharmacophoreGenerator(False)
            pharm_gen.generate(ligand, lig_pharm)
            pharm_gen.generate(lig_env, env_pharm)
            analyzer = Pharm.DefaultInteractionAnalyzer()
            interactions = Pharm.FeatureMapping()
            analyzer.analyze(lig_pharm, env_pharm, interactions)

            #------------------------- XVOLS

            int_env_ftrs = Pharm.FeatureSet()
            Pharm.getFeatures(int_env_ftrs, interactions, False)
            int_core_ftrs = Pharm.FeatureSet()
            Pharm.getFeatures(int_core_ftrs, interactions, True)
            int_pharm = Pharm.BasicPharmacophore(int_core_ftrs)

            for ftr in int_env_ftrs:
                if Pharm.getType(
                        ftr
                ) == Pharm.FeatureType.H_BOND_DONOR or Pharm.getType(
                        ftr) == Pharm.FeatureType.H_BOND_ACCEPTOR:
                    Pharm.setTolerance(ftr, 1.0)
                else:
                    Pharm.setTolerance(ftr, 1.5)

            Pharm.createExclusionVolumes(int_pharm, int_env_ftrs, 0.0, 0.1,
                                         False)
            int_env_ftr_atoms = Chem.Fragment()
            Pharm.getFeatureAtoms(int_env_ftrs, int_env_ftr_atoms)
            int_residue_atoms = Chem.Fragment()
            Biomol.extractResidueSubstructures(int_env_ftr_atoms, lig_env,
                                               int_residue_atoms, True)
            Chem.makeHydrogenDeplete(int_residue_atoms)

            def isAlphaAtom(atom):
                return Biomol.getResidueAtomName(atom) == 'CA'

            Chem.removeAtomsIfNot(int_residue_atoms, isAlphaAtom)
            Pharm.createExclusionVolumes(int_pharm, int_residue_atoms,
                                         Chem.Atom3DCoordinatesFunctor(), 1.0,
                                         2.0, False)

            features_in_ph = []
            for int_ftr in int_pharm:
                if Pharm.hasSubstructure(int_ftr) == False:
                    continue
                elif ftype_names[Pharm.getType(int_ftr)] == 'XV':
                    continue
                feature_id = generate_key(int_ftr)
                features_in_ph.append(str(feature_id))
                self.unique_feature_vector.add(str(feature_id))

            int_pharm.fv = features_in_ph
            int_pharm.path_to_pdb = pdb

            return int_pharm