def plot_network(vertices, poly, L, file): plt.cla() fig = plt.figure() ax = fig.add_subplot(1, 1, 1) # for x,y in vertices: # ax.scatter(x, y, c="m", marker=".", s=100) for poly in poly: indices = poly.indices for i, index in enumerate(indices): x1, y1 = vertices[index] if i == len(indices) - 1: x2, y2 = vertices[indices[0]] else: x2, y2 = vertices[indices[i + 1]] v1 = np.array((x1, y1)) v2 = np.array((x2, y2)) v2 = v1 + periodic_diff(v2, v1, L) x2, y2 = v2 ax.plot([x1, x2], [y1, y2], c="c") v2 = np.array((x2, y2)) v1 = v2 + periodic_diff(v1, v2, L) x1, y1 = v1 ax.plot([x1, x2], [y1, y2], c="c") # # plot centers x, y = poly.get_center(vertices, L) if x <= 0: x = x + L[0] if x >= L[0]: x = x - L[0] if y <= 0: y = y + L[1] if y >= L[1]: y = y - L[1] plt.scatter(x, y, color="c", marker=".") # remove axis ticks ax.axes.get_xaxis().set_ticks([]) ax.axes.get_yaxis().set_ticks([]) ax.axis([0, L[0], 0, L[1]]) plt.savefig(file) plt.close(fig) return
def T1_transition(vertices, polys, edges, parameters): lx = parameters['lx'] ly = parameters['ly'] L = np.array([lx, ly]) lmin = parameters['lmin'] reverse = [] for edge in edges: i1 = edge[0] i2 = edge[1] v1 = vertices[i1] vertex2 = vertices[i2] v2 = v1 + periodic_diff(vertex2, v1, L) dist = euclidean_distance(v1[0], v1[1], v2[0], v2[1]) if dist < lmin and (i1, i2) not in reverse: print "T1", i1, i2, dist poly_ids = get_4_polys(polys, i1, i2) if -1 in poly_ids: pass else: # find minimum configuration reverse.append((i2, i1)) # 6 indices for vertices involved in transition indices = get_6_indices(polys, i1, i2, poly_ids) # original configuration polys_0, edges_0 = T1_0(polys, i1, i2, poly_ids, indices) E0 = get_energy(vertices, polys_0, edges_0, parameters) # left T1 transition polys_l, edges_l = T1_left(polys, i1, i2, poly_ids, indices) E_left = get_energy(vertices, polys_l, edges_l, parameters) # # right T1 transition polys_r, edges_r = T1_right(polys, i1, i2, poly_ids, indices) E_right = get_energy(vertices, polys_r, edges_r, parameters) # get minimum min_energy = np.min((E0, E_left, E_right)) min_i = np.argmin((E0, E_left, E_right)) print min_i # # do nothing - same configuration if min_i == 0: pass if min_i == 1: set_T1_left(polys, polys_l, poly_ids, edges, indices) if min_i == 2: set_T1_right(polys, polys_r, poly_ids, edges, indices) return polys, edges
def T1_transition(vertices, polys, edges, parameters): lx = parameters['lx'] ly = parameters['ly'] L = np.array([lx,ly]) lmin = parameters['lmin'] for edge in edges: i1 = edge[0] i2 = edge[1] v1 = vertices[i1] vertex2 = vertices[i2] v2 = v1 + periodic_diff(vertex2, v1, L) dist = euclidean_distance(v1[0], v1[1], v2[0], v2[1]) if dist < lmin: # print "T1", i1, i2, dist poly_ids = get_4_polys(polys, i1, i2) if -1 in poly_ids: pass else: # find minimum configuration # 6 indices for vertices involved in transition indices = get_6_indices(polys, i1, i2, poly_ids) # original configuration polys_0, edges_0 = T1_0(polys, i1, i2, poly_ids, indices) E0 = get_energy(vertices, polys_0, edges_0, parameters) # left T1 transition polys_l, edges_l = T1_left(polys, i1, i2, poly_ids, indices) E_left = get_energy(vertices, polys_l, edges_l, parameters) # # right T1 transition polys_r, edges_r = T1_right(polys, i1, i2, poly_ids, indices) E_right = get_energy(vertices, polys_r, edges_r, parameters) # get minimum min_energy = np.min((E0, E_left, E_right)) min_i = np.argmin((E0, E_left, E_right)) # # do nothing - same configuration if min_i == 0: pass if min_i == 1: set_T1_left(polys, polys_l, poly_ids, edges, indices) if min_i == 2: set_T1_right(polys, polys_r, poly_ids, edges, indices) return polys, edges
def E_adhesion(vertices, edges, Lambda, L): e = 0. for edge in edges: i1 = edge[0] i2 = edge[1] v1 = vertices[i1] vertex2 = vertices[i2] v2 = v1 + periodic_diff(vertex2, v1, L) dist = euclidean_distance(v1[0], v1[1], v2[0], v2[1]) e += Lambda * dist return e
def E_adhesion(vertices, edges, Lambda , L): e = 0. for edge in edges: i1 = edge[0] i2 = edge[1] v1 = vertices[i1] vertex2 = vertices[i2] v2 = v1 + periodic_diff(vertex2, v1, L) dist = euclidean_distance(v1[0], v1[1], v2[0], v2[1]) e += Lambda * dist return e
def plot_network(vertices, polys, L, file): plt.cla() fig = plt.figure() ax = fig.add_subplot(1, 1, 1) for x, y in vertices: ax.scatter(x, y, c="m", marker=".", s=50) for poly in polys: indices = poly.indices for i, index in enumerate(indices): x1, y1 = vertices[index] if i == len(indices) - 1: x2, y2 = vertices[indices[0]] else: x2, y2 = vertices[indices[i + 1]] v1 = np.array((x1, y1)) v2 = np.array((x2, y2)) v2 = v1 + periodic_diff(v2, v1, L) x2, y2 = v2 ax.plot([x1, x2], [y1, y2], c="c") v2 = np.array((x2, y2)) v1 = v2 + periodic_diff(v1, v2, L) x1, y1 = v1 ax.plot([x1, x2], [y1, y2], c="c") # # plot centers # x,y = poly.get_center(vertices, L) # plt.scatter(x,y,color="m", marker="*") # remove axis ticks ax.axes.get_xaxis().set_ticks([]) ax.axes.get_yaxis().set_ticks([]) ax.axis([0, L[0], 0, L[1]]) plt.savefig(file) plt.close(fig) return
def plot_edges(vertices, edges, L): plt.cla() for vertex in vertices: x = vertex[0] y = vertex[1] plt.scatter(x, y, c="c") for edge in edges: i1 = edge[0] i2 = edge[1] x1, y1 = vertices[i1] x2, y2 = vertices[i2] v1 = np.array((x1, y1)) v2 = np.array((x2, y2)) v2 = v1 + periodic_diff(v2, v1, L) x2, y2 = v2 plt.plot([x1, x2], [y1, y2], c="k") plt.axis([0, L[0], 0, L[1]]) plt.show() return