igraph-help
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[igraph] Re: Calculation of Coordination Number


From: Lorenzo Isella
Subject: [igraph] Re: Calculation of Coordination Number
Date: Wed, 12 Nov 2008 14:14:04 +0100

> Date: Wed, 13 Feb 2008 10:47:50 +0100
> From: Tamas Nepusz <address@hidden>
> Subject: Re: [igraph] Calculation of Coordination Number
> To: Help for igraph users <address@hidden>
> Message-ID: <address@hidden>
> Content-Type: text/plain; charset=US-ASCII; format=flowed; delsp=yes
>
>> Lorenzo,
>> if your graph is `g` then
>>    degree(g)
>> gives the number of direct neighbors of each vertex (or particle).
> Just to translate it to Python: g.degree() gives the number of direct
> neighbors of each vertex. If your graph is directed, you may only want
> to count only the outgoing or the incoming edges: g.degree(igraph.OUT)
> or g.degree(igraph.IN)
>
>> So
>>    mean(degree(g))
> In Python: sum(g.degree()) / float(g.vcount())5       3       5       6       
> 5       7       4       4       6       3
>
>> (and to turn an adjacency matrix `am` into an igraph object `g` just
>> use "g <- graph.adjacency(am)")
> In Python: g = Graph.Adjacency(matrix)
> e.g. g = Graph.Adjacency([[0,1,0],[1,0,1],[0,1,0]])
>
> --
> T.
>

Hi Tamas,
Sorry for digging up such an old thread, but I believe there is something odd.
I am trying to calculate the degree of a simple graph, representing a
set of 10 connected particles.
I want to find out how many particles each particle is directly connected to.
Here are the positions of my particles in 3D: (in the form
  x1,y1, z1
  x2,y2, z2
...............
  x10,y10, z10
)


4.999290193854580139e+03 5.000533149148433040e+03 4.999447398587620228e+03
5.001064834585380595e+03 4.999035380244733460e+03 5.000528812802220273e+03
5.000120919149179826e+03 4.999124865795292862e+03 5.000077351035920401e+03
5.000139576462180230e+03 4.999916602466933000e+03 4.999383863046020451e+03
5.000189348003380474e+03 5.000829723772032594e+03 4.999904583548320261e+03
4.999636597644080211e+03 5.000028047572132891e+03 5.000298602886120534e+03
5.000987932255779924e+03 4.999317367246232607e+03 4.999519349528220118e+03
4.999271418429880214e+03 5.001011288548943412e+03 5.000380003697220673e+03
5.000688509976780551e+03 4.999983668506032700e+03 5.000274007730819903e+03
4.998610669638780564e+03 5.000219906699233434e+03 5.000186027137519886e+03

>From the data above I can calculate the 10x10 distance matrix using
the Euclidean distance between the particle coordinates [trivially
sqrt((xi-xj)^2+(yi-yj)^2+(zi-zj)^2)] and obtain an adjacency matrix by
setting equal to 1 the entries of the distance matrix smaller than
1.06 and 0 the other ones. This is what I get

1       0       0       1       1       1       0       1       0       1
0       1       1       0       0       0       1       0       1       0
0       1       1       1       0       1       1       0       1       0
1       0       1       1       1       1       1       0       1       0
1       0       0       1       1       1       0       1       1       0
1       0       1       1       1       1       0       1       1       1
0       1       1       1       0       0       1       0       1       0
1       0       0       0       1       1       0       1       0       1
0       1       1       1       1       1       1       0       1       0
1       0       0       0       0       1       0       1       0       1


However, if I run the following python code (where dist_mat is the
distance matrix)


import igraph as ig

cluster_obj=ig.Graph.Adjacency((dist_mat <= 1.06).tolist(),\
                                               ig.ADJ_UNDIRECTED)

# Now I start the calculation of the coordination number

coord_list=cluster_obj.degree() #Now I have a list with the number of 1rst
                         #neughbors of each particle


print "coord_list is, ", coord_list

These are the numbers I get

coord_list is,  [7, 5, 7, 8, 7, 9, 6, 6, 8, 5]

This looks wrong. If I consider the adjacency matrix given above, this
is the result I would expect

5       3       5       6       5       7       4       4       6       3
(where I so not consider each monomer as its own first neighbor).
Can someone please explain to me what I am doing wrong?
In case it matters, my box is running Debian testing and I have igraph
0.5 installed, built from Debian source for the amd64 architecture.
Cheers

Lorenzo




reply via email to

[Prev in Thread] Current Thread [Next in Thread]