zzqsb's picture
Release the REE tasks and dataset card.
7f50cd1
Raw History Blame Contribute Delete
2.12 kB
import json
import pickle
import sys
from pathlib import Path
import numpy as np
from scipy.spatial import cKDTree
CORE_DIR = __import__("os").environ.get("CORE_DIR")
if CORE_DIR:
sys.path.insert(0, CORE_DIR)
from interface.io import read_items, write_predictions
# RF-Score-VS v2 uses nine ligand and four protein atomic-number classes. The
# task's atom categories carry the corresponding element/environment labels.
ATOMIC_NUMBER = {
0: 35, 1: 6, 2: 6, 3: 6, 4: 6, 5: 6, 6: 20, 7: 17, 8: 9,
9: 1, 10: 53, 11: 12, 12: 25, 13: 7, 14: 7, 15: 7, 16: 7,
17: 7, 18: 7, 19: 7, 20: 11, 21: 8, 22: 8, 23: 8, 24: 15,
25: 16, 26: 16, 27: 30,
}
LIGAND_TYPES = (6, 7, 8, 9, 15, 16, 17, 35, 53)
PROTEIN_TYPES = (6, 7, 8, 16)
TYPE_L = {v: i for i, v in enumerate(LIGAND_TYPES)}
TYPE_P = {v: i for i, v in enumerate(PROTEIN_TYPES)}
def descriptor(item):
ligand = [n for n in item["left"]["nodes"] if n[1] == 0]
protein = [n for n in item["right"]["nodes"] if n[1] == 0]
coords = np.asarray([n[2:5] for n in protein], dtype=float)
tree = cKDTree(coords)
values = np.zeros((9, 4, 6), dtype=np.uint16)
for atom in ligand:
li = TYPE_L.get(ATOMIC_NUMBER.get(atom[0]))
if li is None:
continue
q = np.asarray(atom[2:5], dtype=float)
for j in tree.query_ball_point(q, 12.0):
pi = TYPE_P.get(ATOMIC_NUMBER.get(protein[j][0]))
if pi is None:
continue
distance = float(np.linalg.norm(coords[j] - q))
values[li, pi, min(int(distance // 2), 5)] += 1
return values.ravel()
def main():
if len(sys.argv) != 3:
raise SystemExit("usage: run.sh <data dir> <output dir>")
model_path = Path(__file__).with_name("model.pkl")
with model_path.open("rb") as fh:
model = pickle.load(fh)
items = read_items(sys.argv[1])
matrix = np.asarray([descriptor(item) for item in items])
predictions = model.predict(matrix)
write_predictions(sys.argv[2], ((item["id"], value) for item, value in zip(items, predictions)))
if __name__ == "__main__":
main()