| name | write-program |
| description | Composes proto-language optimization programs in Python. Covers Segments, Constructs, Generators, Constraints, Optimizers, and Programs for designing biological sequences. Use when writing programs, composing optimization pipelines, designing DNA/protein/RNA sequences, or setting up multi-stage optimization with constraints like GC content, structure prediction, or protein quality.
|
| allowed-tools | ["Read","Write","Bash","Glob","Grep"] |
write-program skill
Before You Start
- Browse example programs in
examples/scripts/ (DNA, RNA, protein, multi-chain designs) to match the user's design goal, and read the example closest to it before writing a new program.
- Discover available components using the registry API (see Component Discovery below) to find constraints, generators, and optimizers and inspect their config schemas.
Program Structure (6 Steps)
Every program follows this exact flow:
1. Segments -> Define design regions (fixed or variable)
2. Constructs -> Combine segments into complete designs
3. Generators -> Create + assign to segments
4. Constraints -> Define scoring functions on segments
5. Optimizers -> Wire constructs + generators + constraints
6. Program -> Run sequential optimizer stages
Complete Template
from proto_language.core import (
Constraint,
Construct,
Program,
Segment,
Sequence,
)
from proto_language.constraint import gc_content_constraint
from proto_language.generator import (
MaskingStrategy,
RandomNucleotideGenerator,
RandomNucleotideGeneratorConfig,
)
from proto_language.optimizer import MCMCOptimizer, MCMCOptimizerConfig
variable = Segment(length=100, sequence_type="dna")
construct = Construct([variable])
gen = RandomNucleotideGenerator(
RandomNucleotideGeneratorConfig(masking_strategy=MaskingStrategy(num_mutations=1))
)
gen.assign(variable)
gc = Constraint(
inputs=[variable],
function=gc_content_constraint,
function_config={"min_gc": 40, "max_gc": 60},
)
optimizer = MCMCOptimizer(
constructs=[construct],
generators=[gen],
constraints=[gc],
config=MCMCOptimizerConfig(
num_results=1,
num_steps=100,
),
)
program = Program(optimizers=[optimizer], num_results=1)
program.run()
for seq in construct.joined_sequences:
print(seq.sequence)
Key Rules
Construct Identity
All optimizers in a multi-stage program MUST share the same construct objects by identity (not copies). This is how state flows between stages.
Generator-Segment Assignment
Every variable segment needs exactly one generator per optimizer stage. Call gen.assign(segment) before creating the optimizer.
Fresh Generators/Constraints Per Stage
Generators and constraints cannot be reused across optimizer stages. Create new instances for each stage.
Constraint Config
function_config accepts either a dict or a Pydantic config object:
Constraint(function_config={"min_gc": 40, "max_gc": 60}, ...)
from proto_language.constraint.sequence_composition.gc_content_constraint import GCContentConfig
Constraint(function_config=GCContentConfig(min_gc=40, max_gc=60), ...)
Filter vs Scoring Constraints
Constraint(inputs=[seg], function=fn, function_config=cfg)
Constraint(inputs=[seg], function=fn, function_config=cfg, weight=2.0)
Constraint(inputs=[seg], function=fn, function_config=cfg, threshold=0.1)
Discovering Available Components
Do NOT rely on hardcoded lists — always discover dynamically via the registry APIs:
from proto_language.constraint import ConstraintRegistry
from proto_language.generator import GeneratorRegistry
from proto_language.optimizer import OptimizerRegistry
ConstraintRegistry.list_all()
GeneratorRegistry.list_all()
OptimizerRegistry.list_all()
For a component's config schema, read its source file:
- Constraints:
proto_language/constraint/{category}/{name}_constraint.py
- Generators:
proto_language/generator/{name}_generator.py
- Optimizers:
proto_language/optimizer/{name}_optimizer.py
Constraints are grouped by category as subdirectories under proto_language/constraint/. To find gradient-capable (dual-mode) constraints, filter the registry on spec.mode == "dual" or grep for backward= under proto_language/constraint/. See PATTERNS.md for the gradient-based optimization worked example.
Common Patterns
For detailed examples of common patterns, use the Read tool to load:
- Patterns reference:
.claude/skills/write-program/PATTERNS.md
Covers: multi-stage (Rejection Sampling -> MCMC), program-level num_results, multi-segment (fixed flanks + variable region), multi-constraint protein design, gradient-based optimization (GradientOptimizer), incremental execution, custom logging, export results, and accessing results.
Validation Checklist
Copy this and check off as you go:
If any check fails, fix before proceeding.