pestifer.molecule.chainidmanager module

A chain ID manager makes sure all chains have unique IDs and ID maps are tracked.

class pestifer.molecule.chainidmanager.ChainIDManager(format: str = 'PDB', remap: dict[str, str] | None = None, transform_reserves: dict[str, list[str]] | None = None)[source]

Bases: object

A class for managing chainIDs. Allows for users to request changes to chainIDs, assign specific chainIDs to transformed subunits, and prevents duplicate usage.

Parameters:
  • format (str, optional) – The format of the chain IDs, either ‘PDB’ or ‘mmCIF’. Default is ‘PDB’.

  • remap (Dict[str, str], optional) – A dictionary mapping user-defined chain IDs to their desired replacements. Default is an empty dictionary.

  • transform_reserves (Dict[str, List[str]], optional) – A dictionary mapping chain IDs to lists of reserved chain IDs for transformed subunits. This allows for specific chain IDs to be reserved for the products of asymmetric unit transformations. Default is an empty dictionary.

check(proposed_chainID: str) str[source]

Check if the proposed chainID is available and return a valid chainID. If the proposed chainID is already in use or reserved, a new chainID will be proposed.

Parameters:

proposed_chainID (str) – The chainID proposed by the user. This can be a 1- or 2-byte string, depending on the format of the ChainIDManager.

generate_next_map(chainIDs: list[str], active_chains: list[str] | None = None) dict[str, str][source]

Generate a map identifying new chainIDs for each existing chainID in the list chainIDs. If active_chains is not empty, then it must list a subset of the chainIDs considered actually active

Parameters:
  • chainIDs (list of str) – List of chainIDs for which to generate a map of next available chainIDs.

  • active_chains (list of str, optional) – List of chainIDs that are currently active. If provided, only these chainIDs will be considered for the next available chainIDs. If not provided, all chainIDs in chainIDs will be considered active.

next_reserved_chainID(key: str) str | None[source]

Returns the next available chainID from the ReservedUnused list that is mapped to the given key. If the key is not in the transform_reserves, an error is raised. If no reserved chainIDs are available for the key, an error is raised.

Parameters:

key (str) – The chainID key for which to find the next available reserved chainID.

next_unused_chainID()[source]

Returns the next unused chainID from the Unused list. If there are no unused chainIDs, this will raise an error.

sandbag(i_chainIDs: list[str] | None = None)[source]

moves all chainIDs in i_chainIDs to end of Unused so they are not popped too early.

Parameters:

i_chainIDs (list[str], optional) – List of chainIDs to sandbag. These chainIDs will be moved to the end of the Unused list, ensuring they are not used until explicitly requested.

thru_map(chainIDs: list[str], active_chains: list[str] | None = None) dict[str, str][source]

Generate a map that maps each chainID in chainIDs to itself, but only for the chainIDs that are considered active. If active_chains is provided, only those chainIDs will be included in the map. If active_chains is empty, all chainIDs in chainIDs will be considered active.

Parameters:
  • chainIDs (list of str) – List of chainIDs to include in the map.

  • active_chains (list of str, optional) – List of chainIDs that are currently active. If provided, only these chainIDs will be included in the map. If not provided, all chainIDs in chainIDs will be considered active.

touch(chainID: str)[source]

Mark chainID as used if it is not already

unregister_chain(chainID: str)[source]

Unregister the single chainID with the manager

Parameters:

chainID (str) – 1- or 2-byte chainID to unregister