コード例 #1
0
ファイル: mastgui.py プロジェクト: zhenming-xu/MAST
    def __init__(self):
        self.root_window = Tk()
        self.vframe = VerticalScrolledFrame(self.root_window)
        self.vframe.pack(fill=BOTH, expand=1)
        self.window = self.vframe.interior
        self.sections = []

        self.initialize_window()
コード例 #2
0
ファイル: mastgui.py プロジェクト: ZhewenSong/USIT
    def __init__(self):
        self.root_window = Tk()
        self.vframe = VerticalScrolledFrame(self.root_window)
        self.vframe.pack(fill=BOTH, expand=1)
        self.window = self.vframe.interior
        self.sections = []
 
        self.initialize_window()
コード例 #3
0
ファイル: neb.py プロジェクト: ZhewenSong/USIT
    def create_window(self):
        self.window = ttk.Toplevel(self.parent_window)
        self.window.title("NEB Information")
        self.window.minsize(500, 500)
        self.vframe = VerticalScrolledFrame(self.window)
        self.vframe.pack(fill=BOTH, expand=1)
        self.neb_window = self.vframe.interior
        self.neb_window.grid_rowconfigure(0, weight=1)
        self.neb_window.grid_columnconfigure(0, weight=1)


        neb_frame = LabelFrame(self.neb_window, text="NEB")
        neb_frame.grid(row=0, column=0, padx=20, pady=20)
        neb_frame.grid_rowconfigure(0, weight=1)
        neb_frame.grid_columnconfigure(0, weight=1)

        #frame for images and button
        frame1 = Frame(neb_frame)
        frame1.grid(row=0, column=0)
        frame1.grid_rowconfigure(0, weight=1)
        frame1.grid_rowconfigure(1, weight=1)
        frame1.grid_columnconfigure(0, weight=1)
        frame1.grid_columnconfigure(1, weight=1)
        frame1.grid_columnconfigure(2, weight=1)

        #add images 
        label = Label(frame1, text="IMAGES")
        label.grid(row=0, column=0, sticky=E, pady=10, padx=10)
        images_val = StringVar(frame1)
        if self.neb_info['images'][0] is not None:
            images_val.set(self.neb_info['images'][0])
        images_menu  = Entry(frame1, textvariable=images_val)
        images_menu.grid(row=0, column=1, sticky=W, pady=10, padx=10)
        self.neb_info["images"] = [images_val.get(), images_val]
        images_btn = Button(frame1, text="Add Posfiles", command=self.create_window_with_posfiles)
        images_btn.grid(row=0, column=2, sticky=W, pady=10, padx=10)

        #frame for entities
        frame2 = Frame(neb_frame)
        frame2.grid(row=1, column=0)



        #a label frame to add neb related information
        self.neb_entities_frame = LabelFrame(frame2, text="NEB ENTITIES")  
        self.neb_entities_frame.grid(row=0, column=0, columnspan=3, padx=10, pady=10) 
        
         
        for rownum in xrange(self.num_neb_fields):
            self.create_neb_fields(self.neb_entities_frame, rownum)  

        self.add_button = Button(self.neb_entities_frame, text="Add more neb", command=self.add_elements)
        self.add_button.grid(row=self.num_neb_fields + 1, column=0, columnspan=6, pady=10, padx=10)

        #save button
        save_button = Button(neb_frame, text="Save", command=self.save)
        save_button.grid(row=3, column=0, columnspan=2, padx=20, pady=10)
コード例 #4
0
ファイル: defects.py プロジェクト: ZhewenSong/USIT
    def create_window(self):
        self.window = ttk.Toplevel(self.parent_window)
        self.window.title("Defects Information")
        self.window.minsize(500, 500)
        self.vframe = VerticalScrolledFrame(self.window)
        self.vframe.pack(fill=BOTH, expand=1)
        self.defects_window = self.vframe.interior
        self.defects_window.grid_rowconfigure(0, weight=1)
        self.defects_window.grid_columnconfigure(0, weight=1)


        defects_frame = LabelFrame(self.defects_window, text="Defects")
        defects_frame.grid(row=0, column=0, padx=20, pady=20)
        defects_frame.grid_rowconfigure(0, weight=1)
        defects_frame.grid_rowconfigure(1, weight=1)
        defects_frame.grid_columnconfigure(0, weight=1)
        defects_frame.grid_columnconfigure(1, weight=1)

        #add coordtype 
        label = Label(defects_frame, text="COORD_TYPE")
        label.grid(row=0, column=0, sticky=E, pady=10, padx=10)
        coord_type = StringVar(defects_frame)
        coord_type.set("fractional")
        if self.defects_info['coord_type'][0] is not None:
            coord_type.set(self.defects_info['coord_type'][0])
        coord_type_option = OptionMenu(defects_frame, coord_type, "fractional", "cartesian")  
        coord_type_option.grid(row=0, column=1, sticky=W, pady=10, padx=10)
        self.defects_info["coord_type"] = [coord_type.get(), coord_type]
        #add posfile
        label = Label(defects_frame, text="POS FILE")
        label.grid(row=1, column=0, sticky=E, pady=10, padx=10)
        pos_value = StringVar(defects_frame)
        pos_value.set("")
        if self.defects_info['posfile'][0] is not None:
            pos_value.set(self.defects_info['posfile'][0])
        pos_entry  = Entry(defects_frame, textvariable=pos_value)
        pos_entry.grid(row=1, column=1, sticky=W, pady=10, padx=10)
        self.defects_info["posfile"] = [pos_value.get(), pos_value]

        #a label frame to add defects related information
        self.defects_entities_frame = LabelFrame(defects_frame, text="DEFECT ENTITIES")  
        self.defects_entities_frame.grid(row=2, column=0, columnspan=2, padx=10, pady=10) 
        #create field headers 

        for rownum in xrange(self.num_defect_fields):
            self.create_defect_fields(self.defects_entities_frame, rownum)  

        self.add_button = Button(self.defects_entities_frame, text="Add more defects", command=self.add_elements)
        self.add_button.grid(row=self.num_defect_fields + 1, column=0, columnspan=2, pady=10, padx=10)

        #save button
        save_button = Button(defects_frame, text="Save", command=self.save)
        save_button.grid(row=3, column=0, columnspan=2, padx=20, pady=10)
コード例 #5
0
ファイル: ingredients.py プロジェクト: ZhewenSong/USIT
    def create_window(self):
        self.window = Toplevel(self.parent_window)
        self.window.title("Ingredients Information")
        self.window.minsize(500, 600)
        self.vframe = VerticalScrolledFrame(self.window)
        self.vframe.pack(fill=BOTH, expand=1)
        self.ingredients_window = self.vframe.interior
        self.ingredients_window.grid_rowconfigure(0, weight=1)
        self.ingredients_window.grid_rowconfigure(1, weight=1)
        self.ingredients_window.grid_rowconfigure(2, weight=1)
        self.ingredients_window.grid_columnconfigure(0, weight=1)


        #global param frame
        global_frame = LabelFrame(self.ingredients_window, text="Global Parameters")
        global_frame.grid(row=0, column=0, padx=20, pady=20, sticky=N+S+W+E)

        global_label = Label(global_frame, text="Global Parameters")
        global_label.grid(row=0, column=0, padx=20, sticky=W)
        global_box = Text(global_frame, height=5, width=80)
        if self.ingredients_info['global'][0] is not None:
            global_box.insert('1.0', self.ingredients_info['global'][0])
        else:
            global_box.insert('1.0', '\n'.join(["%s    %s" % (key, value) for key, value in self.keywords]))
        global_box.grid(row=1, column=0, padx=20, pady=5)
        self.ingredients_info['global'][1] = global_box 

        self.ingredients_frame = LabelFrame(self.ingredients_window, text="Ingredients information")
        self.ingredients_frame.grid(row=1, column=0, padx=20, pady=5, sticky=N+S+W+E)

        self.ingredients_frame.grid_rowconfigure(0, weight=1)
        self.ingredients_frame.grid_columnconfigure(0, weight=1)

        #ingredients frames
        for rownum in xrange(self.num_ing_fields):
            self.create_ingredient_fields(self.ingredients_frame, rownum) 

        self.add_button = Button(self.ingredients_frame, text="Add more Ingredients", command=self.add_ingredients)
        self.add_button.grid(row=self.num_ing_fields + 1, column=0, pady=10, padx=10)

        #save button
        save_button = Button(self.ingredients_window, text="Save", command=self.save)
        save_button.grid(row=2, column=0, padx=20, pady=10, sticky=N+S+W+E)
コード例 #6
0
ファイル: ingredients.py プロジェクト: ZhewenSong/USIT
class IngredientsSection:
    def __init__(self, parent_window, grid_row):
        self.parent_window = parent_window
        self.grid_row = grid_row
        self.summary_frame = None
        self.keywords = [\
                           ('mast_program', 'vasp'), ('mast_kpoints', '2x2x2 M'), ('mast_pp_setup', 'La=La Mn=Mn_pv O=O_s'), ('mast_xc', 'PW91'), ('mast_multiplyencut', '1.5'),\
                           ('mast_setmagmom', '1 -1 1 -1 1 -1 1 -1'), ('mast_charge', '1'),('mast_coordinates', 'im1poscar,im2poscar,im3poscar'), ('mast_strain', '1.01 1.03 0.98'),\
                           ('mast_write_method', 'no_setup'), ('mast_ready_method', 'ready_singlerun'), ('mast_run_method', 'run_singlerun'), ('mast_complete_method', 'complete_singlerun'),\
                           ('mast_update_children_method', 'give_structure'), ('mast_nodes', '3'), ('mast_ppn', '8'), ('mast_queue', 'morgan1'),\
                           ('mast_exec', '//opt/mpiexec/bin/mpiexec //share/apps/bin/vasp5.2_CNEB'), ('mast_walltime', '12'), ('mast_memory', '2'),\
                           ('ibrion', '-1'), ('lcharge', 'False'), ('lwave', 'False'),\
                        ]
        self.ingredients_info = {\
                                    'global'       : [None, None],\
                                    'ingredients'  : [{}, {}],\
                                }
        self.key_boxes = {}
        self.num_ing_fields = 1

    def content(self):
        content_start = "$ingredients\n"
        content_end   = "$end\n\n"
        content_lines = ""

        if self.ingredients_info['global'][0]: 
            content_lines += "begin ingredients_global\n"
            content_lines += "%s\n" % self.ingredients_info['global'][0]
            content_lines += "end\n\n"

        if self.ingredients_info['ingredients'][0]:
            for ing_key, ing_data in self.ingredients_info['ingredients'][0].iteritems():
                content_lines += "begin %s\n" % ing_data[0]
                content_lines += "%s\n" % ing_data[1]
                content_lines += "end\n\n"

        return content_start + content_lines + content_end
    
    def summary(self):
        #the frame which encloses all the contents
        self.summary_frame = LabelFrame(self.parent_window, text="Ingredients")

        #the frame contents
        add_button = Button(self.summary_frame, text="Add Ingredients", command=self.create_window)
        add_button.pack(pady=20)

        self.summary_frame.grid(row=self.grid_row, column=0, sticky=W+E, padx=20, pady=5)

    def create_window(self):
        self.window = Toplevel(self.parent_window)
        self.window.title("Ingredients Information")
        self.window.minsize(500, 600)
        self.vframe = VerticalScrolledFrame(self.window)
        self.vframe.pack(fill=BOTH, expand=1)
        self.ingredients_window = self.vframe.interior
        self.ingredients_window.grid_rowconfigure(0, weight=1)
        self.ingredients_window.grid_rowconfigure(1, weight=1)
        self.ingredients_window.grid_rowconfigure(2, weight=1)
        self.ingredients_window.grid_columnconfigure(0, weight=1)


        #global param frame
        global_frame = LabelFrame(self.ingredients_window, text="Global Parameters")
        global_frame.grid(row=0, column=0, padx=20, pady=20, sticky=N+S+W+E)

        global_label = Label(global_frame, text="Global Parameters")
        global_label.grid(row=0, column=0, padx=20, sticky=W)
        global_box = Text(global_frame, height=5, width=80)
        if self.ingredients_info['global'][0] is not None:
            global_box.insert('1.0', self.ingredients_info['global'][0])
        else:
            global_box.insert('1.0', '\n'.join(["%s    %s" % (key, value) for key, value in self.keywords]))
        global_box.grid(row=1, column=0, padx=20, pady=5)
        self.ingredients_info['global'][1] = global_box 

        self.ingredients_frame = LabelFrame(self.ingredients_window, text="Ingredients information")
        self.ingredients_frame.grid(row=1, column=0, padx=20, pady=5, sticky=N+S+W+E)

        self.ingredients_frame.grid_rowconfigure(0, weight=1)
        self.ingredients_frame.grid_columnconfigure(0, weight=1)

        #ingredients frames
        for rownum in xrange(self.num_ing_fields):
            self.create_ingredient_fields(self.ingredients_frame, rownum) 

        self.add_button = Button(self.ingredients_frame, text="Add more Ingredients", command=self.add_ingredients)
        self.add_button.grid(row=self.num_ing_fields + 1, column=0, pady=10, padx=10)

        #save button
        save_button = Button(self.ingredients_window, text="Save", command=self.save)
        save_button.grid(row=2, column=0, padx=20, pady=10, sticky=N+S+W+E)
            

        #individual ingredients
        #param_box = self.create_param_box(global_frame, "global")
        #ind_frame = LabelFrame(self.ingredients_window, text="Ingredients")
        #ind_frame.grid(row=1, column=0, padx=20, pady=20)
        #for num in xrange(self.num_ing_fields):
        #    param_box = self.create_param_box(ind_frame, "individual", ingredient_index=num)
        #    param_box.grid(row=num, column=0, padx=20, pady=20)

    def save(self):
        self.ingredients_info['global'][0] = self.ingredients_info['global'][1].get("1.0", END)
        for rownum in xrange(self.num_ing_fields):
            self.ingredients_info['ingredients'][0][rownum] = [self.ingredients_info['ingredients'][1][rownum][0].get(), self.ingredients_info['ingredients'][1][rownum][1].get("1.0", END)]

        self.window.destroy()
        self.window = None
        self.has_summary = True
        self.summary_frame.grid_remove()
        self.summary()
       
    def add_ingredients(self):
        self.num_ing_fields += 1
        self.add_button.grid_remove()
        self.create_ingredient_fields(self.ingredients_frame, self.num_ing_fields-1)
        self.add_button = Button(self.ingredients_frame, text="Add more Ingredients", command=self.add_ingredients)
        self.add_button.grid(row=self.num_ing_fields + 1, column=0, pady=10, padx=10)

    def create_ingredient_fields(self, frame, rownum):
        if rownum not in self.ingredients_info['ingredients'][1]:
            self.ingredients_info['ingredients'][1][rownum] = [None, None]

        ing_frame = LabelFrame(frame, text="Ingredient %s" % (rownum + 1))
        ing_frame.grid(row=rownum, column=0, padx=10, pady=10, sticky=N+S+W+E)
        ing_frame.grid_rowconfigure(0, weight=1)
        ing_frame.grid_columnconfigure(0, weight=1)
        ing_frame.grid_columnconfigure(1, weight=10)

        space_label = Label(ing_frame, text="")
        space_label.grid(row=0, column=0, pady=5, sticky=W)

        name_label = Label(ing_frame, text="Ingredient Name")
        name_label.grid(row=1, column=0, columnspan=2, padx=10, pady=2, sticky=W)
        name_value = StringVar()
        if rownum in self.ingredients_info['ingredients'][0]:
            name_value.set(self.ingredients_info['ingredients'][0][rownum][0])
        name_box = Entry(ing_frame, textvariable=name_value)
        name_box.grid(row=2, column=0, columnspan=2, padx=10, pady=2, sticky=W)

        param_label = Label(ing_frame, text="Ingredient Parameters")
        param_label.grid(row=3, column=0, columnspan=2, padx=10, pady=2, sticky=W)

        key_option_val  = StringVar(ing_frame)
        key_option_val.set(self.keywords[0][0])
        key_option_menu = Combobox(ing_frame, textvariable=key_option_val, state='readonly')
        key_option_menu['values'] = [key for key, value in self.keywords]
        key_option_menu.grid(row=4, column=0, sticky=W, pady=10, padx=10)
        add_key_btn = Button(ing_frame, text="+")
        add_key_btn.grid(row=4, column=1, padx=10, pady=10, sticky=W)
        self.key_boxes[rownum] = key_option_val

        param_box = Text(ing_frame, height=5, width=80)
        if rownum in self.ingredients_info['ingredients'][0]:
            param_box.insert('1.0', self.ingredients_info['ingredients'][0][rownum][1])
        param_box.grid(row=5, column=0, columnspan=2, padx=10, pady=2, sticky=W)


        space_label = Label(ing_frame, text="")
        space_label.grid(row=5, column=0, pady=5, sticky=W)
        add_key_btn.configure(command=lambda:self.add_param_text(param_box, key_option_val))
        self.ingredients_info['ingredients'][1][rownum] = [name_value, param_box]


    def add_param_text(self, param_box, option_val):
        text = param_box.get("1.0", END)
        text += option_val.get()
        param_box.delete("1.0", END)
        param_box.insert("1.0", text)


    def create_param_box(self, parent, box_type, ingredient_index=-1): 
        values_map = {}
        object_map = {}

        #global param
        if box_type == 'global':
           values_map = self.ingredients_info['global'][0]
           object_map = self.ingredients_info['global'][1]
        #individual ingredients
        elif box_type == 'individual':
           if ingredient_index >= 0 and len(self.ingredients_info['ingredients'][0]) >= ingredient_index + 1:
               values_map = self.ingredients_info['ingredients'][0][ingredient_index]
               object_map = self.ingredients_info['ingredients'][1][ingredient_index]

        frame = Frame(parent)

        self.add_param_fields(frame, 0, object_map)
        add_button = Button(frame, text="+")
        add_button.configure(command=lambda:self.add_param(add_button, parent, box_type))
        add_button.grid(row=0, column=2, pady=20, padx=20)

        return frame

    def add_param(self, add_button, parent, box_type):
        print "success"
        add_button.grid_remove()
        self.create_param_box(parent, box_type)
       
       
        
    def add_param_fields(self, frame, rownum, object_map):
        #create the fields
        key_option_val  = StringVar(frame)
        key_option_val.set(self.keywords[0])
        key_option_menu = Combobox(frame, textvariable=key_option_val, state='readonly')
        key_option_menu['values'] = self.keywords
        key_option_menu.grid(row=0, column=0, sticky=W, pady=10, padx=10)

        val_text   = StringVar(frame)
        val_entry  = Entry(frame, textvariable=val_text)
        val_entry.grid(row=0, column=1, pady=10, padx=10, sticky=W)
        
        object_map.append((key_option_val, val_text))
コード例 #7
0
ファイル: mastgui.py プロジェクト: ZhewenSong/USIT
class MastGui:
    def __init__(self):
        self.root_window = Tk()
        self.vframe = VerticalScrolledFrame(self.root_window)
        self.vframe.pack(fill=BOTH, expand=1)
        self.window = self.vframe.interior
        self.sections = []
 
        self.initialize_window()

    def initialize_window(self):
        #window properties
        self.root_window.title("MAST")
        screensizeX = self.root_window.winfo_screenwidth()
        screensizeY = self.root_window.winfo_screenheight()
        self.root_window.minsize(screensizeX-100, screensizeY - 100)

        self.window.grid_rowconfigure(0, weight=1)
        self.window.grid_rowconfigure(1, weight=1)
        self.window.grid_rowconfigure(2, weight=1)
        self.window.grid_rowconfigure(3, weight=1)
        self.window.grid_rowconfigure(4, weight=1)
        self.window.grid_rowconfigure(5, weight=1)
        self.window.grid_rowconfigure(6, weight=1)
        self.window.grid_columnconfigure(0, weight=1)

        #add sections
        self.mast_section = MastSection(self.window, 0)
        self.mast_section.summary()
        self.sections.append(self.mast_section)

        self.structure_section = StructureSection(self.window, 1)
        self.structure_section.summary()
        self.sections.append(self.structure_section)

        self.defects_section = DefectsSection(self.window, 2, self.structure_section)
        self.defects_section.summary()
        self.sections.append(self.defects_section)

        self.neb_section = NEBSection(self.window, 3, self.structure_section, self.defects_section)
        self.neb_section.summary()
        self.sections.append(self.neb_section)

        self.ingredients_section = IngredientsSection(self.window, 4)
        self.ingredients_section.summary()
        self.sections.append(self.ingredients_section)

        self.phonon_section = PhononSection(self.window, 5)
        self.phonon_section.summary()

        self.create_btn = Button(self.window, text="Create Input File", command=self.create_input)
        self.create_btn.grid(row=6, column=0, pady=10, padx=10)


    def create_input(self):
        input_file = open("mast_input.inp", "w")

        for section_obj in self.sections:
            output_content =  section_obj.content()
            input_file.write(output_content)

        input_file.close()
        self.root_window.destroy()
       
        

    def run(self):
        self.root_window.mainloop()
コード例 #8
0
ファイル: defects.py プロジェクト: ZhewenSong/USIT
class DefectsSection:
    def __init__(self, parent_window, grid_row, structure_section):
        self.parent_window = parent_window
        self.grid_row = grid_row
        self.summary_frame = None
        self.defects_info = {\
                                'coord_type'   : [None, None],\
                                'posfile'      : [None, None],\
                                'defecttype'   : [{}, {}],\
                                'namemap'      : [{}, {}],\
                                'elementmap'   : [{}, {}],\
                                'infomap'      : [{}, {}],\
                                'chargemap'    : [{}, {}],\
                            } 
        self.num_defect_fields = 1
        self.structure_section = structure_section
        self.has_summary=False
        self.defect_types = ['vacancy', 'interstitial', 'substitution', 'antisite']
        self.fields_hash  = {}

    def content(self):
        content_start = "$defects\n"
        content_end = "$end\n\n"

        content_lines = ""

        if self.defects_info['coord_type'][0]:
            content_lines += "coord_type %s\n\n" % self.defects_info['coord_type'][0]

        if self.defects_info['posfile'][0]:
            content_lines += "posfile %s\n\n" % self.defects_info['posfile'][0]

        if self.defects_info['namemap'][0]:
            for d_id, d_name in self.defects_info['namemap'][0].iteritems():
                content_lines += "begin %s\n" % d_name
                if self.defects_info['elementmap'][0][d_id]:
                    for idx, elt in enumerate(self.defects_info['elementmap'][0][d_id]):
                        elt = elt.split('(', 1)[1].replace(')', '').strip()
                        content_lines += "%s %s %s" % (self.defects_info['defecttype'][0][d_id][idx], self.defects_info['infomap'][0][d_id][idx], elt)
                        if self.defects_info['chargemap'][0][d_id][idx]:
                            content_lines += " charge=%s" % self.defects_info['chargemap'][0][d_id][idx]
                        content_lines += "\n"
                content_lines += "end\n\n"

        return content_start + content_lines + content_end

    def get_defects_map(self):
        return self.defects_info['namemap'][0]
    
    def summary(self):
        #the frame which encloses all the contents
        self.summary_frame = LabelFrame(self.parent_window, text="Defects")
        self.summary_frame.grid_rowconfigure(0, weight=1)
        self.summary_frame.grid_rowconfigure(1, weight=1)
        self.summary_frame.grid_columnconfigure(0, weight=1)
        self.summary_frame.grid_columnconfigure(1, weight=1)
        self.summary_frame.grid_columnconfigure(2, weight=1)
        self.summary_frame.grid_columnconfigure(3, weight=1)
        self.summary_frame.grid_columnconfigure(4, weight=1)
        self.summary_frame.grid_columnconfigure(5, weight=1)

        #if it has summary show it
        if self.has_summary:
           #coord_type
           coord_type = Label(self.summary_frame, text="COORD_TYPE :")   
           coord_type.grid(row=0, column=2, sticky=E, pady=5)
           coord_type_value = Label(self.summary_frame, text=self.defects_info['coord_type'][0])
           coord_type_value.grid(row=0, column=3, sticky=W, pady=5)
           if self.defects_info['posfile'][0] is not None:
               pos_label = Label(self.summary_frame, text="POSFILE :")   
               pos_label.grid(row=1, column=2, sticky=E, pady=5)
               pos_value = Label(self.summary_frame, text=self.defects_info['posfile'][0])
               pos_value.grid(row=1, column=3, sticky=W, pady=5)

           for rownum in xrange(self.num_defect_fields):
               if rownum == 0:
                   continue
               if self.defects_info['elementmap'][0]['D' + str(rownum)][0].strip() == "":
                   continue
               id_label = Label(self.summary_frame, text='D'+ str(rownum))
               id_label.grid(row=2 + rownum, column=0, padx=10, pady=2, sticky=E)
               name_label = Label(self.summary_frame, text=self.defects_info['namemap'][0]['D'+str(rownum)])
               name_label.grid(row=2 + rownum, column=1, padx=10, pady=2, sticky=E)
               element_label = Label(self.summary_frame, text=self.defects_info['elementmap'][0]['D'+str(rownum)][0])
               element_label.grid(row=2 + rownum, column=2, padx=10, pady=2, sticky=W)
               type_label = Label(self.summary_frame, text=self.defects_info['defecttype'][0]['D'+str(rownum)][0])
               type_label.grid(row=2 + rownum, column=3, padx=10, pady=2, sticky=W)
               defect_info_label = Label(self.summary_frame, text=self.defects_info['infomap'][0]['D'+str(rownum)][0])
               defect_info_label.grid(row=2 + rownum, column=4, padx=10, pady=2, sticky=W)
               charge_label = Label(self.summary_frame, text=self.defects_info['chargemap'][0]['D'+str(rownum)][0])
               charge_label.grid(row=2 + rownum, column=5, padx=10, pady=2, sticky=W)

        #the frame contents
        add_button = Button(self.summary_frame, text="Add Defects", command=self.create_window)
        add_button.grid(row=3 + self.num_defect_fields, column=0, columnspan=6, pady=20, padx=20)

        self.summary_frame.grid(row=self.grid_row, column=0, padx=20, pady=5, sticky=W+E)


    def create_window(self):
        self.window = ttk.Toplevel(self.parent_window)
        self.window.title("Defects Information")
        self.window.minsize(500, 500)
        self.vframe = VerticalScrolledFrame(self.window)
        self.vframe.pack(fill=BOTH, expand=1)
        self.defects_window = self.vframe.interior
        self.defects_window.grid_rowconfigure(0, weight=1)
        self.defects_window.grid_columnconfigure(0, weight=1)


        defects_frame = LabelFrame(self.defects_window, text="Defects")
        defects_frame.grid(row=0, column=0, padx=20, pady=20)
        defects_frame.grid_rowconfigure(0, weight=1)
        defects_frame.grid_rowconfigure(1, weight=1)
        defects_frame.grid_columnconfigure(0, weight=1)
        defects_frame.grid_columnconfigure(1, weight=1)

        #add coordtype 
        label = Label(defects_frame, text="COORD_TYPE")
        label.grid(row=0, column=0, sticky=E, pady=10, padx=10)
        coord_type = StringVar(defects_frame)
        coord_type.set("fractional")
        if self.defects_info['coord_type'][0] is not None:
            coord_type.set(self.defects_info['coord_type'][0])
        coord_type_option = OptionMenu(defects_frame, coord_type, "fractional", "cartesian")  
        coord_type_option.grid(row=0, column=1, sticky=W, pady=10, padx=10)
        self.defects_info["coord_type"] = [coord_type.get(), coord_type]
        #add posfile
        label = Label(defects_frame, text="POS FILE")
        label.grid(row=1, column=0, sticky=E, pady=10, padx=10)
        pos_value = StringVar(defects_frame)
        pos_value.set("")
        if self.defects_info['posfile'][0] is not None:
            pos_value.set(self.defects_info['posfile'][0])
        pos_entry  = Entry(defects_frame, textvariable=pos_value)
        pos_entry.grid(row=1, column=1, sticky=W, pady=10, padx=10)
        self.defects_info["posfile"] = [pos_value.get(), pos_value]

        #a label frame to add defects related information
        self.defects_entities_frame = LabelFrame(defects_frame, text="DEFECT ENTITIES")  
        self.defects_entities_frame.grid(row=2, column=0, columnspan=2, padx=10, pady=10) 
        #create field headers 

        for rownum in xrange(self.num_defect_fields):
            self.create_defect_fields(self.defects_entities_frame, rownum)  

        self.add_button = Button(self.defects_entities_frame, text="Add more defects", command=self.add_elements)
        self.add_button.grid(row=self.num_defect_fields + 1, column=0, columnspan=2, pady=10, padx=10)

        #save button
        save_button = Button(defects_frame, text="Save", command=self.save)
        save_button.grid(row=3, column=0, columnspan=2, padx=20, pady=10)

    def save(self):
        self.defects_info['coord_type'][0] = self.defects_info['coord_type'][1].get()
        self.defects_info['posfile'][0]    = self.defects_info['posfile'][1].get() 
        for rownum in xrange(self.num_defect_fields):
            self.defects_info['namemap'][0]['D'+str(rownum)]    = self.defects_info['namemap'][1]['D'+str(rownum)].get()
            num_fields = self.fields_hash.get('D' + str(rownum), 0)
            for i in xrange(num_fields):
                if 'D' + str(rownum) in self.defects_info['elementmap'][0]:
                    if i < len(self.defects_info['elementmap'][0]['D' + str(rownum)]):
                        self.defects_info['elementmap'][0]['D' + str(rownum)][i] = self.defects_info['elementmap'][1]['D'+str(rownum)][i].get()
                    else:
                        self.defects_info['elementmap'][0]['D' + str(rownum)].append(self.defects_info['elementmap'][1]['D'+str(rownum)][i].get())
                else:
                    self.defects_info['elementmap'][0]['D'+str(rownum)] = [self.defects_info['elementmap'][1]['D'+str(rownum)][i].get()]
                if 'D' + str(rownum) in self.defects_info['infomap'][0]:
                    if i < len(self.defects_info['infomap'][0]['D' + str(rownum)]):
                        self.defects_info['infomap'][0]['D' + str(rownum)][i] = self.defects_info['infomap'][1]['D'+str(rownum)][i].get()
                    else:
                        self.defects_info['infomap'][0]['D' + str(rownum)].append(self.defects_info['infomap'][1]['D'+str(rownum)][i].get())
                else:
                    self.defects_info['infomap'][0]['D'+str(rownum)] = [self.defects_info['infomap'][1]['D'+str(rownum)][i].get()]
                if 'D' + str(rownum) in self.defects_info['chargemap'][0]:
                    if i < len(self.defects_info['chargemap'][0]['D' + str(rownum)]):
                        self.defects_info['chargemap'][0]['D' + str(rownum)][i] = self.defects_info['chargemap'][1]['D'+str(rownum)][i].get()
                    else:
                        self.defects_info['chargemap'][0]['D' + str(rownum)].append(self.defects_info['chargemap'][1]['D'+str(rownum)][i].get())
                else:
                    self.defects_info['chargemap'][0]['D'+str(rownum)] = [self.defects_info['chargemap'][1]['D'+str(rownum)][i].get()]
                if 'D' + str(rownum) in self.defects_info['defecttype'][0]:
                    if i < len(self.defects_info['defecttype'][0]['D' + str(rownum)]):
                        self.defects_info['defecttype'][0]['D' + str(rownum)][i] = self.defects_info['defecttype'][1]['D'+str(rownum)][i].get()
                    else:
                        self.defects_info['defecttype'][0]['D' + str(rownum)].append(self.defects_info['defecttype'][1]['D'+str(rownum)][i].get())
                else:
                    self.defects_info['defecttype'][0]['D'+str(rownum)] = [self.defects_info['defecttype'][1]['D'+str(rownum)][i].get()]

        self.window.destroy()
        self.window = None
        self.has_summary = True
        self.summary_frame.grid_remove()
        self.summary()
         

    def add_elements(self):
        self.num_defect_fields += 1
        self.add_button.grid_remove()
        self.create_defect_fields(self.defects_entities_frame, self.num_defect_fields - 1)
        self.add_button = Button(self.defects_entities_frame, text="Add more defects", command=self.add_elements)
        self.add_button.grid(row=self.num_defect_fields + 1, column=0, columnspan=6, pady=10, padx=10)
      

    def create_defect_fields(self, frame, rownum):
        elements_map = self.structure_section.get_elements_map()
        elements_options = ["%s (%s)" % (value, key) for key, value in elements_map.iteritems()]

        num_fields = self.fields_hash.get('D' + str(rownum), 1)
        self.fields_hash['D' + str(rownum)] = num_fields

        d_frame = LabelFrame(frame, text="D" + str(rownum))
        d_frame.grid(row=rownum, column=0, padx=10, pady=10, sticky=N+S+W+E)
        
        id_label = Label(d_frame, text="D" + str(rownum))
        id_label.grid(row=0, column=0, padx=10, pady=10, sticky=W)
        name_label = Label(d_frame, text="NAME")
        name_label.grid(row=0, column=0, padx=10, pady=10, sticky=W)
        element_label = Label(d_frame, text="ELEMENT")
        element_label.grid(row=0, column=1, padx=10, pady=10, sticky=W)
        vacancy_label = Label(d_frame, text="DEFECT_TYPE")
        vacancy_label.grid(row=0, column=2, padx=10, pady=10, sticky=W)
        vacancy_label = Label(d_frame, text="DEFECT_INFO")
        vacancy_label.grid(row=0, column=3, padx=10, pady=10, sticky=W)
        charge_label = Label(d_frame, text="CHARGE")
        charge_label.grid(row=0, column=4, padx=10, pady=10, sticky=W)

        name_text = StringVar()
        if self.defects_info['namemap'][0] and ('D' + str(rownum)) in self.defects_info['namemap'][0]:
            name_text.set(self.defects_info['namemap'][0]['D'+str(rownum)])
        name_val  = Entry(d_frame, textvariable=name_text)
        name_val.grid(row=1, column=0, pady=10, padx=10, sticky=W)
        self.defects_info['namemap'][1]['D' + str(rownum)] = name_text

        for i in xrange(num_fields):
            self.create_individual_fields(d_frame, elements_options, rownum, i + 1)

    def create_individual_fields(self, d_frame, elements_options, defect_id, rownum):
        element = StringVar(d_frame)
        element_val = None
        if self.defects_info['elementmap'][0] and ('D' + str(defect_id)) in self.defects_info['elementmap'][0] and \
                rownum <= len(self.defects_info['elementmap'][0]['D' + str(defect_id)]):
            element_val = self.defects_info['elementmap'][0]['D' + str(defect_id)][rownum - 1]
        option_menu = OptionMenu(d_frame, element, ())
        option_menu.grid(row=rownum, column=1, sticky=W, pady=10, padx=10)
        self.add_options(option_menu, elements_options, element, element_val)
        if 'D' + str(defect_id) in self.defects_info['elementmap'][1]:
            if rownum <= len(self.defects_info['elementmap'][1]['D' + str(defect_id)]):
                self.defects_info['elementmap'][1]['D' + str(defect_id)][rownum - 1] = element
            else:
                self.defects_info['elementmap'][1]['D' + str(defect_id)].append(element)
        else:
                self.defects_info['elementmap'][1]['D' + str(defect_id)] = [element]

        defect_type_text = StringVar(d_frame)
        defect_type_val  = None
        if self.defects_info['defecttype'][0] and ('D' + str(defect_id)) in self.defects_info['defecttype'][0] and \
                rownum <= len(self.defects_info['defecttype'][0]['D' + str(defect_id)]):
            defect_type_val = self.defects_info['defecttype'][0]['D' + str(defect_id)][rownum - 1] 
        defect_type_menu = OptionMenu(d_frame, defect_type_text, ())
        defect_type_menu.grid(row=rownum, column=2, sticky=W, pady=10, padx=10)
        self.add_options(defect_type_menu, self.defect_types, defect_type_text, defect_type_val)
        if 'D' + str(defect_id) in self.defects_info['defecttype'][1]:
            if rownum <= len(self.defects_info['defecttype'][1]['D' + str(defect_id)]):
                self.defects_info['defecttype'][1]['D' + str(defect_id)][rownum - 1] = defect_type_text
            else:
                self.defects_info['defecttype'][1]['D' + str(defect_id)].append(defect_type_text)
        else:
                self.defects_info['defecttype'][1]['D' + str(defect_id)] = [defect_type_text]

        vacancy_text = StringVar(d_frame)
        if self.defects_info['infomap'][0] and ('D' + str(defect_id)) in self.defects_info['infomap'][0] and \
                rownum <= len(self.defects_info['infomap'][0]['D' + str(defect_id)]):
            vacancy_text.set(self.defects_info['infomap'][0]['D'+str(defect_id)][rownum - 1])
        vacancy_val  = Entry(d_frame, textvariable=vacancy_text)
        vacancy_val.grid(row=rownum, column=3, pady=10, padx=10, sticky=W)
        if 'D' + str(defect_id) in self.defects_info['infomap'][1]:
            if rownum <= len(self.defects_info['infomap'][1]['D' + str(defect_id)]):
                self.defects_info['infomap'][1]['D' + str(defect_id)][rownum - 1] = vacancy_text
            else:
                self.defects_info['infomap'][1]['D' + str(defect_id)].append(vacancy_text)
        else:
                self.defects_info['infomap'][1]['D' + str(defect_id)] = [vacancy_text]

        charge_text = StringVar(d_frame)
        if self.defects_info['chargemap'][0] and ('D' + str(defect_id)) in self.defects_info['chargemap'][0] and \
                rownum <= len(self.defects_info['chargemap'][0]['D' + str(defect_id)]):
            charge_text.set(self.defects_info['chargemap'][0]['D'+str(defect_id)][rownum - 1])
        charge_val  = Entry(d_frame, textvariable=charge_text)
        charge_val.grid(row=rownum, column=4, pady=10, padx=10, sticky=W)
        if 'D' + str(defect_id) in self.defects_info['chargemap'][1]:
            if rownum <= len(self.defects_info['chargemap'][1]['D' + str(defect_id)]):
                self.defects_info['chargemap'][1]['D' + str(defect_id)][rownum - 1] = charge_text
            else:
                self.defects_info['chargemap'][1]['D' + str(defect_id)].append(charge_text)
        else:
                self.defects_info['chargemap'][1]['D' + str(defect_id)] = [charge_text]
        
        add_button = Button(d_frame, text="+")
        add_button.grid(row=rownum, column=5, pady=10, padx=10)
        add_button.configure(command=lambda:self.add_defect_field(add_button, d_frame, rownum, elements_options, defect_id))

    def add_defect_field(self, add_button, d_frame, rownum, elements_options, defect_id):
        add_button.grid_remove()
        num_fields = self.fields_hash.get('D' + str(defect_id), 1)
        self.fields_hash['D' + str(defect_id)] = num_fields + 1
        self.create_individual_fields(d_frame, elements_options, defect_id, rownum + 1)


    def add_options(self, option_menu, options, element_var, index_val):
        menu = option_menu["menu"]
        menu.delete(0, "end")
        for string in options:
            menu.add_command(label=string, command=lambda value=string:element_var.set(value))
        if index_val is not None:
            element_var.set(index_val)
コード例 #9
0
ファイル: defects.py プロジェクト: zhenming-xu/MAST
class DefectsSection:
    def __init__(self, parent_window, grid_row, structure_section):
        self.parent_window = parent_window
        self.grid_row = grid_row
        self.summary_frame = None
        self.defects_info = {\
                                'coord_type'   : [None, None],\
                                'posfile'      : [None, None],\
                                'defecttype'   : [{}, {}],\
                                'namemap'      : [{}, {}],\
                                'elementmap'   : [{}, {}],\
                                'infomap'      : [{}, {}],\
                                'chargemap'    : [{}, {}],\
                            }
        self.num_defect_fields = 1
        self.structure_section = structure_section
        self.has_summary = False
        self.defect_types = [
            'vacancy', 'interstitial', 'substitution', 'antisite'
        ]
        self.fields_hash = {}

    def content(self):
        content_start = "$defects\n"
        content_end = "$end\n\n"

        content_lines = ""

        if self.defects_info['coord_type'][0]:
            content_lines += "coord_type %s\n\n" % self.defects_info[
                'coord_type'][0]

        if self.defects_info['posfile'][0]:
            content_lines += "posfile %s\n\n" % self.defects_info['posfile'][0]

        if self.defects_info['namemap'][0]:
            for d_id, d_name in self.defects_info['namemap'][0].iteritems():
                content_lines += "begin %s\n" % d_name
                if self.defects_info['elementmap'][0][d_id]:
                    for idx, elt in enumerate(
                            self.defects_info['elementmap'][0][d_id]):
                        elt = elt.split('(', 1)[1].replace(')', '').strip()
                        content_lines += "%s %s %s" % (
                            self.defects_info['defecttype'][0][d_id][idx],
                            self.defects_info['infomap'][0][d_id][idx], elt)
                        if self.defects_info['chargemap'][0][d_id][idx]:
                            content_lines += " charge=%s" % self.defects_info[
                                'chargemap'][0][d_id][idx]
                        content_lines += "\n"
                content_lines += "end\n\n"

        return content_start + content_lines + content_end

    def get_defects_map(self):
        return self.defects_info['namemap'][0]

    def summary(self):
        #the frame which encloses all the contents
        self.summary_frame = LabelFrame(self.parent_window, text="Defects")
        self.summary_frame.grid_rowconfigure(0, weight=1)
        self.summary_frame.grid_rowconfigure(1, weight=1)
        self.summary_frame.grid_columnconfigure(0, weight=1)
        self.summary_frame.grid_columnconfigure(1, weight=1)
        self.summary_frame.grid_columnconfigure(2, weight=1)
        self.summary_frame.grid_columnconfigure(3, weight=1)
        self.summary_frame.grid_columnconfigure(4, weight=1)
        self.summary_frame.grid_columnconfigure(5, weight=1)

        #if it has summary show it
        if self.has_summary:
            #coord_type
            coord_type = Label(self.summary_frame, text="COORD_TYPE :")
            coord_type.grid(row=0, column=2, sticky=E, pady=5)
            coord_type_value = Label(self.summary_frame,
                                     text=self.defects_info['coord_type'][0])
            coord_type_value.grid(row=0, column=3, sticky=W, pady=5)
            if self.defects_info['posfile'][0] is not None:
                pos_label = Label(self.summary_frame, text="POSFILE :")
                pos_label.grid(row=1, column=2, sticky=E, pady=5)
                pos_value = Label(self.summary_frame,
                                  text=self.defects_info['posfile'][0])
                pos_value.grid(row=1, column=3, sticky=W, pady=5)

            for rownum in xrange(self.num_defect_fields):
                if rownum == 0:
                    continue
                if self.defects_info['elementmap'][0][
                        'D' + str(rownum)][0].strip() == "":
                    continue
                id_label = Label(self.summary_frame, text='D' + str(rownum))
                id_label.grid(row=2 + rownum,
                              column=0,
                              padx=10,
                              pady=2,
                              sticky=E)
                name_label = Label(
                    self.summary_frame,
                    text=self.defects_info['namemap'][0]['D' + str(rownum)])
                name_label.grid(row=2 + rownum,
                                column=1,
                                padx=10,
                                pady=2,
                                sticky=E)
                element_label = Label(
                    self.summary_frame,
                    text=self.defects_info['elementmap'][0]['D' +
                                                            str(rownum)][0])
                element_label.grid(row=2 + rownum,
                                   column=2,
                                   padx=10,
                                   pady=2,
                                   sticky=W)
                type_label = Label(
                    self.summary_frame,
                    text=self.defects_info['defecttype'][0]['D' +
                                                            str(rownum)][0])
                type_label.grid(row=2 + rownum,
                                column=3,
                                padx=10,
                                pady=2,
                                sticky=W)
                defect_info_label = Label(
                    self.summary_frame,
                    text=self.defects_info['infomap'][0]['D' + str(rownum)][0])
                defect_info_label.grid(row=2 + rownum,
                                       column=4,
                                       padx=10,
                                       pady=2,
                                       sticky=W)
                charge_label = Label(
                    self.summary_frame,
                    text=self.defects_info['chargemap'][0]['D' +
                                                           str(rownum)][0])
                charge_label.grid(row=2 + rownum,
                                  column=5,
                                  padx=10,
                                  pady=2,
                                  sticky=W)

        #the frame contents
        add_button = Button(self.summary_frame,
                            text="Add Defects",
                            command=self.create_window)
        add_button.grid(row=3 + self.num_defect_fields,
                        column=0,
                        columnspan=6,
                        pady=20,
                        padx=20)

        self.summary_frame.grid(row=self.grid_row,
                                column=0,
                                padx=20,
                                pady=5,
                                sticky=W + E)

    def create_window(self):
        self.window = ttk.Toplevel(self.parent_window)
        self.window.title("Defects Information")
        self.window.minsize(500, 500)
        self.vframe = VerticalScrolledFrame(self.window)
        self.vframe.pack(fill=BOTH, expand=1)
        self.defects_window = self.vframe.interior
        self.defects_window.grid_rowconfigure(0, weight=1)
        self.defects_window.grid_columnconfigure(0, weight=1)

        defects_frame = LabelFrame(self.defects_window, text="Defects")
        defects_frame.grid(row=0, column=0, padx=20, pady=20)
        defects_frame.grid_rowconfigure(0, weight=1)
        defects_frame.grid_rowconfigure(1, weight=1)
        defects_frame.grid_columnconfigure(0, weight=1)
        defects_frame.grid_columnconfigure(1, weight=1)

        #add coordtype
        label = Label(defects_frame, text="COORD_TYPE")
        label.grid(row=0, column=0, sticky=E, pady=10, padx=10)
        coord_type = StringVar(defects_frame)
        coord_type.set("fractional")
        if self.defects_info['coord_type'][0] is not None:
            coord_type.set(self.defects_info['coord_type'][0])
        coord_type_option = OptionMenu(defects_frame, coord_type, "fractional",
                                       "cartesian")
        coord_type_option.grid(row=0, column=1, sticky=W, pady=10, padx=10)
        self.defects_info["coord_type"] = [coord_type.get(), coord_type]
        #add posfile
        label = Label(defects_frame, text="POS FILE")
        label.grid(row=1, column=0, sticky=E, pady=10, padx=10)
        pos_value = StringVar(defects_frame)
        pos_value.set("")
        if self.defects_info['posfile'][0] is not None:
            pos_value.set(self.defects_info['posfile'][0])
        pos_entry = Entry(defects_frame, textvariable=pos_value)
        pos_entry.grid(row=1, column=1, sticky=W, pady=10, padx=10)
        self.defects_info["posfile"] = [pos_value.get(), pos_value]

        #a label frame to add defects related information
        self.defects_entities_frame = LabelFrame(defects_frame,
                                                 text="DEFECT ENTITIES")
        self.defects_entities_frame.grid(row=2,
                                         column=0,
                                         columnspan=2,
                                         padx=10,
                                         pady=10)
        #create field headers

        for rownum in xrange(self.num_defect_fields):
            self.create_defect_fields(self.defects_entities_frame, rownum)

        self.add_button = Button(self.defects_entities_frame,
                                 text="Add more defects",
                                 command=self.add_elements)
        self.add_button.grid(row=self.num_defect_fields + 1,
                             column=0,
                             columnspan=2,
                             pady=10,
                             padx=10)

        #save button
        save_button = Button(defects_frame, text="Save", command=self.save)
        save_button.grid(row=3, column=0, columnspan=2, padx=20, pady=10)

    def save(self):
        self.defects_info['coord_type'][0] = self.defects_info['coord_type'][
            1].get()
        self.defects_info['posfile'][0] = self.defects_info['posfile'][1].get()
        for rownum in xrange(self.num_defect_fields):
            self.defects_info['namemap'][0]['D' + str(
                rownum)] = self.defects_info['namemap'][1]['D' +
                                                           str(rownum)].get()
            num_fields = self.fields_hash.get('D' + str(rownum), 0)
            for i in xrange(num_fields):
                if 'D' + str(rownum) in self.defects_info['elementmap'][0]:
                    if i < len(
                            self.defects_info['elementmap'][0]['D' +
                                                               str(rownum)]):
                        self.defects_info['elementmap'][0]['D' + str(
                            rownum)][i] = self.defects_info['elementmap'][1][
                                'D' + str(rownum)][i].get()
                    else:
                        self.defects_info['elementmap'][0][
                            'D' + str(rownum)].append(
                                self.defects_info['elementmap'][1][
                                    'D' + str(rownum)][i].get())
                else:
                    self.defects_info['elementmap'][0]['D' + str(rownum)] = [
                        self.defects_info['elementmap'][1]['D' + str(rownum)]
                        [i].get()
                    ]
                if 'D' + str(rownum) in self.defects_info['infomap'][0]:
                    if i < len(self.defects_info['infomap'][0]['D' +
                                                               str(rownum)]):
                        self.defects_info['infomap'][0][
                            'D' +
                            str(rownum)][i] = self.defects_info['infomap'][1][
                                'D' + str(rownum)][i].get()
                    else:
                        self.defects_info['infomap'][0][
                            'D' + str(rownum)].append(
                                self.defects_info['infomap'][1][
                                    'D' + str(rownum)][i].get())
                else:
                    self.defects_info['infomap'][0]['D' + str(rownum)] = [
                        self.defects_info['infomap'][1]['D' +
                                                        str(rownum)][i].get()
                    ]
                if 'D' + str(rownum) in self.defects_info['chargemap'][0]:
                    if i < len(self.defects_info['chargemap'][0]['D' +
                                                                 str(rownum)]):
                        self.defects_info['chargemap'][0]['D' + str(
                            rownum)][i] = self.defects_info['chargemap'][1][
                                'D' + str(rownum)][i].get()
                    else:
                        self.defects_info['chargemap'][0][
                            'D' + str(rownum)].append(
                                self.defects_info['chargemap'][1][
                                    'D' + str(rownum)][i].get())
                else:
                    self.defects_info['chargemap'][0]['D' + str(rownum)] = [
                        self.defects_info['chargemap'][1]['D' + str(rownum)]
                        [i].get()
                    ]
                if 'D' + str(rownum) in self.defects_info['defecttype'][0]:
                    if i < len(
                            self.defects_info['defecttype'][0]['D' +
                                                               str(rownum)]):
                        self.defects_info['defecttype'][0]['D' + str(
                            rownum)][i] = self.defects_info['defecttype'][1][
                                'D' + str(rownum)][i].get()
                    else:
                        self.defects_info['defecttype'][0][
                            'D' + str(rownum)].append(
                                self.defects_info['defecttype'][1][
                                    'D' + str(rownum)][i].get())
                else:
                    self.defects_info['defecttype'][0]['D' + str(rownum)] = [
                        self.defects_info['defecttype'][1]['D' + str(rownum)]
                        [i].get()
                    ]

        self.window.destroy()
        self.window = None
        self.has_summary = True
        self.summary_frame.grid_remove()
        self.summary()

    def add_elements(self):
        self.num_defect_fields += 1
        self.add_button.grid_remove()
        self.create_defect_fields(self.defects_entities_frame,
                                  self.num_defect_fields - 1)
        self.add_button = Button(self.defects_entities_frame,
                                 text="Add more defects",
                                 command=self.add_elements)
        self.add_button.grid(row=self.num_defect_fields + 1,
                             column=0,
                             columnspan=6,
                             pady=10,
                             padx=10)

    def create_defect_fields(self, frame, rownum):
        elements_map = self.structure_section.get_elements_map()
        elements_options = [
            "%s (%s)" % (value, key)
            for key, value in elements_map.iteritems()
        ]

        num_fields = self.fields_hash.get('D' + str(rownum), 1)
        self.fields_hash['D' + str(rownum)] = num_fields

        d_frame = LabelFrame(frame, text="D" + str(rownum))
        d_frame.grid(row=rownum,
                     column=0,
                     padx=10,
                     pady=10,
                     sticky=N + S + W + E)

        id_label = Label(d_frame, text="D" + str(rownum))
        id_label.grid(row=0, column=0, padx=10, pady=10, sticky=W)
        name_label = Label(d_frame, text="NAME")
        name_label.grid(row=0, column=0, padx=10, pady=10, sticky=W)
        element_label = Label(d_frame, text="ELEMENT")
        element_label.grid(row=0, column=1, padx=10, pady=10, sticky=W)
        vacancy_label = Label(d_frame, text="DEFECT_TYPE")
        vacancy_label.grid(row=0, column=2, padx=10, pady=10, sticky=W)
        vacancy_label = Label(d_frame, text="DEFECT_INFO")
        vacancy_label.grid(row=0, column=3, padx=10, pady=10, sticky=W)
        charge_label = Label(d_frame, text="CHARGE")
        charge_label.grid(row=0, column=4, padx=10, pady=10, sticky=W)

        name_text = StringVar()
        if self.defects_info['namemap'][0] and (
                'D' + str(rownum)) in self.defects_info['namemap'][0]:
            name_text.set(self.defects_info['namemap'][0]['D' + str(rownum)])
        name_val = Entry(d_frame, textvariable=name_text)
        name_val.grid(row=1, column=0, pady=10, padx=10, sticky=W)
        self.defects_info['namemap'][1]['D' + str(rownum)] = name_text

        for i in xrange(num_fields):
            self.create_individual_fields(d_frame, elements_options, rownum,
                                          i + 1)

    def create_individual_fields(self, d_frame, elements_options, defect_id,
                                 rownum):
        element = StringVar(d_frame)
        element_val = None
        if self.defects_info['elementmap'][0] and ('D' + str(defect_id)) in self.defects_info['elementmap'][0] and \
                rownum <= len(self.defects_info['elementmap'][0]['D' + str(defect_id)]):
            element_val = self.defects_info['elementmap'][0][
                'D' + str(defect_id)][rownum - 1]
        option_menu = OptionMenu(d_frame, element, ())
        option_menu.grid(row=rownum, column=1, sticky=W, pady=10, padx=10)
        self.add_options(option_menu, elements_options, element, element_val)
        if 'D' + str(defect_id) in self.defects_info['elementmap'][1]:
            if rownum <= len(
                    self.defects_info['elementmap'][1]['D' + str(defect_id)]):
                self.defects_info['elementmap'][1]['D' +
                                                   str(defect_id)][rownum -
                                                                   1] = element
            else:
                self.defects_info['elementmap'][1][
                    'D' + str(defect_id)].append(element)
        else:
            self.defects_info['elementmap'][1]['D' +
                                               str(defect_id)] = [element]

        defect_type_text = StringVar(d_frame)
        defect_type_val = None
        if self.defects_info['defecttype'][0] and ('D' + str(defect_id)) in self.defects_info['defecttype'][0] and \
                rownum <= len(self.defects_info['defecttype'][0]['D' + str(defect_id)]):
            defect_type_val = self.defects_info['defecttype'][0][
                'D' + str(defect_id)][rownum - 1]
        defect_type_menu = OptionMenu(d_frame, defect_type_text, ())
        defect_type_menu.grid(row=rownum, column=2, sticky=W, pady=10, padx=10)
        self.add_options(defect_type_menu, self.defect_types, defect_type_text,
                         defect_type_val)
        if 'D' + str(defect_id) in self.defects_info['defecttype'][1]:
            if rownum <= len(
                    self.defects_info['defecttype'][1]['D' + str(defect_id)]):
                self.defects_info['defecttype'][1]['D' + str(defect_id)][
                    rownum - 1] = defect_type_text
            else:
                self.defects_info['defecttype'][1][
                    'D' + str(defect_id)].append(defect_type_text)
        else:
            self.defects_info['defecttype'][1]['D' + str(defect_id)] = [
                defect_type_text
            ]

        vacancy_text = StringVar(d_frame)
        if self.defects_info['infomap'][0] and ('D' + str(defect_id)) in self.defects_info['infomap'][0] and \
                rownum <= len(self.defects_info['infomap'][0]['D' + str(defect_id)]):
            vacancy_text.set(
                self.defects_info['infomap'][0]['D' + str(defect_id)][rownum -
                                                                      1])
        vacancy_val = Entry(d_frame, textvariable=vacancy_text)
        vacancy_val.grid(row=rownum, column=3, pady=10, padx=10, sticky=W)
        if 'D' + str(defect_id) in self.defects_info['infomap'][1]:
            if rownum <= len(
                    self.defects_info['infomap'][1]['D' + str(defect_id)]):
                self.defects_info['infomap'][1]['D' + str(defect_id)][
                    rownum - 1] = vacancy_text
            else:
                self.defects_info['infomap'][1]['D' + str(defect_id)].append(
                    vacancy_text)
        else:
            self.defects_info['infomap'][1]['D' +
                                            str(defect_id)] = [vacancy_text]

        charge_text = StringVar(d_frame)
        if self.defects_info['chargemap'][0] and ('D' + str(defect_id)) in self.defects_info['chargemap'][0] and \
                rownum <= len(self.defects_info['chargemap'][0]['D' + str(defect_id)]):
            charge_text.set(
                self.defects_info['chargemap'][0]['D' +
                                                  str(defect_id)][rownum - 1])
        charge_val = Entry(d_frame, textvariable=charge_text)
        charge_val.grid(row=rownum, column=4, pady=10, padx=10, sticky=W)
        if 'D' + str(defect_id) in self.defects_info['chargemap'][1]:
            if rownum <= len(
                    self.defects_info['chargemap'][1]['D' + str(defect_id)]):
                self.defects_info['chargemap'][1]['D' + str(defect_id)][
                    rownum - 1] = charge_text
            else:
                self.defects_info['chargemap'][1]['D' + str(defect_id)].append(
                    charge_text)
        else:
            self.defects_info['chargemap'][1]['D' +
                                              str(defect_id)] = [charge_text]

        add_button = Button(d_frame, text="+")
        add_button.grid(row=rownum, column=5, pady=10, padx=10)
        add_button.configure(command=lambda: self.add_defect_field(
            add_button, d_frame, rownum, elements_options, defect_id))

    def add_defect_field(self, add_button, d_frame, rownum, elements_options,
                         defect_id):
        add_button.grid_remove()
        num_fields = self.fields_hash.get('D' + str(defect_id), 1)
        self.fields_hash['D' + str(defect_id)] = num_fields + 1
        self.create_individual_fields(d_frame, elements_options, defect_id,
                                      rownum + 1)

    def add_options(self, option_menu, options, element_var, index_val):
        menu = option_menu["menu"]
        menu.delete(0, "end")
        for string in options:
            menu.add_command(
                label=string,
                command=lambda value=string: element_var.set(value))
        if index_val is not None:
            element_var.set(index_val)
コード例 #10
0
ファイル: defects.py プロジェクト: zhenming-xu/MAST
    def create_window(self):
        self.window = ttk.Toplevel(self.parent_window)
        self.window.title("Defects Information")
        self.window.minsize(500, 500)
        self.vframe = VerticalScrolledFrame(self.window)
        self.vframe.pack(fill=BOTH, expand=1)
        self.defects_window = self.vframe.interior
        self.defects_window.grid_rowconfigure(0, weight=1)
        self.defects_window.grid_columnconfigure(0, weight=1)

        defects_frame = LabelFrame(self.defects_window, text="Defects")
        defects_frame.grid(row=0, column=0, padx=20, pady=20)
        defects_frame.grid_rowconfigure(0, weight=1)
        defects_frame.grid_rowconfigure(1, weight=1)
        defects_frame.grid_columnconfigure(0, weight=1)
        defects_frame.grid_columnconfigure(1, weight=1)

        #add coordtype
        label = Label(defects_frame, text="COORD_TYPE")
        label.grid(row=0, column=0, sticky=E, pady=10, padx=10)
        coord_type = StringVar(defects_frame)
        coord_type.set("fractional")
        if self.defects_info['coord_type'][0] is not None:
            coord_type.set(self.defects_info['coord_type'][0])
        coord_type_option = OptionMenu(defects_frame, coord_type, "fractional",
                                       "cartesian")
        coord_type_option.grid(row=0, column=1, sticky=W, pady=10, padx=10)
        self.defects_info["coord_type"] = [coord_type.get(), coord_type]
        #add posfile
        label = Label(defects_frame, text="POS FILE")
        label.grid(row=1, column=0, sticky=E, pady=10, padx=10)
        pos_value = StringVar(defects_frame)
        pos_value.set("")
        if self.defects_info['posfile'][0] is not None:
            pos_value.set(self.defects_info['posfile'][0])
        pos_entry = Entry(defects_frame, textvariable=pos_value)
        pos_entry.grid(row=1, column=1, sticky=W, pady=10, padx=10)
        self.defects_info["posfile"] = [pos_value.get(), pos_value]

        #a label frame to add defects related information
        self.defects_entities_frame = LabelFrame(defects_frame,
                                                 text="DEFECT ENTITIES")
        self.defects_entities_frame.grid(row=2,
                                         column=0,
                                         columnspan=2,
                                         padx=10,
                                         pady=10)
        #create field headers

        for rownum in xrange(self.num_defect_fields):
            self.create_defect_fields(self.defects_entities_frame, rownum)

        self.add_button = Button(self.defects_entities_frame,
                                 text="Add more defects",
                                 command=self.add_elements)
        self.add_button.grid(row=self.num_defect_fields + 1,
                             column=0,
                             columnspan=2,
                             pady=10,
                             padx=10)

        #save button
        save_button = Button(defects_frame, text="Save", command=self.save)
        save_button.grid(row=3, column=0, columnspan=2, padx=20, pady=10)
コード例 #11
0
ファイル: neb.py プロジェクト: ZhewenSong/USIT
class NEBSection:
    def __init__(self, parent_window, grid_row, structure_section, defects_section):
        self.parent_window = parent_window
        self.grid_row = grid_row
        self.structure_section = structure_section
        self.defects_section = defects_section
        self.has_summary = False
        self.neb_info = {\
                            'images'       : [None, None],\
                            'posfiles'     : [{}, {}],\
                            'startdefect'  : [{}, {}],\
                            'enddefect'    : [{}, {}],\
                            'elementmap'   : [{}, {}],\
                            'startpos'     : [{}, {}],\
                            'endpos'       : [{}, {}],\
                        }
        self.num_neb_fields = 1
        self.fields_hash    = {}

    def content(self):
        content_start = "$neb\n"
        content_end   = "$end\n\n"
        content_lines = ""

        if self.neb_info['startdefect'][0]:
            for n_id, s_defect in self.neb_info['startdefect'][0].iteritems():
                if n_id not in self.neb_info['enddefect'][0]:
                    continue
                content_lines += "begin %s-%s\n" % (s_defect.split('(', 1)[0].strip(), self.neb_info['enddefect'][0][n_id].split('(', 1)[0].strip())
                if n_id in self.neb_info['elementmap'][0]:
                    for idx, elt in enumerate(self.neb_info['elementmap'][0][n_id]):
                        elt = elt.split('(', 1)[1].replace(')', '').strip()
                        content_lines += "%s, %s, %s\n" % (elt, self.neb_info['startpos'][0][n_id][idx], self.neb_info['endpos'][0][n_id][idx])
                if n_id in self.neb_info['posfiles'][0]:
                    content_lines += "posfile %s\n" % ",".join(self.neb_info['posfiles'][0][n_id])
                    
                content_lines += "end\n\n"

        if self.neb_info['images'][0]:
            content_lines += "images %s\n" % self.neb_info['images'][0]

        return content_start + content_lines + content_end
    
    def summary(self):
        #the frame which encloses all the contents
        self.summary_frame = LabelFrame(self.parent_window, text="NEB")
        self.summary_frame.grid_rowconfigure(0, weight=1)
        self.summary_frame.grid_rowconfigure(1, weight=1)
        self.summary_frame.grid_columnconfigure(0, weight=1)
        self.summary_frame.grid_columnconfigure(1, weight=1)
        self.summary_frame.grid_columnconfigure(2, weight=1)
        self.summary_frame.grid_columnconfigure(3, weight=1)
        self.summary_frame.grid_columnconfigure(4, weight=1)
        self.summary_frame.grid_columnconfigure(5, weight=1)

        #if it has summary show it
        if self.has_summary:
           #coord_type
           images = Label(self.summary_frame, text="IMAGES :")   
           images.grid(row=0, column=2, sticky=E, pady=5)
           images_value = Label(self.summary_frame, text=self.neb_info['images'][0])
           images_value.grid(row=0, column=3, sticky=W, pady=5)

           for rownum in xrange(self.num_neb_fields):
               if self.neb_info['startdefect'][0]['N' + str(rownum)].strip() == "":
                   continue
               id_label = Label(self.summary_frame, text='N'+ str(rownum))
               id_label.grid(row=2 + rownum, column=0, padx=10, pady=2, sticky=E)
               s_defect_label = Label(self.summary_frame, text=self.neb_info['startdefect'][0]['N'+str(rownum)])
               s_defect_label.grid(row=2 + rownum, column=1, padx=10, pady=2, sticky=E)
               e_defect_label = Label(self.summary_frame, text=self.neb_info['enddefect'][0]['N'+str(rownum)])
               e_defect_label.grid(row=2 + rownum, column=2, padx=10, pady=2, sticky=E)
               element_label = Label(self.summary_frame, text=self.neb_info['elementmap'][0]['N'+str(rownum)][0])
               element_label.grid(row=2 + rownum, column=3, padx=10, pady=2, sticky=E)
               s_pos_label = Label(self.summary_frame, text=self.neb_info['startpos'][0]['N'+str(rownum)][0])
               s_pos_label.grid(row=2 + rownum, column=4, padx=10, pady=2, sticky=E)
               e_pos_label = Label(self.summary_frame, text=self.neb_info['endpos'][0]['N'+str(rownum)][0])
               e_pos_label.grid(row=2 + rownum, column=5, padx=10, pady=2, sticky=E)

        #the frame contents
        add_button = Button(self.summary_frame, text="Add NEB properties", command=self.create_window)
        add_button.grid(row=3 + self.num_neb_fields, column=0, columnspan=7, pady=20, padx=20)

        self.summary_frame.grid(row=self.grid_row, column=0, sticky=W+E, padx=20, pady=5)

    def create_window_with_posfiles(self):
        self.neb_info['images'][0] = self.neb_info['images'][1].get()
        self.window.destroy()
        self.window = None
        self.create_window()

    def create_window(self):
        self.window = ttk.Toplevel(self.parent_window)
        self.window.title("NEB Information")
        self.window.minsize(500, 500)
        self.vframe = VerticalScrolledFrame(self.window)
        self.vframe.pack(fill=BOTH, expand=1)
        self.neb_window = self.vframe.interior
        self.neb_window.grid_rowconfigure(0, weight=1)
        self.neb_window.grid_columnconfigure(0, weight=1)


        neb_frame = LabelFrame(self.neb_window, text="NEB")
        neb_frame.grid(row=0, column=0, padx=20, pady=20)
        neb_frame.grid_rowconfigure(0, weight=1)
        neb_frame.grid_columnconfigure(0, weight=1)

        #frame for images and button
        frame1 = Frame(neb_frame)
        frame1.grid(row=0, column=0)
        frame1.grid_rowconfigure(0, weight=1)
        frame1.grid_rowconfigure(1, weight=1)
        frame1.grid_columnconfigure(0, weight=1)
        frame1.grid_columnconfigure(1, weight=1)
        frame1.grid_columnconfigure(2, weight=1)

        #add images 
        label = Label(frame1, text="IMAGES")
        label.grid(row=0, column=0, sticky=E, pady=10, padx=10)
        images_val = StringVar(frame1)
        if self.neb_info['images'][0] is not None:
            images_val.set(self.neb_info['images'][0])
        images_menu  = Entry(frame1, textvariable=images_val)
        images_menu.grid(row=0, column=1, sticky=W, pady=10, padx=10)
        self.neb_info["images"] = [images_val.get(), images_val]
        images_btn = Button(frame1, text="Add Posfiles", command=self.create_window_with_posfiles)
        images_btn.grid(row=0, column=2, sticky=W, pady=10, padx=10)

        #frame for entities
        frame2 = Frame(neb_frame)
        frame2.grid(row=1, column=0)



        #a label frame to add neb related information
        self.neb_entities_frame = LabelFrame(frame2, text="NEB ENTITIES")  
        self.neb_entities_frame.grid(row=0, column=0, columnspan=3, padx=10, pady=10) 
        
         
        for rownum in xrange(self.num_neb_fields):
            self.create_neb_fields(self.neb_entities_frame, rownum)  

        self.add_button = Button(self.neb_entities_frame, text="Add more neb", command=self.add_elements)
        self.add_button.grid(row=self.num_neb_fields + 1, column=0, columnspan=6, pady=10, padx=10)

        #save button
        save_button = Button(neb_frame, text="Save", command=self.save)
        save_button.grid(row=3, column=0, columnspan=2, padx=20, pady=10)

    def add_elements(self):
        self.num_neb_fields += 1
        self.add_button.grid_remove()
        self.create_neb_fields(self.neb_entities_frame, self.num_neb_fields - 1)
        self.add_button = Button(self.neb_entities_frame, text="Add more neb", command=self.add_elements)
        self.add_button.grid(row=self.num_neb_fields + 1, column=0, pady=10, padx=10)

    def save(self):
        self.neb_info['images'][0] = self.neb_info['images'][1].get()
        for rownum in xrange(self.num_neb_fields):
            self.neb_info['startdefect'][0]['N'+str(rownum)]    = self.neb_info['startdefect'][1]['N'+str(rownum)].get()
            self.neb_info['enddefect'][0]['N'+str(rownum)]      = self.neb_info['enddefect'][1]['N'+str(rownum)].get()
            num_fields = self.fields_hash.get('N' + str(rownum), 0)
            for i in xrange(num_fields):
                if 'N' + str(rownum) in self.neb_info['elementmap'][0]:
                    if i < len(self.neb_info['elementmap'][0]['N' + str(rownum)]):
                        self.neb_info['elementmap'][0]['N' + str(rownum)][i] = self.neb_info['elementmap'][1]['N'+str(rownum)][i].get()
                    else:
                        self.neb_info['elementmap'][0]['N' + str(rownum)].append(self.neb_info['elementmap'][1]['N'+str(rownum)][i].get())
                else:
                    self.neb_info['elementmap'][0]['N'+str(rownum)] = [self.neb_info['elementmap'][1]['N'+str(rownum)][i].get()]
                if 'N' + str(rownum) in self.neb_info['startpos'][0]:
                    if i < len(self.neb_info['startpos'][0]['N' + str(rownum)]):
                        self.neb_info['startpos'][0]['N' + str(rownum)][i] = self.neb_info['startpos'][1]['N'+str(rownum)][i].get()
                    else:
                        self.neb_info['startpos'][0]['N' + str(rownum)].append(self.neb_info['startpos'][1]['N'+str(rownum)][i].get())
                else:
                    self.neb_info['startpos'][0]['N'+str(rownum)] = [self.neb_info['startpos'][1]['N'+str(rownum)][i].get()]
                if 'N' + str(rownum) in self.neb_info['endpos'][0]:
                    if i < len(self.neb_info['endpos'][0]['N' + str(rownum)]):
                        self.neb_info['endpos'][0]['N' + str(rownum)][i] = self.neb_info['endpos'][1]['N'+str(rownum)][i].get()
                    else:
                        self.neb_info['endpos'][0]['N' + str(rownum)].append(self.neb_info['endpos'][1]['N'+str(rownum)][i].get())
                else:
                    self.neb_info['endpos'][0]['N'+str(rownum)] = [self.neb_info['endpos'][1]['N'+str(rownum)][i].get()]

            #save the posfile values
            if not self.neb_info['posfiles'][1]:
                continue
            for entry in self.neb_info['posfiles'][1]['N' + str(rownum)]:
                val_list = self.neb_info['posfiles'][0].setdefault('N' + str(rownum), [])
                val_list.append(entry.get())

        self.window.destroy()
        self.window = None
        self.has_summary = True
        self.summary_frame.grid_remove()
        self.summary()

        


    def create_neb_fields(self, frame, rownum):
        elements_map = self.structure_section.get_elements_map()
        elements_options = ["%s (%s)" % (value, key) for key, value in elements_map.iteritems()]
        defects_map = self.defects_section.get_defects_map()
        defects_options = ["%s (%s)" % (value, key) for key, value in defects_map.iteritems()]

        num_fields = self.fields_hash.get('N' + str(rownum), 1)
        self.fields_hash['N' + str(rownum)] = num_fields


        #label frame for this entity
        m_frame = LabelFrame(frame, text="N" + str(rownum))
        m_frame.grid(row=rownum, column=0, padx=10, pady=10)

        e_frame = Frame(m_frame)
        e_frame.grid(row=0, column=0)
        p_frame = Frame(m_frame)
        p_frame.grid(row=1, column=0)

        #create field headers 
        start_label = Label(e_frame, text="START DEFECT")
        start_label.grid(row=0, column=0, padx=10, pady=10, sticky=W)
        end_label = Label(e_frame, text="END DEFECT")
        end_label.grid(row=0, column=1, padx=10, pady=10, sticky=W)
        element_label = Label(e_frame, text="ELEMENT")
        element_label.grid(row=0, column=2, padx=10, pady=10, sticky=W)
        start_pos = Label(e_frame, text="START POSITION")
        start_pos.grid(row=0, column=3, padx=10, pady=10, sticky=W)
        end_pos = Label(e_frame, text="END POSITION")
        end_pos.grid(row=0, column=4, padx=10, pady=10, sticky=W)



        start_defect = StringVar(e_frame)
        start_defect_val = None
        if self.neb_info['startdefect'][0] and ('N' + str(rownum)) in self.neb_info['startdefect'][0]:
            start_defect_val = self.neb_info['startdefect'][0]['N' + str(rownum)]
        s_option_menu = OptionMenu(e_frame, start_defect, ())
        s_option_menu.grid(row=1, column=0, sticky=W, pady=10, padx=10)
        self.add_options(s_option_menu, defects_options, start_defect, start_defect_val)
        self.neb_info['startdefect'][1]['N' + str(rownum)] = start_defect

        end_defect = StringVar(e_frame)
        end_defect_val = None
        if self.neb_info['enddefect'][0] and ('N' + str(rownum)) in self.neb_info['enddefect'][0]:
            end_defect_val = self.neb_info['enddefect'][0]['N' + str(rownum)]
        e_option_menu = OptionMenu(e_frame, end_defect, ())
        e_option_menu.grid(row=1, column=1, sticky=W, pady=10, padx=10)
        self.add_options(e_option_menu, defects_options, end_defect, end_defect_val)
        self.neb_info['enddefect'][1]['N' + str(rownum)] = end_defect

        for i in xrange(num_fields):
            self.create_individual_fields(e_frame, elements_options, rownum, i + 1)

        #put the pos file input boxes
        #add posfiles if needed
        if self.neb_info['images'][0] is not None and self.neb_info['images'][0] != "" and int(self.neb_info['images'][0]) > 0:
            label = Label(p_frame, text="POSFILES")
            label.grid(row=0, column=0, sticky=E, pady=10, padx=10)
            pos_files_frame = Frame(p_frame)
            pos_files_frame.grid(row=0, column=1, sticky=W, pady=10, padx=10)
            #create boxes
            for i in xrange(int(self.neb_info['images'][0])):
                entry_val = StringVar(pos_files_frame)
                if 'N' + str(rownum) in self.neb_info['posfiles'][0] and len(self.neb_info['posfiles'][0]['N' + str(rownum)]) >= i + 1:
                    entry_val.set(self.neb_info['posfiles'][0]['N' + str(rownum)][i])
                    self.neb_info['posfiles'][1]['N' + str(rownum)][i] = entry_val
                else:
                    if not self.neb_info['posfiles'][1] or 'N' + str(rownum) not in self.neb_info['posfiles'][1]:
                        self.neb_info['posfiles'][1]['N' + str(rownum)] = [entry_val]
                    else:
                        self.neb_info['posfiles'][1]['N' + str(rownum)].append(entry_val)
                pos_entry = Entry(pos_files_frame, textvariable=entry_val)
                pos_entry.grid(row=i, column=0, sticky=W)


    def create_individual_fields(self, e_frame, elements_options, neb_id, rownum):
        element = StringVar(e_frame)
        element_val = None
        if self.neb_info['elementmap'][0] and ('N' + str(neb_id)) in self.neb_info['elementmap'][0] and \
                rownum <= len(self.neb_info['elementmap'][0]['N' + str(neb_id)]):
            element_val = self.neb_info['elementmap'][0]['N' + str(neb_id)][rownum - 1]
        option_menu = OptionMenu(e_frame, element, ())
        option_menu.grid(row=rownum, column=2, sticky=W, pady=10, padx=10)
        self.add_options(option_menu, elements_options, element, element_val)
        if 'N' + str(neb_id) in self.neb_info['elementmap'][1]:
            if rownum <= len(self.neb_info['elementmap'][1]['N' + str(neb_id)]):
                self.neb_info['elementmap'][1]['N' + str(neb_id)][rownum - 1] = element
            else:
                self.neb_info['elementmap'][1]['N' + str(neb_id)].append(element)
        else:
                self.neb_info['elementmap'][1]['N' + str(neb_id)] = [element]
         
        startpos_text = StringVar()
        if self.neb_info['startpos'][0] and ('N' + str(neb_id)) in self.neb_info['startpos'][0] and \
                rownum <= len(self.neb_info['startpos'][0]['N' + str(neb_id)]):
            startpos_text.set(self.neb_info['startpos'][0]['N'+str(neb_id)][rownum - 1])
        startpos_val  = Entry(e_frame, textvariable=startpos_text)
        startpos_val.grid(row=rownum, column=3, pady=10, padx=10, sticky=W)
        if 'N' + str(neb_id) in self.neb_info['startpos'][1]:
            if rownum <= len(self.neb_info['startpos'][1]['N' + str(neb_id)]):
                self.neb_info['startpos'][1]['N' + str(neb_id)][rownum - 1] = startpos_text
            else:
                self.neb_info['startpos'][1]['N' + str(neb_id)].append(startpos_text)
        else:
                self.neb_info['startpos'][1]['N' + str(neb_id)] = [startpos_text]

        endpos_text = StringVar()
        if self.neb_info['endpos'][0] and ('N' + str(rownum)) in self.neb_info['endpos'][0] and \
                rownum <= len(self.neb_info['endpos'][0]['N' + str(neb_id)]):
            endpos_text.set(self.neb_info['endpos'][0]['N'+str(neb_id)][rownum - 1])
        endpos_val  = Entry(e_frame, textvariable=endpos_text)
        endpos_val.grid(row=rownum, column=4, pady=10, padx=10, sticky=W)
        if 'N' + str(neb_id) in self.neb_info['endpos'][1]:
            if rownum <= len(self.neb_info['endpos'][1]['N' + str(neb_id)]):
                self.neb_info['endpos'][1]['N' + str(neb_id)][rownum - 1] = endpos_text
            else:
                self.neb_info['endpos'][1]['N' + str(neb_id)].append(endpos_text)
        else:
                self.neb_info['endpos'][1]['N' + str(neb_id)] = [endpos_text]

        add_button = Button(e_frame, text="+")
        add_button.grid(row=rownum, column=5, pady=10, padx=10)
        add_button.configure(command=lambda:self.add_neb_field(add_button, e_frame, rownum, elements_options, neb_id))

    def add_neb_field(self, add_button, e_frame, rownum, elements_options, neb_id):
        add_button.grid_remove()
        num_fields = self.fields_hash.get('N' + str(neb_id), 1)
        self.fields_hash['N' + str(neb_id)] = num_fields + 1
        self.create_individual_fields(e_frame, elements_options, neb_id, rownum + 1)

    def add_options(self, option_menu, options, element_var, index_val):
        menu = option_menu["menu"]
        menu.delete(0, "end")
        for string in options:
            menu.add_command(label=string, command=lambda value=string:element_var.set(value))
        if index_val is not None:
            element_var.set(index_val)
コード例 #12
0
ファイル: structure.py プロジェクト: ZhewenSong/USIT
class StructureSection:
    def __init__(self, parent_window, grid_row):
        self.parent_window = parent_window
        self.grid_row = grid_row
        self.summary_frame = None
        self.structure_info = {\
                                  'coord_type' : [None, None],\
                                  'posfile'    : [None, None],\
                                  'elementmap' : [{}, {}],\
                                  'lattice'    : [None, None],\
                                  'coordinates': [{}, {}],\
                              }
        self.num_elt_fields = 1
        self.has_summary = False

    def get_elements_map(self):
        return self.structure_info['elementmap'][0]

    def content(self):
        content_start = "$structure\n"
        content_end   = "$end\n\n"

        content_lines = ""

        if self.structure_info['coord_type'][0]:
            content_lines += "coord_type %s\n\n" % self.structure_info['coord_type'][0]

        if self.structure_info['posfile'][0]:
            content_lines += "posfile %s\n\n" % self.structure_info['posfile'][0]

        if self.structure_info['elementmap'][0]:
            content_lines += "begin elementmap\n"
            for elt_key, elt_name in self.structure_info['elementmap'][0].iteritems():
                content_lines += "%s %s\n" % (elt_key, elt_name)
            content_lines += "end\n\n"

        if self.structure_info['coordinates'][0]:
            content_lines += "begin coordinates\n"
            for elt_key, elt_coord in self.structure_info['coordinates'][0].iteritems():
                coord_lines = elt_coord.split('\n')
                for line in coord_lines:
                    if line:
                        content_lines += "%s %s\n" % (elt_key, line)
            content_lines += "end\n\n"

        if self.structure_info['lattice'][0]:
            content_lines += "begin lattice\n"
            content_lines += "%s\n" % self.structure_info['lattice'][0] 
            content_lines += "end\n\n" 

        return content_start + content_lines + content_end
    
    def summary(self):
        #the frame which encloses all the contents
        self.summary_frame = LabelFrame(self.parent_window, text="Structure")
        self.summary_frame.grid_rowconfigure(0, weight=1)
        self.summary_frame.grid_rowconfigure(1, weight=1)
        self.summary_frame.grid_columnconfigure(0, weight=1)
        self.summary_frame.grid_columnconfigure(1, weight=1)
        self.summary_frame.grid_columnconfigure(2, weight=1)

        #if it has summary show it
        if self.has_summary:
           #coord_type
           coord_type = Label(self.summary_frame, text="COORD_TYPE :")   
           coord_type.grid(row=0, column=1, sticky=E, pady=5)
           coord_type_value = Label(self.summary_frame, text=self.structure_info['coord_type'][0])
           coord_type_value.grid(row=0, column=2, sticky=W, pady=5)

           #posfile
           if self.structure_info['posfile'][0].strip() != "":
               posfile = Label(self.summary_frame, text="POSFILE :")   
               posfile.grid(row=1, column=1, sticky=E, pady=5)
               posfile_value = Label(self.summary_frame, text=self.structure_info['posfile'][0])
               posfile_value.grid(row=1, column=2, sticky=W, pady=5)

           #lattice structure
           lattice = Label(self.summary_frame, text="LATTICE : ")
           lattice.grid(row=2, column=1, sticky=E, pady=5)
           lattice_value = Label(self.summary_frame, text=self.structure_info['lattice'][0])
           lattice_value.grid(row=2, column=2, sticky=W, pady=5)

           for row_num in xrange(self.num_elt_fields + 1):
               if row_num == 0:
                   continue
               if self.structure_info['elementmap'][0]['X' + str(row_num)].strip() == "":
                   continue
               id_label = Label(self.summary_frame, text='X'+ str(row_num))
               id_label.grid(row=2 + row_num, column=0, padx=10, pady=2, sticky=E)
               element_label = Label(self.summary_frame, text=self.structure_info['elementmap'][0]['X'+str(row_num)])
               element_label.grid(row=2 + row_num, column=1, padx=10, pady=2, sticky=W)
               coordinates_label = Label(self.summary_frame, text=self.structure_info['coordinates'][0]['X'+str(row_num)])
               coordinates_label.grid(row=2 + row_num, column=2, padx=10, pady=2, sticky=W)
           


        #the frame contents
        add_button = Button(self.summary_frame, text="Add Structure properties", command=self.create_window)
        add_button.grid(row=3 + self.num_elt_fields, column=0, columnspan=3, pady=20, padx=20)

        self.summary_frame.grid(row=self.grid_row, column=0, padx=20, pady=5, sticky=W+E)

    def create_window(self):
        self.window = ttk.Toplevel(self.parent_window)
        self.window.title("Structure Information")
        self.window.minsize(500, 500)
        self.vframe = VerticalScrolledFrame(self.window)
        self.vframe.pack(fill=BOTH, expand=1)
        self.structure_window = self.vframe.interior
        self.structure_window.grid_rowconfigure(0, weight=1)
        self.structure_window.grid_columnconfigure(0, weight=1)
        self.structure_window.grid_rowconfigure(0, weight=1)
        self.structure_window.grid_columnconfigure(0, weight=1)

        structure_frame = LabelFrame(self.structure_window, text="Structure")
        structure_frame.grid(row=0, column=0, padx=20, pady=20)
        structure_frame.grid_rowconfigure(0, weight=1)
        structure_frame.grid_rowconfigure(1, weight=1)
        structure_frame.grid_columnconfigure(0, weight=1)
        structure_frame.grid_columnconfigure(1, weight=1)

        #add coordtype 
        label = Label(structure_frame, text="COORD_TYPE")
        label.grid(row=0, column=0, sticky=E, pady=10, padx=10)
        coord_type = StringVar(structure_frame)
        coord_type.set("fractional")
        if self.structure_info['coord_type'][0] is not None:
            coord_type.set(self.structure_info['coord_type'][0])
        coord_type_option = OptionMenu(structure_frame, coord_type, "fractional", "cartesian")  
        coord_type_option.grid(row=0, column=1, sticky=W, pady=10, padx=10)
        self.structure_info["coord_type"] = [coord_type.get(), coord_type]

        #pos file
        label = Label(structure_frame, text="POSFILE")
        label.grid(row=1, column=0, sticky=E, pady=10, padx=10)
        text_val = StringVar()
        if self.structure_info['posfile'][0] is not None:
            text_val.set(self.structure_info['posfile'][0])
        text  = Entry(structure_frame, textvariable=text_val)
        text.grid(row=1, column=1, sticky=W, pady=10, padx=10)
        self.structure_info['posfile'] = [text_val.get(), text_val]
        
      
        #pos file
        label = Label(structure_frame, text="LATTICE")
        label.grid(row=2, column=0, sticky=E, pady=10, padx=10)
        text  = Text(structure_frame, height=5, width=30)
        if self.structure_info['lattice'][0] is not None:
            text.insert('1.0', self.structure_info['lattice'][0])
        text.grid(row=2, column=1, sticky=W, pady=10, padx=10)
        self.structure_info['lattice'][1] = text

        #label frame to add elements info
        self.elements_frame =  LabelFrame(structure_frame, text="ELEMENTS INFORMATION")
        self.elements_frame.grid(row=3, column=0, columnspan=2, pady=10, padx=10)
        #create field headers 
        id_label = Label(self.elements_frame, text="ID")
        id_label.grid(row=0, column=0, padx=10, pady=10, sticky=W)
        element_label = Label(self.elements_frame, text="ELEMENT")
        element_label.grid(row=0, column=1, padx=10, pady=10, sticky=W)
        coordinates_label = Label(self.elements_frame, text="COORDINATES")
        coordinates_label.grid(row=0, column=2, padx=10, pady=10, sticky=W)

        for row_num in xrange(self.num_elt_fields + 1):
            if row_num == 0:
                continue
            self.create_element_fields(self.elements_frame, row_num)
        
        self.add_button = Button(self.elements_frame, text="Add more elements", command=self.add_elements)
        self.add_button.grid(row=self.num_elt_fields + 1, column=0, columnspan=3, pady=10, padx=10)

        #save button
        save_button = Button(structure_frame, text="Save", command=self.save)
        save_button.grid(row=4, column=0, columnspan=2, padx=20, pady=10)

    def save(self):
        self.structure_info['coord_type'][0] = self.structure_info['coord_type'][1].get()
        self.structure_info['posfile'][0] = self.structure_info['posfile'][1].get()
        self.structure_info['lattice'][0] = self.structure_info['lattice'][1].get("1.0", END)
        for row_num in xrange(self.num_elt_fields + 1):
            if row_num == 0:
                continue
            self.structure_info['elementmap'][0]['X'+str(row_num)] = self.structure_info['elementmap'][1]['X'+str(row_num)].get()
            self.structure_info['coordinates'][0]['X'+str(row_num)] = self.structure_info['coordinates'][1]['X'+str(row_num)].get("1.0", END)

        self.window.destroy()
        self.window = None
        self.has_summary = True
        self.summary_frame.grid_remove()
        self.summary()

    def add_elements(self):
        self.num_elt_fields += 1
        self.add_button.grid_remove()
        self.create_element_fields(self.elements_frame, self.num_elt_fields)
        self.add_button = Button(self.elements_frame, text="Add more elements", command=self.add_elements)
        self.add_button.grid(row=self.num_elt_fields + 1, column=0, columnspan=3, pady=10, padx=10)


    def create_element_fields(self, elements_frame, row_num):
        id_label = Label(elements_frame, text="X" + str(row_num))
        id_label.grid(row=row_num, column=0, padx=10, pady=10, sticky=W)
        text_val = StringVar()
        if self.structure_info['elementmap'][0] and ('X' + str(row_num)) in self.structure_info['elementmap'][0]:
            text_val.set(self.structure_info['elementmap'][0]['X'+str(row_num)])
        element_name  = Entry(elements_frame, textvariable=text_val)
        element_name.grid(row=row_num, column=1, pady=10, padx=10, sticky=W)
        self.structure_info['elementmap'][1]['X'+ str(row_num)] = text_val
        coordinates  = Text(elements_frame, height=5, width=30)
        if self.structure_info['coordinates'][0] and ('X' + str(row_num)) in self.structure_info['coordinates'][0]:
            coordinates.insert('1.0', self.structure_info['coordinates'][0]['X' + str(row_num)])
        coordinates.grid(row=row_num, column=2, pady=10, padx=10, sticky=W)
        self.structure_info['coordinates'][1]['X'+ str(row_num)] = coordinates
コード例 #13
0
ファイル: structure.py プロジェクト: ZhewenSong/USIT
    def create_window(self):
        self.window = ttk.Toplevel(self.parent_window)
        self.window.title("Structure Information")
        self.window.minsize(500, 500)
        self.vframe = VerticalScrolledFrame(self.window)
        self.vframe.pack(fill=BOTH, expand=1)
        self.structure_window = self.vframe.interior
        self.structure_window.grid_rowconfigure(0, weight=1)
        self.structure_window.grid_columnconfigure(0, weight=1)
        self.structure_window.grid_rowconfigure(0, weight=1)
        self.structure_window.grid_columnconfigure(0, weight=1)

        structure_frame = LabelFrame(self.structure_window, text="Structure")
        structure_frame.grid(row=0, column=0, padx=20, pady=20)
        structure_frame.grid_rowconfigure(0, weight=1)
        structure_frame.grid_rowconfigure(1, weight=1)
        structure_frame.grid_columnconfigure(0, weight=1)
        structure_frame.grid_columnconfigure(1, weight=1)

        #add coordtype 
        label = Label(structure_frame, text="COORD_TYPE")
        label.grid(row=0, column=0, sticky=E, pady=10, padx=10)
        coord_type = StringVar(structure_frame)
        coord_type.set("fractional")
        if self.structure_info['coord_type'][0] is not None:
            coord_type.set(self.structure_info['coord_type'][0])
        coord_type_option = OptionMenu(structure_frame, coord_type, "fractional", "cartesian")  
        coord_type_option.grid(row=0, column=1, sticky=W, pady=10, padx=10)
        self.structure_info["coord_type"] = [coord_type.get(), coord_type]

        #pos file
        label = Label(structure_frame, text="POSFILE")
        label.grid(row=1, column=0, sticky=E, pady=10, padx=10)
        text_val = StringVar()
        if self.structure_info['posfile'][0] is not None:
            text_val.set(self.structure_info['posfile'][0])
        text  = Entry(structure_frame, textvariable=text_val)
        text.grid(row=1, column=1, sticky=W, pady=10, padx=10)
        self.structure_info['posfile'] = [text_val.get(), text_val]
        
      
        #pos file
        label = Label(structure_frame, text="LATTICE")
        label.grid(row=2, column=0, sticky=E, pady=10, padx=10)
        text  = Text(structure_frame, height=5, width=30)
        if self.structure_info['lattice'][0] is not None:
            text.insert('1.0', self.structure_info['lattice'][0])
        text.grid(row=2, column=1, sticky=W, pady=10, padx=10)
        self.structure_info['lattice'][1] = text

        #label frame to add elements info
        self.elements_frame =  LabelFrame(structure_frame, text="ELEMENTS INFORMATION")
        self.elements_frame.grid(row=3, column=0, columnspan=2, pady=10, padx=10)
        #create field headers 
        id_label = Label(self.elements_frame, text="ID")
        id_label.grid(row=0, column=0, padx=10, pady=10, sticky=W)
        element_label = Label(self.elements_frame, text="ELEMENT")
        element_label.grid(row=0, column=1, padx=10, pady=10, sticky=W)
        coordinates_label = Label(self.elements_frame, text="COORDINATES")
        coordinates_label.grid(row=0, column=2, padx=10, pady=10, sticky=W)

        for row_num in xrange(self.num_elt_fields + 1):
            if row_num == 0:
                continue
            self.create_element_fields(self.elements_frame, row_num)
        
        self.add_button = Button(self.elements_frame, text="Add more elements", command=self.add_elements)
        self.add_button.grid(row=self.num_elt_fields + 1, column=0, columnspan=3, pady=10, padx=10)

        #save button
        save_button = Button(structure_frame, text="Save", command=self.save)
        save_button.grid(row=4, column=0, columnspan=2, padx=20, pady=10)
コード例 #14
0
class NEBSection:
    def __init__(self, parent_window, grid_row, structure_section,
                 defects_section):
        self.parent_window = parent_window
        self.grid_row = grid_row
        self.structure_section = structure_section
        self.defects_section = defects_section
        self.has_summary = False
        self.neb_info = {\
                            'images'       : [None, None],\
                            'posfiles'     : [{}, {}],\
                            'startdefect'  : [{}, {}],\
                            'enddefect'    : [{}, {}],\
                            'elementmap'   : [{}, {}],\
                            'startpos'     : [{}, {}],\
                            'endpos'       : [{}, {}],\
                        }
        self.num_neb_fields = 1
        self.fields_hash = {}

    def content(self):
        content_start = "$neb\n"
        content_end = "$end\n\n"
        content_lines = ""

        if self.neb_info['startdefect'][0]:
            for n_id, s_defect in self.neb_info['startdefect'][0].iteritems():
                if n_id not in self.neb_info['enddefect'][0]:
                    continue
                content_lines += "begin %s-%s\n" % (s_defect.split(
                    '(',
                    1)[0].strip(), self.neb_info['enddefect'][0][n_id].split(
                        '(', 1)[0].strip())
                if n_id in self.neb_info['elementmap'][0]:
                    for idx, elt in enumerate(
                            self.neb_info['elementmap'][0][n_id]):
                        elt = elt.split('(', 1)[1].replace(')', '').strip()
                        content_lines += "%s, %s, %s\n" % (
                            elt, self.neb_info['startpos'][0][n_id][idx],
                            self.neb_info['endpos'][0][n_id][idx])
                if n_id in self.neb_info['posfiles'][0]:
                    content_lines += "posfile %s\n" % ",".join(
                        self.neb_info['posfiles'][0][n_id])

                content_lines += "end\n\n"

        if self.neb_info['images'][0]:
            content_lines += "images %s\n" % self.neb_info['images'][0]

        return content_start + content_lines + content_end

    def summary(self):
        #the frame which encloses all the contents
        self.summary_frame = LabelFrame(self.parent_window, text="NEB")
        self.summary_frame.grid_rowconfigure(0, weight=1)
        self.summary_frame.grid_rowconfigure(1, weight=1)
        self.summary_frame.grid_columnconfigure(0, weight=1)
        self.summary_frame.grid_columnconfigure(1, weight=1)
        self.summary_frame.grid_columnconfigure(2, weight=1)
        self.summary_frame.grid_columnconfigure(3, weight=1)
        self.summary_frame.grid_columnconfigure(4, weight=1)
        self.summary_frame.grid_columnconfigure(5, weight=1)

        #if it has summary show it
        if self.has_summary:
            #coord_type
            images = Label(self.summary_frame, text="IMAGES :")
            images.grid(row=0, column=2, sticky=E, pady=5)
            images_value = Label(self.summary_frame,
                                 text=self.neb_info['images'][0])
            images_value.grid(row=0, column=3, sticky=W, pady=5)

            for rownum in xrange(self.num_neb_fields):
                if self.neb_info['startdefect'][0]['N' +
                                                   str(rownum)].strip() == "":
                    continue
                id_label = Label(self.summary_frame, text='N' + str(rownum))
                id_label.grid(row=2 + rownum,
                              column=0,
                              padx=10,
                              pady=2,
                              sticky=E)
                s_defect_label = Label(
                    self.summary_frame,
                    text=self.neb_info['startdefect'][0]['N' + str(rownum)])
                s_defect_label.grid(row=2 + rownum,
                                    column=1,
                                    padx=10,
                                    pady=2,
                                    sticky=E)
                e_defect_label = Label(
                    self.summary_frame,
                    text=self.neb_info['enddefect'][0]['N' + str(rownum)])
                e_defect_label.grid(row=2 + rownum,
                                    column=2,
                                    padx=10,
                                    pady=2,
                                    sticky=E)
                element_label = Label(
                    self.summary_frame,
                    text=self.neb_info['elementmap'][0]['N' + str(rownum)][0])
                element_label.grid(row=2 + rownum,
                                   column=3,
                                   padx=10,
                                   pady=2,
                                   sticky=E)
                s_pos_label = Label(
                    self.summary_frame,
                    text=self.neb_info['startpos'][0]['N' + str(rownum)][0])
                s_pos_label.grid(row=2 + rownum,
                                 column=4,
                                 padx=10,
                                 pady=2,
                                 sticky=E)
                e_pos_label = Label(
                    self.summary_frame,
                    text=self.neb_info['endpos'][0]['N' + str(rownum)][0])
                e_pos_label.grid(row=2 + rownum,
                                 column=5,
                                 padx=10,
                                 pady=2,
                                 sticky=E)

        #the frame contents
        add_button = Button(self.summary_frame,
                            text="Add NEB properties",
                            command=self.create_window)
        add_button.grid(row=3 + self.num_neb_fields,
                        column=0,
                        columnspan=7,
                        pady=20,
                        padx=20)

        self.summary_frame.grid(row=self.grid_row,
                                column=0,
                                sticky=W + E,
                                padx=20,
                                pady=5)

    def create_window_with_posfiles(self):
        self.neb_info['images'][0] = self.neb_info['images'][1].get()
        self.window.destroy()
        self.window = None
        self.create_window()

    def create_window(self):
        self.window = ttk.Toplevel(self.parent_window)
        self.window.title("NEB Information")
        self.window.minsize(500, 500)
        self.vframe = VerticalScrolledFrame(self.window)
        self.vframe.pack(fill=BOTH, expand=1)
        self.neb_window = self.vframe.interior
        self.neb_window.grid_rowconfigure(0, weight=1)
        self.neb_window.grid_columnconfigure(0, weight=1)

        neb_frame = LabelFrame(self.neb_window, text="NEB")
        neb_frame.grid(row=0, column=0, padx=20, pady=20)
        neb_frame.grid_rowconfigure(0, weight=1)
        neb_frame.grid_columnconfigure(0, weight=1)

        #frame for images and button
        frame1 = Frame(neb_frame)
        frame1.grid(row=0, column=0)
        frame1.grid_rowconfigure(0, weight=1)
        frame1.grid_rowconfigure(1, weight=1)
        frame1.grid_columnconfigure(0, weight=1)
        frame1.grid_columnconfigure(1, weight=1)
        frame1.grid_columnconfigure(2, weight=1)

        #add images
        label = Label(frame1, text="IMAGES")
        label.grid(row=0, column=0, sticky=E, pady=10, padx=10)
        images_val = StringVar(frame1)
        if self.neb_info['images'][0] is not None:
            images_val.set(self.neb_info['images'][0])
        images_menu = Entry(frame1, textvariable=images_val)
        images_menu.grid(row=0, column=1, sticky=W, pady=10, padx=10)
        self.neb_info["images"] = [images_val.get(), images_val]
        images_btn = Button(frame1,
                            text="Add Posfiles",
                            command=self.create_window_with_posfiles)
        images_btn.grid(row=0, column=2, sticky=W, pady=10, padx=10)

        #frame for entities
        frame2 = Frame(neb_frame)
        frame2.grid(row=1, column=0)

        #a label frame to add neb related information
        self.neb_entities_frame = LabelFrame(frame2, text="NEB ENTITIES")
        self.neb_entities_frame.grid(row=0,
                                     column=0,
                                     columnspan=3,
                                     padx=10,
                                     pady=10)

        for rownum in xrange(self.num_neb_fields):
            self.create_neb_fields(self.neb_entities_frame, rownum)

        self.add_button = Button(self.neb_entities_frame,
                                 text="Add more neb",
                                 command=self.add_elements)
        self.add_button.grid(row=self.num_neb_fields + 1,
                             column=0,
                             columnspan=6,
                             pady=10,
                             padx=10)

        #save button
        save_button = Button(neb_frame, text="Save", command=self.save)
        save_button.grid(row=3, column=0, columnspan=2, padx=20, pady=10)

    def add_elements(self):
        self.num_neb_fields += 1
        self.add_button.grid_remove()
        self.create_neb_fields(self.neb_entities_frame,
                               self.num_neb_fields - 1)
        self.add_button = Button(self.neb_entities_frame,
                                 text="Add more neb",
                                 command=self.add_elements)
        self.add_button.grid(row=self.num_neb_fields + 1,
                             column=0,
                             pady=10,
                             padx=10)

    def save(self):
        self.neb_info['images'][0] = self.neb_info['images'][1].get()
        for rownum in xrange(self.num_neb_fields):
            self.neb_info['startdefect'][0]['N' + str(
                rownum)] = self.neb_info['startdefect'][1]['N' +
                                                           str(rownum)].get()
            self.neb_info['enddefect'][0]['N' + str(
                rownum)] = self.neb_info['enddefect'][1]['N' +
                                                         str(rownum)].get()
            num_fields = self.fields_hash.get('N' + str(rownum), 0)
            for i in xrange(num_fields):
                if 'N' + str(rownum) in self.neb_info['elementmap'][0]:
                    if i < len(
                            self.neb_info['elementmap'][0]['N' + str(rownum)]):
                        self.neb_info['elementmap'][0][
                            'N' +
                            str(rownum)][i] = self.neb_info['elementmap'][1][
                                'N' + str(rownum)][i].get()
                    else:
                        self.neb_info['elementmap'][0][
                            'N' + str(rownum)].append(
                                self.neb_info['elementmap'][1][
                                    'N' + str(rownum)][i].get())
                else:
                    self.neb_info['elementmap'][0]['N' + str(rownum)] = [
                        self.neb_info['elementmap'][1]['N' +
                                                       str(rownum)][i].get()
                    ]
                if 'N' + str(rownum) in self.neb_info['startpos'][0]:
                    if i < len(
                            self.neb_info['startpos'][0]['N' + str(rownum)]):
                        self.neb_info['startpos'][0][
                            'N' +
                            str(rownum)][i] = self.neb_info['startpos'][1][
                                'N' + str(rownum)][i].get()
                    else:
                        self.neb_info['startpos'][0]['N' + str(rownum)].append(
                            self.neb_info['startpos'][1]['N' +
                                                         str(rownum)][i].get())
                else:
                    self.neb_info['startpos'][0]['N' + str(rownum)] = [
                        self.neb_info['startpos'][1]['N' +
                                                     str(rownum)][i].get()
                    ]
                if 'N' + str(rownum) in self.neb_info['endpos'][0]:
                    if i < len(self.neb_info['endpos'][0]['N' + str(rownum)]):
                        self.neb_info['endpos'][0][
                            'N' + str(rownum)][i] = self.neb_info['endpos'][1][
                                'N' + str(rownum)][i].get()
                    else:
                        self.neb_info['endpos'][0]['N' + str(rownum)].append(
                            self.neb_info['endpos'][1]['N' +
                                                       str(rownum)][i].get())
                else:
                    self.neb_info['endpos'][0]['N' + str(rownum)] = [
                        self.neb_info['endpos'][1]['N' + str(rownum)][i].get()
                    ]

            #save the posfile values
            if not self.neb_info['posfiles'][1]:
                continue
            for entry in self.neb_info['posfiles'][1]['N' + str(rownum)]:
                val_list = self.neb_info['posfiles'][0].setdefault(
                    'N' + str(rownum), [])
                val_list.append(entry.get())

        self.window.destroy()
        self.window = None
        self.has_summary = True
        self.summary_frame.grid_remove()
        self.summary()

    def create_neb_fields(self, frame, rownum):
        elements_map = self.structure_section.get_elements_map()
        elements_options = [
            "%s (%s)" % (value, key)
            for key, value in elements_map.iteritems()
        ]
        defects_map = self.defects_section.get_defects_map()
        defects_options = [
            "%s (%s)" % (value, key) for key, value in defects_map.iteritems()
        ]

        num_fields = self.fields_hash.get('N' + str(rownum), 1)
        self.fields_hash['N' + str(rownum)] = num_fields

        #label frame for this entity
        m_frame = LabelFrame(frame, text="N" + str(rownum))
        m_frame.grid(row=rownum, column=0, padx=10, pady=10)

        e_frame = Frame(m_frame)
        e_frame.grid(row=0, column=0)
        p_frame = Frame(m_frame)
        p_frame.grid(row=1, column=0)

        #create field headers
        start_label = Label(e_frame, text="START DEFECT")
        start_label.grid(row=0, column=0, padx=10, pady=10, sticky=W)
        end_label = Label(e_frame, text="END DEFECT")
        end_label.grid(row=0, column=1, padx=10, pady=10, sticky=W)
        element_label = Label(e_frame, text="ELEMENT")
        element_label.grid(row=0, column=2, padx=10, pady=10, sticky=W)
        start_pos = Label(e_frame, text="START POSITION")
        start_pos.grid(row=0, column=3, padx=10, pady=10, sticky=W)
        end_pos = Label(e_frame, text="END POSITION")
        end_pos.grid(row=0, column=4, padx=10, pady=10, sticky=W)

        start_defect = StringVar(e_frame)
        start_defect_val = None
        if self.neb_info['startdefect'][0] and (
                'N' + str(rownum)) in self.neb_info['startdefect'][0]:
            start_defect_val = self.neb_info['startdefect'][0]['N' +
                                                               str(rownum)]
        s_option_menu = OptionMenu(e_frame, start_defect, ())
        s_option_menu.grid(row=1, column=0, sticky=W, pady=10, padx=10)
        self.add_options(s_option_menu, defects_options, start_defect,
                         start_defect_val)
        self.neb_info['startdefect'][1]['N' + str(rownum)] = start_defect

        end_defect = StringVar(e_frame)
        end_defect_val = None
        if self.neb_info['enddefect'][0] and (
                'N' + str(rownum)) in self.neb_info['enddefect'][0]:
            end_defect_val = self.neb_info['enddefect'][0]['N' + str(rownum)]
        e_option_menu = OptionMenu(e_frame, end_defect, ())
        e_option_menu.grid(row=1, column=1, sticky=W, pady=10, padx=10)
        self.add_options(e_option_menu, defects_options, end_defect,
                         end_defect_val)
        self.neb_info['enddefect'][1]['N' + str(rownum)] = end_defect

        for i in xrange(num_fields):
            self.create_individual_fields(e_frame, elements_options, rownum,
                                          i + 1)

        #put the pos file input boxes
        #add posfiles if needed
        if self.neb_info['images'][0] is not None and self.neb_info['images'][
                0] != "" and int(self.neb_info['images'][0]) > 0:
            label = Label(p_frame, text="POSFILES")
            label.grid(row=0, column=0, sticky=E, pady=10, padx=10)
            pos_files_frame = Frame(p_frame)
            pos_files_frame.grid(row=0, column=1, sticky=W, pady=10, padx=10)
            #create boxes
            for i in xrange(int(self.neb_info['images'][0])):
                entry_val = StringVar(pos_files_frame)
                if 'N' + str(rownum) in self.neb_info['posfiles'][0] and len(
                        self.neb_info['posfiles'][0]['N' +
                                                     str(rownum)]) >= i + 1:
                    entry_val.set(self.neb_info['posfiles'][0]['N' +
                                                               str(rownum)][i])
                    self.neb_info['posfiles'][1]['N' +
                                                 str(rownum)][i] = entry_val
                else:
                    if not self.neb_info['posfiles'][1] or 'N' + str(
                            rownum) not in self.neb_info['posfiles'][1]:
                        self.neb_info['posfiles'][1]['N' + str(rownum)] = [
                            entry_val
                        ]
                    else:
                        self.neb_info['posfiles'][1]['N' + str(rownum)].append(
                            entry_val)
                pos_entry = Entry(pos_files_frame, textvariable=entry_val)
                pos_entry.grid(row=i, column=0, sticky=W)

    def create_individual_fields(self, e_frame, elements_options, neb_id,
                                 rownum):
        element = StringVar(e_frame)
        element_val = None
        if self.neb_info['elementmap'][0] and ('N' + str(neb_id)) in self.neb_info['elementmap'][0] and \
                rownum <= len(self.neb_info['elementmap'][0]['N' + str(neb_id)]):
            element_val = self.neb_info['elementmap'][0]['N' +
                                                         str(neb_id)][rownum -
                                                                      1]
        option_menu = OptionMenu(e_frame, element, ())
        option_menu.grid(row=rownum, column=2, sticky=W, pady=10, padx=10)
        self.add_options(option_menu, elements_options, element, element_val)
        if 'N' + str(neb_id) in self.neb_info['elementmap'][1]:
            if rownum <= len(
                    self.neb_info['elementmap'][1]['N' + str(neb_id)]):
                self.neb_info['elementmap'][1]['N' + str(neb_id)][rownum -
                                                                  1] = element
            else:
                self.neb_info['elementmap'][1]['N' +
                                               str(neb_id)].append(element)
        else:
            self.neb_info['elementmap'][1]['N' + str(neb_id)] = [element]

        startpos_text = StringVar()
        if self.neb_info['startpos'][0] and ('N' + str(neb_id)) in self.neb_info['startpos'][0] and \
                rownum <= len(self.neb_info['startpos'][0]['N' + str(neb_id)]):
            startpos_text.set(
                self.neb_info['startpos'][0]['N' + str(neb_id)][rownum - 1])
        startpos_val = Entry(e_frame, textvariable=startpos_text)
        startpos_val.grid(row=rownum, column=3, pady=10, padx=10, sticky=W)
        if 'N' + str(neb_id) in self.neb_info['startpos'][1]:
            if rownum <= len(self.neb_info['startpos'][1]['N' + str(neb_id)]):
                self.neb_info['startpos'][1]['N' +
                                             str(neb_id)][rownum -
                                                          1] = startpos_text
            else:
                self.neb_info['startpos'][1]['N' +
                                             str(neb_id)].append(startpos_text)
        else:
            self.neb_info['startpos'][1]['N' + str(neb_id)] = [startpos_text]

        endpos_text = StringVar()
        if self.neb_info['endpos'][0] and ('N' + str(rownum)) in self.neb_info['endpos'][0] and \
                rownum <= len(self.neb_info['endpos'][0]['N' + str(neb_id)]):
            endpos_text.set(
                self.neb_info['endpos'][0]['N' + str(neb_id)][rownum - 1])
        endpos_val = Entry(e_frame, textvariable=endpos_text)
        endpos_val.grid(row=rownum, column=4, pady=10, padx=10, sticky=W)
        if 'N' + str(neb_id) in self.neb_info['endpos'][1]:
            if rownum <= len(self.neb_info['endpos'][1]['N' + str(neb_id)]):
                self.neb_info['endpos'][1]['N' + str(neb_id)][rownum -
                                                              1] = endpos_text
            else:
                self.neb_info['endpos'][1]['N' +
                                           str(neb_id)].append(endpos_text)
        else:
            self.neb_info['endpos'][1]['N' + str(neb_id)] = [endpos_text]

        add_button = Button(e_frame, text="+")
        add_button.grid(row=rownum, column=5, pady=10, padx=10)
        add_button.configure(command=lambda: self.add_neb_field(
            add_button, e_frame, rownum, elements_options, neb_id))

    def add_neb_field(self, add_button, e_frame, rownum, elements_options,
                      neb_id):
        add_button.grid_remove()
        num_fields = self.fields_hash.get('N' + str(neb_id), 1)
        self.fields_hash['N' + str(neb_id)] = num_fields + 1
        self.create_individual_fields(e_frame, elements_options, neb_id,
                                      rownum + 1)

    def add_options(self, option_menu, options, element_var, index_val):
        menu = option_menu["menu"]
        menu.delete(0, "end")
        for string in options:
            menu.add_command(
                label=string,
                command=lambda value=string: element_var.set(value))
        if index_val is not None:
            element_var.set(index_val)
コード例 #15
0
ファイル: mastgui.py プロジェクト: zhenming-xu/MAST
class MastGui:
    def __init__(self):
        self.root_window = Tk()
        self.vframe = VerticalScrolledFrame(self.root_window)
        self.vframe.pack(fill=BOTH, expand=1)
        self.window = self.vframe.interior
        self.sections = []

        self.initialize_window()

    def initialize_window(self):
        #window properties
        self.root_window.title("MAST")
        screensizeX = self.root_window.winfo_screenwidth()
        screensizeY = self.root_window.winfo_screenheight()
        self.root_window.minsize(screensizeX - 100, screensizeY - 100)

        self.window.grid_rowconfigure(0, weight=1)
        self.window.grid_rowconfigure(1, weight=1)
        self.window.grid_rowconfigure(2, weight=1)
        self.window.grid_rowconfigure(3, weight=1)
        self.window.grid_rowconfigure(4, weight=1)
        self.window.grid_rowconfigure(5, weight=1)
        self.window.grid_rowconfigure(6, weight=1)
        self.window.grid_columnconfigure(0, weight=1)

        #add sections
        self.mast_section = MastSection(self.window, 0)
        self.mast_section.summary()
        self.sections.append(self.mast_section)

        self.structure_section = StructureSection(self.window, 1)
        self.structure_section.summary()
        self.sections.append(self.structure_section)

        self.defects_section = DefectsSection(self.window, 2,
                                              self.structure_section)
        self.defects_section.summary()
        self.sections.append(self.defects_section)

        self.neb_section = NEBSection(self.window, 3, self.structure_section,
                                      self.defects_section)
        self.neb_section.summary()
        self.sections.append(self.neb_section)

        self.ingredients_section = IngredientsSection(self.window, 4)
        self.ingredients_section.summary()
        self.sections.append(self.ingredients_section)

        self.phonon_section = PhononSection(self.window, 5)
        self.phonon_section.summary()

        self.create_btn = Button(self.window,
                                 text="Create Input File",
                                 command=self.create_input)
        self.create_btn.grid(row=6, column=0, pady=10, padx=10)

    def create_input(self):
        input_file = open("mast_input.inp", "w")

        for section_obj in self.sections:
            output_content = section_obj.content()
            input_file.write(output_content)

        input_file.close()
        self.root_window.destroy()

    def run(self):
        self.root_window.mainloop()
コード例 #16
0
    def create_window(self):
        self.window = ttk.Toplevel(self.parent_window)
        self.window.title("Structure Information")
        self.window.minsize(500, 500)
        self.vframe = VerticalScrolledFrame(self.window)
        self.vframe.pack(fill=BOTH, expand=1)
        self.structure_window = self.vframe.interior
        self.structure_window.grid_rowconfigure(0, weight=1)
        self.structure_window.grid_columnconfigure(0, weight=1)
        self.structure_window.grid_rowconfigure(0, weight=1)
        self.structure_window.grid_columnconfigure(0, weight=1)

        structure_frame = LabelFrame(self.structure_window, text="Structure")
        structure_frame.grid(row=0, column=0, padx=20, pady=20)
        structure_frame.grid_rowconfigure(0, weight=1)
        structure_frame.grid_rowconfigure(1, weight=1)
        structure_frame.grid_columnconfigure(0, weight=1)
        structure_frame.grid_columnconfigure(1, weight=1)

        #add coordtype
        label = Label(structure_frame, text="COORD_TYPE")
        label.grid(row=0, column=0, sticky=E, pady=10, padx=10)
        coord_type = StringVar(structure_frame)
        coord_type.set("fractional")
        if self.structure_info['coord_type'][0] is not None:
            coord_type.set(self.structure_info['coord_type'][0])
        coord_type_option = OptionMenu(structure_frame, coord_type,
                                       "fractional", "cartesian")
        coord_type_option.grid(row=0, column=1, sticky=W, pady=10, padx=10)
        self.structure_info["coord_type"] = [coord_type.get(), coord_type]

        #pos file
        label = Label(structure_frame, text="POSFILE")
        label.grid(row=1, column=0, sticky=E, pady=10, padx=10)
        text_val = StringVar()
        if self.structure_info['posfile'][0] is not None:
            text_val.set(self.structure_info['posfile'][0])
        text = Entry(structure_frame, textvariable=text_val)
        text.grid(row=1, column=1, sticky=W, pady=10, padx=10)
        self.structure_info['posfile'] = [text_val.get(), text_val]

        #pos file
        label = Label(structure_frame, text="LATTICE")
        label.grid(row=2, column=0, sticky=E, pady=10, padx=10)
        text = Text(structure_frame, height=5, width=30)
        if self.structure_info['lattice'][0] is not None:
            text.insert('1.0', self.structure_info['lattice'][0])
        text.grid(row=2, column=1, sticky=W, pady=10, padx=10)
        self.structure_info['lattice'][1] = text

        #label frame to add elements info
        self.elements_frame = LabelFrame(structure_frame,
                                         text="ELEMENTS INFORMATION")
        self.elements_frame.grid(row=3,
                                 column=0,
                                 columnspan=2,
                                 pady=10,
                                 padx=10)
        #create field headers
        id_label = Label(self.elements_frame, text="ID")
        id_label.grid(row=0, column=0, padx=10, pady=10, sticky=W)
        element_label = Label(self.elements_frame, text="ELEMENT")
        element_label.grid(row=0, column=1, padx=10, pady=10, sticky=W)
        coordinates_label = Label(self.elements_frame, text="COORDINATES")
        coordinates_label.grid(row=0, column=2, padx=10, pady=10, sticky=W)

        for row_num in xrange(self.num_elt_fields + 1):
            if row_num == 0:
                continue
            self.create_element_fields(self.elements_frame, row_num)

        self.add_button = Button(self.elements_frame,
                                 text="Add more elements",
                                 command=self.add_elements)
        self.add_button.grid(row=self.num_elt_fields + 1,
                             column=0,
                             columnspan=3,
                             pady=10,
                             padx=10)

        #save button
        save_button = Button(structure_frame, text="Save", command=self.save)
        save_button.grid(row=4, column=0, columnspan=2, padx=20, pady=10)
コード例 #17
0
class StructureSection:
    def __init__(self, parent_window, grid_row):
        self.parent_window = parent_window
        self.grid_row = grid_row
        self.summary_frame = None
        self.structure_info = {\
                                  'coord_type' : [None, None],\
                                  'posfile'    : [None, None],\
                                  'elementmap' : [{}, {}],\
                                  'lattice'    : [None, None],\
                                  'coordinates': [{}, {}],\
                              }
        self.num_elt_fields = 1
        self.has_summary = False

    def get_elements_map(self):
        return self.structure_info['elementmap'][0]

    def content(self):
        content_start = "$structure\n"
        content_end = "$end\n\n"

        content_lines = ""

        if self.structure_info['coord_type'][0]:
            content_lines += "coord_type %s\n\n" % self.structure_info[
                'coord_type'][0]

        if self.structure_info['posfile'][0]:
            content_lines += "posfile %s\n\n" % self.structure_info['posfile'][
                0]

        if self.structure_info['elementmap'][0]:
            content_lines += "begin elementmap\n"
            for elt_key, elt_name in self.structure_info['elementmap'][
                    0].iteritems():
                content_lines += "%s %s\n" % (elt_key, elt_name)
            content_lines += "end\n\n"

        if self.structure_info['coordinates'][0]:
            content_lines += "begin coordinates\n"
            for elt_key, elt_coord in self.structure_info['coordinates'][
                    0].iteritems():
                coord_lines = elt_coord.split('\n')
                for line in coord_lines:
                    if line:
                        content_lines += "%s %s\n" % (elt_key, line)
            content_lines += "end\n\n"

        if self.structure_info['lattice'][0]:
            content_lines += "begin lattice\n"
            content_lines += "%s\n" % self.structure_info['lattice'][0]
            content_lines += "end\n\n"

        return content_start + content_lines + content_end

    def summary(self):
        #the frame which encloses all the contents
        self.summary_frame = LabelFrame(self.parent_window, text="Structure")
        self.summary_frame.grid_rowconfigure(0, weight=1)
        self.summary_frame.grid_rowconfigure(1, weight=1)
        self.summary_frame.grid_columnconfigure(0, weight=1)
        self.summary_frame.grid_columnconfigure(1, weight=1)
        self.summary_frame.grid_columnconfigure(2, weight=1)

        #if it has summary show it
        if self.has_summary:
            #coord_type
            coord_type = Label(self.summary_frame, text="COORD_TYPE :")
            coord_type.grid(row=0, column=1, sticky=E, pady=5)
            coord_type_value = Label(self.summary_frame,
                                     text=self.structure_info['coord_type'][0])
            coord_type_value.grid(row=0, column=2, sticky=W, pady=5)

            #posfile
            if self.structure_info['posfile'][0].strip() != "":
                posfile = Label(self.summary_frame, text="POSFILE :")
                posfile.grid(row=1, column=1, sticky=E, pady=5)
                posfile_value = Label(self.summary_frame,
                                      text=self.structure_info['posfile'][0])
                posfile_value.grid(row=1, column=2, sticky=W, pady=5)

            #lattice structure
            lattice = Label(self.summary_frame, text="LATTICE : ")
            lattice.grid(row=2, column=1, sticky=E, pady=5)
            lattice_value = Label(self.summary_frame,
                                  text=self.structure_info['lattice'][0])
            lattice_value.grid(row=2, column=2, sticky=W, pady=5)

            for row_num in xrange(self.num_elt_fields + 1):
                if row_num == 0:
                    continue
                if self.structure_info['elementmap'][0][
                        'X' + str(row_num)].strip() == "":
                    continue
                id_label = Label(self.summary_frame, text='X' + str(row_num))
                id_label.grid(row=2 + row_num,
                              column=0,
                              padx=10,
                              pady=2,
                              sticky=E)
                element_label = Label(
                    self.summary_frame,
                    text=self.structure_info['elementmap'][0]['X' +
                                                              str(row_num)])
                element_label.grid(row=2 + row_num,
                                   column=1,
                                   padx=10,
                                   pady=2,
                                   sticky=W)
                coordinates_label = Label(
                    self.summary_frame,
                    text=self.structure_info['coordinates'][0]['X' +
                                                               str(row_num)])
                coordinates_label.grid(row=2 + row_num,
                                       column=2,
                                       padx=10,
                                       pady=2,
                                       sticky=W)

        #the frame contents
        add_button = Button(self.summary_frame,
                            text="Add Structure properties",
                            command=self.create_window)
        add_button.grid(row=3 + self.num_elt_fields,
                        column=0,
                        columnspan=3,
                        pady=20,
                        padx=20)

        self.summary_frame.grid(row=self.grid_row,
                                column=0,
                                padx=20,
                                pady=5,
                                sticky=W + E)

    def create_window(self):
        self.window = ttk.Toplevel(self.parent_window)
        self.window.title("Structure Information")
        self.window.minsize(500, 500)
        self.vframe = VerticalScrolledFrame(self.window)
        self.vframe.pack(fill=BOTH, expand=1)
        self.structure_window = self.vframe.interior
        self.structure_window.grid_rowconfigure(0, weight=1)
        self.structure_window.grid_columnconfigure(0, weight=1)
        self.structure_window.grid_rowconfigure(0, weight=1)
        self.structure_window.grid_columnconfigure(0, weight=1)

        structure_frame = LabelFrame(self.structure_window, text="Structure")
        structure_frame.grid(row=0, column=0, padx=20, pady=20)
        structure_frame.grid_rowconfigure(0, weight=1)
        structure_frame.grid_rowconfigure(1, weight=1)
        structure_frame.grid_columnconfigure(0, weight=1)
        structure_frame.grid_columnconfigure(1, weight=1)

        #add coordtype
        label = Label(structure_frame, text="COORD_TYPE")
        label.grid(row=0, column=0, sticky=E, pady=10, padx=10)
        coord_type = StringVar(structure_frame)
        coord_type.set("fractional")
        if self.structure_info['coord_type'][0] is not None:
            coord_type.set(self.structure_info['coord_type'][0])
        coord_type_option = OptionMenu(structure_frame, coord_type,
                                       "fractional", "cartesian")
        coord_type_option.grid(row=0, column=1, sticky=W, pady=10, padx=10)
        self.structure_info["coord_type"] = [coord_type.get(), coord_type]

        #pos file
        label = Label(structure_frame, text="POSFILE")
        label.grid(row=1, column=0, sticky=E, pady=10, padx=10)
        text_val = StringVar()
        if self.structure_info['posfile'][0] is not None:
            text_val.set(self.structure_info['posfile'][0])
        text = Entry(structure_frame, textvariable=text_val)
        text.grid(row=1, column=1, sticky=W, pady=10, padx=10)
        self.structure_info['posfile'] = [text_val.get(), text_val]

        #pos file
        label = Label(structure_frame, text="LATTICE")
        label.grid(row=2, column=0, sticky=E, pady=10, padx=10)
        text = Text(structure_frame, height=5, width=30)
        if self.structure_info['lattice'][0] is not None:
            text.insert('1.0', self.structure_info['lattice'][0])
        text.grid(row=2, column=1, sticky=W, pady=10, padx=10)
        self.structure_info['lattice'][1] = text

        #label frame to add elements info
        self.elements_frame = LabelFrame(structure_frame,
                                         text="ELEMENTS INFORMATION")
        self.elements_frame.grid(row=3,
                                 column=0,
                                 columnspan=2,
                                 pady=10,
                                 padx=10)
        #create field headers
        id_label = Label(self.elements_frame, text="ID")
        id_label.grid(row=0, column=0, padx=10, pady=10, sticky=W)
        element_label = Label(self.elements_frame, text="ELEMENT")
        element_label.grid(row=0, column=1, padx=10, pady=10, sticky=W)
        coordinates_label = Label(self.elements_frame, text="COORDINATES")
        coordinates_label.grid(row=0, column=2, padx=10, pady=10, sticky=W)

        for row_num in xrange(self.num_elt_fields + 1):
            if row_num == 0:
                continue
            self.create_element_fields(self.elements_frame, row_num)

        self.add_button = Button(self.elements_frame,
                                 text="Add more elements",
                                 command=self.add_elements)
        self.add_button.grid(row=self.num_elt_fields + 1,
                             column=0,
                             columnspan=3,
                             pady=10,
                             padx=10)

        #save button
        save_button = Button(structure_frame, text="Save", command=self.save)
        save_button.grid(row=4, column=0, columnspan=2, padx=20, pady=10)

    def save(self):
        self.structure_info['coord_type'][0] = self.structure_info[
            'coord_type'][1].get()
        self.structure_info['posfile'][0] = self.structure_info['posfile'][
            1].get()
        self.structure_info['lattice'][0] = self.structure_info['lattice'][
            1].get("1.0", END)
        for row_num in xrange(self.num_elt_fields + 1):
            if row_num == 0:
                continue
            self.structure_info['elementmap'][0][
                'X' + str(row_num)] = self.structure_info['elementmap'][1][
                    'X' + str(row_num)].get()
            self.structure_info['coordinates'][0][
                'X' + str(row_num)] = self.structure_info['coordinates'][1][
                    'X' + str(row_num)].get("1.0", END)

        self.window.destroy()
        self.window = None
        self.has_summary = True
        self.summary_frame.grid_remove()
        self.summary()

    def add_elements(self):
        self.num_elt_fields += 1
        self.add_button.grid_remove()
        self.create_element_fields(self.elements_frame, self.num_elt_fields)
        self.add_button = Button(self.elements_frame,
                                 text="Add more elements",
                                 command=self.add_elements)
        self.add_button.grid(row=self.num_elt_fields + 1,
                             column=0,
                             columnspan=3,
                             pady=10,
                             padx=10)

    def create_element_fields(self, elements_frame, row_num):
        id_label = Label(elements_frame, text="X" + str(row_num))
        id_label.grid(row=row_num, column=0, padx=10, pady=10, sticky=W)
        text_val = StringVar()
        if self.structure_info['elementmap'][0] and (
                'X' + str(row_num)) in self.structure_info['elementmap'][0]:
            text_val.set(self.structure_info['elementmap'][0]['X' +
                                                              str(row_num)])
        element_name = Entry(elements_frame, textvariable=text_val)
        element_name.grid(row=row_num, column=1, pady=10, padx=10, sticky=W)
        self.structure_info['elementmap'][1]['X' + str(row_num)] = text_val
        coordinates = Text(elements_frame, height=5, width=30)
        if self.structure_info['coordinates'][0] and (
                'X' + str(row_num)) in self.structure_info['coordinates'][0]:
            coordinates.insert(
                '1.0',
                self.structure_info['coordinates'][0]['X' + str(row_num)])
        coordinates.grid(row=row_num, column=2, pady=10, padx=10, sticky=W)
        self.structure_info['coordinates'][1]['X' + str(row_num)] = coordinates
コード例 #18
0
    def create_window(self):
        self.window = ttk.Toplevel(self.parent_window)
        self.window.title("NEB Information")
        self.window.minsize(500, 500)
        self.vframe = VerticalScrolledFrame(self.window)
        self.vframe.pack(fill=BOTH, expand=1)
        self.neb_window = self.vframe.interior
        self.neb_window.grid_rowconfigure(0, weight=1)
        self.neb_window.grid_columnconfigure(0, weight=1)

        neb_frame = LabelFrame(self.neb_window, text="NEB")
        neb_frame.grid(row=0, column=0, padx=20, pady=20)
        neb_frame.grid_rowconfigure(0, weight=1)
        neb_frame.grid_columnconfigure(0, weight=1)

        #frame for images and button
        frame1 = Frame(neb_frame)
        frame1.grid(row=0, column=0)
        frame1.grid_rowconfigure(0, weight=1)
        frame1.grid_rowconfigure(1, weight=1)
        frame1.grid_columnconfigure(0, weight=1)
        frame1.grid_columnconfigure(1, weight=1)
        frame1.grid_columnconfigure(2, weight=1)

        #add images
        label = Label(frame1, text="IMAGES")
        label.grid(row=0, column=0, sticky=E, pady=10, padx=10)
        images_val = StringVar(frame1)
        if self.neb_info['images'][0] is not None:
            images_val.set(self.neb_info['images'][0])
        images_menu = Entry(frame1, textvariable=images_val)
        images_menu.grid(row=0, column=1, sticky=W, pady=10, padx=10)
        self.neb_info["images"] = [images_val.get(), images_val]
        images_btn = Button(frame1,
                            text="Add Posfiles",
                            command=self.create_window_with_posfiles)
        images_btn.grid(row=0, column=2, sticky=W, pady=10, padx=10)

        #frame for entities
        frame2 = Frame(neb_frame)
        frame2.grid(row=1, column=0)

        #a label frame to add neb related information
        self.neb_entities_frame = LabelFrame(frame2, text="NEB ENTITIES")
        self.neb_entities_frame.grid(row=0,
                                     column=0,
                                     columnspan=3,
                                     padx=10,
                                     pady=10)

        for rownum in xrange(self.num_neb_fields):
            self.create_neb_fields(self.neb_entities_frame, rownum)

        self.add_button = Button(self.neb_entities_frame,
                                 text="Add more neb",
                                 command=self.add_elements)
        self.add_button.grid(row=self.num_neb_fields + 1,
                             column=0,
                             columnspan=6,
                             pady=10,
                             padx=10)

        #save button
        save_button = Button(neb_frame, text="Save", command=self.save)
        save_button.grid(row=3, column=0, columnspan=2, padx=20, pady=10)