Re: [Rdkit-discuss] Molecule losing properties
Joos, I'm glad you found the issue. Perhaps GetMolFrags should retain or have an option to retain public properties such as sd data. Brian Kelley > On Jan 21, 2016, at 8:14 AM, Joos Kienerwrote: > > Hi Brian, > > thanks for your reply. I now figured out the issue. The SDF I load has a few > multi-component entries and I wanted to just look at the first component to > avoid any issues with such molecules. > > hence I had following step: > > mols = [Chem.GetMolFrags(x, asMols=True)[0] for x in mols] > > And this then breaks property for all molecules that where multi-component > but not for the other ones. > > I fixed it by reassigning properties. If anyone know a nicer way to do this > would also be good: > > for idx in range(0,len(mols)): > mol = mols[idx] > fragments = Chem.GetMolFrags(mol, asMols=True) > if len(fragments) > 1: > first_frag = fragments[0] > for prop in mol.GetPropNames(): > first_frag.SetProp(prop, mol.GetProp(prop)) > mols[idx]=first_frag > > > Best Regards, > > Joos > > 2016-01-21 13:26 GMT+01:00 Brian Kelley : >> Joos, >> >> In your second loop, could you "print repr(prop)"as opposed to "print >> prop" It could be that the name actually has a space in it which the sd >> format supports and can drive one to distraction. >> >> >> Brian Kelley >> >>> On Jan 21, 2016, at 2:11 AM, Joos Kiener wrote: >>> >>> Hi all, >>> >>> I have a strange issue. I'm trying to display pairs of molecules (the pair >>> has a certain similarity threshold) and show a property for both molecules. >>> This is in IPyhton Notebook. >>> >>> The weird thing is the first molecule of the pair loses all properties: >>> >>> toShow=[] >>> lbls=[] >>> for idx in pairs: >>> did=dindices[idx] >>> mol1=und[did[0]] # und = list of molecules loaded from sd-file >>> mol2=und[did[1]] >>> toShow.append(mol1) >>> toShow.append(mol2) >>> lbls.append('Active: %.2f'%mol1.GetProp('Activ')) >>> lbls.append('Active: %.2f'%mol2.GetProp('Activ')) >>> Draw.MolsToGridImage(toShow,molsPerRow=2,legends=lbls) >>> --- >>> KeyError Traceback (most recent call last) >>> in () >>> 7 toShow.append(mol1) >>> 8 toShow.append(mol2) >>> > 9 lbls.append('Active: %.2f'%mol1.GetProp('Activ')) >>> 10 lbls.append('Active: %.2f'%mol2.GetProp('Activ')) >>> 11 Draw.MolsToGridImage(toShow,molsPerRow=2,legends=lbls) >>> >>> KeyError: 'Activ' >>> >>> >>> If I change the code (remove the label) and print all properties of mol1, >>> the are displayed correctly. >>> >>> toShow=[] >>> lbls=[] >>> for idx in pairs: >>> did=dindices[idx] >>> mol1=und[did[0]] >>> mol2=und[did[1]] >>> toShow.append(mol1) >>> toShow.append(mol2) >>> for prop in mol1.GetPropNames(): >>> print prop + ": " + mol1.GetProp(prop) >>> #lbls.append('Active: %.2f'%mol1.GetProp('Activ')) >>> #lbls.append('Active: %.2f'%mol2.GetProp('Activ')) >>> Draw.MolsToGridImage(toShow,molsPerRow=2) >>> >>> This shows all the properties of mol1 plus draws the grid. No error. >>> >>> However directly accessing the property by name fails with key error: >>> toShow=[] >>> lbls=[] >>> for idx in pairs: >>> did=dindices[idx] >>> mol1=und[did[0]] >>> mol2=und[did[1]] >>> toShow.append(mol1) >>> toShow.append(mol2) >>> print mol1.GetProp('Activ') >>> #lbls.append('Active: %.2f'%mol1.GetProp('Activ')) >>> #lbls.append('Active: %.2f'%mol2.GetProp('Activ')) >>> Draw.MolsToGridImage(toShow,molsPerRow=2) >>> --- >>> KeyError Traceback (most recent call last) >>> in () >>> 7 toShow.append(mol1) >>> 8 toShow.append(mol2) >>> > 9 print mol1.GetProp('Activ') >>> 10 #lbls.append('Active: %.2f'%mol1.GetProp('Activ')) >>> 11 #lbls.append('Active: %.2f'%mol2.GetProp('Activ')) >>> >>> KeyError: 'Activ' >>> >>> This all works fine for mol2: >>> >>> >>> toShow=[] >>> lbls=[] >>> for idx in pairs: >>> did=dindices[idx] >>> mol1=und[did[0]] >>> mol2=und[did[1]] >>> toShow.append(mol1) >>> toShow.append(mol2) >>> print mol2.GetProp('Activ') >>> #lbls.append('Active: %.2f'%mol1.GetProp('Activ')) >>> #lbls.append('Active: %.2f'%mol2.GetProp('Activ')) >>> Draw.MolsToGridImage(toShow,molsPerRow=2) >>> 2.5 >>> 7.7 >>> 10.93 >>> 2.0434 >>> 190.0 >>> 25.0 >>> ... >>> What is going on here??? How can I resolve this? >>> Best Regards, >>> >>> Joos >>> -- >>> Site24x7 APM Insight: Get Deep Visibility into Application Performance >>> APM + Mobile APM + RUM: Monitor
Re: [Rdkit-discuss] Molecule losing properties
Joos, In your second loop, could you "print repr(prop)"as opposed to "print prop" It could be that the name actually has a space in it which the sd format supports and can drive one to distraction. Brian Kelley > On Jan 21, 2016, at 2:11 AM, Joos Kienerwrote: > > Hi all, > > I have a strange issue. I'm trying to display pairs of molecules (the pair > has a certain similarity threshold) and show a property for both molecules. > This is in IPyhton Notebook. > > The weird thing is the first molecule of the pair loses all properties: > > toShow=[] > lbls=[] > for idx in pairs: > did=dindices[idx] > mol1=und[did[0]] # und = list of molecules loaded from sd-file > mol2=und[did[1]] > toShow.append(mol1) > toShow.append(mol2) > lbls.append('Active: %.2f'%mol1.GetProp('Activ')) > lbls.append('Active: %.2f'%mol2.GetProp('Activ')) > Draw.MolsToGridImage(toShow,molsPerRow=2,legends=lbls) > --- > KeyError Traceback (most recent call last) > in () > 7 toShow.append(mol1) > 8 toShow.append(mol2) > > 9 lbls.append('Active: %.2f'%mol1.GetProp('Activ')) > 10 lbls.append('Active: %.2f'%mol2.GetProp('Activ')) > 11 Draw.MolsToGridImage(toShow,molsPerRow=2,legends=lbls) > > KeyError: 'Activ' > > > If I change the code (remove the label) and print all properties of mol1, the > are displayed correctly. > > toShow=[] > lbls=[] > for idx in pairs: > did=dindices[idx] > mol1=und[did[0]] > mol2=und[did[1]] > toShow.append(mol1) > toShow.append(mol2) > for prop in mol1.GetPropNames(): > print prop + ": " + mol1.GetProp(prop) > #lbls.append('Active: %.2f'%mol1.GetProp('Activ')) > #lbls.append('Active: %.2f'%mol2.GetProp('Activ')) > Draw.MolsToGridImage(toShow,molsPerRow=2) > > This shows all the properties of mol1 plus draws the grid. No error. > > However directly accessing the property by name fails with key error: > toShow=[] > lbls=[] > for idx in pairs: > did=dindices[idx] > mol1=und[did[0]] > mol2=und[did[1]] > toShow.append(mol1) > toShow.append(mol2) > print mol1.GetProp('Activ') > #lbls.append('Active: %.2f'%mol1.GetProp('Activ')) > #lbls.append('Active: %.2f'%mol2.GetProp('Activ')) > Draw.MolsToGridImage(toShow,molsPerRow=2) > --- > KeyError Traceback (most recent call last) > in () > 7 toShow.append(mol1) > 8 toShow.append(mol2) > > 9 print mol1.GetProp('Activ') > 10 #lbls.append('Active: %.2f'%mol1.GetProp('Activ')) > 11 #lbls.append('Active: %.2f'%mol2.GetProp('Activ')) > > KeyError: 'Activ' > > This all works fine for mol2: > > > toShow=[] > lbls=[] > for idx in pairs: > did=dindices[idx] > mol1=und[did[0]] > mol2=und[did[1]] > toShow.append(mol1) > toShow.append(mol2) > print mol2.GetProp('Activ') > #lbls.append('Active: %.2f'%mol1.GetProp('Activ')) > #lbls.append('Active: %.2f'%mol2.GetProp('Activ')) > Draw.MolsToGridImage(toShow,molsPerRow=2) > 2.5 > 7.7 > 10.93 > 2.0434 > 190.0 > 25.0 > ... > What is going on here??? How can I resolve this? > Best Regards, > > Joos > -- > Site24x7 APM Insight: Get Deep Visibility into Application Performance > APM + Mobile APM + RUM: Monitor 3 App instances at just $35/Month > Monitor end-to-end web transactions and take corrective actions now > Troubleshoot faster and improve end-user experience. Signup Now! > http://pubads.g.doubleclick.net/gampad/clk?id=267308311=/4140 > ___ > Rdkit-discuss mailing list > Rdkit-discuss@lists.sourceforge.net > https://lists.sourceforge.net/lists/listinfo/rdkit-discuss -- Site24x7 APM Insight: Get Deep Visibility into Application Performance APM + Mobile APM + RUM: Monitor 3 App instances at just $35/Month Monitor end-to-end web transactions and take corrective actions now Troubleshoot faster and improve end-user experience. Signup Now! http://pubads.g.doubleclick.net/gampad/clk?id=267308311=/4140___ Rdkit-discuss mailing list Rdkit-discuss@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/rdkit-discuss
[Rdkit-discuss] Molecule losing properties
Hi all, I have a strange issue. I'm trying to display pairs of molecules (the pair has a certain similarity threshold) and show a property for both molecules. This is in IPyhton Notebook. The weird thing is the first molecule of the pair loses all properties: toShow=[] lbls=[] for idx in pairs: did=dindices[idx] mol1=und[did[0]] # und = list of molecules loaded from sd-file mol2=und[did[1]] toShow.append(mol1) toShow.append(mol2) lbls.append('Active: %.2f'%mol1.GetProp('Activ')) lbls.append('Active: %.2f'%mol2.GetProp('Activ')) Draw.MolsToGridImage(toShow,molsPerRow=2,legends=lbls) ---KeyError Traceback (most recent call last) in () 7 toShow.append(mol1) 8 toShow.append(mol2)> 9 lbls.append('Active: %.2f'%mol1.GetProp('Activ')) 10 lbls.append('Active: %.2f'%mol2.GetProp('Activ')) 11 Draw.MolsToGridImage(toShow,molsPerRow=2,legends=lbls) KeyError: 'Activ' If I change the code (remove the label) and print all properties of mol1, the are displayed correctly. toShow=[] lbls=[] for idx in pairs: did=dindices[idx] mol1=und[did[0]] mol2=und[did[1]] toShow.append(mol1) toShow.append(mol2) for prop in mol1.GetPropNames(): print prop + ": " + mol1.GetProp(prop) #lbls.append('Active: %.2f'%mol1.GetProp('Activ')) #lbls.append('Active: %.2f'%mol2.GetProp('Activ')) Draw.MolsToGridImage(toShow,molsPerRow=2) This shows all the properties of mol1 plus draws the grid. No error. However directly accessing the property by name fails with key error: toShow=[] lbls=[] for idx in pairs: did=dindices[idx] mol1=und[did[0]] mol2=und[did[1]] toShow.append(mol1) toShow.append(mol2) print mol1.GetProp('Activ') #lbls.append('Active: %.2f'%mol1.GetProp('Activ')) #lbls.append('Active: %.2f'%mol2.GetProp('Activ')) Draw.MolsToGridImage(toShow,molsPerRow=2) ---KeyError Traceback (most recent call last) in () 7 toShow.append(mol1) 8 toShow.append(mol2)> 9 print mol1.GetProp('Activ') 10 #lbls.append('Active: %.2f'%mol1.GetProp('Activ')) 11 #lbls.append('Active: %.2f'%mol2.GetProp('Activ')) KeyError: 'Activ' This all works fine for mol2: toShow=[] lbls=[] for idx in pairs: did=dindices[idx] mol1=und[did[0]] mol2=und[did[1]] toShow.append(mol1) toShow.append(mol2) print mol2.GetProp('Activ') #lbls.append('Active: %.2f'%mol1.GetProp('Activ')) #lbls.append('Active: %.2f'%mol2.GetProp('Activ')) Draw.MolsToGridImage(toShow,molsPerRow=2) 2.5 7.7 10.93 2.0434 190.0 25.0 ... What is going on here??? How can I resolve this? Best Regards, Joos -- Site24x7 APM Insight: Get Deep Visibility into Application Performance APM + Mobile APM + RUM: Monitor 3 App instances at just $35/Month Monitor end-to-end web transactions and take corrective actions now Troubleshoot faster and improve end-user experience. Signup Now! http://pubads.g.doubleclick.net/gampad/clk?id=267308311=/4140___ Rdkit-discuss mailing list Rdkit-discuss@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/rdkit-discuss