molstar / pdbe-molstar

Molstar PDBe implementation
Apache License 2.0
96 stars 33 forks source link

Colouring each residue #90

Open rsakai opened 1 year ago

rsakai commented 1 year ago

Is it possible to loop through each residue and colour them? I am loading a PDB file and would like to colour each residue based on experimental value I get for each residue.

CrisSherban commented 1 year ago

Probably this could be of help for you.

I usually create a list of dicts with the necessary color and residue information and then pass it to the color function. Here you can find a snippet: https://github.com/bayer-science-for-a-better-life/topefind-public/blob/73a40c4f0ef38a21d49e46e7987f69ac02baffd4/topefind/dashboard/dashboard.py#L578

KeaunAmani commented 10 months ago

Probably this could be of help for you.

I usually create a list of dicts with the necessary color and residue information and then pass it to the color function. Here you can find a snippet: https://github.com/bayer-science-for-a-better-life/topefind-public/blob/73a40c4f0ef38a21d49e46e7987f69ac02baffd4/topefind/dashboard/dashboard.py#L578

I believe the user wants to color the residues within the viewer directly.

midlik commented 2 months ago

You can use the .visual.select helper method (basically what CrisSherban suggested, thank you). The call will look something like this:

viewerInstance.visual.select({
    data: [
        { struct_asym_id: 'A', residue_number: 1, color: '#ff0000' }, 
        { struct_asym_id: 'A', residue_number: 2, color: '#ff8800' }, 
        { struct_asym_id: 'A', start_residue_number: 3, end_residue_number: 6, color: '#ffff00' }, 
        { struct_asym_id: 'A', start_residue_number: 15, end_residue_number: 20, color: '#88ff00' },
    ],
    nonSelectedColor: '#ffffff',
});