def testRepeat(self): self._readData() nMols = len(self.smis) for i in range(nMols): smi = self.smis[i] mol = Chem.MolFromSmiles(smi) clog = self.clogs[i] tmp = Crippen.MolLogP(mol) tmp = Crippen.MolLogP(mol) self.failUnless(feq(clog,tmp),'bad logp fooutF,r %s: %4.4f != %4.4f'%(smi,clog,tmp)) mr = self.mrs[i] tmp = Crippen.MolMR(mol) tmp = Crippen.MolMR(mol) self.failUnless(feq(mr,tmp),'bad MR for %s: %4.4f != %4.4f'%(smi,mr,tmp))
def check_ligand(file_path): bool = False if os.path.isfile(file_path): suppl = Chem.SDMolSupplier(file_path) for mol in suppl: if mol is not None: # components of rule hydrogen_bond_doner = True if Lipinski.NumHDonors( mol) <= 5 else False hydrogen_bond_acceptors = True if Lipinski.NumHAcceptors( mol) <= 10 else False molecular_mass = True if Descriptors.ExactMolWt( mol) <= 500 else False octanol_water_partition_coefficient_logP = True if Crippen.MolLogP( mol) <= 5 else False components_rank = hydrogen_bond_doner + hydrogen_bond_acceptors + molecular_mass + octanol_water_partition_coefficient_logP # variants partition_coefficient_logP = True if -0.4 <= Crippen.MolLogP( mol) <= 5.6 else False molar_refractivity = True if 40 <= Crippen.MolMR( mol) <= 130 else False molecular_weight = True if 180 <= Descriptors.ExactMolWt( mol) <= 500 else False number_of_atoms = True if 20 <= Lipinski.HeavyAtomCount( mol) <= 70 else False polar_surface_area = True if MolSurf.TPSA( mol) <= 140 else False variants_rank = partition_coefficient_logP + molar_refractivity + molecular_weight + number_of_atoms + polar_surface_area if (components_rank == 4) and (variants_rank == 4 or variants_rank == 5): bool = True return bool
def testLogP(self): self._readData() nMols = len(self.smis) #outF = file(self.fName,'w') for i in range(nMols): smi = self.smis[i] mol = Chem.MolFromSmiles(smi) if 1: clog = self.clogs[i] tmp = Crippen.MolLogP(mol) self.failUnless(feq(clog,tmp),'bad logp for %s: %4.4f != %4.4f'%(smi,clog,tmp)) mr = self.mrs[i] tmp = Crippen.MolMR(mol) self.failUnless(feq(mr,tmp),'bad MR for %s: %4.4f != %4.4f'%(smi,mr,tmp)) else: clog = Crippen.MolLogP(mol) mr = Crippen.MolMR(mol) print >>outF,'%s,%.4f,%.4f'%(smi,clog,mr)
def run_filter(self, mol): """ This runs a Ghose filter for drug-likeliness. Ghose filter filters molecules by Molecular weight (MW), the number of atoms, and the logP value. We protonate the mol in this filter because hydrogens affect atom count. Our Ghose implementation counts hydrogens in against the total number of atoms. To pass the filter a molecule must be: MW between 160 and 480 dalton Number of Atoms: between 20 and 70 logP between -0,4 and +5,6 Inputs: :param rdkit.Chem.rdchem.Mol object mol: An rdkit mol object to be tested if it passes the filters Returns: :returns: bool bool: True if the mol passes the filter; False if it fails the filter """ # Make a copy of the mol so we can AddHs without affecting other filters # number of atoms is altered by the presence/absence of hydrogens. # Our Ghose filter counts hydrogenss towards atom count copy_mol = copy.deepcopy(mol) copy_mol = Chem.AddHs(copy_mol) exact_mwt = Descriptors.ExactMolWt(copy_mol) if ((exact_mwt < 160) or (exact_mwt > 480)): return False num_atoms = copy_mol.GetNumAtoms() if ((num_atoms < 20) or (num_atoms > 70)): return False # molar Refractivity MolMR = Crippen.MolMR(copy_mol) if ((MolMR < 40) or (MolMR > 130)): return False # molar LogP mol_log_p = Crippen.MolLogP(copy_mol) if ((mol_log_p < -0.4) or (mol_log_p > 5.6)): return False # passed all filters return True
def QSArproperties_test(array,forest, num, namefile): ##Bickerton, G.R.; Paolini, G.V.; Besnard, J.; Muresan, S.; Hopkins, A.L. (2012) ##Quantifying the chemical beauty of drugs, ##Nature Chemistry, 4, 90-98 ##[https://doi.org/10.1038/nchem.1243] # ##Wildman, S.A.; Crippen, G.M. (1999) ##Prediction of Physicochemical Parameters by Atomic Contributions, ##Journal of Chemical Information and Computer Sciences, 39, 868-873 ##[https://doi.org/10.1021/ci990307l] # fw = open( 'QSAR-2D' + str(num) + str(namefile) + '.csv', 'w') # for line in array: parameter= line.split(sep="\t",maxsplit=9) peptide_seq = parameter[0] peptide = parameter[1] # molpeptideLi = Chem.MolFromSmiles(peptide) # subprocess scoreSA_Li = calculateScore(molpeptideLi) # # Make Prediction Random-Forest fp_vect_Li = genFP(molpeptideLi) # Get probabilities predictionsLi = forest.predict_proba(fp_vect_Li.reshape(1,-1)) #print ("Probability %s mutagenic %0.6f " % (sequence,predictionsLi[0][1])) # See http://cdb.ics.uci.edu/cgibin/Smi2DepictWeb.py propQSAR = QED.properties(molpeptideLi) MolWeight = propQSAR.MW MolLogP = propQSAR.ALOGP HbondA = propQSAR.HBA HbondD = propQSAR.HBD PolarSA = propQSAR.PSA Rbonds = propQSAR.ROTB Aromatic = propQSAR.AROM # MolarRefractivity = Crippen.MolMR(molpeptideLi) nAtoms = molpeptideLi.GetNumAtoms() # SynthAcces = scoreSA_Li AmesMutagenic = predictionsLi[0][1] # result = ( str(MolWeight) + "\t" + str(MolLogP) + "\t" + str(HbondA) + "\t" + str(HbondD) + "\t" + str(PolarSA) + "\t" + str(Rbonds) + "\t" + str(MolarRefractivity) + "\t" + str(nAtoms) + "\t" + str(SynthAcces) + "\t" + str(AmesMutagenic) + "\t" + str (peptide_seq) + "\t" + str(peptide) + "\n") #print (result) fw.write(result) fw.close()
def CalculateMolMR(mol): """ ################################################################# Cacluation of molecular refraction value based on Crippen method ---->MR Usage: result=CalculateMolMR(mol) Input: mol is a molecule object. Output: result is a numeric value. ################################################################# """ return round(Crippen.MolMR(mol), 3)
def PhyChem(smiles): """ Calculating the 19D physicochemical descriptors for each molecules, the value has been normalized with Gaussian distribution. Arguments: smiles (list): list of SMILES strings. Returns: props (ndarray): m X 19 matrix as normalized PhysChem descriptors. m is the No. of samples """ props = [] for smile in smiles: mol = Chem.MolFromSmiles(smile) try: MW = desc.MolWt(mol) LOGP = Crippen.MolLogP(mol) HBA = Lipinski.NumHAcceptors(mol) HBD = Lipinski.NumHDonors(mol) rotable = Lipinski.NumRotatableBonds(mol) amide = AllChem.CalcNumAmideBonds(mol) bridge = AllChem.CalcNumBridgeheadAtoms(mol) heteroA = Lipinski.NumHeteroatoms(mol) heavy = Lipinski.HeavyAtomCount(mol) spiro = AllChem.CalcNumSpiroAtoms(mol) FCSP3 = AllChem.CalcFractionCSP3(mol) ring = Lipinski.RingCount(mol) Aliphatic = AllChem.CalcNumAliphaticRings(mol) aromatic = AllChem.CalcNumAromaticRings(mol) saturated = AllChem.CalcNumSaturatedRings(mol) heteroR = AllChem.CalcNumHeterocycles(mol) TPSA = MolSurf.TPSA(mol) valence = desc.NumValenceElectrons(mol) mr = Crippen.MolMR(mol) # charge = AllChem.ComputeGasteigerCharges(mol) prop = [ MW, LOGP, HBA, HBD, rotable, amide, bridge, heteroA, heavy, spiro, FCSP3, ring, Aliphatic, aromatic, saturated, heteroR, TPSA, valence, mr ] except Exception: print(smile) prop = [0] * 19 props.append(prop) props = np.array(props) props = Scaler().fit_transform(props) return props
def QSArproperties(mol, sa, seq, Ames): propQSAR = QED.properties(mol) """Bickerton, G.R.; Paolini, G.V.; Besnard, J.; Muresan, S.; Hopkins, A.L. (2012) Quantifying the chemical beauty of drugs, Nature Chemistry, 4, 90-98 [https://doi.org/10.1038/nchem.1243]""" # """Wildman, S.A.; Crippen, G.M. (1999) Prediction of Physicochemical Parameters by Atomic Contributions, Journal of Chemical Information and Computer Sciences, 39, 868-873 [https://doi.org/10.1021/ci990307l]""" # MolWeight = propQSAR.MW MolLogP = propQSAR.ALOGP HbondA = propQSAR.HBA HbondD = propQSAR.HBD PolarSA = propQSAR.PSA Rbonds = propQSAR.ROTB Aromatic = propQSAR.AROM MolarRefractivity = Crippen.MolMR(mol) SynthAcces = sa nAtoms = mol.GetNumAtoms() AmesMutagenic = Ames
def extract(x, from_smiles): if from_smiles: mol = Chem.MolFromSmiles(x) else: mol = x if (mol is None) or (len(mol.GetAtoms()) == 0): if include_3D: return [0] * 29 else: return [0] * 24 else: logP = Crippen.MolLogP(mol) refractivity = Crippen.MolMR(mol) weight = Descriptors.MolWt(mol) exact_weight = Descriptors.ExactMolWt(mol) heavy_weight = Descriptors.HeavyAtomMolWt(mol) heavy_count = Lipinski.HeavyAtomCount(mol) nhoh_count = Lipinski.NHOHCount(mol) no_count = Lipinski.NOCount(mol) hacceptor_count = Lipinski.NumHAcceptors(mol) hdonor_count = Lipinski.NumHDonors(mol) hetero_count = Lipinski.NumHeteroatoms(mol) rotatable_bond_count = Lipinski.NumRotatableBonds(mol) valance_electron_count = Descriptors.NumValenceElectrons(mol) amide_bond_count = rdMolDescriptors.CalcNumAmideBonds(mol) aliphatic_ring_count = Lipinski.NumAliphaticRings(mol) aromatic_ring_count = Lipinski.NumAromaticRings(mol) saturated_ring_count = Lipinski.NumSaturatedRings(mol) aliphatic_cycle_count = Lipinski.NumAliphaticCarbocycles(mol) aliphaticHetero_cycle_count = Lipinski.NumAliphaticHeterocycles( mol) aromatic_cycle_count = Lipinski.NumAromaticCarbocycles(mol) aromaticHetero_cycle_count = Lipinski.NumAromaticHeterocycles(mol) saturated_cycle_count = Lipinski.NumSaturatedCarbocycles(mol) saturatedHetero_cycle_count = Lipinski.NumSaturatedHeterocycles( mol) tpsa = rdMolDescriptors.CalcTPSA(mol) if include_3D: mol_3D = Chem.AddHs(mol) AllChem.EmbedMolecule(mol_3D) AllChem.MMFFOptimizeMolecule(mol_3D) eccentricity = rdMolDescriptors.CalcEccentricity(mol_3D) asphericity = rdMolDescriptors.CalcAsphericity(mol_3D) spherocity = rdMolDescriptors.CalcSpherocityIndex(mol_3D) inertial = rdMolDescriptors.CalcInertialShapeFactor(mol_3D) gyration = rdMolDescriptors.CalcRadiusOfGyration(mol_3D) return [ logP, refractivity, weight, exact_weight, heavy_weight, heavy_count, nhoh_count, no_count, hacceptor_count, hdonor_count, hetero_count, rotatable_bond_count, valance_electron_count, amide_bond_count, aliphatic_ring_count, aromatic_ring_count, saturated_ring_count, aliphatic_cycle_count, aliphaticHetero_cycle_count, aromatic_cycle_count, aromaticHetero_cycle_count, saturated_cycle_count, saturatedHetero_cycle_count, tpsa, eccentricity, asphericity, spherocity, inertial, gyration ] else: return [ logP, refractivity, weight, exact_weight, heavy_weight, heavy_count, nhoh_count, no_count, hacceptor_count, hdonor_count, hetero_count, rotatable_bond_count, valance_electron_count, amide_bond_count, aliphatic_ring_count, aromatic_ring_count, saturated_ring_count, aliphatic_cycle_count, aliphaticHetero_cycle_count, aromatic_cycle_count, aromaticHetero_cycle_count, saturated_cycle_count, saturatedHetero_cycle_count, tpsa ]
def mr(mol): return Crippen.MolMR(mol) if mol else None
def calc_rdkit(mol): descriptors = pd.Series( np.array([ Crippen.MolLogP(mol), Crippen.MolMR(mol), Descriptors.FpDensityMorgan1(mol), Descriptors.FpDensityMorgan2(mol), Descriptors.FpDensityMorgan3(mol), Descriptors.FractionCSP3(mol), Descriptors.HeavyAtomMolWt(mol), Descriptors.MaxAbsPartialCharge(mol), Descriptors.MaxPartialCharge(mol), Descriptors.MinAbsPartialCharge(mol), Descriptors.MinPartialCharge(mol), Descriptors.MolWt(mol), Descriptors.NumRadicalElectrons(mol), Descriptors.NumValenceElectrons(mol), EState.EState.MaxAbsEStateIndex(mol), EState.EState.MaxEStateIndex(mol), EState.EState.MinAbsEStateIndex(mol), EState.EState.MinEStateIndex(mol), EState.EState_VSA.EState_VSA1(mol), EState.EState_VSA.EState_VSA10(mol), EState.EState_VSA.EState_VSA11(mol), EState.EState_VSA.EState_VSA2(mol), EState.EState_VSA.EState_VSA3(mol), EState.EState_VSA.EState_VSA4(mol), EState.EState_VSA.EState_VSA5(mol), EState.EState_VSA.EState_VSA6(mol), EState.EState_VSA.EState_VSA7(mol), EState.EState_VSA.EState_VSA8(mol), EState.EState_VSA.EState_VSA9(mol), Fragments.fr_Al_COO(mol), Fragments.fr_Al_OH(mol), Fragments.fr_Al_OH_noTert(mol), Fragments.fr_aldehyde(mol), Fragments.fr_alkyl_carbamate(mol), Fragments.fr_alkyl_halide(mol), Fragments.fr_allylic_oxid(mol), Fragments.fr_amide(mol), Fragments.fr_amidine(mol), Fragments.fr_aniline(mol), Fragments.fr_Ar_COO(mol), Fragments.fr_Ar_N(mol), Fragments.fr_Ar_NH(mol), Fragments.fr_Ar_OH(mol), Fragments.fr_ArN(mol), Fragments.fr_aryl_methyl(mol), Fragments.fr_azide(mol), Fragments.fr_azo(mol), Fragments.fr_barbitur(mol), Fragments.fr_benzene(mol), Fragments.fr_benzodiazepine(mol), Fragments.fr_bicyclic(mol), Fragments.fr_C_O(mol), Fragments.fr_C_O_noCOO(mol), Fragments.fr_C_S(mol), Fragments.fr_COO(mol), Fragments.fr_COO2(mol), Fragments.fr_diazo(mol), Fragments.fr_dihydropyridine(mol), Fragments.fr_epoxide(mol), Fragments.fr_ester(mol), Fragments.fr_ether(mol), Fragments.fr_furan(mol), Fragments.fr_guanido(mol), Fragments.fr_halogen(mol), Fragments.fr_hdrzine(mol), Fragments.fr_hdrzone(mol), Fragments.fr_HOCCN(mol), Fragments.fr_imidazole(mol), Fragments.fr_imide(mol), Fragments.fr_Imine(mol), Fragments.fr_isocyan(mol), Fragments.fr_isothiocyan(mol), Fragments.fr_ketone(mol), Fragments.fr_ketone_Topliss(mol), Fragments.fr_lactam(mol), Fragments.fr_lactone(mol), Fragments.fr_methoxy(mol), Fragments.fr_morpholine(mol), Fragments.fr_N_O(mol), Fragments.fr_Ndealkylation1(mol), Fragments.fr_Ndealkylation2(mol), Fragments.fr_NH0(mol), Fragments.fr_NH1(mol), Fragments.fr_NH2(mol), Fragments.fr_Nhpyrrole(mol), Fragments.fr_nitrile(mol), Fragments.fr_nitro(mol), Fragments.fr_nitro_arom(mol), Fragments.fr_nitro_arom_nonortho(mol), Fragments.fr_nitroso(mol), Fragments.fr_oxazole(mol), Fragments.fr_oxime(mol), Fragments.fr_para_hydroxylation(mol), Fragments.fr_phenol(mol), Fragments.fr_phenol_noOrthoHbond(mol), Fragments.fr_phos_acid(mol), Fragments.fr_phos_ester(mol), Fragments.fr_piperdine(mol), Fragments.fr_piperzine(mol), Fragments.fr_priamide(mol), Fragments.fr_prisulfonamd(mol), Fragments.fr_pyridine(mol), Fragments.fr_quatN(mol), Fragments.fr_SH(mol), Fragments.fr_sulfide(mol), Fragments.fr_sulfonamd(mol), Fragments.fr_sulfone(mol), Fragments.fr_term_acetylene(mol), Fragments.fr_tetrazole(mol), Fragments.fr_thiazole(mol), Fragments.fr_thiocyan(mol), Fragments.fr_thiophene(mol), Fragments.fr_unbrch_alkane(mol), Fragments.fr_urea(mol), GraphDescriptors.BalabanJ(mol), GraphDescriptors.BertzCT(mol), GraphDescriptors.Chi0(mol), GraphDescriptors.Chi0n(mol), GraphDescriptors.Chi0v(mol), GraphDescriptors.Chi1(mol), GraphDescriptors.Chi1n(mol), GraphDescriptors.Chi1v(mol), GraphDescriptors.Chi2n(mol), GraphDescriptors.Chi2v(mol), GraphDescriptors.Chi3n(mol), GraphDescriptors.Chi3v(mol), GraphDescriptors.Chi4n(mol), GraphDescriptors.Chi4v(mol), GraphDescriptors.HallKierAlpha(mol), GraphDescriptors.Ipc(mol), GraphDescriptors.Kappa1(mol), GraphDescriptors.Kappa2(mol), GraphDescriptors.Kappa3(mol), Lipinski.HeavyAtomCount(mol), Lipinski.NHOHCount(mol), Lipinski.NOCount(mol), Lipinski.NumAliphaticCarbocycles(mol), Lipinski.NumAliphaticHeterocycles(mol), Lipinski.NumAliphaticRings(mol), Lipinski.NumAromaticCarbocycles(mol), Lipinski.NumAromaticHeterocycles(mol), Lipinski.NumAromaticRings(mol), Lipinski.NumHAcceptors(mol), Lipinski.NumHDonors(mol), Lipinski.NumHeteroatoms(mol), Lipinski.NumRotatableBonds(mol), Lipinski.NumSaturatedCarbocycles(mol), Lipinski.NumSaturatedHeterocycles(mol), Lipinski.NumSaturatedRings(mol), Lipinski.RingCount(mol), MolSurf.LabuteASA(mol), MolSurf.PEOE_VSA1(mol), MolSurf.PEOE_VSA10(mol), MolSurf.PEOE_VSA11(mol), MolSurf.PEOE_VSA12(mol), MolSurf.PEOE_VSA13(mol), MolSurf.PEOE_VSA14(mol), MolSurf.PEOE_VSA2(mol), MolSurf.PEOE_VSA3(mol), MolSurf.PEOE_VSA4(mol), MolSurf.PEOE_VSA5(mol), MolSurf.PEOE_VSA6(mol), MolSurf.PEOE_VSA7(mol), MolSurf.PEOE_VSA8(mol), MolSurf.PEOE_VSA9(mol), MolSurf.SlogP_VSA1(mol), MolSurf.SlogP_VSA10(mol), MolSurf.SlogP_VSA11(mol), MolSurf.SlogP_VSA12(mol), MolSurf.SlogP_VSA2(mol), MolSurf.SlogP_VSA3(mol), MolSurf.SlogP_VSA4(mol), MolSurf.SlogP_VSA5(mol), MolSurf.SlogP_VSA6(mol), MolSurf.SlogP_VSA7(mol), MolSurf.SlogP_VSA8(mol), MolSurf.SlogP_VSA9(mol), MolSurf.SMR_VSA1(mol), MolSurf.SMR_VSA10(mol), MolSurf.SMR_VSA2(mol), MolSurf.SMR_VSA3(mol), MolSurf.SMR_VSA4(mol), MolSurf.SMR_VSA5(mol), MolSurf.SMR_VSA6(mol), MolSurf.SMR_VSA7(mol), MolSurf.SMR_VSA8(mol), MolSurf.SMR_VSA9(mol), MolSurf.TPSA(mol) ])) return descriptors
def calculate(self): return Crippen.MolMR(self.mol)
def CalculateMolMR(mol): return round(Crippen.MolMR(mol), 3)