本文整理汇总了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)
示例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)
示例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)
示例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)
示例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
示例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')
示例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
示例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
示例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)
示例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)
示例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)
示例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())
示例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')
示例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)
示例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())