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


Python NeighborSearch.search方法代码示例

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


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

示例1: check_clash

# 需要导入模块: from Bio.PDB import NeighborSearch [as 别名]
# 或者: from Bio.PDB.NeighborSearch import search [as 别名]
def check_clash(str_name, v=True):
        """check_clash, fract of clashes!

        if zero contacts then error -> fix ->

        Problem, contacts, str_name: 311 505 na-prot_13536.pdb
        Sterical clashes  0.615841584158

        c is counter
        """
        print(str_name)
        structure = open(str_name)
        #model = structure[0]
        atoms_A = []
        atoms_B = []
        for line in structure.readlines():
            if line[:4] == "ATOM":
                #print line
                at_nam = line[12:16].strip()
                coor = [float(line[30:38]),float(line[38:46]), float(line[46:54])]	
                at = Atom.Atom(at_nam,coor,0.0,1.0,' ',at_nam,1,at_nam[0])
                if line[21] == "A":
                    atoms_A.append(at)
                elif line[21] == "B":
                    atoms_B.append(at)
                else: pass
        #atoms_B = Selection.unfold_entities(structure[0]['B'], 'A')
        #print len(atoms_A), len(atoms_B)
        if len(atoms_A) > len(atoms_B):
            less = atoms_B
            more = atoms_A
        else: 
            less = atoms_A
            more = atoms_B
        problem = 0
        contacts = 0 
        ns=NeighborSearch(more)
        for at in less:
             neighbors=ns.search(array(at.get_coord()),2.0,'A')
             if neighbors != []:
                 problem +=1
                 contacts +=1
             else:
                 neighbors1=ns.search(array(at.get_coord()),4.0,'A')
                 if neighbors1 != []:
                     contacts +=1
        if v:
                print('problem:', float(problem))
                print('contacts:', float(contacts))
        try:
            fract = float(problem)/float(contacts)
        except ZeroDivisionError:
            fract = problem # or skip this structure
            print('ZeroDivison -- skip:', problem, contacts, str_name)
            return fract

        #print 'Contacts, str_name:', problem, contacts, str_name, "Sterical clashes ", fract
        return fract
开发者ID:mmagnus,项目名称:rna-pdb-tools,代码行数:60,代码来源:ClashCalc.py

示例2: extract_feature

# 需要导入模块: from Bio.PDB import NeighborSearch [as 别名]
# 或者: from Bio.PDB.NeighborSearch import search [as 别名]
 def extract_feature(self):
     seed(self.seed)
     counter = 0
     print_info_nn(" >>> Adding D2 category based shape distribution for database {0} ... ".format(self._database.name))
     overall_time = datetime.now()
     if not os.path.exists(self._get_dir_name()):
         os.makedirs(self._get_dir_name())
     for complex_name in self._database.complexes.keys():
         protein_complex = self._database.complexes[complex_name]
         proteins = [protein_complex.unbound_formation.ligand, protein_complex.unbound_formation.receptor]
         for protein in proteins:
             shape_dist_file = self._get_dir_name() + protein.name
             if not os.path.exists(shape_dist_file + ".npy"):
                 counter += 1
                 if counter <= 15:
                     print_info_nn("{0}, ".format(protein.name))
                 else:
                     counter = 0
                     print_info("{0}".format(protein.name))
                 atoms = protein.atoms
                 neighbour_search = NeighborSearch(atoms)
                 distributions = np.zeros((len(protein.residues), self.number_of_bins))
                 for i in range(len(protein.residues)):
                     residue = protein.residues[i]
                     nearby_residues = neighbour_search.search(residue.center, self.radius, "R")
                     distributions[i, :] = self._compute_distribution(nearby_residues)
                 np.save(shape_dist_file, distributions)
             distributions = np.load(shape_dist_file + ".npy")
             for i in range(len(protein.residues)):
                 protein.residues[i].add_feature(Features.D2_CATEGORY_SHAPE_DISTRIBUTION, distributions[i, :])
     print_info("took {0} seconds.".format((datetime.now() - overall_time).seconds))
开发者ID:sluggishcrow,项目名称:PAIRpred,代码行数:33,代码来源:d2_category_shape_distribution.py

示例3: get_residues_distance_distribution

# 需要导入模块: from Bio.PDB import NeighborSearch [as 别名]
# 或者: from Bio.PDB.NeighborSearch import search [as 别名]
def get_residues_distance_distribution(data, r):
    """
    This function computes the distribution of number of residues in certain radius around residues.

    """
    files = glob.glob(data + "*_b.pdb")
    dist = {}
    files.sort()
    file_counter = 0
    for bound_pbd in files:
        dist[bound_pbd] = []
    l = []
    for bound_pbd in files:
        file_counter += 1
        print "Protein " + str(file_counter) + "/" + str(len(files))
        s, a, r = read_pdb_file(bound_pbd)
        ns = NeighborSearch(a)
        res_counter = 0
        for res in r:
            b = 0 * res.child_list[0].get_coord()
            for atom in res.child_list:
                b += atom.get_coord()
            center = b / len(res.child_list)
            l.append(len(ns.search(center, 100, "R")))
            res_counter += 1
            # print "Residue " + str(res_counter) + "out of " + str(len(r))
    plot(np.bincount(l))
    show()
    print files
开发者ID:sluggishcrow,项目名称:PAIRpred,代码行数:31,代码来源:residue_dist.py

示例4: get_interactions_between_chains

# 需要导入模块: from Bio.PDB import NeighborSearch [as 别名]
# 或者: from Bio.PDB.NeighborSearch import search [as 别名]
def get_interactions_between_chains(model, chain_id_1, chain_id_2, r_cutoff=6):
    """Calculate interactions between the residues of the two chains.

    An interaction is defines as a pair of residues where at least one pair of atom
    is closer than r_cutoff.

    .. deprecated:: 1.0
        Use python:fn:`get_interacting_residues` instead.
        It gives you both the residue index and the resnum.

    Returns
    -------
    OrderedDict
        Keys are (residue_number, residue_amino_acid) tuples
        (e.g. ('0', 'M'), ('1', 'Q'), ...).
        Values are lists of (residue_number, residue_amino_acid) tuples.
        (e.g. [('0', 'M'), ('1', 'Q'), ...]).
    """
    try:
        from Bio.PDB import NeighborSearch
    except ImportError as e:
        logger.warning('Importing Biopython NeighborSearch returned an error: {}'.format(e))
        logger.warning('Using the the slow version of the neighbour-finding algorithm...')
        return get_interactions_between_chains_slow(model, chain_id_1, chain_id_2, r_cutoff)

    # Extract the chains of interest from the model
    chain_1 = None
    chain_2 = None
    for child in model.get_list():
        if child.id == chain_id_1:
            chain_1 = child
        if child.id == chain_id_2:
            chain_2 = child
    if chain_1 is None or chain_2 is None:
        raise Exception('Chains %s and %s were not found in the model' % (chain_id_1, chain_id_2))

    ns = NeighborSearch(list(chain_2.get_atoms()))
    interactions_between_chains = OrderedDict()
    for idx, residue_1 in enumerate(chain_1):
        if residue_1.resname in AMINO_ACIDS and residue_1.id[0] == ' ':
            resnum_1 = str(residue_1.id[1]) + residue_1.id[2].strip()
            resaa_1 = convert_aa(residue_1.get_resname(), quiet=True)
            interacting_residues = set()
            for atom_1 in residue_1:
                interacting_residues.update(ns.search(atom_1.get_coord(), r_cutoff, 'R'))
            interacting_resids = []
            for residue_2 in interacting_residues:
                resnum_2 = str(residue_2.id[1]) + residue_2.id[2].strip()
                resaa_2 = convert_aa(residue_2.get_resname(), quiet=True)
                if residue_2.resname in AMINO_ACIDS and residue_2.id[0] == ' ':
                    interacting_resids.append((resnum_2, resaa_2,))
            if interacting_resids:
                interacting_resids.sort(
                    key=lambda x: int(''.join([c for c in x[0] if c.isdigit()])))
                interactions_between_chains[(resnum_1, resaa_1)] = interacting_resids
    return interactions_between_chains
开发者ID:kimlaborg,项目名称:kmtools,代码行数:58,代码来源:structure_parser_legacy.py

示例5: interaction

# 需要导入模块: from Bio.PDB import NeighborSearch [as 别名]
# 或者: from Bio.PDB.NeighborSearch import search [as 别名]
 def interaction(self, pdb_id, filename, domain_1, domain_2):
     """Returns a dict with informations (atoms, residues...) if two domains
     interact with each other, and returns False if not."""
     print "Searching for interactions in "+pdb_id+"..."
     # creates a strucuture object/class to extract atoms of the two domains
     model = structure(pdb_id).get_model(pdb_id, filename)
     residues_1 = structure(pdb_id).get_residues(model, domain_1)
     residues_2 = structure(pdb_id).get_residues(model, domain_2)
     atoms_1 = Selection.unfold_entities(residues_1, 'A')
     atoms_2 = Selection.unfold_entities(residues_2, 'A')
     # gets the serial numbers of the atoms
     numbers_1 = structure(pdb_id).serial_numbers(atoms_1)
     numbers_2 = structure(pdb_id).serial_numbers(atoms_2)
     # the search starts here !
     atoms = Selection.unfold_entities(model, 'A')
     nsearch = NeighborSearch(atoms)
     interacting_atoms_1 = []
     interacting_atoms_2 = []
     for atom in atoms:
         if atom.get_serial_number() in numbers_1:
             point = atom.get_coord()
             # This is how we detect an interaction, we put 5 angstroms
             # here.
             # This is the simplest method we can use, and we're not sure
             # that it is correct.
             # Originally we have planned to go further by doing a surface
             # and accesssion analysis, but we had no time.
             # We hope we can talk about that during the talk.
             neighbors = nsearch.search(point, 5)
             for neighbor in neighbors:
                 if neighbor.get_serial_number() in numbers_2:
                     interacting_atoms_2.append(neighbor)
                     if atom not in interacting_atoms_1:
                         interacting_atoms_1.append(atom)
     # returns a dict with all residues and atoms
     if len(interacting_atoms_2) > 0:
         infos = {}
         infos['1'] = {}
         infos['2'] = {}
         # just get the parent residues for the list of atoms
         interacting_residues_1 = structure(pdb_id).atoms2residues(
                 interacting_atoms_1)
         interacting_residues_2 = structure(pdb_id).atoms2residues(
                 interacting_atoms_2)
         infos['1']['atoms'] = interacting_atoms_1
         infos['2']['atoms'] = interacting_atoms_2
         infos['1']['residues'] = interacting_residues_1
         infos['2']['residues'] = interacting_residues_2
         return infos
     else: return False
开发者ID:hibarikyouya,项目名称:itpp,代码行数:52,代码来源:interaction.py

示例6: _remove_distant_hatatms

# 需要导入模块: from Bio.PDB import NeighborSearch [as 别名]
# 或者: from Bio.PDB.NeighborSearch import search [as 别名]
 def _remove_distant_hatatms(self, new_model, hetatm_chain):
     """Detach hetatms that are more than ``self.r_cutoff`` away from the main chain(s)."""
     ns = NeighborSearch(list(new_model.get_atoms()))
     hetatm_chain.id = [
         c for c in reversed(string.ascii_uppercase) if c not in self.chain_ids][0]
     res_idx = 0
     while res_idx < len(hetatm_chain):
         res_1 = hetatm_chain.child_list[res_idx]
         in_contact = False
         for atom_1 in res_1:
             interacting_residues = ns.search(atom_1.get_coord(), self.r_cutoff, 'R')
             if interacting_residues:
                 # logger.debug(res_1.id)
                 # logger.debug(interacting_residues)
                 in_contact = True
         if in_contact:
             res_idx += 1
             continue
         # logger.debug('Detaching child: {}'.format(res_1.id))
         hetatm_chain.detach_child(res_1.id)
开发者ID:kimlaborg,项目名称:kmtools,代码行数:22,代码来源:structure_parser_legacy.py

示例7: extract_feature

# 需要导入模块: from Bio.PDB import NeighborSearch [as 别名]
# 或者: from Bio.PDB.NeighborSearch import search [as 别名]
    def extract_feature(self):
        seed(self.seed)
        print_info_nn(" >>> Adding D1 surface shape distribution for database {0} ... ".format(self._database.name))
        overall_time = datetime.now()
        counter = 0
        if not os.path.exists(self._get_dir_name()):
            os.makedirs(self._get_dir_name())
        for complex_name in self._database.complexes.keys():
            protein_complex = self._database.complexes[complex_name]
            proteins = [protein_complex.unbound_formation.ligand, protein_complex.unbound_formation.receptor]
            for protein in proteins:
                shape_dist_file = self._get_dir_name() + protein.name
                if not os.path.exists(shape_dist_file + ".npy"):
                    counter += 1
                    if counter <= 15:
                        print_info_nn("{0}, ".format(protein.name))
                    else:
                        counter = 0
                        print_info("{0}".format(protein.name))
                    atoms = protein.atoms
                    neighbour_search = NeighborSearch(atoms)
                    distributions = np.zeros((len(protein.residues), self.number_of_bins + 1))
                    for i in range(len(protein.residues)):
                        residue = protein.residues[i]
                        nearby_residues = [protein.biopython_residues[i]]
                        temp_nearby_residues = neighbour_search.search(residue.center, self.radius, "R")
                        for nearby_residue in temp_nearby_residues:
                            if nearby_residue not in protein.biopython_residues:
                                continue
                            residues_index = protein.biopython_residues.index(nearby_residue)
                            residue = protein.residues[residues_index]

                            if residue.get_feature(Features.RELATIVE_ACCESSIBLE_SURFACE_AREA) >= self.rASA_threshold:
                                nearby_residues.append(nearby_residue)
                        distributions[i, :] = self._compute_distribution(nearby_residues, residue.center)
                    np.save(shape_dist_file, distributions)
                distributions = np.load(shape_dist_file + ".npy")
                for i in range(len(protein.residues)):
                    protein.residues[i].add_feature(Features.D1_SURFACE_SHAPE_DISTRIBUTION, distributions[i, :])
        print_info("took {0} seconds.".format((datetime.now() - overall_time).seconds))
开发者ID:sluggishcrow,项目名称:PAIRpred,代码行数:42,代码来源:d2_sureface_atoms_shape_distribution.py

示例8: PDBParser

# 需要导入模块: from Bio.PDB import NeighborSearch [as 别名]
# 或者: from Bio.PDB.NeighborSearch import search [as 别名]
structure = PDBParser().get_structure('X', args.pdb)

center_atoms = []
pymol_command = ""

all_atom_list = [atom for atom in structure.get_atoms() if atom.name == 'CA' ]

for k in args.chain1 :
    chain_atoms = [atom for atom in structure[0][k].get_atoms() if atom.name == 'CA' ]

    center_atoms += chain_atoms

#atom_list = [x for x in all_atom_list if x not in center_atoms]

for j in args.chain2 :
    atom_list = [atom for atom in structure[0][j].get_atoms() if atom.name == 'CA' ]
    ns = NeighborSearch(atom_list)

    nearby_residues = {res for center_atom in center_atoms
                        for res in ns.search(center_atom.coord, 8.5, 'R')}

    print "\nNeighbor residues in chain ", j, ": \n"
    print sorted(res.id[1] for res in nearby_residues)

    pymol_command = "show spheres, chain " + j + " and resi "

    for m in sorted(res.id[1] for res in nearby_residues):
        pymol_command = pymol_command + str(m) + "+"

    print pymol_command[:-1] + " and name CA \n" 
开发者ID:shantanu012,项目名称:cidechain,代码行数:32,代码来源:interface_chains.py

示例9: get_interacting_residues

# 需要导入模块: from Bio.PDB import NeighborSearch [as 别名]
# 或者: from Bio.PDB.NeighborSearch import search [as 别名]
def get_interacting_residues(model, r_cutoff=5, skip_hetatm_chains=True):
    """Return residue-residue interactions between all chains in `model`.

    Parameters
    ----------
    model : biopython.Model
        Model to analyse.

    Returns
    -------
    dict
        A dictionary of interactions between chains i (0..n-1) and j (i+1..n).
        Keys are (chain_idx, chain_id, residue_idx, residue_resnum, residue_amino_acid) tuples.
        (e.g. (0, 'A', 0, '0', 'M'), (0, 1, '2', 'K'), ...)
        Values are a list of tuples having the same format as the keys.

    Examples
    --------
    You can reverse the order of keys and values like this::

        complement = dict()
        for key, values in get_interacting_chains(model):
            for value in values:
                complement.setdefault(value, set()).add(key)


    You can get a list of all interacting chains using this command::

        {(key[0], value[0])
         for (key, values) in get_interacting_chains(model).items()
         for value in values}

    """
    from Bio.PDB import NeighborSearch

    interactions_between_chains = dict()

    # Chain 1
    for chain_1_idx, chain_1 in enumerate(model):
        if skip_hetatm_chains and chain_is_hetatm(chain_1):
            message = (
                "Skipping chain_1 with idx {} because it contains only hetatms."
                .format(chain_1_idx)
            )
            logger.debug(message)
            continue
        chain_1_residue_ids = get_aa_residues(chain_1)

        # Chain 2
        for j, chain_2 in enumerate(model.child_list[chain_1_idx + 1:]):
            chain_2_idx = chain_1_idx + 1 + j
            if skip_hetatm_chains and chain_is_hetatm(chain_2):
                message = (
                    "Skipping chain_2 with idx {} because it contains only hetatms."
                    .format(chain_2_idx)
                )
                logger.debug(message)
                continue
            chain_2_residue_ids = get_aa_residues(chain_2)
            ns = NeighborSearch(list(chain_2.get_atoms()))

            # Residue 1
            for residue_1 in chain_1:
                try:
                    residue_1_idx = chain_1_residue_ids.index(residue_1.id)
                except ValueError:
                    continue
                residue_1_resnum = str(residue_1.id[1]) + residue_1.id[2].strip()
                residue_1_aa = convert_aa(residue_1.resname, quiet=True)
                residue_1_key = (
                    chain_1_idx, chain_1.id, residue_1_idx, residue_1_resnum, residue_1_aa
                )
                interacting_residues = set()
                for atom_1 in residue_1:
                    interacting_residues.update(ns.search(atom_1.get_coord(), r_cutoff, 'R'))

                # Residue 2
                interacting_residue_ids = []
                for residue_2 in interacting_residues:
                    try:
                        residue_2_idx = chain_2_residue_ids.index(residue_2.id)
                    except ValueError:
                        continue
                    residue_2_resnum = str(residue_2.id[1]) + residue_2.id[2].strip()
                    residue_2_aa = convert_aa(residue_2.get_resname(), quiet=True)
                    residue_2_key = (
                        chain_2_idx, chain_2.id, residue_2_idx, residue_2_resnum, residue_2_aa
                    )
                    interacting_residue_ids.append(residue_2_key)
                if interacting_residue_ids:
                    interactions_between_chains\
                        .setdefault(residue_1_key, set())\
                        .update(interacting_residue_ids)

    return interactions_between_chains
开发者ID:kimlaborg,项目名称:kmtools,代码行数:97,代码来源:structure_parser_legacy.py

示例10: print

# 需要导入模块: from Bio.PDB import NeighborSearch [as 别名]
# 或者: from Bio.PDB.NeighborSearch import search [as 别名]
    if residue.resname == args.ligand:
        ligand = residue
        break

if not ligand:
    print('[!!] Ligand residue \'{0}\' not found in structure'.format(args.ligand), file=sys.stderr)
    sys.exit(1)

# Calculate center of mass of the ligand
ligand_com = map(lambda x: sum(x)/len(x), zip(*[at.coord for at in ligand]))
ligand_com = np.asarray(ligand_com, dtype=np.float32)

# Calculate neighbors considering only aminoacid/nucleotide atoms (excl. waters, other ligands, etc)
sel_atoms = [at for at in structure.get_atoms() if at.parent.id[0] == ' ']
ns = NeighborSearch(sel_atoms)
neighbors = ns.search(ligand_com, 10.0, level='R') # 10A radius, return residues

# Calculate residue closer to each ligand atom and the respective distance
ligand_atoms = ligand.child_list
min_dist_list, _seen = [], set()

for l_at in ligand_atoms:
    distances = []
    for residue in neighbors:
        for r_at in residue:
            distances.append((r_at, l_at, r_at - l_at))

    distances.sort(key=lambda x: x[-1])
    min_dist = distances[0]
    # One restraint per residue to keep the number of restraints small
    if min_dist[0].parent not in _seen:
开发者ID:CunliangGeng,项目名称:haddock-tools,代码行数:33,代码来源:restrain_ligand.py


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