Open thetechnocrat-dev opened 6 months ago
Thanks for the report! I can reproduce this error:
from a clean python3.10 env with pip install ipykernel molecularnodes bpy
this can be fixed with using a previous version of molecular nodes with pip install molecularnodes==2.10.0
https://pypi.org/project/molecularnodes/#history
@BradyAJohnston : Can you give us a hint on how to use the load function with the latest api? :)
pip install molecularnodes==2.10.0
Worked for me as well, good catch!
The underlying API should not be considered stable at all. We are still trying to figure out what is the best approach for everything. It is discussed here and I welcome feedback or suggestions on what you would like to see.
To replicate importing from the PDB, you can now use as follows:
mol = mn.io.fetch('7YTG')
The result will be a Molecule
object, which is intended to be a more helpful interface for working with Blender objects / underlying data.
mol.object # accesses the Blender object
mol.data # accessses the underlying AtomArray and original data
# get and set named attributes on the Blender object
mol.get_attribute('position')
mol.set_attribute('b_factor', np.repeat(100, len(mol))
I welcome feedback and suggestions on how you think should be implemented / changed / improved
oh, nice!
Seems like these the latest mn.io.fetch
is not yet released on pypi:
Otherwise, I like the naming of the new api!
Ah yeah I have not been prioritising releasing to pypi
because the API is in such flux, but I'll release the latest version for testing
v4.0.12
is now on pypi
Thanks for the update! With the latest version, I still get an error though
Add in molecularnodes.register()
after import and it should fix it.
now I still get this error:
the structure is not released yet and thus cannot be downloaded, this is not a MN issue
Oh, I realize there was a typo, it's 7TYG instead of 7YTG :)
mol = mn.io.fetch('7TYG')
works fine now!
Now I don't get any errors anymore, however the scene is rendering empty, probably I still have to add the object to the scene somehow.
The default style is now spheres, if you use another style or change the spheres to work in eevee it will render
Nice!
Next question would be then: How does the API look now in order to change to
style="ball_and_stick"
?
I'm also right now thinking if it makes sense to maintain this repo at all, or if it would be better to archive it and keep the notebooks directly in the main molecular nodes repo. That way, it would probably be easier to keep the api in sync.
Currently you can change the style by either stating a different style on import, or changing the style with a function (which isn't particularly nice but is just the current way to do it).
import molecularnodes as mn
mn.register()
# import with a specific style other than the default
mol = mn.io.fetch('7TYG', style='ball_and_stick')
# change the style node which is used for the blender object
mn.blender.nodes.change_style_node(mol.object, 'surface')
Again I have to emphasize that a lot of this will change (especially the changing of styles).
I'm also right now thinking if it makes sense to maintain this repo at all, or if it would be better to archive it and keep the notebooks directly in the main molecular nodes repo. That way, it would probably be easier to keep the api in sync.
If you would like to contribute to the improvement and refinement of the API and also some example documents / notebooks then I would certainly welcome it. I'm not focused on maintaining example code at the moment if the API is still not settled at all.
awesome, that below script is working with mn version 4.0.12.
I think the best path for this repo is then to pin the molecularnodes version to 2.10.0 and install withpip install molecularnodes==2.10.0
.
And at one point in future when there is a more stable version, rendering molecules in notebooks could maybe be revisited.
here the script for reference:
import sys
import os
def clear_scene():
bpy.ops.object.select_all(action="DESELECT")
bpy.ops.object.select_by_type(type="MESH")
bpy.ops.object.delete()
def render_image():
# Render
path = "test.png"
bpy.context.scene.render.resolution_x = 1000
bpy.context.scene.render.resolution_y = 500
bpy.context.scene.render.image_settings.file_format = "PNG"
bpy.context.scene.render.filepath = path
bpy.ops.render.render(write_still=True)
bpy.data.images["Render Result"].save_render(filepath=bpy.context.scene.render.filepath)
display(Image(filename=path))
import bpy
from IPython.display import display, Image
clear_scene()
# Camera
camera = bpy.data.objects["Camera"]
camera.location = (5, -3, 4)
camera.data.dof.use_dof = True
camera.data.dof.focus_distance = 4
camera.data.dof.aperture_fstop = 4
import molecularnodes as mn
mn.register()
# import with a specific style other than the default
mol = mn.io.fetch('7TYG', style='ball_and_stick')
# change the style node which is used for the blender object
mn.blender.nodes.change_style_node(mol.object, 'surface')
render_image()
I am getting the below issue at the moment when running the minimal example as a python script. I briefly looked at the molecular nodes package to see if I could find if the function name was updated.