Skip to content

structure

Module for querying and modifying [gemmi structures][gemmi.Structure].

ChainNotFoundError

Bases: IndexError

Exception raised when a chain is not found in a structure.

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')

Returns the number of residues in a specific chain from a structure file.

Parameters:

Name Type Description Default
file Path

Path to the input structure file.

required
chain str

Chain to count residues of.

'A'

Returns:

Type Description
int

The number of residues in the specified chain.

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.