lab-cosmo / chemiscope

An interactive structure/property explorer for materials and molecules
http://chemiscope.org
BSD 3-Clause "New" or "Revised" License
119 stars 29 forks source link

Color the 3D structure by a property #303

Closed MaximeScope closed 8 months ago

MaximeScope commented 8 months ago

It should finally be possible to merge the coloring of the 3d structure with master.

There is an additional option to color the background atoms by property => (Environments -> more options -> color: prop, style: ball and stick)


EDIT:

Fixes #118

MaximeScope commented 8 months ago

I should note that I've implemented a _colorfunction that includes a check for undefined values (such as when taking the square root of a negative value of the selected property). In such cases, the atom is assigned a gray color.

ceriottm commented 8 months ago

I think you should start by adding a minimal example to the python/examples folder. I tested it on the chemical shielding dataset and my impression is that it doesn't really work but it's hard to make a reproducible example with this much data. I have it loaded with these parameters image and I'm looking at structure 276, atoms 75 and 78. They have a CS_total of 24 and 26 (quite close on a range between 15 and 30) but they end up colored in bright red and bright blue as if they were pretty much extreme.

ceriottm commented 8 months ago

Another observation is that IMO we REALLY need to provide a rudimentary color scale, otherwise it's very hard to read the figures. I read a bit and it seems the best way to do this would be to add an HTML entity outside the widget, a bit like the floating buttons in the top-right cornier.

Luthaf commented 8 months ago

I read a bit and it seems the best way to do this would be to add an HTML entity outside the widget, a bit like the floating buttons in the top-right cornier.

The idea was to us a custom label, for which we can set the background to an arbitrary HTML canvas, for which doing a gradient would be fairly easy.

But let's make sure the core of the functionality works first, merge it and then work on the color bar in a separate PR to reduce the size of the individual PRs.

MaximeScope commented 8 months ago

I think you should start by adding a minimal example to the python/examples folder. I tested it on the chemical shielding dataset and my impression is that it doesn't really work but it's hard to make a reproducible example with this much data. I have it loaded with these parameters image and I'm looking at structure 276, atoms 75 and 78. They have a CS_total of 24 and 26 (quite close on a range between 15 and 30) but they end up colored in bright red and bright blue as if they were pretty much extreme.

I have addressed the issue, and the code should now work correctly. Initially, the code was selecting the first atoms independently from the structure. With the help of the environnements, the visualizers should now accurately assign colors based on the correct atoms property value.

ceriottm commented 8 months ago

OK I have added an example that generates a simple color-coded figure. I have also renamed the RWB color scheme because it's blue first. I think one important thing is we can do to make it possible to have a reference for the colors is to make sure we have color schemes that match the plotly one. BWR is very similar to seismic (and this I have used in the example) but it'd be nice to have exactly the same schemes - at least viridis and magma for instance. Looks like you just need to sample the plotly/matplotlib palettes and hardcode say 16 intermediate points. Could you do this?

ceriottm commented 8 months ago

Just commenting that this Fixes #118 for good

Luthaf commented 8 months ago

Just commenting that this Fixes #118 for good

This kind of comment needs to be in the first message of the PR for github to automatically close the issue

Luthaf commented 8 months ago

merged! 🎉 Thanks @MaximeScope and @angerossi for your work implementing this!