> ## Documentation Index
> Fetch the complete documentation index at: https://bagel.softnanolab.com/llms.txt
> Use this file to discover all available pages before exploring further.

# MutationProtocol

## Parameters

<ResponseField name="mutation_bias" type="Dict[str, float]" default="lambda: mutation_bias_no_cystein()" />

<ResponseField name="n_mutations" type="int" default="1" />

<ResponseField name="exclude_self" type="bool" default="True" />

## Methods

### one\_step

Abstract method for performing a single mutation step.

**Parameters**

<ResponseField name="system" type="System" required>
  The system to be mutated
</ResponseField>

**Returns**

<ResponseField name="return" type="System">
  The mutated system (new copy) MutationRecord Record of all mutations performed in this step
</ResponseField>

### choose\_chain

Choose one of the chains in the whole System that needs to be mutated. This is done by selecting a chain

**Parameters**

<ResponseField name="system" type="System" required />

### mutate\_random\_residue

Mutate a random residue on a chain.

**Parameters**

<ResponseField name="chain" type="Chain" required>
  The chain to mutate.
</ResponseField>

**Returns**

<ResponseField name="return" type="Mutation">
  The mutation performed. This includes the chain\_id, the move\_type, the residue\_index, the old\_amino\_acid, and the new\_amino\_acid.
</ResponseField>

### replay

Replay a mutation record on a system, reusing existing mutation logic.

**Parameters**

<ResponseField name="system" type="System" required>
  The system to apply mutations to
</ResponseField>

<ResponseField name="mutation_record" type="MutationRecord" required>
  Record of mutations to replay
</ResponseField>

**Returns**

<ResponseField name="return" type="System">
  System with mutations applied
</ResponseField>

## Example

```python theme={null}
import bagel as bg

class AlwaysSubstitute(bg.mutation.MutationProtocol):
    def one_step(self, system: bg.System) -> tuple[bg.System, bg.mutation.MutationRecord]:
        mutated = system.__copy__()
        chain = self.choose_chain(mutated)
        mutation = self.mutate_random_residue(chain)
        return mutated, bg.mutation.MutationRecord(mutations=[mutation])
```
