Hi Payal, The function you are looking for is DataStructs.ConvertToNumpyArray. Here's a short demo:
In [3]: from rdkit import DataStructs In [4]: from rdkit.Chem import rdMolDescriptors In [5]: fpLen = 2048 In [6]: fp = rdMolDescriptors.GetHashedAtomPairFingerprintAsBitVect(Chem.MolFromSmiles('CCCC'),fpLen) In [7]: import numpy as np In [9]: v = np.array(fpLen,np.short) In [10]: DataStructs.ConvertToNumpyArray(fp,v) In [11]: v Out[11]: array([0, 0, 0, ..., 0, 0, 0], dtype=int16) In [12]: sum(v) Out[12]: 6 I hope this helps, -greg On Mon, Oct 22, 2018 at 4:29 PM Payal Chatterjee < payalchatterjee...@gmail.com> wrote: > Hi > > I am using rdkit to fetch atom pair information as AtomPairFingerprint. I > am reading from a list of molecules as individual SDF. Calling > GetHashedAtomPairFingerprintAsBitVect on the object "m" (where m is read as > each molecule), object strings are returned. > > trainResi=open(rootpath + 'trialResi.list').readlines() > trainResi = [x.strip() for x in trainResi] > print len(trainResi) > > for name in trainResi: > for ligname in glob.glob(os.path.join(modelDir+name+'.sdf'))[:]: > m = Chem.MolFromMolFile(ligname, sanitize=False, removeHs=False) > > for atm in m.GetAtoms(): > aid = atm.GetIdx() > m.UpdatePropertyCache(strict=False) ##Required because I > want to include charged molecules too! > fp = > AllChem.GetHashedAtomPairFingerprintAsBitVect(m,maxLength=APLength, \ > > fromAtoms=[aid]) > print fp > > * "fp" are returned as (including only one example) :* > <rdkit.DataStructs.cDataStructs.ExplicitBitVect object at 0x11bfc4d70> > > For my code to work further, I am converting my fp into a numpy array, > which returns [0 0 0 ..., 0 0 0] (zero values) > What am I doing wrong? > > I am new to rdkit and machine learning, and I am using jupyter notebook. > > Thanks > Payal > _______________________________________________ > Rdkit-discuss mailing list > Rdkit-discuss@lists.sourceforge.net > https://lists.sourceforge.net/lists/listinfo/rdkit-discuss >
_______________________________________________ Rdkit-discuss mailing list Rdkit-discuss@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/rdkit-discuss