def _get_volume_overlap(self, cav_id, other_id, lig_id): """ find the highest median bcv from all cavities, calculate percentage over between the best bcv and each query ligand :return: """ def nonzero(val): if val == 0: return 1 else: return val # inputs mol = io.MoleculeReader(self.extracted_ligands[other_id][lig_id])[0] path1 = os.path.join(self.hotspot[cav_id], "out.zip") path2 = os.path.join(self.bcv[cav_id][other_id][lig_id], "out.zip") thresholds = [10, 14, 17] if os.path.exists(path1) and os.path.exists(path2): bcv = HotspotReader(path2).read() hot = HotspotReader(path1).read() # tasks other = Grid.from_molecule(mol) bcv_sg = Grid.get_single_grid(bcv.super_grids, mask=False) bcv_overlap = bcv_sg._mutually_inclusive(other=other).count_grid() lig_vol = (other > 0).count_grid() bcv_vol = (bcv_sg > 0).count_grid() hot_sgs = [(Grid.get_single_grid(hot.super_grids, mask=False) > t) for t in thresholds] hot_vols = [nonzero(hot_sg.count_grid()) for hot_sg in hot_sgs] hot_overlap = [hot_sg._mutually_inclusive(other=other).count_grid() for hot_sg in hot_sgs] # output with open(self.bcv_lig_overlaps[cav_id][other_id][lig_id], 'w') as writer: writer.write(str((bcv_overlap / lig_vol) * 100)) with open(self.bcv_hot_overlaps[cav_id][other_id][lig_id], 'w') as writer: writer.write(str((bcv_overlap / bcv_vol) * 100)) with open(self.hot_lig_overlaps[cav_id][other_id][lig_id], 'w') as writer: hot_lig = [str((a / lig_vol) * 100) for a in hot_overlap] print(hot_lig) writer.write(",".join(hot_lig)) with open(self.hot_hot_overlaps[cav_id][other_id][lig_id], 'w') as writer: hot_hot = [str((hot_overlap[i] / hot_vols[i]) * 100) for i in range(len(thresholds))] writer.write(",".join(hot_hot)) else: print("no BCV for cavity {}, BCV {}".format(cav_id, lig_id))
def generate_fake(self, buriedness=False, weighted=False, superstar=True): """ create a small set of grids for testing :param buriedness: :param weighted: :param superstar: :return: """ def populate_grid(template, num_spheres, radius=1, value=8, scaling='linear'): h = template.copy_and_clear() for i in range(1, num_spheres): x, y, z = [np.random.randint(low=2, high=ax - 2, size=1) for ax in h.nsteps] h.set_sphere(point=h.indices_to_point(x, y, z), radius=radius, value=value, scaling=scaling) return h protein = Protein.from_file("testdata/6y2g_A/binding_site.pdb") mol = MoleculeReader("testdata/6y2g_A/A_mol.mol2")[0] g = Grid.initalise_grid([a.coordinates for a in mol.atoms]) if buriedness: buriedness_grid = Grid.from_molecule(mol) else: buriedness_grid = None interactions = ["apolar", "donor", "acceptor"] super_grids = {p: populate_grid(template=g, num_spheres=3) for p in interactions} if superstar: superstar_grids = {p: populate_grid(template=g, num_spheres=3) for p in interactions} else: superstar_grids = None if weighted: weighted_superstar_grids = {p: populate_grid(template=g, num_spheres=3) for p in interactions} else: weighted_superstar_grids = None return Results(super_grids=super_grids, protein=protein, buriedness=buriedness_grid, superstar=superstar_grids, weighted_superstar=weighted_superstar_grids)
def main(): base = "/local/pcurran/leads_frag" pdbs = [ p for p in os.listdir(base) if os.path.isdir(os.path.join(base, p)) ] for pdb in tqdm(pdbs): fpath = os.path.join(base, pdb, f"{pdb}_ref.mol2") mol = io.MoleculeReader(fpath)[0] g = Grid.from_molecule(mol, mode='replace', padding=10, scaling=0.5) out_path = os.path.join(base, pdb, "control.mol2") docking_fitting_pts(g, fname=out_path, high=1)
def set_background(self, background_value=1.0): spacing = self.super_grids["apolar"]._spacing prot_g = Grid.from_molecule(self.protein, value=background_value, scaling_type='none', scaling=1, spacing=spacing) for probe, g in self.super_grids.items(): common_prot, common_g = Grid.common_grid([prot_g, g]) bg_mask = (common_prot < 0.1) & (common_g < 1) tmp_g = common_g + bg_mask new_g = tmp_g - (common_prot) origin, corner = g.bounding_box i, j, k = new_g.point_to_indices(origin) l, m, n = new_g.point_to_indices(corner) self.super_grids[probe] = new_g.sub_grid((i, j, k, l, m, n))
def _get_ligand_volume(self, other_id, lig_id): """ from a ligand, output a molecular volume in A^3 :param i: position in list of 'other' proteins :return: """ # inputs ligand = io.MoleculeReader(self.extracted_ligands[other_id][lig_id])[0] # tasks g = Grid.from_molecule(ligand) vol = g.count_grid() * (g.spacing ** 3) # output with open(self.ligand_volume[other_id][lig_id], 'w') as f: f.write(str(vol))
def _remove_protein_vol(self, g): """ :param g: :return: """ prot_g = Grid.from_molecule(self.hotspot_result.protein, value=1, scaling_type='none', scaling=1) common_prot, common_g = Grid.common_grid([prot_g, g]) new_g = common_g * (common_prot < 1) origin, corner = g.bounding_box i, j, k = new_g.point_to_indices(origin) l, m, n = new_g.point_to_indices(corner) return new_g.sub_grid((i, j, k, l, m, n))