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

Is there a way to add new attributes to atom? #892

Closed
appassionate opened this issue Nov 24, 2021 · 8 comments
Closed

Is there a way to add new attributes to atom? #892

appassionate opened this issue Nov 24, 2021 · 8 comments

Comments

@appassionate
Copy link

Hi, I want to present my data in every atom
I imaged a customized colorscheme will read the value of atoms if i can do this successfully.

It might exist in NGL: atom.resno
can I get atoms._input_value in NGL?
Thanks!

@ppillot
Copy link
Collaborator

ppillot commented Nov 24, 2021

The list of fields is preconfigured.
What you can do is create a ColorMaker that will poll values from your own data structure based on the atom id.
https://nglviewer.org/ngl/api/manual/coloring.html#custom-coloring

@appassionate
Copy link
Author

appassionate commented Nov 25, 2021

The list of fields is preconfigured. What you can do is create a ColorMaker that will poll values from your own data structure based on the atom id. https://nglviewer.org/ngl/api/manual/coloring.html#custom-coloring

@ppillot thanks! actually, i'm nglview user. Maybe it will be easier to add my data using this function, but in python console i have no idea about to trans numpy numerical array to a data in a TS or JS form...
A trick thinking is that if i can update specific color in an exist representation just as adding a reprensentation by sele= "@1","@2","@3". Or a presentation just owns a colorscheme? thank you : )

@hainm
Copy link
Contributor

hainm commented Dec 1, 2021

@appassionate maybe try to follow those threads in nglview:

@fredludlow
Copy link
Collaborator

fredludlow commented Dec 13, 2021

I do a similar thing (more or less per @ppillot's link, custom class polls data from another source). This gets messier when:

  1. The source is async
  2. Serializing state (persisting parameters etc) - requires also serializing/reproducing state of the data source

I've been toying with a few ways around this and wondered whether having a general method for passing data through to custom colormakers would be useful? I think it would make a few things I do less verbose as no custom colormaker would be required, just some paramters.

export interface ColormakerParameters extends ScaleParameters {
  structure?: Structure
  volume?: Volume
  surface?: Surface
  data?: any  // 
}

This would make use of all the existing code around updating a representation with new data (i.e. setParameters({colorData: someNewData}).

More formally, it might be nice to tie the type down a bit more than just any (maybe have optional atomData: { [atomIndex: number]: number}, bondData), these could work with a StructureDataColorMaker so you could do something like this without any custom colormaker code:

// Data as object
representation.setParameters({
  colorScheme: 'structuredata',
  colorData: {
    atomData: {0: 0.51 1: 0.65, ... }
  },
  colorScale: 'rwb'
}) 

// Or as array
representation.setParameters({
  colorScheme: 'structuredata',
  colorData: {
    atomData: [0.51, 0.66, 1.3], 
  },
  colorScale: 'rwb' // colorDomain, etc. 
})

All thoughts and discussion welcome!

fredludlow added a commit to fredludlow/ngl that referenced this issue Dec 13, 2021
…gh to a StructuredataColormaker class. It also provides a mechanism for passing arbitrary data through to a Colormaker instance - see nglviewer#892
fredludlow added a commit to fredludlow/ngl that referenced this issue Dec 13, 2021
…gh to a StructuredataColormaker class. It also provides a mechanism for passing arbitrary data through to a Colormaker instance - see nglviewer#892
@fredludlow fredludlow mentioned this issue Dec 15, 2021
@appassionate
Copy link
Author

appassionate commented Dec 26, 2021

merry xmas!
Thanks those consideration. "colormaker” will contain rendering performance optimization...? i guess. As a python user, i know less about it... : ) A single structure can be imaged, will it be suitable to render a trajectory? Thanks.

@fredludlow
Copy link
Collaborator

Colormakers are the mechanism by which NGL generates color values for rendering (for single structures or trajectories). If you're just passing in an array of values (one per atom index) then the performance would be comparable to e.g. coloring by bfactor.

If the values are static across the whole trajectory, then I think it should "just work" after this is merged, with no hit to performance. If the values (and therefore colors) are changing per-frame, then it might require another few changes, but should be feasible, is that the case?

@appassionate
Copy link
Author

appassionate commented Dec 28, 2021

Colormakers are the mechanism by which NGL generates color values for rendering (for single structures or trajectories). If you're just passing in an array of values (one per atom index) then the performance would be comparable to e.g. coloring by bfactor.

If the values are static across the whole trajectory, then I think it should "just work" after this is merged, with no hit to performance. If the values (and therefore colors) are changing per-frame, then it might require another few changes, but should be feasible, is that the case?

Yes, I agree. If value changing per-frame, I guess it will need some "stream reading" process. I think NGL have finished this topic, for nglview can visualize MDAnalysis trajectory (which is a "stream-like reading" package).
"Original" trajectory information have been loaded by a file in a format. And the data "containing information per frame" might be extra, i guess..

@fredludlow
Copy link
Collaborator

@appassionate - I'm going to close this for now, but please feel free to re-open if you want to revisit it.

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

4 participants