Skip to content

Commit a69e7d3

Browse files
committed
Add SMARTS example.
1 parent cf8ac1d commit a69e7d3

File tree

1 file changed

+28
-0
lines changed

1 file changed

+28
-0
lines changed

simple_smarts.py

+28
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
#!/usr/bin/env python
2+
"""
3+
simple_smarts.py - simple example on how to use SMARTS patterns
4+
via the Open Babel API
5+
"""
6+
import openbabel
7+
8+
filename = '1UAO.pdb'
9+
pattern = "[$(CN)][$(C=O)]"
10+
11+
# OpenBabel utilities
12+
obmol = openbabel.OBMol()
13+
obconv = openbabel.OBConversion()
14+
obpat = openbabel.OBSmartsPattern()
15+
16+
# load the molecule
17+
obconv.SetInFormat(filename[-3:])
18+
obconv.ReadFile(obmol, filename)
19+
20+
# initialize pattern matching
21+
obpat.Init(pattern)
22+
23+
# apply pattern matching to the molecule
24+
obpat.Match(obmol)
25+
26+
# avoid getting lots of <openbabel.vectorvInt; proxy ... > etc.
27+
matches = [m for m in obpat.GetUMapList()]
28+
print matches

0 commit comments

Comments
 (0)