Paolo's answer provides you with the (possibly very useful) path (in atom
indices) between the two atoms.

If you just want the distances, you can use Chem.GetDistanceMatrix(m):
In [7]: Chem.GetDistanceMatrix?
Docstring:
GetDistanceMatrix( (Mol)mol [, (bool)useBO=False [, (bool)useAtomWts=False
[, (bool)force=False [, (str)prefix='']]]]) -> object :
    Returns the molecule's topological distance matrix.

      ARGUMENTS:

        - mol: the molecule to use

        - useBO: (optional) toggles use of bond orders in calculating the
distance matrix.
          Default value is 0.

        - useAtomWts: (optional) toggles using atom weights for the
diagonal elements of the
          matrix (to return a "Balaban" distance matrix).
          Default value is 0.

        - force: (optional) forces the calculation to proceed, even if
there is a cached value.
          Default value is 0.

        - prefix: (optional, internal use) sets the prefix used in the
property cache
          Default value is .

      RETURNS: a Numeric array of floats with the distance matrix



On Thu, Oct 20, 2016 at 5:47 AM, Paolo Tosco <paolo.to...@unito.it> wrote:

> Hi Hongbin,
>
> I think rdmolops.GetShortestPath() might help you with this.
>
> Cheers,
> p.
>
>
> On 10/20/16 09:47, 杨弘宾 wrote:
>
> Hi, guys.
>     I wanted to calculate the topological distance between two
> substructures. For example, the distance between carboxyl and acetyl in
> aspirin is 3 (or 4 if consider bond numbers) which are carbon, carbon and
> oxygen.
>     My idea is to compare all the matched atoms between the two
> substructures.
>
> >>> m = Chem.MolFromSmiles('CC(=O)Oc1ccccc1C(=O)O')
> >>> carboxyl = Chem.MolFromSmarts('C(=O)[OH]')
> >>> m.GetSubstructMatch(carboxyl)
> (10, 11, 12)
> >>> acetyl = Chem.MolFromSmarts('[CH3]C(=O)O')
> >>> m.GetSubstructMatch(acetyl)
> (0, 1, 2, 3)
>
> So, What I want is :
> a = [10,11,12]
> b = [0,1,2,3]
> def distrance(id1,id2):
>     m = Chem.MolFromSmiles('CC(=O)Oc1ccccc1C(=O)O')
>     ...
>     return d
> >>> min ( map(distance, [(x,y) for x in a for y in b] ) )
> 3 ( or 4)
>
> Unnecessary to consider that using m as a parameter is better.
>
> Is it possible to define the distrance function with rdkit python API ?  I
> tried to use atom pair but found that it seemed helpless.
>
> ------------------------------
> Hongbin Yang
>
>
> ------------------------------------------------------------------------------
> 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 
> listRdkit-discuss@lists.sourceforge.nethttps://lists.sourceforge.net/lists/listinfo/rdkit-discuss
>
>
>
> ------------------------------------------------------------
> ------------------
> 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
> Rdkit-discuss@lists.sourceforge.net
> https://lists.sourceforge.net/lists/listinfo/rdkit-discuss
>
>
------------------------------------------------------------------------------
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
Rdkit-discuss@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/rdkit-discuss

Reply via email to