-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathfragments.sql.in
90 lines (83 loc) · 2.67 KB
/
fragments.sql.in
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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
Create Or Replace Function _OCSCHEMA_.atoms(smi Text, nbrflag Integer)
Returns SetOf text As $EOPY$
import obchord
import openbabel
# array for SetOf return
retsmarts = []
oc=obchord.obchord(GD)
mol = oc.parse_smi(smi)
if mol:
for a in openbabel.OBMolAtomIter(mol):
if a.GetAtomicNum() == 1: continue
if nbrflag > 0:
retsmarts.append(obchord.atom_sym(a,True) + obchord.nbr_smarts(a))
else:
retsmarts.append(obchord.atom_sym(a,True))
if nbrflag == 0:
retsmarts.append(obchord.atom_sym(a,True) + obchord.nbr_smarts(a))
return retsmarts
else:
# bad mol (bad smiles)
return None
$EOPY$ Language plpythonu Immutable;
Comment on Function _OCSCHEMA_.atoms(Text,Integer)
Is 'return a table of SMARTS of each atom and optionally its nearest neighbors; -1 no neighbors, 0 with neighbors, 1 only neighbors';
Create Or Replace Function _OCSCHEMA_.bonds(smi Text, nbrflag Integer)
Returns SetOf text As $EOPY$
import obchord
import openbabel
retsmarts = []
oc=obchord.obchord(GD)
mol = oc.parse_smi(smi)
if mol:
for b in openbabel.OBMolBondIter(mol):
a1 = b.GetBeginAtom()
a2 = b.GetEndAtom()
a1sma = obchord.atom_sym(a1,True)
a2sma = obchord.atom_sym(a2,True)
if nbrflag < 0:
a1nbr = ""
a2nbr = ""
else:
a1nbr = obchord.nbr_smarts(a1,a2)
a2nbr = obchord.nbr_smarts(a2,a1)
# use a symbol for every bond type
if b.IsSingle(): bnd = "-"
elif b.IsAromatic(): bnd = ":"
elif b.IsDouble(): bnd = "="
elif b.IsTriple(): bnd = "#"
else: bnd = "~"
if a1sma+a1nbr < a2sma+a2nbr:
sma = a1sma + bnd + a2sma
if nbrflag < 0:
pass
else:
nbrsma = '[$(' + a1sma + a1nbr + ')]' + bnd + '[$(' + a2sma + a2nbr + ')]'
else:
sma = a2sma + bnd + a1sma
if nbrflag < 0:
pass
else:
nbrsma = '[$(' + a2sma + a2nbr + ')]' + bnd + '[$(' + a1sma + a1nbr + ')]'
if nbrflag > 0:
retsmarts.append(nbrsma)
else:
retsmarts.append(sma)
if nbrflag == 0:
retsmarts.append(nbrsma)
return retsmarts
else:
return None
$EOPY$ Language plpythonu Immutable;
Comment on Function _OCSCHEMA_.bonds(Text,Integer)
Is 'return a table of SMARTS of atoms in each bond and optionally their nearest neighbors; -1 no neighbors, 0 with neighbors, 1 only neighbors';
Create Or Replace Function _OCSCHEMA_.fragments(smi Text, minpath Integer, maxpath Integer, smarts Boolean)
Returns SetOf Text As $EOPY$
import obchord
oc = obchord.obchord(GD)
mol = oc.parse_smi(smi)
paths = obchord.make_mol_paths(mol, minpath, maxpath, smarts)
return paths
$EOPY$ Language plpythonu Immutable;
Comment on Function _OCSCHEMA_.fragments(Text,Integer,Integer,Boolean)
Is 'return a table of SMARTS of fragments of length min to max, using atom symbols or smarts with charge and valence';