Пример #1
0
def get_events(events_csv_path):
    events_table = pd.read_csv(str(events_csv_path))
    events: List[Event] = []

    for idx, event_record in events_table.iterrows():
        # event: Event = Event(dtag=str(event_record["dtag"]),
        #                      event_idx=int(event_record["event_idx"]),
        #                      occupancy=event_record["occupancy"],
        #                      analysed_resolution=event_record["analysed_resolution"],
        #                      high_resolution=event_record["high_resolution"],
        #                      interesting=event_record["interesting"],
        #                      ligand_placed=event_record["ligand_placed"],
        #                      ligand_confidence=event_record["ligand_confidence"],
        #                      viewed=event_record["viewed"],
        #                      initial_model_path=Path(event_record["initial_model_path"]),
        #                      data_path=Path(event_record["data_path"]),
        #                      final_model_path=Path(event_record["final_model_path"]),
        #                      event_map_path=Path(event_record["event_map_path"]),
        #                      actually_built=event_record["actually_built"],
        #                      x=event_record["x"],
        #                      y=event_record["y"],
        #                      z=event_record["z"],
        #                      )
        event = Event.from_record(event_record)

        events.append(event)

    return events
Пример #2
0
def get_events(path):
    events = {}
    event_table = pd.read_csv(str(path))
    for idx, event_row in event_table.iterrows():
        if event_row["actually_built"] is True:
            pandda_processed_dir = Path(event_row["event_map_path"]).parent
            print(pandda_processed_dir)
            if pandda_processed_dir.exists():
                try:
                    event_row["ligand_smiles_path"] = get_ligand_smiles(
                        Path(event_row["event_map_path"]).parent)
                    print("\tLigand smiles path:{}".format(
                        event_row["ligand_smiles_path"]))
                    event = Event.from_record(event_row)
                    # events.append(event)
                    events[(event.pandda_name, event.dtag,
                            event.event_idx)] = event

                except Exception as e:
                    print(e)
                    continue

        else:
            continue

    return events
Пример #3
0
def get_events(events_table: pd.DataFrame):
    events = {}
    for idx, row in events_table.iterrows():
        event = Event.from_record(row)
        event_id = EventID(row["dtag"], row["event_idx"])
        events[event_id] = event

    return events
Пример #4
0
def get_events(event_talbe_path):
    event_table = pd.read_csv(str(event_talbe_path))

    events = {}
    for event_id, row in event_table.iterrows():
        event = Event.from_record(row)
        events[(event.pandda_name, event.dtag, event.event_idx)] = event

    return events
def get_events(events_csv_path):
    events_table = pd.read_csv(str(events_csv_path))
    events: List[Event] = []

    for idx, event_record in events_table.iterrows():

        event = Event.from_record(event_record)

        events.append(event)

    return events, events_table
Пример #6
0
def get_event_table(path):
    events = []
    event_table = pd.read_csv(str(path))
    for idx, event_row in event_table.iterrows():
        if event_row["actually_built"] is True:
            event = Event.from_record(event_row)
            events.append(event)
        else:
            continue

    return events
Пример #7
0
    def __getitem__(self, item):
        event_record = self.table.iloc[item]

        event = Event.from_record(event_record)
        # print(event.viewed)
        # print(type(event.viewed))

        if bool(event.viewed) is False:
            sample_dict = {
                "id": {
                    "pandda_name": event.pandda_name,
                    "dtag": event.dtag,
                    "event_idx": event.event_idx,
                },
                "data":
                np.zeros(
                    (
                        2,
                        self.sample_shape[0],
                        self.sample_shape[1],
                        self.sample_shape[2],
                    ),
                    dtype=np.float32,
                ),
                "label":
                np.array([1, 0], dtype=np.float32),
                "event_map_path":
                str(event.event_map_path),
                "model_path":
                str(event.initial_model_path),
                "coords":
                str([event.x, event.y, event.z])
            }

            return sample_dict
        try:

            event_centroid = np.array([
                event.x,
                event.y,
                event.z,
            ])

            data_map = get_map_from_mtz_path(event.data_path)
            event_map: gemmi.Grid = gemmi.read_ccp4_map(event.event_map_path)

            rotation = sample_rotation()
            translation = sample_translation()

            data_map_layer = sample_map(
                data_map,
                event_centroid,
                rotation,
                translation,
                self.sample_shape,
            )
            event_map_layer = sample_event_map(
                event_map,
                event_centroid,
                rotation,
                translation,
                self.sample_shape,
            )
            data = np.stack(
                [data_map_layer, event_map_layer],
                axis=0,
            )

            label = get_label(event)

            sample_dict = {
                "id": {
                    "pandda_name": event.pandda_name,
                    "dtag": event.dtag,
                    "event_idx": event.event_idx,
                },
                "data": data,
                "label": label,
                "event_map_path": str(event.event_map_path),
                "model_path": str(event.initial_model_path),
                "coords": str([event.x, event.y, event.z])
            }

            return sample_dict
        except Exception as e:
            # Null result
            # print(e)
            sample_dict = {
                "id": {
                    "pandda_name": event.pandda_name,
                    "dtag": event.dtag,
                    "event_idx": event.event_idx,
                    # "initial_model_dir": ,
                },
                "data":
                np.zeros(
                    (
                        2,
                        self.sample_shape[0],
                        self.sample_shape[1],
                        self.sample_shape[2],
                    ),
                    dtype=np.float32,
                ),
                "label":
                np.array([1, 0], dtype=np.float32),
                "event_map_path":
                str(event.event_map_path),
                "model_path":
                str(event.initial_model_path),
                "coords":
                str([event.x, event.y, event.z])
            }

            return sample_dict
Пример #8
0
    def __getitem__(self, item):
        event_record = self.table.iloc[item]

        event = Event.from_record(event_record)
        rscc = self.rscc_dict[(event.pandda_name, event.dtag, event.event_idx)]

        # if bool(event.viewed) is False:
        #     sample_dict = {"id": {"pandda_name": event.pandda_name,
        #                           "dtag": event.dtag,
        #                           "event_idx": event.event_idx,
        #                           },
        #                    "data": np.zeros((2,
        #                                      self.sample_shape[0],
        #                                      self.sample_shape[1],
        #                                      self.sample_shape[2],
        #                                      ),
        #                                     dtype=np.float32,
        #                                     ),
        #                    "label": np.array([1, 0], dtype=np.float32),
        #                    "event_map_path": str(event.event_map_path),
        #                    "model_path": str(event.initial_model_path),
        #                    "coords": str([event.x, event.y, event.z]),
        #                    "rscc": 0,
        #                    }
        #
        #     return sample_dict

        if float(rscc) == 0.0:
            sample_dict = {"id": {"pandda_name": event.pandda_name,
                                  "dtag": event.dtag,
                                  "event_idx": event.event_idx,
                                  },
                           "data": np.zeros((2,
                                             self.sample_shape[0],
                                             self.sample_shape[1],
                                             self.sample_shape[2],
                                             ),
                                            dtype=np.float32,
                                            ),
                           "label": np.array([1, 0], dtype=np.float32),
                           "event_map_path": str(event.event_map_path),
                           "model_path": str(event.initial_model_path),
                           "coords": str([event.x, event.y, event.z]),
                           "rscc": 0.0,
                           "rscc_class": np.array([1.0,0.0], dtype=np.float32),
                           }

            return sample_dict

        try:

            event_centroid = np.array([event.x,
                                       event.y,
                                       event.z,
                                       ])

            data_map = get_map_from_mtz_path(event.data_path)
            event_map: gemmi.Grid = gemmi.read_ccp4_map(event.event_map_path)

            rotation = sample_rotation()
            translation = sample_translation()

            data_map_layer = sample_map(data_map,
                                        event_centroid,
                                        rotation,
                                        translation,
                                        self.sample_shape,
                                        )
            event_map_layer = sample_event_map(event_map,
                                               event_centroid,
                                               rotation,
                                               translation,
                                               self.sample_shape,
                                               )
            data = np.stack([data_map_layer, event_map_layer],
                            axis=0,
                            )

            label = get_label(event)

            if rscc <0.7:
                rscc_class = np.array([1.0, 0.0], dtype=np.float32)
            else:
                rscc_class = np.array([0.0,1.0], dtype=np.float32)

            sample_dict = {"id": {"pandda_name": event.pandda_name,
                                  "dtag": event.dtag,
                                  "event_idx": event.event_idx,
                                  },
                           "data": data,
                           "label": label,
                           "event_map_path": str(event.event_map_path),
                           "model_path": str(event.initial_model_path),
                           "coords": str([event.x, event.y, event.z]),
                           "rscc": rscc,
                           "rscc_class": rscc_class,
                           }

            return sample_dict
        except Exception as e:
            # Null result
            # print(e)
            sample_dict = {"id": {"pandda_name": event.pandda_name,
                                  "dtag": event.dtag,
                                  "event_idx": event.event_idx,
                                  # "initial_model_dir": ,
                                  },
                           "data": np.zeros((2,
                                             self.sample_shape[0],
                                             self.sample_shape[1],
                                             self.sample_shape[2],
                                             ),
                                            dtype=np.float32,
                                            ),
                           "label": np.array([1, 0], dtype=np.float32),
                           "event_map_path": str(event.event_map_path),
                           "model_path": str(event.initial_model_path),
                           "coords": str([event.x, event.y, event.z]),
                           "rscc": 0.0,
                           "rscc_class": np.array([1, 0], dtype=np.float32),
                           }

            return sample_dict
Пример #9
0
    def __getitem__(self, item):
        event_record = self.table.iloc[item]

        event = Event.from_record(event_record)
        # print(event.viewed)
        # print(type(event.viewed))

        if bool(event.viewed) is False:
            sample_dict = {
                "id": {
                    "pandda_name": event.pandda_name,
                    "dtag": event.dtag,
                    "event_idx": event.event_idx,
                },
                "data": np.zeros(
                    self.sample_shape,
                    dtype=np.float32,
                ),
                "label": np.array([1, 0], dtype=np.float32),
            }

            return sample_dict
        try:

            event_centroid = np.array([
                event.x,
                event.y,
                event.z,
            ])

            event_map: gemmi.Grid = gemmi.read_ccp4_map(event.event_map_path)

            rotation = sample_rotation()
            translation = sample_translation()

            event_map_layer = sample_event_map(
                event_map,
                event_centroid,
                rotation,
                translation,
                self.sample_shape,
            )
            data = event_map_layer

            label = get_label(event)

            sample_dict = {
                "id": {
                    "pandda_name": event.pandda_name,
                    "dtag": event.dtag,
                    "event_idx": event.event_idx,
                },
                "data": data,
                "label": label,
            }

            return sample_dict
        except:
            # Null result
            sample_dict = {
                "id": {
                    "pandda_name": event.pandda_name,
                    "dtag": event.dtag,
                    "event_idx": event.event_idx,
                },
                "data": np.zeros(
                    self.sample_shape,
                    dtype=np.float32,
                ),
                "label": np.array([1, 0], dtype=np.float32),
            }

            return sample_dict