ConformerGenerator#

class skfp.preprocessing.ConformerGenerator(num_conformers: int = 1, max_gen_attempts: int = 1000, optimize_force_field: str | None = None, multiple_confs_select: str | None = 'min_energy', errors: str = 'raise', n_jobs: int | None = None, batch_size: int | None = None, verbose: int = 0, random_state: int | None = 0)#

Generate molecule conformer.

The implementation uses RDKit and distance geometry (DG) approach [1], with optimized ETKDGv3 improvements for small rings, macrocycles and experimental torsional angle preferences [2]. Generated conformations are optionally optimized with a force field approach.

Resulting conformation is saved in conf_id integer property of a molecule, and can be retrieved with GetIntProp("conf_id") method.

If multiple conformations are generated, one per molecule is returned. By default, the most stable conformer (with the lowest energy) is selected.

Note that conformer generation can fail, either due to not enough iterations, or it can be just impossible for a given molecule [3]. This by default results in an error, but can be controlled with error_on_gen_fail parameter. For multiple conformers, error is thrown only when no conformations can be generated, not if any one fails.

If error_on_gen_fail is False and no conformers could be generated, the number of returned molecules will be smaller than input length. For supervised learning, use transform_x_y() instead of transform method to properly return labels for those molecules.

Parameters:
  • num_conformers (int, default=1) – Number of conformers to initially generate for each molecule. Must be positive. If larger than 1, one conformation will be selected, as specified with multiple_confs_select.

  • max_gen_attempts (int, default=10000) – Number of attempts to generate a conformer. Must be positive, and should be sufficiently large, typically at least a few thousands.

  • optimize_force_field ({"UFF", "MMFF94", "MMFF94s", None}, default=None) – Force field optimization algorithm used on generated conformers. It is also used for calculation of conformer energy when selecting one of multiple conformations with multiple_confs_select="min_energy".

  • multiple_confs_select ({"min_energy", "first"}, default="min_energy") – How to select final conformer for each molecule when multiple conformers are generated. “first” selects first conformer generated by RDKit.

  • errors ({"raise", "ignore", "filter"}, default="raise") – How to handle errors during conformer generation, if after all attempts and approaches a conformer could not be generated. "raise" immediately raises any errors, with failure reason. "ignore" suppresses errors and returns molecules without conformers and conf_id property set to -1. "filter" suppresses errors and removes such conformers, resulting in potentially less output molecules than inputs. The latter two options can potentially cause problems downstream, and should be used with caution.

  • n_jobs (int, default=None) – The number of jobs to run in parallel. transform_x_y() and transform() are parallelized over the input molecules. None means 1 unless in a joblib.parallel_backend context. -1 means using all processors. See Scikit-learn documentation on n_jobs for more details.

  • batch_size (int, default=None) – Number of inputs processed in each batch. None divides input data into equal-sized parts, as many as n_jobs.

  • verbose (int, default=0) – Controls the verbosity when generating conformers.

  • random_state (int or None, default=0) – Controls the randomness of conformer generation. Note that in constrast to most classes, here it cannot be a RandomState instance, only an integer.

References

Examples

>>> from skfp.preprocessing import MolFromSmilesTransformer, ConformerGenerator
>>> smiles = ["O", "CC", "[C-]#N", "CC=O"]
>>> conf_gen = ConformerGenerator()
>>> conf_gen
ConformerGenerator()
>>> mol_from_smiles = MolFromSmilesTransformer()
>>> mols = mol_from_smiles.transform(smiles)
>>> conf_gen.transform(mols) 
[<rdkit.Chem.PropertyMol.PropertyMol...>, ..., <rdkit.Chem.PropertyMol.PropertyMol...>]

Methods

fit(X[, y])

Unused, kept for Scikit-learn compatibility.

fit_transform(X[, y])

The same as transform method, kept for Scikit-learn compatibility.

get_metadata_routing()

Get metadata routing of this object.

get_params([deep])

Get parameters for this estimator.

set_output(*[, transform])

Set output container.

set_params(**params)

Set the parameters of this estimator.

set_transform_request(*[, copy])

Request metadata passed to the transform method.

transform(X[, copy])

Generate conformers for molecules.

transform_x_y(X, y[, copy])

Generate conformers for molecules.

fit(X, y=None, **fit_params)#

Unused, kept for Scikit-learn compatibility.

Parameters:
  • X (any) – Unused, kept for Scikit-learn compatibility.

  • y (any) – Unused, kept for Scikit-learn compatibility.

  • **fit_params (dict) – Unused, kept for Scikit-learn compatibility.

Return type:

self

fit_transform(X, y=None, **fit_params)#

The same as transform method, kept for Scikit-learn compatibility.

Parameters:
  • X (any) – See transform method.

  • y (any) – See transform method.

  • **fit_params (dict) – Unused, kept for Scikit-learn compatibility.

Returns:

X_new – See transform method.

Return type:

any

get_metadata_routing()#

Get metadata routing of this object.

Please check User Guide on how the routing mechanism works.

Returns:

routing – A MetadataRequest encapsulating routing information.

Return type:

MetadataRequest

get_params(deep=True)#

Get parameters for this estimator.

Parameters:

deep (bool, default=True) – If True, will return the parameters for this estimator and contained subobjects that are estimators.

Returns:

params – Parameter names mapped to their values.

Return type:

dict

set_output(*, transform=None)#

Set output container.

See Introducing the set_output API for an example on how to use the API.

Parameters:

transform ({"default", "pandas", "polars"}, default=None) –

Configure output of transform and fit_transform.

  • ”default”: Default output format of a transformer

  • ”pandas”: DataFrame output

  • ”polars”: Polars output

  • None: Transform configuration is unchanged

Added in version 1.4: “polars” option was added.

Returns:

self – Estimator instance.

Return type:

estimator instance

set_params(**params)#

Set the parameters of this estimator.

The method works on simple estimators as well as on nested objects (such as Pipeline). The latter have parameters of the form <component>__<parameter> so that it’s possible to update each component of a nested object.

Parameters:

**params (dict) – Estimator parameters.

Returns:

self – Estimator instance.

Return type:

estimator instance

set_transform_request(*, copy: bool | None | str = '$UNCHANGED$') ConformerGenerator#

Request metadata passed to the transform method.

Note that this method is only relevant if enable_metadata_routing=True (see sklearn.set_config()). Please see User Guide on how the routing mechanism works.

The options for each parameter are:

  • True: metadata is requested, and passed to transform if provided. The request is ignored if metadata is not provided.

  • False: metadata is not requested and the meta-estimator will not pass it to transform.

  • None: metadata is not requested, and the meta-estimator will raise an error if the user provides it.

  • str: metadata should be passed to the meta-estimator with this given alias instead of the original name.

The default (sklearn.utils.metadata_routing.UNCHANGED) retains the existing request. This allows you to change the request for some parameters and not others.

Added in version 1.3.

Note

This method is only relevant if this estimator is used as a sub-estimator of a meta-estimator, e.g. used inside a Pipeline. Otherwise it has no effect.

Parameters:

copy (str, True, False, or None, default=sklearn.utils.metadata_routing.UNCHANGED) – Metadata routing for copy parameter in transform.

Returns:

self – The updated object.

Return type:

object

transform(X: Sequence[Mol], copy: bool = False) list[PropertyMol]#

Generate conformers for molecules.

If errors is set to "filter", then in case of errors less than n_samples values may be returned. If errors is set to "ignore", some molecules may be returned without conformers generated and with conf_id property set to -1.

Parameters:
  • X ({sequence, array-like} of shape (n_samples,)) – Sequence containing RDKit Mol objects.

  • copy (bool, default=True) – Copy the input X or not. In contrast to most classes, input molecules are copied by default, since RDKit modifies them with conformers in place.

Returns:

X – List with RDKit PropertyMol objects, each one with conformers computed and conf_id integer property set.

Return type:

list of shape (n_samples_conf_gen,)

transform_x_y(X: Sequence[Mol], y: ndarray, copy: bool = False) tuple[list[PropertyMol], ndarray]#

Generate conformers for molecules.

If errors is set to "filter", then in case of errors less than n_samples values may be returned. If errors is set to "ignore", some molecules may be returned without conformers generated and with conf_id property set to -1.

Parameters:
  • X ({sequence, array-like} of shape (n_samples,)) – Sequence containing RDKit Mol objects.

  • y (np.ndarray of shape (n_samples,)) – Array with labels for molecules.

  • copy (bool, default=True) – Copy the input X or not. In contrast to most classes, input molecules are copied by default, since RDKit modifies them with conformers in place.

Returns:

  • X (list of shape (n_samples_conf_gen,)) – List with RDKit PropertyMol objects, each one with conformers computed and conf_id integer property set.

  • y (np.ndarray of shape (n_samples_conf_gen,)) – Array with labels for molecules.