Skip to content

Commit

Permalink
Various blender fixes and tweaks
Browse files Browse the repository at this point in the history
  • Loading branch information
AndrewRadev committed Dec 12, 2024
1 parent c3696e6 commit 52ba311
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 63 deletions.
3 changes: 2 additions & 1 deletion blender/extension/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import bpy
import os

from .ui.import_pdb_operator import ImportPDBOperator
from .ui.animate_trajectory_operator import AnimateTrajectoryOperator
Expand Down Expand Up @@ -94,7 +95,7 @@ def update_segmentation_path(self, context):
self.ProteinRunway_segmentation_items.clear()

path = self.ProteinRunway_segmentation_path
if len(path) == 0:
if len(path) == 0 or not os.path.isfile(path):
# The path has been removed, clear out the UI lists:
return

Expand Down
51 changes: 4 additions & 47 deletions blender/extension/blender_manifest.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,31 +4,18 @@ id = "protein_runway"
version = "0.0.1"
name = "Protein Runway"
tagline = "Render proteins with their trajectories, segment and extract normal modes."
maintainer = "TODO <[email protected]>"
maintainer = "Andrew Radev <[email protected]>"

type = "add-on"

# # Optional: link to documentation, support, source files, etc
# website = "https://extensions.blender.org/add-ons/my-example-package/"

# # Optional: tag list defined by Blender and server, see:
# # https://docs.blender.org/manual/en/dev/advanced/extensions/tags.html
# tags = ["Animation", "Sequencer"]
type = "add-on"
website = "https://andrewradev.github.io/protein-runway/"
tags = ["Animation", "Import-Export", "Physics"]

blender_version_min = "4.2.0"
# # Optional: Blender version that the extension does not support, earlier versions are supported.
# # This can be omitted and defined later on the extensions platform if an issue is found.
# blender_version_max = "5.1.0"

# https://docs.blender.org/manual/en/dev/advanced/extensions/licenses.html
license = [
"SPDX:GPL-3.0-or-later",
]
# # Optional: required by some licenses.
# copyright = [
# "2002-2024 Developer Name",
# "1998 Company Name",
# ]

platforms = ["windows-x64", "macos-arm64", "linux-x64", "macos-x64"]
# Other supported platforms: "windows-arm64"
Expand Down Expand Up @@ -92,33 +79,3 @@ wheels = [
"./wheels/tqdm-4.67.1-py3-none-any.whl",
"./wheels/waterdynamics-1.2.0-py3-none-any.whl",
]

# # Optional: add-ons can list which resources they will require:
# # * files (for access of any filesystem operations)
# # * network (for internet access)
# # * clipboard (to read and/or write the system clipboard)
# # * camera (to capture photos and videos)
# # * microphone (to capture audio)
# #
# # If using network, remember to also check `bpy.app.online_access`
# # https://docs.blender.org/manual/en/dev/advanced/extensions/addons.html#internet-access
# #
# # For each permission it is important to also specify the reason why it is required.
# # Keep this a single short sentence without a period (.) at the end.
# # For longer explanations use the documentation or detail page.
#
# [permissions]
# network = "Need to sync motion-capture data to server"
# files = "Import/export FBX from/to disk"
# clipboard = "Copy and paste bone transforms"

# # Optional: advanced build settings.
# # https://docs.blender.org/manual/en/dev/advanced/extensions/command_line_arguments.html#command-line-args-extension-build
# [build]
# # These are the default build excluded patterns.
# # You only need to edit them if you want different options.
# paths_exclude_pattern = [
# "__pycache__/",
# "/.git/",
# "/*.zip",
# ]
22 changes: 14 additions & 8 deletions blender/extension/lib/segmentation.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,21 +2,27 @@
import re
from collections import defaultdict


class ParseError(Exception):
pass


def parse_segmentation_file(path):
"""
Expected columns: 'index', 'method', 'domain_count', 'chopping'
"""
# A nested dictionary of { <method>: { <domain_count>: <chopping> } }
segmentations = defaultdict(dict)

# TODO (2024-11-17) Handle errors

with open(path) as f:
reader = csv.DictReader(f, delimiter='\t')
for row in reader:
segmentations[row['method']][row['domain_count']] = row['chopping']
try:
with open(path) as f:
reader = csv.DictReader(f, delimiter='\t')
for row in reader:
segmentations[row['method']][row['domain_count']] = row['chopping']

return segmentations
return segmentations
except Exception as e:
raise ParseError(f"Couldn't parse segmentation file {path}") from e


def generate_domain_ranges(chopping):
Expand All @@ -25,7 +31,7 @@ def generate_domain_ranges(chopping):
for domain in chopping.split(','):
regions = []
for region in domain.split('_'):
if re.match('^\d+$', region) is None:
if re.match(r'^\d+$', region) is None:
start, end = region.split('-')
else:
# Only a single domain
Expand Down
6 changes: 0 additions & 6 deletions blender/extension/ui/import_pdb_operator.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,12 +60,6 @@ def execute(self, context):
o.select_set(True)
bpy.ops.protein_runway.animate_trajectory('INVOKE_DEFAULT')

# TODO (2024-11-14) This is messy and invasive, it might interfere with
# multiple trajectories
#
# Fit the number of global frames to this trajectory's length.
bpy.data.scenes[0].frame_end = len(mda_universe.trajectory)

return {'FINISHED'}

def draw_alpha_carbons(self, universe, domain_regions, add_convex_hull):
Expand Down
2 changes: 1 addition & 1 deletion blender/extension/ui/import_trajectory_panel.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@


class ImportTrajectoryPanel(bpy.types.Panel):
bl_label = "Import Trajectory"
bl_label = "ProteinRunway: Import Trajectory"
bl_idname = "PROTEINRUNWAY_PT_import_panel"
bl_space_type = "PROPERTIES"
bl_region_type = "WINDOW"
Expand Down

0 comments on commit 52ba311

Please sign in to comment.