datamol-io / datamol

Molecular Processing Made Easy.
https://docs.datamol.io
Apache License 2.0
452 stars 47 forks source link

Question on dm.viz.circle_grid #196

Closed PatWalters closed 1 year ago

PatWalters commented 1 year ago

The circle_grid capability is very interesting. However, I can't figure out how to get text to display. I put together this gist to show how I'm trying to use it. Please tell me what I'm doing wrong. Thanks!

https://gist.github.com/PatWalters/cab0c8555298a5b9fca5e047b3a7096a

hadim commented 1 year ago

Thanks.

I'll try to have a look soon enough.

PatWalters commented 1 year ago

Thanks, it would also be useful to scale the structure in the middle of the circle. Currently, it's really big.

maclandrol commented 1 year ago

I revisited the code and it turns out that we compute the bounding box coordinate but never "draw" the actual text 😅

https://github.com/datamol-io/datamol/blob/97bb202f0c85fba0b471058b5eaf0c7245211574/datamol/viz/_circle_grid.py#L155-L166

The following line is missing after the snippet above:

self.draw.text((center_x - w//2, center_y + width //2 - 2*h), txt, fill="black", font=font)

I can make a PR (and also remove the annoying missing font message on osx). But I really would like to move away from hacking PIL image together to using the RDKit's canvas framework and this seems like one good opportunity.

Should be easy to translate the current code, but I probably wouldn't get started on this before the weekend

maclandrol commented 1 year ago

Thanks, it would also be useful to scale the structure in the middle of the circle. Currently, it's really big.

In addition to this, it would make sense to give the user some control over how the molecules are rendered (just forwarding dm.to_image arguments)

PatWalters commented 1 year ago

This all sounds great, thank you!