7
$\begingroup$

I am looking for calculation of molecular fingerprints (FingerprintFunction) in v13 of Mathematica. There was a WTC talk around v12.2 showing this functionality, however, I can't seem to find this in v13.

Additionally, I tried to use the resource function MACCSKeys for my task; however, I encounter a strange behavior. When I try to invoke the function on around 100 SMILES strings, the local kernel quits. My system has 32 GB RAM and as far as I can check using free, there doesn't seem to be a memory issue. The list of molecules is provided here.

I wonder if there is any way to invoke the calculation of fingerprints or an update for the ResourceFunction.

I am running Mathematica v13 on a Linux box (Ubuntu 20.04).

$\endgroup$
2
  • 3
    $\begingroup$ Will give a larger answer later, but you can try Chemistry`MACCSKeysFingerprint[ Import["https://pastebin.com/raw/687NTfND", "SMILES"]] to get the MACCS keys for these molecules in V13. $\endgroup$
    – Jason B.
    Jan 27, 2022 at 23:20
  • 1
    $\begingroup$ I reproduced your kernel crash when using the resource function and have made a fix. It will be included in the next update to the Chemistry paclet. $\endgroup$
    – Jason B.
    Jan 28, 2022 at 22:39

1 Answer 1

12
$\begingroup$

edit: For direct access to the underlying fingerprint functions behind FeatureExtraction for molecules, see the Molecule Fingerprints paclet in the new paclet repository.

Molecule fingerprints are being integrated with the Wolfram Language through the FeatureExtraction framework, starting in version 12.3. You can obtain a set of molecule fingerprints using FeatureExtract

mols = Import["https://pastebin.com/raw/687NTfND", "SMILES"];

fprints = FeatureExtract[mols, "MoleculeTopologicalFeatures"];

Counts[Flatten[fprints]]
(* <|0 -> 2170194, 1 -> 172718|> *)

The fingerprint types available are "AtomPairs", "MoleculeTopologicalFeatures" (also known as RDKit fingerprints, which can be described as Daylight-like), and "MoleculeExtendedConnectivity" (aka circular fingerprints or ECFP).

This means you can use these fingerprints directly in the built-in supervised and unsupervised machine learning applications like FindClusters or FeatureSpacePlot.

FeatureSpacePlot[mols, 
 FeatureExtractor -> "MoleculeExtendedConnectivity", 
 LabelingFunction -> 
  Function[mol, 
   Placed[Dynamic[MoleculePlot[mol, ImageSize -> Small]], Tooltip]]]

enter image description here

Note the dynamic in the labeling function, which is nice because then the function doesn't typeset 1100 molecules before rendering the featurespace plot.

More named feature extractors will be added in the near future. There are functions in the "Chemistry`" context fingerprint for generating fingerprints, some of which may change in the future. The functions I don't expect to change include

AtomPairFingerprint
ExtendedConnectivityFingerprint
TopologicalFingerprint
MACCSKeyFingerprint

These will be documented either through the function repository interface or paclet-level documentation. These can be called on a single molecule or a list of molecules. They return NumericArray by default but can take the option "OutputType" to change that. When called with no arguments (or just options) they return a MoleculeFingerprintFunction` that can be used elsewhere. For example you can make an FCFP fingerprinter using

ExtendedConnectivityFingerprint[
  "OutputType" -> "CountVector", "UseFeatures" -> True, "Radius" -> 4
]

I will make a cloud notebook demonstrating the functions more fully and link it here shortly.

$\endgroup$
1
  • $\begingroup$ Awesome, thank you so much! $\endgroup$
    – bhopshang
    Jan 29, 2022 at 13:12

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.