-
Notifications
You must be signed in to change notification settings - Fork 9
/
placing_edge.py
241 lines (159 loc) · 7.68 KB
/
placing_edge.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
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
#################
#
# This file is part of
# ToBaCCo - Topologically-Based Crystal Constructor
#
# Copyright 2017 Yamil J. Colon <[email protected]>
# Diego Gomez-Gualdron <[email protected]>
# Ben Bucior <[email protected]>
#
# 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 os
import numpy as np
import sys
import re
import fnmatch
import itertools
from neighbors import neighbor_edges, neighbor_vertices
from nodes import __node_properties
from transformations import superimposition_matrix
from placing_bb_func import __place_bb
from connect_nodetonode import __node_to_node
from edges import __edge_properties
from operator import itemgetter
##Placing edge building block when topology contains two nodes.
np.set_printoptions(threshold = sys.maxint)
def __place_edge(arg, unit_cell, edge_coord, node_1_coord, node_2_coord, node_1_neighbor, node_2_neighbor):
edge= __edge_properties(arg)
connection_site_edge = edge[0]
distance_connection_site = edge[1]
angle_connection_site_pair = edge[2]
connectivity = edge[3]
elements = edge[4]
element_coord = edge[5]
bb_elements=[]
bb_frac_coordinates=[]
bb_connectivity=[]
for j in range(len(edge_coord)):
node_1_vector =[]
node_2_vector =[]
##Get coordinates of neighboring nodes to find connection vectors
for i in range(len(node_1_neighbor[j])):
node_1_vector.append(node_1_coord[node_1_neighbor[j][i]])
for i in range(len(node_2_neighbor[j])):
node_2_vector.append(node_2_coord[node_2_neighbor[j][i]])
node_1_vector=np.asarray(node_1_vector) # fract. coord. of neigboring nodes
node_2_vector=np.asarray(node_2_vector)
edge_node_1_vector=[]
for i in range(len(node_1_vector)):
diffa = node_1_vector[i][0]-edge_coord[j][0]
diffb = node_1_vector[i][1]-edge_coord[j][1]
diffc = node_1_vector[i][2]-edge_coord[j][2]
### PERIODIC BOUNDARY CONDITIONS
if diffa > 0.5:
node_1_vector[i][0] = node_1_vector[i][0] - 1
elif diffa < -0.5:
node_1_vector[i][0] = node_1_vector[i][0] + 1
if diffb > 0.5:
node_1_vector[i][1] = node_1_vector[i][1] - 1
elif diffb < -0.5:
node_1_vector[i][1] = node_1_vector[i][1] + 1
if diffc > 0.5:
node_1_vector[i][2] = node_1_vector[i][2] - 1
elif diffc < -0.5:
node_1_vector[i][2] = node_1_vector[i][2] + 1
edge_node_1_vector.append(node_1_vector[i] - edge_coord[j])
edge_node_1_vector =np.asarray(edge_node_1_vector) ## fract vectors edge to node adjusted for PBCs
node_1_vector_real=[]
for i in range(len(edge_node_1_vector)):
vector_1_real = np.dot(np.transpose(unit_cell), edge_node_1_vector[i])
node_1_vector_real.append(vector_1_real)
node_1_vector_real = np.asarray(node_1_vector_real) # real (not fractional) coord vector of network
edge_node_2_vector=[]
for i in range(len(node_2_vector)):
diffa = node_2_vector[i][0]-edge_coord[j][0]
diffb = node_2_vector[i][1]-edge_coord[j][1]
diffc = node_2_vector[i][2]-edge_coord[j][2]
### PERIODIC BOUNDARY CONDITIONS
if diffa > 0.5:
node_2_vector[i][0] = node_2_vector[i][0] - 1
elif diffa < -0.5:
node_2_vector[i][0] = node_2_vector[i][0] + 1
if diffb > 0.5:
node_2_vector[i][1] = node_2_vector[i][1] - 1
elif diffb < -0.5:
node_2_vector[i][1] = node_2_vector[i][1] + 1
if diffc > 0.5:
node_2_vector[i][2] = node_2_vector[i][2] - 1
elif diffc < -0.5:
node_2_vector[i][2] = node_2_vector[i][2] + 1
edge_node_2_vector.append(node_2_vector[i] - edge_coord[j])
edge_node_2_vector =np.asarray(edge_node_2_vector) ## fract vectors from edge to node 2 adjusted for PBCs
node_2_vector_real=[]
for i in range(len(edge_node_2_vector)):
vector_2_real = np.dot(np.transpose(unit_cell), edge_node_2_vector[i])
node_2_vector_real.append(vector_2_real)
node_2_vector_real = np.asarray(node_2_vector_real) # real (not fractional) coord vector of network
edge_coord_real = np.dot(np.transpose(unit_cell), edge_coord[j]) # real coord of network edge (centroid of edge)
norm_node_1_vector_real=[]
for i in range(len(node_1_vector_real)):
norm = node_1_vector_real[i]/np.linalg.norm(node_1_vector_real[i])
norm_node_1_vector_real.append(norm)
norm_node_1_vector_real = np.asarray(norm_node_1_vector_real) # normalized network vectors
norm_node_2_vector_real=[]
for i in range(len(node_2_vector_real)):
norm = node_2_vector_real[i]/np.linalg.norm(node_2_vector_real[i])
norm_node_2_vector_real.append(norm)
norm_node_2_vector_real = np.asarray(norm_node_2_vector_real) # normalized network vectors
connection_edge=[]
connection_1 = norm_node_1_vector_real[0]*distance_connection_site[0]
connection_2 = norm_node_2_vector_real[0]*distance_connection_site[1] ##coordinates to where edge connection sites should be placed
connection_edge.append(connection_1)
connection_edge.append(connection_2)
connection_edge.append(np.cross(connection_1, connection_2))
connection_edge = np.asarray(connection_edge)
connection_site=[]
connection_site.append(connection_site_edge[0])
connection_site.append(connection_site_edge[1])
connection_site.append(np.cross(connection_site_edge[0], connection_site_edge[1]))
connection_site = np.asarray(connection_site)
##Calculate transformation matrix, using quaternions, to map building block vectors onto network vectors
tfmatrix = superimposition_matrix(np.transpose(connection_site), np.transpose(connection_edge), usesvd=False)
connection_site_plusone = np.append(connection_site, np.ones([len(connection_site),1]),1) # add a column of ones for dimension agreement
tf_connection_site =[]
for i in range(len(connection_site)):
new_sites = np.dot(tfmatrix, connection_site_plusone[i]) #apply transformation matrix to each building block vector
tf_connection_site.append(new_sites)
tf_connection_site = np.asarray(tf_connection_site) #coordinates of building block connection sites, mapped onto network node sites
tf_connection_site = tf_connection_site[:, :-1] #remove the column of ones, to obtain final set of coordinates
###Apply transformation matrix to all atoms in building block
element_coord_plusone = np.append(element_coord, np.ones([len(element_coord),1]),1)
tf_element_coord=[]
for i in range(len(element_coord)):
new_element= np.dot(tfmatrix, element_coord_plusone[i])
tf_element_coord.append(new_element)
tf_element_coord = np.asarray(tf_element_coord)
tf_element_coord = tf_element_coord[:, :-1]
tf_frac_element_coord=[]
for i in range(len(tf_element_coord)):
frac_element_coord = np.dot(np.transpose(np.linalg.inv(unit_cell)), tf_element_coord[i])
frac_element_coord = frac_element_coord + edge_coord[j]
tf_frac_element_coord.append(frac_element_coord)
tf_frac_element_coord = np.asarray(tf_frac_element_coord) #edge after transformation, in frac coords
bb_elements.append(elements)
bb_frac_coordinates.append(tf_frac_element_coord)
bb_connectivity.append(connectivity)
bb_elements = np.asarray(bb_elements)
bb_frac_coordinates = np.asarray(bb_frac_coordinates)
bb_connectivity=np.asarray(bb_connectivity)
return bb_elements, bb_frac_coordinates, bb_connectivity