route_distances package

Subpackages

Submodules

route_distances.clustering module

Module containing a class to help out with clustering

class route_distances.clustering.ClusteringHelper(distances)

Bases: object

A helper class to perform clustering of items based on a pre-computed distance matrix.

The clustering is the agglomerative clustering algorithm implemented in Scikit-learn.

Parameters:

distances (np.ndarray)

property labels: ndarray

Return the cluster labels

fixed_clustering(n_clusters, **kwargs)

Make a fixed number of clusters.

Additional arguments to the clustering algorithm can be passed in as key-word arguments

Parameters:
  • n_clusters (int) – the desired number of clusters

  • kwargs (Any)

Returns:

the cluster index for each observation

Return type:

ndarray

linkage_matrix(**kwargs)

Compute the linkage matrix.

Additional arguments to the clustering algorithm can be passed in as key-word arguments

Returns:

the linkage matrix

Parameters:

kwargs (Any)

Return type:

ndarray

optimize(max_clusters=5, **kwargs)

Optimize the number of cluster based Silhouette metric.

Additional arguments to the clustering algorithm can be passed in as key-word arguments

Parameters:
  • max_clusters (int) – the maximum number of clusters to consider

  • kwargs (Any)

Returns:

the cluster index for each observation

Return type:

ndarray

static cluster(distances, n_clusters, **kwargs)

Cluster items based on a pre-computed distance matrix using a hierarchical clustering.

Parameters:
  • distances (ndarray) – the distance matrix

  • n_clusters (int) – the desired number of clusters

  • kwargs (Any)

Returns:

the cluster index for each observation

Return type:

ndarray

route_distances.route_distances module

Module containing a factory function for making predictions of route distances

route_distances.route_distances.route_distances_calculator(model, **kwargs)

Return a callable that given a list routes as dictionaries calculate the squared distance matrix

Parameters:
  • model (str)

  • kwargs (Any)

Returns:

Return type:

Callable[[List[Dict[str, Any]]], ndarray]

route_distances.validation module

Module containing routes to validate AiZynthFinder-like input dictionaries

class route_distances.validation.ReactionNode(**data)

Bases: BaseModel

Node representing a reaction

Parameters:

data (Any)

type: Annotated[str, StringConstraints(pattern='^reaction$')]
children: List[MoleculeNode]
model_config: ClassVar[ConfigDict] = {}

Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].

class route_distances.validation.MoleculeNode(*, smiles, type, children=None)

Bases: BaseModel

Node representing a molecule

Parameters:
  • smiles (str)

  • type (Annotated[str, StringConstraints(strip_whitespace=None, to_upper=None, to_lower=None, strict=None, min_length=None, max_length=None, pattern=^mol$)])

  • children (Annotated[List[ReactionNode], Len(min_length=1, max_length=1)] | None)

smiles: str
type: Annotated[str, StringConstraints(pattern='^mol$')]
children: conlist(ReactionNode, min_length=1, max_length=1) | None
model_config: ClassVar[ConfigDict] = {}

Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].

route_distances.validation.validate_dict(dict_)

Check that the route dictionary is a valid structure

Parameters:
  • dict – the route as dictionary

  • dict_ (Dict[str, Any])

Return type:

None

Module contents