[Bf-extensions-cvs] SVN commit: /data/svn/bf-extensions [3168] trunk/py/scripts/addons/ io_mesh_pdb:

Clemens Barth barth at root-1.de
Fri Mar 23 21:34:56 CET 2012


Revision: 3168
          http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-extensions&revision=3168
Author:   blendphys
Date:     2012-03-23 20:34:45 +0000 (Fri, 23 Mar 2012)
Log Message:
-----------

- Option 'smooth' permits now a better 'polishing' of the sticks.

- The default value for the precision of the sticks (unit length)
  has been put from 0.2 onto 0.05. If the sticks are shown, they do not 
  overlapp anymore.

- Code cleaning

- Due to the recent large changes of the code the addon has been tested 
  with even more PDB files.
  
  
Blendphys 

PS: see recent comment here: http://blenderartists.org/forum/showthread.php?235003-Atomic-Blender-for-loading-PDB-files-into-Blender-2.5&p=2079416&viewfull=1#post2079416

Modified Paths:
--------------
    trunk/py/scripts/addons/io_mesh_pdb/__init__.py
    trunk/py/scripts/addons/io_mesh_pdb/export_pdb.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	2012-03-23 19:04:44 UTC (rev 3167)
+++ trunk/py/scripts/addons/io_mesh_pdb/__init__.py	2012-03-23 20:34:45 UTC (rev 3168)
@@ -42,12 +42,9 @@
                        IntProperty,
                        FloatProperty)
 
-
-# TODO, allow reload
 from . import import_pdb
 from . import export_pdb
 
-
 ATOM_PDB_ERROR = ""
 ATOM_PDB_PANEL = ""
 
@@ -230,7 +227,7 @@
         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,
+        name = "Unit", default=0.05, min=0.0001,
         description = "Length of the unit of a stick in Angstrom")        
     use_sticks_color = BoolProperty(
         name="Color", default=True,
@@ -303,22 +300,6 @@
 
         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:
-            if len(obj.children) != 0:
-                child = obj.children[0]
-                if child.type == "SURFACE" or child.type  == "MESH":
-                    for element in import_pdb.ATOM_PDB_ELEMENTS:
-                        if element.name in obj.name:
-                            child.scale = (element.radii[0],) * 3
-                            child.active_material.diffuse_color = element.color
-            else:
-                if obj.type == "SURFACE" or obj.type == "MESH":
-                    for element in import_pdb.ATOM_PDB_ELEMENTS:
-                        if element.name in obj.name:
-                            obj.scale = (element.radii[0],) * 3
-                            obj.active_material.diffuse_color = element.color
-
         return {'FINISHED'}
 
 
@@ -350,7 +331,7 @@
         # ... delete the new mesh including the separated vertex
         bpy.ops.object.select_all(action='DESELECT')
         new_object.select = True
-        bpy.ops.object.delete()  # TODO, use scene.objects.unlink()
+        bpy.ops.object.delete()  
 
         # Create a new atom/vacancy at the position of the old atom
         current_layers=bpy.context.scene.layers
@@ -426,8 +407,7 @@
         scn = bpy.context.scene.atom_pdb[0]
         import_pdb.DEF_atom_pdb_radius_all(
                 scn.radius_all,
-                scn.radius_how,
-                )
+                scn.radius_how,)
         return {'FINISHED'}
 
 
@@ -441,8 +421,7 @@
         scn = bpy.context.scene.atom_pdb[0]
         import_pdb.DEF_atom_pdb_radius_all(
                 1.0/scn.radius_all,
-                scn.radius_how,
-                )
+                scn.radius_how,)
         return {'FINISHED'}
 
 
@@ -458,9 +437,8 @@
         scn = bpy.context.scene.atom_pdb[0]
                 
         result = import_pdb.DEF_atom_pdb_radius_sticks(
-                     scn.sticks_radius * 0.9,
-                     scn.radius_how,)
-                     
+                     0.01,
+                     scn.radius_how,)  
         if result == False:
             ATOM_PDB_ERROR = "No sticks => no changes"
             bpy.ops.atom_pdb.error_dialog('INVOKE_DEFAULT')
@@ -606,7 +584,7 @@
         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,
+        name = "Unit", default=0.05, min=0.0001,
         description = "Length of the unit of a stick in Angstrom")        
     use_sticks_color = BoolProperty(
         name="Color", default=True,

Modified: trunk/py/scripts/addons/io_mesh_pdb/export_pdb.py
===================================================================
--- trunk/py/scripts/addons/io_mesh_pdb/export_pdb.py	2012-03-23 19:04:44 UTC (rev 3167)
+++ trunk/py/scripts/addons/io_mesh_pdb/export_pdb.py	2012-03-23 20:34:45 UTC (rev 3168)
@@ -25,7 +25,7 @@
 #
 #  Start of project              : 2011-08-31 by Clemens Barth
 #  First publication in Blender  : 2011-11-11
-#  Last modified                 : 2012-03-22
+#  Last modified                 : 2012-03-23
 #
 #  Acknowledgements: Thanks to ideasman, meta_androcto, truman, kilon,
 #  dairin0d, PKHG, Valter, etc
@@ -50,8 +50,6 @@
                      + "REMARK\n")
 
 
-
-
 class CLASS_atom_pdb_atoms_export(object):  
     __slots__ = ('element', 'location')
     def __init__(self, element, location):
@@ -59,8 +57,6 @@
         self.location = location
 
 
-
-
 def DEF_atom_pdb_export(obj_type):
 
     list_atoms = []
@@ -117,3 +113,4 @@
     pdb_file_p.close()
 
     return True
+

Modified: trunk/py/scripts/addons/io_mesh_pdb/import_pdb.py
===================================================================
--- trunk/py/scripts/addons/io_mesh_pdb/import_pdb.py	2012-03-23 19:04:44 UTC (rev 3167)
+++ trunk/py/scripts/addons/io_mesh_pdb/import_pdb.py	2012-03-23 20:34:45 UTC (rev 3168)
@@ -25,7 +25,7 @@
 #
 #  Start of project              : 2011-08-31 by Clemens Barth
 #  First publication in Blender  : 2011-11-11
-#  Last modified                 : 2012-03-22
+#  Last modified                 : 2012-03-23
 #
 #  Acknowledgements: Thanks to ideasman, meta_androcto, truman, kilon,
 #  dairin0d, PKHG, Valter, etc
@@ -216,22 +216,18 @@
         self.number = number
         self.dist = dist
 
-
 # -----------------------------------------------------------------------------
 #                                                          Some small routines
 
-
 # Routine which produces a cylinder. All is somewhat easy to undertsand.
 def DEF_atom_pdb_build_stick(radius, length, sectors):
 
-    vertices = []
-    faces    = []
-
     dphi = 2.0 * pi/(float(sectors)-1)
 
     # Vertices
     vertices_top    = [Vector((0,0,length / 2.0))]
     vertices_bottom = [Vector((0,0,-length / 2.0))]
+    vertices = []
     for i in range(sectors-1):
         x = radius * cos( dphi * i )
         y = radius * sin( dphi * i )
@@ -243,7 +239,16 @@
         vertices_bottom.append(vertex)
     vertices = vertices_top + vertices_bottom
 
+    # Side facets (Cylinder)
+    faces1 = []    
+    for i in range(sectors-1):
+        if i == sectors-2:
+            faces1.append(  [i+1, 1, 1+sectors, i+1+sectors] )
+        else:
+            faces1.append(  [i+1, i+2, i+2+sectors, i+1+sectors] )
+
     # Top facets
+    faces2 = []    
     for i in range(sectors-1):
         if i == sectors-2:
             face_top = [0,sectors-1,1]
@@ -254,28 +259,27 @@
             for j in range(2):
                 face_top.append(i+j+1)
                 face_bottom.append(i+j+1+sectors)
-        faces.append(face_top)
-        faces.append(face_bottom)
+        faces2.append(face_top)
+        faces2.append(face_bottom)
 
-    # Side facets
-    for i in range(sectors-1):
-        if i == sectors-2:
-            faces.append(  [i+1, 1, 1+sectors, i+1+sectors] )
-        else:
-            faces.append(  [i+1, i+2, i+2+sectors, i+1+sectors] )
-
-    # Build the mesh
+    # Build the mesh, Cylinder
     cylinder = bpy.data.meshes.new("Sticks_Cylinder")
-    cylinder.from_pydata(vertices, [], faces)
+    cylinder.from_pydata(vertices, [], faces1)
     cylinder.update()
     new_cylinder = bpy.data.objects.new("Sticks_Cylinder", cylinder)
     bpy.context.scene.objects.link(new_cylinder)
 
-    return new_cylinder
+    # Build the mesh, Cups
+    cups = bpy.data.meshes.new("Sticks_Cups")
+    cups.from_pydata(vertices, [], faces2)
+    cups.update()
+    new_cups = bpy.data.objects.new("Sticks_Cups", cups)
+    bpy.context.scene.objects.link(new_cups)
 
+    return (new_cylinder, new_cups)
 
-# This function measures the distance between two objects (atoms),
-# which are active.
+
+# This function measures the distance between two active objects (atoms).
 def DEF_atom_pdb_distance():
 
     if len(bpy.context.selected_bases) > 1:
@@ -495,7 +499,6 @@
 
     return True
 
-
 # -----------------------------------------------------------------------------
 #                                                         The custom data file
 
@@ -556,14 +559,27 @@
             ATOM_PDB_ELEMENTS.append(element)
 
     data_file_p.close()
-
+    
+    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.name in obj.name:
+                        child.scale = (element.radii[0],) * 3
+                        child.active_material.diffuse_color = element.color
+        else:
+            if obj.type == "SURFACE" or obj.type == "MESH":
+                for element in ATOM_PDB_ELEMENTS:
+                    if element.name in obj.name:
+                        obj.scale = (element.radii[0],) * 3
+                        obj.active_material.diffuse_color = element.color
+                        
     return True
 
-
 # -----------------------------------------------------------------------------
 #                                                            The main routine
 
-
 def DEF_atom_pdb_main(use_mesh,Ball_azimuth,Ball_zenith,
                Ball_radius_factor,radiustype,Ball_distance_factor,
                use_sticks,use_sticks_color,use_sticks_smooth,
@@ -602,11 +618,9 @@
                                      radii,radii_ionic)
         ATOM_PDB_ELEMENTS.append(li)
 
-
     # ------------------------------------------------------------------------
     # READING DATA OF ATOMS
 
-
     if DEF_atom_pdb_custom_datafile(path_datafile):
         print("Custom data file is loaded.")
 
@@ -738,11 +752,9 @@
     # From above it can be clearly seen that j is now the number of all atoms.
     Number_of_total_atoms = j
 
-
     # ------------------------------------------------------------------------
     # MATERIAL PROPERTIES FOR ATOMS
 
-
     # The list that contains info about all types of atoms is created
     # here. It is used for building the material properties for
     # instance (see below).
@@ -795,11 +807,9 @@
                 # The atom gets its properties.
                 atom.material = material
 
-
     # ------------------------------------------------------------------------
     # READING DATA OF STICKS
 
-
     # Open the PDB file again such that the file pointer is in the first

@@ Diff output truncated at 10240 characters. @@


More information about the Bf-extensions-cvs mailing list