From 6fd9329c5b115c883dc9cc64e96be2b4d899b86e Mon Sep 17 00:00:00 2001 From: Clemens Barth <barth@root-1.de> Date: Wed, 21 Mar 2012 21:50:24 +0000 Subject: [PATCH] Attention: big changes in __init__.py, almost no changes in import_pdb.py and export_pdb.py 1. With respect to the propositions made by Campbell and Sebastian (see http://projects.blender.org/tracker/?func=detail&group_id=153&aid=29226&atid=469) I changed the code. The PDB IO has now the preset option in the file dialog of the importer and exporter. 2. Furthermore, I have put all properties into one group, which is located in bpy.contect.scene. 3. Some code cleaning Soon, I will put in a new option (next days): the user can decide whether the panel is always, once or never shown after a PDB file is loaded. Note that the panel is essential for me and also my students. It helps quickly modifying PDB structures. Blendphys --- io_mesh_pdb/__init__.py | 459 +++++++++++++++++++++----------------- io_mesh_pdb/export_pdb.py | 2 +- io_mesh_pdb/import_pdb.py | 2 +- 3 files changed, 258 insertions(+), 205 deletions(-) diff --git a/io_mesh_pdb/__init__.py b/io_mesh_pdb/__init__.py index c32382f44..539c299bc 100644 --- a/io_mesh_pdb/__init__.py +++ b/io_mesh_pdb/__init__.py @@ -71,94 +71,89 @@ class CLASS_atom_pdb_panel(Panel): def draw(self, context): layout = self.layout - scn = bpy.context.scene + scn = context.scene.atom_pdb[0] row = layout.row() row.label(text="Outputs and custom data file") - box = layout.box() row = box.row() row.label(text="Custom data file") row = box.row() col = row.column() - col.prop(scn, "atom_pdb_datafile") + col.prop(scn, "datafile") col.operator("atom_pdb.datafile_apply") row = box.row() col = row.column(align=True) - col.prop(scn, "atom_pdb_PDB_file") - + col.prop(scn, "PDB_file") row = layout.row() row.label(text="Reload structure") - box = layout.box() row = box.row() col = row.column() - col.prop(scn, "use_atom_pdb_mesh") + col.prop(scn, "use_mesh") col = row.column() col.label(text="Scaling factors") row = box.row() col = row.column(align=True) - col.active = scn.use_atom_pdb_mesh - col.prop(scn, "atom_pdb_mesh_azimuth") - col.prop(scn, "atom_pdb_mesh_zenith") + col.active = scn.use_mesh + col.prop(scn, "mesh_azimuth") + col.prop(scn, "mesh_zenith") col = row.column(align=True) - col.prop(scn, "atom_pdb_scale_ballradius") - col.prop(scn, "atom_pdb_scale_distances") + col.prop(scn, "scale_ballradius") + col.prop(scn, "scale_distances") row = box.row() col = row.column() - col.prop(scn, "use_atom_pdb_sticks") + col.prop(scn, "use_sticks") row = box.row() - row.active = scn.use_atom_pdb_sticks + row.active = scn.use_sticks col = row.column(align=True) - col.prop(scn, "atom_pdb_sticks_sectors") - col.prop(scn, "atom_pdb_sticks_radius") - col.prop(scn, "atom_pdb_sticks_unit_length") + col.prop(scn, "sticks_sectors") + col.prop(scn, "sticks_radius") + col.prop(scn, "sticks_unit_length") col = row.column(align=True) - col.prop(scn, "use_atom_pdb_sticks_color") - col.prop(scn, "use_atom_pdb_sticks_smooth") - col.prop(scn, "use_atom_pdb_sticks_bonds") + col.prop(scn, "use_sticks_color") + col.prop(scn, "use_sticks_smooth") + col.prop(scn, "use_sticks_bonds") row = box.row() - row.active = scn.use_atom_pdb_sticks + row.active = scn.use_sticks col = row.column(align=True) col = row.column(align=True) - col.active = scn.use_atom_pdb_sticks and scn.use_atom_pdb_sticks_bonds - col.prop(scn, "atom_pdb_sticks_dist") + col.active = scn.use_sticks and scn.use_sticks_bonds + col.prop(scn, "sticks_dist") row = box.row() - row.prop(scn, "use_atom_pdb_center") + row.prop(scn, "use_center") row = box.row() col = row.column() - col.prop(scn, "use_atom_pdb_cam") - col.prop(scn, "use_atom_pdb_lamp") + col.prop(scn, "use_camera") + col.prop(scn, "use_lamp") col = row.column() col.operator("atom_pdb.button_reload") - col.prop(scn, "atom_pdb_number_atoms") + col.prop(scn, "number_atoms") row = box.row() row.operator("atom_pdb.button_distance") - row.prop(scn, "atom_pdb_distance") - + row.prop(scn, "distance") row = layout.row() row.label(text="Modify atom radii") - box = layout.box() row = box.row() row.label(text="All changes concern:") row = box.row() - row.prop(scn, "atom_pdb_radius_how") + row.prop(scn, "radius_how") row = box.row() row.label(text="1. Change type of radii") row = box.row() - row.prop(scn, "atom_pdb_radius_type") + row.prop(scn, "radius_type") row = box.row() row.label(text="2. Change atom radii in pm") row = box.row() - row.prop(scn, "atom_pdb_radius_pm_name") + row.prop(scn, "radius_pm_name") row = box.row() - row.prop(scn, "atom_pdb_radius_pm") + row.prop(scn, "radius_pm") row = box.row() row.label(text="3. Change atom radii by scale") row = box.row() col = row.column() - col.prop(scn, "atom_pdb_radius_all") + col.prop(scn, "radius_all") col = row.column(align=True) col.operator( "atom_pdb.radius_all_bigger" ) col.operator( "atom_pdb.radius_all_smaller" ) @@ -177,124 +172,114 @@ class CLASS_atom_pdb_panel(Panel): row.operator( "atom_pdb.separate_atom" ) -class CLASS_atom_pdb_IO(bpy.types.PropertyGroup): +# The properties (gadgets) in the panel. They all go to scene +# during initialization (see end) +class CLASS_atom_pdb_Properties(bpy.types.PropertyGroup): def Callback_radius_type(self, context): - scnn = bpy.context.scene + scn = bpy.context.scene.atom_pdb[0] import_pdb.DEF_atom_pdb_radius_type( - scnn.atom_pdb_radius_type, - scnn.atom_pdb_radius_how, - ) + scn.radius_type, + scn.radius_how,) def Callback_radius_pm(self, context): - scnn = bpy.context.scene + scn = bpy.context.scene.atom_pdb[0] import_pdb.DEF_atom_pdb_radius_pm( - scnn.atom_pdb_radius_pm_name, - scnn.atom_pdb_radius_pm, - scnn.atom_pdb_radius_how, - ) + scn.radius_pm_name, + scn.radius_pm, + scn.radius_how,) # In the file dialog window - Import - scn = bpy.types.Scene - scn.use_atom_pdb_cam = BoolProperty( + use_camera = BoolProperty( name="Camera", default=False, description="Do you need a camera?") - scn.use_atom_pdb_lamp = BoolProperty( + use_lamp = BoolProperty( name="Lamp", default=False, description = "Do you need a lamp?") - scn.use_atom_pdb_mesh = BoolProperty( + use_mesh = BoolProperty( name = "Mesh balls", default=False, description = "Use mesh balls instead of NURBS") - scn.atom_pdb_mesh_azimuth = IntProperty( - name = "Azimuth", default=32, min=0, + mesh_azimuth = IntProperty( + name = "Azimuth", default=32, min=1, description = "Number of sectors (azimuth)") - scn.atom_pdb_mesh_zenith = IntProperty( - name = "Zenith", default=32, min=0, + mesh_zenith = IntProperty( + name = "Zenith", default=32, min=1, description = "Number of sectors (zenith)") - scn.atom_pdb_scale_ballradius = FloatProperty( - name = "Balls", default=1.0, min=0.0, + scale_ballradius = FloatProperty( + name = "Balls", default=1.0, min=0.0001, description = "Scale factor for all atom radii") - scn.atom_pdb_scale_distances = FloatProperty ( - name = "Distances", default=1.0, min=0.0, + scale_distances = FloatProperty ( + name = "Distances", default=1.0, min=0.0001, description = "Scale factor for all distances") - scn.use_atom_pdb_center = BoolProperty( + use_center = BoolProperty( name = "Object to origin", default=True, description = "Put the object into the global origin") - scn.use_atom_pdb_sticks = BoolProperty( + use_sticks = BoolProperty( name="Use sticks", default=True, description="Do you want to display the sticks?") - scn.atom_pdb_sticks_sectors = IntProperty( - name = "Sector", default=20, min=0, + sticks_sectors = IntProperty( + name = "Sector", default=20, min=1, description="Number of sectors of a stick") - scn.atom_pdb_sticks_radius = FloatProperty( - name = "Radius", default=0.1, min=0.0, + sticks_radius = FloatProperty( + name = "Radius", default=0.1, min=0.0001, description ="Radius of a stick") - scn.atom_pdb_sticks_unit_length = FloatProperty( - name = "Unit", default=0.2, min=0, + sticks_unit_length = FloatProperty( + name = "Unit", default=0.2, min=0.0001, description = "Length of the unit of a stick in Angstrom") - scn.use_atom_pdb_sticks_color = BoolProperty( + use_sticks_color = BoolProperty( name="Color", default=True, description="The sticks appear in the color of the atoms") - scn.use_atom_pdb_sticks_smooth = BoolProperty( + use_sticks_smooth = BoolProperty( name="Smooth", default=False, description="The sticks are round (sectors are not visible)") - scn.use_atom_pdb_sticks_bonds = BoolProperty( + use_sticks_bonds = BoolProperty( name="Bonds", default=False, description="Show double and tripple bonds.") - scn.atom_pdb_sticks_dist = FloatProperty( + sticks_dist = FloatProperty( name="Distance", default = 1.1, min=1.0, max=3.0, description="Distance between sticks measured in stick diameter") - scn.atom_pdb_atomradius = EnumProperty( + atomradius = EnumProperty( name="Type of radius", description="Choose type of atom radius", items=(('0', "Pre-defined", "Use pre-defined radius"), ('1', "Atomic", "Use atomic radius"), ('2', "van der Waals", "Use van der Waals radius")), - default='0',) - - # In the file dialog window - Export - scn.atom_pdb_export_type = EnumProperty( - name="Type of Objects", - description="Choose type of objects", - items=(('0', "All", "Export all active objects"), - ('1', "Elements", "Export only those active objects which have a proper element name")), - default='1',) - + default='0',) # In the panel - scn.atom_pdb_datafile = StringProperty( + datafile = StringProperty( name = "", description="Path to your custom data file", maxlen = 256, default = "", subtype='FILE_PATH') - scn.atom_pdb_PDB_file = StringProperty( + PDB_file = StringProperty( name = "PDB file", default="", description = "Path of the PDB file") - scn.atom_pdb_number_atoms = StringProperty(name="", + number_atoms = StringProperty(name="", default="Number", description = "This output shows " "the number of atoms which have been loaded") - scn.atom_pdb_distance = StringProperty( + distance = StringProperty( name="", default="Distance (A)", description="Distance of 2 objects in Angstrom") - scn.atom_pdb_radius_how = EnumProperty( + radius_how = EnumProperty( name="", description="Which objects shall be modified?", items=(('ALL_ACTIVE',"all active objects", "in the current layer"), ('ALL_IN_LAYER',"all"," in active layer(s)")), default='ALL_ACTIVE',) - scn.atom_pdb_radius_type = EnumProperty( + radius_type = EnumProperty( name="Type", description="Which type of atom radii?", items=(('0',"predefined", "Use pre-defined radii"), ('1',"atomic", "Use atomic radii"), ('2',"van der Waals","Use van der Waals radii")), default='0',update=Callback_radius_type) - scn.atom_pdb_radius_pm_name = StringProperty( + radius_pm_name = StringProperty( name="", default="Atom name", description="Put in the name of the atom (e.g. Hydrogen)") - scn.atom_pdb_radius_pm = FloatProperty( - name="", default=100.0, min=0.0, + radius_pm = FloatProperty( + name="", default=100.0, min=0.01, description="Put in the radius of the atom (in pm)", update=Callback_radius_pm) - scn.atom_pdb_radius_all = FloatProperty( - name="Scale", default = 1.05, min=1.0, + radius_all = FloatProperty( + name="Scale", default = 1.05, min=1.0, max=5.0, description="Put in the scale factor") @@ -305,12 +290,12 @@ class CLASS_atom_pdb_datafile_apply(Operator): bl_description = "Use color and radii values stored in the custom file" def execute(self, context): - scn = bpy.context.scene + scn = bpy.context.scene.atom_pdb[0] - if scn.atom_pdb_datafile == "": + if scn.datafile == "": return {'FINISHED'} - import_pdb.DEF_atom_pdb_custom_datafile(scn.atom_pdb_datafile) + import_pdb.DEF_atom_pdb_custom_datafile(scn.datafile) # TODO, move this into 'import_pdb' and call the function for obj in bpy.context.selected_objects: @@ -338,7 +323,7 @@ class CLASS_atom_pdb_separate_atom(Operator): bl_description = "Separate the atom you have chosen" def execute(self, context): - scn = bpy.context.scene + scn = bpy.context.scene.atom_pdb[0] # Get first all important properties from the atom which the user # has chosen: location, color, scale @@ -365,7 +350,7 @@ class CLASS_atom_pdb_separate_atom(Operator): current_layers=bpy.context.scene.layers if "Vacancy" not in name: - if scn.use_atom_pdb_mesh == False: + if scn.use_mesh == False: bpy.ops.surface.primitive_nurbs_surface_sphere_add( view_align=False, enter_editmode=False, location=loc_vec+loc_obj_vec, @@ -373,8 +358,8 @@ class CLASS_atom_pdb_separate_atom(Operator): layers=current_layers) else: bpy.ops.mesh.primitive_uv_sphere_add( - segments=scn.atom_pdb_mesh_azimuth, - ring_count=scn.atom_pdb_mesh_zenith, + segments=scn.mesh_azimuth, + ring_count=scn.mesh_zenith, size=1, view_align=False, enter_editmode=False, location=loc_vec+loc_obj_vec, rotation=(0, 0, 0), @@ -410,7 +395,7 @@ class CLASS_atom_pdb_distance_button(Operator): bl_description = "Measure the distance between two objects (only in Object Mode)" def execute(self, context): - scn = bpy.context.scene + scn = bpy.context.scene.atom_pdb[0] dist = import_pdb.DEF_atom_pdb_distance() if dist != "N.A.": @@ -422,7 +407,7 @@ class CLASS_atom_pdb_distance_button(Operator): dist = dist + " A" # Put the distance into the string of the output field. - scn.atom_pdb_distance = dist + scn.distance = dist return {'FINISHED'} @@ -433,10 +418,10 @@ class CLASS_atom_pdb_radius_all_bigger_button(Operator): bl_description = "Increase the radii of the atoms" def execute(self, context): - scn = bpy.context.scene + scn = bpy.context.scene.atom_pdb[0] import_pdb.DEF_atom_pdb_radius_all( - scn.atom_pdb_radius_all, - scn.atom_pdb_radius_how, + scn.radius_all, + scn.radius_how, ) return {'FINISHED'} @@ -448,10 +433,10 @@ class CLASS_atom_pdb_radius_all_smaller_button(Operator): bl_description = "Decrease the radii of the atoms" def execute(self, context): - scn = bpy.context.scene + scn = bpy.context.scene.atom_pdb[0] import_pdb.DEF_atom_pdb_radius_all( - 1.0/scn.atom_pdb_radius_all, - scn.atom_pdb_radius_how, + 1.0/scn.radius_all, + scn.radius_how, ) return {'FINISHED'} @@ -465,12 +450,11 @@ class CLASS_atom_pdb_radius_sticks_button(Operator): def execute(self, context): global ATOM_PDB_ERROR - - scn = bpy.context.scene + scn = bpy.context.scene.atom_pdb[0] result = import_pdb.DEF_atom_pdb_radius_sticks( - scn.atom_pdb_sticks_radius * 0.9, - scn.atom_pdb_radius_how, + scn.sticks_radius * 0.9, + scn.radius_how, ) if result == False: @@ -487,154 +471,221 @@ class CLASS_atom_pdb_load_button(Operator): bl_description = "Load the structure again" def execute(self, context): - scn = bpy.context.scene - - azimuth = scn.atom_pdb_mesh_azimuth - zenith = scn.atom_pdb_mesh_zenith - bradius = scn.atom_pdb_scale_ballradius - bdistance = scn.atom_pdb_scale_distances - radiustype = scn.atom_pdb_atomradius - center = scn.use_atom_pdb_center - sticks = scn.use_atom_pdb_sticks - sticks_col = scn.use_atom_pdb_sticks_color - sticks_sm = scn.use_atom_pdb_sticks_smooth - ssector = scn.atom_pdb_sticks_sectors - sradius = scn.atom_pdb_sticks_radius - stick_bond = scn.use_atom_pdb_sticks_bonds - stick_dist = scn.atom_pdb_sticks_dist - stick_unit = scn.atom_pdb_sticks_unit_length - - cam = scn.use_atom_pdb_cam - lamp = scn.use_atom_pdb_lamp - mesh = scn.use_atom_pdb_mesh - datafile = scn.atom_pdb_datafile + scn = context.scene.atom_pdb[0] - # Execute main routine an other time ... from the panel atom_number = import_pdb.DEF_atom_pdb_main( - mesh, azimuth, zenith, bradius, radiustype, bdistance, - sticks, sticks_col, sticks_sm, stick_bond, stick_unit, - stick_dist, ssector, sradius, center, cam, lamp, datafile) - scn.atom_pdb_number_atoms = str(atom_number) + " atoms" + scn.use_mesh, + scn.mesh_azimuth, + scn.mesh_zenith, + scn.scale_ballradius, + scn.atomradius, + scn.scale_distances, + scn.use_sticks, + scn.use_sticks_color, + scn.use_sticks_smooth, + scn.use_sticks_bonds, + scn.sticks_unit_length, + scn.sticks_dist, + scn.sticks_sectors, + scn.sticks_radius, + scn.use_center, + scn.use_camera, + scn.use_lamp, + scn.datafile) + + scn.number_atoms = str(atom_number) + " atoms" return {'FINISHED'} -# This is the class for the file dialog. +# This is the class for the file dialog of the importer. class ImportPDB(Operator, ImportHelper): bl_idname = "import_mesh.pdb" bl_label = "Import Protein Data Bank(*.pdb)" + bl_options = {'PRESET', 'UNDO'} filename_ext = ".pdb" filter_glob = StringProperty(default="*.pdb", options={'HIDDEN'},) + use_camera = BoolProperty( + name="Camera", default=False, + description="Do you need a camera?") + use_lamp = BoolProperty( + name="Lamp", default=False, + description = "Do you need a lamp?") + use_mesh = BoolProperty( + name = "Mesh balls", default=False, + description = "Use mesh balls instead of NURBS") + mesh_azimuth = IntProperty( + name = "Azimuth", default=32, min=1, + description = "Number of sectors (azimuth)") + mesh_zenith = IntProperty( + name = "Zenith", default=32, min=1, + description = "Number of sectors (zenith)") + scale_ballradius = FloatProperty( + name = "Balls", default=1.0, min=0.0001, + description = "Scale factor for all atom radii") + scale_distances = FloatProperty ( + name = "Distances", default=1.0, min=0.0001, + description = "Scale factor for all distances") + use_center = BoolProperty( + name = "Object to origin", default=True, + description = "Put the object into the global origin") + use_sticks = BoolProperty( + name="Use sticks", default=True, + description="Do you want to display the sticks?") + sticks_sectors = IntProperty( + name = "Sector", default=20, min=1, + description="Number of sectors of a stick") + sticks_radius = FloatProperty( + name = "Radius", default=0.1, min=0.0001, + description ="Radius of a stick") + sticks_unit_length = FloatProperty( + name = "Unit", default=0.2, min=0.0001, + description = "Length of the unit of a stick in Angstrom") + use_sticks_color = BoolProperty( + name="Color", default=True, + description="The sticks appear in the color of the atoms") + use_sticks_smooth = BoolProperty( + name="Smooth", default=False, + description="The sticks are round (sectors are not visible)") + use_sticks_bonds = BoolProperty( + name="Bonds", default=False, + description="Show double and tripple bonds.") + sticks_dist = FloatProperty( + name="Distance", default = 1.1, min=1.0, max=3.0, + description="Distance between sticks measured in stick diameter") + atomradius = EnumProperty( + name="Type of radius", + description="Choose type of atom radius", + items=(('0', "Pre-defined", "Use pre-defined radius"), + ('1', "Atomic", "Use atomic radius"), + ('2', "van der Waals", "Use van der Waals radius")), + default='0',) + datafile = StringProperty( + name = "", description="Path to your custom data file", + maxlen = 256, default = "", subtype='FILE_PATH') + def draw(self, context): layout = self.layout - scn = bpy.context.scene - row = layout.row() - row.prop(scn, "use_atom_pdb_cam") - row.prop(scn, "use_atom_pdb_lamp") + row.prop(self, "use_camera") + row.prop(self, "use_lamp") row = layout.row() col = row.column() - col.prop(scn, "use_atom_pdb_mesh") + col.prop(self, "use_mesh") col = row.column(align=True) - col.active = scn.use_atom_pdb_mesh - col.prop(scn, "atom_pdb_mesh_azimuth") - col.prop(scn, "atom_pdb_mesh_zenith") - + col.active = self.use_mesh + col.prop(self, "mesh_azimuth") + col.prop(self, "mesh_zenith") row = layout.row() col = row.column() col.label(text="Scaling factors") col = row.column(align=True) - col.prop(scn, "atom_pdb_scale_ballradius") - col.prop(scn, "atom_pdb_scale_distances") + col.prop(self, "scale_ballradius") + col.prop(self, "scale_distances") row = layout.row() col = row.column() - col.prop(scn, "use_atom_pdb_sticks") + col.prop(self, "use_sticks") row = layout.row() - row.active = scn.use_atom_pdb_sticks + row.active = self.use_sticks col = row.column() - col.prop(scn, "atom_pdb_sticks_sectors") - col.prop(scn, "atom_pdb_sticks_radius") - col.prop(scn, "atom_pdb_sticks_unit_length") + col.prop(self, "sticks_sectors") + col.prop(self, "sticks_radius") + col.prop(self, "sticks_unit_length") col = row.column(align=True) - col.prop(scn, "use_atom_pdb_sticks_color") - col.prop(scn, "use_atom_pdb_sticks_smooth") - col.prop(scn, "use_atom_pdb_sticks_bonds") + col.prop(self, "use_sticks_color") + col.prop(self, "use_sticks_smooth") + col.prop(self, "use_sticks_bonds") row = layout.row() - row.active = scn.use_atom_pdb_sticks + row.active = self.use_sticks col = row.column(align=True) col = row.column(align=True) - col.active = scn.use_atom_pdb_sticks and scn.use_atom_pdb_sticks_bonds - col.prop(scn, "atom_pdb_sticks_dist") - + col.active = self.use_sticks and self.use_sticks_bonds + col.prop(self, "sticks_dist") row = layout.row() - row.prop(scn, "use_atom_pdb_center") - + row.prop(self, "use_center") row = layout.row() - row.prop(scn, "atom_pdb_atomradius") + row.prop(self, "atomradius") def execute(self, context): - scn = bpy.context.scene - # This is in order to solve this strange 'relative path' thing. import_pdb.ATOM_PDB_FILEPATH = bpy.path.abspath(self.filepath) - scn.atom_pdb_PDB_file = import_pdb.ATOM_PDB_FILEPATH - - azimuth = scn.atom_pdb_mesh_azimuth - zenith = scn.atom_pdb_mesh_zenith - bradius = scn.atom_pdb_scale_ballradius - bdistance = scn.atom_pdb_scale_distances - radiustype = scn.atom_pdb_atomradius - center = scn.use_atom_pdb_center - sticks = scn.use_atom_pdb_sticks - sticks_col = scn.use_atom_pdb_sticks_color - sticks_sm = scn.use_atom_pdb_sticks_smooth - ssector = scn.atom_pdb_sticks_sectors - sradius = scn.atom_pdb_sticks_radius - stick_bond = scn.use_atom_pdb_sticks_bonds - stick_dist = scn.atom_pdb_sticks_dist - stick_unit = scn.atom_pdb_sticks_unit_length - - cam = scn.use_atom_pdb_cam - lamp = scn.use_atom_pdb_lamp - mesh = scn.use_atom_pdb_mesh - datafile = scn.atom_pdb_datafile - - # Execute main routine + # Execute main routine atom_number = import_pdb.DEF_atom_pdb_main( - mesh, azimuth, zenith, bradius, radiustype, bdistance, - sticks, sticks_col, sticks_sm, stick_bond, stick_unit, - stick_dist, ssector, sradius, center, cam, lamp, datafile) - - scn.atom_pdb_number_atoms = str(atom_number) + " atoms" + self.use_mesh, + self.mesh_azimuth, + self.mesh_zenith, + self.scale_ballradius, + self.atomradius, + self.scale_distances, + self.use_sticks, + self.use_sticks_color, + self.use_sticks_smooth, + self.use_sticks_bonds, + self.sticks_unit_length, + self.sticks_dist, + self.sticks_sectors, + self.sticks_radius, + self.use_center, + self.use_camera, + self.use_lamp, + self.datafile) + + # Copy the whole bunch of values into the property collection. + scn = context.scene.atom_pdb[0] + scn.use_mesh = self.use_mesh + scn.mesh_azimuth = self.mesh_azimuth + scn.mesh_zenith = self.mesh_zenith + scn.scale_ballradius = self.scale_ballradius + scn.atomradius = self.atomradius + scn.scale_distances = self.scale_distances + scn.use_sticks = self.use_sticks + scn.use_sticks_color = self.use_sticks_color + scn.use_sticks_smooth = self.use_sticks_smooth + scn.use_sticks_bonds = self.use_sticks_bonds + scn.sticks_unit_length = self.sticks_unit_length + scn.sticks_dist = self.sticks_dist + scn.sticks_sectors = self.sticks_sectors + scn.sticks_radius = self.sticks_radius + scn.use_center = self.use_center + scn.use_camera = self.use_camera + scn.use_lamp = self.use_lamp + scn.datafile = self.datafile + + scn.number_atoms = str(atom_number) + " atoms" + scn.PDB_file = import_pdb.ATOM_PDB_FILEPATH return {'FINISHED'} -# This is the class for the file dialog. +# This is the class for the file dialog of the exporter. class ExportPDB(Operator, ExportHelper): bl_idname = "export_mesh.pdb" bl_label = "Export Protein Data Bank(*.pdb)" - filename_ext = ".pdb" - filter_glob = StringProperty(default="*.pdb", options={'HIDDEN'},) + + filter_glob = StringProperty( + default="*.pdb", options={'HIDDEN'},) + + atom_pdb_export_type = EnumProperty( + name="Type of Objects", + description="Choose type of objects", + items=(('0', "All", "Export all active objects"), + ('1', "Elements", "Export only those active objects which have a proper element name")), + default='1',) def draw(self, context): layout = self.layout - scn = bpy.context.scene - row = layout.row() - row.prop(scn, "atom_pdb_export_type") + row.prop(self, "atom_pdb_export_type") def execute(self, context): - scn = bpy.context.scene - # This is in order to solve this strange 'relative path' thing. export_pdb.ATOM_PDB_FILEPATH = bpy.path.abspath(self.filepath) - export_pdb.DEF_atom_pdb_export(scn.atom_pdb_export_type) + export_pdb.DEF_atom_pdb_export(self.atom_pdb_export_type) return {'FINISHED'} @@ -668,7 +719,9 @@ def register(): bpy.utils.register_module(__name__) bpy.types.INFO_MT_file_import.append(menu_func_import) bpy.types.INFO_MT_file_export.append(menu_func_export) - + bpy.types.Scene.atom_pdb = bpy.props.CollectionProperty(type=CLASS_atom_pdb_Properties) + bpy.context.scene.atom_pdb.add() + def unregister(): bpy.utils.unregister_module(__name__) bpy.types.INFO_MT_file_import.remove(menu_func_import) diff --git a/io_mesh_pdb/export_pdb.py b/io_mesh_pdb/export_pdb.py index eadeb6c89..04b79fc5e 100644 --- a/io_mesh_pdb/export_pdb.py +++ b/io_mesh_pdb/export_pdb.py @@ -25,7 +25,7 @@ # # Start of project : 2011-08-31 by Clemens Barth # First publication in Blender : 2011-11-11 -# Last modified : 2012-03-09 +# Last modified : 2012-03-21 # # Acknowledgements: Thanks to ideasman, meta_androcto, truman, kilon, # dairin0d, PKHG, Valter, etc diff --git a/io_mesh_pdb/import_pdb.py b/io_mesh_pdb/import_pdb.py index 45d858bf5..0db76e92c 100644 --- a/io_mesh_pdb/import_pdb.py +++ b/io_mesh_pdb/import_pdb.py @@ -25,7 +25,7 @@ # # Start of project : 2011-08-31 by Clemens Barth # First publication in Blender : 2011-11-11 -# Last modified : 2012-03-09 +# Last modified : 2012-03-21 # # Acknowledgements: Thanks to ideasman, meta_androcto, truman, kilon, # dairin0d, PKHG, Valter, etc -- GitLab