DrrDom / crem

CReM: chemically reasonable mutations framework
BSD 3-Clause "New" or "Revised" License
198 stars 38 forks source link

Fix error if max_replacements is too small #1

Closed k-ujihara closed 4 years ago

k-ujihara commented 4 years ago

mutate_mol raises StopIteration error when max_replacements is smaller than number of replacement generated. It is better to return here rather than raising error.

from rdkit import Chem
from crem.crem import mutate_mol

db_name = "replacements02_sc2.5.db"
print(
    [
        m
        for m in mutate_mol(
            Chem.MolFromSmiles("CCC(C)C(N)C(N)=O"),
            db_name=db_name,
            radius=3,
            min_inc=-2,
            max_inc=2,
            max_replacements=5,
        )
    ]
)
  File "crem.py", line 418, in mutate_mol
    for frag_sma, core_sma, freq, ids in __gen_replacements(mol1=mol, mol2=None, db_name=db_name, radius=radius,
RuntimeError: generator raised StopIteration
DrrDom commented 4 years ago

Thank you for the fix! This change in generators was described in PEP-479 and affects Python 3.7 and later