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

Adds support for importing CellPack models #283

Merged
merged 51 commits into from
Nov 1, 2023
Merged

Conversation

BradyAJohnston
Copy link
Owner

@BradyAJohnston BradyAJohnston commented Aug 3, 2023

Imports CellPack models that are stored as .cif files. Creates a data storage object which stores all of the required rotation / translation operations, and creates a collection which contains an object for each protein. The collection can then be used as instances for instancing on the data object to create the assembled model.

image

@codecov
Copy link

codecov bot commented Aug 3, 2023

Codecov Report

Attention: 187 lines in your changes are missing coverage. Please review.

Comparison is base (0b90f84) 66.60% compared to head (2399640) 66.48%.

Additional details and impacted files
@@            Coverage Diff             @@
##             main     #283      +/-   ##
==========================================
- Coverage   66.60%   66.48%   -0.12%     
==========================================
  Files          21       24       +3     
  Lines        2530     3076     +546     
==========================================
+ Hits         1685     2045     +360     
- Misses        845     1031     +186     
Files Coverage Δ
molecularnodes/assembly/mesh.py 98.27% <100.00%> (-0.03%) ⬇️
molecularnodes/load.py 88.59% <100.00%> (+0.03%) ⬆️
molecularnodes/nodes.py 62.69% <100.00%> (+0.14%) ⬆️
molecularnodes/obj.py 100.00% <100.00%> (ø)
molecularnodes/coll.py 96.77% <93.33%> (-3.23%) ⬇️
molecularnodes/assembly/cif.py 89.33% <44.44%> (-6.32%) ⬇️
molecularnodes/ui.py 38.42% <43.75%> (+0.27%) ⬆️
molecularnodes/pack.py 75.00% <75.00%> (ø)
molecularnodes/bcif.py 91.16% <91.16%> (ø)
molecularnodes/decode.py 15.78% <15.78%> (ø)

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@BradyAJohnston
Copy link
Owner Author

BradyAJohnston commented Aug 3, 2023

@corredD would you want to have a look at this? I kept putting off going back to your PR (#121) because I wanted to first integrate the better handling of biological assemblies and instancing of larger structures. I finished implementing that in #278.

With the overhauled biological assembly parsing, it now opens some cellpack models without too much trouble. The above image is tested on the isg_immature.cif from (https://github.com/ccsb-scripps/ISG). Does it look (relatively) correct? I want to hopefully test on other models as well if you have available more cellpack models like the one that you showed off in #121.

I ended up moving completely away from instancing on geometry that was originally implemented in your PR, as Blender is planning on removing that entirely possibly in 4.0 or in a later version in favor of instancing through points / geomtry nodes. If you were willing, having parsing of the colors and other attributes from the .json files that come with the .cif would be be great, and we could then add those as attributes to the models when they are added to get the user-specificied colors and improve possibilities for animations and the like.

@corredD
Copy link
Contributor

corredD commented Aug 3, 2023

Looks great, except for one protein that should not be at the surface. You can see the model here for comparison : https://molstar.org/dev/me/
image
I was able to get the branch running on my workstation, however I am really not familiar with geometry nodes. Here is what I have after loading a small cif file
image
What should I do to add some style to it ?
About the metadata, it would help if you prepare some template function that would change the color style but with random value. I can help replace after that with some coloring based on function or other attributes.

@BradyAJohnston
Copy link
Owner Author

Thanks for the info @corredD and glad you'd like to still contribute.

image

I have fixed the instancing (some of the ordering was slightly out) and have set it up to create a per-molecule color (currently generated randomly).

They should take on the colors automatically now. I have just added a 'Sun' light, then used some nodes to slice through it based on the X axis positions of the instances as shown.

In the initial node tree, the 'proportion' will reduce the number of instances randomly (to make the scene less heavy). I added a compare, separate XYZ and position nodes to get the sliced selection. I'll try and improve the defaults to make it a bit more useful as well.

@BradyAJohnston
Copy link
Owner Author

Also tested on the mature ISG.
image

Fof the lipid .cif files, I get this error which I asume is related to the way biotite deals with the files which we discussed in the other PR:

  File "C:\Users\BradyJohnston\AppData\Roaming\Blender Foundation\Blender\3.6\scripts\addons\MolecularNodes\pack.py", line 131, in execute
    load_cellpack(
  File "C:\Users\BradyJohnston\AppData\Roaming\Blender Foundation\Blender\3.6\scripts\addons\MolecularNodes\pack.py", line 37, in load_cellpack
    obj_data, coll_cellpack = open_file(file_path, name)
  File "C:\Users\BradyJohnston\AppData\Roaming\Blender Foundation\Blender\3.6\scripts\addons\MolecularNodes\pack.py", line 49, in open_file 
    file_open = pdbx.PDBxFile.read(file)
  File "C:\Users\BradyJohnston\Documents\Blender Launcher\stable\blender-3.6.0+stable.c7fc78b81ecb\3.6\python\lib\site-packages\biotite\structure\io\pdbx\file.py", line 138, in read
    data_block,
  File "C:\Users\BradyJohnston\AppData\Roaming\Blender Foundation\Blender\3.6\scripts\addons\MolecularNodes\pack.py", line 131, in execute
    load_cellpack(
  File "C:\Users\BradyJohnston\AppData\Roaming\Blender Foundation\Blender\3.6\scripts\addons\MolecularNodes\pack.py", line 37, in load_cellpack
    obj_data, coll_cellpack = open_file(file_path, name)
  File "C:\Users\BradyJohnston\AppData\Roaming\Blender Foundation\Blender\3.6\scripts\addons\MolecularNodes\pack.py", line 49, in open_file
    file_open = pdbx.PDBxFile.read(file)
  File "C:\Users\BradyJohnston\Documents\Blender Launcher\stable\blender-3.6.0+stable.c7fc78b81ecb\3.6\python\lib\site-packages\biotite\structure\io\pdbx\file.py", line 138, in read  
    data_block,
UnboundLocalError: local variable 'data_block' referenced before assignment

@BradyAJohnston BradyAJohnston merged commit 0e49d57 into main Nov 1, 2023
5 of 6 checks passed
@BradyAJohnston
Copy link
Owner Author

@corredD I did a bunch of cleanup and refactoring and I was pretty happy with how it was handling everything. Thanks for the assistance in getting it all working. Happy with how it is currently for initial support.

The next things to add would be using the custom color palettes and adding other specific attributes that could be useful.

@BradyAJohnston BradyAJohnston deleted the dev-cellpack branch November 1, 2023 07:26
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.

None yet

2 participants