def save_structure(structure, list_of_stem_pairs, structure_PDB_ID, list_of_residues): """ Function creates the file with junction 3D model (*.cif format) and returns its name :param structure: the whole PDB structure :param list_of_stem_pairs: list of all pairs that junction consist of :param structure_PDB_ID: PDB ID of whole structure :param list_of_residues: list of residues full IDs that junction consist of :return: name of the created file """ list_of_fragments = list_of_stem_pairs #list_of_fragments = [[item[0], item[1]-1] for item in list_of_fragments] stems_location = '_'.join( str(item) for sublist in list_of_fragments for item in sublist) name_of_file = structure_PDB_ID + '_' + str( len(list_of_stem_pairs)) + 'WJ' + '_' + stems_location + '.cif' if not is_non_zero_file('./output/structures/' + (structure_PDB_ID + ".cif")): io = MMCIFIO() io.set_structure(structure) name_of_file = structure_PDB_ID + '_' + str( len(list_of_stem_pairs)) + 'WJ' + '_' + stems_location + '.cif' if len(name_of_file) > 255: name_of_file = name_of_file[0:251] + '.cif' io.save('./output/structures/' + name_of_file, StructureSelection2(list_of_residues)) return name_of_file
def save(self, fileout): #io = PDBIO() #io.set_structure(self.structure) #io.save(fileout) io = MMCIFIO() io.set_structure(self.structure) io.save(fileout)
def clean_pdb(file_input, file_output, chain_to_keep, parameters): parser = MMCIFParser() structure = parser.get_structure(file_input[:-4].upper(), file_input) structure = remove_chains(structure, chain_to_keep) structure = remove_extra_atoms(structure, parameters) io = MMCIFIO() io.set_structure(structure) io.save(file_output)
def generate_output_file(final_model, out_name): """ This function takes as input both the final model created with the building algorithm and the output filename given by the user (if not defined, is macrocomplex by default). Eventually, it returns the file saved in either ".pdb" or ".mmcif" format. """ out_name = str(out_name.strip()) # If the output file is too big, we save it in ".mmcif" format if len(list(final_model[0].get_atoms())) > 99999 or len( list(final_model[0].get_chains())) > 62: mmcif_IO = MMCIFIO() mmcif_IO.set_structure(final_model[0]) mmcif_IO.save(out_name + ".cif") # Otherwise, save it ".pdb" format else: pdb_IO = PDBIO() pdb_IO.set_structure(final_model[0]) pdb_IO.save(out_name + ".pdb")
def save_structure(structure, structure_PDB_ID): """ Function creates the file with junction 3D model (*.cif format) and returns its name :param structure: the whole PDB structure :param structure_PDB_ID: PDB ID of whole structure :return: name of the created file """ pdbout_data_folder = Path("PDB_files/") if not os.path.exists(pdbout_data_folder): os.makedirs(pdbout_data_folder) name_of_file = structure_PDB_ID + ".cif" io = MMCIFIO() io.set_structure(structure) io.save('./PDB_files/' + name_of_file) return name_of_file
def createPDBFile(self): "Create test CIF file with 12 Atoms in icosahedron vertexes" from Bio.PDB.Structure import Structure from Bio.PDB.Model import Model from Bio.PDB.Chain import Chain from Bio.PDB.Residue import Residue from Bio.PDB.Atom import Atom from Bio.PDB.mmcifio import MMCIFIO import os CIFFILENAME = "/tmp/out.cif" # create atom struct with ico simmety (i222r) icosahedron = Icosahedron(circumscribed_radius=100, orientation='222r') pentomVectorI222r = icosahedron.getVertices() # create biopython object structure = Structure('result') # structure_id model = Model(1, 1) # model_id,serial_num structure.add(model) chain = Chain('A') # chain Id model.add(chain) for i, v in enumerate(pentomVectorI222r, 1): res_id = (' ', i, ' ') # first arg ' ' -> aTOm else heteroatom res_name = "ALA" #+ str(i) # define name of residue res_segid = ' ' residue = Residue(res_id, res_name, res_segid) chain.add(residue) # ATOM name, coord, bfactor, occupancy, altloc, fullname, serial_number, # element=None) atom = Atom('CA', v, 0., 1., " ", " CA ", i, "C") residue.add(atom) io = MMCIFIO() io.set_structure(structure) # delete file if exists if os.path.exists(CIFFILENAME): os.remove(CIFFILENAME) io.save(CIFFILENAME) return CIFFILENAME
from Bio.Alphabet import generic_protein from Bio.PDB import calc_dihedral seqs = [ Seq('HRFKVYNYMSPTFCDHCGSLLWGLVKQGLKCEDCGMNVHHKCREKVANLC', generic_protein) ] s = ds.Distructure('1ptq', seqs) s.generate_primary_contacts() s.run() for r in s.get_residues(): if r.get_resname() != 'GLY': v1 = r['CA'].get_vector() v2 = r['N'].get_vector() v3 = r['C'].get_vector() v4 = r['CB'].get_vector() theta = calc_dihedral(v1, v2, v3, v4) if theta < 0.: print("dihedral error at", r) else: print(r) pass pass # NOTE write result to file from Bio.PDB.mmcifio import MMCIFIO io = MMCIFIO() io.set_structure(s) io.save('chirality_test.cif')
# NOTE read a sequence from Bio.Seq import Seq from Bio.Alphabet import generic_protein seqs = [ Seq('HRFKVYNYMSPTFCDHCGSLLWGLVKQGLKCEDCGMNVHHKCREKVANLC', generic_protein) ] # NOTE read a list of contacts import os distFile = os.path.dirname(__file__) + '/../share/1ptq.dist' contacts = [] with open(distFile, 'r') as f: for line in f: (c1, r1, a1, c2, r2, a2, distance, weight) = line.split() c = (((c1, int(r1), a1), (c2, int(r2), a2)), float(distance), float(weight)) contacts.append(c) # NOTE generate the structure s = ds.Distructure('1ptq', seqs) s.generate_primary_contacts() s.set_tertiary_contacts(contacts) s.run() # NOTE write result to file from Bio.PDB.mmcifio import MMCIFIO io = MMCIFIO() io.set_structure(s) io.save('1ptq_out.cif')
def root_self(rootname: str = '') -> str: """Returns the rootpath for the project if it's unique in the current folder tree.""" root = os.path.abspath( __file__)[:os.path.abspath(__file__).find(rootname) + len(rootname)] sys.path.append(root) load_dotenv(os.path.join(root, '.env')) root_self('ribxz') from ciftools.Neoget import _neoget prs = FastMMCIFParser(QUIET=True) io = MMCIFIO() for pdbid in [ '1vy4', ]: pdbid = pdbid.upper() struct: Structure = prs.get_structure(f'{pdbid}', f'{pdbid}.cif') for chain in struct[0].child_list: strand_id = chain.id nomclass_result = _neoget( f"""match (r:RibosomeStructure{{rcsb_id: "{pdbid.upper()}"}})-[]-(rp:RibosomalProtein)-[]-(n:NomenclatureClass) where rp.entity_poly_strand_id = "{strand_id}" return n.class_id""") print(nomclass_result) if len(nomclass_result) > 0: struct[0][strand_id].id = f"{strand_id}[{nomclass_result[0][0]}]" print("got nomcalss", nomclass_result[0][0])
filesuffix = '.cif' else: print 'ERROR: the input file shall end with either .pdb or .cif' exit(1) chainNames = sys.argv[2].split(',') ResDir = os.getcwd() if len(sys.argv) > 3: ResDir = sys.argv[3] if not os.path.isdir(ResDir): os.mkdir(ResDir) structure = parser.get_structure('test', infile) availableChains = GetValidChains(structure, chainNames) print '#requested chains: ', len(chainNames), ' #available chains: ', len( availableChains) if infile.endswith('.cif'): io = MMCIFIO() else: io = PDBIO() io.set_structure(structure) bname = os.path.basename(infile).split('.')[0] for chainName in availableChains: savefile = bname.upper() + '_' + chainName + filesuffix savefile = os.path.join(ResDir, savefile) io.save(savefile, ChainSelect(chainName))