The structural package#

The structural package contains modules for dealing with molecular structures - it is the functional core that performs the real action behind most of the methods that are available in the Molecule class’s methods. This includes operations such as computing angles, rotating around bonds, and assembling molecules together.

The structural package is divided into several submodules, each of which is described below.

Basic structural operations#

The base module contains the basic structural operations that are used by the other modules.

Basic structure related functions

biobuild.structural.base.angle_between(coords1, coords2, coords3)[source]#

Compute the angle between three atoms.

Parameters:
  • coords1 (numpy.ndarray) – The coordinates of the first atom

  • coords2 (numpy.ndarray) – The coordinates of the second atom

  • coords3 (numpy.ndarray) – The coordinates of the third atom

Returns:

angle – The angle between the three atoms in degrees

Return type:

float

biobuild.structural.base.atom_make_full_id(self)[source]#

A self-adjusting full_id for an Biopython Atom

biobuild.structural.base.bond_angle(bond1, bond2)[source]#

Compute the angle between two bonds.

Parameters:
  • bond1 (Bio.PDB.Bond) – The first bond

  • bond2 (Bio.PDB.Bond) – The second bond

Returns:

angle – The angle between the two bonds in degrees

Return type:

float

biobuild.structural.base.bond_vector(bond)[source]#

Compute the vector between two atoms in a bond.

Parameters:

bond (Bio.PDB.Bond) – The bond

Returns:

vector – The vector between the two atoms in the bond

Return type:

numpy.ndarray

biobuild.structural.base.center_of_gravity(masses, coords)[source]#

Compute the center of gravity of a molecule.

Parameters:
  • masses (array-like) – The masses of the atoms as an nx1 vector

  • coords (array-like) – The coordinates of the atoms as an nx3 array

Returns:

cog – The center of gravity

Return type:

array-like

biobuild.structural.base.chain_make_full_id(self)[source]#

A self-adjusting full_id for an Biopython Chain

biobuild.structural.base.compute_angle(atom1, atom2, atom3)[source]#

Compute the angle between three atoms.

Parameters:
  • atom1 (Bio.PDB.Atom) – The first atom

  • atom2 (Bio.PDB.Atom) – The second atom

  • atom3 (Bio.PDB.Atom) – The third atom

Returns:

angle – The angle between the three atoms in degrees

Return type:

float

biobuild.structural.base.compute_dihedral(atom1, atom2, atom3, atom4)[source]#

Compute the dihedral angle between four atoms.

Parameters:
  • atom1 (Bio.PDB.Atom) – The first atom

  • atom2 (Bio.PDB.Atom) – The second atom

  • atom3 (Bio.PDB.Atom) – The third atom

  • atom4 (Bio.PDB.Atom) – The fourth atom

Returns:

dihedral – The dihedral angle between the four atoms in degrees

Return type:

float

biobuild.structural.base.compute_distance(atom1, atom2)[source]#

Compute the distance between two atoms.

Parameters:
  • atom1 (Bio.PDB.Atom) – The first atom

  • atom2 (Bio.PDB.Atom) – The second atom

Returns:

distance – The distance between the two atoms

Return type:

float

biobuild.structural.base.compute_torsional(atom1, atom2, atom3, atom4)[source]#

Compute the torsional angle between four atoms.

Parameters:
  • atom1 (Bio.PDB.Atom) – The first atom

  • atom2 (Bio.PDB.Atom) – The second atom

  • atom3 (Bio.PDB.Atom) – The third atom

  • atom4 (Bio.PDB.Atom) – The fourth atom

Returns:

torsional – The torsional angle between the four atoms in degrees

Return type:

float

biobuild.structural.base.distance_between(coord1, coord2)[source]#

Compute the distance between two 3d coordinates.

Parameters:
  • coord1 (numpy.ndarray) – The first coordinate

  • coord2 (numpy.ndarray) – The second coordinate

Returns:

distance – The euclidean distance between the two coordinates

Return type:

float

biobuild.structural.base.make_empty_structure(id: str = 'empty')[source]#

Make an empty PDB structure with a single model and chain.

Returns:

structure – The empty structure

Return type:

Bio.PDB.Structure

biobuild.structural.base.model_make_full_id(self)[source]#

A self-adjusting full_id for an Biopython Model

biobuild.structural.base.norm_vector(atom1, atom2)[source]#

Compute the normalized vector between two atoms.

Parameters:
  • atom1 (Bio.PDB.Atom) – The first atom

  • atom2 (Bio.PDB.Atom) – The second atom

Returns:

vector – The normalized vector between the two atoms

Return type:

numpy.ndarray

biobuild.structural.base.plane_vector(vec1, vec2)[source]#

Compute the vector in the plane of two vectors.

Parameters:
  • vec1 (numpy.ndarray) – The first vector

  • vec2 (numpy.ndarray) – The second vector

Returns:

vector – The vector in the plane of the two vectors

Return type:

numpy.ndarray

biobuild.structural.base.rename_residue(residue: Residue, new_name: str)[source]#

Rename a biopython residue object. This happens in-place.

Parameters:
  • residue (Bio.PDB.Residue.Residue) – The residue to rename.

  • new_name (str) – The new name of the residue.

Returns:

residue – The renamed residue.

Return type:

Bio.PDB.Residue.Residue

biobuild.structural.base.residue_make_full_id(self)[source]#

A self-adjusting full_id for an Biopython Residue

biobuild.structural.base.set_full_id(self, value)[source]#
biobuild.structural.base.vector_between(atom1, atom2)[source]#

Compute the vector between two atoms.

Parameters:
  • atom1 (Bio.PDB.Atom) – The first atom

  • atom2 (Bio.PDB.Atom) – The second atom

Returns:

vector – The vector between the two atoms

Return type:

numpy.ndarray

Inferring structural properties#

The infer module contains methods for inferring structural properties from a molecule’s atoms and connectivity. Among these are connections, or atom labels.

Functions to infer structural data such as missing atom coordinates, bond connectivity, or atom labels.

class biobuild.structural.infer.AutoLabel(atom_graph)[source]#

Bases: object

A automatic atom labeller

Parameters:

atom_graph (nx.Graph) – The molecule’s atom graph

autolabel()[source]#

Generate labels for the atoms in the molecule

Returns:

A dataframe with the atom objects and their new labels.

Return type:

pd.DataFrame

property carbons#

All carbon atoms in the molecule.

biobuild.structural.infer.apply_reference_bonds(structure, _compounds=None)[source]#

Apply bonds according to loaded reference compounds. This will compute a list of tuples with bonded atoms from the same residue. It will not infer residue-residue connections! It is possible to provide a single atom as input structure, in which case all bonds that involve said atom are returned.

Parameters:
  • structure – The structure to apply the bonds to. This can be any of the following objects which hosts Atoms: - biobuild.Structure - biobuild.Model - biobuild.Chain - biobuild.Residue

  • _compounds (PDBECompounds) – The reference compounds to use for bond inference. If not provided, the default compounds are used.

Returns:

bonds – A list of tuples of Atoms that are bonded.

Return type:

list

biobuild.structural.infer.atoms_in_area(structure, center, radius)[source]#

Get all atoms in a given area around a center point.

Parameters:
  • structure (Structure) – The structure to search for atoms.

  • center (np.ndarray) – The center point of the area to search.

  • radius (float) – The radius of the area to search.

Yields:

Atom – The atoms in the area.

biobuild.structural.infer.autolabel(molecule)[source]#

Automatically relabel atoms in a structure to match the CHARMM naming scheme. Note, this function is not guaranteed to produce the correct labels in all cases, validation of the labels is recommended.

Parameters:

molecule (biobuild.core.Molecule) – The molecule that holds the atoms to be relabeled. This molecule needs to have bonds assigned or computed.

biobuild.structural.infer.compute_atom1_from_others(coords2, coords3, coords4, ic)[source]#

Compute the coordinates of the first atom from internal coordinates and the coordinates of the other three.

Parameters:
  • *coords (array-like) – The coordinates of the other three atoms

  • ic (InternalCoordinates) – The internal coordinates

Returns:

coords1 – The coordinates of the first atom

Return type:

array-like

biobuild.structural.infer.compute_atom4_from_others(coords1, coords2, coords3, ic)[source]#

Compute the coordinates of the fourth atom from internal coordinates and the coordinates of the other three.

Parameters:
  • *coords (array-like) – The coordinates of the other three atoms

  • ic (InternalCoordinates) – The internal coordinates

Returns:

coords4 – The coordinates of the fourth atom

Return type:

array-like

biobuild.structural.infer.compute_internal_coordinates(bonds: list)[source]#

Compute internal coordinates for a structure.

Parameters:

bonds (list) – A list of tuples of atoms that are bonded. The atoms must be Bio.PDB.Atom objects with coordinates.

Returns:

A list of InternalCoordinates

Return type:

list

biobuild.structural.infer.compute_outlier_atoms(residue, f: float = 1.5)[source]#

Compute which atoms of a residue are especially far away from the residues center of mass. This function compute the distances between the center of mass of the residue and its atoms and returns all atoms are further than f * p75 away from the center of mass, where p75 is the 75th percentile of the distances.

Parameters:
  • residue (Bio.PDB.Residue.Residue) – The residue to compute the outlier atoms for.

  • f (float) – The factor to multiply the 75th percentile with.

Returns:

outlier_atoms – A list of atoms that are considered outliers.

Return type:

list

biobuild.structural.infer.compute_residue_radius(residue)[source]#

Compute the radius of a residue by computing the distance between its center of mass and the furthest atom.

Parameters:

residue (Bio.PDB.Residue.Residue) – The residue to compute the radius for.

Returns:

radius – The radius of the residue.

Return type:

float

biobuild.structural.infer.find_clashes(molecule, min_dist: float = 0.9)[source]#

Find all clashing atoms within a molecule.

Parameters:
  • molecule (Molecule) – A biobuild Molecule

  • min_dist (float) – The minimal allowed distance between atoms (in Angstrom).

Yields:

tuple – A tuple of clashing atoms.

biobuild.structural.infer.infer_bonds(structure, bond_length: float = None, restrict_residues: bool = True)[source]#

Generate a connectivity graph by inferring bonds from the distance between atoms.

Parameters:
  • structure (Bio.PDB.Structure.Structure) – The structure to infer the bonds from. This can be any of the following objects which host Residues: - Bio.PDB.Structure - Bio.PDB.Model - Bio.PDB.Chain - Bio.PDB.Residue

  • bond_length (float or tuple) – The maximum distance between two atoms to be considered a bond. If a tuple is provided, it specifies the minimal and maximal distances between atoms.

  • restrict_residues (bool) – If set to True, only bonds between atoms of the same residue will be considered.

Returns:

bonds – The connectivity graph of the molecule, storing tuples of Bio.PDB.Atom objects.

Return type:

list

biobuild.structural.infer.infer_residue_connections(structure, bond_length: float = None, triplet: bool = False)[source]#

Infer the connectivity graph of residues from the distances between atoms of residue pairs. This will establish only bonds between close-by atoms from non-identical residues.

Parameters:
  • structure (Bio.PDB.Structure.Structure) – The structure to infer the bonds from. This can be any of the following objects which host at least two Residues: - Bio.PDB.Structure - Bio.PDB.Model - Bio.PDB.Chain

  • bond_length (float) – The maximum distance between two atoms to be considered a bond.

  • triplet (bool) – If True, bonds between atoms of the same residue are also added, if one of the atoms is considered bonded to another residue. Like this residue connections are described not by a single bond with a pair of atoms, but two bonds with a triplet of atoms.

Returns:

bonds – A list of tuples of Atoms from different Residues that are bonded.

Return type:

list

biobuild.structural.infer.infer_surface_residues(structure, cutoff: int = 75, fraction: float = None)[source]#

Infer residues that are likely to be on the surface of the structure using the Solvent accessible surface area (SASA) of the structure.

Parameters:
  • structure (Bio.PDB.Structure.Structure) – The structure to infer the surface residues from.

  • n_points (int) – The number of points to sample on the surface of the structure.

  • cutoff (int) – The cutoff to use for classifying residues as surface residues.

  • fraction (float) – The fraction of residues to classify as surface residues. In this case, the cutoff is adjusted to match the fraction of residues.

Returns:

surface_residues – A list of residues that are likely to be on the surface of the structure.

Return type:

list

biobuild.structural.infer.relabel_hydrogens(molecule)[source]#

Relabel hydrogen atoms in a structure to match the CHARMM naming scheme.

Parameters:

molecule (biobuild.structural.base.Molecule) – The molecule that holds the atoms to be relabeled. This molecule needs to have bonds assigned or computed.

biobuild.structural.infer.sample_atoms_around_reference(reference_coord: ndarray, candidates: ndarray, num_samples: int, max_radius: float = 10.0)[source]#

Sample atoms around a reference coordinate. Such that they are spacially evenly distributed around the central reference coordinates.

Parameters:
  • reference_coord (np.ndarray) – The reference coordinate to sample around.

  • candidates (np.ndarray) – The atoms to sample from. This must be an array of Atom objects.

  • num_samples (int) – The number of samples to generate.

  • max_radius (float) – The maximum radius to sample for.

Returns:

samples – The sampled atoms.

Return type:

np.ndarray

biobuild.structural.infer.vet_structure(molecule, clash_range: tuple = (0.6, 1.7), angle_range: tuple = (90, 180)) bool[source]#

Check for basic structure integrity. This will return False if there are clashes within the structure, or invalid angles.

Parameters:
  • molecule (Molecule) – A biobuild Molecule

  • clash_range (tuple) – The minimal and maximal allowed distances between bonded atoms (in Angstrom). The lower limit is also used for non-bonded atoms.

  • angle_range (tuple) – The minimal and maximal allowed angle between a triplet of adjacent bonded atoms (in degrees).

Returns:

True if the structure is free from any obstacles, False otherwise.

Return type:

bool

Functions for handling SMILES strings

biobuild.structural.smiles.make_smiles(structure)[source]#
biobuild.structural.smiles.read_smiles(smiles: str, add_hydrogens: bool = True)[source]#

Assembling molecules#

In order to assemble two molecules together there are two modules that are used: stitch and patch. The patch module defines a patch function and corresponding Patcher class that can be used to assemble two molecules together using a patch (i.e. a Linkage with internal coordinates). The stitch module defines a stitch function and corresponding Stitcher class that can be used to assemble two molecules together using a recipe (i.e. a Linkage without internal coordinates).

Functions to patch molecules together

exception biobuild.structural.patch.PatchError[source]#

Bases: Exception

class biobuild.structural.patch.Patcher(copy_target: bool = False, copy_source: bool = False)[source]#

Bases: Connector

This class is responsible for patching molecules together based on a Linkage object and two Molecule objects, of which one is the target and one is the source. Residues from the source are integrated into the target molecule. The Linkage object must define a “patch”, meaning it must contain data on internal coodrinates (ICs) of the resulting molecule in the vicinity of the newly formed bond.

Parameters:
  • copy_target (bool) – Whether to copy the target molecule before patching

  • copy_source (bool) – Whether to copy the source molecule before patching

apply(patch: Linkage = None, target: Molecule = None, source: Molecule = None, target_residue=None, source_residue=None)[source]#

Patch two molecules together. This will merge the source molecule’s residues into the target molecule. If no patch, target, and source have been set already, they can be provided as arguments to this method.

Parameters:
  • patch (Linkage) – The patch to apply (this needs to have ICs)

  • target (Molecule) – The target molecule

  • source (Molecule) – The source molecule

  • target_residue (int or str or Residue) – The residue in the target molecule to which the source molecule will be patched. By default, the last residue in the target molecule will be used if it contains appropriate anchor atoms.

  • source_residue (int or str or Residue) – The residue in the source molecule that will be patched into the target molecule. By default, the first residue in the source molecule will be used if it contains appropriate anchor atoms.

Returns:

The patched target and source molecules (not yet merged into one molecule)

Return type:

tuple

get_anchors(target_residue=None, source_residue=None)[source]#

Returns the two atoms that will be used for anchoring structure alignment. These atoms form a bond between the two molecules.

Parameters:
  • target_residue (int or str or Residue) – The residue in the target molecule to which the source molecule will be patched. By default, the last residue in the target molecule will be used if it contains appropriate anchor atoms.

  • source_residue (int or str or Residue) – The residue in the source molecule that will be patched into the target molecule. By default, the first residue in the source molecule will be used if it contains appropriate anchor atoms.

Returns:

The two atoms that form the bond between the two molecules the first atom is from molecule1 and the second is from molecule2.

Return type:

tuple

merge()[source]#

Merge the source molecule into the target molecule

Returns:

The target molecule with the source molecule merged into it

Return type:

Molecule

set_patch(patch: Linkage)[source]#

Set the patch

Parameters:

patch (Linkage) – The patch

biobuild.structural.patch.patch(target: Molecule, source: Molecule, patch: Linkage, target_residue=None, source_residue=None, copy_target: bool = False, copy_source: bool = False) Molecule[source]#

Patch two molecules together. This will merge the source molecule’s residues into the target molecule.

Parameters:
  • patch (Linkage) – The patch to apply

  • target (Molecule) – The target molecule

  • source (Molecule) – The source molecule

  • target_residue (int or str or Residue) – The residue in the target molecule to which the source molecule will be patched. By default, the last residue in the target molecule will be used if it contains appropriate anchor atoms.

  • source_residue (int or str or Residue) – The residue in the source molecule that will be patched into the target molecule. By default, the first residue in the source molecule will be used if it contains appropriate anchor atoms.

  • copy_target (bool) – Whether to copy the target molecule before patching it

  • copy_source (bool) – Whether to copy the source molecule before patching it

Returns:

The patched molecule

Return type:

Molecule

Functions to stitch molecules together even in the absence of a patch

class biobuild.structural.stitch.Stitcher(copy_target: bool = False, copy_source: bool = False)[source]#

Bases: Connector

This class is responsible for stitching molecules together when there is not a patch available which specifies the immediate geometry of their connection. The only required input is a pair of atoms that should form a new bond, and two tuples of atoms (at least one from each molecule) that are being removed in the process.

Parameters:
  • copy_target (bool) – Whether to copy the target molecule before stitching

  • copy_source (bool) – Whether to copy the source molecule before stitching

apply(target: Molecule, source: Molecule, target_removals: tuple = None, source_removals: tuple = None, target_atom: int | Atom = None, source_atom: int | Atom = None, target_residue: int | Residue = None, source_residue: int | Residue = None, optimization_steps: int = 30, **kwargs) Molecule[source]#

Stitch the source and target molecules together

Parameters:
  • target (Molecule) – The target molecule

  • source (Molecule) – The source molecule. This will be attached to the target molecule.

  • target_removals (tuple) – A tuple of atoms to be removed from the target molecule. These must be the atom’s ids within the attaching residue. All atoms must be part fo the same residue as the attaching target_atom. If not provided, just any Hydrogen atom next to the target_atom will be used.

  • source_removals (tuple) – A tuple of atoms to be removed from the source molecule. These must be the atom’s ids within the attaching residue. All atoms must be part fo the same residue as the attaching source_atom. If not provided, just any Hydrogen atom next to the source_atom will be used.

  • target_atom (int or Atom) – The atom on the target molecule to which the source molecule will be attached. This may either be the atom object directly or its serial number. If none is provided, the molecule’s “root atom” is used (if defined).

  • source_atom (int or Atom) – The atom on the source molecule to which the target molecule will be attached. This may either be the atom object directly or its serial number. If none is provided, the molecule’s “root atom” is used (if defined).

  • target_residue (int or Residue) – The residue hosting the target atom. This is only required if the target atom is not given directly or specified by name.

  • source_residue (int or Residue) – The residue hosting the source atom. This is only required if the source atom is not given directly or specified by name.

  • optimization_steps (int, optional) – The number of steps to take in the optimization process.

  • **kwargs – Additional keyword arguments to pass to the optimizer. See the documentation for biobuild.optimizers.agents.optimize for more details.

Returns:

The target and source molecules after stitching. At this point, the source molecule is aligned to the target molecules but not yet integrated into it. Use the merge method to do this.

Return type:

tuple

merge() Molecule[source]#

Merge the source molecule into the target molecule

biobuild.structural.stitch.stitch(target: Molecule, source: Molecule, recipe: Linkage = None, target_removals: tuple = None, source_removals: tuple = None, target_atom: int | Atom = None, source_atom: int | Atom = None, target_residue: int | Residue = None, source_residue: int | Residue = None, optimization_steps: int = 10000.0, copy_target: bool = False, copy_source: bool = False, **kwargs) Molecule[source]#

Stitch two molecules together. Thereby the source molecule is integrated into the target molecule.

Parameters:
  • target (Molecule) – The target molecule

  • source (Molecule) – The source molecule. This will be attached to the target molecule.

  • recipe (AbstractRecipe) – The recipe to be used for stitching. If none is provided, the stitching instructions can be submitted manually via the other parameters.

  • target_removals (tuple) – This parameter is only used if no recipe is provided. A tuple of atoms to be removed from the target molecule. These must be the atom’s ids within the attaching residue. All atoms must be part fo the same residue as the attaching target_atom.

  • source_removals (tuple) – This parameter is only used if no recipe is provided. A tuple of atoms to be removed from the source molecule. These must be the atom’s ids within the attaching residue. All atoms must be part fo the same residue as the attaching source_atom.

  • target_atom (int or Atom) – This parameter is only used if no recipe is provided. The atom on the target molecule to which the source molecule will be attached. This may either be the atom object directly or its serial number. If none is provided, the molecule’s “root atom” is used (if defined).

  • source_atom (int or Atom) – This parameter is only used if no recipe is provided. The atom on the source molecule to which the target molecule will be attached. This may either be the atom object directly or its serial number. If none is provided, the molecule’s “root atom” is used (if defined).

  • target_residue (int or Residue) – The residue hosting the target atom. This is only required if the target atom is not given directly or specified by name. If a recipe is provided, the “attach_residue” is used by default. A ValueError is raised if none is defined.

  • source_residue (int or Residue) – The residue hosting the source atom. This is only required if the source atom is not given directly or specified by name. If a recipe is provided, the “attach_residue” is used by default. A ValueError is raised if none is defined.

  • optimization_steps (int, optional) – The number of steps to take in the optimization process, by default 1e4

  • copy_target (bool, optional) – Whether to copy the target molecule before stitching, by default False

  • copy_source (bool, optional) – Whether to copy the source molecule before stitching, by default False

  • **kwargs – Additional keyword arguments to pass to the optimizer. See the documentation for biobuild.optimizers.agents.optimize for more details.

Returns:

The stitched molecule

Return type:

Molecule

The base class for the Patcher and Stitcher classes.

class biobuild.structural.connector.Connector(copy_target: bool = False, copy_source: bool = False)[source]#

Bases: object

get_anchors(_ref_atoms, target_residue=None, source_residue=None)[source]#

Find appropriate anchor atoms in the source and target molecules

Parameters:
  • _ref_atoms (tuple) – The two atoms that form the bond between the two molecules. These may be specified by name or by index.

  • target_residue (int or str or Residue) – The residue in the target molecule to which the source molecule will be patched. By default, the last residue in the target molecule will be used if it contains appropriate anchor atoms.

  • source_residue (int or str or Residue) – The residue in the source molecule that will be patched into the target molecule. By default, the first residue in the source molecule will be used if it contains appropriate anchor atoms.

Returns:

The two atoms that form the bond between the two molecules

Return type:

tuple

set_source(source: Molecule.Molecule)[source]#

Set the source molecule

Parameters:

source (Molecule) – The source molecule

set_target(target: Molecule.Molecule)[source]#

Set the target molecule

Parameters:

target (Molecule) – The target molecule

Graph neighborhood in molecular structures#

In order to infer the neighborhoods from connectivity information in molecules, the neighbors module defines a Neighborhood class that can be used to infer the neighborhoods of atoms in a molecule.

Classes to handle the atom and residue neighborhoods of a structure

class biobuild.structural.neighbors.AtomNeighborhood(graph)[source]#

Bases: Neighborhood

This class handles the bond connectivity neighborhood of atoms in a structure and can be used to obtain bonded atom triplets.

Parameters:

graph – An AtomGraph

property atoms#

Returns the atoms in the structure

property bonds#

Returns the bonds in the structure

get_neighbors(atom, n: int = 1, mode: str = 'upto')[source]#

Get the neighbors of an atom

Parameters:
  • atom (Bio.PDB.Atom) – The atom whose neighbors should be returned.

  • n (int) – The (maximal) number of bonds that should separate the target from the neighbors.

  • mode (str) – The mode of the neighbor search. Can be either “upto” or “at”. If “upto”, this will get all neighbors that are n bonds away from the target or closer. If “at”, this will get all neighbors that are exactly n bonds away from the target.

Returns:

neighbors – The neighbors of the atom

Return type:

set

class biobuild.structural.neighbors.Neighborhood(graph)[source]#

Bases: object

This class handles graph connectivity of connected nodes and is the basis for the AtomNeighborhood and ResidueNeighborhood classes.

Parameters:

graph – A networkx graph

get_neighbors(node, n: int = 1, mode: str = 'upto')[source]#

Get the neighbors of an atom

Parameters:
  • node (object) – The target node object.

  • n (int) – The (maximal) number of edges that should separate the target from neighbors.

  • mode (str) – The mode of the neighbor search. Can be either “upto” or “at”. If “upto”, this will get all neighbors that are n edges away from the target or closer. If “at”, this will get all neighbors that are exactly n edges away from the target.

Returns:

neighbors – The neighbors of the target node

Return type:

set

class biobuild.structural.neighbors.Quartet(atom1, atom2, atom3, atom4, improper: bool = False)[source]#

Bases: object

An atom quartet that can be used to compute internal coordinates

property angle_123#
property angle_234#
property atom1#
property atom2#
property atom3#
property atom4#
property atoms#
property center_atom#
property dihedral#
property dist_12#
property dist_13#
property dist_23#
property dist_34#
property improper#
class biobuild.structural.neighbors.ResidueNeighborhood(graph)[source]#

Bases: Neighborhood

This class handles the residue connectivity neighborhood of residues in a structure and can be used to obtain residue triplets.

Parameters:

graph – A ResidueGraph

property bonds#

Returns the bonds in the structure

get_neighbors(residue, n: int = 1, mode: str = 'upto')[source]#

Get the neighbors of a residue

Parameters:
  • residue (Bio.PDB.Residue) – The residue whose neighbors should be returned.

  • n (int) – The (maximal) number of bonds that should separate the target from the neighbors.

  • mode (str) – The mode of the neighbor search. Can be either “upto” or “at”. If “upto”, this will get all neighbors that are n bonds away from the target or closer. If “at”, this will get all neighbors that are exactly n bonds away from the target.

Returns:

neighbors – The neighbors of the residue

Return type:

set

property residues#

Returns the residues in the structure

biobuild.structural.neighbors.compute_quartets(bonds: list)[source]#

Compute all possible quartets of atoms from a list of bonds.

Parameters:

bonds (list) – A list of bonds

Returns:

quartets – A list of quartets

Return type:

list

Examples

``` ( 1 )—( 2 )—( 4 )

( 3 )


( 5 )

``` >>> bonds = [(1, 2), (2, 3), (2, 4), (3, 5)] >>> compute_quartets(bonds) {Quartet(1, 2, 3, 5, improper=False), Quartet(5, 3, 2, 4, improper=False), Quartet(1, 3, 2, 4, improper=True)}

biobuild.structural.neighbors.compute_triplets(bonds: list, unique: bool = True)[source]#

Compute all possible triplets of atoms from a list of bonds.

Parameters:
  • bonds (list) – A list of bonds

  • unique (bool) – Whether to return only unique triplets. If False, triplets (1,2,3) and (3,2,1) will be returned. Otherwise only one of them will be returned.

Returns:

triplets – A list of triplets

Return type:

list

Examples

``` ( 1 )—( 2 )—( 4 )

( 3 )


( 5 )

``` >>> bonds = [(1, 2), (1, 3), (2, 4), (3, 5)] >>> compute_triplets(bonds) [(2, 1, 3), (1, 2, 4), (1, 3, 5)]

biobuild.structural.neighbors.generate_quartets(bonds: list)[source]#

Generate all possible quartets of atoms from a list of bonds.

Parameters:

bonds (list) – A list of bonds

Yields:

quartet (Quartet) – A quartet of atoms

biobuild.structural.neighbors.generate_triplets(bonds: list)[source]#

Compute all possible triplets of atoms from a list of bonds.

Parameters:

bonds (list) – A list of bonds

Returns:

triplets – A generator of triplets

Return type:

generator

Examples

``` ( 1 )—( 2 )—( 4 )

( 3 )


( 5 )

``` >>> bonds = [(1, 2), (1, 3), (2, 4), (3, 5)] >>> list(generate_triplets(bonds)) [(2, 1, 3), (3, 1, 2), (1, 2, 4), (4, 2, 1), (1, 2, 4)]