def read_start(self, filobj): ## parse the mmCIF file self.cif_file = mmCIF.mmCIFFile() self.cif_file.load_file(filobj) ## for a mmCIF file for a structure, assume the first data item ## contains the structure; if there is no data in the mmCIF ## file, halt try: self.cif_data = self.cif_file[0] except IndexError: self.halt = True return self.set_atom_site_data_columns() ## maintain a map of atom_site.id -> atm self.atom_site_id_map = {}
def read_start(self, filobj): ## parse the mmCIF file self.cif_file = mmCIF.mmCIFFile() self.cif_file.load_file(filobj) ## for an mmCIF file for a structure, assume the first data item ## contains the structure; if there is no data in the mmCIF ## file, halt try: self.cif_data = self.cif_file[0] except IndexError: self.halt = True return self.set_atom_site_data_columns() ## maintain a map of atom_site.id -> atm self.atom_site_id_map = {}
def SaveStructure(**args): """Saves a Structure object into a supported file type. file = <file object or path; required> structure = <mmLib.Structure object to save; required> format = <'PDB' or 'CIF'; defaults to 'PDB'> """ fil = get_file_arg(args) if not args.has_key("format"): args["format"] = get_file_extension(fil) else: args["format"] = args["format"].upper() fileobj = open_fileobj(fil, "w") try: struct = args["struct"] except KeyError: try: struct = args["structure"] except KeyError: raise TypeError, "LoadStructure(structure=) argument required" if args["format"] == "PDB": pdb_file = PDBFile() PDBFileBuilder(struct, pdb_file) pdb_file.save_file(fileobj) return elif args["format"] == "CIF": cif_file = mmCIFFile() mmCIFFileBuilder(struct, cif_file) cif_file.save_file(fileobj) return raise FileIOUnsupportedFormat("Unsupported file format %s" % (str(fil)))
def SaveStructure(**args): """Saves a Structure object into a supported file type. file = <file object or path; required> structure = <mmLib.Structure object to save; required> format = <'PDB' or 'CIF'; defaults to 'PDB'> """ fil = get_file_arg(args) if not args.has_key("format"): args["format"] = get_file_extension(fil) else: args["format"] = args["format"].upper() fileobj = open_fileobj(fil, "w") try: struct = args["struct"] except KeyError: try: struct = args["structure"] except KeyError: raise TypeError,"LoadStructure(structure=) argument required" if args["format"] == "PDB": pdb_file = PDBFile() PDBFileBuilder(struct, pdb_file) pdb_file.save_file(fileobj) return elif args["format"] == "CIF": cif_file = mmCIFFile() mmCIFFileBuilder(struct, cif_file) cif_file.save_file(fileobj) return raise FileIOUnsupportedFormat("Unsupported file format %s" % (str(fil)))
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
elif __file__: MMLIB_PATH = os.path.dirname(__file__) DATA_PATH = os.path.join(MMLIB_PATH, "Data") ELEMENT_DATA_PATH = os.path.join(MMLIB_PATH, "Data", "elements.cif") MMLIB_MONOMER_DATA_PATH = os.path.join(MMLIB_PATH, "Data", "monomers.cif") RCSB_MONOMER_DATA_FILE = os.path.join(MMLIB_PATH, "Data", "Monomers.zip") RCSB_MONOMER_DATA_PATH = os.path.join(MMLIB_PATH, "Data", "Monomers") ############################################################################### ## Caches ## ELEMENT_CACHE = {} MONOMER_RES_NAME_CACHE = {} ELEMENT_CIF_FILE = mmCIF.mmCIFFile() ELEMENT_CIF_FILE.load_file(open(ELEMENT_DATA_PATH, "r")) MMLIB_MONOMERS_CIF = mmCIF.mmCIFFile() MMLIB_MONOMERS_CIF.load_file(open(MMLIB_MONOMER_DATA_PATH, "r")) RCSB_USE_ZIP = None RCSB_ZIP = None ############################################################################### ## Constants ## ELEMENT_SYMBOL_DICT = { "H" : True, "h" : True, "He": True, "he": True, "HE": True, "Li": True, "li": True, "LI": True,
elif __file__: MMLIB_PATH = os.path.dirname(__file__) DATA_PATH = os.path.join(MMLIB_PATH, "Data") ELEMENT_DATA_PATH = os.path.join(MMLIB_PATH, "Data", "elements.cif") MMLIB_MONOMER_DATA_PATH = os.path.join(MMLIB_PATH, "Data", "monomers.cif") RCSB_MONOMER_DATA_FILE = os.path.join(MMLIB_PATH, "Data", "Monomers.zip") RCSB_MONOMER_DATA_PATH = os.path.join(MMLIB_PATH, "Data", "Monomers") ############################################################################### ## Caches ## ELEMENT_CACHE = {} MONOMER_RES_NAME_CACHE = {} ELEMENT_CIF_FILE = mmCIF.mmCIFFile() ELEMENT_CIF_FILE.load_file(open(ELEMENT_DATA_PATH, "r")) MMLIB_MONOMERS_CIF = mmCIF.mmCIFFile() MMLIB_MONOMERS_CIF.load_file(open(MMLIB_MONOMER_DATA_PATH, "r")) RCSB_USE_ZIP = None RCSB_ZIP = None ############################################################################### ## Constants ## ELEMENT_SYMBOL_DICT = { "H": True, "h": True, "He": True,