From 70f855bd200de8b761d4b157c8331952f7593ec1 Mon Sep 17 00:00:00 2001 From: Beale John Henry Date: Tue, 19 Sep 2023 11:38:12 +0200 Subject: [PATCH] gui to create correctly formated .cell files --- cells/unit_cell_generator.py | 174 +++++++++++++++++++++++++++++++++++ 1 file changed, 174 insertions(+) create mode 100644 cells/unit_cell_generator.py diff --git a/cells/unit_cell_generator.py b/cells/unit_cell_generator.py new file mode 100644 index 0000000..40aa92b --- /dev/null +++ b/cells/unit_cell_generator.py @@ -0,0 +1,174 @@ +#!/usr/bin/python + +# author G.Gotthard + +""" +# aim +gui to produced .cell files formated corrected for Crystfel + +# usage +python unit_cell_generator +""" + +from tkinter import Tk, Frame, Label, Entry, Button, ttk +from tkinter.filedialog import asksaveasfilename +import tkinter.messagebox as messagebox + +space_groups = [ + ("P1", "1", "triclinic", "P"), + ("P2", "3", "monoclinic", "P", "b or c"), + ("P21", "4", "monoclinic", "P", "b or c"), + ("C2", "5", "monoclinic", "C", "b or c"), + ("I2", "5", "monoclinic", "I", "b or c"), + ("P2 2 2", "16", "orthorhombic", "P"), + ("P2 2 21", "17", "orthorhombic", "P"), + ("P2 21 2", "17", "orthorhombic", "P"), + ("P2 21 21", "18", "orthorhombic", "P"), + ("P21 2 2", "17", "orthorhombic", "P"), + ("P21 2 21", "18", "orthorhombic", "P"), + ("P21 21 2", "18", "orthorhombic", "P"), + ("P21 21 21", "19", "orthorhombic", "P"), + ("C2 2 2", "21", "orthorhombic", "C"), + ("C2 2 21", "20", "orthorhombic", "C"), + ("I2 2 2", "23", "orthorhombic", "I"), + ("I21 21 21", "24", "orthorhombic", "I"), + ("F2 2 2", "22", "orthorhombic", "F"), + ("P4", "75", "tetragonal", "P"), + ("P42", "77", "tetragonal", "P"), + ("P41", "76", "tetragonal", "P"), + ("P43", "78", "tetragonal", "P"), + ("P4 2 2", "89", "tetragonal", "P"), + ("P4 21 2", "90", "tetragonal", "P"), + ("P42 2 2", "93", "tetragonal", "P"), + ("P42 21 2", "94", "tetragonal", "P"), + ("P41 2 2", "91", "tetragonal", "P"), + ("P41 21 2", "92", "tetragonal", "P"), + ("P43 2 2", "95", "tetragonal", "P"), + ("P43 21 2", "96", "tetragonal", "P"), + ("I4", "79", "tetragonal", "I"), + ("I41", "80", "tetragonal", "I"), + ("I4 2 2", "97", "tetragonal", "I"), + ("I41 2 2", "98", "tetragonal", "I"), + ("P3", "143", "trigonal", "P"), + ("P31", "144", "trigonal", "P"), + ("P32", "145", "trigonal", "P"), + ("P3 1 2", "149", "trigonal", "P"), + ("P3 2 1", "150", "trigonal", "P"), + ("P31 1 2", "151", "trigonal", "P"), + ("P31 2 1", "152", "trigonal", "P"), + ("P32 1 2", "153", "trigonal", "P"), + ("P32 2 1", "154", "trigonal", "P"), + ("P6", "168", "hexagonal", "P"), + ("P63", "173", "hexagonal", "P"), + ("P62", "171", "hexagonal", "P"), + ("P61", "169", "hexagonal", "P"), + ("P64", "172", "hexagonal", "P"), + ("P65", "170", "hexagonal", "P"), + ("P622", "177", "hexagonal", "P"), + ("P63 2 2", "182", "hexagonal", "P"), + ("P62 2 2", "180", "hexagonal", "P"), + ("P61 2 2", "178", "hexagonal", "P"), + ("P64 2 2", "181", "hexagonal", "P"), + ("P65 2 2", "179", "hexagonal", "P"), + ("R3", "146", "trigonal", "R"), + ("R3 2", "155", "trigonal", "R"), + ("P2 3", "195", "cubic", "P"), + ("P21 3", "198", "cubic", "P"), + ("P4 3 2", "207", "cubic", "P"), + ("P42 3 2", "208", "cubic", "P"), + ("P43 3 2", "212", "cubic", "P"), + ("P41 3 2", "213", "cubic", "P"), + ("I2 3", "197", "cubic", "I"), + ("I21 3", "199", "cubic", "I"), + ("I4 3 2", "211", "cubic", "I"), + ("I41 3 2", "214", "cubic", "I"), + ("F2 3", "196", "cubic", "F"), + ("F4 3 2", "209", "cubic", "F"), + ("F41 3 2", "210", "cubic", "F") +] + +def generate_unit_cell_file(): + space_group = combobox_space_group.get() + group_info = next((group for group in space_groups if group[0] == space_group), None) + + if group_info: + lattice_type = group_info[2] + centering = group_info[3] + else: + lattice_type = "" + centering = "" + + unique_axis = combobox_unique_axis.get() + a = entry_a.get() + b = entry_b.get() + c = entry_c.get() + alpha = entry_alpha.get() + beta = entry_beta.get() + gamma = entry_gamma.get() + + output_text = f"CrystFEL unit cell file version 1.0\n\n" + output_text += f"lattice_type = {lattice_type}\n" + output_text += f"unique_axis = {unique_axis}\n" + output_text += f"centering = {centering}\n" + output_text += f"a = {a} A\n" + output_text += f"b = {b} A\n" + output_text += f"c = {c} A\n" + output_text += f"al = {alpha} deg\n" + output_text += f"be = {beta} deg\n" + output_text += f"ga = {gamma} deg" + + file_path = asksaveasfilename(defaultextension=".cell", filetypes=[("Crystallographic Unit Cell Files", "*.cell")]) + if file_path: + with open(file_path, "w") as file: + file.write(output_text) + + messagebox.showinfo("File Generated", "Unit cell file generated successfully. Please check the file.") + +# Create Tkinter window +window = Tk() +window.title("Unit Cell File Generator") + +# Create a frame +frame = Frame(window) +frame.pack(pady=20) + +# Create labels and entry fields for unit cell parameters +Label(frame, text="Space Group:").grid(row=0, column=0, sticky="E") +Label(frame, text="Unique axis:").grid(row=1, column=0, sticky="E") +Label(frame, text="a:").grid(row=2, column=0, sticky="E") +Label(frame, text="b:").grid(row=3, column=0, sticky="E") +Label(frame, text="c:").grid(row=4, column=0, sticky="E") +Label(frame, text="alpha:").grid(row=5, column=0, sticky="E") +Label(frame, text="beta:").grid(row=6, column=0, sticky="E") +Label(frame, text="gamma:").grid(row=7, column=0, sticky="E") + +combobox_space_group = ttk.Combobox(frame, values=[group[0] for group in space_groups]) +combobox_space_group.grid(row=0, column=1, pady=5) + +combobox_unique_axis = ttk.Combobox(frame, values=["", "a", "b", "c"]) +combobox_unique_axis.grid(row=1, column=1, pady=5) + +entry_a = Entry(frame) +entry_a.grid(row=2, column=1, pady=5) + +entry_b = Entry(frame) +entry_b.grid(row=3, column=1, pady=5) + +entry_c = Entry(frame) +entry_c.grid(row=4, column=1, pady=5) + +entry_alpha = Entry(frame) +entry_alpha.grid(row=5, column=1, pady=5) + +entry_beta = Entry(frame) +entry_beta.grid(row=6, column=1, pady=5) + +entry_gamma = Entry(frame) +entry_gamma.grid(row=7, column=1, pady=5) + +# Create a button to generate the unit cell file +generate_button = Button(frame, text="Generate", command=generate_unit_cell_file) +generate_button.grid(row=8, columnspan=2, pady=10) + +# Run the Tkinter event loop +window.mainloop()