MolecularNodes icon indicating copy to clipboard operation
MolecularNodes copied to clipboard

Color atoms using external data

Open nilsholle opened this issue 1 year ago • 8 comments

Hi, I would like to color the atoms from MolecularNodes based on numbers calculated externally, for example the coordination number of each atom. I can see that the "Color Map Range" node could be useful here, but I don't know how to use data as an input that is not an atom_index or similar. Is there any standard way i am missing? Thanks!

nilsholle avatar Jul 29 '22 11:07 nilsholle

The easiest way currently would be to write whatever information you wanted to the b-factor column of a .pdb file and then use that inside of Molecular Nodes.

There is no easy way currently to import just arbitrary tabular data (although I am working on some data-specific nodes for this purpose).

You could import arbitrary tabular data through the python API and then match up the points via index & a transfer attribute node, but simplest approach would be to use the b-factor column.

BradyAJohnston avatar Jul 30 '22 00:07 BradyAJohnston

Thank you, using the b-factor columns works just fine for now!

For other people using the ASE package: You can add b-factor data to an ASE Atoms-object e.g. using

import numpy as np
from ase import io

atoms = io.read(...)
atoms.arrays["bfactor"] = np.random.random(len(atoms))
io.write("....pdb", atoms)

nilsholle avatar Aug 01 '22 09:08 nilsholle

Nice! Glad that it's working and thanks for sharing the code :)

BradyAJohnston avatar Aug 02 '22 03:08 BradyAJohnston

I am having an additional issue, when using a multiframe PBD. The b-factor field (and alternatives such as chainID) seem fixed based on the initial frame and fixed to that value, rather than updating like the coordinate data does. Is there any workaround for this?

ghost avatar Aug 11 '22 13:08 ghost

If the b-factor is different between the models in the file, it should be updating, the new b-factor that comes from the MOL_animate_frames node. image

I am just realising that inside of the node, I don't re-assign the updated b-factor to the model, so this could be causing the issue here! But if you manually set that up as shown below, this might solve the issue. image

Let me know if it doesn't. If the PDB file definitely has changing values and it's now showing up, then if you can share the file I can try and debug it.

BradyAJohnston avatar Aug 11 '22 13:08 BradyAJohnston

I still can't fix the issue. Although I wonder if it is my lack of understanding of blender at this point. The Store Named Attirbute block now makes the B_factor value change in the pointcloud points data. I can't make this propagate through to the colouring.

I have included a minimal example I quickly put together to test this.

TITLE     MDANALYSIS FRAMES FROM 0, STEP 1: Created by PDBWriter
CRYST1    1.000    1.000    1.000  90.00  90.00  90.00 P 1           1
REMARK     285 UNITARY VALUES FOR THE UNIT CELL AUTOMATICALLY SET
REMARK     285 BY MDANALYSIS PDBWRITER BECAUSE UNIT CELL INFORMATION
REMARK     285 WAS MISSING.
REMARK     285 PROTEIN DATA BANK CONVENTIONS REQUIRE THAT
REMARK     285 CRYST1 RECORD IS INCLUDED, BUT THE VALUES ON
REMARK     285 THIS RECORD ARE MEANINGLESS.
MODEL        1
ATOM      1  O   SOL X   1       0.000   0.000   0.000  1.00  0.17      SOL  O
ATOM      2  H1  SOL X   1       0.000   0.000   0.000  1.00  0.17      SOL  H
ATOM      3  H2  SOL X   1       0.000   0.000   0.000  1.00  0.17      SOL  H
ENDMDL
MODEL        2
ATOM      1  O   SOL X   1       0.000   0.000   0.000  1.00  0.33      SOL  O
ATOM      2  H1  SOL X   1       0.000   0.000   0.000  1.00  0.33      SOL  H
ATOM      3  H2  SOL X   1       0.959   0.959   0.959  1.00  0.33      SOL  H
ENDMDL
MODEL        3
ATOM      1  O   SOL X   1       0.959   0.959  -0.027  1.00  0.50      SOL  O
ATOM      2  H1  SOL X   1      -0.027  -0.027  -0.027  1.00  0.50      SOL  H
ATOM      3  H2  SOL X   1      -0.027   0.032   0.032  1.00  0.50      SOL  H
ENDMDL
MODEL        4
ATOM      1  O   SOL X   1       0.032   0.032   0.032  1.00  0.67      SOL  O
ATOM      2  H1  SOL X   1      -0.280  -0.280  -0.280  1.00  0.67      SOL  H
ATOM      3  H2  SOL X   1      -0.280  -0.280  -0.588  1.00  0.67      SOL  H
ENDMDL
MODEL        5
ATOM      1  O   SOL X   1      -0.588  -0.588  -0.588  1.00  0.83      SOL  O
ATOM      2  H1  SOL X   1      -0.588   0.706   0.706  1.00  0.83      SOL  H
ATOM      3  H2  SOL X   1       0.706   0.706   0.706  1.00  0.83      SOL  H
ENDMDL
END

ghost avatar Aug 11 '22 14:08 ghost

I have just had a play around and it seems that when importing via the 'Local File' tab which goes via Atomium then the B-value changes with the frame (but is still kind of wrong) but it doesn't change at all when imported via MDAnalysis.

Will have a look into it! Thanks for the bug report and the reproducible example.

BradyAJohnston avatar Aug 13 '22 08:08 BradyAJohnston

After the MolecularNodes re-write I thought this would be fixed, but it turns out this is still an issue with Biotite as well: https://github.com/biotite-dev/biotite/issues/449

This is unfortunately still an issue, open to suggestions on fixes, but we may have to wait for Biotite to support it.

BradyAJohnston avatar Dec 13 '22 11:12 BradyAJohnston