Re: [Rdkit-discuss] GetMolFrags asMols with persistent atom indexes
Open-Source Cheminformatics and Machine Learning
Brought to you by:
glandrum
From: Paolo T. <pao...@gm...> - 2018-06-26 11:25:29
|
Hi Josh, if you pass empty lists as the frags and as the fragsMolAtomMapping parameters of GetMolFrags() they will be filled with indices referring to the indices of the original molecule (see lines highlighted in red below). Hope that helps, cheers p. GetMolFrags(...) GetMolFrags( (Mol)mol [, (bool)asMols=False [, (bool)sanitizeFrags=True [, (AtomPairsParameters)frags=None [, (AtomPairsParameters)fragsMolAtomMapping=None]]]]) -> tuple : Finds the disconnected fragments from a molecule. For example, for the molecule 'CC(=O)[O-].[NH3+]C' GetMolFrags() returns ((0, 1, 2, 3), (4, 5)) ARGUMENTS: - mol: the molecule to use - asMols: (optional) if this is provided and true, the fragments will be returned as molecules instead of atom ids. - sanitizeFrags: (optional) if this is provided and true, the fragments molecules will be sanitized before returning them. - frags: (optional, defaults to None) if this is provided as an empty list, the result will be mol.GetNumAtoms() long on return and will contain the fragment assignment for each Atom - fragsMolAtomMapping: (optional, defaults to None) if this is provided as an empty list, the result will be a a numFrags long list on return, and each entry will contain the indices of the Atoms in that fragment: [(0, 1, 2, 3), (4, 5)] RETURNS: a tuple of tuples with IDs for the atoms in each fragment or a tuple of molecules. On 26/06/2018 10:29, Joshua Meyers wrote: > Hey All, > > I am chopping parts out of molecules and picking up the pieces using > the Chem.GetMolFrags() function. > I would like to separate fragments into distinct mol objects but keep > the original atom indexes however setting the asMols=True flag seems > to reset the indexes, is this expected behaviour? Is there a way > around this? > > Here's some code: > > In [1]: from rdkit import Chem > > In [2]: m = Chem.MolFromSmiles('c1ccccc1.CCO') > > In [3]: Chem.GetMolFrags(m) > Out[3]: ((0, 1, 2, 3, 4, 5), (6, 7, 8)) <----- desired indexes > > In [4]: frags = Chem.GetMolFrags(m, asMols=True) > > In [5]: for frag in frags: > ...: print([a.GetIdx() for a in frag.GetAtoms()]) > ...: > [0, 1, 2, 3, 4, 5] > [0, 1, 2] < ------ indexes have been reset > > > Many thanks in advance, > Josh > > > ------------------------------------------------------------------------------ > Check out the vibrant tech community on one of the world's most > engaging tech sites, Slashdot.org! http://sdm.link/slashdot > > > _______________________________________________ > Rdkit-discuss mailing list > Rdk...@li... > https://lists.sourceforge.net/lists/listinfo/rdkit-discuss |