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

Unable to import Molecular nodes #651

Open
universvm opened this issue Nov 8, 2024 · 6 comments
Open

Unable to import Molecular nodes #651

universvm opened this issue Nov 8, 2024 · 6 comments
Labels
bug Something isn't working

Comments

@universvm
Copy link

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):

  • OS: MacOS
  • Hardware: ARM Mac
  • Blender Version: 4.2.3
  • MolecularNodes Version: 4.2.7

Additional context
Add any other context about the problem here.

@universvm universvm added the bug Something isn't working label Nov 8, 2024
@BradyAJohnston
Copy link
Owner

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
Copy link
Author

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
Copy link
Owner

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

@universvm
Copy link
Author

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
Copy link
Owner

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
Copy link
Author

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 :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants