libpdb: PDB helping functions

Parse molecular structures in PDB format.

haddock.libs.libpdb.add_TER_on_chain_breaks(input_pdb: str | Path, output_pdb: str | Path) → None[source]

Detect chain breaks and add TER statements between them.

Parameters:
  • input_pdb (FilePath) – Input PDB filepath with potential chain breaks.

  • output_pdb (FilePath) – Output PDB filepath with added TER statements between chain breaks.

haddock.libs.libpdb.check_combination_chains(combination: list[PDBFile]) → list[str][source]

Check if chain IDs are unique for each pdb in combination.

haddock.libs.libpdb.check_mol_shape(input_mol: Path) → bool[source]

Checks if molecules provided is a shape or not.

Parameters:

input_pdb (PDBFile) – input PDB to check if shape.

Returns:

bool – True if shape, False if not.

haddock.libs.libpdb.find_insertion_codes(pdb_file_path: str | Path) → list[str][source]

Find the residues with an insertion code (e.g. 52A).

Returns:

list[str] – The residues, as "<resname> (chain <chain>, residue <resid>)", in the order of the file.

haddock.libs.libpdb.format_atom_name(atom: str, element: str) → str[source]

Format PDB atom name.

Further Reading:

Parameters:
  • atom (str) – The atom name.

  • element (str) – The atom element code.

Returns:

str – Formatted atom name.

haddock.libs.libpdb.get_new_models(pdb_file_path: str | Path) → list[Path][source]

Get new PDB models if they exist.

If no new models are found, return the original path within a list.

haddock.libs.libpdb.get_pdb_file_suffix_variations(file_name: str | Path, sep: str = '_') → list[Path][source]

List suffix variations of a PDB file in the current path.

If file.pdb is given, and files file_1.pdb, file_2.pdb, exist in the folder, those will be listed.

Parameters:
  • file_name (str or Path) – The name of the file with extension.

  • sep (str) – The separation between the file base name and the suffix. Defaults to “_”.

Returns:

list – List of Paths with the identified PBD files. If no files are found return an empty list.

haddock.libs.libpdb.get_supported_residues(haddock_topology: str | Path) → list[str][source]

Read the topology file and identify which data is supported.

haddock.libs.libpdb.handle_input_reference(reference: Path) → list[Path][source]

Validate the reference file by returning only one model.

Parameters:

reference (Path) – Path to the input reference structure, possibly containing an ensemble.

Returns:

reference or first_model_path (Path) – Path to the reference structure to be used downstream.

haddock.libs.libpdb.identify_chainseg(pdb_file_path: str | Path, sort: bool = True) → tuple[list[str], list[str]][source]

Return segID OR chainID.

haddock.libs.libpdb.read_RECORD_section(lines: ~typing.Iterable[str], section_slice: slice, func: ~typing.Callable[[~typing.Iterable[str]], ~typing.Iterable[str]] = <class 'set'>) → Iterable[str][source]

Create a set of observations from a section of the ATOM line.

Returns:

set – A set of the observations.

haddock.libs.libpdb.read_chainids(lines: ~typing.Iterable[str], *, section_slice: slice = slice(21, 22, None), func: ~typing.Callable[[~typing.Iterable[str]], ~typing.Iterable[str]] = <class 'list'>) → Iterable[str]

Create a set of observations from a section of the ATOM line.

Returns:

set – A set of the observations.

haddock.libs.libpdb.read_segids(lines: ~typing.Iterable[str], *, section_slice: slice = slice(72, 76, None), func: ~typing.Callable[[~typing.Iterable[str]], ~typing.Iterable[str]] = <class 'list'>) → Iterable[str]

Create a set of observations from a section of the ATOM line.

Returns:

set – A set of the observations.

haddock.libs.libpdb.rename_residues(pdb_file_path: str | Path) → list[str][source]

Give HADDOCK3 names to the residues of a PDB file, in place.

Running this before looking for unknown residues ensures that residues known under another name (e.g. TPO for TOP) are not reported as unknown.

Selenocysteines (PDB residue SEC with an SE atom) are converted to cysteines, with SE renamed to SG: HADDOCK3 has no selenocysteine, and its own SEC residue is a serine variant for covalent docking.

Returns:

list[str] – The selenocysteines converted to cysteines, as "chain <chain>, residue <resid>".

haddock.libs.libpdb.sanitize(pdb_file_path: FilePathT, overwrite: bool = True, custom_topology: str | Path | None = None) → FilePathT | Path[source]

Sanitize a PDB file.

haddock.libs.libpdb.split_by_chain(pdb_file_path: str | Path) → list[Path][source]

Split a PDB file into multiple structures for each chain.

haddock.libs.libpdb.split_ensemble(pdb_file_path: Path, dest: str | Path | None = None) → list[Path][source]

Split a multimodel PDB file into different structures.

Parameters:

dest (str or pathlib.Path) – Destination folder.

haddock.libs.libpdb.swap_segid_chain(pdb_file_path: str | Path, new_pdb_file_path: str | Path) → None[source]

Add to the Chain ID column the found Segid.

haddock.libs.libpdb.tidy(pdb_file_path: str | Path, new_pdb_file_path: str | Path) → None[source]

Tidy PDB structure.