DeepGraphLearning / torchdrug

A powerful and flexible machine learning platform for drug discovery
https://torchdrug.ai/
Apache License 2.0
1.43k stars 199 forks source link

Can't kekulize mol. #170

Open YifaSuoha962 opened 1 year ago

YifaSuoha962 commented 1 year ago

 When I ran the code below(same as the demo in retrosynthesis tutorial)

from torchdrug import data, datasets, utils
from torchdrug.utils import plot
from torchdrug import core, models, tasks

synthon_dataset = datasets.USPTO50k("~/data", as_synthon=True,
                                    node_feature="synthon_completion",
                                    kekulize=True)
torch.manual_seed(1)
synthon_train, synthon_valid, synthon_test = synthon_dataset.split()
synthon_model = models.RGCN(input_dim=synthon_dataset.node_feature_dim,
                            hidden_dims=[256, 256, 256, 256, 256, 256],
                            num_relation=synthon_dataset.num_bond_type,
                            concat_hidden=True)
synthon_task = tasks.SynthonCompletion(synthon_model, feature=("graph",))
synthon_optimizer = torch.optim.Adam(synthon_task.parameters(), lr=1e-3)
synthon_solver = core.Engine(synthon_task, synthon_train, synthon_valid,
                             synthon_test, synthon_optimizer,
                             gpus=[0], batch_size=128)
synthon_solver.train(num_epoch=10)
synthon_solver.evaluate("valid")
synthon_solver.save("~/data/g2gs_synthon_model.pth")

an exception appeared:

    Chem.Kekulize(mol)
rdkit.Chem.rdchem.KekulizeException: Can't kekulize mol.  Unkekulized atoms: 11

Have anyone encountered that case, and how did you solve? Vary appreciated for relpies!

freehome1 commented 1 year ago

I met the same question

Oxer11 commented 1 year ago

Sorry for the inconvience. I've changed rdkit version to 2021.9.2, which can address the problem in my case. Maybe you can have a try.

If it doesn't work for you, could you please tell us your pytorch and rdkit version? Since I'm not a developer for the retrosynthesis part, maybe @KiddoZhu and @shichence will help you on this.

YifaSuoha962 commented 1 year ago

Sorry for the inconvience. I've changed rdkit version to 2021.9.2, which can address the problem in my case. Maybe you can have a try.

If it doesn't work for you, could you please tell us your pytorch and rdkit version? Since I'm not a developer for the retrosynthesis part, maybe @KiddoZhu and @shichence will help you on this.

Thx! The problem is solved with the rdkit version you offered, the version I previously used is 2022.9.3 .

neurowelt commented 1 year ago

For anyone working on OSX (M1), I was able to succeed using version 2021.9.4.

pip install rdkit-pypi-2021.9.4