-
Notifications
You must be signed in to change notification settings - Fork 8
/
neighbors.py
93 lines (80 loc) · 2.87 KB
/
neighbors.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
#################
#
# This file is part of
# ToBaCCo - Topologically-Based Crystal Constructor
#
# Copyright 2017 Yamil J. Colon <yamilcolon2015@u.northwestern.edu>
# Diego Gomez-Gualdron <dgomezgualdron@mines.edu>
# Ben Bucior <ben.bucior@gmail.com>
#
# ToBaCCo is free software: you can redistribute it and/or modify
# it under the terms of the GNU Lesser General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# ToBaCCo is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Lesser General Public License for more details.
#
#################
import numpy as np
def neighbor_edges(uc, v1, nv1, e1, ne1, cn, hl):
tolerance = 0.1
e1_nabors = []
for i in range(0,nv1) :
v = np.asarray([v1[i,0], v1[i,1], v1[i,2]])
for j in range(0, ne1):
e = np.asarray([e1[j,0], e1[j,1], e1[j,2]])
diffa = v[0] - e[0]
diffb = v[1] - e[1]
diffc = v[2] - e[2]
if diffa > 0.5:
e[0] = e[0] + 1.0
elif diffa < -0.5:
e[0] = e[0] - 1.0
if diffb > 0.5:
e[1] = e[1] + 1.0
elif diffb < -0.5:
e[1] = e[1] - 1.0
if diffc > 0.5:
e[2] = e[2] + 1.0
elif diffc < -0.5:
e[2] = e[2] - 1.0
v_xyz = np.dot(np.transpose(uc), v)
e_xyz = np.dot(np.transpose(uc), e)
distance = np.linalg.norm(v_xyz - e_xyz)
if distance < (hl + tolerance) and distance > (hl - tolerance):
e1_nabors.append([j])
e1_nabors = np.asarray(e1_nabors)
e1_nabors = np.reshape(e1_nabors, (nv1, cn))
return e1_nabors
def neighbor_vertices(uc, v1, nv1, e1, ne1, hl):
tolerance = 0.1
v1_nabors = []
for i in range(0,ne1) :
e = np.asarray([e1[i,0], e1[i,1], e1[i,2]])
for j in range(0, nv1):
v = np.asarray([v1[j,0], v1[j,1], v1[j,2]])
diffa = e[0] - v[0]
diffb = e[1] - v[1]
diffc = e[2] - v[2]
if diffa > 0.5:
v[0] = v[0] + 1.0
elif diffa < -0.5:
v[0] = v[0] - 1.0
if diffb > 0.5:
v[1] = v[1] + 1.0
elif diffb < -0.5:
v[1] = v[1] - 1.0
if diffc > 0.5:
v[2] = v[2] + 1.0
elif diffc < -0.5:
v[2] = v[2] - 1.0
v_xyz = np.dot(np.transpose(uc), v)
e_xyz = np.dot(np.transpose(uc), e)
distance = np.linalg.norm(v_xyz - e_xyz)
if distance < (hl + tolerance) and distance > (hl - tolerance):
v1_nabors.append([j])
v1_nabors = np.asarray(v1_nabors)
return v1_nabors