BradyAJohnston / MolecularNodes

Toolbox for molecular animations in Blender, powered by Geometry Nodes.
https://bradyajohnston.github.io/MolecularNodes/
GNU General Public License v3.0
912 stars 85 forks source link

Unable to import Molecular nodes #651

Open universvm opened 4 days ago

universvm commented 4 days ago

Hi there,

Sorry if this is a dumb question but I'm fairly new to blender. I've installed the plugin and made my first render. However, I would like to automate this with a python script to download and generate several images of a different proteins.

However, I'm sure I'm doing something wrong:

Describe the bug

When I move to the "Scripting" tab and simply type:

import MolecularNodes as mn

Python: Traceback (most recent call last):
  File "<frozen importlib._bootstrap>", line 1176, in _find_and_load
  File "<frozen importlib._bootstrap>", line 1140, in _find_and_load_unlocked
ModuleNotFoundError: No module named 'MolecularNodes'

To Reproduce See above

Expected behavior No error

Error Codes

Screenshots If applicable, add screenshots to help explain your problem.

Desktop (please complete the following information):

Additional context Add any other context about the problem here.

BradyAJohnston commented 3 days ago

For the 4.2 update, Blender changed how add-ons are imported. Currently you can import molecularnodes like this:

from bl_ext.user_default import molecularnodes as mn

mn.entities.fetch("8H1B", style="cartoon", centre="centroid")

The python API should not be considered stable, as it is something that is still being developed and is evolving (and isn't well documented because of this), but I welcome feedback and suggestions on how you would like this to work.

universvm commented 3 days ago

For the 4.2 update, Blender changed how add-ons are imported. Currently you can import molecularnodes like this:

from bl_ext.user_default import molecularnodes as mn

mn.entities.fetch("8H1B", style="cartoon", centre="centroid")

The python API should not be considered stable, as it is something that is still being developed and is evolving (and isn't well documented because of this), but I welcome feedback and suggestions on how you would like this to work.

Hi there, thanks for your reply, I'd be more than happy to help with the python interface. I've been getting these weird errors though:

import bpy
from bl_ext.user_default import molecularnodes as mn

mn.entities.fetch("8H1B", style="cartoon", centre="centroid")
Traceback (most recent call last):
  File "/Users/leo/Desktop/prova.py", line 22, in <module>
    mn.entities.fetch("8H1B", style="cartoon", centre="centroid")
  File "/Users/leo/Library/Application Support/Blender/4.2/extensions/user_default/molecularnodes/entities/molecule/ui.py", line 65, in fetch
    mol = parse(file_path)
          ^^^^^^^^^^^^^^^^
  File "/Users/leo/Library/Application Support/Blender/4.2/extensions/user_default/molecularnodes/entities/molecule/ui.py", line 39, in parse
    molecule = parser[suffix](filepath)
               ^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/leo/Library/Application Support/Blender/4.2/extensions/user_default/molecularnodes/entities/molecule/pdbx.py", line 270, in __init__
    super().__init__(file_path)
  File "/Users/leo/Library/Application Support/Blender/4.2/extensions/user_default/molecularnodes/entities/molecule/pdbx.py", line 13, in __init__
    super().__init__(file_path=file_path)
  File "/Users/leo/Library/Application Support/Blender/4.2/extensions/user_default/molecularnodes/entities/molecule/molecule.py", line 67, in __init__
    bpy.context.scene.MNSession.molecules[self.uuid] = self
    ^^^^^^^^^^^^^^^^^^^^^^^^^^^
AttributeError: 'Scene' object has no attribute 'MNSession'
[1]    42276 segmentation fault  python prova.py
BradyAJohnston commented 2 days ago

I haven't seen this error before, but it might be that the add-on is disabled in Blender preferences?

universvm commented 2 days ago

I haven't seen this error before, but it might be that the add-on is disabled in Blender preferences?

Ah! Seems like within blender this works. However, if I create a conda environment with blender and Molecular Nodes I get that error.

A way around it is simply to use:

blender -b --python /Users/leo/Desktop/prova.py

Here's a pretty protein 1qys_render

BradyAJohnston commented 2 days ago

Ah yes it'll currently need to be executed by Blender to work properly. This is something that can be improved upon though, as I can skip the step that is currently failing when we are not in Blender to begin with.

Glad to see it's working! Please do keep me update

universvm commented 2 days ago

Ah yes it'll currently need to be executed by Blender to work properly. This is something that can be improved upon though, as I can skip the step that is currently failing when we are not in Blender to begin with.

Glad to see it's working! Please do keep me update

Ofc I'll keep you up to date with this :)