Tutorial: learn a chemical rule from examples

ICaRuS learns a logical rule for a chemical concept (for example "carboxylic acid") from molecules you label as positive or negative. You start from a ChEBI class or from SMILES / InChI strings, let ICaRuS suggest more molecules and learn a rule with an ILP system (Popper or Aleph) or with an LLM (Claude Haiku 5.5). Then, you can inspect, edit and compare the rules. This tutorial walks through one complete session on the Learn page. The About page explains some additional background. The source code is available on GitHub.

Contents

  1. Seed the examples from a ChEBI class
  2. Sort and add examples
  3. Label suggested molecules
  4. Learn a rule and read the result
  5. Edit the rule and apply it
  6. Add examples and learn again
  7. Compare rules in the history

1 · Seed the examples from a ChEBI class

Type a ChEBI class name or ID into the search bar, for example carboxylic acid. Pick a class from the list. Set how many positive and negative molecules to take (default 8 each) and click Fill examples.

The positives are small molecules below the class in ChEBI, and the negatives are molecules close to the class in the hierarchy that are not part of it. Only concrete molecules are used; generic class structures with wildcard atoms are skipped.

Class search with 'carboxylic acid' selected
Searching for a ChEBI class and selecting it.
Positive and negative example grids after filling from the class
After Fill examples: eight positive (green) and eight negative (red) molecules.

2 · Sort and add examples

Each molecule card shows its 2D structure. Click a card to open its details: a zoomable structure, the ChEBI ID, SMILES, InChI and definition. In the details you can move the molecule to the other column or remove it.

Molecule details dialog with move and remove buttons
The molecule details dialog, with move and remove actions.

To add your own molecules, paste SMILES or InChI into the text box of a column, one per line, and click Add + (positive) or Add − (negative). Here, two negatives (ethanol and ethyl acetate) were added.

Example grids after adding SMILES strings
The example grids after adding molecules by SMILES.

3 · Label suggested molecules

If you need more examples, click Find similar molecules. ICaRuS looks for ChEBI molecules similar to your positives (Morgan fingerprints) and shows them one at a time. Each card shows the similarity score, the structure, the name, the ChEBI ID and the definition.

Use ← + Positive or − Negative → to label the current molecule, or Skip to pass on it. You can also swipe or drag the card: left for positive, right for negative. The counter (for example 3 / 6) shows your position in the batch. Once a rule exists, each card also shows what the rule predicts, so you can confirm or contradict it.

Suggestion section after labelling two molecules
The suggestion section after two labels. The batch continues until its molecules are used up.

4 · Learn a rule and read the result

In Learn a rule, choose a method and click Learn rule. The method dropdown offers Popper (ILP) and Aleph (ILP), both of which run on the ICaRuS server; the timeout (default 60 seconds) limits the ILP search. Popper tolerates noise and returns the best rule it finds, while Aleph looks for a rule that separates the examples cleanly.

The LLM option sends the concept name and its definition to a language model (Claude Haiku 5.5), which writes the rule. When you seeded from a ChEBI class, the Concept definition box shows the ChEBI definition, and you can edit it before learning. If the rule library already has a rule for the class, that rule is shown first, and Prompt the LLM asks the model for a fresh one. Both the ILP learners and the LLM have access to a library of LLM-generated chemical concepts that they can use as building blocks for new definitions. Under Settings you choose which library predicates the learner may use: generated predicates (aux) and functional groups (EFG). In this session the functional groups were switched off, so Popper built the rule from a generated predicate, which the editor can show atom by atom. (With functional groups on, Popper picks the ready-made Carboxylic acids group instead.)

When the run finishes, the rule appears below, with a result summary. The result shows:

Learned rule with block editor, rule explanation, confusion counts and mismatches
The learned rule: an O=C–OH or S=C–OH group, as two OR alternatives. All examples are classified as told.

Click ? on a molecule to see why the rule accepts or rejects it. For an accepted molecule, the explanation highlights the atoms that match the rule. For a rejected one, it highlights the closest match and marks where it fails.

Explanation dialog for why the rule accepts a molecule
The explanation for a positive prediction.

5 · Edit the rule and apply it

You can change the rule in two ways. Drag blocks from the palette onto the molecule or an atom in the Rule canvas, or open Logic program and edit the text directly. Edited Prolog is parsed back into blocks when you click away.

+ not box and + count box add a box to the canvas. Drag atoms into a box (or drop atom properties onto it) to build its pattern. Bonds may connect atoms in a box to atoms outside it. A not box means the molecule has no match of its pattern. A count box sets how many matches there must be (exactly, at least, at most, …). It counts the different atoms marked #, so with a counted carbon and an unmarked oxygen it counts carbons that have such an oxygen. For molecule-level properties, + not in the Whole molecule strip adds a not box there, and ¬ on an atom's property negates just that property. The logic program also lists the auxiliary predicates the rule defines (LLM-generated helpers that summarize chemical subconcepts), as written, and they can be edited there too.

In this session the edit added a not box with a nitrogen atom to both alternatives: the molecule must not contain any nitrogen. Click Apply edited rule to run the edited rule. Its result becomes a new entry in the history, and ICaRuS lists every classification that changed.

Rule area after applying an edit, showing new confusion counts and changed classifications
After applying the edit: glycine and glycine-d5 contain nitrogen, so the rule now rejects them (two false negatives).

Revert edits discards unsaved changes and restores the selected rule.

6 · Add examples and learn again

A rule is only as good as its examples. Use the steps above to improve them: add SMILES, move molecules between the columns, remove doubtful ones, or label more suggestions.

In this session benzoic acid (positive) and hexane (negative) were added by SMILES, and then Learn rule was clicked again. Each learning run adds a new entry to the history and makes it the selected rule. The result depends on the examples, so the learner can return a different rule than before. Here it returned the same rule, which also classifies the two new molecules correctly.

Rule area after learning again with more examples
The rule after the second learning run.

7 · Compare rules in the history

Every learned or edited rule is kept. Click ▸ Show rule history (n) to list them, newest first. Each entry shows its origin (POPPER or EDITED), its age, the rule, and its confusion counts. The selected rule is marked ● selected.

Click Select on another entry to make it the current, editable rule. Selecting does not learn anything new. When the examples change, an entry is marked ⚠ examples changed since — re-evaluate, because its counts refer to the old examples. The Re-evaluate all button then recomputes all counts against the current examples.

Rule history list with three entries
The rule history, newest first: the new learned rule (selected), the edited rule, and the first learned rule. The last two are marked as stale.
Rule history after re-evaluating all entries
After Re-evaluate all, the counts match the current examples.