# Re: [Rdkit-discuss] edge matrix

```Dear Chris,

Thanks, thats it :)```
```

On Wed, Jan 17, 2018 at 6:25 PM, Chris Earnshaw <cgearns...@gmail.com>
wrote:

> I don't think there's a way to do this using RDKit itself, but it appears
> to be straightforward using Python with numpy and networkx, e.g.
>
> import numpy as np
> import networkx as nx
> a = np.matrix([[0, 1, 0, 0, 0],[1, 0, 1, 1, 0],[0, 1, 0, 0, 0],[0, 1, 0,
> 0, 1],[0, 0, 0, 1, 0]])
> b = nx.from_numpy_matrix(a)
> lg = nx.line_graph(b)
> ea = nx.adjacency_matrix(lg)
> ea
>
> matrix([[ 0.,  1.,  1.,  0.],
>         [ 1.,  0.,  1.,  0.],
>         [ 1.,  1.,  0.,  1.],
>         [ 0.,  0.,  1.,  0.]])
>
> Hope this helps - but I'm way out of my depth here!
>
> Best regards,
> Chris
>
>
> On 17 January 2018 at 16:57, Mario Lovrić <mario.lovri...@gmail.com>
> wrote:
>
>> Correct, I am looking for a rdkit-hidden-option to do it :D
>>
>> On Wed, Jan 17, 2018 at 5:56 PM, Jason Biggs <jasondbi...@gmail.com>
>> wrote:
>>
>>> I am a novice when it comes to graph theory, but it seems like what is
>>> wanted here is the adjacency matrix of the corresponding line graph (
>>> http://mathworld.wolfram.com/LineGraph.html).
>>>
>>> I don't know how to do this in python, but if I use mathematica, it goes
>>> like this
>>>
>>> adjacencyMatrix = {{0, 1, 0, 0, 0}, {1, 0, 1, 1, 0}, {0, 1, 0, 0,
>>>     0}, {0, 1, 0, 0, 1}, {0, 0, 0, 1, 0}};
>>>
>>> lineGraph = LineGraph[graph];
>>> AdjacencyMatrix[lineGraph] // MatrixForm
>>>
>>> [image: Inline image 1]
>>>
>>>
>>> Jason Biggs
>>>
>>>
>>> On Wed, Jan 17, 2018 at 10:21 AM, Marta Stępniewska-Dziubińska via
>>> Rdkit-discuss <rdkit-discuss@lists.sourceforge.net> 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
>>>>>
>>>>>
>>>>
>>>> ------------------------------------------------------------
>>>> ------------------
>>>> 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
>> 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
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
```