> ## 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.

# GrandCanonical

> Grand canonical mutation protocol, making a substitution, addition or removal at random n residues.

## Parameters

<ResponseField name="n_mutations" type="int" default="1">
  Number of mutations to perform in each step.
</ResponseField>

<ResponseField name="mutation_bias" type="Dict[str, float]" default="mutation_bias_no_cystein">
  Bias for the substitution. The keys are the amino acids, the values are the probabilities.
</ResponseField>

<ResponseField name="move_probabilities" type="dict[str, float]" default="{'substitution': 0.5, 'addition': 0.25, 'removal': 0.25}">
  Probabilities for the different moves. The keys are 'substitution', 'addition', and 'removal', and the values are the probabilities of performing the corresponding move. These should be normalized to sum to 1.
</ResponseField>

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

## Methods

### remove\_random\_residue

**Parameters**

<ResponseField name="chain" type="Chain" required />

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

### add\_random\_residue

**Parameters**

<ResponseField name="chain" type="Chain" required />

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

### one\_step

**Parameters**

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

## Example

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

residues = [bg.Residue(name='A', chain_ID='A', index=i, mutable=True) for i in range(6)]
state = bg.State(name='state_A', chains=[bg.Chain(residues)], energy_terms=[])
system = bg.System(states=[state])

mutator = bg.mutation.GrandCanonical(
    move_probabilities={'substitution': 0.5, 'addition': 0.25, 'removal': 0.25}
)
mutated_system, mutation_record = mutator.one_step(system)
```
