stk.BuildingBlock
- class stk.BuildingBlock(smiles, functional_groups=(), placer_ids=None, position_matrix=None)[source]
Bases:
Molecule
Represents a building block of a
ConstructedMolecule
.A
BuildingBlock
can represent either an entire molecule or a molecular fragments used to construct aConstructedMolecule
. The building block usesFunctionalGroup
instances to identify which atoms are modified during construction.- Parameters:
smiles (str) – A SMILES string of the molecule.
functional_groups (FunctionalGroup | FunctionalGroupFactory | list[FunctionalGroup | FunctionalGroupFactory]) –
FunctionalGroup
instances added to the building block andFunctionalGroupFactory
instances used to createFunctionalGroup
instances added to the building block.FunctionalGroup
instances are used to identify which atoms are modified duringConstructedMolecule
construction.The ids of placer atoms. These are the atoms which should be used for calculating the position of the building block. Depending on the values passed to placer_ids, and the functional groups in the building block, different placer ids will be used by the building block.
placer_ids is passed to the initializer: the passed placer ids will be used by the building block.
placer_ids is
None
and the building block has functional groups: The placer ids of the functional groups will be used as the placer ids of the building block.placer_ids is
None
and functional_groups is empty. All atoms of the molecule will be used for placer ids.
position_matrix (ndarray | None) – The position matrix the building block should use. If
None
,rdkit.ETKDGv2()
will be used to calculate it.
- Raises:
RuntimeError – If embedding the molecule fails.
Methods
Return a clone.
Yield the positions of atoms.
Yield the atoms in the molecule, ordered by id.
Yield the bond in the molecule.
Map the id of each atom to its id under canonical ordering.
Return the centroid.
Yield ids of atoms which form the core of the building block.
Return a vector of best fit through the atoms.
Yield the functional groups, ordered by id.
Return the maximum diameter.
Return the number of atoms in the molecule.
Return the number of bonds in the molecule.
Return the number of functional groups.
Return the number of placer atoms in the building block.
Yield the ids of placer atoms.
Return the normal to the plane of best fit.
Return a matrix holding the atomic positions.
Initialize a
BuildingBlock
from its components.Initialize from a file.
Initialize from a
Molecule
.Initialize from an
rdkit
molecule.Initialize from a
vabene.Molecule
.Return an
rdkit
representation.Return a clone, with canonically ordered atoms.
Return a clone with its centroid at position.
Return a displaced clone.
Return a clone with specific functional groups.
Return a clone with atomic positions set by position_matrix.
Return a rotated clone.
Return a rotated clone.
Return a rotated clone.
Return a clone, with its structure taken from a file.
Write the structure to a file.
- get_atomic_positions(atom_ids=None)
Yield the positions of atoms.
- get_atoms(atom_ids=None)
Yield the atoms in the molecule, ordered by id.
- get_bonds()
Yield the bond in the molecule.
- get_canonical_atom_ids()
Map the id of each atom to its id under canonical ordering.
- get_centroid(atom_ids=None)
Return the centroid.
- Parameters:
atom_ids (int | list[int] | None) – The ids of atoms which are used to calculate the centroid. If
None
, all atoms are used.- Returns:
The centroid of atoms specified by atom_ids.
- Raises:
ValueError – If atom_ids has a length of
0
.- Return type:
- get_core_atom_ids()[source]
Yield ids of atoms which form the core of the building block.
This includes all atoms in the building block not part of a functional group, as well as any atoms in a functional group, specifically labelled as core atoms.
See also
FunctionalGroup.get_core_atom_ids()
: For getting the core atom ids of functional groups.
- get_direction(atom_ids=None)
Return a vector of best fit through the atoms.
- Parameters:
atom_ids (int | list[int] | None) – The ids of atoms which should be used to calculate the vector. If
None
, all atoms are used.- Returns:
The vector of best fit.
- Raises:
ValueError – If atom_ids has a length of
0
.- Return type:
- get_functional_groups(fg_ids=None)[source]
Yield the functional groups, ordered by id.
- get_maximum_diameter(atom_ids=None)
Return the maximum diameter.
This method does not account for the van der Waals radius of atoms.
- Parameters:
atom_ids (int | list[int] | None) – The ids of atoms which are considered when looking for the maximum diameter. If
None
, all atoms are used.- Returns:
The maximum diameter in the molecule.
- Raises:
ValueError – If atom_ids has a length of
0
.- Return type:
- get_num_atoms()
Return the number of atoms in the molecule.
- Returns:
The number of atoms in the molecule.
- Return type:
- get_num_bonds()
Return the number of bonds in the molecule.
- Returns:
The number of bonds in the molecule.
- Return type:
- get_num_functional_groups()[source]
Return the number of functional groups.
- Returns:
The number of functional groups in the building block.
- Return type:
- get_num_placers()[source]
Return the number of placer atoms in the building block.
- Returns:
The number of placer atoms in the building block.
- Return type:
- get_placer_ids()[source]
Yield the ids of placer atoms.
Placer atoms are those, which should be used to calculate the position of the building block.
See also
FunctionalGroup.get_placer_ids()
: For getting the placer ids of functional groups.
- get_plane_normal(atom_ids=None)
Return the normal to the plane of best fit.
- Parameters:
atom_ids (int | list[int] | None) – The ids of atoms which should be used to calculate the plane. If
None
, all atoms are used.- Returns:
Vector orthonormal to the plane of the molecule.
- Raises:
ValueError – If atom_ids has a length of
0
.- Return type:
- get_position_matrix()
Return a matrix holding the atomic positions.
- Returns:
The array has the shape
(n, 3)
. Each row holds the x, y and z coordinates of an atom.- Return type:
- classmethod init(atoms, bonds, position_matrix, functional_groups=(), placer_ids=None)[source]
Initialize a
BuildingBlock
from its components.- Parameters:
position_matrix (ndarray) – An
(n, 3)
position matrix of the building block.functional_groups (FunctionalGroup | FunctionalGroupFactory | list[FunctionalGroup | FunctionalGroupFactory]) –
FunctionalGroup
instances added to the building block andFunctionalGroupFactory
instances used to createFunctionalGroup
instances added to the building block.FunctionalGroup
instances are used to identify which atoms are modified duringConstructedMolecule
construction.The ids of placer atoms. These are the atoms which should be used for calculating the position of the building block. Depending on the values passed to placer_ids, and the functional groups in the building block, different placer ids will be used by the building block.
placer_ids is passed to the initializer: the passed placer ids will be used by the building block.
placer_ids is
None
and the building block has functional groups: The placer ids of the functional groups will be used as the placer ids of the building block.placer_ids is
None
and functional_groups is empty. All atoms of the molecule will be used for placer ids.
- Returns:
The building block.
- Return type:
- classmethod init_from_file(path, functional_groups=(), placer_ids=None)[source]
Initialize from a file.
- Parameters:
The path to a molecular structure file. Supported file types are:
.mol
,.sdf
- MDL V3000 MOL file
functional_groups (FunctionalGroup | FunctionalGroupFactory | list[FunctionalGroup | FunctionalGroupFactory]) –
FunctionalGroup
instances added to the building block andFunctionalGroupFactory
instances used to createFunctionalGroup
instances added to the building block.FunctionalGroup
instances are used to identify which atoms are modified duringConstructedMolecule
construction.The ids of placer atoms. These are the atoms which should be used for calculating the position of the building block. Depending on the values passed to placer_ids, and the functional groups in the building block, different placer ids will be used by the building block.
placer_ids is passed to the initializer: the passed placer ids will be used by the building block.
placer_ids is
None
and the building block has functional groups: The placer ids of the functional groups will be used as the placer ids of the building block.placer_ids is
None
and functional_groups is empty. All atoms of the molecule will be used for placer ids.
- Returns:
The building block.
- Return type:
- Raises:
ValueError – If the file type cannot be used for initialization.
- classmethod init_from_molecule(molecule, functional_groups=(), placer_ids=None)[source]
Initialize from a
Molecule
.- Parameters:
molecule (Molecule) – The molecule to initialize from.
functional_groups (FunctionalGroup | FunctionalGroupFactory | list[FunctionalGroup | FunctionalGroupFactory]) –
FunctionalGroup
instances added to the building block andFunctionalGroupFactory
instances used to createFunctionalGroup
instances added to the building block.FunctionalGroup
instances are used to identify which atoms are modified duringConstructedMolecule
construction.The ids of placer atoms. These are the atoms which should be used for calculating the position of the building block. Depending on the values passed to placer_ids, and the functional groups in the building block, different placer ids will be used by the building block.
placer_ids is passed to the initializer: the passed placer ids will be used by the building block.
placer_ids is
None
and the building block has functional groups: The placer ids of the functional groups will be used as the placer ids of the building block.placer_ids is
None
and functional_groups is empty. All atoms of the molecule will be used for placer ids.
- Returns:
The building block. It will have the same atoms, bonds and atomic positions as molecule.
- Return type:
- classmethod init_from_rdkit_mol(molecule, functional_groups=(), placer_ids=None)[source]
Initialize from an
rdkit
molecule.Warning
For
rdkit
molecules with non-integer bond orders, such as 1.5, the molecule should be kekulized prior to calling this method. Otherwise, all bond orders will be set to an integer value in the building block.- Parameters:
molecule (Mol) – The molecule.
functional_groups (FunctionalGroup | FunctionalGroupFactory | list[FunctionalGroup | FunctionalGroupFactory]) –
FunctionalGroup
instances added to the building block andFunctionalGroupFactory
instances used to createFunctionalGroup
instances added to the building block.FunctionalGroup
instances are used to identify which atoms are modified duringConstructedMolecule
construction.The ids of placer atoms. These are the atoms which should be used for calculating the position of the building block. Depending on the values passed to placer_ids, and the functional groups in the building block, different placer ids will be used by the building block.
placer_ids is passed to the initializer: the passed placer ids will be used by the building block.
placer_ids is
None
and the building block has functional groups: The placer ids of the functional groups will be used as the placer ids of the building block.placer_ids is
None
and functional_groups is empty. All atoms of the molecule will be used for placer ids.
- Returns:
The building block.
- Return type:
- classmethod init_from_vabene_molecule(molecule, functional_groups=(), placer_ids=None, position_matrix=None)[source]
Initialize from a
vabene.Molecule
.Notes
The molecule is given 3D coordinates with
rdkit.ETKDGv2()
.- Parameters:
molecule (Molecule) – The
vabene.Molecule
from which to initialize.functional_groups (FunctionalGroup | FunctionalGroupFactory | list[FunctionalGroup | FunctionalGroupFactory]) –
FunctionalGroup
instances added to the building block andFunctionalGroupFactory
instances used to createFunctionalGroup
instances added to the building block.FunctionalGroup
instances are used to identify which atoms are modified duringConstructedMolecule
construction.The ids of placer atoms. These are the atoms which should be used for calculating the position of the building block. Depending on the values passed to placer_ids, and the functional groups in the building block, different placer ids will be used by the building block.
placer_ids is passed to the initializer: the passed placer ids will be used by the building block.
placer_ids is
None
and the building block has functional groups: The placer ids of the functional groups will be used as the placer ids of the building block.placer_ids is
None
and functional_groups is empty. All atoms of the molecule will be used for placer ids.
position_matrix (ndarray | None) – The position matrix the building block should use. If
None
,rdkit.ETKDGv2()
will be used to calculate it.
- Returns:
The building block.
- Return type:
- Raises:
RuntimeError – If embedding the molecule fails.
- to_rdkit_mol()
Return an
rdkit
representation.- Returns:
The molecule in
rdkit
format.- Return type:
Mol
- with_canonical_atom_ordering()[source]
Return a clone, with canonically ordered atoms.
- Returns:
The clone.
- Return type:
- with_centroid(position, atom_ids=None)[source]
Return a clone with its centroid at position.
- Parameters:
- Returns:
A clone with its centroid at position.
- Return type:
- with_displacement(displacement)[source]
Return a displaced clone.
- Parameters:
displacement (ndarray) – The displacement vector to be applied.
- Returns:
A displaced clone.
- Return type:
- with_functional_groups(functional_groups)[source]
Return a clone with specific functional groups.
- Parameters:
functional_groups (list[FunctionalGroup]) – Functional groups the clone should have.
- Returns:
The clone.
- Return type:
- with_position_matrix(position_matrix)[source]
Return a clone with atomic positions set by position_matrix.
- Parameters:
position_matrix (ndarray) – The position matrix of the clone. The shape of the matrix is
(n, 3)
.- Returns:
The clone.
- Return type:
- with_rotation_about_axis(angle, axis, origin)[source]
Return a rotated clone.
The clone is rotated by angle about axis on the origin.
- Parameters:
- Returns:
A rotated clone.
- Return type:
- with_rotation_between_vectors(start, target, origin)[source]
Return a rotated clone.
The rotation is equal to a rotation from start to target.
Given two direction vectors, start and target, this method applies the rotation required transform start to target onto the clone. The rotation occurs about the origin.
For example, if the start and target vectors are 45 degrees apart, a 45 degree rotation will be applied to the clone. The rotation will be along the appropriate direction.
The great thing about this method is that you as long as you can associate a geometric feature of the molecule with a vector, then the clone can be rotated so that this vector is aligned with target. The defined vector can be virtually anything. This means that any geometric feature of the molecule can be easily aligned with any arbitrary direction.
- Parameters:
- Returns:
A rotated clone.
- Return type:
- with_rotation_to_minimize_angle(start, target, axis, origin)[source]
Return a rotated clone.
The clone is rotated by the rotation required to minimize the angle between start and target.
Note that this function will not necessarily overlay the start and target vectors. This is because the possible rotation is restricted to the axis.
- Parameters:
- Returns:
A rotated clone.
- Return type:
- Raises:
ValueError – If target has a magnitude of 0. In this case it is not possible to calculate an angle between start and target.
- with_structure_from_file(path, extension=None)[source]
Return a clone, with its structure taken from a file.
Multiple file types are supported, namely:
.mol
,.sdf
- MDL V2000 and V3000 files.xyz
- XYZ files.mae
- Schrodinger Maestro files.coord
- Turbomole files.pdb
- PDB files
- Parameters:
- Returns:
A clone with atomic positions found in path.
- Return type: