-
-
Save mkhorton/aefa5378ec7ec3160876 to your computer and use it in GitHub Desktop.
Attempt to understand graph-tool geometric graph generation + possible bug
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# coding: utf-8 | |
import graph_tool.all as gt | |
import math | |
import numpy as np | |
# basis vectors for hexagonal-close-packed lattice | |
basis = np.array([[ 0. , 0. , 0. ], | |
[ 0.5 , 0.5 , 0. ], | |
[ 0.5 , 0.16666667, 0.5 ], | |
[ 0. , 0.66666667, 0.5 ]]) | |
# unit cell for hexagonal-close-packed lattice | |
cell = np.array([1.0, math.sqrt(3), math.sqrt(8/3.)]) | |
def make_points(size): | |
'''Generates a hexagonal-close-packed lattice of a given size from basis vectors and unit cell.''' | |
points = [] | |
for i in range(size): | |
for j in range(size): | |
for k in range(size): | |
for v in basis: | |
points.append((v+[i,j,k])*cell) | |
return np.array(points) | |
# This example works. | |
size = 3 | |
points = make_points(size) | |
g3, pos3 = gt.geometric_graph(points, 1.00000001, [(0,cell[0]*size),(0,cell[1]*size),(0,cell[2]*size)]) | |
print g3 | |
print float(g3.num_edges())/g3.num_vertices() # should be 6.0 | |
# This example doesn't seem to work. | |
# Note that points array here is a subset of the points array for size=3 | |
size = 4 | |
points = make_points(size) | |
g4, pos4 = gt.geometric_graph(points, 1.00000001, [(0,cell[0]*size),(0,cell[1]*size),(0,cell[2]*size)]) | |
print g4 | |
print float(g4.num_edges())/g4.num_vertices() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment