Пример #1
0
    def cavities(self, obj):
        """
        optional settings, cavities supplied to the calculation
        :param list or Coordinate or `ccdc.molecule.Molecule` or `ccdc.cavity.Cavity`: cavity information provided
        :return:
        """
        if obj is not None:
            if isinstance(obj, list) or isinstance(obj, tuple):
                if isinstance(obj, Coordinates):
                    try:
                        print(obj.x)
                        self._cavities = [obj]
                    except AttributeError:
                        self._cavities = obj

                    self._cavities = [obj]
                elif isinstance(obj[0], Molecule):
                    self._cavities = [m.centre_of_geometry() for m in obj]
                elif isinstance(obj[0], Cavity):
                    self._cavities = [Helper.cavity_centroid(c) for c in obj]
                else:
                    print("WARNING! Failed to detected cavity, Atomic Hotspot detection to run on whole protein")
                    self._cavities = None

            elif isinstance(obj, Molecule):
                self._cavities = [obj.centre_of_geometry()]
            elif isinstance(obj, Cavity):
                self._cavities = [Helper.cavity_centroid(obj)]

            else:
                print("WARNING! Failed to detected cavity, Atomic Hotspot detection to run on whole protein")
                self._cavities = None
        else:
            self._cavities = None
Пример #2
0
    def _get_cavities(self, min_vol):
        """
        detect cavities using Cavity API, generate new directory for each cavity

        :return: None
        """

        # inputs
        cavs = [c for c in Cavity.from_pdb_file(self.apo_prep) if c.volume > min_vol]

        # task
        for i in range(len(cavs)):
            create_directory(path=os.path.join(self.working_dir, 'cavity_{}'.format(i)))

        cav_dic = {os.path.join(self.working_dir, 'cavity_{}'.format(i)): Helper.cavity_centroid(c)
                   for i, c in enumerate(cavs)}

        cav_volume_dic = {os.path.join(self.working_dir, 'cavity_{}'.format(i), "cavity.volume"): c.volume
                          for i, c in enumerate(cavs)}

        cav_bb = {os.path.join(self.working_dir, 'cavity_{}'.format(i), "bounding_box.pkl"): c.bounding_box
                  for i, c in enumerate(cavs)}

        # output
        for path, origin in cav_dic.items():
            with open(os.path.join(path, "cavity_origin.pkl"), 'wb') as handle:
                pickle.dump(origin, handle)

        for path, vol in cav_volume_dic.items():
            with open(os.path.join(path), 'w') as f:
                f.write(str(vol))

        for path, bb in cav_bb.items():
            with open(os.path.join(path), 'wb') as h:
                pickle.dump(bb, h)

        # update attr
        self.runs += ["cavity_{}".format(i) for i in range(len(cavs))]

        self.cavities = {
            "cavity_{}".format(p): os.path.join(self.working_dir, 'cavity_{}'.format(p), "cavity_origin.pkl")
            for p in range(len(cav_dic))}
        self.cavities_volumes = {
            "cavity_{}".format(p): os.path.join(self.working_dir, 'cavity_{}'.format(p), "cavity.volume")
            for p in range(len(cav_dic))}
        self.cavity_score = {
            "cavity_{}".format(p): os.path.join(self.working_dir, "cavity_{}".format(p), "cavity.score")
            for p in range(len(cav_dic))}
        self.bounding_box = {
            "cavity_{}".format(p): os.path.join(self.working_dir, 'cavity_{}'.format(p), "bounding_box.pkl")
            for p in range(len(cav_dic))}

        self.superstar = {p: os.path.join(self.working_dir, p, "superstar") for p in self.runs}
        self.superstar_time = {k: os.path.join(v, "time.time") for k, v in self.superstar.items()}

        self.hotspot = {p: os.path.join(self.working_dir, p, "hotspot") for p in self.runs}
        self.hotspot_time = {k: os.path.join(v, "time.time") for k, v in self.hotspot.items()}

        self.bcv = {i: {pid: {k: os.path.join(self.working_dir, i, "bcv", "volume_{}".format(k))
                              for k in self.ligand_id[j]}
                        for j, pid in enumerate(self.protein_id)}
                    for i in self.runs}
        self.bcv_time = {i: {pid: {k: os.path.join(self.working_dir, i, "bcv", "volume_{}".format(k), "time.time")
                                   for k in self.ligand_id[j]}
                             for j, pid in enumerate(self.protein_id)}
                         for i in self.runs}
        self.bcv_threshold = {i: {pid: {k: os.path.join(self.working_dir, i, "bcv", "volume_{}".format(k),
                                                        "threshold.dat")
                                        for k in self.ligand_id[j]}
                                  for j, pid in enumerate(self.protein_id)}
                              for i in self.runs}

        self.bcv_lig_overlaps = {
            i: {pid: {k: os.path.join(self.working_dir, i, "bcv", "lig_overlap_{}.percentage".format(k))
                      for k in self.ligand_id[j]}
                for j, pid in enumerate(self.protein_id)}
            for i in self.runs}

        self.bcv_hot_overlaps = {
            i: {pid: {k: os.path.join(self.working_dir, i, "bcv", "hot_overlap_{}.percentage".format(k))
                      for k in self.ligand_id[j]}
                for j, pid in enumerate(self.protein_id)}
            for i in self.runs}

        self.hot_lig_overlaps = {
            i: {pid: {k: os.path.join(self.working_dir, i, "hotspot", "lig_overlap_{}.percentage".format(k))
                      for k in self.ligand_id[j]}
                for j, pid in enumerate(self.protein_id)}
            for i in self.runs}

        self.hot_hot_overlaps = {
            i: {pid: {k: os.path.join(self.working_dir, i, "hotspot", "hot_overlap_{}.percentage".format(k))
                      for k in self.ligand_id[j]}
                for j, pid in enumerate(self.protein_id)}
            for i in self.runs}

        self.atomic_overlaps = {i: {pid: {k: os.path.join(self.working_dir, i, "bcv", "atomic_overlap_{}.dat".format(k))
                                  for k in self.ligand_id[j]}
                            for j, pid in enumerate(self.protein_id)}
                        for i in self.runs}

        self.matched = {i: {pid: {k: os.path.join(self.working_dir, i, "bcv", "atom_match_{}.percentage".format(k))
                                  for k in self.ligand_id[j]}
                            for j, pid in enumerate(self.protein_id)}
                        for i in self.runs}