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
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.
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.
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.
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.
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:
- Build the rule — the rule as blocks (the molecule-level property, and atoms with their bonds), with any auxiliary predicates unfolded into their definitions. A generated predicate you add yourself from the palette stays a single chip; its ⊞ button unfolds it into atoms and bonds too. A pattern the molecule must not contain sits in a red not box, and a pattern that has to occur a certain number of times sits in a purple count box.
- What the rule asks for — a picture of the pattern the rule looks for, with a short sentence.
- The confusion counts (TP, TN, FP, FN) and the list of molecules not classified as told. A false positive (FP) is a negative example the rule marks positive; a false negative (FN) is the reverse. Every molecule has a ? button on its card (grey if the rule rejects it).
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.
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.
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.
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.