def test7ScoreMolecules(self): suppl = Chem.SmilesMolSupplierFromText('\n'.join(self.smiList2), ',', 0, -1, 0) cat = BuildFragmentCatalog.BuildCatalog(suppl, minPath=1, reportFreq=20) assert cat.GetNumEntries() == 21 assert cat.GetFPLength() == 21 scores, obls = BuildFragmentCatalog.ScoreMolecules(suppl, cat, acts=self.list2Acts, reportFreq=20) for i in range(len(self.list2Obls)): assert tuple( obls[i]) == self.list2Obls[i], '%d: %s != %s' % (i, str( obls[i]), str(self.list2Obls[i])) scores2 = BuildFragmentCatalog.ScoreFromLists(obls, suppl, cat, acts=self.list2Acts, reportFreq=20) for i in range(len(scores)): assert (scores[i] == scores2[i]).all(), '%d: %s != %s' % ( i, str(scores[i]), str(scores2[i]))
def test6Builder(self): suppl = Chem.SmilesMolSupplierFromText('\n'.join(self.smiList2), ',',0,-1,0) cat = BuildFragmentCatalog.BuildCatalog(suppl,minPath=1,reportFreq=20) assert cat.GetNumEntries()==21 assert cat.GetFPLength()==21 self._testBits(cat)
def test9Issue116(self): smiList = ['Cc1ccccc1'] suppl = Chem.SmilesMolSupplierFromText('\n'.join(smiList), ',', 0, -1, 0) cat = BuildFragmentCatalog.BuildCatalog(suppl, minPath=2, maxPath=2) assert cat.GetFPLength() == 2 assert cat.GetBitDescription(0) == 'ccC' fpgen = FragmentCatalog.FragFPGenerator() mol = Chem.MolFromSmiles('Cc1ccccc1') fp = fpgen.GetFPForMol(mol, cat) assert fp[0] assert fp[1] mol = Chem.MolFromSmiles('c1ccccc1-c1ccccc1') fp = fpgen.GetFPForMol(mol, cat) assert not fp[0] assert fp[1]
def test8MolRanks(self): suppl = Chem.SmilesMolSupplierFromText('\n'.join(self.smiList2), ',', 0, -1, 0) cat = BuildFragmentCatalog.BuildCatalog(suppl, minPath=1, reportFreq=20) assert cat.GetNumEntries() == 21 assert cat.GetFPLength() == 21 # new InfoGain ranking: bitInfo, fps = BuildFragmentCatalog.CalcGains(suppl, cat, topN=10, acts=self.list2Acts, reportFreq=20, biasList=(1, )) entry = bitInfo[0] assert int(entry[0]) == 0 assert cat.GetBitDescription(int(entry[0])) == 'C<-O>C' assert feq(entry[1], 0.4669) entry = bitInfo[1] assert int(entry[0]) in (2, 6) txt = cat.GetBitDescription(int(entry[0])) self.assertTrue(txt in ('C<-O>CC', 'C<-O>=C'), txt) assert feq(entry[1], 0.1611) entry = bitInfo[6] assert int(entry[0]) == 16 assert cat.GetBitDescription(int(entry[0])) == 'C=CC<-O>' assert feq(entry[1], 0.0560) # standard InfoGain ranking: bitInfo, fps = BuildFragmentCatalog.CalcGains(suppl, cat, topN=10, acts=self.list2Acts, reportFreq=20) entry = bitInfo[0] assert int(entry[0]) == 0 assert cat.GetBitDescription(int(entry[0])) == 'C<-O>C' assert feq(entry[1], 0.4669) entry = bitInfo[1] assert int(entry[0]) == 5 assert cat.GetBitDescription(int(entry[0])) == 'C=CC' assert feq(entry[1], 0.2057)