From c626dd02b57174bfacda49aec37ee603461190e3 Mon Sep 17 00:00:00 2001 From: Greg Landrum Date: Tue, 27 Feb 2024 13:45:06 +0100 Subject: [PATCH] switch the TFD code to use a fingerprint generator (#7187) --- rdkit/Chem/TorsionFingerprints.py | 21 +++++++++++++-------- 1 file changed, 13 insertions(+), 8 deletions(-) diff --git a/rdkit/Chem/TorsionFingerprints.py b/rdkit/Chem/TorsionFingerprints.py index 3249bbdaa..d0a28f23d 100644 --- a/rdkit/Chem/TorsionFingerprints.py +++ b/rdkit/Chem/TorsionFingerprints.py @@ -1,4 +1,4 @@ -# Copyright (C) 2014 Sereina Riniker +# Copyright (C) 2014-2024 Sereina Riniker and other RDKit contributors # # This file is part of the RDKit. # The contents are covered by the terms of the BSD license @@ -14,7 +14,7 @@ import os from rdkit import Chem, Geometry, RDConfig, rdBase from rdkit.Chem import rdchem, rdMolDescriptors - +from rdkit.Chem import rdFingerprintGenerator def _doMatch(inv, atoms): """ Helper function to check if all atoms in the list are the same @@ -88,12 +88,17 @@ def _getAtomInvariantsWithRadius(mol, radius): Return: list of atom invariants """ inv = [] - for i in range(mol.GetNumAtoms()): - info = {} - fp = rdMolDescriptors.GetMorganFingerprint(mol, radius, fromAtoms=[i], bitInfo=info) - for k in info.keys(): - if info[k][0][1] == radius: - inv.append(k) + fpg = rdFingerprintGenerator.GetMorganGenerator(radius,includeRedundantEnvironments=True) + ao = rdFingerprintGenerator.AdditionalOutput() + ao.AllocateBitInfoMap() + + fp = fpg.GetSparseCountFingerprint(mol, additionalOutput=ao) + bim = ao.GetBitInfoMap() + inv = [0]*mol.GetNumAtoms() + for k,vs in bim.items(): + for (aid,r) in vs: + if r == radius: + inv[aid] = k return inv