0
votes

Here's my script:

   dopts = Draw.rdMolDraw2D.MolDrawOptions()
    dopts.prepareMolsBeforeDrawing = True

    k = 10
    results = Draw.MolsToGridImage(
        self.hits[:k + 1], molsPerRow=5, subImgSize=(250,250),
        drawOptions=dopts,
        legends=[x.GetProp("chembl_id")
                 for x in self.hits[:k]],        )
    results.save(f'{self.out_dir}/output.png')

But the whole image output file has misplaced molecules inside it. output is something like this.

I have posted this as an issue and hasn't been resolved yet. https://github.com/rdkit/rdkit/issues/4097

1

1 Answers

0
votes

Looking at the documentation section (prepareMolsBeforeDrawing) concerning the molecule preparation, it seems to suggest that if a 2D conformation already exists it will not generate a new one.

Does some cleanup operations on the molecule to prepare it to draw nicely. The operations include: kekulization, addition of chiral Hs (so that we can draw wedges to them), wedging of bonds at chiral centers, and generation of a 2D conformation if the molecule does not already have a conformation

If your molecules are coming from something like an SDF then perhaps removing the conformations already present will fix this problem, although I am not entirely sure as I don't have an SDF to test. Try adding the below before drawing the images, assuming you don't have a use for the conformation already present, otherwise, make a copy beforehand.

# Assuming molecules are in a list named mols
for mol in mols:
    mol.RemoveAllConformers()  # edited in-place

Edit:

Tested this on some compounds with 3D conformations and removing the conformers indeed forced rdkit to generate new 2D coordinates for the depiction.

Alternatively you could also add the 2D coordinates yourself overwriting the existing conformation, then you can remove the preparation argument if you desire, assuming you are not interested in the other cleanup steps it performs:

for mol in mols:
    AllChem.Compute2dCoords(mol, clearConfs=True)