Skip to content

Commit

Permalink
Exposed canonical alg
Browse files Browse the repository at this point in the history
  • Loading branch information
whitead committed Oct 30, 2022
1 parent 39fb1ee commit 5ec1301
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 7 deletions.
6 changes: 4 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -57,10 +57,12 @@ where $M$ is the size in bits, $N$ is the number of compounds, and $\epsilon$ is
### Build with Python

```py
from molbloom import CustomFilter
from molbloom import CustomFilter, canon
bf = CustomFilter(100, 1000, 'myfilter')
bf.add('CCCO')

# canonicalize one
s = canon("CCCOC")
bf.add(s)
# save it
bf.save('test.bloom')
```
14 changes: 9 additions & 5 deletions molbloom/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,16 +51,20 @@ def _load_filter(name):
_load_big_filter(name)


def canon(smiles):
try:
from rdkit import Chem
except ImportError:
raise ImportError("To canonicalize SMILES, rdkit is required.")
return Chem.MolToSmiles(Chem.MolFromSmiles(smiles), canonical=True)


def buy(smiles, instock=True, canonicalize=False):
if instock:
name = "instock"
else:
name = "zinc20"
_load_filter(name)
if canonicalize:
try:
from rdkit import Chem
except ImportError:
raise ImportError("To canonicalize SMILES, rdkit is required.")
smiles = Chem.MolToSmiles(Chem.MolFromSmiles(smiles), canonical=True)
smiles = canon(smiles)
return smiles in filters[name]
3 changes: 3 additions & 0 deletions tests/test_molbloom.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,9 @@ def test_build_custom():
"""Build a custom filter"""
bf = molbloom.CustomFilter(100, 1000, "test")
bf.add("CCCO")
# canonicalize
s = molbloom.canon("CCCOC")
bf.add(s)
assert "CCCO" in bf
assert "CCCOO" not in bf
bf.save("test.bloom")
Expand Down

0 comments on commit 5ec1301

Please sign in to comment.