def load_unit_cell(self, ucell_map): """Called by the implementation of load_metadata to load the unit cell pararameters for the structure. """ for key in ("a", "b", "c", "alpha", "beta", "gamma"): if not ucell_map.has_key(key): ConsoleOutput.debug("ucell_map missing: %s" % (key)) return if ucell_map.has_key("space_group"): self.struct.unit_cell = UnitCell.UnitCell( a=ucell_map["a"], b=ucell_map["b"], c=ucell_map["c"], alpha=ucell_map["alpha"], beta=ucell_map["beta"], gamma=ucell_map["gamma"], space_group=ucell_map["space_group"]) else: self.struct.unit_cell = UnitCell.UnitCell(a=ucell_map["a"], b=ucell_map["b"], c=ucell_map["c"], alpha=ucell_map["alpha"], beta=ucell_map["beta"], gamma=ucell_map["gamma"])
def load_atom(self, atm_map): """Called repeatedly by the implementation of read_atoms to load all the data for a single atom. The data is contained in the atm_map argument, and is not well documented at this point. Look at this function and you'll figure it out. """ ## create atom object atm = Structure.Atom(**atm_map) ## survey the atom and structure and determine if the atom requres ## being passed to the naming service ## absence of requred fields if not atm.fragment_id or not atm.chain_id: self.name_service_list.append(atm) return atm try: self.struct.add_atom(atm, True) except Structure.FragmentOverwrite: ConsoleOutput.warning("FragmentOverwrite: %s" % (atm)) self.name_service_list.append(atm) except Structure.AtomOverwrite, err: ConsoleOutput.warning("AtomOverwrite: %s" % (err)) self.name_service_list.append(atm)
def load_atom(self, atm_map): """Called repeatedly by the implementation of read_atoms to load all the data for a single atom. The data is contained in the atm_map argument, and is not well documented at this point. Look at this function and you'll figure it out. """ ## create atom object atm = Structure.Atom(**atm_map) ## survey the atom and structure and determine if the atom requires ## being passed to the naming service, absence of required fields if not atm.fragment_id or not atm.chain_id: self.name_service_list.append(atm) return atm try: self.struct.add_atom(atm, True) except Structure.FragmentOverwrite: ConsoleOutput.warning("FragmentOverwrite: %s" % (atm)) self.name_service_list.append(atm) except Structure.AtomOverwrite, err: ConsoleOutput.warning("AtomOverwrite: %s" % (err)) self.name_service_list.append(atm)
def library_construct_element_desc(symbol): """Constructs the ElementDesc object for the given element symbol. """ cif_data = ELEMENT_CIF_FILE.get_data(symbol) if cif_data is None: ConsoleOutput.warning("element description not found for %s" % (symbol)) return None ## create element description element_desc = ElementDesc() element_desc.cif_data = cif_data element = cif_data.get_table("element") element_desc.name = element["name"] element_desc.symbol = element["symbol"] element_desc.number = int(element["number"]) element_desc.atomic_weight = float(element["atomic_weight"]) element_desc.vdw_radius = float(element["van_der_walls_radius"]) element_desc.covalent_radius = float(element.get("covalent_radius", 0.0)) rgb8 = element["color_rgb"] element_desc.color_rgbf = (int(rgb8[1:3], 16) / 255.0, int(rgb8[3:5], 16) / 255.0, int(rgb8[5:7], 16) / 255.0) return element_desc
def load_unit_cell(self, ucell_map): """Called by the implementation of load_metadata to load the unit cell parameters for the structure. """ for key in ("a", "b", "c", "alpha", "beta", "gamma"): if not ucell_map.has_key(key): ConsoleOutput.debug("ucell_map missing: %s" % (key)) return if ucell_map.has_key("space_group"): self.struct.unit_cell = UnitCell.UnitCell( a = ucell_map["a"], b = ucell_map["b"], c = ucell_map["c"], alpha = ucell_map["alpha"], beta = ucell_map["beta"], gamma = ucell_map["gamma"], space_group = ucell_map["space_group"]) else: self.struct.unit_cell = UnitCell.UnitCell( a = ucell_map["a"], b = ucell_map["b"], c = ucell_map["c"], alpha = ucell_map["alpha"], beta = ucell_map["beta"], gamma = ucell_map["gamma"])
def library_open_monomer_lib_zipfile(monomer_name): """Returns the open file object for the mmCIF monomer library file if it is found in the monomer library zipfile. """ if library_use_monomer_zipfile(): ## read data from zip file try: blob = RCSB_ZIP.read(monomer_name.upper()) except KeyError: ConsoleOutput.warning("monomer description not found in zipfile for '%s'" % (monomer_name)) else: from cStringIO import StringIO return StringIO(blob) return None
def setupUi(self, MainWindow): MainWindow.setObjectName(_fromUtf8("MainWindow")) MainWindow.resize(1016, 818) #Central Widget is the main area to put Widgets on the program #Itis not a container. self.centralwidget = QtGui.QWidget(MainWindow) self.centralwidget.setObjectName(_fromUtf8("centralwidget")) self.init_tool_bar(MainWindow) #initialize the Capture Area self.captureArea = CaptureArea(self.centralwidget) MainWindow.setCentralWidget(self.centralwidget) #Initialize the ProjectViewer self.projectViewer = ProjectViewer(MainWindow) #This may be the buttons but might remove in an update self.dockWidgetControls = QtGui.QDockWidget(MainWindow) self.dockWidgetControls.setObjectName(_fromUtf8("dockWidgetControls")) self.dockWidgetContents_8 = QtGui.QWidget() self.dockWidgetContents_8.setObjectName( _fromUtf8("dockWidgetContents_8")) self.pushButton = QtGui.QPushButton(self.dockWidgetContents_8) self.pushButton.setGeometry(QtCore.QRect(10, 10, 61, 51)) self.pushButton.setObjectName(_fromUtf8("pushButton")) self.dockWidgetControls.setWidget(self.dockWidgetContents_8) MainWindow.addDockWidget(QtCore.Qt.DockWidgetArea(2), self.dockWidgetControls) #initialize the Console Output self.consoleOutput = ConsoleOutput(MainWindow) MainWindow.setCentralWidget(self.centralwidget) #Set up the Menu Bar self.init_menu_bar(MainWindow) self.statusbar = QtGui.QStatusBar(MainWindow) self.statusbar.setObjectName(_fromUtf8("statusbar")) MainWindow.setStatusBar(self.statusbar) self.retranslateUi(MainWindow) QtCore.QMetaObject.connectSlotsByName(MainWindow)
def library_open_monomer_lib_zipfile(monomer_name): """Returns the open file object for the mmCIF monomer library file if it is found in the monomer library zipfile. """ if library_use_monomer_zipfile(): ## read data from zip file try: blob = RCSB_ZIP.read(monomer_name.upper()) except KeyError: ConsoleOutput.warning( "monomer description not found in zipfile for '%s'" % (monomer_name)) else: from cStringIO import StringIO return StringIO(blob) return None
def __init__(self, sequence_from_structure = False, library_bonds = False, distance_bonds = False, auto_sort = True, **args): ## allocate a new Structure object for building if one was not ## passed to the StructureBuilder if args.has_key("structure"): self.struct = args["structure"] elif args.has_key("struct"): self.struct = args["struct"] else: self.struct = Structure.Structure() ## set structure_id if args.has_key("structure_id"): self.struct.structure_id = args["structure_id"] ## options self.calc_sequence = sequence_from_structure self.library_bonds = library_bonds self.distance_bonds = distance_bonds self.auto_sort = auto_sort ## caches used while building self.cache_chain = None self.cache_frag = None ## if anything goes wrong, setting self.halt=True will stop the madness self.halt = False ## build the structure by executing this fixed sequence of methods self.read_start(args["fil"]) if not self.halt: self.read_start_finalize() if not self.halt: self.read_atoms() if not self.halt: self.read_atoms_finalize() if not self.halt: self.read_metadata() if not self.halt: self.read_metadata_finalize() if not self.halt: self.read_end() if not self.halt: self.read_end_finalize() ## self.struct is now built and ready for use if self.halt == True: ConsoleOutput.fatal("self.halt == True")
def __init__(self, sequence_from_structure=False, library_bonds=False, distance_bonds=False, auto_sort=True, **args): ## allocate a new Structure object for building if one was not ## passed to the StructureBuilder if args.has_key("structure"): self.struct = args["structure"] elif args.has_key("struct"): self.struct = args["struct"] else: self.struct = Structure.Structure() ## set structure_id if args.has_key("structure_id"): self.struct.structure_id = args["structure_id"] ## options self.calc_sequence = sequence_from_structure self.library_bonds = library_bonds self.distance_bonds = distance_bonds self.auto_sort = auto_sort ## caches used while building self.cache_chain = None self.cache_frag = None ## if anything goes wrong, setting self.halt=True will stop the madness self.halt = False ## build the structure by executing this fixed sequence of methods self.read_start(args["fil"]) if not self.halt: self.read_start_finalize() if not self.halt: self.read_atoms() if not self.halt: self.read_atoms_finalize() if not self.halt: self.read_metadata() if not self.halt: self.read_metadata_finalize() if not self.halt: self.read_end() if not self.halt: self.read_end_finalize() ## self.struct is now built and ready for use if self.halt == True: ConsoleOutput.fatal("self.halt == True")
def library_get_element_desc(symbol): """Loads/caches/returns an instance of the ElementDesc class for the given element symbol. The source of the element data is the mmLib/Data/elements.cif file. """ assert isinstance(symbol, str) try: return ELEMENT_CACHE[symbol] except KeyError: pass element_desc = library_construct_element_desc(symbol) if element_desc is None: ConsoleOutput.warning("element description not found for %s" % (symbol)) return None ELEMENT_CACHE[symbol] = element_desc return element_desc
def read_end_finalize(self): """Called for final cleanup after structure source reading is done. Currently, this method does nothing but may be used in future versions. """ ConsoleOutput.debug("read_end_finalize()") ## calculate sequences for all chains if self.calc_sequence is True: for model in self.struct.iter_models(): for chain in model.iter_chains(): if len(chain.sequence) == 0: chain.sequence.set_from_fragments(chain.iter_fragments()) ## build bonds as defined in the monomer library if self.library_bonds is True: self.struct.add_bonds_from_library() ## build bonds by covalent distance calculations if self.distance_bonds is True: self.struct.add_bonds_from_covalent_distance()
def read_end_finalize(self): """Called for final cleanup after structure source reading is done. Currently, this method does nothing but may be used in future versions. """ ConsoleOutput.debug("read_end_finalize()") ## calculate sequences for all chains if self.calc_sequence is True: for model in self.struct.iter_models(): for chain in model.iter_chains(): if len(chain.sequence) == 0: chain.sequence.set_from_fragments( chain.iter_fragments()) ## build bonds as defined in the monomer library if self.library_bonds is True: self.struct.add_bonds_from_library() ## build bonds by covalent distance calculations if self.distance_bonds is True: self.struct.add_bonds_from_covalent_distance()
def load_bonds(self, bond_map): """Call by the implementation of load_metadata to load bond information on the structure. The keys of the bond map are a 2-tuple of the bonded Atom instances, and the value is a dictionary containing information on the type of bond, which may also be a symmetry operator. [bond_map] keys: (atm1, atm2) values: bond_data_map(s) [bond_data_map] bond_type -> text description of bond type: covalent, salt bridge, hydrogen, cispeptide atm1_symop -> symmetry operation (if any) to be applied to atm1 atm2_symop -> same as above, for atom 2 The symmetry operations themselves are a 3x4 array of floating point values composed of the 3x3 rotation matrix and the 3x1 translation. """ ### XXX: fix this to build bonds in all models!!! for ((atm1, atm2), bd_map) in bond_map.iteritems(): ## check for files which, for some reason, define have a bond ## entry bonding the atom to itself if atm1 == atm2: ConsoleOutput.warning("silly file defines self bonded atom") continue atm1.create_bonds(atom=atm2, bond_type=bd_map.get("bond_type"), atom1_symop=bd_map.get("atm1_symop"), atom2_symop=bd_map.get("atm2_symop"), standard_res_bond=False)
def load_bonds(self, bond_map): """Call by the implementation of load_metadata to load bond information on the structure. The keys of the bond map are a 2-tuple of the bonded Atom instances, and the value is a dictionary containing information on the type of bond, which may also be a symmetry operator. [bond_map] keys: (atm1, atm2) values: bond_data_map(s) [bond_data_map] bond_type -> text description of bond type: covalent, salt bridge, hydrogen, cispeptide atm1_symop -> symmetry operation (if any) to be applied to atm1 atm2_symop -> same as above, for atom 2 The symmetry operations themselves are a 3x4 array of floating point values composed of the 3x3 rotation matrix and the 3x1 translation. """ ### TODO: Fix this to build bonds in all models! 2010-09-22 for ((atm1, atm2), bd_map) in bond_map.iteritems(): ## check for files which, for some reason, define have a bond ## entry bonding the atom to itself if atm1 == atm2: ConsoleOutput.warning("silly file defines self bonded atom") continue atm1.create_bonds( atom = atm2, bond_type = bd_map.get("bond_type"), atom1_symop = bd_map.get("atm1_symop"), atom2_symop = bd_map.get("atm2_symop"), standard_res_bond = False)
def glr_render_end(self): """Write out the input file for the render program. """ ## open r3d file, write header pobj = None if self.render_stdin is not None: stdin = self.render_stdin else: cmdlist = [ self.render_program_path, "-png", self.render_png_path, "-gamma", "1.5" ] try: pobj = subprocess.Popen(cmdlist, stdin=subprocess.PIPE, stdout=subprocess.PIPE, stderr=subprocess.STDOUT, close_fds=True, bufsize=32768) except OSError: ConsoleOutput.warning( "the render program failed to execute from path: %s" % (self.render_program_path)) return stdin = pobj.stdin ## XXX: debug ##r3dfil = open("/tmp/raytrace.r3d","w") ##stdin = TeeWrite(stdin) ## add required hader for the render program self.glr_construct_header() try: stdin.write("\n".join(self.header_list)) stdin.write("\n") self.glr_write_objects(stdin) except IOError, err: ConsoleOutput.warning("IOError while executing %s" % (self.render_program_path)) ConsoleOutput.warning(str(err)) return
def glr_render_end(self): """Write out the input file for the render program. """ ## open r3d file, write header pobj = None if self.render_stdin is not None: stdin = self.render_stdin else: cmdlist = [self.render_program_path, "-png", self.render_png_path, "-gamma", "1.5"] try: pobj = subprocess.Popen( cmdlist, stdin=subprocess.PIPE, stdout=subprocess.PIPE, stderr=subprocess.STDOUT, close_fds=True, bufsize=32768, ) except OSError: ConsoleOutput.warning("the render program failed to execute from path: %s" % (self.render_program_path)) return stdin = pobj.stdin ## XXX: debug ##r3dfil = open("/tmp/raytrace.r3d","w") ##stdin = TeeWrite(stdin) ## add required hader for the render program self.glr_construct_header() try: stdin.write("\n".join(self.header_list)) stdin.write("\n") self.glr_write_objects(stdin) except IOError, err: ConsoleOutput.warning("IOError while executing %s" % (self.render_program_path)) ConsoleOutput.warning(str(err)) return
def read_atoms(self): try: atom_site_table = self.cif_data["atom_site"] except KeyError: ConsoleOutput.warning("read_atoms: atom_site table not found") return try: aniso_table = self.cif_data["atom_site_anisotrop"] except KeyError: aniso_table = None else: aniso_dict = aniso_table.row_index_dict("id") for atom_site in atom_site_table: try: atom_site_id = atom_site["id"] except KeyError: ConsoleOutput.warning("unable to find id for atom_site row") continue atm_map = {} atm_map["chain_id"] = ' ' # default for chimera setmaps_cif(atom_site, self.atom_id, atm_map, "name") setmaps_cif(atom_site, self.alt_id, atm_map, "alt_loc") setmaps_cif(atom_site, self.comp_id, atm_map, "res_name") setmaps_cif(atom_site, self.seq_id, atm_map, "fragment_id") if setmaps_cif(atom_site, self.icode_id, atm_map, "icode"): atm_map["fragment_id"] += atm_map["icode"] setmaps_cif(atom_site, self.asym_id, atm_map, "chain_id") setmaps_cif(atom_site, "label_entity_id", atm_map, "label_entity_id") setmaps_cif(atom_site, "label_asym_id", atm_map, "label_asym_id") setmaps_cif(atom_site, "label_seq_id", atm_map, "label_seq_id") setmaps_cif(atom_site, "type_symbol", atm_map, "element") setmapf_cif(atom_site, "cartn_x", atm_map, "x") setmapf_cif(atom_site, "cartn_y", atm_map, "y") setmapf_cif(atom_site, "cartn_z", atm_map, "z") setmapf_cif(atom_site, "occupancy", atm_map, "occupancy") setmapf_cif(atom_site, "b_iso_or_equiv", atm_map, "temp_factor") setmapf_cif(atom_site, "cartn_x_esd", atm_map, "sig_x") setmapf_cif(atom_site, "cartn_y_esd", atm_map, "sig_y") setmapf_cif(atom_site, "cartn_z_esd", atm_map, "sig_z") setmapf_cif(atom_site, "occupancy_esd", atm_map, "sig_occupancy") setmapf_cif(atom_site, "b_iso_or_equiv_esd", atm_map, "sig_temp_factor") setmapi_cif(atom_site, "pdbx_pdb_model_num", atm_map, "model_id") if aniso_table is not None: try: aniso = aniso_dict[atom_site_id] except KeyError: ConsoleOutput.warning("unable to find aniso row for atom") else: setmapf_cif(aniso, "u[1][1]", atm_map, "u11") setmapf_cif(aniso, "u[2][2]", atm_map, "u22") setmapf_cif(aniso, "u[3][3]", atm_map, "u33") setmapf_cif(aniso, "u[1][2]", atm_map, "u12") setmapf_cif(aniso, "u[1][3]", atm_map, "u13") setmapf_cif(aniso, "u[2][3]", atm_map, "u23") setmapf_cif(aniso, "u[1][1]_esd", atm_map, "sig_u12") setmapf_cif(aniso, "u[2][2]_esd", atm_map, "sig_u22") setmapf_cif(aniso, "u[3][3]_esd", atm_map, "sig_u33") setmapf_cif(aniso, "u[1][2]_esd", atm_map, "sig_u12") setmapf_cif(aniso, "u[1][3]_esd", atm_map, "sig_u13") setmapf_cif(aniso, "u[2][3]_esd", atm_map, "sig_u23") atm = self.load_atom(atm_map) self.atom_site_id_map[atom_site_id] = atm
def read_struct_conn(self): """Read bond information form the struct_conn and struct_conn_type sections. """ ## only read these types of bonds for now bond_type_list = [ "covale", # covalent bond "metalc", # metal coordination "disulf", # disulfide bridge "saltbr", # ionic interaction "covale_base", # covalent modification of a nucleotide base "covale_sugar", # covalent modification of a nucleotide sugar "covale_phosphate", # covalent modification of a nucleotide phosphate ] try: atom_site = self.cif_data["atom_site"] except KeyError: ConsoleOutput.warning("read_struct_conn: atom_site table not found") return try: struct_conn_table = self.cif_data["struct_conn"] except KeyError: ConsoleOutput.warning("read_struct_conn: struct_conn table not found") return bond_map = {} for row in struct_conn_table: conn_type = row.get("conn_type_id") if conn_type not in bond_type_list: continue # Always use label_ values since they are mandatory asym_id1 = row.get("ptnr1_label_asym_id") seq_id1 = row.get("ptnr1_label_seq_id") comp_id1 = row.get("ptnr1_label_comp_id") atom_id1 = row.get("ptnr1_label_atom_id") auth_asym_id1 = row.get("ptnr1_auth_asym_id") auth_seq_id1 = row.get("ptnr1_auth_seq_id") auth_comp_id1 = row.get("ptnr1_auth_comp_id") symm1 = row.get("ptnr1_symmetry") asym_id2 = row.get("ptnr2_label_asym_id") seq_id2 = row.get("ptnr2_label_seq_id") comp_id2 = row.get("ptnr2_label_comp_id") atom_id2 = row.get("ptnr2_label_atom_id") auth_asym_id2 = row.get("ptnr2_auth_asym_id") auth_seq_id2 = row.get("ptnr2_auth_seq_id") auth_comp_id2 = row.get("ptnr2_auth_comp_id") symm2 = row.get("ptnr2_symmetry") ## check for these special mmCIF tokens if conn_type == "disulf": atom_id1 = atom_id2 = "SG" as1 = atom_site.get_row( ("label_asym_id", asym_id1), ("label_seq_id", seq_id1), ("label_comp_id", comp_id1), ("auth_asym_id", auth_asym_id1), ("auth_seq_id", auth_seq_id1), ("auth_comp_id", auth_comp_id1), ("label_atom_id", atom_id1)) as2 = atom_site.get_row( ("label_asym_id", asym_id2), ("label_seq_id", seq_id2), ("label_comp_id", comp_id2), ("auth_asym_id", auth_asym_id2), ("auth_seq_id", auth_seq_id2), ("auth_comp_id", auth_comp_id2), ("label_atom_id", atom_id2)) if not as1 or not as2: ConsoleOutput.warning("read_struct_conn: atom not found id: " + \ row.get("id","[No ID]")) ConsoleOutput.warning("atm1: asym=%s seq=%s comp=%s atom=%s symm=%s" % ( asym_id1, seq_id1, comp_id1, atom_id1, symm1)) ConsoleOutput.warning("atm2: asym=%s seq=%s comp=%s atom=%s symm=%s" % ( asym_id2, seq_id2, comp_id2, atom_id2, symm2)) continue try: atm1 = self.atom_site_id_map[as1["id"]] atm2 = self.atom_site_id_map[as2["id"]] except KeyError: ConsoleOutput.warning("read_struct_conn: atom_site_id_map incorrect id: " + \ row.get("id", "[No ID]")) ConsoleOutput.warning("atm1: asym=%s seq=%s comp=%s atom=%s symm=%s" % ( asym_id1, seq_id1, comp_id1, atom_id1, symm1)) ConsoleOutput.warning("atm2: asym=%s seq=%s comp=%s atom=%s symm=%s" % ( asym_id2, seq_id2, comp_id2, atom_id2, symm2)) continue if id(atm1) < id(atm2): bnd = (atm1, atm2) else: bnd = (atm2, atm1) try: bond_map[bnd]["bond_type"] = conn_type except KeyError: bond_map[bnd] = {"bond_type": conn_type} if symm1: bond_map[bnd]["symop1"] = symm1 if symm2: bond_map[bnd]["symop2"] = symm2 ## load the bonds self.load_bonds(bond_map)
def read_atoms(self): try: atom_site_table = self.cif_data["atom_site"] except KeyError: ConsoleOutput.warning("read_atoms: atom_site table not found") return try: aniso_table = self.cif_data["atom_site_anisotrop"] except KeyError: aniso_table = None else: aniso_dict = aniso_table.row_index_dict("id") for atom_site in atom_site_table: try: atom_site_id = atom_site["id"] except KeyError: ConsoleOutput.warning("unable to find id for atom_site row") continue atm_map = {} setmaps_cif(atom_site, self.atom_id, atm_map, "name") setmaps_cif(atom_site, self.alt_id, atm_map, "alt_loc") setmaps_cif(atom_site, self.comp_id, atm_map, "res_name") setmaps_cif(atom_site, self.seq_id, atm_map, "fragment_id") setmaps_cif(atom_site, self.asym_id, atm_map, "chain_id") setmaps_cif(atom_site, "label_entity_id", atm_map, "label_entity_id") setmaps_cif(atom_site, "label_asym_id", atm_map, "label_asym_id") setmaps_cif(atom_site, "label_seq_id", atm_map, "label_seq_id") setmaps_cif(atom_site, "type_symbol", atm_map, "element") setmapf_cif(atom_site, "cartn_x", atm_map, "x") setmapf_cif(atom_site, "cartn_y", atm_map, "y") setmapf_cif(atom_site, "cartn_z", atm_map, "z") setmapf_cif(atom_site, "occupancy", atm_map, "occupancy") setmapf_cif(atom_site, "b_iso_or_equiv", atm_map, "temp_factor") setmapf_cif(atom_site, "cartn_x_esd", atm_map, "sig_x") setmapf_cif(atom_site, "cartn_y_esd", atm_map, "sig_y") setmapf_cif(atom_site, "cartn_z_esd", atm_map, "sig_z") setmapf_cif(atom_site, "occupancy_esd", atm_map, "sig_occupancy") setmapf_cif(atom_site, "b_iso_or_equiv_esd", atm_map, "sig_temp_factor") setmapi_cif(atom_site, "pdbx_pdb_model_num", atm_map, "model_id") if aniso_table is not None: try: aniso = aniso_dict[atom_site_id] except KeyError: ConsoleOutput.warning("unable to find aniso row for atom") else: setmapf_cif(aniso, "u[1][1]", atm_map, "u11") setmapf_cif(aniso, "u[2][2]", atm_map, "u22") setmapf_cif(aniso, "u[3][3]", atm_map, "u33") setmapf_cif(aniso, "u[1][2]", atm_map, "u12") setmapf_cif(aniso, "u[1][3]", atm_map, "u13") setmapf_cif(aniso, "u[2][3]", atm_map, "u23") setmapf_cif(aniso, "u[1][1]_esd", atm_map, "sig_u12") setmapf_cif(aniso, "u[2][2]_esd", atm_map, "sig_u22") setmapf_cif(aniso, "u[3][3]_esd", atm_map, "sig_u33") setmapf_cif(aniso, "u[1][2]_esd", atm_map, "sig_u12") setmapf_cif(aniso, "u[1][3]_esd", atm_map, "sig_u13") setmapf_cif(aniso, "u[2][3]_esd", atm_map, "sig_u23") atm = self.load_atom(atm_map) self.atom_site_id_map[atom_site_id] = atm
except ImportError: import NumericCompat as numpy from NumericCompat import linalg from OpenGL.GL import * from OpenGL.GLU import * from OpenGL.GLUT import * import ConsoleOutput import Gaussian import AtomMath try: import glaccel except ImportError: ConsoleOutput.warning("cannot load OpenGL acceloration module glaccel") GLACCEL_EXISTS = False else: GLACCEL_EXISTS = True class OpenGLDriver(object): """OpenGL render driver for Viewer.py """ def __init__(self): object.__init__(self) ## some objects have a accelorated C version built in ## src/glaccel.c; if they exist, then use them ## this should really be done by a factory function... if GLACCEL_EXISTS:
def pdb_error(self, rec_name, text): ConsoleOutput.warning("PDB::%s %s" % (rec_name, text))
def output(self): return ConsoleOutput()
class Ui_MainWindow(object): def setupUi(self, MainWindow): MainWindow.setObjectName(_fromUtf8("MainWindow")) MainWindow.resize(1016, 818) #Central Widget is the main area to put Widgets on the program #Itis not a container. self.centralwidget = QtGui.QWidget(MainWindow) self.centralwidget.setObjectName(_fromUtf8("centralwidget")) self.init_tool_bar(MainWindow) #initialize the Capture Area self.captureArea = CaptureArea(self.centralwidget) MainWindow.setCentralWidget(self.centralwidget) #Initialize the ProjectViewer self.projectViewer = ProjectViewer(MainWindow) #This may be the buttons but might remove in an update self.dockWidgetControls = QtGui.QDockWidget(MainWindow) self.dockWidgetControls.setObjectName(_fromUtf8("dockWidgetControls")) self.dockWidgetContents_8 = QtGui.QWidget() self.dockWidgetContents_8.setObjectName( _fromUtf8("dockWidgetContents_8")) self.pushButton = QtGui.QPushButton(self.dockWidgetContents_8) self.pushButton.setGeometry(QtCore.QRect(10, 10, 61, 51)) self.pushButton.setObjectName(_fromUtf8("pushButton")) self.dockWidgetControls.setWidget(self.dockWidgetContents_8) MainWindow.addDockWidget(QtCore.Qt.DockWidgetArea(2), self.dockWidgetControls) #initialize the Console Output self.consoleOutput = ConsoleOutput(MainWindow) MainWindow.setCentralWidget(self.centralwidget) #Set up the Menu Bar self.init_menu_bar(MainWindow) self.statusbar = QtGui.QStatusBar(MainWindow) self.statusbar.setObjectName(_fromUtf8("statusbar")) MainWindow.setStatusBar(self.statusbar) self.retranslateUi(MainWindow) QtCore.QMetaObject.connectSlotsByName(MainWindow) def retranslateUi(self, MainWindow): #This will be used to support multiple languages MainWindow.setWindowTitle( _translate("MainWindow", "Mo Cap pie - Team Ep0ch", None)) MainWindow.setWindowIcon(QtGui.QIcon("./imgs/icon.ico")) #self.captureArea.setTabText(self.captureArea.indexOf(self.tab), _translate("MainWindow", "Tab 1", None)) #self.captureArea.setTabText(self.captureArea.indexOf(self.tab_2), _translate("MainWindow", "Tab 2", None)) def init_tool_bar(self, MainWindow): self.playMotionAction = QtGui.QAction( QtGui.QIcon("./imgs/PlayGreenButton.ico"), "Play Motion", MainWindow) self.playMotionAction.triggered.connect(self.play_motion) self.pauseMotionAction = QtGui.QAction(QtGui.QIcon("./imgs/Pause.ico"), "Pause Motion Capture", MainWindow) self.pauseMotionAction.triggered.connect(self.pause_motion) self.stopMotionAction = QtGui.QAction( QtGui.QIcon("./imgs/StopRedButton.ico"), "Stop Motion Capture", MainWindow) self.stopMotionAction.triggered.connect(self.stop_motion) self.recordMotionAction = QtGui.QAction( QtGui.QIcon("./imgs/RecordButton.ico"), "Record New Motion Capture", MainWindow) self.recordMotionAction.triggered.connect(self.record_Motion) # Let me tell you all a story about a mouse named glory self.toolBar = MainWindow.addToolBar("Test test") self.toolBar.addAction(self.playMotionAction) self.toolBar.addAction(self.pauseMotionAction) self.toolBar.addAction(self.stopMotionAction) self.toolBar.addAction(self.recordMotionAction) def record_Motion(self): self.consoleOutput.outputText("Recording motion...") def play_motion(self): self.consoleOutput.outputText("playing motion...") self.captureArea.start_clicked() def pause_motion(self): self.consoleOutput.outputText("Motion Capture paused") #self.playMotionAction.setEnabled(False) def stop_motion(self): self.consoleOutput.outputText("Motion Captured stopped") def init_menu_bar(self, MainWindow): self.menuBar = QtGui.QMenuBar(MainWindow) self.menuBar.setNativeMenuBar(False) self.menuBar.setGeometry(QtCore.QRect(0, 0, 1055, 25)) self.menuBar.setObjectName(_fromUtf8("menubar")) #Initialze the Menu Items self.menuFile = QtGui.QMenu(self.menuBar) self.menuFile.setObjectName(_fromUtf8("menuFile")) self.menuEdit = QtGui.QMenu(self.menuBar) self.menuEdit.setObjectName(_fromUtf8("menuEdit")) self.menuProject = QtGui.QMenu(self.menuBar) self.menuProject.setObjectName(_fromUtf8("menuProject")) self.menuView = QtGui.QMenu(self.menuBar) self.menuView.setObjectName(_fromUtf8("menuView")) self.menuTools = QtGui.QMenu(self.menuBar) self.menuTools.setObjectName(_fromUtf8("menuTools")) self.menuHelp = QtGui.QMenu(self.menuBar) self.menuHelp.setObjectName(_fromUtf8("menuHelp")) #Open a project file Action self.actionOpen = QtGui.QAction(MainWindow) self.actionOpen.setObjectName(_fromUtf8("actionOpen")) self.actionOpen.setShortcut("Ctrl+O") self.actionOpen.setStatusTip("Open a file") self.actionOpen.triggered.connect(lambda: self.open_file(MainWindow)) # New File Action self.actionNewFile = QtGui.QAction(MainWindow) self.actionNewFile.setObjectName(_fromUtf8("actionOpen")) self.actionNewFile.setShortcut("Ctrl+N") self.actionNewFile.setStatusTip("New File") self.actionNewFile.triggered.connect(self.new_file) #Save the Project Action self.actionSave = QtGui.QAction(MainWindow) self.actionSave.setObjectName(_fromUtf8("actionSave")) self.actionSave.setShortcut("Ctrl+S") self.actionSave.setStatusTip("Save the Project") #self.actionSave.connect(self.FUNCTION NAME) #Save As Action self.actionSave_As = QtGui.QAction(MainWindow) self.actionSave_As.setObjectName(_fromUtf8("actionSave_As")) #Open project Directory Action self.actionOpenProjectDirectory = QtGui.QAction(MainWindow) self.actionOpenProjectDirectory.setObjectName(_fromUtf8("actionOpen")) self.actionOpenProjectDirectory.setShortcut("Ctrl+N") self.actionOpenProjectDirectory.setStatusTip("Open a Project Folder") self.actionOpenProjectDirectory.triggered.connect( self.open_project_directory) #Quit the program Action self.actionQuit = QtGui.QAction(MainWindow) self.actionQuit.setObjectName(_fromUtf8("actionQuit")) self.actionQuit.setShortcut("Ctrl+Q") self.actionQuit.setStatusTip("Quit the application") self.actionQuit.triggered.connect( lambda: self.close_application(MainWindow)) self.actionOpenProjectViewerWindow = QtGui.QAction(MainWindow) self.actionOpenProjectViewerWindow.setObjectName( _fromUtf8("actionOpenProjectViewerWindow")) self.actionOpenProjectViewerWindow.setShortcut("Ctrl+P") self.actionOpenProjectViewerWindow.setStatusTip( "Open Project Viewer Window") self.actionOpenProjectViewerWindow.triggered.connect( self.openProjectViewerWindow) self.actionOpenConsoleOutputWindow = QtGui.QAction(MainWindow) self.actionOpenConsoleOutputWindow.setObjectName( _fromUtf8("actionOpenConsoleOutputWindow")) self.actionOpenConsoleOutputWindow.setShortcut("Ctrl+L") self.actionOpenConsoleOutputWindow.setStatusTip("Open Console Window") self.actionOpenConsoleOutputWindow.triggered.connect( self.openConsoleOutputWindow) #Add Action to the "File" submenu self.menuFile.addAction(self.actionNewFile) self.menuFile.addAction(self.actionOpen) self.menuFile.addAction(self.actionSave) self.menuFile.addAction(self.actionSave_As) self.menuFile.addAction(self.actionQuit) #Add Action to the "Project" submenu self.menuProject.addAction(self.actionOpenProjectDirectory) #Add Actions to the "View" Submenu self.menuView.addAction(self.actionOpenProjectViewerWindow) self.menuView.addAction(self.actionOpenConsoleOutputWindow) #Add Menu Items to the Menu Bar self.menuBar.addAction(self.menuFile.menuAction()) self.menuBar.addAction(self.menuEdit.menuAction()) self.menuBar.addAction(self.menuProject.menuAction()) self.menuBar.addAction(self.menuView.menuAction()) self.menuBar.addAction(self.menuTools.menuAction()) self.menuBar.addAction(self.menuHelp.menuAction()) #Name the Menu Items self.menuFile.setTitle(_translate("MainWindow", "File", None)) self.menuEdit.setTitle(_translate("MainWindow", "Edit", None)) self.menuProject.setTitle(_translate("MainWindow", "Project", None)) self.menuView.setTitle(_translate("MainWindow", "View", None)) self.menuTools.setTitle(_translate("MainWindow", "Tools", None)) self.menuHelp.setTitle(_translate("MainWindow", "Help", None)) self.actionNewFile.setText(_translate("MainWindow", "New File", None)) self.actionOpen.setText(_translate("MainWindow", "Open", None)) self.actionSave.setText(_translate("MainWindow", "Save", None)) self.actionSave_As.setText(_translate("MainWindow", "Save As", None)) self.actionQuit.setText(_translate("MainWindow", "Quit", None)) self.actionOpenProjectDirectory.setText( _translate("MainWindow", "Open Project Directory", None)) self.actionOpenProjectViewerWindow.setText( _translate("MainWindow", "Open Project Viewer Window", None)) self.actionOpenConsoleOutputWindow.setText( _translate("MainWindow", "Open Console Output Window", None)) MainWindow.setMenuBar(self.menuBar) def open_project_directory(self): self.projectViewer.open_project_directory() #self.gridLayout.update() def new_file(self): self.captureArea.newTab() def open_file(self, MainWindow): self.dlg = QtGui.QFileDialog(MainWindow) self.dlg.setFileMode(QtGui.QFileDialog.AnyFile) self.dlg.setFilter("Text files (*.txt)") #self.fileName = QtCore.QString() self.fileName = QtGui.QFileDialog.getOpenFileName( MainWindow, 'Open File', '/') print(str(self.fileName)) def close_application(self, MainWindow): choice = QtGui.QMessageBox.question( MainWindow, 'Extract!', "Quit the Application?", QtGui.QMessageBox.No | QtGui.QMessageBox.Yes) if choice == QtGui.QMessageBox.Yes: sys.exit() else: pass #The following function will deal with opening Docked Windows def openProjectViewerWindow(self): self.projectViewer.open_docker() def openConsoleOutputWindow(self): self.consoleOutput.open_docker()
def name_service(self): """Runs the name service on all atoms needing to be named. This is a complicated function which corrects most commonly found errors and omissions from PDB files. """ if len(self.name_service_list) == 0: return ## returns the next available chain_id in self.struct ## XXX: it's possible to run out of chain IDs! def next_chain_id(suggest_chain_id): if suggest_chain_id != "": chain = self.struct.get_chain(suggest_chain_id) if not chain: return suggest_chain_id ## TODO: Add the following alphanumeric string to Constants.py, 2010-09-21 for chain_id in "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789": chain = self.struct.get_chain(chain_id) if not chain: return chain_id raise StructureBuilderError("name_service exhausted new chain_ids") ## NAME SERVICE FOR POLYMER ATOMS ## What if we are given a list of atoms with res_name, frag_id, and ## model_id where the frag_id are sequential? They can be sequential ## several ways using insertion codes, but large breaks often denote ## chain breaks. ## We need to handle the special case of a list of polymer residues ## which do not have chain_ids. This requires a first pass over the ## atom list using different rules than what we use for sorting out ## non-polymers. current_polymer_type = None current_polymer_model_id = None current_polymer_chain_id = None current_polymer_frag_id = None current_polymer_res_name = None current_polymer_name_dict = None polymer_model_dict = {} current_frag = None current_frag_list = None for atm in self.name_service_list[:]: ## determine the polymer type of the atom if Library.library_is_amino_acid(atm.res_name): polymer_type = "protein" elif Library.library_is_nucleic_acid(atm.res_name): polymer_type = "dna" else: ## if the atom is not a polymer, we definitely have a break ## in this chain current_polymer_type = None current_polymer_model_id = None current_polymer_chain_id = None current_polymer_frag_id = None current_polymer_res_name = None current_polymer_name_dict = None current_frag = None current_frag_list = None continue fragment_id = Structure.FragmentID(atm.fragment_id) ## now we deal with conditions which can terminate the current ## polymer chain if polymer_type!=current_polymer_type or \ atm.model_id!=current_polymer_model_id or \ atm.chain_id!=current_polymer_chain_id or \ fragment_id<current_polymer_frag_id: current_polymer_type = polymer_type current_polymer_model_id = atm.model_id current_polymer_chain_id = atm.chain_id current_polymer_frag_id = Structure.FragmentID(atm.fragment_id) current_polymer_res_name = atm.res_name current_polymer_name_dict = {atm.name: True} ## create new fragment current_frag = [atm] current_frag_list = [current_frag] ## create new fragment list (chain) try: model = polymer_model_dict[atm.model_id] except KeyError: model = [current_frag_list] polymer_model_dict[atm.model_id] = model else: model.append(current_frag_list) ## we have now dealt with the atom, so it can be removed from ## the name service list self.name_service_list.remove(atm) continue ## if we get here, then we know this atom is destine for the ## current chain, and the algorithm needs to place the atom ## in the current fragment, or create a new fragment for it ## to go into; the conditions for it going into the current ## fragment are: it has it have the same res_name, and its ## atom name cannot conflict with the names of atoms already in ## in the fragment if atm.res_name != current_polymer_res_name or current_polymer_name_dict.has_key(atm.name): current_polymer_res_name = atm.res_name current_polymer_name_dict = {atm.name: True} ## create new fragment and add it to the current fragment list current_frag = [atm] current_frag_list.append(current_frag) ## we have now dealt with the atom, so it can be removed ## from the name service list self.name_service_list.remove(atm) continue ## okay, put it in the current fragment current_frag.append(atm) self.name_service_list.remove(atm) ## now assign chain_ids and add the atoms to the structure model_ids = polymer_model_dict.keys() model_ids.sort() model_list = [polymer_model_dict[model_id] for model_id in model_ids] num_chains = 0 for frag_list in polymer_model_dict.itervalues(): num_chains = max(num_chains, len(frag_list)) for chain_index in xrange(num_chains): ## get next available chain_id chain_id = next_chain_id("") ## assign the chain_id to all the atoms in the chain ## TODO: check fragment_id too, 2010-09-22 for model in model_list: frag_list = model[chain_index] for frag in frag_list: for atm in frag: atm.chain_id = chain_id self.struct.add_atom(atm, True) ## free the memory used by the polymer naming service del polymer_model_dict del model_list ## NAME SERVICE FOR NON-POLYMER ATOMS ## cr = (chain_id, res_name) ## ## cr_dict[cr_key] = model_dict ## ## model_dict[model] = frag_list ## ## frag_list = [ frag1, frag2, frag3, ...] ## ## frag = [atm1, atm2, atm3, ...] cr_dict = {} cr_key_list = [] frag_id = None frag = None name_dict = {} ## split atoms into fragments for atm in self.name_service_list: atm_id = (atm.name, atm.alt_loc) atm_frag_id = (atm.model_id, atm.chain_id, atm.fragment_id, atm.res_name) ## if the atom fragment id matches the current fragment id ## and doesn't conflict with any other atom name in the fragment ## then add it to the fragment if atm_frag_id==frag_id and not name_dict.has_key(atm_id): frag.append(atm) name_dict[atm_id] = True else: cr_key = (atm.chain_id, atm.res_name) ### debug if frag: msg = "name_service: fragment detected in cr=%s" % ( str(cr_key)) ConsoleOutput.debug(msg) for a in frag: ConsoleOutput.debug(" " + str(a)) ### /debug try: model_dict = cr_dict[cr_key] except KeyError: model_dict = cr_dict[cr_key] = {} cr_key_list.append(cr_key) try: frag_list = model_dict[atm.model_id] except KeyError: frag_list = model_dict[atm.model_id] = [] name_dict = {atm_id: True} frag_id = atm_frag_id frag = [atm] frag_list.append(frag) ## free self.name_service_list and other vars to save some memory del self.name_service_list new_chain_id = None fragment_id_num = None for cr_key in cr_key_list: ### debug msg = "name_service: chain_id / res_name keys\n" msg += " cr_key: chain_id='%s' res_name='%s'" % ( cr_key[0], cr_key[1]) ConsoleOutput.debug(msg) ### /debug ## get the next chain ID, use the cfr group's ## loaded chain_id if possible chain_id = next_chain_id(cr_key[0]) ## if we are not out of chain IDs, use the new chain ID and ## reset the fragment_id if chain_id != None: new_chain_id = chain_id fragment_id_num = 0 elif new_chain_id == None or fragment_id_num == None: ConsoleOutput.fatal("name_service: unable to assign any chain ids") ## get model dictionary model_dict = cr_dict[cr_key] ## inspect the model dictionary to determine the number of ## fragments in each model -- they should be the same ## and have a 1:1 correspondence; if not, match up the ## fragments as much as possible max_frags = -1 for (model, frag_list) in model_dict.iteritems(): frag_list_len = len(frag_list) if max_frags == -1: max_frags = frag_list_len continue if max_frags != frag_list_len: strx = "name_service: model fragments not identical" ConsoleOutput.debug(strx) ConsoleOutput.warning(strx) max_frags = max(max_frags, frag_list_len) ## now iterate through the fragment lists in parallel and assign ## the new chain_id and fragment_id for i in xrange(max_frags): fragment_id_num += 1 for frag_list in model_dict.itervalues(): try: frag = frag_list[i] except IndexError: continue ## assign new chain_id and fragment_id, than place the ## atom in the structure for atm in frag: atm.chain_id = new_chain_id atm.fragment_id = str(fragment_id_num) self.struct.add_atom(atm, True) ## logging ConsoleOutput.warning("name_service(): added chain_id=%s, res_name=%s, num_residues=%d" % ( new_chain_id, cr_key[1], fragment_id_num))
def library_guess_element_from_name(name0, res_name): """Try everything we can possibly think of to extract the element symbol from the atom name. If available, use the monomer dictionary to help narrow down the search. """ ## strip any space from the name, and return now if there ## is nothing left to work with name = name0.strip() if name == "": return None if name0 != res_name: ## try the easy way out -- look up the atom in the monomer dictionary mdesc = library_get_monomer_desc(res_name) if mdesc is not None: if mdesc.atom_dict.has_key(name): symbol = mdesc.atom_dict[name] if symbol is not None: return symbol if mdesc.is_amino_acid() and name == "OXT": return "O" if mdesc.is_amino_acid(): msg = "invalid amino acid atom name '%s' in residue '%s'" % ( name, res_name) ConsoleOutput.warning(msg) ## okay, that didn't work... ## set the space_flag to true if the name starts with a space, which can ## indicate the name of the atom is only 1 character long. if name0.startswith(" "): space_flag = True else: space_flag = False ## remove all non-alpha chars from the name alpha_name = "" for c in name: if c.isalpha() == True: alpha_name += c ## look up two possible element symbols in the library: ## e1 is the possible one-character symbol ## e2 is the possible two-character symbol if len(alpha_name) == 0: return None e1_symbol = alpha_name[0] e1_valid = ELEMENT_SYMBOL_DICT.has_key(e1_symbol) if len(alpha_name) > 1: e2_symbol = alpha_name[:2] e2_valid = ELEMENT_SYMBOL_DICT.has_key(e2_symbol) else: e2_symbol = None e2_valid = False ## e1 or e2 must return something for us to proceed, otherwise, ## there's just no possible element symbol contained in the atom ## name if e1_valid == False and e2_valid == False: return None elif e1_valid == True and e2_valid == False: return e1_symbol elif e1_valid == False and e2_valid == True: return e2_symbol ## if we get here, then e1 and e2 are both valid elements ## we're out of choices, go by the space_flag: if there is a space ## before the atom name, then use the 1-char element symbol; ## if there is no space, then use the 2-char element symbol if space_flag == True: return e1_symbol return e2_symbol
def read_struct_conn(self): """Read bond information form the struct_conn and struct_conn_type sections. """ ## only read these types of bonds for now bond_type_list = [ "covale", # covalent bond "metalc", # metal coordination "disulf", # disulfide bridge "saltbr", # ionic interaction "covale_base", # covalent modification of a nucleotide base "covale_sugar", # covalent modification of a nucleotide sugar "covale_phosphate", # covalent modification of a nucleotide phosphate ] try: atom_site = self.cif_data["atom_site"] except KeyError: ConsoleOutput.warning( "read_struct_conn: atom_site table not found") return try: struct_conn_table = self.cif_data["struct_conn"] except KeyError: ConsoleOutput.warning( "read_struct_conn: struct_conn table not found") return bond_map = {} for row in struct_conn_table: conn_type = row.get("conn_type_id") if conn_type not in bond_type_list: continue # Always use label_ values since they are mandatory asym_id1 = row.get("ptnr1_label_asym_id") seq_id1 = row.get("ptnr1_label_seq_id") comp_id1 = row.get("ptnr1_label_comp_id") atom_id1 = row.get("ptnr1_label_atom_id") auth_asym_id1 = row.get("ptnr1_auth_asym_id") auth_seq_id1 = row.get("ptnr1_auth_seq_id") auth_comp_id1 = row.get("ptnr1_auth_comp_id") symm1 = row.get("ptnr1_symmetry") asym_id2 = row.get("ptnr2_label_asym_id") seq_id2 = row.get("ptnr2_label_seq_id") comp_id2 = row.get("ptnr2_label_comp_id") atom_id2 = row.get("ptnr2_label_atom_id") auth_asym_id2 = row.get("ptnr2_auth_asym_id") auth_seq_id2 = row.get("ptnr2_auth_seq_id") auth_comp_id2 = row.get("ptnr2_auth_comp_id") symm2 = row.get("ptnr2_symmetry") ## check for these special mmCIF tokens if conn_type == "disulf": atom_id1 = atom_id2 = "SG" as1list = atom_site.get_all_rows( ("label_asym_id", asym_id1), ("label_seq_id", seq_id1), ("label_comp_id", comp_id1), ("auth_asym_id", auth_asym_id1), ("auth_seq_id", auth_seq_id1), ("auth_comp_id", auth_comp_id1), ("label_atom_id", atom_id1)) as2list = atom_site.get_all_rows( ("label_asym_id", asym_id2), ("label_seq_id", seq_id2), ("label_comp_id", comp_id2), ("auth_asym_id", auth_asym_id2), ("auth_seq_id", auth_seq_id2), ("auth_comp_id", auth_comp_id2), ("label_atom_id", atom_id2)) if not as1list or not as2list: ConsoleOutput.warning("read_struct_conn: atom not found id: " + \ row.get("id","[No ID]")) ConsoleOutput.warning( "atm1: asym=%s seq=%s comp=%s atom=%s symm=%s" % (asym_id1, seq_id1, comp_id1, atom_id1, symm1)) ConsoleOutput.warning( "atm2: asym=%s seq=%s comp=%s atom=%s symm=%s" % (asym_id2, seq_id2, comp_id2, atom_id2, symm2)) continue for as1 in as1list: for as2 in as2list: try: atm1 = self.atom_site_id_map[as1["id"]] atm2 = self.atom_site_id_map[as2["id"]] except KeyError: ConsoleOutput.warning("read_struct_conn: atom_site_id_map incorrect id: " + \ row.get("id", "[No ID]")) ConsoleOutput.warning( "atm1: asym=%s seq=%s comp=%s atom=%s symm=%s" % (asym_id1, seq_id1, comp_id1, atom_id1, symm1)) ConsoleOutput.warning( "atm2: asym=%s seq=%s comp=%s atom=%s symm=%s" % (asym_id2, seq_id2, comp_id2, atom_id2, symm2)) continue if atm1.model_id != atm2.model_id: continue if id(atm1) < id(atm2): bnd = (atm1, atm2) else: bnd = (atm2, atm1) try: bond_map[bnd]["bond_type"] = conn_type except KeyError: bond_map[bnd] = {"bond_type": conn_type} if symm1: bond_map[bnd]["symop1"] = symm1 if symm2: bond_map[bnd]["symop2"] = symm2 ## load the bonds self.load_bonds(bond_map)
def name_service(self): """Runs the name service on all atoms needing to be named. This is a complicated function which corrects most commonly found errors and omitions from PDB files. """ if len(self.name_service_list) == 0: return ## returns the next available chain_id in self.struct ## XXX: it's possible to run out of chain IDs! def next_chain_id(suggest_chain_id): if suggest_chain_id != "": chain = self.struct.get_chain(suggest_chain_id) if not chain: return suggest_chain_id for chain_id in "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789": chain = self.struct.get_chain(chain_id) if not chain: return chain_id raise StructureBuilderError("name_service exhausted new chain_ids") ## NAME SERVICE FOR POLYMER ATOMS ## what if we are given a list of atoms with res_name, frag_id, ## and model_id where the frag_id are sequental? they can be ## sequental several ways using insertion codes, but large breaks ## often denote chain breaks ## I need to handle the special case of a list of polymer residues ## which do not have chain_ids. This requires a first pass over ## the atom list usind different rules than what I use for sorting ## out non-polymers current_polymer_type = None current_polymer_model_id = None current_polymer_chain_id = None current_polymer_frag_id = None current_polymer_res_name = None current_polymer_name_dict = None polymer_model_dict = {} current_frag = None current_frag_list = None for atm in self.name_service_list[:]: ## determine the polymer type of the atom if Library.library_is_amino_acid(atm.res_name): polymer_type = "protein" elif Library.library_is_nucleic_acid(atm.res_name): polymer_type = "dna" else: ## if the atom is not a polymer, we definately have a break ## in this chain current_polymer_type = None current_polymer_model_id = None current_polymer_chain_id = None current_polymer_frag_id = None current_polymer_res_name = None current_polymer_name_dict = None current_frag = None current_frag_list = None continue fragment_id = Structure.FragmentID(atm.fragment_id) ## now we deal with conditions which can terminate the current ## polymer chain if polymer_type!=current_polymer_type or \ atm.model_id!=current_polymer_model_id or \ atm.chain_id!=current_polymer_chain_id or \ fragment_id<current_polymer_frag_id: current_polymer_type = polymer_type current_polymer_model_id = atm.model_id current_polymer_chain_id = atm.chain_id current_polymer_frag_id = Structure.FragmentID(atm.fragment_id) current_polymer_res_name = atm.res_name current_polymer_name_dict = {atm.name: True} ## create new fragment current_frag = [atm] current_frag_list = [current_frag] ## create new fragment list (chain) try: model = polymer_model_dict[atm.model_id] except KeyError: model = [current_frag_list] polymer_model_dict[atm.model_id] = model else: model.append(current_frag_list) ## we have now dealt with the atom, so it can be removed ## from the name service list self.name_service_list.remove(atm) continue ## if we get here, then we know this atom is destine for the ## current chain, and the algorithm needs to place the atom ## in the current fragment, or create a new fragment for it ## to go into; the conditions for it going into the current ## fragment are: it has it have the same res_name, and its ## atom name cannot conflict with the names of atoms already in ## in the fragment if atm.res_name != current_polymer_res_name or current_polymer_name_dict.has_key( atm.name): current_polymer_res_name = atm.res_name current_polymer_name_dict = {atm.name: True} ## create new fragment and add it to the current fragment list current_frag = [atm] current_frag_list.append(current_frag) ## we have now dealt with the atom, so it can be removed ## from the name service list self.name_service_list.remove(atm) continue ## okay, put it in the current fragment current_frag.append(atm) self.name_service_list.remove(atm) ## now assign chain_ids and add the atoms to the structure model_ids = polymer_model_dict.keys() model_ids.sort() model_list = [polymer_model_dict[model_id] for model_id in model_ids] num_chains = 0 for frag_list in polymer_model_dict.itervalues(): num_chains = max(num_chains, len(frag_list)) for chain_index in xrange(num_chains): ## get next availible chain_id chain_id = next_chain_id("") ## assign the chain_id to all the atoms in the chain ## TODO: check fragment_id too for model in model_list: frag_list = model[chain_index] for frag in frag_list: for atm in frag: atm.chain_id = chain_id self.struct.add_atom(atm, True) ## free the memory used by the polymer naming service del polymer_model_dict del model_list ## NAME SERVICE FOR NON-POLYMER ATOMS ## cr = (chain_id, res_name) ## ## cr_dict[cr_key] = model_dict ## ## model_dict[model] = frag_list ## ## frag_list = [ frag1, frag2, frag3, ...] ## ## frag = [atm1, atm2, atm3, ...] cr_dict = {} cr_key_list = [] frag_id = None frag = None name_dict = {} ## split atoms into fragments for atm in self.name_service_list: atm_id = (atm.name, atm.alt_loc) atm_frag_id = (atm.model_id, atm.chain_id, atm.fragment_id, atm.res_name) ## if the atom fragment id matches the current fragment id ## and doesn't conflict with any other atom name in the fragment ## then add it to the fragment if atm_frag_id == frag_id and not name_dict.has_key(atm_id): frag.append(atm) name_dict[atm_id] = True else: cr_key = (atm.chain_id, atm.res_name) ### debug if frag: ConsoleOutput.debug( "name_service: fragment detected in cr=%s" % (str(cr_key))) for a in frag: ConsoleOutput.debug(" " + str(a)) ### /debug try: model_dict = cr_dict[cr_key] except KeyError: model_dict = cr_dict[cr_key] = {} cr_key_list.append(cr_key) try: frag_list = model_dict[atm.model_id] except KeyError: frag_list = model_dict[atm.model_id] = [] name_dict = {atm_id: True} frag_id = atm_frag_id frag = [atm] frag_list.append(frag) ## free self.name_service_list and other vars to save some memory del self.name_service_list new_chain_id = None fragment_id_num = None for cr_key in cr_key_list: ### debug ConsoleOutput.debug("name_service: chain_id / res_name keys") ConsoleOutput.debug(" cr_key: chain_id='%s' res_name='%s'" % (cr_key[0], cr_key[1])) ### /debug ## get the next chain ID, use the cfr group's ## loaded chain_id if possible chain_id = next_chain_id(cr_key[0]) ## if we are not out of chain IDs, use the new chain ID and ## reset the fragment_id if chain_id != None: new_chain_id = chain_id fragment_id_num = 0 elif new_chain_id == None or fragment_id_num == None: ConsoleOutput.fatal( "name_service: unable to assign any chain ids") ## get model dictionary model_dict = cr_dict[cr_key] ## inspect the model dictionary to determine the number ## of fragments in each model -- they should be the same ## and have a 1:1 cooraspondance; if not, match up the ## fragments as much as possible max_frags = -1 for (model, frag_list) in model_dict.iteritems(): frag_list_len = len(frag_list) if max_frags == -1: max_frags = frag_list_len continue if max_frags != frag_list_len: strx = "name_service: model fragments not identical" ConsoleOutput.debug(strx) ConsoleOutput.warning(strx) max_frags = max(max_frags, frag_list_len) ## now iterate through the fragment lists in parallel and assign ## the new chain_id and fragment_id for i in xrange(max_frags): fragment_id_num += 1 for frag_list in model_dict.itervalues(): try: frag = frag_list[i] except IndexError: continue ## assign new chain_id and fragment_id, than place the ## atom in the structure for atm in frag: atm.chain_id = new_chain_id atm.fragment_id = str(fragment_id_num) self.struct.add_atom(atm, True) ## logging ConsoleOutput.warning( "name_service(): added chain_id=%s, res_name=%s, num_residues=%d" % (new_chain_id, cr_key[1], fragment_id_num))
def library_construct_monomer_desc(res_name): """Constructs the MonomerDesc object for the given residue name. """ ## return None when the res_name is an empty string if len(res_name) < 1: return None if ALT_RES_NAME_DICT.has_key(res_name): lookup_name = ALT_RES_NAME_DICT[res_name] else: lookup_name = res_name.upper() libfil = library_open_monomer_lib_file(lookup_name) if libfil is None: ConsoleOutput.warning("monomer description not found for '%s'" % (res_name)) return None ## generate monomer description mon_desc = MonomerDesc() ## data from RCSB library rcsb_cif_file = mmCIF.mmCIFFile() rcsb_cif_file.load_file(libfil) rcsb_cif_data = rcsb_cif_file[0] libfil.close() chem_comp = rcsb_cif_data.get_table("chem_comp")[0] mon_desc.res_name = chem_comp.get_lower("res_name") mon_desc.full_name = chem_comp.get_lower("name") mon_desc.type = chem_comp.get_lower("type") mon_desc.pdbx_type = chem_comp.get_lower("pdbx_type") mon_desc.formula = chem_comp.get_lower("formula") mon_desc.rcsb_class_1 = chem_comp.get_lower("rcsb_class_1") chem_comp_atom = rcsb_cif_data.get_table("chem_comp_atom") if chem_comp_atom is not None: for cif_row in chem_comp_atom: name = cif_row.getitem_lower("atom_id") try: symbol = cif_row.getitem_lower("type_symbol") except KeyError: ## this should occur when an atom name does not match the ones ## found in a monomer file symbol = name msg = "unrecognized atom name: '%s' in residue '%s'" % ( symbol, res_name) ConsoleOutput.warning(msg) mon_desc.atom_list.append({"name": name, "symbol": symbol}) mon_desc.atom_dict[name] = symbol try: alt_name = cif_row.getitem_lower("alt_atom_id") except KeyError: pass else: mon_desc.alt_atom_dict[name] = alt_name chem_comp_bond = rcsb_cif_data.get_table("chem_comp_bond") if chem_comp_bond is not None: for cif_row in chem_comp_bond: atom1 = cif_row.getitem_lower("atom_id_1") atom2 = cif_row.getitem_lower("atom_id_2") mon_desc.bond_list.append({"atom1": atom1, "atom2": atom2}) ## data from mmLib supplemental library in mmLib/Data/monomers.cif mmlib_cif_data = MMLIB_MONOMERS_CIF.get_data(res_name) if mmlib_cif_data is not None: ## get additional chemical information on amino acids chem_comp = mmlib_cif_data.get_table("chem_comp") if chem_comp is not None: mon_desc.one_letter_code = chem_comp["one_letter_code"] mon_desc.chem_type = chem_comp["chem_type"] ## get torsion angle definitions torsion_angles = mmlib_cif_data.get_table("torsion_angles") if torsion_angles is not None: for cif_row in torsion_angles: mon_desc.torsion_angle_dict[cif_row["name"]] = ( cif_row["atom1"], cif_row["atom2"], cif_row["atom3"], cif_row["atom4"]) ## set some derived flags on the monomer description mon_type = mon_desc.type.upper() if mon_type == "L-PEPTIDE LINKING": mon_desc.amino_acid = True elif mon_type == "DNA LINKING" or mon_type == "RNA LINKING": mon_desc.nucleic_acid = True elif mon_type == "HOH" or mon_type == "WAT": mon_desc.water = True return mon_desc
class Ui_MainWindow(QtGui.QMainWindow): def __init__(self, MainWindow, *args, **kwargs): super(Ui_MainWindow, self).__init__(*args, **kwargs) #This is for the splash screen showSplashScreen = False if (showSplashScreen == True): splashLogo = QtGui.QPixmap("./imgs/splashScreen.jpg") splashScreen = QtGui.QSplashScreen(splashLogo, QtCore.Qt.WindowStaysOnTopHint) splashScreen.setMask(splashLogo.mask()) splashScreen.show() time.sleep(2.0) self.setupUi(MainWindow) def setupUi(self, MainWindow): MainWindow.setObjectName(_fromUtf8("MainWindow")) MainWindow.resize(1016, 818) #Central Widget is the main area to put Widgets on the program #Itis not a container. self.centralwidget = QtGui.QWidget(MainWindow) self.centralwidget.setObjectName(_fromUtf8("centralwidget")) self.init_tool_bar(MainWindow) # initialize the Console Output self.consoleOutput = ConsoleOutput(MainWindow) #initialize the Capture Area self.captureArea = CaptureArea(self.centralwidget, self.consoleOutput) MainWindow.setCentralWidget(self.centralwidget) #Initialize the ProjectViewer self.projectViewer = ProjectViewer(MainWindow) #This may be the buttons but might remove in an update #self.dockWidgetControls = QtGui.QDockWidget(MainWindow) #self.dockWidgetControls.setObjectName(_fromUtf8("dockWidgetControls")) self.dockWidgetContents_8 = QtGui.QWidget() self.dockWidgetContents_8.setObjectName( _fromUtf8("dockWidgetContents_8")) self.pushButton = QtGui.QPushButton(self.dockWidgetContents_8) self.pushButton.setGeometry(QtCore.QRect(10, 10, 61, 51)) self.pushButton.setObjectName(_fromUtf8("pushButton")) #elf.dockWidgetControls.setWidget(self.dockWidgetContents_8) #MainWindow.addDockWidget(QtCore.Qt.DockWidgetArea(2), self.dockWidgetControls) MainWindow.setCentralWidget(self.centralwidget) #Set up the Menu Bar self.init_menu_bar(MainWindow) self.statusbar = QtGui.QStatusBar(MainWindow) self.statusbar.setObjectName(_fromUtf8("statusbar")) MainWindow.setStatusBar(self.statusbar) self.retranslateUi(MainWindow) QtCore.QMetaObject.connectSlotsByName(MainWindow) #This is a virtual method that is used to set the text, this makes it easy to support multiple languages def retranslateUi(self, MainWindow): #This will be used to support multiple languages MainWindow.setWindowTitle( _translate("MainWindow", "Mo Cap pie - Team Ep0ch", None)) MainWindow.setWindowIcon(QtGui.QIcon("./imgs/icon.ico")) #self.captureArea.setTabText(self.captureArea.indexOf(self.tab), _translate("MainWindow", "Tab 1", None)) #self.captureArea.setTabText(self.captureArea.indexOf(self.tab_2), _translate("MainWindow", "Tab 2", None)) #Method I wrote to set up the docakable tool bar def init_tool_bar(self, MainWindow): #This line assigns this veriable to a QAction. then set the ICON and text self.playMotionAction = QtGui.QAction( QtGui.QIcon("./imgs/PlayGreenButton.ico"), "Play Motion", MainWindow) #This is how you link a QAction to a function. The function here is Play_motion self.playMotionAction.triggered.connect(self.play_motion) #If you would like a new button, you can just copy these 2 lines like how I did for the next 3. This simpley makes #the veriable, once created, you have to add these "actions" to a menu or tool bar. self.pauseMotionAction = QtGui.QAction(QtGui.QIcon("./imgs/Pause.ico"), "Pause Motion Capture", MainWindow) self.pauseMotionAction.triggered.connect(self.pause_motion) self.stopMotionAction = QtGui.QAction( QtGui.QIcon("./imgs/StopRedButton.ico"), "Stop Motion Capture", MainWindow) self.stopMotionAction.triggered.connect(self.stop_motion) self.recordMotionAction = QtGui.QAction( QtGui.QIcon("./imgs/RecordButton.ico"), "Record New Motion Capture", MainWindow) self.recordMotionAction.triggered.connect(self.record_Motion) self.testMotionAction = QtGui.QAction( QtGui.QIcon("./imgs/playbackmotion.ico"), "Playback motion", MainWindow) self.testMotionAction.triggered.connect(self.playback_motion) self.connectCamerasAction = QtGui.QAction( QtGui.QIcon("./imgs/connect.ico"), "Connect to Cameras", MainWindow) self.connectCamerasAction.triggered.connect(self.connectCameras) self.takePictureAction = QtGui.QAction( QtGui.QIcon("./imgs/takepicture.ico"), "take Calibration picture", MainWindow) self.takePictureAction.triggered.connect(self.takeCalibrationPicture) # Let me tell you all a story about a mouse named glory #Here I create a tool bar and add it to the MainWindow. self.toolBar = MainWindow.addToolBar("Test test") #Once the toolbar is made, you can add the actions, AKA buttons, to the tool bar like so. self.toolBar.addAction(self.playMotionAction) self.toolBar.addAction(self.pauseMotionAction) self.toolBar.addAction(self.stopMotionAction) self.toolBar.addAction(self.recordMotionAction) self.toolBar.addAction(self.testMotionAction) self.toolBar.addAction(self.connectCamerasAction) self.toolBar.addAction(self.takePictureAction) def takeCalibrationPicture(self): self.captureArea.takeCalibrationPicture() def connectCameras(self): self.captureArea.connectToCameras() #self.captureArea.rectify() def playback_motion(self): motion_file = Path("./motion.txt") if motion_file.is_file(): self.captureArea.playBackMotion() self.consoleOutput.outputText("Playing back recorded motion...") else: self.consoleOutput.outputText( "A pre recorded motion file does not exist.") #Yoy need to link a button action to a method, so this method is called when the user clicks, "record motion" button def record_Motion(self): #this line just prints the string to the output console in the program self.captureArea.recordMotion() # you could just do "print("test stuff")" to print to IDE consoles #same as above, this method is called wehn you click play motion button def play_motion(self): self.captureArea.start_clicked() #Same, this button does not work. To pause, need access to CVHandlerCLass which is not made in this class. def pause_motion(self): self.captureArea.stopRecording() #same as above def stop_motion(self): self.consoleOutput.outputText("Motion Captured stopped") self.captureArea.stop_playback() #This method is called when clicked set up cameras button def setUpWizardAction(self): #This creates a new instance of SetUpWizard class self.setUpWizard = SetUpWizard() #This is just like the tool bar except this is a menu bar. "File, Edit, Help, ect" def init_menu_bar(self, MainWindow): #Create a new QMenuBar, Takes in a QMainWindow self.menuBar = QtGui.QMenuBar(MainWindow) #This line is false to improve functionality for Linux. self.menuBar.setNativeMenuBar(False) #This changes the size. NOTE: I did not set these numbers, they are auto generated in QT Designer 4 self.menuBar.setGeometry(QtCore.QRect(0, 0, 1055, 25)) #Every single QSomthing, need a UNIQUE object name, no 2 can be alike self.menuBar.setObjectName(_fromUtf8("menubar")) #Initialze the Menu Items #This is how you make menu items, like "File" self.menuFile = QtGui.QMenu(self.menuBar) # again needs a unique object name self.menuFile.setObjectName(_fromUtf8("menuFile")) #made a "Edit" menu item here self.menuEdit = QtGui.QMenu(self.menuBar) self.menuEdit.setObjectName(_fromUtf8("menuEdit")) #made a "Project" menu item self.menuProject = QtGui.QMenu(self.menuBar) self.menuProject.setObjectName(_fromUtf8("menuProject")) #made a "View" menu item here self.menuView = QtGui.QMenu(self.menuBar) self.menuView.setObjectName(_fromUtf8("menuView")) #made a "Tools" menu item self.menuTools = QtGui.QMenu(self.menuBar) self.menuTools.setObjectName(_fromUtf8("menuTools")) #Help menu item self.menuHelp = QtGui.QMenu(self.menuBar) self.menuHelp.setObjectName(_fromUtf8("menuHelp")) #Note: The above lines makes the Main Menus, these are not the sub menus #blow is how to make actions for the menu bar. #These 5 lines is how to create a sub menu item #Open a project file Action self.actionOpen = QtGui.QAction(MainWindow) self.actionOpen.setObjectName(_fromUtf8("actionOpen")) #This is how to set a shortcut. self.actionOpen.setShortcut("Ctrl+O") #this is a tool tip, just a tip that pops up if the user hovers over the button self.actionOpen.setStatusTip("Open a file") #this is how you link the button to a function #You might have notcie the "lambda". I don't truly understand it but let me explain why and what it is for. # in Python, to create an Anonamous function, you use the keyword lambda. Anonamous methods are like regular methods #except they do not have a method name. This is used here to pass in "MainWindow" to the Open_File method when the #user clicks #This is how you pass in veriables to a method that is connected to a button. self.actionOpen.triggered.connect(lambda: self.open_file(MainWindow)) # New File Action self.actionNewFile = QtGui.QAction(MainWindow) self.actionNewFile.setObjectName(_fromUtf8("actionOpen")) self.actionNewFile.setShortcut("Ctrl+N") self.actionNewFile.setStatusTip("New File") self.actionNewFile.triggered.connect(self.new_file) #Save the Project Action self.actionSave = QtGui.QAction(MainWindow) self.actionSave.setObjectName(_fromUtf8("actionSave")) self.actionSave.setShortcut("Ctrl+S") self.actionSave.setStatusTip("Save the Project") #self.actionSave.connect(self.FUNCTION NAME) #Save As Action self.actionSave_As = QtGui.QAction(MainWindow) self.actionSave_As.setObjectName(_fromUtf8("actionSave_As")) #Open project Directory Action self.actionOpenProjectDirectory = QtGui.QAction(MainWindow) self.actionOpenProjectDirectory.setObjectName(_fromUtf8("actionOpen")) self.actionOpenProjectDirectory.setShortcut("Ctrl+I") self.actionOpenProjectDirectory.setStatusTip("Open a Project Folder") self.actionOpenProjectDirectory.triggered.connect( self.open_project_directory) #Quit the program Action self.actionQuit = QtGui.QAction(MainWindow) self.actionQuit.setObjectName(_fromUtf8("actionQuit")) self.actionQuit.setShortcut("Ctrl+Q") self.actionQuit.setStatusTip("Quit the application") self.actionQuit.triggered.connect( lambda: self.close_application(MainWindow)) self.actionOpenProjectViewerWindow = QtGui.QAction(MainWindow) self.actionOpenProjectViewerWindow.setObjectName( _fromUtf8("actionOpenProjectViewerWindow")) self.actionOpenProjectViewerWindow.setShortcut("Ctrl+P") self.actionOpenProjectViewerWindow.setStatusTip( "Open Project Viewer Window") self.actionOpenProjectViewerWindow.triggered.connect( self.openProjectViewerWindow) self.setUpWizardActionButton = QtGui.QAction(MainWindow) self.setUpWizardActionButton.setObjectName( _fromUtf8("setUpWizardAction")) self.setUpWizardActionButton.setShortcut("Ctrl+K") self.setUpWizardActionButton.setStatusTip("Set up the Cameras") self.setUpWizardActionButton.triggered.connect(self.setUpWizardAction) self.actionOpenConsoleOutputWindow = QtGui.QAction(MainWindow) self.actionOpenConsoleOutputWindow.setObjectName( _fromUtf8("actionOpenConsoleOutputWindow")) self.actionOpenConsoleOutputWindow.setShortcut("Ctrl+L") self.actionOpenConsoleOutputWindow.setStatusTip("Open Console Window") self.actionOpenConsoleOutputWindow.triggered.connect( self.openConsoleOutputWindow) self.actionConnectToStream = QtGui.QAction(MainWindow) self.actionConnectToStream.setObjectName( _fromUtf8("actionConnectToStream")) self.actionConnectToStream.setShortcut("Ctrl+M") self.actionConnectToStream.setStatusTip("Connect to a stream") self.actionConnectToStream.triggered.connect(self.connectToStream) #Add Action to the "File" submenu #here we add all the items to the "File" Menu self.menuFile.addAction(self.actionNewFile) self.menuFile.addAction(self.actionOpen) self.menuFile.addAction(self.actionSave) self.menuFile.addAction(self.actionSave_As) self.menuFile.addAction(self.actionQuit) #Add Action to the "Project" submenu #Here we add actions to the "Project" menu self.menuProject.addAction(self.actionOpenProjectDirectory) self.menuProject.addAction(self.actionConnectToStream) #Add Actions to the "View" Submenu self.menuView.addAction(self.actionOpenProjectViewerWindow) self.menuView.addAction(self.actionOpenConsoleOutputWindow) #Add Menu Items to the Menu Bar #Here we add all the main menus to the menu Bar self.menuBar.addAction(self.menuFile.menuAction()) self.menuBar.addAction(self.menuEdit.menuAction()) self.menuBar.addAction(self.menuProject.menuAction()) self.menuBar.addAction(self.menuView.menuAction()) self.menuBar.addAction(self.menuTools.menuAction()) self.menuBar.addAction(self.menuHelp.menuAction()) #Add Menu Items to the Menu Bar self.menuTools.addAction(self.setUpWizardActionButton) #Name the Menu Items #used to set the text, can be used to translate to different languges self.menuFile.setTitle(_translate("MainWindow", "File", None)) self.menuEdit.setTitle(_translate("MainWindow", "Edit", None)) self.menuProject.setTitle(_translate("MainWindow", "Project", None)) self.menuView.setTitle(_translate("MainWindow", "View", None)) self.menuTools.setTitle(_translate("MainWindow", "Tools", None)) self.menuHelp.setTitle(_translate("MainWindow", "Help", None)) self.actionNewFile.setText(_translate("MainWindow", "New File", None)) self.actionOpen.setText(_translate("MainWindow", "Open", None)) self.actionSave.setText(_translate("MainWindow", "Save", None)) self.actionSave_As.setText(_translate("MainWindow", "Save As", None)) self.actionQuit.setText(_translate("MainWindow", "Quit", None)) self.actionOpenProjectDirectory.setText( _translate("MainWindow", "Open Project Directory", None)) self.actionOpenProjectViewerWindow.setText( _translate("MainWindow", "Open Project Viewer Window", None)) self.actionConnectToStream.setText( _translate("MainWindow", "Connect to a Stream", None)) self.actionOpenConsoleOutputWindow.setText( _translate("MainWindow", "Open Console Output Window", None)) self.setUpWizardActionButton.setText( _translate("MainWindow", "Set up Cameras Wizard", None)) #Set the Menu mar to the main menu. #You can put a menu bar on any Qwidget MainWindow.setMenuBar(self.menuBar) #A lot of the following methods are just used to link the menu buttons to. def open_project_directory(self): self.projectViewer.open_project_directory() #self.gridLayout.update() def new_file(self): self.captureArea.newTab() #This code is used to open up a file def open_file(self, MainWindow): self.dlg = QtGui.QFileDialog(MainWindow) self.dlg.setFileMode(QtGui.QFileDialog.AnyFile) self.dlg.setFilter("Text files (*.mp4)") #self.fileName = QtCore.QString() #once you open a file, the file Name is set here #You can use this file name to do a "open(self.fileName, 'r')" This will be used when we open up files self.fileName = QtGui.QFileDialog.getOpenFileName( MainWindow, 'Open File', '/') #siple output the text to console self.consoleOutput.outputText("Opening file") #Here we need to check if it is a valid file. we can set filters in the project viewer class #once we have the motion file we want, pass it to Capture Area to open it in a tab. self.captureArea.openVideoFile(self.fileName) print(str(self.fileName)) #This is used by the Quit button in the menu bar def close_application(self, MainWindow): choice = QtGui.QMessageBox.question( MainWindow, 'Exit?', "Quit the Application?", QtGui.QMessageBox.No | QtGui.QMessageBox.Yes) if choice == QtGui.QMessageBox.Yes: sys.exit() else: pass #This is used by the connect to a stream def connectToStream(self): #This makes a pop up box asking for an IP to connect to self.connectToStreamBox = ConnectToStreamBox(self.captureArea) #ipAddress = self.connectToStreamBox.getIpAddress() #self.captureArea.connectToIP(self.connectToStreamBox) #The following function will deal with opening Docked Windows #If you close out a dock widget, you can get them back with these lines. def openProjectViewerWindow(self): self.projectViewer.open_docker() def openConsoleOutputWindow(self): self.consoleOutput.open_docker() #Doesn't work here, Maybe Fix, maybe now. WOrks in MyWIndow CLass def closeEvent(self, event): result = QtGui.QMessageBox.question( self, "Confirm Exit...", "Are you sure you want to exit ?", QtGui.QMessageBox.Yes | QtGui.QMessageBox.No) event.ignore() if result == QtGui.QMessageBox.Yes: #self.captureArea.stop_playback() event.accept() sys.exit()