Crystal design structure crossover agent

From pdl-openair/OpenAIR · View interactive version

Crystal design structure crossover agent is an AI agent skill from the GitHub repository pdl-openair/OpenAIR. Agent-guided multi-objective evolutionary search for inorganic crystals. Use when the user wants to discover / optimize / evolve crystal structures toward materials goals (e.g. "find a stable lead-free wide-bandgap oxide", "evolve hard materials maximizing bulk modulus", "search for low-ehull high-d

How to use this skill

Skill file

crystal-design-structure-crossover-agent — agent-guided evolutionary crystal search

Orchestrate a multi-objective evolutionary search over the deployed material MCPs. You (Claude) are the evolutionary strategist: translate the user's goal into objectives/constraints, drive the loop one generation at a time, read each generation's snapshot, and adaptively steer (ban elements, tighten constraints, raise mutation strength, push diversity). The deterministic loop + selection code lives in scripts/ and runs in-container; you call it per step.

What runs where (read this first)

The driver invocation (every subcommand uses this wrapper)

bash <SKILL>/scripts/run.sh <subcommand> --run-dir <RUN_DIR> ...

<SKILL> is the absolute path to this skill directory in whatever repo it's synced into (e.g. .claude/skills/crystal-design-structure-crossover-agent after sync_claude_skills.py, or skills/materials/crystal-design-structure-crossover-agent in source). run.sh runs evolve_driver.py with a host Python that has pymatgen (no docker, no mounts by default). <RUN_DIR> (e.g. outputs/evo_widegap) holds config.json, constraints.json, population.json, per-gen snapshots, and final leaderboard.csv + pareto/. Because it's host-side, seed CIF paths and --run-dir can be any host path — no mount gymnastics. If no venv has pymatgen, run.sh falls back to $EVOLVE_IMAGE Docker image (then --run-dir must be under your cwd so it can be mounted).

The flow

Step 0 — Pre-flight. Confirm the required MCPs are up (curl each /mcp handshake, see references/runtime-topology.md). Translate the user's NL goal → objectives + constraints using references/property-keys.md and references/objective-constraint-schema.md. Pick --fitness-backend (alignn default for multi-property; mattersim for energy-only stability-proxy), then RUN_DIR, pop-size, max-generations, noise-level, and --crossover-rate (0=pure mutation, 0.5=half/half — recommended when the seed pool is narrow).

Step 1 — init. Build + characterize the initial pool (seed CIFs via --seed-cifs — any host path now works, and/or --generate N for mattergen-generate). Show the user the generation-0 Pareto front and confirm the config before evolving further.

# Default alignn backend (multi-property objectives)
bash <SKILL>/scripts/run.sh init --run-dir <RUN_DIR> \
    --fitness-backend alignn \
    --objectives '{"ehull":"minimize","bandgap":"maximize"}' \
    --constraints '{"bandgap":{"min":0.5,"max":3.0,"weight":10},"element_set":{"banned":["Pb"]}}' \
    --pop-size 20 --max-generations 30 --noise-level 0.3 --crossover-rate 0.5 \
    --seed-cifs /path/to/AlInSe3.cif,/path/to/b.cif --generate 15

# mattersim backend (energy-only stability proxy under fixed composition)
bash <SKILL>/scripts/run.sh init --run-dir <RUN_DIR> \
    --fitness-backend mattersim \
    --objectives '{"energy_per_atom":"minimize"}' \
    --constraints '{"element_set":{"allowed_only":["Si","O"],"weight":10},"sg_number":{"allowed_only":[148,227]}}' \
    --pop-size 20 --max-generations 30 --noise-level 0.3 \
    --seed-cifs /path/to/seed_SiO2.cif

(<SKILL> = the absolute path to this skill directory, see "The driver invocation" above.)

Step 2 — evolve loop (you steer each generation). Repeat until max-generations:

  1. bash <SKILL>/scripts/run.sh step --run-dir <RUN_DIR> → produces offspring (diffusion-mutate: mutation and/or crossover), characterizes (relax+alignn), runs SAES environmental selection, writes snapshot_gen<N>.json.
  2. Read snapshot_latest.json. Decide steering per references/steering-playbook.md:
  1. If you steered, the next step picks it up from constraints.json. If not, just step again.

Step 3 — finalize.

bash <SKILL>/scripts/run.sh finalize --run-dir <RUN_DIR> --top-n 20 --evaluate

Exports pareto/*.cif + leaderboard.csv; --evaluate runs mattergen-evaluate for an independent novelty/stability report (evaluate_report.json).

Step 3b — render Pareto CIF. PNG rendering is now built into the finalize subcommand — evolve_driver.py calls render_batch.py automatically after writing all CIF files. Images land next to the CIF files (pareto/01_MgO.png, etc.). No manual step needed. If rendering fails for any reason it prints a warning but does not block the CIF artifacts.

Step 4 — report. Summarize the Pareto front to the user: top formulas, their objective trade-offs, novelty/stability metrics, the CIF paths, and the rendered PNG paths. Flag any infeasible candidates still on the front.

Hard rules (enforce these)

  1. Objectives are fixed at init. To shift objectives mid-search, start a new run seeded with the current Pareto front (--seed-cifs from pareto/). Changing objectives invalidates Pareto ranking — only steer (constraints/weights/noise) is allowed mid-run.
  2. Mutate outputs are characterized before selection. The driver already does relax→alignn per offspring; don't inject uncharacterized structures.
  3. Crossover is available via crossover_rate. The diffusion-mutate MCP exposes both mutate_structure (single-parent) and crossover_structures (two-parent blend). Set --crossover-rate at init (0 = pure mutation, 0.5 = half/half, 1 = pure crossover), or switch mid-run via steer --crossover-rate. Default 0 (mutation-only) unless the goal benefits from combining parents.
  4. Each MCP serializes GPU work (process lock). A generation over pop 20 ≈ 20 mutations + ~40 characterizations; expect minutes per generation (faster for mattersim backend since it skips the second MCP). Tell the user it's slow and don't spam parallel calls.
  5. Fitness backend is fixed at init (--fitness-backend), like objectives. Switching backend invalidates comparability of property values across the run — start a new run (you can reuse seed CIFs from the current Pareto front). Mid-run you may only steer constraints/weights/noise/crossover, not the backend.

Reference files

Memory module (cross-run memory-augmented steering)

When --memory-dir <path> is set at init, every step writes two extra

artifacts next to snapshot_latest.json:

the shared store, ranked by Jaccard similarity × confidence. Read this file

alongside the snapshot before deciding whether to steer.

<memory-dir>/store.json capturing the (prev_context, last_steer_action,

Δsun/Δehull) outcome. Confidence is outcome-driven: starts at 0.5,

immediately ±0.05 depending on whether the action improved SUN/ehull

(ExpeL-style upvote/downvote — retrieval frequency never boosts

confidence), and decays ×0.98 per step.

To enable agent-with-memory mode in a run:

bash <SKILL>/scripts/run.sh init --run-dir <RUN_DIR> \
    --fitness-backend mattergen_eval \
    --objectives '{...}' --constraints '{...}' \
    --memory-dir /path/to/shared_memory \
    --family rare_earth_intermetallics \
    ...

See references/memory-module.md for schema and retrieval details.

Goal-evolving demo (mid-search pivot)

For the Nature-paper Fig 7a demo. Mid-search objective change requires that

the new objectives' property keys are already characterized in the current

population (no re-evaluation):

bash <SKILL>/scripts/run.sh pivot --run-dir <RUN_DIR> \
    --objectives '{"ehull": "minimize", "novel": "maximize"}'

Re-ranks the existing population in place using NSGA-II fast non-dominated

sorting with the new objectives. Appends a pivot_log.jsonl entry. See

references/goal-evolving-demo.md for the demo runbook.

4-way ablation harness

For the Nature-paper Fig 4. Scaffolds N×M run directories for the four

steering modes:

python <SKILL>/scripts/ablation_runner.py scaffold \
    --base-run-dir <BASE> --family <TAG> \
    --fitness-backend mattergen_eval \
    --objectives '{...}' --constraints '{...}' \
    --seeds <cif1,cif2,...> \
    --modes static_rules,agent_no_mem,agent_with_mem \
    --replicates 5 --pop-size 16 --max-generations 4

STATIC_RULES runs are fully automated (run_static.sh per run dir).

AGENT_NO_MEM and AGENT_WITH_MEM runs require external Claude orchestration

(MANUAL_ORCHESTRATION.md per run dir). Aggregate metrics via

pilot_analysis.py.

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.