ADMET Optimizer

This guide walks through the molcube.admet_optimizer.AdmetOptimizerProject workflow. Unlike ADMET Predictor, which only scores molecules that already exist, this module generates new ones: starting from a scaffold with * attachment points, REINVENT4 (LibINVENT) grows substituents, ADMET-AI filters and scores each candidate, and AiZynthFinder can optionally check whether a route to synthesize it exists — all as one GPU job.

Setup

Import the client and authenticate before calling any project methods:

import molcube as mc

molcube = mc.API("api.molcube.com", 443)
molcube.authenticate(api_token="<your-api-token>")

Create one project helper instance and reuse it throughout the workflow:

opt = molcube.create_admet_optimizer_project()

If you already have a submitted project id – e.g. one created interactively in MolCube Apps – resume it with resume_project() instead of creating a new one:

opt = molcube.create_admet_optimizer_project()
opt.resume_project("submitted-admet-optimizer-project-id")

opt.get_step()   # 1 while running/not started, 2 once results are available

This re-hydrates scaffold_smiles/reference_smiles and the reinvent/admet/synthesis blocks from what the server has stored, so resubmit() and best_molecules() keep working correctly on a resumed project rather than acting on empty state. One exception: a project’s admet targets cannot be recovered if it was submitted before endpoint names moved into a list (older than this SDK version) – pass optimize explicitly on the first resubmit() call for such a project to repopulate it. Resuming also clears any results this AdmetOptimizerProject instance had cached locally, so it is safe to reuse one object across several projects one after another.

Step 1. Scaffold Input

create_project() accepts the scaffold two ways. Use exactly one.

Already-cut scaffold and reference

Pass scaffold_smiles (with one or more * attachment points) and reference_smiles (the full “mother” molecule, used as the ADMET baseline) directly:

scaffold_smiles = "*c1ccc2ncnc(N*)c2c1"
reference_smiles = "COc1cc2ncnc(Nc3ccc(F)c(Cl)c3)c2cc1OCCCN1CCOCC1"

Full molecule + core pattern

If you only have the full molecule and want to cut a scaffold out of it — the equivalent of selecting a region in the web app’s Ketcher editor — pass full_smiles and core instead, and let create_project() run extract_scaffold() for you. core defaults to a SMARTS pattern matched against the full molecule; it also accepts a SMILES fragment or a molblock via core_format:

full_smiles = "COc1cc2ncnc(Nc3ccc(F)c(Cl)c3)c2cc1OCCCN1CCOCC1"
core = "c1ncnc2ccccc12"  # SMARTS by default

Calling extract_scaffold() directly first — instead of leaving it to create_project() — lets you inspect the cut before submitting:

extraction = opt.extract_scaffold(full_smiles, core)
extraction["scaffold_smiles"]
extraction["reference_smiles"]
extraction["attachment_points"]

Note

By default, a core pattern that does not match the full molecule raises a ValueError immediately (raise_on_warning=True). The server itself would otherwise accept the mismatch as a 200 response with a warning and zero attachment points — a scaffold the GPU job rejects anyway, just much later. Pass raise_on_warning=False to get that unmatched result back instead of raising.

Step 2. Configure the Optimization

ADMET targets

optimize is required and takes either a list of endpoint names or a dict mapping endpoint names to a direction. Endpoints from the built-in catalog (molcube.admet_optimizer.ENDPOINT_CATALOG, 15 well-known ADMET-AI endpoints such as Caco2_Wang or hERG) get their direction and filter strategy filled in automatically; endpoints outside the catalog need a direction stated explicitly:

from molcube.admet_optimizer import ENDPOINT_CATALOG

ENDPOINT_CATALOG.keys()          # every endpoint with a built-in default
ENDPOINT_CATALOG["Caco2_Wang"]   # {'label': ..., 'group': ..., 'default_direction': ...}

# List form -- direction/filter_strategy auto-filled from the catalog
optimize = ["Caco2_Wang", "hERG"]

# Dict form -- states direction explicitly
optimize = {"Caco2_Wang": "higher_is_better", "hERG": "lower_is_better"}

Every name, catalog or not, must be one of the server’s 49 canonical ADMET-AI column names – anything else is rejected locally (as a ValueError) before it would reach the server as a failed request. See molcube.admet_optimizer.AdmetEndpoint for the full list, or check a name against molcube.admet_optimizer.ADMET_ENDPOINT_NAMES directly:

from molcube.admet_optimizer import ADMET_ENDPOINT_NAMES

"QED" in ADMET_ENDPOINT_NAMES   # True -- valid, just outside the 15-entry catalog

Use filter_strategy to control whether a candidate failing an endpoint’s constraint is dropped ("must", the default for auto-filled endpoints) or just reported ("optional"):

filter_strategy = {"Caco2_Wang": "must", "hERG": "optional"}

Note

Setting every optimized endpoint’s filter_strategy to "must" can filter out every generated candidate, which fails the project with no results to read at all. If a run comes back with nothing, loosen one or more endpoints to "optional" or raise n_compounds before resubmitting.

Generation parameters

  • n_compounds (int): Molecules generated per batch. Defaults to 10.

  • max_iterations (int): REINVENT4 iterations. Defaults to 5.

  • batch_size (int): REINVENT4 batch size. Defaults to 50.

Retrosynthesis (SDK only)

Score generated candidates with AiZynthFinder by passing run_synthesis=True. The web app currently has this section commented out entirely — the SDK is the only way to use it:

run_synthesis = True
max_synthesis_steps = 4          # defaults to 4
keep_synthesizable_only = False  # defaults to False
nproc = 4                        # defaults to 4

Step 3. Submit

Call create_project() with the pieces from Step 1 and Step 2. It blocks until the GPU job finishes. Use assert so the notebook stops immediately if submission fails:

assert opt.create_project(
    title="EGFR hinge-binder optimization",
    scaffold_smiles=scaffold_smiles,
    reference_smiles=reference_smiles,
    n_compounds=30,
    optimize=["Caco2_Wang", "hERG"],
)

Returns True only once the optimization has completed and the project is confirmed to have reached its final step — a clean progress bar alone does not guarantee a result exists (see the method’s docstring for why).

Change settings and rerun with resubmit(). Every argument is optional; anything omitted keeps its current value — including within the optimize/direction/filter_strategy and retrosynthesis settings, which are always resent whole rather than merged piecemeal:

assert opt.resubmit(n_compounds=50)

Cancel a running job with stop_project():

opt.stop_project()

Before submitting, inspect the current local state or preview the exact payload that will be sent:

opt.get_state()
opt.preview_payload()

Step 4. Check Status

get_step() returns 1 while the optimization is running or has not started, and 2 once results are available:

opt.get_step()

Step 5. Read Results

get_results() fetches and caches the full result payload; every accessor below reads from that cache without contacting the server again:

opt.get_results()

opt.get_reference_molecule()     # the mother molecule this run started from
opt.get_generated_molecules()    # compact table of every generated candidate

molecule = opt.get_generated_molecules()[0]
opt.get_molecule(molecule["smiles"])          # full record: predictions + synthesis
opt.get_predictions(molecule["smiles"])        # ADMET endpoint -> predicted value
opt.get_synthesis_route(molecule["smiles"])    # AiZynthFinder route, if run_synthesis was on

opt.get_column_description()     # human-readable description per ADMET endpoint

Molecules have no numeric id — every accessor above looks a candidate up by its SMILES, exactly as it appears in get_results().

Three keys in get_predictions()’s result are bookkeeping, not ADMET endpoints: passed (whether the candidate cleared every "must" endpoint – failing only "optional" ones still counts as passed), failedColumns (which endpoints it failed, if any), and nSoftViolations (how many "optional" endpoints it failed). passed is None on the reference row.

Step 6. Bulk Comparison

The web app shows one candidate at a time behind a paginated list, which makes comparing the whole generated library impractical. get_dataframe() lays the same data out as a molecules-by-endpoints table instead:

df = opt.get_dataframe()
df = opt.get_dataframe(endpoints=["Caco2_Wang", "hERG"])

Endpoint names may be given in either the original ADMET-AI spelling (Caco2_Wang) or the API’s mangled camelCase form (Caco2Wang) — both resolve to the same column. Calling get_dataframe() with no endpoints argument includes every key present across all molecules’ predictions, which means the passed/failedColumns/nSoftViolations bookkeeping columns from Step 5 show up as columns too, mixed in with the real ADMET values — pass an explicit endpoints list to exclude them.

Use best_molecules() to rank generated candidates by a single endpoint. The reference molecule is always excluded, since it is the baseline rather than a candidate to rank:

opt.best_molecules("Caco2_Wang", top_n=5)

By default, ranking direction is inferred from how this project submitted that endpoint (a "lower_is_better" endpoint ranks its lowest values first); pass ascending explicitly to override it.

Step 7. Download Outputs

Download the full project archive with download_project():

opt.download_project()

When output_path is omitted, the archive is saved to the current directory as <projectId>.tar.gz. Calling this before the project reaches step 2 raises a ValueError rather than the unhandled server error an early call would otherwise hit.