Skip to content

Adding new generate_recipes command to generate recipes from a template recipe .json and design matrix .csv - #156

Open
BenEmeryCMD wants to merge 5 commits into
masterfrom
besandbox
Open

Adding new generate_recipes command to generate recipes from a template recipe .json and design matrix .csv#156
BenEmeryCMD wants to merge 5 commits into
masterfrom
besandbox

Conversation

@BenEmeryCMD

Copy link
Copy Markdown
Collaborator

Summary

This PR improves the Recipe Generator workflow by enabling direct export of generated recipes as JSON files and updating the generated recipe schema to be compatible with CAR recipe upload requirements.

Previously, recipes generated via the Recipe Generator were only returned to the shell as Python dictionaries, requiring manual copy/paste before they could be saved or imported into CAR. This PR adds an export pathway and aligns the generated output with the format expected by CAR.

Changes

Recipe JSON export

  • Added support for writing generated recipes directly to .json files.
  • Added a helper function to save generated recipe dictionaries to disk.
  • Added optional output_dir support to recipe generation methods.
  • Generated recipes continue to be returned as Python dictionaries to preserve existing behaviour.

Command-line recipe generation

  • Added a Django management command:
python3 manage.py generate_recipes <template.json> <design_matrix.csv> -o <output_directory>

This allows recipe generation to be performed from the command line without manually running Python code in a shell.

CAR schema compatibility

Updated generated recipe output to better match the schema expected by CAR:

  • Added top-level reaction_class field.
  • Retrieved reaction_class automatically from the base recipe definition.
  • Renamed sessionsaction_sessions.
  • Removed nested recipe wrapper and flattened recipe contents into the top-level output structure.
  • Renamed action field equivalentsamount.

Example

Previous output

{
  "name": "BE_Urea_1",
  "template": "260423_BE_Urea_screen_1",
  "base": "Urea formation.standard",
  "recipe": {
    "estimated_yield": 100,
    "sessions": [...]
  }
}

New output

{
  "reaction_class": "Urea formation",
  "name": "BE_Urea_1",
  "template": "260423_BE_Urea_screen_1",
  "base": "Urea formation.standard",
  "estimated_yield": 100,
  "reaction_smarts": [...],
  "action_sessions": [...]
}

Motivation

This change removes the need for manual copy/paste of generated recipes and allows recipes produced by the Recipe Generator to be imported directly into CAR with minimal or no post-processing.

Testing

Tested using existing validated recipe templates and design matrices.

Verified that:

  • Recipe generation still succeeds from templates and CSV design matrices.
  • JSON files are written successfully to the specified output directory.
  • Generated recipes contain the expected reaction_class.
  • Generated recipes use action_sessions rather than sessions.
  • Generated recipes use amount rather than equivalents.
  • Generated recipes can be loaded into CAR successfully.

P.S.

Removed "." from enamine real tools script to fix import issues.

@BenEmeryCMD
BenEmeryCMD requested a review from Waztom June 5, 2026 20:32
@Waztom

Waztom commented Jun 8, 2026

Copy link
Copy Markdown
Owner

@BenEmeryCMD this is awesome, and thanks for requesting your very first pull request for CAR!

Can you please:

  1. Run the tests locally - see here for more info
  2. Click through the CI (continuous integration) red crosses above to review what the errors need to be addressed
  3. Re tests failing, you might need to change the way the recipe tests are ingesting the data with your latest changes, the point is that it's OK to change the tests if the input data doesn't match!
  4. A small thing, but please remove and commented code. If you'd like to keep the commented code, please make it clear in a comment why it needs to stay.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants