molstar / pdbe-molstar

Molstar PDBe implementation
Apache License 2.0
89 stars 30 forks source link

How To color by secondary structure #102

Open ap-jain opened 6 months ago

ap-jain commented 6 months ago

how can i set secondary structure as default coloring on rendering it in code image

image

this is my code

any help is appreciated.

midlik commented 4 months ago

Hi. There is no option to achieve this directly. But you can add this code which changes the color theme for polymer component once the structure is loaded:

function colorPolymerBySecStr() {
    const cells = Array.from(viewerInstance.plugin.state.data.cells.values());
    const polymerComponents = cells.filter(c => c.transform.tags?.includes('structure-component-static-polymer'));
    for (const component of polymerComponents) {
        const polymerRepresentations = viewerInstance.plugin.state.data.tree.children.get(component.transform.ref);
        for (const repr of polymerRepresentations) {
            viewerInstance.plugin.build().to(repr).update({ colorTheme: { name: 'secondary-structure', params: {} } }).commit();
        }
    }
}
viewerInstance.events.loadComplete.subscribe(colorPolymerBySecStr);
midlik commented 4 months ago

You could also apply the color theme to all representations:

const representations = cells.filter(c => c.transform.transformer.id === 'ms-plugin.structure-representation-3d');

but I think it wouldn't make sense for non-polymers

midlik commented 2 weeks ago

Update:

With PDBe Molstar 3.3.0, this is now much easier. Follow the solution described here https://github.com/molstar/pdbe-molstar/issues/110

But instead of polymer: { type: 'cartoon', color: 'sequence-id' }, use polymer: { type: 'cartoon', color: 'secondary-structure' },