wengong-jin / hgraph2graph

Hierarchical Generation of Molecular Graphs using Structural Motifs
MIT License
367 stars 108 forks source link

Chem.Kekulize(mol) error #24

Open Nokimann opened 3 years ago

Nokimann commented 3 years ago

rdkit version: 2021.03.3 (didn't check in other versions)

Doing python get_vocab.py --ncpu 16 < aromatic.txt > vocab.txt with aromatic SMILES, an error occurs because of Chem.Kekulize function.

In chemutils.py,

Before:

def get_mol(smiles):
    mol = Chem.MolFromSmiles(smiles)
    if mol is not None: Chem.Kekulize(mol)
    return mol

After: adding clearAromaticFlags=True

def get_mol(smiles):
    mol = Chem.MolFromSmiles(smiles)
    if mol is not None: Chem.Kekulize(mol, clearAromaticFlags=True)
    return mol

Solved.

HarreyJia commented 3 years ago

Thank you SO much! I have been stuck in the error for a long time.

However, I still want to know whether something different would happen in the later judgement if I changed the code.

purplerainf commented 3 years ago

Hi, I think I had the same issue. The error message I've got was "rdkit.Chem.rdchem.KekulizeException: Can't kekulize mol. Unkekulized atoms: 5 6 7 8 9 10 18 26 27"

Nokimann's suggestion works for me as well, but it would be great if the author or others confirm it.

marshallcase commented 2 years ago

Just had the same issue as @purplerainf and @Nokimann's suggestion seemed to fix the issue. Thanks!