File size: 5,608 Bytes
94391f2 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 | # Copyright (c) DP Technology.
# This source code is licensed under the MIT license found in the
# LICENSE file in the root directory of this source tree.
from functools import lru_cache
import numpy as np
from unicore.data import BaseWrapperDataset
from . import data_utils
class VAEBindingDataset(BaseWrapperDataset):
def __init__(
self,
dataset,
seed,
atoms,
coordinates,
pocket_atoms,
pocket_coordinates,
selfies,
is_train=True,
):
self.dataset = dataset
self.seed = seed
self.atoms = atoms
self.coordinates = coordinates
self.pocket_atoms = pocket_atoms
self.pocket_coordinates = pocket_coordinates
self.selfies = selfies
self.is_train = is_train
self.set_epoch(None)
def set_epoch(self, epoch, **unused):
super().set_epoch(epoch)
self.epoch = epoch
def pocket_atom(self, atom):
if atom[0] in ['0', '1', '2', '3', '4', '5', '6', '7', '8', '9']:
return atom[1]
else:
return atom[0]
@lru_cache(maxsize=16)
def __cached_item__(self, index: int, epoch: int):
atoms = np.array(self.dataset[index][self.atoms])
coordinates = self.dataset[index][self.coordinates]
pocket_atoms = np.array(
[self.pocket_atom(item) for item in self.dataset[index][self.pocket_atoms]]
)
pocket_coordinates = np.stack(self.dataset[index][self.pocket_coordinates])
smi = self.dataset[index]["smi"]
pocket = self.dataset[index]["pocket"]
#affinity = self.dataset[index][self.affinity]
selfies = np.array(self.dataset[index][self.selfies])
return {
"atoms": atoms,
"coordinates": coordinates.astype(np.float32),
"holo_coordinates": coordinates.astype(np.float32),#placeholder
"pocket_atoms": pocket_atoms,
"pocket_coordinates": pocket_coordinates.astype(np.float32),
"holo_pocket_coordinates": pocket_coordinates.astype(np.float32),#placeholder
"smi": smi,
"pocket": pocket,
"selfies": selfies
}
def __getitem__(self, index: int):
return self.__cached_item__(index, self.epoch)
class VAEBindingTestDataset(BaseWrapperDataset):
def __init__(
self,
dataset,
seed,
atoms,
coordinates,
pocket_atoms,
pocket_coordinates,
is_train=True,
):
self.dataset = dataset
self.seed = seed
self.atoms = atoms
self.coordinates = coordinates
self.pocket_atoms = pocket_atoms
self.pocket_coordinates = pocket_coordinates
self.is_train = is_train
self.set_epoch(None)
def set_epoch(self, epoch, **unused):
super().set_epoch(epoch)
self.epoch = epoch
def pocket_atom(self, atom):
if atom[0] in ['0', '1', '2', '3', '4', '5', '6', '7', '8', '9']:
return atom[1]
else:
return atom[0]
@lru_cache(maxsize=16)
def __cached_item__(self, index: int, epoch: int):
atoms = np.array(self.dataset[index][self.atoms])
coordinates = self.dataset[index][self.coordinates]
pocket_atoms = np.array(
[self.pocket_atom(item) for item in self.dataset[index][self.pocket_atoms]]
)
pocket_coordinates = np.stack(self.dataset[index][self.pocket_coordinates])
smi = self.dataset[index]["smi"]
pocket = self.dataset[index]["pocket_name"]
lig = self.dataset[index]["lig_name"]
#affinity = self.dataset[index][self.affinity]
return {
"atoms": atoms,
"coordinates": coordinates.astype(np.float32),
"holo_coordinates": coordinates.astype(np.float32),#placeholder
"pocket_atoms": pocket_atoms,
"pocket_coordinates": pocket_coordinates.astype(np.float32),
"holo_pocket_coordinates": pocket_coordinates.astype(np.float32),#placeholder
"smi": smi,
"pocket": pocket,
"lig": lig
}
def __getitem__(self, index: int):
return self.__cached_item__(index, self.epoch)
class VAEGenerationTestDataset(BaseWrapperDataset):
def __init__(
self,
dataset,
seed,
pocket_atoms,
pocket_coordinates,
is_train=True,
):
self.dataset = dataset
self.seed = seed
self.pocket_atoms = pocket_atoms
self.pocket_coordinates = pocket_coordinates
self.is_train = is_train
self.set_epoch(None)
def set_epoch(self, epoch, **unused):
super().set_epoch(epoch)
self.epoch = epoch
def pocket_atom(self, atom):
if atom[0] in ['0', '1', '2', '3', '4', '5', '6', '7', '8', '9']:
return atom[1]
else:
return atom[0]
@lru_cache(maxsize=16)
def __cached_item__(self, index: int, epoch: int):
pocket_atoms = np.array(
[self.pocket_atom(item) for item in self.dataset[index][self.pocket_atoms]]
)
pocket_coordinates = np.stack(self.dataset[index][self.pocket_coordinates])
return {
"pocket_atoms": pocket_atoms,
"pocket_coordinates": pocket_coordinates.astype(np.float32),
"holo_pocket_coordinates": pocket_coordinates.astype(np.float32),#placeholder
}
def __getitem__(self, index: int):
return self.__cached_item__(index, self.epoch)
|