[Bf-extensions-cvs] SVN commit: /data/svn/bf-extensions [2687] contrib/py/scripts/addons/ io_import_pdb_atomic_blender.py:

Clemens Barth barth at root-1.de
Wed Nov 30 16:04:00 CET 2011


Revision: 2687
          http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-extensions&revision=2687
Author:   blendphys
Date:     2011-11-30 15:03:56 +0000 (Wed, 30 Nov 2011)
Log Message:
-----------


Dear all.

The script uses now classes for 

   - elements
   - atoms
   - and sticks
   
With this the code has become more readable.



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-30 08:00:29 UTC (rev 2686)
+++ contrib/py/scripts/addons/io_import_pdb_atomic_blender.py	2011-11-30 15:03:56 UTC (rev 2687)
@@ -73,7 +73,12 @@
 ATOM_PDB_STRING = "Atomic Blender "+ATOM_PDB_VERSION+"\n==================="
 ATOM_PDB_PANELNAME = "PDB - Atomic Blender - v"+ATOM_PDB_VERSION
 
-# This is a list that contains some data of all possible atoms. The structure 
+
+# -----------------------------------------------------------------------------
+#                                                  Atom, stick and element data
+
+
+# This is a list that contains some data of all possible elements. The structure 
 # is as follows:
 #
 # 1, "Hydrogen", "H", [0.0,0.0,1.0], 0.32, 0.32, 0.32 , -1 , 1.54   means
@@ -82,8 +87,9 @@
 # 
 # charge state 1, radius (ionic) 1, charge state 2, radius (ionic) 2, ... all 
 # charge states for any atom are listed, if existing.
+# The list is fixed and cannot be changed ... (see below)
 
-ATOM_PDB_ELEMENTS = [
+ATOM_PDB_ELEMENTS_DEFAULT = (
 ( 1,      "Hydrogen",        "H", (  1.0,   1.0,   1.0), 0.32, 0.32, 0.79 , -1 , 1.54 ),
 ( 2,        "Helium",       "He", ( 0.85,   1.0,   1.0), 0.93, 0.93, 0.49 ),
 ( 3,       "Lithium",       "Li", (  0.8,  0.50,   1.0), 1.23, 1.23, 2.05 ,  1 , 0.68 ),
@@ -190,12 +196,53 @@
 (104,       "Vacancy",      "Vac", (  0.5,   0.5,   0.5), 1.00, 1.00, 1.00),
 (105,       "Default",  "Default", (  1.0,   1.0,   1.0), 1.00, 1.00, 1.00),
 (106,         "Stick",    "Stick", (  0.5,   0.5,   0.5), 1.00, 1.00, 1.00),
-]
+)
 
-# A list of ALL objects which are loaded (needed for selected the loaded
+# This list here contains all data of the elements and will be used during 
+# runtime. It is a list of classes. 
+# During executing Atomic Blender, the list will be initialized with the fixed
+# data from above via the class structure below (CLASS_atom_pdb_Elements). We
+# have then one fixed list (above), which will never be changed, and a list of
+# classes with same data. The latter can be modified via loading a separate 
+# custom data file.  
+ATOM_PDB_ELEMENTS = []
+
+# This is the class, which stores the properties for one element.
+class CLASS_atom_pdb_Elements:
+    def __init__(self, number, name,short_name, color, radii, radii_ionic):
+        self.number = number
+        self.name = name
+        self.short_name = short_name
+        self.color = color
+        self.radii = radii
+        self.radii_ionic = radii_ionic
+                 
+# This is the class, which stores the properties of one atom.      
+class CLASS_atom_pdb_atom:
+    def __init__(self, element, name, location, radius, color, material):
+        self.element = element
+        self.name = name
+        self.location = location
+        self.radius = radius
+        self.color = color
+        self.material = material
+        
+# This is the class, which stores the two atoms of one stick.      
+class CLASS_atom_pdb_stick:
+    def __init__(self, atom1, atom2):
+        self.atom1 = atom1
+        self.atom2 = atom2       
+
+
+# A list of ALL objects which are loaded (needed for selecting the loaded
 # structure. 
 LOADED_STRUCTURE = []
     
+
+# -----------------------------------------------------------------------------
+#                                                                           GUI
+    
+    
 # The panel, which is loaded after the file has been
 # chosen via the menu 'File -> Import'
 class CLASS_atom_pdb_panel(bpy.types.Panel):
@@ -245,10 +292,6 @@
         col.prop(scn, "atom_pdb_PDB_filename") 
         col.prop(scn, "atom_pdb_PDB_file")
 
-
-
-
-
         layout.separator()
         
         row = layout.row()  
@@ -271,12 +314,7 @@
 
         row = layout.row()           
         row.prop(scn, "use_atom_pdb_center")        
-       
-       
-       
-        
-        
-        
+          
         row = layout.row()        
         col = row.column()
         col.prop(scn, "use_atom_pdb_cam")
@@ -422,7 +460,6 @@
         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"
@@ -442,19 +479,19 @@
                 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] 
+                        if element.name in obj.name:
+                            child.scale = (element.radii[0],
+                                           element.radii[0],
+                                           element.radii[0])
+                            child.active_material.diffuse_color = element.color
             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]
+                            obj.scale = (element.radii[0],
+                                         element.radii[0],
+                                         element.radii[0])
+                            obj.active_material.diffuse_color = element.color
              
         return {'FINISHED'}   
         
@@ -619,6 +656,7 @@
 
         return {'FINISHED'}
 
+
 # This is the class for the file dialog.
 class CLASS_LoadPDB(bpy.types.Operator, ImportHelper):
     bl_idname = "import_pdb.pdb"
@@ -663,12 +701,27 @@
     def execute(self, context):   
         global ATOM_PDB_FILEPATH
         global ATOM_PDB_FILENAME
+        global ATOM_PDB_ELEMENTS_DEFAULT
+        global ATOM_PDB_ELEMENTS
       
+        # Initialize the element list
+        for item in ATOM_PDB_ELEMENTS_DEFAULT:
+        
+            # All three radii into a list
+            radii = [item[4],item[5],item[6]]
+            # The handling of the ionic radii will be done later. So far, it is an
+            # empty list.
+            radii_ionic = []  
+
+            li = CLASS_atom_pdb_Elements(item[0],item[1],item[2],item[3],
+                                         radii,radii_ionic)                                 
+            ATOM_PDB_ELEMENTS.append(li)
+     
         scn = bpy.context.scene
-        ATOM_PDB_FILEPATH     = self.filepath
-        ATOM_PDB_FILENAME     = os.path.basename(ATOM_PDB_FILEPATH)
+        ATOM_PDB_FILEPATH = self.filepath
+        ATOM_PDB_FILENAME = os.path.basename(ATOM_PDB_FILEPATH)
         scn.atom_pdb_PDB_filename = ATOM_PDB_FILENAME
-        scn.atom_pdb_PDB_file     = ATOM_PDB_FILEPATH
+        scn.atom_pdb_PDB_file = ATOM_PDB_FILEPATH
         
         azimuth    = scn.atom_pdb_mesh_azimuth
         zenith     = scn.atom_pdb_mesh_zenith 
@@ -695,7 +748,7 @@
         for obj in LOADED_STRUCTURE:
             obj.select = True
             bpy.context.scene.objects.active = obj
-        # Clean this list
+        # Clean the list which contains the last loaded structure
         LOADED_STRUCTURE[:] = []
         
         return {'FINISHED'}
@@ -705,6 +758,7 @@
 def menu_func(self, context):
     self.layout.operator(CLASS_LoadPDB.bl_idname, text="PDB (.pdb)")
 
+
 def register():
     bpy.utils.register_class(CLASS_atom_pdb_panel)
     bpy.utils.register_class(CLASS_atom_pdb_datafile_apply)
@@ -730,8 +784,9 @@
     bpy.types.INFO_MT_file_import.remove(menu_func)
         
 if __name__ == "__main__":
-
+ 
     register()
+    
 
 
 # -----------------------------------------------------------------------------
@@ -777,35 +832,36 @@
             if len(obj.children) != 0:
                 if obj.children[0].type == "SURFACE" or obj.children[0].type  == "MESH":
                     for element in ATOM_PDB_ELEMENTS:      
-                        if element[1] in obj.name:
-                            obj.children[0].scale = (element[4+int(rtype)],
-                                                     element[4+int(rtype)],
-                                                     element[4+int(rtype)])
+                        if element.name in obj.name:
+                            obj.children[0].scale = (element.radii[int(rtype)],
+                                                     element.radii[int(rtype)],
+                                                     element.radii[int(rtype)])
             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+int(rtype)],
-                                         element[4+int(rtype)],
-                                         element[4+int(rtype)])
+                        if element.name in obj.name:
+                            obj.scale = (element.radii[int(rtype)],
+                                         element.radii[int(rtype)],
+                                         element.radii[int(rtype)])
 
     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":
                     for element in ATOM_PDB_ELEMENTS:        
-                        if element[1] in obj.name:
-                            obj.children[0].scale = (element[4+int(rtype)],
-                                                     element[4+int(rtype)],
-                                                     element[4+int(rtype)])
+                        if element.name in obj.name:
+                            obj.children[0].scale = (element.radii[int(rtype)],
+                                                     element.radii[int(rtype)],

@@ Diff output truncated at 10240 characters. @@


More information about the Bf-extensions-cvs mailing list