morfeus.utils module#

Helper functions.

class morfeus.utils.Import(module, item=None, alias=None)[source]#

Bases: object

Class for handling optional dependency imports.

Parameters:
  • module (str) –

  • item (str | None) –

  • alias (str | None) –

morfeus.utils.check_distances(elements, coordinates, check_atom, radii=None, check_radius=0, excluded_atoms=None, epsilon=0, radii_type='crc')[source]#

Check which atoms are within clashing vdW radii distances.

Parameters:
  • elements (Iterable[int] | Iterable[str]) – Elements as atomic symbols or numbers

  • coordinates (ArrayLike2D) – Coordinates (Å)

  • check_atom (int) – Index of atom to check against (1-indexed)

  • radii (ArrayLike1D | None) – vdW radii (Å)

  • check_radius (float) – Radius to use for check_atom (Å)

  • excluded_atoms (Sequence[int] | None) – Atom indices to exclude (1-indexed)

  • epsilon (float) – Numeric term add to the radii (Å)

  • radii_type (str) – Radii type: ‘alvarez’, ‘bondi’, ‘crc’, ‘pyykko’, ‘rahm’ or ‘truhlar’

Returns:

Atom indices within vdW distance of check atom.

Return type:

within_list

morfeus.utils.convert_elements(elements: Iterable[int] | Iterable[str], output: Literal['numbers']) list[int][source]#
morfeus.utils.convert_elements(elements: Iterable[int] | Iterable[str], output: Literal['symbols']) list[str]

Converts elements to atomic symbols or numbers.

Parameters:
  • elements – Elements as atomic symbols or numbers

  • output – Output format: ‘numbers’ (default) or ‘symbols’.

Returns:

Converted elements

Return type:

elements

Raises:
  • TypeError – When input type not supported

  • ValueError – When output not supported

morfeus.utils.get_connectivity_matrix(coordinates, elements=None, radii=None, radii_type='pyykko', scale_factor=1.2)[source]#

Get connectivity matrix from covalent radii.

Parameters:
  • elements (Iterable[int] | Iterable[str] | None) – Elements as atomic symbols or numbers

  • coordinates (ArrayLike2D) – Coordinates (Å)

  • radii (ArrayLike1D | None) – Radii (Å)

  • radii_type (str) – Radii type: ‘pyykko’

  • scale_factor (float) – Factor for scaling covalent radii

Returns:

Connectivity matrix

Return type:

connectivity_matrix

Raises:

RuntimeError – When neither elements nor radii given

morfeus.utils.get_excluded_from_connectivity(connectivity_matrix, center_atoms, connected_atoms)[source]#

Get atom indices to exclude bassed on connectivity and fragmentation.

Convenience function that determines atoms to exclude from a calculation of a larger structure with multiple fragments. Connected atoms belong to the fragment of interest, e.g., a ligand. Center atoms are those of e.g. a central metal atom that. By default, the center atoms are added to the excluded ones.

Parameters:
  • connectivity_matrix (_SupportsArray[dtype[Any]] | _NestedSequence[_SupportsArray[dtype[Any]]] | bool | int | float | complex | str | bytes | _NestedSequence[bool | int | float | complex | str | bytes]) – Connectivity matrix

  • center_atoms (_SupportsArray[dtype[Any]] | _NestedSequence[_SupportsArray[dtype[Any]]] | bool | int | float | complex | str | bytes | _NestedSequence[bool | int | float | complex | str | bytes]) – Atoms of central unit which connects to fragment (1-indexed)

  • connected_atoms (_SupportsArray[dtype[Any]] | _NestedSequence[_SupportsArray[dtype[Any]]] | bool | int | float | complex | str | bytes | _NestedSequence[bool | int | float | complex | str | bytes]) – Atoms of fragment (1-indexed)

Returns:

Atom indices to exclude

Return type:

excluded_atoms

Raises:

ValueError – When connected atoms belong to different fragments or when connected atoms belong to same fragment as other neighbors of center atoms (1-indexed)

morfeus.utils.get_radii(elements, radii_type='crc', scale=1)[source]#

Gets radii from element identifiers.

Parameters:
  • elements (Iterable[int] | Iterable[str]) – Elements as atomic symbols or numbers

  • radii_type (str) – Radii type: ‘alvarez’, ‘bondi’, ‘crc’, ‘pyykko’ ‘rahm’ or ‘truhlar’

  • scale (float) – Scaling factor

Returns:

Radii (Å)

Return type:

radii

morfeus.utils.requires_dependency(imports, _globals)[source]#

Decorator factory to control optional dependencies.

Parameters:
  • imports (Sequence[Import]) – Imports

  • _globals (dict) – Global symbol table from calling module.

Returns:

Either ‘noop_decorator’ that returns the original function or

’error_decorator’ that raises an ImportError and lists absent dependencies.

Return type:

decorator

morfeus.utils.requires_executable(executables)[source]#

Decorator factory to control optional executables.

Parameters:

executables (Sequence[str]) – Names of executables

Returns:

Either ‘noop_decorator’ that returns the original function or

’error_decorator’ that raises an OSError and lists absent executables.

Return type:

decorator