# Re: [Rdkit-discuss] edge matrix

```Dear Marta and Guillaume,

Thank you both.
matrix.
There is something called the edge-adjaceny matrix. Its defined in several
papers by Trinajstic to calculate the M2 Zagreb indices, eg. "The Zagreb
Indices 30 Years After"
The matrix I wrote is manually written, it returns adjacent bonds instead
of atoms.```
```

KR

On Wed, Jan 17, 2018 at 5:21 PM, Marta Stępniewska-Dziubińska <
mart...@ibb.waw.pl> wrote:

> Hi Mario,
>
> What exactly do you mean by 'edge matrix'? Are you sure you provided a
> correct example? If you want to get an adjacency matrix of a molecular
> graph you can iterate over bonds to get it:
>
> from rdkit.Chem import MolFromSmiles
> import numpy as np
> m = MolFromSmiles('CC(C)CC')
> n = m.GetNumAtoms()
> E = np.zeros((n, n))
> for b in m.GetBonds():
>     i = b.GetBeginAtomIdx()
>     j = b.GetEndAtomIdx()
>     E[[i,j], [j,i]] = 1
>
>
> Hope this helps,
> Marta SD
>
>
>
> 2018-01-17 16:31 GMT+01:00 Mario Lovrić <mario.lovri...@gmail.com>:
>
>> Dear all,
>>
>> Does any one have an idea how to get an edge matrix (graph theory) out of
>> Rdkit, I digged deep but didnt find anything.
>>
>> F.example for:
>>
>> 'CC(C)CC'
>>
>>
>> it would be:
>>
>> array([[0, 1, 1, 0],
>>        [1, 0, 1, 0],
>>        [1, 1, 0, 1],
>>        [0, 0, 1, 0]])
>>
>> Thanks.
>>
>>
>> --
>> Mario Lovrić
>>
>> ------------------------------------------------------------
>> ------------------
>> 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
>>
>>
>

--
Mario Lovrić
```
```------------------------------------------------------------------------------
Check out the vibrant tech community on one of the world's most
```_______________________________________________