当前位置: 首页>>代码示例>>Python>>正文


Python PDBIO.save方法代码示例

本文整理汇总了Python中Bio.PDB.PDBIO.save方法的典型用法代码示例。如果您正苦于以下问题:Python PDBIO.save方法的具体用法?Python PDBIO.save怎么用?Python PDBIO.save使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Bio.PDB.PDBIO的用法示例。


在下文中一共展示了PDBIO.save方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: RemoveLigandsOneBioUnit

# 需要导入模块: from Bio.PDB import PDBIO [as 别名]
# 或者: from Bio.PDB.PDBIO import save [as 别名]
def RemoveLigandsOneBioUnit(biounit, ligandlist):
    # ligandlist is a residue list with residue chain id, name and residue number
    p = PDBParser(PERMISSIVE = 1)
    pdbname= biounit.split("/")[-1]
    try:
        models = p.get_structure(pdbname, biounit)
    except:
        return None
    #for model in models:
    #    for chain in model:
    #        for residue in chain:
    #            print residue
    for rligand in ligandlist:
        for model in models:
            for chain in model:
                for residue in list(chain):
                    if chain.id == rligand["ChainID"] and int(rligand["ResNum"]) == residue.id[1]:
                        chain.detach_child(residue.id)
                    elif residue.id[0] == "W":
                        chain.detach_child(residue.id)
                    elif len(rligand["LigName"].split()) > 1 and int(rligand["ResNum"]) <= residue.id[1]:
                        LongLigand(chain, residue, rligand)
    io = PDBIO()
    io.set_structure(models)
    filepath = os.path.join(BIOSTRDIR, models.id)
    io.save(filepath)
开发者ID:ajing,项目名称:SIFTS.py,代码行数:28,代码来源:RemoveLigand.py

示例2: test_conversion

# 需要导入模块: from Bio.PDB import PDBIO [as 别名]
# 或者: from Bio.PDB.PDBIO import save [as 别名]
    def test_conversion(self):
        """Parse 1A8O.cif, write 1A8O.pdb, parse again and compare"""

        cif_parser = MMCIFParser(QUIET=1)
        cif_struct = cif_parser.get_structure("example", "PDB/1LCD.cif")

        pdb_writer = PDBIO()
        pdb_writer.set_structure(cif_struct)
        filenumber, filename = tempfile.mkstemp()
        pdb_writer.save(filename)

        pdb_parser = PDBParser(QUIET=1)
        pdb_struct = pdb_parser.get_structure('example_pdb', filename)

        # comparisons
        self.assertEqual(len(pdb_struct), len(cif_struct))

        pdb_atom_names = [a.name for a in pdb_struct.get_atoms()]
        cif_atom_names = [a.name for a in cif_struct.get_atoms()]
        self.assertEqual(len(pdb_atom_names), len(cif_atom_names))
        self.assertSequenceEqual(pdb_atom_names, cif_atom_names)

        pdb_atom_elems = [a.element for a in pdb_struct.get_atoms()]
        cif_atom_elems = [a.element for a in cif_struct.get_atoms()]
        self.assertSequenceEqual(pdb_atom_elems, cif_atom_elems)
开发者ID:anntzer,项目名称:biopython,代码行数:27,代码来源:test_PDB_MMCIFParser.py

示例3: selectChain

# 需要导入模块: from Bio.PDB import PDBIO [as 别名]
# 或者: from Bio.PDB.PDBIO import save [as 别名]
def selectChain(ifn, ofn, chainID='A'):
    parser = PDBParser()
    structure = parser.get_structure('x', ifn)

    class ChainSelector():
        def __init__(self, chainID=chainID):
            self.chainID = chainID

        def accept_chain(self, chain):
            if chain.get_id() == self.chainID:
                return 1
            return 0

        def accept_model(self, model):
            return 1

        def accept_residue(self, residue):
            return 1

        def accept_atom(self, atom):
            return 1

    sel = ChainSelector(chainID)
    io = PDBIO()
    io.set_structure(structure)
    io.save(ofn, sel)
开发者ID:EricTing,项目名称:casf-benchmark,代码行数:28,代码来源:protein.py

示例4: test_pdbio_select

# 需要导入模块: from Bio.PDB import PDBIO [as 别名]
# 或者: from Bio.PDB.PDBIO import save [as 别名]
 def test_pdbio_select(self):
     """Write a selection of the structure using a Select subclass"""
     
     # Selection class to filter all alpha carbons
     class CAonly(Select):
         """
         Accepts only CA residues
         """
         def accept_atom(self, atom):
             if atom.name == "CA" and atom.element == "C":
                 return 1
             
     io = PDBIO()
     struct1 = self.structure
     # Write to temp file
     io.set_structure(struct1)
     filenumber, filename = tempfile.mkstemp()
     os.close(filenumber)
     try:
         io.save(filename, CAonly())
         struct2 = self.parser.get_structure("1a8o", filename)
         nresidues = len(list(struct2.get_residues()))
         self.assertEqual(nresidues, 70)
     finally:
         os.remove(filename)
开发者ID:HausMa,项目名称:biopython,代码行数:27,代码来源:test_PDB.py

示例5: get

# 需要导入模块: from Bio.PDB import PDBIO [as 别名]
# 或者: from Bio.PDB.PDBIO import save [as 别名]
    def get(self, request, *args, **kwargs):

        if self.kwargs['substructure'] == 'select':
            return HttpResponseRedirect('/structure/pdb_segment_selection')

        if self.kwargs['substructure'] == 'full':
            out_stream = request.session['cleaned_structures']

        elif self.kwargs['substructure'] == 'custom':
            simple_selection = request.session.get('selection', False)
            selection = Selection()
            if simple_selection:
                selection.importer(simple_selection)
            io = PDBIO()
            zipf_in = zipfile.ZipFile(request.session['cleaned_structures'], 'r')
            out_stream = BytesIO()
            zipf_out = zipfile.ZipFile(out_stream, 'w', zipfile.ZIP_DEFLATED)
            for name in zipf_in.namelist():
                tmp = StringIO()
                io.set_structure(PDBParser(QUIET=True).get_structure(name, StringIO(zipf_in.read(name).decode('utf-8')))[0])
                io.save(tmp, SubstructureSelector(request.session['substructure_mapping'], parsed_selection=SelectionParser(selection)))
                zipf_out.writestr(name, tmp.getvalue())

            zipf_in.close()
            zipf_out.close()
            del request.session['substructure_mapping']
        if len(out_stream.getvalue()) > 0:
            response = HttpResponse(content_type="application/zip")
            response['Content-Disposition'] = 'attachment; filename="pdb_structures.zip"'
            response.write(out_stream.getvalue())

        return response
开发者ID:akumar03,项目名称:protwis,代码行数:34,代码来源:views.py

示例6: deleteChain

# 需要导入模块: from Bio.PDB import PDBIO [as 别名]
# 或者: from Bio.PDB.PDBIO import save [as 别名]
def deleteChain():# Delete a complete chain from a pdb and save the new structure in pdbname_free.pdb
	parser = PDBParser()
	nameStruct=pdb_name.partition('.')[0]
	structure = parser.get_structure(nameStruct, pdb_name)
	header = parser.get_header()
	trailer = parser.get_trailer()
	seq=''
	
	nb_chain=input('How many chain do you want to delete : ')
	for i in range(nb_chain):
		rm_chain=raw_input('What chain you want to delete : ')
		for model in structure:
			for chain in model:
				if(chain.id==rm_chain):
					model.detach_child(chain.id)
	pept = raw_input('Do you want to get a pdb with the sequence in its name : ')
	if(pept == 'y'):
		ppb=PPBuilder()
		for pp in ppb.build_peptides(structure):
			seq = seq + pp.get_sequence()
		seq=seq.lower()
		seq=str(seq)
		w = PDBIO()
		w.set_structure(structure)
		w.save(seq+'_bound.pdb')
	else:
		w = PDBIO()
		w.set_structure(structure)
		w.save(nameStruct+'_without'+rm_chain+'.pdb')
开发者ID:rmarabini,项目名称:LAdV23,代码行数:31,代码来源:editPDB.py

示例7: execute_freesasa

# 需要导入模块: from Bio.PDB import PDBIO [as 别名]
# 或者: from Bio.PDB.PDBIO import save [as 别名]
def execute_freesasa(structure, selection=None):
    """
    Runs the freesasa executable on a PDB file.

    You can get the executable from:
        https://github.com/mittinatten/freesasa

    The binding affinity models are calibrated with the parameter
    set for vdW radii used in NACCESS:
        http://www.ncbi.nlm.nih.gov/pubmed/994183
    """
    io = PDBIO()

    freesasa, param_f= FREESASA_BIN, FREESASA_PAR
    if not os.path.isfile(freesasa):
        raise IOError('[!] freesasa binary not found at `{0}`'.format(freesasa))
    if not os.path.isfile(param_f):
        raise IOError('[!] Atomic radii file not found at `{0}`'.format(param_f))

    # Rewrite PDB using Biopython to have a proper format
    # freesasa is very picky with line width (80 characters or fails!)
    # Select chains if necessary
    class ChainSelector(Select):
        """Selector class to filter for specific chains"""
        def accept_chain(self, chain):
            """Returns True for chains within the selection"""
            if selection and chain.id in selection:
                return 1
            elif not selection:
                return 1
            else:
                return 0

    _pdbf = tempfile.NamedTemporaryFile()
    io.set_structure(structure)
    io.save(_pdbf.name, ChainSelector())

    # Run freesasa
    # Save atomic asa output to another temp file
    _outf = tempfile.NamedTemporaryFile()
    cmd = '{0} --B-value-file={1} -c {2} {3}'.format(freesasa, _outf.name, param_f, _pdbf.name)
    p = subprocess.Popen(cmd, shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
    stdout, stderr = p.communicate()

    if p.returncode:
        print('[!] freesasa did not run successfully', file=sys.stderr)
        print(cmd, file=sys.stderr)
        raise Exception(stderr)

    # Rewind & Parse results file
    # Save
    _outf.seek(0)
    asa, rsa = parse_freesasa_output(_outf)

    _pdbf.close()
    _outf.close()

    return asa, rsa
开发者ID:JoaoRodrigues,项目名称:binding_affinity,代码行数:60,代码来源:freesasa.py

示例8: pushToPDB

# 需要导入模块: from Bio.PDB import PDBIO [as 别名]
# 或者: from Bio.PDB.PDBIO import save [as 别名]
	def pushToPDB(self, path, *keys):
		seq_list = [self.getRegion(key) for key in keys]
		if not all(seq_list):
			self.printerr('pushToPDB: RESIDUE LIST IS EMPTY\n')
			return 0

		io = PDBIO()
		io.set_structure(self.__struct)
		io.save(path + '/' +self.__name + ".pdb", self._ResSelect(*seq_list))
		return 1
开发者ID:antigenomics,项目名称:vdjstruct,代码行数:12,代码来源:pdbmod.py

示例9: save_structure

# 需要导入模块: from Bio.PDB import PDBIO [as 别名]
# 或者: from Bio.PDB.PDBIO import save [as 别名]
    def save_structure(self, filename="barnacle.pdb"):
        """
        Save the atomic coordinates of the sampled structure as a PDB file.

        @param filename: The filename of the PDB file to save.
        @type filename: string
        """
        pdbio = PDBIO()
        pdbio.set_structure(self.structure)
        pdbio.save(filename)
开发者ID:mchelem,项目名称:biopython,代码行数:12,代码来源:Barnacle.py

示例10: clean_pdb

# 需要导入模块: from Bio.PDB import PDBIO [as 别名]
# 或者: from Bio.PDB.PDBIO import save [as 别名]
def clean_pdb(pdb_file, pdb_chain, out_dir):

    out_dir_chain = out_dir + '/' + 'chain'

    if not os.path.isfile(pdb_file):
        raise argparse.ArgumentTypeError("PDB file could not be found.")

    # Create output directories if they do not already exist
    if not os.path.exists(out_dir):
        os.makedirs(out_dir)
    if not os.path.exists(out_dir_chain):
        os.makedirs(out_dir_chain)

    # Grab PDB name and make sure it's converted to uppercase
    pdb_name = os.path.basename(pdb_file).split('.')[0].upper()

    # Extract chain of interest
    structure = parsePDBStructure(pdb_file)
    # Make sure chain exists, otherwise throw an error
    try:
        chain = structure[0][pdb_chain]
    except KeyError:
        print("\nERROR:\n\n\t"+pdb_name+": chain "+pdb_chain+" could not be found.\n")
        return

    io = PDBIO()
    chain_select = ChainSelect(pdb_chain)
    io.set_structure(structure)
    pdb_chain_file = out_dir_chain+'/'+pdb_name+'_'+pdb_chain+'_temp.pdb'
    io.save(pdb_chain_file, chain_select)

    # Remove HetAtoms
    temp_file = out_dir + "/" + pdb_name + "_temp.pdb"
    removeHetAtoms(pdb_file, temp_file)

    temp_file_chain = out_dir_chain + "/" + pdb_name + '_' + pdb_chain + "_temp2.pdb"
    removeHetAtoms(pdb_chain_file, temp_file_chain)

    # Renumber PDB
    structure = parsePDBStructure(temp_file)
    (new_pdb, renumbered_pdb) = renumberResidues(structure, pdb_name)

    structure_chain = parsePDBStructure(temp_file_chain)
    (new_pdb_chain, renumbered_pdb) = renumberResidues(structure_chain, pdb_name + '_' + pdb_chain)

    # Remove waters
    removeWaters(new_pdb, out_dir + "/" + pdb_name + ".pdb")
    removeWaters(new_pdb_chain, out_dir_chain+'/'+pdb_name+'_'+pdb_chain+'.pdb')

    # Clean up temporary files
    os.remove(pdb_chain_file)
    os.remove(temp_file)
    os.remove(temp_file_chain)
    os.remove(new_pdb_chain)
    os.remove(new_pdb)
开发者ID:benjaminjack,项目名称:enzyme_distance,代码行数:57,代码来源:clean_pdb.py

示例11: save_superimposed_pdb

# 需要导入模块: from Bio.PDB import PDBIO [as 别名]
# 或者: from Bio.PDB.PDBIO import save [as 别名]
    def save_superimposed_pdb(self, out_filename):
        """
        Saves the superimposed PDB in the given output filename.
        """
        if self.__valid_alignment():
            superimposed_pdb = self.__create_superimposed_pdb()

            # save it to a file
            io = PDBIO()
            io.set_structure(superimposed_pdb)
            io.save(out_filename)
开发者ID:alvaroabascar,项目名称:overlapy,代码行数:13,代码来源:superimposer.py

示例12: post

# 需要导入模块: from Bio.PDB import PDBIO [as 别名]
# 或者: from Bio.PDB.PDBIO import save [as 别名]
    def post(self, request):

        root, ext = os.path.splitext(request.FILES['pdb_file'].name)
        generic_numbering = GenericNumbering(StringIO(request.FILES['pdb_file'].file.read().decode('UTF-8',"ignore")))
        out_struct = generic_numbering.assign_generic_numbers()
        out_stream = StringIO()
        io = PDBIO()
        io.set_structure(out_struct)
        io.save(out_stream)
        print(len(out_stream.getvalue()))
        # filename="{}_GPCRdb.pdb".format(root)
        return Response(out_stream.getvalue())
开发者ID:protwis,项目名称:protwis,代码行数:14,代码来源:views.py

示例13: removeDoubleAtoms

# 需要导入模块: from Bio.PDB import PDBIO [as 别名]
# 或者: from Bio.PDB.PDBIO import save [as 别名]
def removeDoubleAtoms():# Remove all double atoms defined in a pdb and save the new structure in pdbname_noDouble.pdb
	parser = PDBParser()
	nameStruct=pdb_name.partition('.')[0]
	structure = parser.get_structure(nameStruct, pdb_name)
	header = parser.get_header()
	trailer = parser.get_trailer()
	
	structure.remove_disordered_atoms()

	w = PDBIO()
	w.set_structure(structure)
	w.save(nameStruct+'_noDouble.pdb')
开发者ID:rmarabini,项目名称:LAdV23,代码行数:14,代码来源:editPDB.py

示例14: post

# 需要导入模块: from Bio.PDB import PDBIO [as 别名]
# 或者: from Bio.PDB.PDBIO import save [as 别名]
    def post (self, request, *args, **kwargs):
        
        frag_sp = FragmentSuperpose(StringIO(request.FILES['pdb_file'].file.read().decode('UTF-8', 'ignore')),request.FILES['pdb_file'].name)
        superposed_fragments = []
        superposed_fragments_repr = []
        if request.POST['similarity'] == 'identical':
            if request.POST['representative'] == 'any':
                superposed_fragments = frag_sp.superpose_fragments()
            else:
                superposed_fragments_repr = frag_sp.superpose_fragments(representative=True, state=request.POST['state'])
                superposed_fragments = frag_sp.superpose_fragments()
        else:
            if request.POST['representative'] == 'any':
                superposed_fragments = frag_sp.superpose_fragments(use_similar=True)
            else:
                superposed_fragments_repr = frag_sp.superpose_fragments(representative=True, use_similar=True, state=request.POST['state'])
                superposed_fragments = frag_sp.superpose_fragments(use_similar=True)
        if superposed_fragments == []:
            self.message = "No fragments were aligned."
        else:
            io = PDBIO()
            out_stream = BytesIO()
            zipf = zipfile.ZipFile(out_stream, 'a')
            for fragment, pdb_data in superposed_fragments:
                io.set_structure(pdb_data)
                tmp = StringIO()
                io.save(tmp)
                if request.POST['representative'] == 'any':
                    zipf.writestr(fragment.generate_filename(), tmp.getvalue())
                else:
                    zipf.writestr("all_fragments//{!s}".format(fragment.generate_filename()), tmp.getvalue())
            if superposed_fragments_repr != []:
                for fragment, pdb_data in superposed_fragments_repr:
                    io.set_structure(pdb_data)
                    tmp = StringIO()
                    io.save(tmp)
                    zipf.writestr("representative_fragments//{!s}".format(fragment.generate_filename()), tmp.getvalue())
            zipf.close()
            if len(out_stream.getvalue()) > 0:
                request.session['outfile'] = { 'interacting_moiety_residue_fragments.zip' : out_stream, }
                self.outfile = 'interacting_moiety_residue_fragments.zip'
                self.success = True
                self.zip = 'zip'
                self.message = '{:n} fragments were superposed.'.format(len(superposed_fragments))

        context = super(FragmentSuperpositionResults, self).get_context_data(**kwargs)
        attributes = inspect.getmembers(self, lambda a:not(inspect.isroutine(a)))
        for a in attributes:
            if not(a[0].startswith('__') and a[0].endswith('__')):
                context[a[0]] = a[1]

        return render(request, self.template_name, context)
开发者ID:akumar03,项目名称:protwis,代码行数:54,代码来源:views.py

示例15: save_ligand

# 需要导入模块: from Bio.PDB import PDBIO [as 别名]
# 或者: from Bio.PDB.PDBIO import save [as 别名]
def save_ligand(structure, filename):
    # Saves ligand to a filename.pdb
    Select = Bio.PDB.Select
    class LigandSelect(Select):
        def accept_residue(self, residue):
            for group in ligands.values():
                if residue in group:
                    return 1
                else:
                    return 0
    io=PDBIO()
    io.set_structure(structure)
    io.save(filename+'.pdb', LigandSelect())
开发者ID:agpe,项目名称:biopython-ligands,代码行数:15,代码来源:active_site.py


注:本文中的Bio.PDB.PDBIO.save方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。