def test_extra_fields(): path = join(data_dir("structure"), "1l2y.cif") pdbx_file = pdbx.PDBxFile.read(path) stack1 = pdbx.get_structure( pdbx_file, extra_fields=["atom_id", "b_factor", "occupancy", "charge"]) pdbx_file = pdbx.PDBxFile() pdbx.set_structure(pdbx_file, stack1, data_block="test") stack2 = pdbx.get_structure( pdbx_file, extra_fields=["atom_id", "b_factor", "occupancy", "charge"]) assert stack1 == stack2 path = join(data_dir("structure"), "1l2y.cif") pdbx_file = pdbx.PDBxFile.read(path) stack1 = pdbx.get_structure( pdbx_file, extra_fields=["atom_id", "b_factor", "occupancy", "charge"]) pdbx_file = pdbx.PDBxFile() pdbx.set_structure(pdbx_file, stack1, data_block="test") stack2 = pdbx.get_structure( pdbx_file, extra_fields=["atom_id", "b_factor", "occupancy", "charge"]) assert stack1.ins_code.tolist() == stack2.ins_code.tolist() assert stack1.atom_id.tolist() == stack2.atom_id.tolist() assert stack1.b_factor.tolist() == approx(stack2.b_factor.tolist()) assert stack1.occupancy.tolist() == approx(stack2.occupancy.tolist()) assert stack1.charge.tolist() == stack2.charge.tolist() assert stack1 == stack2
def test_conversion(path, model): pdbx_file = pdbx.PDBxFile.read(path) try: array1 = pdbx.get_structure(pdbx_file, model=model) except biotite.InvalidFileError: if model is None: # The file cannot be parsed into an AtomArrayStack, # as the models contain different numbers of atoms # -> skip this test case return else: raise pdbx_file = pdbx.PDBxFile() pdbx.set_structure(pdbx_file, array1, data_block="test") # Remove one optional auth section in label to test fallback to label fields atom_cat = pdbx_file.get_category("atom_site", "test") atom_cat.pop("auth_atom_id") pdbx_file.set_category("atom_site", atom_cat, "test") array2 = pdbx.get_structure(pdbx_file, model=model) assert array1.array_length() > 0 if array1.box is not None: assert np.allclose(array1.box, array2.box) assert array1.bonds == array2.bonds for category in array1.get_annotation_categories(): assert (array1.get_annotation(category).tolist() == array2.get_annotation(category).tolist()) assert array1.coord.tolist() == array2.coord.tolist()
def test_conversion(path, model): pdbx_file = pdbx.PDBxFile.read(path) try: array1 = pdbx.get_structure(pdbx_file, model=model) except biotite.InvalidFileError: if model is None: # The file cannot be parsed into an AtomArrayStack, # as the models contain different numbers of atoms # -> skip this test case return else: raise pdbx_file = pdbx.PDBxFile() pdbx.set_structure(pdbx_file, array1, data_block="test") array2 = pdbx.get_structure(pdbx_file, model=model) if array1.box is not None: assert np.allclose(array1.box, array2.box) assert array1.bonds == array2.bonds for category in array1.get_annotation_categories(): assert array1.get_annotation(category).tolist() == \ array2.get_annotation(category).tolist() assert array1.coord.tolist() == array2.coord.tolist()
def test_extra_fields(): path = join(data_dir, "1l2y.cif") pdbx_file = pdbx.PDBxFile() pdbx_file.read(path) stack1 = pdbx.get_structure(pdbx_file, extra_fields=["atom_id","b_factor", "occupancy","charge"]) pdbx_file = pdbx.PDBxFile() pdbx.set_structure(pdbx_file, stack1, data_block="test") stack2 = pdbx.get_structure(pdbx_file, extra_fields=["atom_id","b_factor", "occupancy","charge"]) assert stack1 == stack2
def test_conversion(path, single_model): model = 1 if single_model else None pdbx_file = pdbx.PDBxFile() pdbx_file.read(path) array1 = pdbx.get_structure(pdbx_file, model=model) pdbx_file = pdbx.PDBxFile() pdbx.set_structure(pdbx_file, array1, data_block="test") array2 = pdbx.get_structure(pdbx_file, model=model) for category in array1.get_annotation_categories(): assert array1.get_annotation(category).tolist() == \ array2.get_annotation(category).tolist() assert array1.coord.tolist() == array2.coord.tolist()
ku_file = biotite.temp_file("ku.cif") # Download and parse structure files file = rcsb.fetch("1JEY", "mmtf", biotite.temp_dir()) ku_dna = strucio.load_structure(file) file = rcsb.fetch("1JEQ", "mmtf", biotite.temp_dir()) ku = strucio.load_structure(file) # Remove DNA and water ku_dna = ku_dna[(ku_dna.chain_id == "A") | (ku_dna.chain_id == "B")] ku_dna = ku_dna[~struc.filter_solvent(ku_dna)] ku = ku[~struc.filter_solvent(ku)] # The structures have a differing amount of atoms missing # at the the start and end of the structure # -> Find common structure ku_dna_common = ku_dna[struc.filter_intersection(ku_dna, ku)] ku_common = ku[struc.filter_intersection(ku, ku_dna)] # Superimpose ku_superimposed, transformation = struc.superimpose( ku_dna_common, ku_common, (ku_common.atom_name == "CA")) # We do not want the cropped structures # -> apply superimposition on structures before intersection filtering ku_superimposed = struc.superimpose_apply(ku, transformation) # Write PDBx files as input for PyMOL cif_file = pdbx.PDBxFile() pdbx.set_structure(cif_file, ku_dna, data_block="ku_dna") cif_file.write(ku_dna_file) cif_file = pdbx.PDBxFile() pdbx.set_structure(cif_file, ku_superimposed, data_block="ku") cif_file.write(ku_file) # Visualization with PyMOL... # biotite_static_image = ku_superimposition.png
chain_combinations = list(combinations(chain_list, 2)) query = 'UPDATE cif SET chain_count = ?, combination_count = ? WHERE pdb_id = ?', ( len(chain_list), len(chain_combinations), pdb_id) sql_queries.append(query) for comb in chain_combinations: dimer = model[np.logical_or(model.chain_id == comb[0], model.chain_id == comb[1])] sasa_result = pifaceFunctions.sasa(dimer, comb[0], comb[1]) if sasa_result[0] + sasa_result[1] - sasa_result[2] > args.sasa: pdbxFile = PDBxFile() set_structure(pdbxFile, dimer, data_block=pdb_id + '_' + comb[0] + '_' + comb[1]) pdbxFile.write("%s_%s_%s.cif" % (pdb_id, comb[0], comb[1])) dimer_id = pdb_id + '_' + comb[0] + '_' + comb[1] query = 'INSERT INTO dimers (dimer_id, pdb_id, chain_1, chain_2, chain_1_sasa, chain_2_sasa, dimer_sasa, sasa_diff, insert_time) VALUES(?,?,?,?,?,?,?,?,?)', ( dimer_id, pdb_id, comb[0], comb[1], float(sasa_result[0]), float(sasa_result[1]), float(sasa_result[2]), float(sasa_result[0] + sasa_result[1] - sasa_result[2]), datetime.strftime(datetime.now(), "%Y-%m-%d %H:%M:%S")) sql_queries.append(query) with open("%s_%s_%s.cif" % (pdb_id, comb[0], comb[1]),
file["audit_author"] = { "name": ["Doe, Jane", "Doe, John"], "pdbx_ordinal": ["1", "2"] } ######################################################################## # In most applications only the structure itself # (stored in the *atom_site* category) is relevant. # :func:`get_structure()` and :func:`set_structure()` are convenience # functions that are used to convert the # *atom_site* category into an atom array (stack) and vice versa. tc5b = pdbx.get_structure(file) # Do some fancy stuff pdbx.set_structure(file, tc5b) ######################################################################## # :func:`get_structure()` creates automatically an # :class:`AtomArrayStack`, even if the file actually contains only a # single model. # If you would like to have an :class:`AtomArray` instead, you have to # specifiy the :obj:`model` parameter. # # .. currentmodule:: biotite.structure.io.mmtf # # If you want to parse a large batch of structure files or you have to # load very large structure files, the usage of PDB or mmCIF files might # be too slow for your requirements. In this case you probably might # want to use MMTF files. # MMTF files describe structures just like PDB and mmCIF files,
cif_file["audit_author"] = { "name": ["Doe, Jane", "Doe, John"], "pdbx_ordinal": ["1", "2"] } ######################################################################## # In most applications only the structure itself # (stored in the *atom_site* category) is relevant. # :func:`get_structure()` and :func:`set_structure()` are convenience # functions that are used to convert the # ``atom_site`` category into an atom array (stack) and vice versa. tc5b = pdbx.get_structure(cif_file) # Do some fancy stuff pdbx.set_structure(cif_file, tc5b) ######################################################################## # :func:`get_structure()` creates automatically an # :class:`AtomArrayStack`, even if the file actually contains only a # single model. # If you would like to have an :class:`AtomArray` instead, you have to # specifiy the :obj:`model` parameter. # # .. currentmodule:: biotite.structure.io.mmtf # # If you want to parse a large batch of structure files or you have to # load very large structure files, the usage of PDB or mmCIF files might # be too slow for your requirements. # In this case you probably might want to use MMTF files. # MMTF files describe structures just like PDB and mmCIF files,