Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How To color by secondary structure #102

Open
ap-jain opened this issue Feb 19, 2024 · 3 comments
Open

How To color by secondary structure #102

ap-jain opened this issue Feb 19, 2024 · 3 comments

Comments

@ap-jain
Copy link

ap-jain commented Feb 19, 2024

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
Copy link
Collaborator

midlik commented Apr 30, 2024

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
Copy link
Collaborator

midlik commented Apr 30, 2024

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
Copy link
Collaborator

midlik commented Aug 29, 2024

Update:

With PDBe Molstar 3.3.0, this is now much easier. Follow the solution described here #110

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants