-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathFragment_Cages-RDKIT
76 lines (61 loc) · 2.54 KB
/
Fragment_Cages-RDKIT
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
import rdkit
from rdkit.Chem import AllChem
import operator
mol = AllChem.MolFromMolFile('test.mol')
imine = AllChem.MolFromSmiles('CC=NC')
subs = mol.GetSubstructMatches(imine)
bonds = []
for i in subs:
bonds.append(i[1:3])
bond_ids = [mol.GetBondBetweenAtoms(x,y).GetIdx() for x,y in bonds]
new_mol = AllChem.FragmentOnBonds(mol,bond_ids)
new_smiles = AllChem.MolToSmiles(new_mol, True)
new_split = new_smiles.split('.')
corrected_fragments = []
uncorrected_fragments = []
for i in new_split:
a = AllChem.ReplaceSubstructs(AllChem.MolFromSmiles(str(i)), AllChem.MolFromSmarts('C=[D1]'), AllChem.MolFromSmarts('C=O'), replaceAll=True)
b = AllChem.MolToSmiles(a[0])
c = AllChem.MolFromSmiles(b)
if '*' not in str(b):
au = AllChem.ReplaceSubstructs(AllChem.MolFromSmiles(str(i)), AllChem.MolFromSmarts('C=[D1]'), AllChem.MolFromSmarts('C=[D1]'), replaceAll=True)
corrected_fragments.append(c)
uncorrected_fragments.append(au[0])
else:
d = AllChem.ReplaceSubstructs(c, AllChem.MolFromSmarts('N=[D1]'), AllChem.MolFromSmarts('N'), replaceAll=True)
au = AllChem.ReplaceSubstructs(c, AllChem.MolFromSmarts('N=[D1]'), AllChem.MolFromSmarts('[D1]'), replaceAll=True)
corrected_fragments.append(d[0])
uncorrected_fragments.append(au[0])
smiles_fragments = []
for i in corrected_fragments:
smiles_fragments.append(AllChem.MolToSmiles(i))
building_blocks_dict = {i:smiles_fragments.count(i) for i in smiles_fragments}
print(building_blocks_dict)
uncorrected_smiles_fragments = []
for i in uncorrected_fragments:
uncorrected_smiles_fragments.append(AllChem.MolToSmiles(i))
unknown_functional_group = AllChem.MolFromSmiles('*')
number_of_groups = []
for i in uncorrected_smiles_fragments:
a = AllChem.MolFromSmiles(i)
b = a.GetSubstructMatches(unknown_functional_group)
number_of_groups.append(len(b))
functional_group_dict = {i:number_of_groups.count(i) for i in number_of_groups}
sorted_fgd = sorted(functional_group_dict.items(), key=operator.itemgetter(0))
if str(sorted_fgd) == '[(2, 3), (3, 2)]':
topology = 'stk.TwoPlusThree'
elif str(sorted_fgd) == '[(2, 6), (3, 4)]':
topology = 'stk.FourPlusSix'
elif str(sorted_fgd) == '[(2, 9), (3, 6)]':
topology = 'stk.SixPlusNine'
elif str(sorted_fgd) == '[(2, 12), (3, 8)]':
topology = 'stk.EightPlusTwelve'
elif str(sorted_fgd) == '[(3, 4), (4, 2)]':
topology = 'stk.TwoPlusFour'
elif str(sorted_fgd) == '[(3, 6), (4, 3)]':
topology = 'stk.ThreePlusSix'
elif str(sorted_fgd) == '[(3, 12), (4, 6)]':
topology = 'stk.SixPlusTwelve'
else:
topology = 'unknown'
print(topology)