← Research
Published

Generate molecules in the color you want, screened against EU restriction rules

By

TL;DR

Julian M. Kleber, an independent researcher in Berlin, trained a small molecule generator twice, with and without two control tokens that ask for a color band and for passing an EU rule screen. Over 20,000 molecules each, the share predicted to absorb at 400 to 450 nm rose from 18.7% to 23.7%. All absorption values are surrogate predictions.

chemistrymolecular generationmachine learningpreprint coming soon

What problem does this solve?

A molecule's color depends on which wavelengths of light it absorbs. A dye or an optical sensor usually needs absorption in a specific band. Chemists who use generative models want two things at once: candidates near the target band, and candidates that avoid structures the EU restricts.

The cheapest way to steer a generator is to give it a label during training and ask for that label at generation time. This is called soft conditioning. It costs almost nothing to add. The study asks how much it actually helps, measured against the same model without labels.

Preprint coming soon.

How does the generator work?

The generator is a small language model that writes molecules as SELFIES strings. SELFIES is a text format for molecules in which every string decodes to a molecule, so the model does not waste effort on broken output.

Two versions were trained on the same data, with the same architecture and the same training budget. The plain version learns from the molecules alone. The steered version sees two extra tokens in front of each training molecule. One says whether the molecule's predicted absorption falls in the 400 to 450 nm band. The other says whether it passes the rule screen.

At generation time the steered version is asked for "in band" and "passes the screen". The plain version generates freely. The difference between the two versions is the steering effect.

What does the EU rule screen check?

The screen is a set of substructure patterns for EU restriction rule families, for example patterns that match PFAS. A molecule passes when it matches none of them.

This is a pattern match. It is not a legal or regulatory determination, and a passing molecule is not cleared for any use. The screen only filters and flags. It is never a generation target and never a reward. The work contains no synthesis routes.

How is the color predicted?

A separate surrogate model predicts each molecule's absorption maximum. It turns the structure into an ECFP fingerprint and feeds it to a gradient-boosting regressor trained on a public database of measured optical properties of organic compounds (Joung et al., 2020). On held-out molecules it reaches a mean absolute error of 24.0 nm, a root-mean-square error of 38.2 nm and an R² of 0.873.

An average error of 24.0 nm is about half the width of the 400 to 450 nm band, so any single "in band" call is uncertain. The comparison between the two versions is still fair, because the same surrogate scores both.

What did steering change?

Over 20,000 samples per version and a target band of 400 to 450 nm, the predicted in-band share rose from 18.7% (plain) to 23.7% (steered). That is a gain of 5.0 percentage points, with a 95% bootstrap confidence interval of [4.3, 5.8]. The interval excludes zero.

The rule-screen pass rate rose from 96.4% to 99.9%. Validity, measured as RDKit parse validity, was 1.000 in both versions.

In one sentence: two control tokens raised the predicted in-band share of a small molecule generator from 18.7% to 23.7%, with parse validity unchanged at 1.000.

What are the limits?

The absorption values are surrogate predictions. No molecule from this study was made or measured.

Most molecules still miss the band. Even with steering, fewer than a quarter land in it.

Each version was trained once, with a single seed. The confidence interval covers sampling from fixed weights and says nothing about retraining. Treat the result as exploratory.

Parse-valid is not the same as plausible. About 9% of samples carry radical electrons, so a molecule that parses can still be chemically unrealistic.

One rule family dominates the screen improvement: the PFAS patterns. The steered model mainly learned to avoid that family. The other rule families contribute little to the gain.

Does it need a GPU, and can I use it?

No GPU is needed. The model is small. On 4 CPU threads, generating and scoring 1,000 molecules takes about 1.0 to 1.2 seconds. A request for 100 molecules takes about 0.12 to 0.17 seconds.

A service built on the generator is in preparation. It will be free for academia and startups. Industry from €2 per 1,000 molecules.

The code will be public together with the preprint.

Key terms in plain language

Absorption maximum: the wavelength at which a molecule absorbs the most light. It largely sets the color you see.

Soft conditioning: steering a generative model with labels it saw during training. It shifts the odds and gives no guarantee.

Surrogate model: a fast machine-learning model that predicts a property in place of a lab measurement.

Parse validity: the share of generated strings that a chemistry toolkit (RDKit) can read as a molecule.

PFAS: per- and polyfluoroalkyl substances, a chemical family the EU is moving to restrict.

What comes next?

More target bands across the spectrum, several training seeds, measured spectra for a sampled subset, and a direct comparison of soft conditioning with hard constraints inside the sampler.

Related reading on this site: CARATE, a model that reads molecules as graphs, and Markov models for drug and protein interactions.

Frequently asked questions

Does the screen make the generated molecules legal?

No. The screen is a pattern match against EU restriction rule families. A pass means no listed pattern matched. It is not a legal assessment.

Are the colors measured?

No. A surrogate model trained on measured UV-Vis data predicts them. Its held-out mean absolute error is 24.0 nm.

Does steering guarantee a molecule in the target band?

No. It raised the predicted in-band share from 18.7% to 23.7%. Most samples still fall outside the band.

What does "valid" mean here?

RDKit can parse the molecule. About 9% of samples carry radical electrons, so parse validity does not mean a molecule is plausible.

Do I need a GPU to run it?

No. 1,000 molecules take about 1.0 to 1.2 seconds on 4 CPU threads.

Who did this work?

Julian M. Kleber, an independent researcher in Berlin.

Links

About the author

Julian M. Kleber is a scientist and engineer in Berlin working on chemistry, machine learning and scientific software. ORCID · Google Scholar · LinkedIn · julianmkleber.com

More