# predict.py — Kidney Arch3 LazyPredict-best deployment model # (BaggingClassifier, the full-pool sweep winner). Predicts the # probability of the kidney-toxic (nephrotoxicity-concern) class for # one molecule. # # Usage: # python3 predict.py "CCO" -> prints the probability # from predict import predict; predict("CCO") # from predict import predict_many; predict_many([smi1, smi2]) # # Requires: scikit-learn, rdkit, joblib, numpy, and # deployment_common.py (shipped in this repo) on the import path — the # shipped preprocessing object (DescPrep) unpickles against that # module. # # Featurization is the deployment pipeline's own code: featurize / # prep_matrix from deployment_common.py; prediction replicates # screen_leads.py's arch3_prob exactly (fp_desc block). import os, sys HERE = os.path.dirname(os.path.abspath(__file__)) sys.path.insert(0, HERE) import numpy as np import joblib from deployment_common import featurize, prep_matrix _bundle = joblib.load(os.path.join(HERE, "model.joblib")) _model, _prep = _bundle["model"], _bundle["prep"] def predict_many(smiles_list): """Probabilities of the toxic class; None where unparseable.""" blocks, valid = featurize(list(smiles_list)) X = prep_matrix(blocks, _prep, "fp_desc") p = _model.predict_proba(X)[:, 1] return [float(v) if ok else None for v, ok in zip(p, valid)] def predict(smiles): """Probability of the toxic class; None if unparseable.""" return predict_many([smiles])[0] if __name__ == "__main__": print(predict(sys.argv[1]))