Constructed Molecule
- class ConstructedMolecule(topology_graph)[source]
Bases:
Molecule
Represents constructed molecules.
Examples
Initialization
A
ConstructedMolecule
is initialized from aTopologyGraph
, which is typically initialized from someBuildingBlock
instances.import stk bb1 = stk.BuildingBlock( smiles='NCCCN', functional_groups=[stk.PrimaryAminoFactory()], ) bb2 = stk.BuildingBlock( smiles='O=CC(C=O)CC=O', functional_groups=[stk.AldehydeFactory()], ) tetrahedron = stk.cage.FourPlusSix((bb1, bb2)) cage = stk.ConstructedMolecule(tetrahedron)
Hierarchical Construction
A
ConstructedMolecule
may be used to construct otherConstructedMolecule
instances, though you will probably have to convert it to aBuildingBlock
firstimport stk bb1 = stk.BuildingBlock( smiles='NCCCN', functional_groups=[stk.PrimaryAminoFactory()], ) bb2 = stk.BuildingBlock( smiles='O=CC(C=O)CC=O', functional_groups=[stk.AldehydeFactory()], ) tetrahedron = stk.cage.FourPlusSix((bb1, bb2)) cage = stk.ConstructedMolecule(tetrahedron) benzene = stk.host_guest.Guest( building_block=stk.BuildingBlock('c1ccccc1'), ) cage_complex = stk.host_guest.Complex( host=stk.BuildingBlock.init_from_molecule(cage), guests=benzene, ) cage_complex = stk.ConstructedMolecule(cage_complex)
Obviously, the initialization of the
ConstructedMolecule
depends mostly on the specifics of theTopologyGraph
used, and the documentation of those classes should be examined for more examples.Methods
clone
()Return a clone.
get_atom_infos
([atom_ids])Yield data about atoms in the molecule.
get_atomic_positions
([atom_ids])Yield the positions of atoms.
get_atoms
([atom_ids])Yield the atoms in the molecule, ordered by id.
Yield data about bonds in the molecule.
Yield the bond in the molecule.
Yield the building blocks of the constructed molecule.
Map the id of each atom to its id under canonical ordering.
get_centroid
([atom_ids])Return the centroid.
get_direction
([atom_ids])Return a vector of best fit through the atoms.
get_maximum_diameter
([atom_ids])Return the maximum diameter.
Return the number of atoms in the molecule.
Return the number of bonds in the molecule.
get_num_building_block
(building_block)Get the number of times building_block is present.
get_plane_normal
([atom_ids])Return the normal to the plane of best fit.
Return a matrix holding the atomic positions.
init
(atoms, bonds, position_matrix, ...)Initialize a
ConstructedMolecule
from its components.Initialize a
ConstructedMolecule
.Return an
rdkit
representation.Return a clone, with canonically ordered atoms.
with_centroid
(position[, atom_ids])Return a clone with its centroid at position.
with_displacement
(displacement)Return a displaced clone.
with_position_matrix
(position_matrix)Return a clone with atomic positions set by position_matrix.
with_rotation_about_axis
(angle, axis, origin)Return a rotated clone.
with_rotation_between_vectors
(start, target, ...)Return a rotated clone.
with_rotation_to_minimize_angle
(start, ...)Return a rotated clone.
with_structure_from_file
(path[, extension])Return a clone, with its structure taken from a file.
write
(path[, atom_ids])Write the structure to a file.
- __init__(topology_graph)[source]
Initialize a
ConstructedMolecule
.- Parameters:
topology_graph (
TopologyGraph
) – The topology graph of the constructed molecule.
- 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_building_blocks()[source]
Yield the building blocks of the constructed molecule.
Building blocks are yielded in an order based on their position in the constructed molecule. For two topologically equivalent constructed molecules, but with different building blocks, equivalently positioned building blocks will be yielded at the same time.
- 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 (
Union
[int
,Iterable
[int
],None
]) – The ids of atoms which are used to calculate the centroid. Can be a singleint
, if a single atom is to be used, orNone
if all atoms are to be used.- Return type:
- Returns:
The centroid of atoms specified by atom_ids.
- Raises:
ValueError – If atom_ids has a length of
0
.
- get_direction(atom_ids=None)
Return a vector of best fit through the atoms.
- Parameters:
atom_ids (
Union
[int
,Iterable
[int
],None
]) – The ids of atoms which should be used to calculate the vector. Can be a singleint
, if a single atom is to be used, orNone
, if all atoms are to be used.- Return type:
- Returns:
The vector of best fit.
- Raises:
ValueError – If atom_ids has a length of
0
.
- 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 (
Union
[int
,Iterable
[int
],None
]) – The ids of atoms which are considered when looking for the maximum diameter. Can be a singleint
, if a single atom is to be used, orNone
, if all atoms are to be used.- Return type:
- Returns:
The maximum diameter in the molecule.
- Raises:
ValueError – If atom_ids has a length of
0
.
- get_num_atoms()
Return the number of atoms in the molecule.
- Return type:
- Returns:
The number of atoms in the molecule.
- get_num_bonds()
Return the number of bonds in the molecule.
- Return type:
- Returns:
The number of bonds in the molecule.
- get_plane_normal(atom_ids=None)
Return the normal to the plane of best fit.
- Parameters:
atom_ids (
Union
[int
,Iterable
[int
],None
]) – The ids of atoms which should be used to calculate the plane. Can be a singleint
, if a single atom is to be used, orNone
, if all atoms are to be used.- Return type:
- Returns:
Vector orthonormal to the plane of the molecule.
- Raises:
ValueError – If atom_ids has a length of
0
.
- get_position_matrix()
Return a matrix holding the atomic positions.
- Return type:
- Returns:
The array has the shape
(n, 3)
. Each row holds the x, y and z coordinates of an atom.
- classmethod init(atoms, bonds, position_matrix, atom_infos, bond_infos, num_building_blocks)[source]
Initialize a
ConstructedMolecule
from its components.- Parameters:
bond – The bonds of the molecule.
position_matrix (
ndarray
) – A(n, 3)
position matrix of the molecule.atom_infos (
tuple
[AtomInfo
,...
]) – The atom infos of the molecule.bond_infos (
tuple
[BondInfo
,...
]) – The bond infos of the molecule.num_building_blocks (
dict
[Molecule
,int
]) – Maps each building block of the constructed molecule to the number of times it is present in it.
- Return type:
- Returns:
The constructed molecule.
- classmethod init_from_construction_result(construction_result)[source]
Initialize a
ConstructedMolecule
.- Parameters:
construction_result (
ConstructionResult
) – The result of a construction, from which theConstructedMolecule
should be initialized.- Return type:
- Returns:
The constructed molecule.
- to_rdkit_mol()
Return an
rdkit
representation.- Return type:
Mol
- Returns:
The molecule in
rdkit
format.
- with_canonical_atom_ordering()[source]
Return a clone, with canonically ordered atoms.
- Return type:
- Returns:
The clone.
- with_centroid(position, atom_ids=None)[source]
Return a clone with its centroid at position.
- Parameters:
position (
ndarray
) – This array holds the position on which the centroid of the clone is going to be placed.atom_ids (
Union
[int
,Iterable
[int
],None
]) – The ids of atoms which should have their centroid set to position. Can be a singleint
, if a single atom is to be used, orNone
, if all atoms are to be used.
- Return type:
- Returns:
A clone with its centroid at position.
- with_displacement(displacement)[source]
Return a displaced clone.
- Parameters:
displacement (
ndarray
) – The displacement vector to be applied.- Return type:
- Returns:
A displaced clone.
- 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)
.- Return type:
- Returns:
The clone.
- with_rotation_about_axis(angle, axis, origin)[source]
Return a rotated clone.
The clone is rotated by angle about axis on the origin.
- Parameters:
- Return type:
- Returns:
A rotated clone.
- 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:
- Return type:
- Returns:
A rotated clone.
- 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:
- Return type:
- Returns:
A rotated clone.
- 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:
- Return type:
- Returns:
A clone with atomic positions found in path.
- write(path, atom_ids=None)[source]
Write the structure to a file.
This function will write the format based on the extension of path.
.mol
,.sdf
- MDL V3000 MOL file.xyz
- XYZ file.pdb
- PDB file
- Parameters:
path (
str
) – The path to which the molecule should be written.atom_ids (
Union
[int
,Iterable
[int
],None
]) – The atom ids of atoms to write. Can be a singleint
, if a single atom is to be used, orNone
, if all atoms are to be used. If you use this parameter, the atom ids in the file may not correspond to the atom ids in the molecule.
- Return type:
- Returns:
The molecule.