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

color by residues #492

Merged
merged 1 commit into from
Oct 1, 2016
Merged

color by residues #492

merged 1 commit into from
Oct 1, 2016

Conversation

hainm
Copy link
Collaborator

@hainm hainm commented Oct 1, 2016

related to #491

Just demo.

@hainm
Copy link
Collaborator Author

hainm commented Oct 1, 2016

import nglview as nv

view = nv.demo()
view

# use hex values for now.
colors = ['0x0000FF', '0xFF0000'] * 1000 # for 2000 residues.
view._set_color_by_residue(colors, component_index=0, repr_index=0)

@hainm
Copy link
Collaborator Author

hainm commented Oct 1, 2016

colors

@hainm hainm merged commit e046f52 into master Oct 1, 2016
@hainm hainm deleted the color branch October 1, 2016 02:45
@arose
Copy link
Collaborator

arose commented Oct 1, 2016

nice, looks good!

@hainm
Copy link
Collaborator Author

hainm commented Oct 1, 2016

@arose seems not working properly. I got black if not using red/green/blue colors.

What should I update here?

    setColorByResidue: function(colors, component_index, repr_index){
        var repr = this.stage.compList[component_index].reprList[repr_index];
        var schemeId = NGL.ColorMakerRegistry.addScheme(function(params){
            this.atomColor = function(atom){
                 var color = colors[atom.residueIndex];
                 return color
            };
        });
        repr.setColor(schemeId);
    },

colors

@arose
Copy link
Collaborator

arose commented Oct 1, 2016

The colors array has to be a list of integers: [ 0xedd1cb, 0xedd1cb, 0xedd1ca, 0xedd0ca ]

@hainm
Copy link
Collaborator Author

hainm commented Oct 1, 2016

I see. This is the output from seaborn

import seaborn as sns

colors = sns.cubehelix_palette(400).as_hex()
colors[:4]
['#edd1cb', '#edd1cb', '#edd0ca', '#edd0ca']

@hainm
Copy link
Collaborator Author

hainm commented Oct 1, 2016

replace '#' by '0x'.

colors = [c.replace('#', '0x') for c in sns.cubehelix_palette(400).as_hex()]

@arose
Copy link
Collaborator

arose commented Oct 1, 2016

no, that are still strings 0xFF00FF is the way to write integers as hex numbers in Python (not, no quotes).

@hainm
Copy link
Collaborator Author

hainm commented Oct 1, 2016

but it (string) actually 'works' :D I guess this happen since python list will be serialized before being sent to JS.

@arose
Copy link
Collaborator

arose commented Oct 1, 2016

:-)

@surgebiswas
Copy link

I copied and pasted the demo code exactly as is above and it does not work. The protein remains blue for me. Has there been any updates to the source code since the discussion above?

@hainm
Copy link
Collaborator Author

hainm commented Oct 26, 2017

@surgebiswas which version you are using? If you are using the version after this commit, can you open a new issue to keep track? thanks.

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

Successfully merging this pull request may close these issues.

3 participants