chemprop.utils#

Submodules#

Classes#

ClassRegistry

dict() -> new empty dictionary

Factory

EnumMapping

Enum where members are also (and must be) strings

Functions#

create_and_call_object(cls[, call_args, call_kwargs, ...])

Instantiate a class with optional init args, then call the instance with args.

make_mol(smi[, keep_h, add_h, ignore_stereo, ...])

build an RDKit molecule from a SMILES string.

parallel_execute(exe_func[, func_args, func_kwargs, ...])

Optionally executes a function in parallel.

pretty_shape(shape)

Make a pretty string from an input shape

Package Contents#

class chemprop.utils.ClassRegistry[source]#

Bases: dict[str, Type[T]]

dict() -> new empty dictionary dict(mapping) -> new dictionary initialized from a mapping object’s

(key, value) pairs

dict(iterable) -> new dictionary initialized as if via:

d = {} for k, v in iterable:

d[k] = v

dict(**kwargs) -> new dictionary initialized with the name=value pairs

in the keyword argument list. For example: dict(one=1, two=2)

register(alias=None)[source]#
Parameters:

alias (Any | Iterable[Any] | None)

__call__#
__repr__()[source]#

Return repr(self).

Return type:

str

__str__()[source]#

Return str(self).

Return type:

str

class chemprop.utils.Factory[source]#
classmethod build(clz_T, *args, **kwargs)[source]#
Parameters:

clz_T (Type[T])

Return type:

T

class chemprop.utils.EnumMapping[source]#

Bases: enum.StrEnum

Enum where members are also (and must be) strings

classmethod get(name)[source]#
Parameters:

name (str | EnumMapping)

Return type:

EnumMapping

classmethod keys()[source]#
Return type:

Iterator[str]

classmethod values()[source]#
Return type:

Iterator[str]

classmethod items()[source]#
Return type:

Iterator[tuple[str, str]]

chemprop.utils.create_and_call_object(cls, call_args=(), call_kwargs=None, init_args=(), init_kwargs=None)[source]#

Instantiate a class with optional init args, then call the instance with args. This is useful for parallel calls to methods that contain boost functions.

Parameters:
  • cls (Type)

  • call_args (tuple)

  • call_kwargs (dict)

  • init_args (tuple)

  • init_kwargs (dict)

Return type:

Any

chemprop.utils.make_mol(smi, keep_h=False, add_h=False, ignore_stereo=False, reorder_atoms=False)[source]#

build an RDKit molecule from a SMILES string.

Parameters:
  • smi (str) – a SMILES string.

  • keep_h (bool, optional) – whether to keep hydrogens in the input smiles. This does not add hydrogens, it only keeps them if they are specified. Default is False.

  • add_h (bool, optional) – whether to add hydrogens to the molecule. Default is False.

  • ignore_stereo (bool, optional) – whether to ignore stereochemical information (R/S and Cis/Trans) when constructing the molecule. Default is False.

  • reorder_atoms (bool, optional) – whether to reorder the atoms in the molecule by their atom map numbers. This is useful when the order of atoms in the SMILES string does not match the atom mapping, e.g. ‘[F:2][Cl:1]’. Default is False. NOTE: This does not reorder the bonds.

Returns:

the RDKit molecule.

Return type:

Chem.Mol

chemprop.utils.parallel_execute(exe_func, func_args=(), func_kwargs=(), n_workers=0)[source]#

Optionally executes a function in parallel.

Parameters:
  • exe_func (Callable) – function to execute.

  • func_args (Iterable) – arguments for each iteration of function execution.

  • func_kwargs (Iterable) – keyword arguments for each iteration of function execution.

  • n_workers (int, optional) – Number of parallel workers.

Returns:

list of function outputs for each argument.

Return type:

list

chemprop.utils.pretty_shape(shape)[source]#

Make a pretty string from an input shape

Example

>>> X = np.random.rand(10, 4)
>>> X.shape
(10, 4)
>>> pretty_shape(X.shape)
'10 x 4'
Parameters:

shape (Iterable[int])

Return type:

str