From 52ba311f21bacc3c41b4fae3f8f4a8425d2b83df Mon Sep 17 00:00:00 2001 From: Andrew Radev Date: Thu, 12 Dec 2024 20:02:56 +0100 Subject: [PATCH] Various blender fixes and tweaks --- blender/extension/__init__.py | 3 +- blender/extension/blender_manifest.toml | 51 ++----------------- blender/extension/lib/segmentation.py | 22 +++++--- blender/extension/ui/import_pdb_operator.py | 6 --- .../extension/ui/import_trajectory_panel.py | 2 +- 5 files changed, 21 insertions(+), 63 deletions(-) diff --git a/blender/extension/__init__.py b/blender/extension/__init__.py index 6d26723..c172e95 100644 --- a/blender/extension/__init__.py +++ b/blender/extension/__init__.py @@ -1,4 +1,5 @@ import bpy +import os from .ui.import_pdb_operator import ImportPDBOperator from .ui.animate_trajectory_operator import AnimateTrajectoryOperator @@ -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 diff --git a/blender/extension/blender_manifest.toml b/blender/extension/blender_manifest.toml index 3e94501..f9e1c99 100644 --- a/blender/extension/blender_manifest.toml +++ b/blender/extension/blender_manifest.toml @@ -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 " +maintainer = "Andrew Radev " -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" @@ -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", -# ] diff --git a/blender/extension/lib/segmentation.py b/blender/extension/lib/segmentation.py index 262a888..f2c59b4 100644 --- a/blender/extension/lib/segmentation.py +++ b/blender/extension/lib/segmentation.py @@ -2,6 +2,11 @@ import re from collections import defaultdict + +class ParseError(Exception): + pass + + def parse_segmentation_file(path): """ Expected columns: 'index', 'method', 'domain_count', 'chopping' @@ -9,14 +14,15 @@ def parse_segmentation_file(path): # A nested dictionary of { : { : } } 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): @@ -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 diff --git a/blender/extension/ui/import_pdb_operator.py b/blender/extension/ui/import_pdb_operator.py index a726fa1..f057837 100644 --- a/blender/extension/ui/import_pdb_operator.py +++ b/blender/extension/ui/import_pdb_operator.py @@ -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): diff --git a/blender/extension/ui/import_trajectory_panel.py b/blender/extension/ui/import_trajectory_panel.py index adddfdb..2cb2886 100644 --- a/blender/extension/ui/import_trajectory_panel.py +++ b/blender/extension/ui/import_trajectory_panel.py @@ -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"