Skip to content

Commit

Permalink
Merge branch 'main' into docs-tutorials
Browse files Browse the repository at this point in the history
  • Loading branch information
BradyAJohnston committed Sep 4, 2023
2 parents 54a26f3 + 8affccd commit c4dd714
Show file tree
Hide file tree
Showing 25 changed files with 1,771 additions and 1,603 deletions.
1 change: 0 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
*.blend1
__pycache__/*
.vscode/*
*.zip
*.pyc
.Rproj.user
/.quarto/
Expand Down
11 changes: 8 additions & 3 deletions MolecularNodes/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,15 +26,20 @@
}

from . import auto_load
from .ui import mol_add_node_menu
from .ui import MN_add_node_menu
import bpy
import pathlib
import os
from . import pref

auto_load.init()

def register():
auto_load.register()
bpy.types.NODE_MT_add.append(mol_add_node_menu)
bpy.types.NODE_MT_add.append(MN_add_node_menu)
pref.template_install()

def unregister():
bpy.types.NODE_MT_add.remove(mol_add_node_menu)
bpy.types.NODE_MT_add.remove(MN_add_node_menu)
auto_load.unregister()
pref.template_uninstall()
8 changes: 4 additions & 4 deletions MolecularNodes/assembly/mesh.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,11 +81,11 @@ def transform_chains(assembly, index = 0):

def rotation_from_matrix(matrix):
from scipy.spatial.transform import Rotation as R
import warnings

# calculate the euler rotation from the rotation matrix
# Blender is 'xyz' euler rotations. Internally they use matrices / quaternions, but
# current interfaces for geometry nodes are just eulers

rotation = R.from_matrix(matrix).as_euler('xyz')

return rotation
with warnings.catch_warnings():
warnings.simplefilter("ignore")
return R.from_matrix(matrix).as_euler('xyz')
Binary file not shown.
Binary file not shown.
28 changes: 28 additions & 0 deletions MolecularNodes/assets/template/Molecular_Nodes/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
# SPDX-License-Identifier: GPL-2.0-or-later

import bpy
# from bpy.app.handlers import persistent


# @persistent
# def load_handler(_):
# import bpy
# Apply subdivision modifier on startup
# bpy.ops.object.mode_set(mode='OBJECT')
# if bpy.app.opensubdiv.supported:
# bpy.ops.object.modifier_apply(modifier="Subdivision")
# bpy.ops.object.mode_set(mode='EDIT')
# bpy.ops.transform.tosphere(value=1.0)
# else:
# bpy.ops.object.modifier_remove(modifier="Subdivision")
# bpy.ops.object.mode_set(mode='EDIT')
# bpy.ops.mesh.subdivide(number_cuts=6, smoothness=1.0)
# bpy.ops.object.mode_set(mode='SCULPT')


def register():
# bpy.app.handlers.load_factory_startup_post.append(load_handler)


def unregister():
# bpy.app.handlers.load_factory_startup_post.remove(load_handler)
Binary file not shown.
9 changes: 9 additions & 0 deletions MolecularNodes/color.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import random
import colorsys
import numpy as np

def random_rgb():
"""Random Pastel RGB values
"""
r, g, b = colorsys.hls_to_rgb(random.random(), 0.6, 0.6)
return np.array((r, g, b, 1))
31 changes: 15 additions & 16 deletions MolecularNodes/density.py
Original file line number Diff line number Diff line change
@@ -1,20 +1,19 @@
import bpy
# import pyopenvdb as vdb
import numpy as np
from . import nodes
import os

bpy.types.Scene.mol_import_map_nodes = bpy.props.BoolProperty(
name = "mol_import_map_nodes",
bpy.types.Scene.MN_import_map_nodes = bpy.props.BoolProperty(
name = "MN_import_map_nodes",
description = "Creating starting node tree for imported map.",
default = True
)
bpy.types.Scene.mol_import_map_invert = bpy.props.BoolProperty(
name = "mol_import_map_invert",
bpy.types.Scene.MN_import_map_invert = bpy.props.BoolProperty(
name = "MN_import_map_invert",
description = "Invert the values in the map. Low becomes high, high becomes low.",
default = False
)
bpy.types.Scene.mol_import_map = bpy.props.StringProperty(
bpy.types.Scene.MN_import_map = bpy.props.StringProperty(
name = 'path_map',
description = 'File path for the map file.',
options = {'TEXTEDIT_UPDATE'},
Expand Down Expand Up @@ -166,8 +165,8 @@ def load(file: str, name: str = None, invert: bool = False, world_scale: float =

return vol_object

class MOL_OT_Import_Map(bpy.types.Operator):
bl_idname = "mol.import_map"
class MN_OT_Import_Map(bpy.types.Operator):
bl_idname = "mn.import_map"
bl_label = "ImportMap"
bl_description = "Import a CryoEM map into Blender"
bl_options = {"REGISTER"}
Expand All @@ -177,9 +176,9 @@ def poll(cls, context):
return True

def execute(self, context):
map_file = bpy.context.scene.mol_import_map
invert = bpy.context.scene.mol_import_map_invert
setup_node_tree = bpy.context.scene.mol_import_map_nodes
map_file = bpy.context.scene.MN_import_map
invert = bpy.context.scene.MN_import_map_invert
setup_node_tree = bpy.context.scene.MN_import_map_nodes

vol = load(
file = map_file,
Expand All @@ -194,17 +193,17 @@ def panel(layout_function, scene):
col_main = layout_function.column(heading = '', align = False)
col_main.label(text = 'Import EM Maps as Volumes')
row = col_main.row()
row.prop(bpy.context.scene, 'mol_import_map_nodes',
row.prop(bpy.context.scene, 'MN_import_map_nodes',
text = 'Starting Node Tree'
)
row.prop(bpy.context.scene, 'mol_import_map_invert',
row.prop(bpy.context.scene, 'MN_import_map_invert',
text = 'Invert Data',
emboss = True
)

row.operator('mol.import_map', text = 'Load Map', icon = 'FILE_TICK')
row.operator('mn.import_map', text = 'Load Map', icon = 'FILE_TICK')

col_main.prop(bpy.context.scene, 'mol_import_map',
col_main.prop(bpy.context.scene, 'MN_import_map',
text = 'EM Map',
emboss = True
)
Expand All @@ -213,7 +212,7 @@ def panel(layout_function, scene):
box.alignment = "LEFT"
box.scale_y = 0.4
box.label(
text = f"Intermediate file: {path_to_vdb(bpy.context.scene.mol_import_map)}."
text = f"Intermediate file: {path_to_vdb(bpy.context.scene.MN_import_map)}."
)
box.label(
text = "Please do not delete this file or the volume will not render."
Expand Down
46 changes: 23 additions & 23 deletions MolecularNodes/esmfold.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,16 @@
import requests
import io

bpy.types.Scene.mol_esmfold_sequence = bpy.props.StringProperty(
bpy.types.Scene.MN_esmfold_sequence = bpy.props.StringProperty(
name = 'amino_acid_sequence',
description = 'Amino acid sequence of the structure to open',
options = {'TEXTEDIT_UPDATE'},
default = '',
subtype = 'FILE_PATH',
maxlen = 0
)
bpy.types.Scene.mol_esmfold_name = bpy.props.StringProperty(
name = 'mol_name',
bpy.types.Scene.MN_esmfold_name = bpy.props.StringProperty(
name = 'MN_name',
description = 'Name of the molecule on import',
options = {'TEXTEDIT_UPDATE'},
default = 'NewMolecule',
Expand All @@ -24,7 +24,7 @@

def molecule_esmfold(
amino_acid_sequence,
mol_name = "Name",
MN_name = "Name",
center_molecule = False,
del_solvent = True,
include_bonds = True,
Expand All @@ -36,9 +36,9 @@ def molecule_esmfold(
include_bonds=include_bonds
)

mol_object, coll_frames = load.create_molecule(
mol_array = mol,
mol_name = mol_name,
MN_object, coll_frames = load.create_molecule(
MN_array = mol,
MN_name = MN_name,
file = file,
calculate_ss = True,
center_molecule = center_molecule,
Expand All @@ -48,11 +48,11 @@ def molecule_esmfold(

if setup_nodes:
nodes.create_starting_node_tree(
obj = mol_object,
obj = MN_object,
coll_frames=coll_frames,
starting_style = starting_style
)
return mol_object
return MN_object

def open_structure_esm_fold(amino_acid_sequence, include_bonds=True):
import biotite.structure.io.pdb as pdb
Expand Down Expand Up @@ -89,8 +89,8 @@ def open_structure_esm_fold(amino_acid_sequence, include_bonds=True):
raise ValueError(f'ESMFold returned an error for the amino acid sequence input. This is the error message: {r.text}')

# operator that calls the function to import the structure from ESMFold
class MOL_OT_Import_Protein_ESMFold(bpy.types.Operator):
bl_idname = "mol.import_protein_esmfold"
class MN_OT_Import_Protein_ESMFold(bpy.types.Operator):
bl_idname = "mn.import_protein_esmfold"
bl_label = "import_protein_esmfold"
bl_description = "Generate structure from ESMFold"
bl_options = {"REGISTER", "UNDO"}
Expand All @@ -100,21 +100,21 @@ def poll(cls, context):
return not False

def execute(self, context):
amino_acid_sequence = bpy.context.scene.mol_esmfold_sequence
amino_acid_sequence = bpy.context.scene.MN_esmfold_sequence

mol_object = molecule_esmfold(
MN_object = molecule_esmfold(
amino_acid_sequence=amino_acid_sequence,
mol_name=bpy.context.scene.mol_esmfold_name,
include_bonds=bpy.context.scene.mol_import_include_bonds,
center_molecule=bpy.context.scene.mol_import_center,
del_solvent=bpy.context.scene.mol_import_del_solvent,
starting_style=bpy.context.scene.mol_import_default_style,
MN_name=bpy.context.scene.MN_esmfold_name,
include_bonds=bpy.context.scene.MN_import_include_bonds,
center_molecule=bpy.context.scene.MN_import_center,
del_solvent=bpy.context.scene.MN_import_del_solvent,
starting_style=bpy.context.scene.MN_import_default_style,
setup_nodes=True
)

# return the good news!
bpy.context.view_layer.objects.active = mol_object
self.report({'INFO'}, message=f"Generated protein '{amino_acid_sequence}' as {mol_object.name}")
bpy.context.view_layer.objects.active = MN_object
self.report({'INFO'}, message=f"Generated protein '{amino_acid_sequence}' as {MN_object.name}")
return {"FINISHED"}

def invoke(self, context, event):
Expand All @@ -129,13 +129,13 @@ def panel(layout_function, ):
col_main.active = True
col_main.label(text = "Generate Structure from ESMFold")
row_name = col_main.row(align = False)
row_name.prop(bpy.context.scene, 'mol_esmfold_name',
row_name.prop(bpy.context.scene, 'MN_esmfold_name',
text = "Name", icon_value = 0, emboss = True)
row_name.operator('mol.import_protein_esmfold', text='Generate', icon='IMPORT')
row_name.operator('mn.import_protein_esmfold', text='Generate', icon='IMPORT')

row_seq = col_main.row()
row_seq.prop(
bpy.context.scene, 'mol_esmfold_sequence',
bpy.context.scene, 'MN_esmfold_sequence',
text = "Sequence",
icon_value = 0,
emboss = True
Expand Down
Loading

0 comments on commit c4dd714

Please sign in to comment.