---
title: Structure workflows
description: Load PDB and mmCIF with Biotite, superpose for RMSD, split chains into per-chain PDB files, and export mmCIF — stripping waters and ligands first.
---

Structure workflows let you load PDB and mmCIF files, superpose structures to measure RMSD, and extract chains for export. Stripping waters and ligands and normalizing alternate locations before superposition are what most affect whether your RMSD reflects the atoms you actually care about.

> **Where this code runs**

> You cannot open a shell on the platform yourself. The scripts on this page are plain Biotite Python and shell: ask Ivy in chat to run them in the chat's [code workspace](/docs/sandbox), which ships Biotite, or run them on your own machine.

## Load and inspect structures

```python
from biotite.structure.io import load_structure

structure = load_structure("inputs/structures/1crn.pdb")
print("Atoms:", structure.array_length())
print("Chains:", structure.get_chain_count())
print("Residues:", structure.res_id[-1])
```

## Center and superpose

```python
import biotite.structure as struc

mobile = load_structure("inputs/structures/mobile.pdb")
target = load_structure("inputs/structures/reference.pdb")

transform = struc.fit_superposition(mobile, target)
mobile_aligned = struc.apply_translation(
    struc.apply_rotation(mobile, transform.rotation), transform.translation
)

print("RMSD:", struc.rmsd(target, mobile_aligned))
mobile_aligned.write("outputs/mobile_aligned.pdb")
```

## Extract chains and save

```python
from biotite.structure.io.pdb import PDBFile

pdb = PDBFile.read("inputs/structures/complex.pdb")
structure = pdb.get_structure()

chains = structure.get_unique_chains()
for chain_id in chains:
    chain = structure[structure.chain_id == chain_id]
    out = PDBFile()
    out.set_structure(chain)
    out.write(f"outputs/chain_{chain_id}.pdb")
```

## Common tips

- Normalize alternate locations and occupancy before superposition.
- Remove water/ligands if you only need backbone atoms for RMSD.
- When exporting to mmCIF, keep atom ordering stable to ease downstream diffing.

## Minimal export to mmCIF

```python
from biotite.structure.io.mmtf import MMTFFile
from biotite.structure.io.mmcif import MMCIFFile

mmtf = MMTFFile.read("inputs/structures/model.mmtf")
structure = mmtf.get_structure()

mmcif = MMCIFFile()
mmcif.set_structure(structure)
mmcif.write("outputs/model.cif")
```
