def test_generate_fraggle_fragmentation(self): mol = Chem.MolFromSmiles('COc1cc(CN2CCC(CC2)NC(=O)c2cncc(C)c2)c(OC)c2ccccc12') frags = FraggleSim.generate_fraggle_fragmentation(mol) self.assertEqual(len(frags), 16) expected = ( '[*]C(=O)NC1CCN(Cc2cc(OC)c3ccccc3c2OC)CC1', '[*]C(=O)c1cncc(C)c1.[*]C1CCN(Cc2cc(OC)c3ccccc3c2OC)CC1', '[*]C(=O)c1cncc(C)c1.[*]c1cc(OC)c2ccccc2c1OC', '[*]C1CCN(Cc2cc(OC)c3ccccc3c2OC)CC1', '[*]C(=O)c1cncc(C)c1.[*]Cc1cc(OC)c2ccccc2c1OC', '[*]Cc1cc(OC)c2ccccc2c1OC.[*]NC(=O)c1cncc(C)c1', '[*]Cc1cc(OC)c2ccccc2c1OC.[*]c1cncc(C)c1', '[*]NC(=O)c1cncc(C)c1.[*]c1cc(OC)c2ccccc2c1OC', '[*]NC1CCN(Cc2cc(OC)c3ccccc3c2OC)CC1', '[*]NC1CCN(Cc2cc(OC)c3ccccc3c2OC)CC1.[*]c1cncc(C)c1', '[*]c1c(CN2CCC(NC(=O)c3cncc(C)c3)CC2)cc(OC)c2ccccc12', '[*]c1c(OC)cc(CN2CCC(NC(=O)c3cncc(C)c3)CC2)c(OC)c1[*]', '[*]c1cc(CN2CCC(NC(=O)c3cncc(C)c3)CC2)c(OC)c2ccccc12', '[*]N1CCC(NC(=O)c2cncc(C)c2)CC1.[*]c1cc(OC)c2ccccc2c1OC', '[*]C1CCN(Cc2cc(OC)c3ccccc3c2OC)CC1.[*]c1cncc(C)c1', '[*]c1cc(OC)c2ccccc2c1OC.[*]c1cncc(C)c1') expected = [_of(s) for s in expected] for smi in frags: self.assertTrue(_of(smi) in expected) # Test case for fragments that contain a cyclic and acyclic component mol = Chem.MolFromSmiles('c12c(CCC)cccc2cccc1') frags = FraggleSim.generate_fraggle_fragmentation(mol) expected = ['[*]CCC.[*]c1ccccc1[*]', '[*]Cc1cccc2ccccc12', '[*]c1cccc(CCC)c1[*]', '[*]c1cccc2ccccc12', '[*]c1ccccc1[*]'] expected = [_of(s) for s in expected] for smi in frags: self.assertTrue(_of(smi) in expected)
def testFragmentation(self): """ """ mol = Chem.MolFromSmiles( 'COc1cc(CN2CCC(CC2)NC(=O)c2cncc(C)c2)c(OC)c2ccccc12') frags = FraggleSim.generate_fraggle_fragmentation(mol) self.assertEqual(len(frags), 16) expected = ('[*]C(=O)NC1CCN(Cc2cc(OC)c3ccccc3c2OC)CC1', '[*]C(=O)c1cncc(C)c1.[*]C1CCN(Cc2cc(OC)c3ccccc3c2OC)CC1', '[*]C(=O)c1cncc(C)c1.[*]c1cc(OC)c2ccccc2c1OC', '[*]C1CCN(Cc2cc(OC)c3ccccc3c2OC)CC1', '[*]C(=O)c1cncc(C)c1.[*]Cc1cc(OC)c2ccccc2c1OC', '[*]Cc1cc(OC)c2ccccc2c1OC.[*]NC(=O)c1cncc(C)c1', '[*]Cc1cc(OC)c2ccccc2c1OC.[*]c1cncc(C)c1', '[*]NC(=O)c1cncc(C)c1.[*]c1cc(OC)c2ccccc2c1OC', '[*]NC1CCN(Cc2cc(OC)c3ccccc3c2OC)CC1', '[*]NC1CCN(Cc2cc(OC)c3ccccc3c2OC)CC1.[*]c1cncc(C)c1', '[*]c1c(CN2CCC(NC(=O)c3cncc(C)c3)CC2)cc(OC)c2ccccc12', '[*]c1c(OC)cc(CN2CCC(NC(=O)c3cncc(C)c3)CC2)c(OC)c1[*]', '[*]c1cc(CN2CCC(NC(=O)c3cncc(C)c3)CC2)c(OC)c2ccccc12', '[*]N1CCC(NC(=O)c2cncc(C)c2)CC1.[*]c1cc(OC)c2ccccc2c1OC', '[*]C1CCN(Cc2cc(OC)c3ccccc3c2OC)CC1.[*]c1cncc(C)c1', '[*]c1cc(OC)c2ccccc2c1OC.[*]c1cncc(C)c1') for smi in frags: self.assertTrue(smi in expected)
def testFragmentation(self): """ """ mol = Chem.MolFromSmiles('COc1cc(CN2CCC(CC2)NC(=O)c2cncc(C)c2)c(OC)c2ccccc12') frags = FraggleSim.generate_fraggle_fragmentation(mol) self.failUnlessEqual(len(frags),16) expected=('[*]C(=O)NC1CCN(Cc2cc(OC)c3ccccc3c2OC)CC1', '[*]C(=O)c1cncc(C)c1.[*]C1CCN(Cc2cc(OC)c3ccccc3c2OC)CC1', '[*]C(=O)c1cncc(C)c1.[*]c1cc(OC)c2ccccc2c1OC', '[*]C1CCN(Cc2cc(OC)c3ccccc3c2OC)CC1', '[*]Cc1cc(OC)c2ccccc2c1OC.[*]C(=O)c1cncc(C)c1', '[*]Cc1cc(OC)c2ccccc2c1OC.[*]NC(=O)c1cncc(C)c1', '[*]Cc1cc(OC)c2ccccc2c1OC.[*]c1cncc(C)c1', '[*]NC(=O)c1cncc(C)c1.[*]c1cc(OC)c2ccccc2c1OC', '[*]NC1CCN(Cc2cc(OC)c3ccccc3c2OC)CC1', '[*]NC1CCN(Cc2cc(OC)c3ccccc3c2OC)CC1.[*]c1cncc(C)c1', '[*]c1c(CN2CCC(NC(=O)c3cncc(C)c3)CC2)cc(OC)c2ccccc12', '[*]c1c([*])c(OC)c(CN2CCC(NC(=O)c3cncc(C)c3)CC2)cc1OC', '[*]c1cc(CN2CCC(NC(=O)c3cncc(C)c3)CC2)c(OC)c2ccccc12', '[*]c1cc(OC)c2ccccc2c1OC.[*]N1CCC(NC(=O)c2cncc(C)c2)CC1', '[*]c1cncc(C)c1.[*]C1CCN(Cc2cc(OC)c3ccccc3c2OC)CC1', '[*]c1cncc(C)c1.[*]c1cc(OC)c2ccccc2c1OC') for smi in frags: self.failUnless(smi in expected)
def frag( mol: Chem.Mol, remove_parent: bool = False, sanitize: bool = True, fix: bool = True, ): """Generate all possible fragmentation of a molecule. Args: mol: a molecule. remove_parent: Remove parent from the fragments. sanitize: Wether to sanitize the fragments. fix: Wether to fix the fragments. """ frags = FraggleSim.generate_fraggle_fragmentation(mol) smiles = set([]) for seq in frags: smiles |= {s.strip() for s in seq.split(".")} smiles = list(sorted(smiles, reverse=True)) frags = [dm.to_mol(s) for s in smiles] if fix: frags = [dm.fix_mol(x) for x in frags] if sanitize: frags = [dm.sanitize_mol(x) for x in frags] frags = [x for x in frags if x is not None] if remove_parent: return frags return [mol] + frags
def testFragmentation2(self): mol = Chem.MolFromSmiles('COc1cc(CN2CCC(NC(=O)c3ccccc3)CC2)c(OC)c2ccccc12') frags = FraggleSim.generate_fraggle_fragmentation(mol) self.assertEqual(len(frags), 13) expected = ( '[*]C(=O)c1ccccc1.[*]C1CCN(Cc2cc(OC)c3ccccc3c2OC)CC1', '[*]C(=O)c1ccccc1.[*]Cc1cc(OC)c2ccccc2c1OC', '[*]C(=O)c1ccccc1.[*]c1cc(OC)c2ccccc2c1OC', '[*]C1CCN(Cc2cc(OC)c3ccccc3c2OC)CC1.[*]c1ccccc1', '[*]Cc1cc(OC)c2ccccc2c1OC.[*]NC(=O)c1ccccc1', '[*]Cc1cc(OC)c2ccccc2c1OC.[*]c1ccccc1', '[*]N1CCC(NC(=O)c2ccccc2)CC1.[*]c1cc(OC)c2ccccc2c1OC', '[*]NC(=O)c1ccccc1.[*]c1cc(OC)c2ccccc2c1OC', '[*]NC1CCN(Cc2cc(OC)c3ccccc3c2OC)CC1.[*]c1ccccc1', '[*]c1c(CN2CCC(NC(=O)c3ccccc3)CC2)cc(OC)c2ccccc12', '[*]c1c(OC)cc(CN2CCC(NC(=O)c3ccccc3)CC2)c(OC)c1[*]', '[*]c1cc(CN2CCC(NC(=O)c3ccccc3)CC2)c(OC)c2ccccc12', '[*]c1cc(OC)c2ccccc2c1OC.[*]c1ccccc1') expected = [_of(s) for s in expected] for smi in frags: self.assertIn(_of(smi), expected)
if __name__ == '__main__': import sys, re if (len(sys.argv) >= 2): print( "Program to run the first part of Fraggle. Program splits the molecule\nready for the search\n") print("USAGE: ./fraggle.py <file_of_smiles") print("Format of smiles file: SMILES ID (space or comma separated)") print("Output: whole mol smiles,ID,fraggle split smiles\n") sys.exit(1) #read the STDIN for line in sys.stdin: line = line.rstrip() smi, id_ = re.split('\s|,', line) #print smi,id_ mol = Chem.MolFromSmiles(smi) if mol is None: sys.stderr.write("Can't generate mol for: %s\n" % (smi)) continue out_fragments = FraggleSim.generate_fraggle_fragmentation(mol) #print out the unique fragments for x in out_fragments: #cansmi temp = Chem.MolFromSmiles(x) print("%s,%s,%s" % (smi, id_, Chem.MolToSmiles(temp)))
if __name__ =='__main__': import sys,re if (len(sys.argv) >= 2): print "Program to run the first part of Fraggle. Program splits the molecule\nready for the search\n" print "USAGE: ./fraggle.py <file_of_smiles" print "Format of smiles file: SMILES ID (space or comma separated)" print "Output: whole mol smiles,ID,fraggle split smiles\n" sys.exit(1) #read the STDIN for line in sys.stdin: line = line.rstrip() smi,id_ = re.split('\s|,',line) #print smi,id_ mol = Chem.MolFromSmiles(smi) if mol is None: sys.stderr.write("Can't generate mol for: %s\n" % (smi) ) continue out_fragments = FraggleSim.generate_fraggle_fragmentation(mol) #print out the unique fragments for x in out_fragments: #cansmi temp = Chem.MolFromSmiles(x) print "%s,%s,%s" % (smi,id_,Chem.MolToSmiles(temp))