structure
Module for querying and modifying [gemmi structures][gemmi.Structure].
ChainNotFoundError
Bases: IndexError
Exception raised when a chain is not found in a structure.
__reduce__()
Helper for pickling the exception.
chains_in_structure(structure)
Get a list of chains in a structure.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
structure
|
Structure
|
The gemmi structure to get chains from. |
required |
Returns:
| Type | Description |
|---|---|
set[Chain]
|
A set of chains in the structure. |
find_chain_in_model(model, wanted_chain)
Find a chain in a model.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
model
|
Model
|
The gemmi model to search in. |
required |
wanted_chain
|
str
|
The chain identifier to search for. |
required |
Returns:
| Type | Description |
|---|---|
Chain | None
|
The found chain or None if not found. |
find_chain_in_structure(structure, wanted_chain)
Find a chain in a structure.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
structure
|
Structure
|
The gemmi structure to search in. |
required |
wanted_chain
|
str
|
The chain identifier to search for. |
required |
Returns:
| Type | Description |
|---|---|
Chain | None
|
The found chain or None if not found. |
nr_residues_in_chain(file, chain='A')
structure2uniprot_accessions(structure)
Extract UniProt accessions from a gemmi Structure object.
Logs a warning and returns an empty set if no accessions are found in structure.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
structure
|
Structure
|
The gemmi Structure object to extract UniProt accessions from. |
required |
Returns:
| Type | Description |
|---|---|
set[str]
|
A set of UniProt accessions found in the structure. |
write_single_chain_structure_file(input_file, chain2keep, output_dir, out_chain='A', copy_method='copy')
Write a single chain from a structure file to a new structure file.
Also
- removes ligands and waters
- renumbers atoms ids
- removes chem_comp section from cif files
- adds provenance information to the header like software and input file+chain
This function is equivalent to the following gemmi commands:
gemmi convert --remove-lig-wat --select=B --to=cif chain-in/3JRS.cif - | \
gemmi convert --from=cif --rename-chain=B:A - chain-out/3JRS_B2A.gemmi.cif
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
input_file
|
Path
|
Path to the input structure file. |
required |
chain2keep
|
str
|
The chain to keep. |
required |
output_dir
|
Path
|
Directory to save the output file. |
required |
out_chain
|
str
|
The chain identifier for the output file. |
'A'
|
copy_method
|
CopyMethod
|
How to copy when no changes are needed to output file. |
'copy'
|
Returns:
| Type | Description |
|---|---|
Path
|
Path to the output structure file |
Raises:
| Type | Description |
|---|---|
FileNotFoundError
|
If the input file does not exist. |
ChainNotFoundError
|
If the specified chain is not found in the input file. |