Skip to content
Snippets Groups Projects
utility_panel.py 47.1 KiB
Newer Older
  • Learn to ignore specific revisions
  •         ELEMENTS.append(li)
    
    
    # Custom data file: changing color and radii by using the list 'ELEMENTS'.
    def custom_datafile_change_atom_props():
    
        for atom in bpy.context.selected_objects:
            if len(atom.children) != 0:
                child = atom.children[0]
                if child.type in {'SURFACE', 'MESH', 'META'}:
                    for element in ELEMENTS:
                        if element.name in atom.name:
                            child.scale = (element.radii[0],) * 3
                            child.active_material.diffuse_color = element.color
            else:
                if atom.type in {'SURFACE', 'MESH', 'META'}:
                    for element in ELEMENTS:
                        if element.name in atom.name:
                            atom.scale = (element.radii[0],) * 3
                            atom.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]),
                         float(color_value[3])]
                # 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