python_pdb.entities module

Classes for representing objects contained within PDB files.

class python_pdb.entities.Atom(name: str, number: int, alt_loc: str | None, pos_x: float, pos_y: float, pos_z: float, occupancy: float, b_factor: float, element: str, charge: str | None, is_het_atom: bool = False)

Bases: Entity

Atom representation.

name

atom name

Type:

str

number

atom number in PDB file

Type:

int

alt_loc

alternate location of the atom

Type:

str | None

pos_x

atom’s x-coordinate

Type:

float

pos_y

atom’s y-coordinate

Type:

float

pos_z

atom’s z-coordinate

Type:

float

occupancy

atom’s occupancy

Type:

float

b_factor

b_factor from experimentally derived data

Type:

float

element

str corresponding to the element id of this atom (periodic table style)

Type:

str

charge

+/- charge on the atom

Type:

str | None

het_atom

True if the atom comes from a hetero atom record

Type:

bool

add_child()

Add child to entitity.

children_equal(other)
copy() Atom

Create a copy of the atom with the same propeties. Note the parent will be reset of the copy.

get_children()

Get children of this entity.

property position: tuple[float, float, float]

the x,y,z coordinates of the atom

remove_child()

Remove child from entity.

class python_pdb.entities.Chain(name: str)

Bases: Entity

Chain representation.

name

name of the chain

Type:

str

add_residue(residue: Residue)

Add residue to chain.

copy() Chain

Create a deep copy of the chain of the chain. Note the parent will be reset.

get_residues() list[Residue]

Get all residues on a chain.

remove_residue(residue: Residue)

Remove residue from chain.

class python_pdb.entities.Entity

Bases: object

Base class that Atom, Residue, Chain, Model, and Structure inherit from.

children

Entities that form this entity.

Type:

list[Entity]

parent

Entity that this entity belongs too.

Type:

Entity

add_child(child: Type[Entity])

Add child to entitity.

children_equal(other: list[Type[Entity]]) bool
get_children() list[Type[Entity]]

Get children of this entity.

get_coordinates() ndarray

Get n x 3 matrix of atomic coordinates based on all the atoms in the Entitity. Ordering is preserved.

remove_child(child: Type[Entity])

Remove child from entity.

class python_pdb.entities.Model(serial_number: int | None = None)

Bases: Entity

Representation of a PDB model.

serial_number

optional serial number to identify the model.

Type:

int | None

add_chain(chain: Chain)

Add chain to model.

copy() Model

Create a deep copy of the Model. Note parent will be reset in copy.

get_chains() list[Chain]

Get all the chains in the model.

remove_chain(chain: Chain)

Remove chain from model.

class python_pdb.entities.Residue(name: str, seq_id: int, insert_code: str | None)

Bases: Entity

Residue representation.

name

Name of the residue (three letter code)

Type:

str

seq_id

Sequence number of the residue.

Type:

int

insert_code

Insert code of the residue if available.

Type:

str | None

add_atom(atom: Atom)

Add an atom to the residue.

copy() Residue

Create a copy of the Residue. Note: the parent of the copied residue will reset.

get_atoms() list[Atom]

Return a list of all atoms in the residue, including atoms with alternate locations.

property olc: str

One letter code of residue.

remove_atom(atom: Atom)

Remove atom from residue.

property tlc: str

Three letter code of the residue.

class python_pdb.entities.Structure

Bases: Entity

PDB Structure representation.

add_model(model: Model)

Add model to the structure.

copy() Structure

Create a deep copy of the structure.

dehydrate()

Remove all water molecules from the Structure.

classmethod from_pandas(df: DataFrame) Structure

Create Structure object from a pandas dataframe.

Parameters:

df

pandas dataframe that has the following columns representing a PDB structure:

  • record_type

  • atom_number

  • atom_name

  • alt_loc

  • residue_name

  • chain_id

  • residue_seq_id

  • residue_insert_code

  • pos_x

  • pos_y

  • pos_z

  • occupancy

  • b_factor

  • element

  • charge

and optionaly model_index if there are multiple models

Returns:

Structure with chains, residues, and atoms from the input dataset.

classmethod from_pdb(contents: str) Structure

Create structure from a PDB formatted file.

get_models() list[Model]

Get models from the structure.

remove_model(model: Model)

Remove model from the structure.

remove_non_amino_acids()

Remove all non amino acids from the Structure.

split_states(all_combinations=False)

Split multiple alternate locations into separate models.

If there are multiple locations for an atom (as designated by alt_loc’s) split the view of the protein into multiple models.

Warning

This method modifies the structure object by overriding the existing models property.

Parameters:

all_combinations – states will be grouped by alt code if False (ie all ‘A’s are together) or else every different combination of alt codes will be used (Default: False).

to_pandas() DataFrame

Convert Structure into pandas dataframe.

Returns:

  • record_type
    • atom_number

    • atom_name

    • alt_loc

    • residue_name

    • chain_id

    • residue_seq_id

    • residue_insert_code

    • pos_x

    • pos_y

    • pos_z

    • occupancy

    • b_factor

    • element

    • charge

and optionally model_index if there are multiple models.

Return type:

dataframe with the following columns representing a structure

exception python_pdb.entities.StructureConstructionWarning

Bases: Warning

Raised if something is flagged for attention while building a structure.