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
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
def get_events(pandda: PanDDA): events: Dict[Tuple[str, int], Event] = {} inspect_table: pd.DataFrame = pd.read_csv(str(pandda.event_table_path)) processed_datasets_path: Path = pandda.dir / "processed_datasets" for idx, event_record in inspect_table.iterrows(): dataset_path = processed_datasets_path / "{}".format(event_record["dtag"]) modelled_structures_path = dataset_path / "{}".format("modelled_structures") initial_model_path = dataset_path / "{}-pandda-input.pdb".format(event_record["dtag"]) data_path = dataset_path / "{}-pandda-input.mtz".format(event_record["dtag"]) final_model_path = modelled_structures_path / "{}-pandda-model.pdb".format(event_record["dtag"]) # final_model_path = modelled_structures_path / "fitted-v0001".format(event_record["dtag"]) event_map_path = dataset_path / "{}-event_{}_1-BDC_{}_map.native.ccp4".format(event_record["dtag"], event_record["event_idx"], event_record["1-BDC"], ) ligand_smiles = get_ligand_smiles(dataset_path) actually_built = is_actually_built(final_model_path) if actually_built: distance_to_ligand_model = get_distance_to_ligand_model(np.array([event_record["x"], event_record["y"], event_record["z"]] ), final_model_path) # print("\t\tDistance to model is: {}".format(distance_to_ligand_model)) else: distance_to_ligand_model = 0 event: Event = Event(dtag=str(event_record["dtag"]), event_idx=int(event_record["event_idx"]), occupancy=event_record["1-BDC"], 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=initial_model_path, data_path=data_path, model_dir=pandda.model_dir, pandda_dir=pandda.dir, pandda_name=pandda.dir.name, final_model_path=final_model_path, event_map_path=event_map_path, actually_built=actually_built, ligand_smiles_path=ligand_smiles, x=event_record["x"], y=event_record["y"], z=event_record["z"], distance_to_ligand_model=distance_to_ligand_model, event_size=event_record["cluster_size"], ) events[(event.dtag, event.event_idx)] = event return events
def get_events(events_table): 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"], ligand_smiles_path=event_record["ligand_smiles_path"], model_dir=event_record["model_dir"], pandda_dir=event_record["pandda_dir"], pandda_name=event_record["pandda_name"], ) events.append(event) return events
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
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
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
def from_pandda_path(path: Path): pandda_dir = path events_csv_path = path / "analyses" / "pandda_analyse_events.csv" pandda_json_path = path / "pandda.json" with open(str(pandda_json_path), "r") as f: pandda_json_string = f.read() pandda_json_dict = json.loads(pandda_json_string) data_dirs = Path(pandda_json_dict["data_dirs"]).parent event_table = pd.read_csv(str(events_csv_path)) events = Event.from_pandda_path(pandda_dir, data_dirs, ) pandda = PanDDA(data_dir=data_dirs, pandda_dir=pandda_dir, events_table_path=events_csv_path, events=events, ) return pandda
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
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
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