Manage the CST template library — save successful designs as reusable templates and query the library to score "CST template readiness" for new design hypotheses. The library grows with each successful tuning run, making future research more informed.
You manage a growing library of proven metamaterial designs at D:/Claude/MetaClaw/.templates/. Each template represents a successfully tuned CST design with optimized parameters and verified performance.
Called after a successful CST tuning run. Extracts artifacts from the project and saves them to the library.
From the project directory:
configs/<project>.json — TargetConfig with target specdesign.py — Optimized parameters (Python dict)results.tsv — Full optimization historyexports/<best_iter>/Absorptance.csv — absorption spectrumFrom user or context:
cross_resonator, split_ring, square_ring, patch_with_slots, slotted_square_ring, fishnet, resistive_film, multilayer, supercell, otherRead TargetConfig from configs/*.json:
# Extract key fields
response_type = config["response_type"] # "narrowband" | "broadband" | "multiband"
freq_min = config["freq_min_thz"]
freq_max = config["freq_max_thz"]
target_value = config["target_value"]
materials = [m["name"] for m in config.get("materials", [])]
tunable_params = config["tunable_params"]
param_bounds = config["param_bounds"]
Read design.py and extract the DESIGN dict:
# Parse DESIGN = {...} from design.py
best_params = {"p": 84.0, "outer_srr": 82.0, ...}
Read results.tsv and extract metrics:
# Find best iteration (lowest score where valid=True)
best_score = min(valid_rows, key=lambda r: r["score"])
iterations_to_converge = best_row_index + 1
total_iterations = len(all_rows)
Read best absorption spectrum from exports/<best_iter>/Absorptance.csv
Generate template ID:
id = "{family}-{freq_min}-{freq_max}thz-{YYYY-MM-DD}"
# e.g., "cross_resonator-0.36-0.44thz-2026-04-06"
Create template directory:
.templates/{response_type}/{family}/{freq_min}-{freq_max}thz/
Save template files:
target_config.json — Copy of TargetConfigdesign_best.json — {"params": best_params, "score": best_score}results_summary.json:
{
"best_score": 0.0016,
"best_absorption_mean": 0.98,
"best_absorption_min": 0.95,
"iterations_to_converge": 14,
"total_iterations": 14,
"convergence_rate": "fast|medium|slow",
"parameter_sensitivity": {"param_name": "high|medium|low", ...}
}
absorption_best.csv — Copy of best spectrumUpdate library-index.json — append new entry:
{
"id": "cross_resonator-0.36-0.44thz-2026-04-06",
"family": "cross_resonator",
"response_type": "narrowband",
"freq_min_thz": 0.36,
"freq_max_thz": 0.44,
"target_value": 0.90,
"best_score": 0.0016,
"best_absorption": 0.98,
"materials": ["gold", "polyimide"],
"iterations_to_converge": 14,
"created": "2026-04-06T12:00:00Z",
"project_path": "/path/to/project",
"template_dir": ".templates/narrowband/cross_resonator/0.36-0.44thz",
"cst_template": "path/to/template.cst",
"tunable_params": ["p", "outer_srr", "w", "gap"]
}
Confirm to user: "Template saved: {id}. Library now has {N} templates."
Called during literature survey to score "CST template readiness" for design hypotheses.
family — topology family name (e.g., "cross_resonator")freq_min_thz, freq_max_thz — target frequency rangeresponse_type — "narrowband" | "broadband" | "multiband" (optional)Read D:/Claude/MetaClaw/.templates/library-index.json
For each template in the library, compute a match score:
# Frequency overlap
overlap_min = max(query.freq_min, template.freq_min)
overlap_max = min(query.freq_max, template.freq_max)
if overlap_max > overlap_min:
overlap_fraction = (overlap_max - overlap_min) / (query.freq_max - query.freq_min)
else:
overlap_fraction = 0.0
# Family match
family_match = 1.0 if query.family == template.family else 0.0
# Response type match (bonus)
type_bonus = 0.1 if query.response_type == template.response_type else 0.0
# Combined match score
match_score = family_match * (0.5 + 0.5 * overlap_fraction) + type_bonus
Return the best match score (0.0 to 1.0):
| Condition | Readiness Score |
|---|---|
| Exact match (same family, >80% freq overlap) | 1.0 |
| Partial match (same family, >50% freq overlap) | 0.7 |
| Family match only (different freq range) | 0.4 |
| Different family but same response type + freq overlap | 0.2 |
| No match in library | 0.1 |
Return result:
{
"readiness": 0.7,
"best_match": "cross_resonator-0.36-0.44thz-2026-04-06",
"match_reason": "Same family, 85% frequency overlap",
"reusable_params": {"p": 84.0, "outer_srr": 82.0, ...},
"expected_performance": "98% absorption in 14 iterations"
}
When user asks about existing templates:
Read library-index.json
Display summary table:
| # | Family | Response | Freq Range | Best Absorption | Score | Materials | Date |
|---|---|---|---|---|---|---|---|
| 1 | cross_resonator | narrowband | 0.36-0.44 THz | 98% | 0.0016 | Au/polyimide | 2026-04-06 |
If user wants details, read the template directory files.
All templates stored at: D:/Claude/MetaClaw/.templates/
.templates/
├── library-index.json # Master catalog
├── narrowband/
│ ├── cross_resonator/
│ │ └── 0.36-0.44thz/
│ │ ├── target_config.json
│ │ ├── design_best.json
│ │ ├── results_summary.json
│ │ └── absorption_best.csv
│ └── split_ring/
│ └── ...
├── broadband/
│ └── ...
└── multiband/
└── ...
-v2, -v3)library-index.json is the single source of truth — always update it atomically