spindry.Molecule

class spindry.Molecule(atoms, bonds, position_matrix)[source]

Bases: object

Molecule to optimize.

Parameters:
  • atoms (tuple[Atom, ...]) – Atoms that define the molecule.

  • bonds (tuple[Bond, ...]) – Bonds between atoms that define the molecule.

  • position_matrix (np.ndarray) – A (n, 3) matrix holding the position of every atom in the Molecule.

Methods

get_atoms

Yield the atoms in the molecule, ordered as input.

get_bonds

Yield the bonds in the molecule, ordered as input.

get_centroid

Return the centroid.

get_num_atoms

Return the number of atoms in the molecule.

get_position_matrix

Return a matrix holding the atomic positions.

get_subunits

Get connected graphs based on Molecule separated by bonds.

with_displacement

Return a displaced clone Molecule.

with_position_matrix

Return clone Molecule with new position matrix.

write_pdb_file

Write basic .pdb file of Molecule to path.

write_xyz_content

Write basic .xyz file content of Molecule.

write_xyz_file

Write basic .xyz file of Molecule to path.

Attributes

atoms

bonds

position_matrix

get_atoms()[source]

Yield the atoms in the molecule, ordered as input.

Return type:

abc.Iterable[Atom]

get_bonds()[source]

Yield the bonds in the molecule, ordered as input.

Return type:

abc.Iterable[Bond]

get_centroid(atom_ids=None)[source]

Return the centroid.

Parameters:

atom_ids (tuple | set | None) – iterable of int, optional The ids of atoms which are used to calculate the centroid. Can be a single int, if a single atom is to be used, or None if all atoms are to be used.

Returns:

The centroid of atoms specified by atom_ids.

Raises:

If atom_ids has a length of 0.

Return type:

float

get_num_atoms()[source]

Return the number of atoms in the molecule.

Return type:

int

get_position_matrix()[source]

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:

ndarray

get_subunits(bond_pair_ids)[source]

Get connected graphs based on Molecule separated by bonds.

Parameters:

bond_pair_ids (tuple) – iterable of tuple of ints Iterable of pairs of atom ids with bond between them to optimize.

Returns:

The subunits of mol split by bonds defined by bond_pair_ids. Key is subunit identifier, Value is iterable of atom ids in subunit.

Return type:

subunits

with_displacement(displacement)[source]

Return a displaced clone Molecule.

Parameters:

displacement (ndarray) – The displacement vector to be applied.

Return type:

Molecule

with_position_matrix(position_matrix)[source]

Return clone Molecule with new position matrix.

Parameters:

position_matrix (ndarray) – A position matrix of the clone. The shape of the matrix is (n, 3).

Return type:

Molecule

write_pdb_file(path)[source]

Write basic .pdb file of Molecule to path.

Parameters:

path (str)

Return type:

None

write_xyz_content()[source]

Write basic .xyz file content of Molecule.

Return type:

list[str]

write_xyz_file(path)[source]

Write basic .xyz file of Molecule to path.

Connectivity is not maintained in this file type!

Parameters:

path (str)

Return type:

None

atoms: tuple[Atom, ...]
bonds: tuple[Bond, ...]
position_matrix: np.ndarray