[Bf-extensions-cvs] SVN commit: /data/svn/bf-extensions [2808] trunk/py/scripts/addons/ io_mesh_pdb:
Clemens Barth
barth at root-1.de
Mon Dec 26 09:14:36 CET 2011
Revision: 2808
http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-extensions&revision=2808
Author: blendphys
Date: 2011-12-26 08:14:24 +0000 (Mon, 26 Dec 2011)
Log Message:
-----------
Dear all.
1. New option: sticks connecting atoms can have now the color of the atoms.
2. New button in the panel: 'Show sticks' scales the atom radii such that only
the sticks are visible.
3. A bug was removed: Scaling atoms with a specific name scaled also the sticks.
This does not happen anymore.
- Due to the changes, the script has version 1.1
- To be done: Update of both Wiki pages (next days)
- Probably, I commit a 2nd time today.
Merry Christams,
Blendphys
Modified Paths:
--------------
trunk/py/scripts/addons/io_mesh_pdb/__init__.py
trunk/py/scripts/addons/io_mesh_pdb/import_pdb.py
Modified: trunk/py/scripts/addons/io_mesh_pdb/__init__.py
===================================================================
--- trunk/py/scripts/addons/io_mesh_pdb/__init__.py 2011-12-24 07:56:06 UTC (rev 2807)
+++ trunk/py/scripts/addons/io_mesh_pdb/__init__.py 2011-12-26 08:14:24 UTC (rev 2808)
@@ -20,7 +20,7 @@
"name": "PDB Atomic Blender",
"description": "Loading and manipulating atoms from PDB files",
"author": "Clemens Barth",
- "version": (1,0),
+ "version": (1,1),
"blender": (2,6),
"api": 31236,
"location": "File -> Import -> PDB (.pdb), Panel: View 3D - Tools",
@@ -119,6 +119,7 @@
col = row.column(align=True)
col.prop(scn, "atom_pdb_sticks_sectors")
col.prop(scn, "atom_pdb_sticks_radius")
+ col.prop(scn, "use_atom_pdb_sticks_color")
row = box.row()
row.prop(scn, "use_atom_pdb_center")
row = box.row()
@@ -129,14 +130,14 @@
col.operator("atom_pdb.button_reload")
# TODO, use lanel() instead
col.prop(scn, "atom_pdb_number_atoms")
+ row = box.row()
+ row.operator("atom_pdb.button_distance")
+ row.prop(scn, "atom_pdb_distance")
row = layout.row()
row.label(text="Modify atom radii")
box = layout.box()
row = box.row()
- row.operator("atom_pdb.button_distance")
- row.prop(scn, "atom_pdb_distance")
- row = box.row()
row.label(text="All changes concern:")
row = box.row()
row.prop(scn, "atom_pdb_radius_how")
@@ -158,6 +159,11 @@
col = row.column(align=True)
col.operator( "atom_pdb.radius_all_bigger" )
col.operator( "atom_pdb.radius_all_smaller" )
+ row = box.row()
+ row.label(text="4. Show sticks only")
+ row = box.row()
+ col = row.column()
+ col.operator( "atom_pdb.radius_sticks" )
if bpy.context.mode == 'EDIT_MESH':
@@ -221,6 +227,9 @@
scn.atom_pdb_sticks_radius = FloatProperty(
name = "Radius", default=0.1, min=0.0,
description ="Radius of a stick")
+ scn.use_atom_pdb_sticks_color = BoolProperty(
+ name="Color of atoms", default=False,
+ description="Shall the sticks appear in the color of the atoms?")
scn.atom_pdb_atomradius = EnumProperty(
name="Type of radius",
description="Choose type of atom radius",
@@ -301,7 +310,7 @@
return {'FINISHED'}
-# Button for measuring the distance of the active objects
+# Button for separating single objects from a atom mesh
class CLASS_atom_pdb_separate_atom(Operator):
bl_idname = "atom_pdb.separate_atom"
bl_label = "Separate atom"
@@ -426,7 +435,23 @@
return {'FINISHED'}
-# The button for loading the atoms and creating the scene
+# Button for showing the sticks only - the radii of the atoms have the radius
+# of the sticks
+class CLASS_atom_pdb_radius_sticks_button(Operator):
+ bl_idname = "atom_pdb.radius_sticks"
+ bl_label = "Show sticks"
+ bl_description = "Show only the sticks (atom radii = stick radii)"
+
+ def execute(self, context):
+ scn = bpy.context.scene
+ import_pdb.DEF_atom_pdb_radius_sticks(
+ scn.atom_pdb_sticks_radius,
+ scn.atom_pdb_radius_how,
+ )
+ return {'FINISHED'}
+
+
+# The button for reloading the atoms and creating the scene
class CLASS_atom_pdb_load_button(Operator):
bl_idname = "atom_pdb.button_reload"
bl_label = "RELOAD"
@@ -442,6 +467,7 @@
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
ssector = scn.atom_pdb_sticks_sectors
sradius = scn.atom_pdb_sticks_radius
cam = scn.use_atom_pdb_cam
@@ -452,7 +478,7 @@
# Execute main routine an other time ... from the panel
atom_number = import_pdb.DEF_atom_pdb_main(
mesh, azimuth, zenith, bradius,
- radiustype, bdistance, sticks,
+ radiustype, bdistance, sticks, sticks_col,
ssector, sradius, center, cam, lamp, datafile,
)
scn.atom_pdb_number_atoms = str(atom_number) + " atoms"
@@ -494,6 +520,7 @@
col = row.column(align=True)
col.prop(scn, "atom_pdb_sticks_sectors")
col.prop(scn, "atom_pdb_sticks_radius")
+ col.prop(scn, "use_atom_pdb_sticks_color")
row = layout.row()
row.prop(scn, "use_atom_pdb_center")
@@ -516,6 +543,7 @@
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
ssector = scn.atom_pdb_sticks_sectors
sradius = scn.atom_pdb_sticks_radius
cam = scn.use_atom_pdb_cam
@@ -526,7 +554,7 @@
# Execute main routine
atom_number = import_pdb.DEF_atom_pdb_main(
mesh, azimuth, zenith, bradius,
- radiustype, bdistance, sticks,
+ radiustype, bdistance, sticks, sticks_col,
ssector, sradius, center, cam, lamp, datafile)
scn.atom_pdb_number_atoms = str(atom_number) + " atoms"
Modified: trunk/py/scripts/addons/io_mesh_pdb/import_pdb.py
===================================================================
--- trunk/py/scripts/addons/io_mesh_pdb/import_pdb.py 2011-12-24 07:56:06 UTC (rev 2807)
+++ trunk/py/scripts/addons/io_mesh_pdb/import_pdb.py 2011-12-26 08:14:24 UTC (rev 2808)
@@ -25,7 +25,7 @@
#
# Start of project : 2011-08-31 by Clemens Barth
# First publication in Blender : 2011-11-11
-# Last modified : 2011-12-22
+# Last modified : 2011-12-26
#
# Acknowledgements: Thanks to ideasman, meta_androcto, truman, kilon,
# dairin0d, PKHG, Valter, etc
@@ -284,8 +284,7 @@
return str(dv.length)
-# Routine to modify the radii via the type:
-# pre-defined, atomic or van der Waals
+# Routine to modify the radii via the type: predefined, atomic or van der Waals
# Explanations here are also valid for the next 3 DEFs.
def DEF_atom_pdb_radius_type(rtype,how):
@@ -351,22 +350,26 @@
if len(obj.children) != 0:
if obj.children[0].type == "SURFACE" or obj.children[0].type == "MESH":
if atomname in obj.name:
- obj.children[0].scale = (radius_pm/100,) * 3
+ if "Stick" not in obj.name:
+ obj.children[0].scale = (radius_pm/100,) * 3
else:
if obj.type == "SURFACE" or obj.type == "MESH":
if atomname in obj.name:
- obj.scale = (radius_pm/100,) * 3
+ if "Stick" not in obj.name:
+ obj.scale = (radius_pm/100,) * 3
if how == "ALL_ACTIVE":
for obj in bpy.context.selected_objects:
if len(obj.children) != 0:
if obj.children[0].type == "SURFACE" or obj.children[0].type == "MESH":
if atomname in obj.name:
- obj.children[0].scale = (radius_pm/100,) * 3
+ if "Stick" not in obj.name:
+ obj.children[0].scale = (radius_pm/100,) * 3
else:
if obj.type == "SURFACE" or obj.type == "MESH":
if atomname in obj.name:
- obj.scale = (radius_pm/100,) * 3
+ if "Stick" not in obj.name:
+ obj.scale = (radius_pm/100,) * 3
# Routine to scale the radii of all atoms
@@ -408,6 +411,47 @@
obj.scale *= scale
+# This routine downscales all atom radii onto the value of the stick radius
+# for showing the sticks.
+def DEF_atom_pdb_radius_sticks(radius, how):
+
+ if how == "ALL_IN_LAYER":
+
+ layers = []
+ for i in range(20):
+ if bpy.context.scene.layers[i] == True:
+ layers.append(i)
+
+ change_objects = []
+ for obj in bpy.context.scene.objects:
+ for layer in layers:
+ if obj.layers[layer] == True:
+ change_objects.append(obj)
+
+
+ for obj in change_objects:
+ if len(obj.children) != 0:
+ if obj.children[0].type == "SURFACE" or obj.children[0].type == "MESH":
+ if "Stick" not in obj.name:
+ obj.children[0].scale = (radius,) * 3
+ else:
+ if obj.type == "SURFACE" or obj.type == "MESH":
+ if "Stick" not in obj.name:
+ obj.scale = (radius,) * 3
+
+ if how == "ALL_ACTIVE":
+ for obj in bpy.context.selected_objects:
+ if len(obj.children) != 0:
+ if obj.children[0].type == "SURFACE" or obj.children[0].type == "MESH":
+ if "Stick" not in obj.name:
+ obj.children[0].scale = (radius,) * 3
+ else:
+ if obj.type == "SURFACE" or obj.type == "MESH":
+ if "Stick" not in obj.name:
+ obj.scale = (radius,) * 3
+
+
+
# This reads a custom data file.
def DEF_atom_pdb_custom_datafile(path_datafile):
@@ -476,7 +520,7 @@
def DEF_atom_pdb_main(use_mesh,Ball_azimuth,Ball_zenith,
Ball_radius_factor,radiustype,Ball_distance_factor,
- use_stick,Stick_sectors,Stick_diameter,put_to_center,
+ use_sticks,use_sticks_color,Stick_sectors,Stick_diameter,put_to_center,
use_camera,use_lamp,path_datafile):
# The list of all atoms as read from the PDB file.
@@ -1068,71 +1112,99 @@
# ------------------------------------------------------------------------
# DRAWING THE STICKS
+ if use_sticks == True and all_sticks != []:
+
+ dl = 0.05
+
+ if use_sticks_color == False:
+ bpy.ops.object.material_slot_add()
+ stick_material = bpy.data.materials.new(ATOM_PDB_ELEMENTS[-1].name)
+ stick_material.diffuse_color = ATOM_PDB_ELEMENTS[-1].color
@@ Diff output truncated at 10240 characters. @@
More information about the Bf-extensions-cvs
mailing list