Scientific schematics

From ovachiever/droid-tings · View interactive version

Scientific schematics is an AI agent skill from the GitHub repository ovachiever/droid-tings. Create publication-quality scientific diagrams using Nano Banana Pro AI with iterative refinement. AI generation is the default method for all diagram types. Generates high-fidelity images with automatic quality review. Specialized in neural network architectures, system diagrams, flowcharts, biolog

How to use this skill

Skill file

Scientific Schematics and Diagrams

Overview

Scientific schematics and diagrams transform complex concepts into clear visual representations for publication. This skill uses Nano Banana Pro AI for all diagram generation.

How it works:

Simply describe what you want, and Nano Banana Pro creates it. All diagrams are stored in the figures/ subfolder and referenced in papers/posters.

Quick Start: Generate Any Diagram

Create any scientific diagram by simply describing it. Nano Banana Pro handles everything automatically:

# Generate any scientific diagram from a description
python scripts/generate_schematic.py "CONSORT participant flow diagram with 500 screened, 150 excluded, 350 randomized" -o figures/consort.png

# Neural network architecture
python scripts/generate_schematic.py "Transformer encoder-decoder architecture showing multi-head attention, feed-forward layers, and residual connections" -o figures/transformer.png

# Biological pathway
python scripts/generate_schematic.py "MAPK signaling pathway from EGFR to gene transcription" -o figures/mapk_pathway.png

# Custom iterations for complex diagrams
python scripts/generate_schematic.py "Complex circuit diagram with op-amp, resistors, and capacitors" -o figures/circuit.png --iterations 5

What happens behind the scenes:

  1. Generation 1: Nano Banana Pro creates initial image following scientific diagram best practices
  2. Review 1: AI evaluates clarity, labels, accuracy, and accessibility
  3. Generation 2: Improved prompt based on critique, regenerate
  4. Review 2: Second evaluation with specific feedback
  5. Generation 3: Final polished version addressing all critiques

Output: Three versions (v1, v2, v3) plus a detailed review log with quality scores and critiques.

Configuration

Set your OpenRouter API key:

export OPENROUTER_API_KEY='your_api_key_here'

Get an API key at: https://openrouter.ai/keys

AI Generation Best Practices

Effective Prompts for Scientific Diagrams:

✓ Good prompts (specific, detailed):

✗ Avoid vague prompts:

Key elements to include:

Scientific Quality Guidelines (automatically applied):

Classic Code-Based Generation

For reproducible, version-controlled diagrams with full programmatic control, use the traditional code-based approach.

When to Use This Skill

This skill should be used when:

How to Use This Skill

Simply describe your diagram in natural language. Nano Banana Pro generates it automatically:

python scripts/generate_schematic.py "your diagram description" -o output.png

That's it! The AI handles:

Works for all diagram types:

No coding, no templates, no manual drawing required.


AI Generation Mode (Nano Banana Pro)

Iterative Refinement Workflow

The AI generation system uses a sophisticated three-iteration refinement process:

Iteration 1: Initial Generation

Prompt Construction:

Scientific diagram guidelines + User request

Example internal prompt:

Create a high-quality scientific diagram with:
- Clean white background
- High contrast for readability
- Clear labels (minimum 10pt font)
- Professional typography
- Colorblind-friendly colors
- Proper spacing

USER REQUEST: CONSORT participant flow diagram showing screening, 
exclusion, randomization, and analysis phases with participant counts

Output: diagram_v1.png

Iteration 2: Review and Improve

AI Quality Review:

Example critique:

Score: 7/10

Strengths:
- Clear flow from top to bottom
- Good use of colors
- All phases labeled

Issues:
- Participant counts (n=X) are too small to read
- "Excluded" box overlaps with arrow
- Would benefit from reasons for exclusion

Suggestions:
- Increase font size for all numbers to at least 12pt
- Add more vertical spacing between boxes
- Include exclusion criteria in a separate annotation box

Improved Prompt:

[Original guidelines + user request]

ITERATION 2: Address these improvements:
- Increase font size for participant counts to 12pt minimum
- Add vertical spacing to prevent overlaps
- Include exclusion criteria in annotation box

Output: diagram_v2.png

Iteration 3: Final Polish

Second Review:

Final Generation:

Output: diagram_v3.png (final version)

Review Log

All iterations are saved with a JSON review log:

{
  "user_prompt": "CONSORT participant flow diagram...",
  "iterations": [
    {
      "iteration": 1,
      "image_path": "figures/consort_v1.png",
      "score": 7.0,
      "critique": "..."
    },
    {
      "iteration": 2,
      "image_path": "figures/consort_v2.png",
      "score": 8.5,
      "critique": "..."
    },
    {
      "iteration": 3,
      "image_path": "figures/consort_v3.png",
      "score": 9.5,
      "critique": "..."
    }
  ],
  "final_score": 9.5
}

Advanced AI Generation Usage

Python API

from scripts.generate_schematic_ai import ScientificSchematicGenerator

# Initialize generator
generator = ScientificSchematicGenerator(
    api_key="your_openrouter_key",
    verbose=True
)

# Generate with iterative refinement
results = generator.generate_iterative(
    user_prompt="Transformer architecture diagram",
    output_path="figures/transformer.png",
    iterations=3
)

# Access results
print(f"Final score: {results['final_score']}/10")
print(f"Final image: {results['final_image']}")

# Review individual iterations
for iteration in results['iterations']:
    print(f"Iteration {iteration['iteration']}: {iteration['score']}/10")
    print(f"Critique: {iteration['critique']}")

Command-Line Options

# Basic usage
python scripts/generate_schematic.py "diagram description" -o output.png

# Custom iterations (1-10)
python scripts/generate_schematic.py "complex diagram" -o diagram.png --iterations 5

# Verbose output (see all API calls and reviews)
python scripts/generate_schematic.py "flowchart" -o flow.png -v

# Provide API key via flag
python scripts/generate_schematic.py "diagram" -o out.png --api-key "sk-or-v1-..."

Prompt Engineering Tips

1. Be Specific About Layout:

✓ "Flowchart with vertical flow, top to bottom"
✓ "Architecture diagram with encoder on left, decoder on right"
✓ "Circular pathway diagram with clockwise flow"

2. Include Quantitative Details:

✓ "Neural network with input layer (784 nodes), hidden layer (128 nodes), output (10 nodes)"
✓ "Flowchart showing n=500 screened, n=150 excluded, n=350 randomized"
✓ "Circuit with 1kΩ resistor, 10µF capacitor, 5V source"

3. Specify Visual Style:

✓ "Minimalist block diagram with clean lines"
✓ "Detailed biological pathway with protein structures"
✓ "Technical schematic with engineering notation"

4. Request Specific Labels:

✓ "Label all arrows with activation/inhibition"
✓ "Include layer dimensions in each box"
✓ "Show time progression with timestamps"

5. Mention Color Requirements:

✓ "Use colorblind-friendly colors"
✓ "Grayscale-compatible design"
✓ "Color-code by function: blue for input, green for processing, red for output"

AI Generation Examples

Example 1: CONSORT Flowchart

python scripts/generate_schematic.py \
  "CONSORT participant flow diagram for randomized controlled trial. \
   Start with 'Assessed for eligibility (n=500)' at top. \
   Show 'Excluded (n=150)' with reasons: age<18 (n=80), declined (n=50), other (n=20). \
   Then 'Randomized (n=350)' splits into two arms: \
   'Treatment group (n=175)' and 'Control group (n=175)'. \
   Each arm shows 'Lost to follow-up' (n=15 and n=10). \
   End with 'Analyzed' (n=160 and n=165). \
   Use blue boxes for process steps, orange for exclusion, green for final analysis." \
  -o figures/consort.png

Example 2: Neural Network Architecture

python scripts/generate_schematic.py \
  "Transformer encoder-decoder architecture diagram. \
   Left side: Encoder stack with input embedding, positional encoding, \
   multi-head self-attention, add & norm, feed-forward, add & norm. \
   Right side: Decoder stack with output embedding, positional encoding, \
   masked self-attention, add & norm, cross-attention (receiving from encoder), \
   add & norm, feed-forward, add & norm, linear & softmax. \
   Show cross-attention connection from encoder to decoder with dashed line. \
   Use light blue for encoder, light red for decoder. \
   Label all components clearly." \
  -o figures/transformer.png --iterations 3

Example 3: Biological Pathway

python scripts/generate_schematic.py \
  "MAPK signaling pathway diagram. \
   Start with EGFR receptor at cell membrane (top). \
   Arrow down to RAS (with GTP label). \
   Arrow to RAF kinase. \
   Arrow to MEK kinase. \
   Arrow to ERK kinase. \
   Final arrow to nucleus showing gene transcription. \
   Label each arrow with 'phosphorylation' or 'activation'. \
   Use rounded rectangles for proteins, different colors for each. \
   Include membrane boundary line at top." \
  -o figures/mapk_pathway.png

Example 4: System Architecture

python scripts/generate_schematic.py \
  "IoT system architecture block diagram. \
   Bottom layer: Sensors (temperature, humidity, motion) in green boxes. \
   Middle layer: Microcontroller (ESP32) in blue box. \
   Connections to WiFi module (orange box) and Display (purple box). \
   Top layer: Cloud server (gray box) connected to mobile app (light blue box). \
   Show data flow arrows between all components. \
   Label connections with protocols: I2C, UART, WiFi, HTTPS." \
  -o figures/iot_architecture.png

Additional Tools

TikZ Compilation (compile_tikz.py)

If you have existing TikZ .tex files that need compilation:

# Compile TikZ diagram to PDF
python scripts/compile_tikz.py diagram.tex -o diagram.pdf

# Compile and generate PNG
python scripts/compile_tikz.py diagram.tex --png --dpi 300

# Compile and preview
python scripts/compile_tikz.py diagram.tex --preview

For details on using compile_tikz.py, run:

python scripts/compile_tikz.py --help

Unified Entry Point: generate_schematic.py

The main entry point supports both AI and code-based generation:

# AI generation (default)
python scripts/generate_schematic.py "diagram description" -o output.png

# Explicit AI method
python scripts/generate_schematic.py "diagram description" -o output.png --method ai

# Code-based generation
python scripts/generate_schematic.py "1. Step one\n2. Step two" -o flow.tex --method code --type flowchart

# Custom iterations for AI
python scripts/generate_schematic.py "complex diagram" -o diagram.png --iterations 5

# Verbose mode
python scripts/generate_schematic.py "diagram" -o out.png -v

Method Selection:

Code-Based Types:

Helper Scripts

`compile_tikz.py`

Standalone TikZ compilation utility with quality checks:

# Compile TikZ to PDF with verification
python scripts/compile_tikz.py flowchart.tex -o flowchart.pdf --verify

# Generate PNG with quality report
python scripts/compile_tikz.py flowchart.tex -o flowchart.pdf --png --dpi 300 --verify

# Preview with quality overlay
python scripts/compile_tikz.py flowchart.tex --preview --show-quality

Note: The Nano Banana Pro AI generation system includes automatic quality review in its iterative refinement process. Each iteration is evaluated for scientific accuracy, clarity, and accessibility.

Best Practices Summary

Design Principles

  1. Clarity over complexity - Simplify, remove unnecessary elements
  2. Consistent styling - Use templates and style files
  3. Colorblind accessibility - Use Okabe-Ito palette, redundant encoding
  4. Appropriate typography - Sans-serif fonts, minimum 7-8 pt
  5. Vector format - Always use PDF/SVG for publication

Technical Requirements

  1. Resolution - Vector preferred, or 300+ DPI for raster
  2. File format - PDF for LaTeX, SVG for web, PNG as fallback
  3. Color space - RGB for digital, CMYK for print (convert if needed)
  4. Line weights - Minimum 0.5 pt, typical 1-2 pt
  5. Text size - 7-8 pt minimum at final size

Integration Guidelines

  1. Include in LaTeX - Use \input{} for TikZ, \includegraphics{} for external
  2. Caption thoroughly - Describe all elements and abbreviations
  3. Reference in text - Explain diagram in narrative flow
  4. Maintain consistency - Same style across all figures in paper
  5. Version control - Keep source files (.tex, .py) in repository

Troubleshooting Common Issues

TikZ Compilation Errors

Problem: ! Package tikz Error: I do not know the key '/tikz/...

Problem: Overlapping text or elements

Problem: Arrows not connecting properly

Python Generation Issues

Problem: Schemdraw elements not aligning

Problem: Matplotlib text rendering issues

Problem: Export quality poor

Problem: Elements overlap after generation

Quality Check Issues

Problem: False positive overlap detection

Problem: Generated image quality is low

Problem: Colorblind simulation shows poor contrast

Problem: High-severity overlaps detected

Problem: Visual report generation fails

Accessibility Problems

Problem: Colors indistinguishable in grayscale

Problem: Text too small when printed

Problem: Accessibility checks consistently fail

Resources and References

Detailed References

Load these files for comprehensive information on specific topics:

External Resources

TikZ and LaTeX

Python Libraries

Publication Standards

Integration with Other Skills

This skill works synergistically with:

Quick Reference Checklist

Before submitting diagrams, verify:

Visual Quality

Accessibility

Typography and Readability

Publication Standards

Quality Verification (Required)

Documentation and Version Control

Final Integration Check

Summary: AI vs Code-Based Generation

Quick Decision Guide

Choose AI Generation (Nano Banana Pro) if:

Choose Code-Based Generation if:

Workflow Comparison

| Aspect | AI Generation | Code-Based |

|--------|---------------|------------|

| Time to first result | 2-3 minutes | 15-30 minutes |

| Iterations | Automatic (3 rounds) | Manual |

| Quality review | Automatic by AI | Manual or scripted |

| Customization | Natural language | Full programmatic control |

| Reproducibility | Prompt-based | Code-based (exact) |

| Learning curve | Low (just describe) | Medium-High (learn libraries) |

| Output format | PNG/JPG | PDF/SVG/EPS/PNG |

| Version control | Prompt + images | Source code + outputs |

| Best for | Quick iteration, complex visuals | Reproducible research, data-driven |

Hybrid Approach (Recommended)

Many users find success with a hybrid workflow:

  1. Prototype with AI: Generate initial designs quickly using natural language
  2. Review and refine: Use the AI's iterative refinement to get close to final
  3. Recreate in code (optional): If exact reproducibility is needed, recreate the approved design in code
  4. Version control: Keep both the AI prompts and code versions

Environment Setup

For AI Generation:

# Required
export OPENROUTER_API_KEY='your_api_key_here'

# Get key at: https://openrouter.ai/keys

For Code-Based Generation:

# Install Graphviz
brew install graphviz  # macOS
sudo apt-get install graphviz  # Linux

# Install Python packages
pip install graphviz schemdraw networkx matplotlib

Getting Started

Simplest possible usage (AI):

python scripts/generate_schematic.py "your diagram description" -o output.png

Simplest possible usage (Code):

python scripts/generate_schematic.py "1. Step one\n2. Step two" -o flow.tex --method code

Use this skill to create clear, accessible, publication-quality diagrams that effectively communicate complex scientific concepts. The AI-powered workflow with iterative refinement ensures diagrams meet professional standards, while the code-based approach provides exact reproducibility for research publications.

Use this skill with your AI agent: Open on Skill Issue to copy, download, or add to your library. Works with Claude, ChatGPT, Gemini, Cursor, Windsurf and more.