patrickfuller / imolecule

An embeddable webGL molecule viewer and file format converter.
http://patrickfuller.github.io/imolecule/
MIT License
86 stars 18 forks source link

Add highlighting support #5

Closed bjonnh closed 9 years ago

bjonnh commented 9 years ago

Can be used with pybel (or anything that sets the "color" property of atoms).

mol = pybel.readstring("smi","CCN(CC)CC") # triethylamine
pybel._operations['highlight'].Do(mol.OBMol, "[#7][#6][#1] #00FF00") 
imolecule.draw(mol, shader="lambert",format="pybel")

For now, only green is supported, I have to check openbabel source for a list of colors they allow.

patrickfuller commented 9 years ago

Looks useful! I use imolecule as a front end to some crystallography software. I wrote an all-js interactive highlighter there:

What's your use case? Would it be more useful to highlight in Python notebook code, or to do it interactively with the output?

Either way, I like the idea. Regarding OB colors, I'd rather convert them to hex python side. It saves us from having to duplicate color data.

bjonnh commented 9 years ago

I use that to highlight substructures in compounds. I have a series of filters (smarts) and apply them to each molecules then display them. That said if you made the highlighter already, I may just tweak it.

patrickfuller commented 9 years ago

Sounds like python functionality is the way to go.

Let's either add in a full list of color options, or edit this openbabel function to convert "green" to hex before sending to js. I like the idea of supporting arbitrary hex values, but either way works.

bjonnh commented 9 years ago

I made a better highlighter, now you can give the highlights with hex codes.

import pybel
import imolecule
mol = pybel.readstring("smi","OCN(CC)CCS")
pybel._operations['highlight'].Do(mol.OBMol, "[#6][#7] #FF0000") 
pybel._operations['highlight'].Do(mol.OBMol, "[#1][#8] #0000FF") 
pybel._operations['highlight'].Do(mol.OBMol, "[#16][#6] #00FF00") 
imolecule.draw(mol, shader="phong",format="pybel")

highlighter

patrickfuller commented 9 years ago

This is cool!

The only things left are to revert the display_html patch and remove all the whitespace edits (they gunk up commit history).

bjonnh commented 9 years ago

Should be ok, I rewrote history (bad I know…) but everything is fine now.