I re-designed the code for replacing/separating atoms: one can now
authorClemens Barth <barth@root-1.de>
Wed, 23 Jan 2013 06:20:17 +0000 (06:20 +0000)
committerClemens Barth <barth@root-1.de>
Wed, 23 Jan 2013 06:20:17 +0000 (06:20 +0000)
independently choose the shape and material. I think that this is
much better.

Blendphys.

io_atomblend_utilities/__init__.py
io_atomblend_utilities/io_atomblend_utilities.py

index b2aec457595796a5bcfedaeae11553581b2e4bd2..667cc85492960c43a41299e8b7f6cf03c58c0be2 100644 (file)
@@ -24,7 +24,7 @@
 #
 #  Start of project              : 2011-12-01 by Clemens Barth
 #  First publication in Blender  : 2012-11-03
-#  Last modified                 : 2013-01-22
+#  Last modified                 : 2013-01-23
 #
 #  Acknowledgements 
 #  ================
@@ -119,10 +119,8 @@ class PreparePanel(Panel):
         col = box.column(align=True)
         col.label(text="Change atom shape")
         col.prop(scn, "replace_objs")
+        col.prop(scn, "replace_objs_material")
         col.operator("atom_blend.replace_atom")  
-
-        box = layout.box()
-        col = box.column(align=True)
         col.label(text="Default values")
         col.operator("atom_blend.default_atoms") 
 
@@ -131,7 +129,8 @@ class PreparePanel(Panel):
         col.label(text="Separate atoms")
         col2 = col.column()
         col2.active = (bpy.context.mode == 'EDIT_MESH')
-        col2.prop(scn, "draw_objs")
+        col2.prop(scn, "separate_objs")
+        col2.prop(scn, "separate_objs_material")        
         col2.operator("atom_blend.separate_atom")
         
 
@@ -173,29 +172,33 @@ class PanelProperties(bpy.types.PropertyGroup):
     replace_objs = EnumProperty(
         name="Shape",
         description="Choose a different shape.",
-        items=(('-1',"Unchanged", "Use again a ball"),
-               ('0a',"Sphere", "Replace with a sphere"),
-               ('0b',"Sphere (NURBS)", "Replace with a sphere (NURBS)"),        
-               ('1',"Cube", "Replace with a cube"),
-               ('2',"Plane", "Replace with a plane"),
-               ('3a',"Circle", "Replace with a circle"),
-               ('3b',"Circle (NURBS)", "Replace with a circle (NURBS)"),               
-               ('4a',"Icosphere 1", "Replace with a icosphere, subd=1"),  
-               ('4b',"Icosphere 2", "Replace with a icosphere, subd=2"),  
-               ('4c',"Icosphere 3", "Replace with a icosphere, subd=3"),                             
-               ('4d',"Icosphere 4", "Replace with a icosphere, subd=4"),                             
-               ('4e',"Icosphere 5", "Replace with a icosphere, subd=5"),                             
-               ('5a',"Cylinder", "Replace with a cylinder"),
-               ('5b',"Cylinder (NURBS)", "Replace with a cylinder (NURBS)"),               
-               ('6',"Cone", "Replace with a cone"),
-               ('7a',"Torus", "Replace with a torus"),
-               ('7b',"Torus (NURBS)", "Replace with a torus (NURBS)"),
-               ('8',"Transparent cube", "Replace with a transparent cube"),      
-               ('9',"Transparent sphere", "Replace with a transparent sphere"),
-               ('10',"Transparent sphere (NURBS)", 
-                                  "Replace with a transparent sphere (NURBS)"),               
-               ('11',"Halo cloud", "Replace with a halo cloud")),
-               default='-1',)          
+        items=(('0',"Unchanged", "Do not change the shape"),
+               ('1a',"Sphere (Mesh)", "Replace with a sphere (Mesh)"),
+               ('1b',"Sphere (NURBS)", "Replace with a sphere (NURBS)"),        
+               ('2',"Cube", "Replace with a cube"),
+               ('3',"Plane", "Replace with a plane"),
+               ('4a',"Circle (Mesh)", "Replace with a circle (Mesh)"),
+               ('4b',"Circle (NURBS)", "Replace with a circle (NURBS)"),               
+               ('5a',"Icosphere 1", "Replace with a icosphere, subd=1"),  
+               ('5b',"Icosphere 2", "Replace with a icosphere, subd=2"),  
+               ('5c',"Icosphere 3", "Replace with a icosphere, subd=3"),  
+               ('5d',"Icosphere 4", "Replace with a icosphere, subd=4"),
+               ('5e',"Icosphere 5", "Replace with a icosphere, subd=5"),                                                         
+               ('6a',"Cylinder (Mesh)", "Replace with a cylinder (Mesh)"),
+               ('6b',"Cylinder (NURBS)", "Replace with a cylinder (NURBS)"),               
+               ('7',"Cone", "Replace with a cone"),
+               ('8a',"Torus (Mesh)", "Replace with a torus (Mesh)"),
+               ('8b',"Torus (NURBS)", "Replace with a torus (NURBS)")),
+               default='0',)     
+    replace_objs_material = EnumProperty(
+        name="Material",
+        description="Choose a different material.",
+        items=(('0',"Unchanged", "Leave the material unchanged"),
+               ('1',"Normal", "Use normal material (no transparency and reflection)"),
+               ('2',"Transparent", "Use transparent material"),
+               ('3',"Reflecting", "Use reflecting material"),
+               ('4',"Transparent + reflecting", "Use transparent and reflecting material")),
+               default='0',)                           
     obj_who = EnumProperty(
         name="",
         description="Which objects shall be modified?",
@@ -240,31 +243,36 @@ class PanelProperties(bpy.types.PropertyGroup):
     sticks_all = FloatProperty(
         name="Scale", default = 1.05, min=1.0, max=5.0,
         description="Put in the scale factor")
-    draw_objs = EnumProperty(
+    separate_objs = EnumProperty(
         name="Shape",
         description="Choose a different shape.",
-        items=(('-1',"Unchanged", "Use again a ball"),
-               ('0a',"Sphere", "Replace with a sphere"),
-               ('0b',"Sphere (NURBS)", "Replace with a sphere (NURBS)"),        
-               ('1',"Cube", "Replace with a cube"),
-               ('2',"Plane", "Replace with a plane"),
-               ('3a',"Circle", "Replace with a circle"),
-               ('3b',"Circle (NURBS)", "Replace with a circle (NURBS)"),               
-               ('4a',"Icosphere 1", "Replace with a icosphere, subd=1"),  
-               ('4b',"Icosphere 2", "Replace with a icosphere, subd=2"),  
-               ('4c',"Icosphere 3", "Replace with a icosphere, subd=3"),                             
-               ('5a',"Cylinder", "Replace with a cylinder"),
-               ('5b',"Cylinder (NURBS)", "Replace with a cylinder (NURBS)"),               
-               ('6',"Cone", "Replace with a cone"),
-               ('7a',"Torus", "Replace with a torus"),
-               ('7b',"Torus (NURBS)", "Replace with a torus (NURBS)"),
-               ('8',"Transparent cube", "Replace with a transparent cube"),      
-               ('9',"Transparent sphere", "Replace with a transparent sphere"),
-               ('10',"Transparent sphere (NURBS)", 
-                                  "Replace with a transparent sphere (NURBS)"),               
-               ('11',"Halo cloud", "Replace with a halo cloud")),
-               default='-1',)     
-
+        items=(('0',"Unchanged", "Do not change the shape"),
+               ('1a',"Sphere (Mesh)", "Replace with a sphere (Mesh)"),
+               ('1b',"Sphere (NURBS)", "Replace with a sphere (NURBS)"),        
+               ('2',"Cube", "Replace with a cube"),
+               ('3',"Plane", "Replace with a plane"),
+               ('4a',"Circle (Mesh)", "Replace with a circle (Mesh)"),
+               ('4b',"Circle (NURBS)", "Replace with a circle (NURBS)"),               
+               ('5a',"Icosphere 1", "Replace with a icosphere, subd=1"),  
+               ('5b',"Icosphere 2", "Replace with a icosphere, subd=2"),  
+               ('5c',"Icosphere 3", "Replace with a icosphere, subd=3"),  
+               ('5d',"Icosphere 4", "Replace with a icosphere, subd=4"),
+               ('5e',"Icosphere 5", "Replace with a icosphere, subd=5"),                                                         
+               ('6a',"Cylinder (Mesh)", "Replace with a cylinder (Mesh)"),
+               ('6b',"Cylinder (NURBS)", "Replace with a cylinder (NURBS)"),               
+               ('7',"Cone", "Replace with a cone"),
+               ('8a',"Torus (Mesh)", "Replace with a torus (Mesh)"),
+               ('8b',"Torus (NURBS)", "Replace with a torus (NURBS)")),
+               default='0',)     
+    separate_objs_material = EnumProperty(
+        name="Material",
+        description="Choose a different material.",
+        items=(('0',"Unchanged", "Leave the material unchanged"),
+               ('1',"Normal", "Use normal material (no transparency and reflection)"),
+               ('2',"Transparent", "Use transparent material"),
+               ('3',"Reflecting", "Use reflecting material"),
+               ('4',"Transparent + reflecting", "Use transparent and reflecting material")),
+               default='0',)  
 
 # Button loading a custom data file
 class DatafileApply(Operator):
index 87a365df1a330c0e0f620e4267ea1687d60d3e0d..01519ef81414ba29443f0371a2c755739671fac9 100644 (file)
@@ -344,53 +344,53 @@ def modify_objects(action_type,
 
         scn = bpy.context.scene.atom_blend
         
-        # Copy all details from the object to be replaced.
-        name = obj.name
-        scale = Vector((0.0,0.0,0.0))
-        scale += obj.scale
-        material = obj.active_material
-        location = obj.location
-        parent = obj.parent       
+        new_material = draw_obj_material(scn.replace_objs_material, 
+                                         obj.active_material)
+        
+        # If the atom shape shall not be changed
+        if scn.replace_objs == '0':
+            obj.active_material = new_material 
+            if "_repl" not in obj.active_material.name:    
+                obj.active_material.name += "_repl"
+        # If the atom shape shall change
+        else:
+            new_atom = draw_obj(scn.replace_objs, obj)
+            new_atom.active_material = new_material                
+            new_atom.parent = obj.parent
         
-        new_obj = draw_obj(scn.replace_objs,name,location,scale,material)
-        new_obj.parent = parent
-        if "_repl" not in new_obj.name:
-            new_obj.name = new_obj.name + "_repl"
-        if "_repl" not in new_obj.active_material.name:    
-            new_obj.active_material.name += "_repl"
+            if "_repl" not in new_atom.name:
+                new_atom.name = new_atom.name + "_repl"
+            if "_repl" not in new_atom.active_material.name:    
+                new_atom.active_material.name += "_repl"
             
-        # Delete the old object.
-        bpy.ops.object.select_all(action='DESELECT')
-        obj.select = True
-        bpy.ops.object.delete()            
+            # Delete the old object.
+            bpy.ops.object.select_all(action='DESELECT')
+            obj.select = True
+            bpy.ops.object.delete()            
 
     # Default shapes and colors for atoms
     if action_type == "ATOM_DEFAULT_OBJ" and "Stick" not in obj.name:
 
-        scn = bpy.context.scene.atom_blend
-        
-        # Copy important details from the object.
-        name = obj.name
-        location = obj.location
-        parent = obj.parent       
+        scn = bpy.context.scene.atom_blend     
 
         # Remove the "_repl" if existing
+        name = obj.name
         if "_repl" in name:
             name = name[:name.find("_repl")]
 
         # Create new material
-        material = bpy.data.materials.new(name)
-        material.name = material.name
+        new_material = bpy.data.materials.new(name)
         
         # Create new object
-        new_obj = draw_obj('0b',name,location,Vector((1.0,1.0,1.0)),material)
-        new_obj.parent = parent
+        new_atom = draw_obj('1b',obj)
+        new_atom.active_material = new_material
+        new_atom.parent = obj.parent
 
         # Change size and color of the new object            
         for element in ELEMENTS:
             if element.name in obj.name:
-                new_obj.scale = (element.radii[0],) * 3
-                new_obj.active_material.diffuse_color = element.color
+                new_atom.scale = (element.radii[0],) * 3
+                new_atom.active_material.diffuse_color = element.color
                 
         # Finally, delete the old object
         bpy.ops.object.select_all(action='DESELECT')
@@ -398,103 +398,6 @@ def modify_objects(action_type,
         bpy.ops.object.delete()    
                            
 
-# Initialization of the list 'ELEMENTS'.
-def read_elements():
-
-    del ELEMENTS[:]
-
-    for item in 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 = item[7:]
-        
-        li = ElementProp(item[0],item[1],item[2],item[3],
-                                     radii,radii_ionic)
-        ELEMENTS.append(li)
-
-
-# Custom data file: changing color and radii by using the list 'ELEMENTS'.
-def custom_datafile_change_atom_props():
-
-    for obj in bpy.context.selected_objects:
-        if len(obj.children) != 0:
-            child = obj.children[0]
-            if child.type in {'SURFACE', 'MESH', 'META'}:
-                for element in ELEMENTS:
-                    if element.name in obj.name:
-                        child.scale = (element.radii[0],) * 3
-                        child.active_material.diffuse_color = element.color
-        else:
-            if obj.type in {'SURFACE', 'MESH', 'META'}:
-                for element in ELEMENTS:
-                    if element.name in obj.name:
-                        obj.scale = (element.radii[0],) * 3
-                        obj.active_material.diffuse_color = element.color
-
-
-# Reading a custom data file and modifying the list 'ELEMENTS'.
-def custom_datafile(path_datafile):
-
-    if path_datafile == "":
-        return False
-
-    path_datafile = bpy.path.abspath(path_datafile)
-
-    if os.path.isfile(path_datafile) == False:
-        return False
-
-    # The whole list gets deleted! We build it new.
-    del ELEMENTS[:]
-
-    # Read the data file, which contains all data
-    # (atom name, radii, colors, etc.)
-    data_file_p = open(path_datafile, "r")
-
-    for line in data_file_p:
-
-        if "Atom" in line:
-
-            line = data_file_p.readline()
-            # Number
-            line = data_file_p.readline()
-            number = line[19:-1]
-            # Name
-            line = data_file_p.readline()
-            name = line[19:-1]
-            # Short name
-            line = data_file_p.readline()
-            short_name = line[19:-1]
-            # Color
-            line = data_file_p.readline()
-            color_value = line[19:-1].split(',')
-            color = [float(color_value[0]),
-                     float(color_value[1]),
-                     float(color_value[2])]
-            # Used radius
-            line = data_file_p.readline()
-            radius_used = float(line[19:-1])
-            # Atomic radius
-            line = data_file_p.readline()
-            radius_atomic = float(line[19:-1])
-            # Van der Waals radius
-            line = data_file_p.readline()
-            radius_vdW = float(line[19:-1])
-            radii = [radius_used,radius_atomic,radius_vdW]
-            radii_ionic = []
-
-            element = ElementProp(number,name,short_name,color,
-                                              radii, radii_ionic)
-
-            ELEMENTS.append(element)
-
-    data_file_p.close()
-
-    return True
-
-
 # Separating atoms from a dupliverts strucutre.
 def separate_atoms(scn):
 
@@ -535,20 +438,78 @@ def separate_atoms(scn):
         # For any selected ball do ...
       
         # Draw same object
-        if scn.draw_objs == '-1':
+        if scn.separate_objs == '0':
             draw_regular_obj(name,obj.children[0],location,scale,material)                
         # Draw selected standard object
-        if scn.draw_objs in {'0a','0b','1','2','3a','3b','4a','4b','4c','5a',
-                             '5b','6','7a','7b','8', '9', '10', '11'}:       
-            new_obj = draw_obj(scn.draw_objs,name,location,scale,material)
-            new_obj.name += "_sep"
-            new_obj.active_material.name += "_sep"
+        if scn.separate_objs in {'1a','1b','2','3','4a','4b',
+                             '5a','5b','5c','5d','5e',
+                             '6a','6b','7','8a','8b','100'}:   
+                                 
+            new_material = draw_obj_material(scn.replace_objs_materials, 
+                                         obj.active_material)
+            new_atom = draw_obj(scn.replace_objs, obj)
+            new_atom.active_material = new_material                            
+                             
+            new_atom.name += "_sep"
+            new_atom.active_material.name += "_sep"
 
     bpy.context.scene.objects.active = obj
 
 
+def draw_obj_material(material_type, material):
+
+    if material_type == '0':
+        material_new = material
+    if material_type == '1': #Normal   
+        material_new = bpy.data.materials.new(material.name + "normal")
+        material_new.name = material.name
+        material_new.diffuse_color = material.diffuse_color
+    if material_type == '2': #Transparent    
+        material_new = bpy.data.materials.new(material.name + "transparent")
+        material_new.name = material.name
+        material_new.diffuse_color = material.diffuse_color
+        material_new.use_transparency = True        
+        material_new.transparency_method = 'Z_TRANSPARENCY'
+        material_new.alpha = 1.3
+        material_new.raytrace_transparency.fresnel = 1.6
+        material_new.raytrace_transparency.fresnel_factor = 1.6
+    if material_type == '3': #Reflecting
+        material_new = bpy.data.materials.new(material.name + "reflecting")
+        material_new.name = material.name
+        material_new.diffuse_color = material.diffuse_color
+        material_new.raytrace_mirror.use = True
+        material_new.raytrace_mirror.reflect_factor = 0.6       
+        material_new.raytrace_mirror.fresnel = 0.0
+        material_new.raytrace_mirror.fresnel_factor = 1.250          
+        material_new.raytrace_mirror.depth = 2
+        material_new.raytrace_mirror.distance = 0.0        
+        material_new.raytrace_mirror.gloss_factor = 1.0                   
+    if material_type == '4': #Transparent + reflecting   
+        material_new = bpy.data.materials.new(material.name + "trans+refl")
+        material_new.name = material.name
+        material_new.diffuse_color = material.diffuse_color
+        material_new.use_transparency = True
+        material_new.transparency_method = 'Z_TRANSPARENCY'
+        material_new.alpha = 1.3
+        material_new.raytrace_transparency.fresnel = 1.6
+        material_new.raytrace_transparency.fresnel_factor = 1.6
+        material_new.raytrace_mirror.use = True
+        material_new.raytrace_mirror.reflect_factor = 0.6       
+        material_new.raytrace_mirror.fresnel = 0.0
+        material_new.raytrace_mirror.fresnel_factor = 1.250          
+        material_new.raytrace_mirror.depth = 2
+        material_new.raytrace_mirror.distance = 0.0        
+        material_new.raytrace_mirror.gloss_factor = 1.0 
+        
+    return material_new
+
+
 # Draw an object (e.g. cube, sphere, cylinder, ...)
-def draw_obj(obj_type, name, location, scale, material):
+def draw_obj(obj_type, obj):
+
+    # No change
+    if obj_type == '0':
+        return None
 
     current_layers=bpy.context.scene.layers
     
@@ -556,66 +517,65 @@ def draw_obj(obj_type, name, location, scale, material):
     # F++ center: halo cloud + 2 small spheres
     # defect: halo cloud + circle
 
-    if obj_type == '0a': #Sphere mesh
+    if obj_type == '1a': #Sphere mesh
         bpy.ops.mesh.primitive_uv_sphere_add(
             segments=32,
             ring_count=32,                    
             size=1, 
             view_align=False, 
             enter_editmode=False,
-            location=location,
+            location=obj.location,
             rotation=(0, 0, 0),
             layers=current_layers)
-    if obj_type == '0b': #Sphere NURBS
+    if obj_type == '1b': #Sphere NURBS
         bpy.ops.surface.primitive_nurbs_surface_sphere_add(
             view_align=False, 
             enter_editmode=False,
-            location=location,
+            location=obj.location,
             rotation=(0.0, 0.0, 0.0),
             layers=current_layers)
-    if obj_type == '1': #Cube
+    if obj_type == '2': #Cube
         bpy.ops.mesh.primitive_cube_add(
             view_align=False, 
             enter_editmode=False,
-            location=location,
+            location=obj.location,
             rotation=(0.0, 0.0, 0.0),
             layers=current_layers)
-    if obj_type == '2': #Plane       
+    if obj_type == '3': #Plane       
         bpy.ops.mesh.primitive_plane_add(
             view_align=False, 
             enter_editmode=False, 
-            location=location, 
+            location=obj.location, 
             rotation=(0.0, 0.0, 0.0), 
             layers=current_layers)
-    if obj_type == '3a': #Circle
+    if obj_type == '4a': #Circle
         bpy.ops.mesh.primitive_circle_add(
             vertices=32, 
             radius=1, 
             fill_type='NOTHING', 
             view_align=False, 
             enter_editmode=False, 
-            location=location, 
+            location=obj.location, 
             rotation=(0, 0, 0), 
             layers=current_layers)      
-    if obj_type == '3b': #Circle NURBS
+    if obj_type == '4b': #Circle NURBS
         bpy.ops.surface.primitive_nurbs_surface_circle_add(
             view_align=False, 
             enter_editmode=False, 
-            location=location, 
+            location=obj.location, 
             rotation=(0, 0, 0), 
             layers=current_layers)
-    if obj_type in {'4a','4b','4c','4d','4e'}: #Icosphere        
-        index = {'4a':1,'4b':2,'4c':3,'4d':4,'4e':5}  
-        print(obj_type, index[obj_type])
+    if obj_type in {'5a','5b','5c','5d','5e'}: #Icosphere        
+        index = {'5a':1,'5b':2,'5c':3,'5d':4,'5e':5}  
         bpy.ops.mesh.primitive_ico_sphere_add(
             subdivisions=int(index[obj_type]), 
             size=1, 
             view_align=False, 
             enter_editmode=False, 
-            location=location, 
+            location=obj.location, 
             rotation=(0, 0, 0), 
             layers=current_layers)
-    if obj_type == '5a': #Cylinder
+    if obj_type == '6a': #Cylinder
         bpy.ops.mesh.primitive_cylinder_add(
             vertices=32, 
             radius=1, 
@@ -623,17 +583,17 @@ def draw_obj(obj_type, name, location, scale, material):
             end_fill_type='NGON', 
             view_align=False, 
             enter_editmode=False, 
-            location=location, 
+            location=obj.location, 
             rotation=(0, 0, 0), 
             layers=current_layers)
-    if obj_type == '5b': #Cylinder NURBS
+    if obj_type == '6b': #Cylinder NURBS
         bpy.ops.surface.primitive_nurbs_surface_cylinder_add(
             view_align=False, 
             enter_editmode=False, 
-            location=location, 
+            location=obj.location, 
             rotation=(0, 0, 0), 
             layers=current_layers)          
-    if obj_type == '6': #Cone
+    if obj_type == '7': #Cone
         bpy.ops.mesh.primitive_cone_add(
             vertices=32, 
             radius1=1, 
@@ -642,13 +602,13 @@ def draw_obj(obj_type, name, location, scale, material):
             end_fill_type='NGON', 
             view_align=False, 
             enter_editmode=False, 
-            location=location, 
+            location=obj.location, 
             rotation=(0, 0, 0), 
             layers=current_layers)
-    if obj_type == '7a': #Torus
+    if obj_type == '8a': #Torus
         bpy.ops.mesh.primitive_torus_add(
             rotation=(0, 0, 0), 
-            location=location, 
+            location=obj.location, 
             view_align=False, 
             major_radius=1, 
             minor_radius=0.25, 
@@ -657,82 +617,18 @@ def draw_obj(obj_type, name, location, scale, material):
             use_abso=False, 
             abso_major_rad=1, 
             abso_minor_rad=0.5)     
-    if obj_type == '7b': #Torus NURBS
+    if obj_type == '8b': #Torus NURBS
         bpy.ops.surface.primitive_nurbs_surface_torus_add(
             view_align=False, 
             enter_editmode=False, 
-            location=location, 
+            location=obj.location, 
             rotation=(0, 0, 0), 
             layers=current_layers)
-    if obj_type in {'8','9','10'}:
-        #Transparent cube
-        if obj_type == '8':
-            bpy.ops.mesh.primitive_cube_add(
-                                            view_align=False, 
-                                            enter_editmode=False,
-                                            location=location,
-                                            rotation=(0.0, 0.0, 0.0),
-                                            layers=current_layers)
-        #Transparent mesh sphere                                    
-        if obj_type == '9':
-            bpy.ops.mesh.primitive_uv_sphere_add(
-                                            segments=32,
-                                            ring_count=32,                    
-                                            size=1, 
-                                            view_align=False, 
-                                            enter_editmode=False,
-                                            location=location,
-                                            rotation=(0, 0, 0),
-                                            layers=current_layers)
-        #Transparent NURBS sphere                                    
-        if obj_type == '10':
-            bpy.ops.surface.primitive_nurbs_surface_sphere_add(
-                                            view_align=False, 
-                                            enter_editmode=False,
-                                            location=location,
-                                            rotation=(0.0, 0.0, 0.0),
-                                            layers=current_layers)
 
-        material_new = bpy.data.materials.new(name + "_sep")
-        material_new.name = material.name
-        material_new.diffuse_color = material.diffuse_color
-        material_new.transparency_method = 'Z_TRANSPARENCY'
-        material_new.alpha = 1.3
-        material_new.raytrace_transparency.fresnel = 1.6
-        material_new.raytrace_transparency.fresnel_factor = 1.6
-        material_new.use_transparency = True   
-        new_atom = bpy.context.scene.objects.active
-        new_atom.scale = scale           
-        new_atom.active_material = material_new
-        new_atom.name = name
-        new_atom.select = True
-    # Halo cloud
-    if obj_type == '11':
-        # Build one mesh point
-        new_mesh = bpy.data.meshes.new("Mesh_"+name)
-        new_mesh.from_pydata([Vector((0.0,0.0,0.0))], [], [])
-        new_mesh.update()
-        new_atom = bpy.data.objects.new(name + "_sep", new_mesh)
-        bpy.context.scene.objects.link(new_atom)
-        new_atom.location = location
-        material_new = bpy.data.materials.new(name + "_sep")
-        material_new.name = material.name
-        material_new.diffuse_color = material.diffuse_color        
-        material_new.type = 'HALO'
-        material_new.halo.size = scale[0]*1.5
-        material_new.halo.hardness = 25
-        material_new.halo.add = 0.0
-        new_atom.active_material = material_new
-        new_atom.name = name
-        new_atom.select = True
-
-    if obj_type in {'0a','0b','1','2','3a','3b','4a','4b','4c','4d','4e',
-                    '5a','5b','6','7a','7b'}:
-        new_atom = bpy.context.scene.objects.active
-        new_atom.scale = scale
-        new_atom.active_material = material
-        new_atom.name = name
-        new_atom.select = True   
+    new_atom = bpy.context.scene.objects.active
+    new_atom.scale = obj.scale + Vector((0.0,0.0,0.0))
+    new_atom.name = obj.name    
+    new_atom.select = True
         
     return new_atom
 
@@ -778,4 +674,100 @@ def draw_regular_obj(name, child, location, scale, material):
     new_atom.active_material = material
     new_atom.name = name + "_sep"
     new_atom.select = True
-                           
+                         
+                         
+# Initialization of the list 'ELEMENTS'.
+def read_elements():
+
+    del ELEMENTS[:]
+
+    for item in 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 = item[7:]
+        
+        li = ElementProp(item[0],item[1],item[2],item[3],
+                                     radii,radii_ionic)
+        ELEMENTS.append(li)
+
+
+# Custom data file: changing color and radii by using the list 'ELEMENTS'.
+def custom_datafile_change_atom_props():
+
+    for obj in bpy.context.selected_objects:
+        if len(obj.children) != 0:
+            child = obj.children[0]
+            if child.type in {'SURFACE', 'MESH', 'META'}:
+                for element in ELEMENTS:
+                    if element.name in obj.name:
+                        child.scale = (element.radii[0],) * 3
+                        child.active_material.diffuse_color = element.color
+        else:
+            if obj.type in {'SURFACE', 'MESH', 'META'}:
+                for element in ELEMENTS:
+                    if element.name in obj.name:
+                        obj.scale = (element.radii[0],) * 3
+                        obj.active_material.diffuse_color = element.color
+
+
+# Reading a custom data file and modifying the list 'ELEMENTS'.
+def custom_datafile(path_datafile):
+
+    if path_datafile == "":
+        return False
+
+    path_datafile = bpy.path.abspath(path_datafile)
+
+    if os.path.isfile(path_datafile) == False:
+        return False
+
+    # The whole list gets deleted! We build it new.
+    del ELEMENTS[:]
+
+    # Read the data file, which contains all data
+    # (atom name, radii, colors, etc.)
+    data_file_p = open(path_datafile, "r")
+
+    for line in data_file_p:
+
+        if "Atom" in line:
+
+            line = data_file_p.readline()
+            # Number
+            line = data_file_p.readline()
+            number = line[19:-1]
+            # Name
+            line = data_file_p.readline()
+            name = line[19:-1]
+            # Short name
+            line = data_file_p.readline()
+            short_name = line[19:-1]
+            # Color
+            line = data_file_p.readline()
+            color_value = line[19:-1].split(',')
+            color = [float(color_value[0]),
+                     float(color_value[1]),
+                     float(color_value[2])]
+            # Used radius
+            line = data_file_p.readline()
+            radius_used = float(line[19:-1])
+            # Atomic radius
+            line = data_file_p.readline()
+            radius_atomic = float(line[19:-1])
+            # Van der Waals radius
+            line = data_file_p.readline()
+            radius_vdW = float(line[19:-1])
+            radii = [radius_used,radius_atomic,radius_vdW]
+            radii_ionic = []
+
+            element = ElementProp(number,name,short_name,color,
+                                              radii, radii_ionic)
+
+            ELEMENTS.append(element)
+
+    data_file_p.close()
+
+    return True