[Bf-extensions-cvs] SVN commit: /data/svn/bf-extensions [2682] contrib/py/scripts/addons/ io_import_pdb_atomic_blender.py:
Clemens Barth
barth at root-1.de
Tue Nov 29 23:04:57 CET 2011
Revision: 2682
http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-extensions&revision=2682
Author: blendphys
Date: 2011-11-29 22:04:54 +0000 (Tue, 29 Nov 2011)
Log Message:
-----------
Dear all.
- A PDB structure is loaded now immediately.
- The latter change asked for some changes in the handling of the custom
data file
- After a structure is loaded the structure is automatically selected and
active.
- Many blank lines were removed.
Cheers,
Blendphys.
Modified Paths:
--------------
contrib/py/scripts/addons/io_import_pdb_atomic_blender.py
Modified: contrib/py/scripts/addons/io_import_pdb_atomic_blender.py
===================================================================
--- contrib/py/scripts/addons/io_import_pdb_atomic_blender.py 2011-11-29 16:24:08 UTC (rev 2681)
+++ contrib/py/scripts/addons/io_import_pdb_atomic_blender.py 2011-11-29 22:04:54 UTC (rev 2682)
@@ -60,7 +60,6 @@
IntProperty,
FloatProperty)
-
# These are variables, which contain the name of the PDB file and
# the path of the PDB file.
# They are used almost everywhere, which is the reason why they
@@ -194,10 +193,11 @@
]
ATOM_PDB_ELEMENTS_NUMBER = 106
-
-
-
+# A list of ALL objects which are loaded (needed for selected the loaded
+# structure.
+LOADED_STRUCTURE = []
+
# The panel, which is loaded after the file has been
# chosen via the menu 'File -> Import'
class CLASS_atom_pdb_panel(bpy.types.Panel):
@@ -237,24 +237,59 @@
scn = bpy.context.scene
row = layout.row()
- row.prop(scn, "atom_pdb_datafile")
+ row.label(text="Custom data file")
row = layout.row()
+ col = row.column()
+ col.prop(scn, "atom_pdb_datafile")
+ col.operator("atom_pdb.datafile_apply")
+ row = layout.row()
col = row.column(align=True)
col.prop(scn, "atom_pdb_PDB_filename")
col.prop(scn, "atom_pdb_PDB_file")
+
+
+
+
layout.separator()
+
+ row = layout.row()
+ col = row.column(align=True)
+ col.prop(scn, "use_atom_pdb_mesh")
+ col.prop(scn, "atom_pdb_mesh_azimuth")
+ col.prop(scn, "atom_pdb_mesh_zenith")
+
+
+ col = row.column(align=True)
+ col.label(text="Scaling factors")
+ col.prop(scn, "atom_pdb_scale_ballradius")
+ col.prop(scn, "atom_pdb_scale_distances")
+ row = layout.row()
+ col = row.column()
+ col.prop(scn, "use_atom_pdb_sticks")
+ col = row.column(align=True)
+ col.prop(scn, "atom_pdb_sticks_sectors")
+ col.prop(scn, "atom_pdb_sticks_radius")
+
+ row = layout.row()
+ row.prop(scn, "use_atom_pdb_center")
+
+
+
+
+
+
row = layout.row()
col = row.column()
col.prop(scn, "use_atom_pdb_cam")
col.prop(scn, "use_atom_pdb_lamp")
col = row.column()
- col.operator( "atom_pdb.button_start" )
+ col.operator("atom_pdb.button_reload")
col.prop(scn, "atom_pdb_number_atoms")
layout.separator()
row = layout.row()
- row.operator( "atom_pdb.button_distance")
+ row.operator("atom_pdb.button_distance")
row.prop(scn, "atom_pdb_distance")
layout.separator()
@@ -303,10 +338,15 @@
DEF_atom_pdb_radius_pm(scnn.atom_pdb_radius_pm_name,
scnn.atom_pdb_radius_pm,
scnn.atom_pdb_radius_how)
-
-
+
# In the file dialog window
scn = bpy.types.Scene
+ scn.use_atom_pdb_cam = BoolProperty(
+ name="Camera", default=False,
+ description="Do you need a camera?")
+ scn.use_atom_pdb_lamp = BoolProperty(
+ name="Lamp", default=False,
+ description = "Do you need a lamp?")
scn.use_atom_pdb_mesh = BoolProperty(
name = "Mesh balls", default=False,
description = "Do you want to use mesh balls instead of NURBS?")
@@ -326,12 +366,6 @@
name = "Object to origin", default=True,
description = "Shall the object first put into the global origin "
"before applying the offsets on the left?")
- scn.atom_pdb_offset_x = FloatProperty(
- name="X", default=0.0, description="Offset in X")
- scn.atom_pdb_offset_y = FloatProperty(
- name="Y", default=0.0, description="Offset in Y")
- scn.atom_pdb_offset_z = FloatProperty(
- name="Z", default=0.0, description="Offset in Z")
scn.use_atom_pdb_sticks = BoolProperty(
name="Use sticks", default=False,
description="Do you want to display also the sticks?")
@@ -351,7 +385,7 @@
# In the panel
scn.atom_pdb_datafile = StringProperty(
- name = "Custom datfile", description="Path to your custom data file",
+ name = "", description="Path to your custom data file",
maxlen = 256, default = "", subtype='FILE_PATH')
scn.atom_pdb_PDB_filename = StringProperty(
name = "File name", default="",
@@ -359,12 +393,6 @@
scn.atom_pdb_PDB_file = StringProperty(
name = "Path to file", default="",
description = "Path of the PDB file")
- scn.use_atom_pdb_cam = BoolProperty(
- name="Camera", default=False,
- description="Do you need a camera?")
- scn.use_atom_pdb_lamp = BoolProperty(
- name="Lamp", default=False,
- description = "Do you need a lamp?")
scn.atom_pdb_number_atoms = StringProperty(name="",
default="Number", description = "This output shows "
"the number of atoms which have been loaded")
@@ -396,10 +424,43 @@
description="Put in the scale factor")
+
+# Button loading a custom data file
+class CLASS_atom_pdb_datafile_apply(bpy.types.Operator):
+ bl_idname = "atom_pdb.datafile_apply"
+ bl_label = "Apply"
+ bl_description = "Use color and radii values stored in a custom file."
-
-
-
+ def execute(self, context):
+ scn = bpy.context.scene
+
+ if scn.atom_pdb_datafile == "":
+ return {'FINISHED'}
+
+ DEF_atom_pdb_custom_datafile(scn.atom_pdb_datafile)
+
+ for obj in bpy.context.selected_objects:
+ if len(obj.children) != 0:
+ child = obj.children[0]
+ if child.type == "SURFACE" or child.type == "MESH":
+ for element in ATOM_PDB_ELEMENTS:
+ if element[1] in obj.name:
+ child.scale = (element[4],
+ element[4],
+ element[4])
+ child.active_material.diffuse_color = element[3]
+ else:
+ if obj.type == "SURFACE" or obj.type == "MESH":
+ for element in ATOM_PDB_ELEMENTS:
+ if element[1] in obj.name:
+ obj.scale = (element[4],
+ element[4],
+ element[4])
+ obj.active_material.diffuse_color = element[3]
+
+ return {'FINISHED'}
+
+
# Button for measuring the distance of the active objects
class CLASS_atom_pdb_separate_atom(bpy.types.Operator):
bl_idname = "atom_pdb.separate_atom"
@@ -429,8 +490,7 @@
bpy.ops.object.select_all(action='DESELECT')
new_object.select = True
bpy.ops.object.delete()
-
-
+
# Create a new atom/vacancy at the position of the old atom
current_layers=bpy.context.scene.layers
@@ -456,7 +516,6 @@
rotation=(0.0, 0.0, 0.0),
layers=current_layers)
-
new_atom = bpy.context.scene.objects.active
# Scale, material and name it.
new_atom.scale = scale
@@ -490,7 +549,7 @@
# Remember: 1 Angstrom = 10^(-10) m
pos = str.find(dist, ".")
dist = dist[:pos+4]
- dist = dist + " Angstrom"
+ dist = dist + " A"
# Put the distance into the string of the output field.
scn.atom_pdb_distance = dist
@@ -504,7 +563,7 @@
bl_description = "Increase the radii of the atoms"
def execute(self, context):
- scn = bpy.context.scene
+ scn = bpy.context.scene
DEF_atom_pdb_radius_all(scn.atom_pdb_radius_all,
scn.atom_pdb_radius_how)
return {'FINISHED'}
@@ -517,17 +576,17 @@
bl_description = "Decrease the radii of the atoms"
def execute(self, context):
- scn = bpy.context.scene
+ scn = bpy.context.scene
DEF_atom_pdb_radius_all(1.0/scn.atom_pdb_radius_all,
scn.atom_pdb_radius_how)
return {'FINISHED'}
# The button for loading the atoms and creating the scene
-class CLASS_atom_pdb_start_button(bpy.types.Operator):
- bl_idname = "atom_pdb.button_start"
- bl_label = "DRAW ..."
- bl_description = "Start to load and draw the atoms and sticks"
+class CLASS_atom_pdb_load_button(bpy.types.Operator):
+ bl_idname = "atom_pdb.button_reload"
+ bl_label = "RELOAD"
+ bl_description = "Load the structure again"
def execute(self, context):
scn = bpy.context.scene
@@ -538,9 +597,6 @@
bdistance = scn.atom_pdb_scale_distances
radiustype = scn.atom_pdb_atomradius
center = scn.use_atom_pdb_center
- offset_vec = Vector((scn.atom_pdb_offset_x,
- scn.atom_pdb_offset_y,
- scn.atom_pdb_offset_z))
sticks = scn.use_atom_pdb_sticks
ssector = scn.atom_pdb_sticks_sectors
sradius = scn.atom_pdb_sticks_radius
@@ -549,14 +605,22 @@
mesh = scn.use_atom_pdb_mesh
datafile = scn.atom_pdb_datafile
+ # Execute main routine an other time ... from the panel
atom_number = DEF_atom_pdb_main(mesh,azimuth,zenith,bradius,
- radiustype,bdistance,offset_vec,sticks,
+ radiustype,bdistance,sticks,
ssector,sradius,center,cam,lamp,datafile)
scn.atom_pdb_number_atoms = str(atom_number) + " atoms"
+
+ # Select all loaded objects
+ bpy.ops.object.select_all(action='DESELECT')
+ for obj in LOADED_STRUCTURE:
@@ Diff output truncated at 10240 characters. @@
More information about the Bf-extensions-cvs
mailing list