AI for Science in Drug Discovery: Building a Screening Funnel from Millions of Molecules to Clinical Candidates
AI for Science (AI4S) in drug discovery faces a fundamental asymmetry: generative models can produce thousands of candidate molecules in minutes, while wet-lab validation remains slow, expensive, and limited in throughput. The real bottleneck is not generation but screening—the ability to converge a massive candidate pool down to a handful of molecules worth validating, at a low false-positive rate. This article walks through a production-ready four-layer architecture for an AI4S pipeline (data and representation, agent orchestration, multi-stage filtering, and engineering infrastructure), includes sample Python code for a pluggable filtering chain with auditable rejection records, and covers reproducibility practices, cost governance, common pitfalls, and deployment recommendations using general-purpose cloud capabilities.
1. Shifting Focus: From “Writing Code” to “Doing Science”
Over the past two years, the first thing most developers associate with large models is code completion and script generation. Research scenarios, however, place different demands on models: coding tasks come with immediate, cheap, reliable feedback in the form of compilation and tests, whereas biomedical research often lacks such validation signals. This has led to a natural division of labor—models are no longer just “coding assistants” but take on roles as research collaborators handling literature comprehension, hypothesis generation, experiment design, and result interpretation.
A typical workload comparison illustrates the point well. Tasks such as marker gene computation, ribosomal protein filtering, and biological plausibility assessment used to take a PhD student four to eight hours of continuous work, with most of that time spent switching between tools, tuning parameters, and cross-checking results. With agent-based orchestration, the same workflow can be compressed to roughly the length of a lunch break. Importantly, this is not “the model replacing scientific judgment”—it is the automation of mechanical, enumerable, and verifiable steps, freeing human attention for hypothesis quality and experimental design.
2. The Core Contradiction: Generation Is Not the Bottleneck—Screening Is
The excitement around AI4S in drug discovery stems from a simple arithmetic problem:
- Combinatorial explosion: The enumerable space of candidate molecules vastly exceeds the throughput of any experimental system; generative models can produce thousands of structures within minutes.
- Limited experimental throughput: Wet-lab cycles are measured in days or even weeks, with high per-unit costs—full validation of every candidate is impossible.
- High clinical failure rates: A significant proportion of clinical candidates fail in later stages due to insufficient efficacy or safety issues, and the cost of failure rises by orders of magnitude as development progresses.
Therefore, what determines the value of AI4S is not “how many molecules can be generated,” but “how low a false-positive rate can be achieved while converging the candidate pool to the few molecules worth wet-lab validation.” This is the purpose of the screening funnel: use cheap prior knowledge to eliminate candidates stage by stage, reserving expensive validation for the most promising few.
3. Reference Architecture: Four Layers
A production-ready AI4S pipeline is best organized into four layers, decoupled through explicit data contracts.
1) Data and Representation Layer
Unify the identifiers and versioning of four entity types: molecules, proteins, genes, and literature. Convert structural formulas, sequences, and pathway relationships into searchable vectors and structured fields. All raw data is append-only—never overwritten—so that any screening result can be traced back to a specific data snapshot.
2) Agent Orchestration Layer
Implement “understand the task → select tools → invoke computation → check results → decide next step” as an explicit state machine, rather than letting the model improvise. The toolset should include deterministic capabilities such as sequence alignment, structural representation computation, pathway enrichment, and literature retrieval. The model is responsible only for planning and interpretation, not numerical computation.
3) Multi-Stage Filtering and Evaluation Layer
Order stages from “lowest cost to highest cost, weakest to strongest confidence,” typically: rule-based and physicochemical property filtering → target relevance and pathway consistency → structural-level alignment → biological plausibility assessment → small-scale wet-lab validation. Every stage must output an interpretable rejection reason.
4) Engineering Foundation Layer
Includes experiment tracking, data versioning, compute scheduling, logging, and monitoring/alerting. This layer is the most easily overlooked, yet it determines whether the pipeline can run reliably over the long term.
4. Illustrative Code: A Pluggable Filtering Chain
The key design principle is making each filter an independent, testable, replaceable component that is forced to record rejection reasons:
from dataclasses import dataclass, field@dataclassclass Candidate:cid: strfeatures: dicthistory: list = field(default_factory=list)class Filter:name = "base"def apply(self, c: Candidate) -> tuple[bool, str]:raise NotImplementedErrorclass PropertyFilter(Filter):name = "physicochemical"def apply(self, c):ok = 0 < c.features.get("logp", 99) < 5return ok, "Physicochemical property out of range" if not ok else "passed"class TargetRelevanceFilter(Filter):name = "target_relevance"def apply(self, c):score = c.features.get("target_score", 0.0)return score >= 0.5, f"target relevance={score:.2f}"def run_funnel(cands, filters, min_survivors=10):pool = list(cands)for f in filters:nxt = []for c in pool:ok, reason = f.apply(c)c.history.append((f.name, ok, reason))if ok:nxt.append(c)pool = nxtif len(pool) < min_survivors:break # Early convergence to avoid wasted computereturn pool
The point of this code is not the algorithm but two things: the filtering chain is pluggable, making it easy to progressively swap in more reliable evaluation models; and every candidate carries a complete rejection trail, making results auditable.
5. Reproducibility and Cost Governance
Scientific scenarios demand stricter reproducibility than typical internet services. At minimum, enforce four constraints:
- Pin all randomness: Random seeds for generation and sampling, model versions, and prompt templates should all be placed under version control.
- Leak-proof data splits: Split by time series or target dimension to prevent data from the same source appearing in both training and evaluation sets—otherwise, offline metrics will be systematically inflated.
- Build a “gold standard” evaluation set: Have domain experts annotate a small, high-confidence sample set for regression testing; run it after any pipeline change to observe how the false-positive rate shifts.
- Cost observability: Record compute consumption and output ratio for every screening run; set budget thresholds through monitoring and alerting to prevent agents from falling into loops of repeated tool calls.
6. Common Pitfalls
- Treating offline metrics as clinical conclusions: The ranking correlation of a predictive model does not equal biological validity—the wet-lab feedback loop must be preserved.
- Letting models do numerical computation: Physicochemical properties, sequence alignment, and the like should be handled by deterministic tools; models should only plan and interpret, otherwise uncontrollable errors creep in.
- One giant funnel: Too many stages without early-convergence mechanisms lets compute costs spiral out of control while returns diminish.
- Ignoring the human in the loop: Experts should review rejection reasons at key checkpoints, not just show up at the final result.
7. Deployment Recommendations
To build this pipeline in your own environment, prioritize general-purpose cloud capabilities: object storage for data snapshots and model artifacts, a container platform for compute tasks and elastic scaling, message queues for task decoupling and load leveling, logging services and monitoring/alerting for observability, and a model serving platform to manage inference capabilities from different sources. Baidu AI Cloud offers capabilities in these general categories that can serve as a reference baseline when selecting your architecture; for specific configurations and quotas, refer to the official documentation.
8. Conclusion
The real barrier in AI4S has never been generation capability—it is the rigor of the screening system. Only by embedding agents into a closed loop of “generate → filter → validate → feedback,” and replacing trust in model intuition with reproducible engineering constraints, can the few candidates that survive from thousands flowing toward the clinic be the ones supported by both data and experiment.
