datamol-io / datamol

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

Non-random arrangement in circle grid #205

Closed PatWalters closed 1 year ago

PatWalters commented 1 year ago

The layout of structures around the central molecule in circle_grid appears somewhat random. While the structures are ordered according to the order in ring_mols, the starting point seems to change every time. Sometimes the first structure is at 3 o'clock other times it's at 9 o'clock. Would it be possible to always put the first structure in the same place and array the remaining structures in a clockwise fashion?

hadim commented 1 year ago

I can see a call to random() in the layout logic: https://github.com/datamol-io/datamol/blob/3ff85614ec4b3bf05347f704ee83cd065903a62d/datamol/viz/_circle_grid.py#L284

@maclandrol would that be as easy as using a seed here?

maclandrol commented 1 year ago

If you use random.seed before calling the function, you should get the same layout everytime. It might make sense to have an argument ring_mol_start_angle that set a starting angle defined by the user (would likely just be replacing the random unit variable)

hadim commented 1 year ago

Indeed it works well.

For ring_mol_start_angle I think it's nice to have it to give even more control over the layout (at the risk of increasing the number of args of that function!).

Will ping when done at #206 206

hadim commented 1 year ago

You can now either set a random seed to make the layout deterministic with layout_random_seed or even specify yourself starting angles with ring_mol_start_angles_degrees.

Thanks as I think those two features will be useful to many!

FYI: I'm going to wait for #201 before cutting a new version.