-
Notifications
You must be signed in to change notification settings - Fork 1
/
area_finder_local.m
138 lines (100 loc) · 2.86 KB
/
area_finder_local.m
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
function [Ax,Ay,Az] = area_finder_local(xyz,conn,geomTXT,ring_size);
% This function estimates normalised
% net cross-section areas of the RCM
% relatively to the x,y,z axes.
% Only used for sinle porphyrin subunits
%count = 1
%conn = conn_local_sub{count,1}
conn_temp = conn(:,2:3);
idx_temp = unique(conn_temp(:));
%idx_temp2 = find(conn(:,1) == 1);
%conn(idx_temp2,:)
%return
if ring_size == 20 || ring_size == 28;
distMat = squareform(pdist(xyz(idx_temp,:))); % distance matrix
adjMat = distMat < 1.75;
adjMat = adjMat - diag(diag(adjMat));
G = graph(adjMat);
cycles = allcycles(G);
size_graphs = zeros(size(cycles,1),1);
for i = 1:size(cycles,1)
size_graphs(i,1) = size(cycles{i,1},2);
end
Idx20 = find(size_graphs == 20);
idx_ring = idx_temp(cycles{Idx20,1}');
xyz_temp = xyz(idx_ring,:);
idx_store = [];
for i = 1:size(conn,1)
idx_store(i,1) = ...
ismember(conn(i,2),idx_ring) & ismember(conn(i,3),idx_ring) ;
end
idx_temp3 = find(idx_store == 1);
conn20 = conn(idx_temp3,:);
reor_conn20 = zeros(size(conn20));
reor_conn20(1,:) = conn20(1,:);
num_1 = reor_conn20(1,3);
count = 2;
while num_1 ~= reor_conn20(1,2)
num_1 = reor_conn20(count-1,3);
num_1 = find(conn20(:,2) == num_1);
reor_conn20(count,:) = conn20(num_1,:);
count = count + 1;
num_1 = reor_conn20(count-1,3);
end
%scatter3(xyz_temp(:,1),xyz_temp(:,2),xyz_temp(:,3))
X = xyz(reor_conn20(:,2),1);
Y = xyz(reor_conn20(:,2),2);
Z = xyz(reor_conn20(:,2),3);
elseif ring_size == 16
distMat = squareform(pdist(xyz(idx_temp,:))); % distance matrix
adjMat = distMat < 1.75;
adjMat = adjMat - diag(diag(adjMat));
G = graph(adjMat);
cycles = allcycles(G);
size_graphs = zeros(size(cycles,1),1);
for i = 1:size(cycles,1)
size_graphs(i,1) = size(cycles{i,1},2);
end
Idx16= find(size_graphs == 16);
idx_ring = idx_temp(cycles{Idx16,1}');
xyz_temp = xyz(idx_ring,:);
idx_store = [];
for i = 1:size(conn,1)
idx_store(i,1) = ...
ismember(conn(i,2),idx_ring) & ismember(conn(i,3),idx_ring) ;
end
idx_temp3 = find(idx_store == 1);
conn16 = conn(idx_temp3,:);
reor_conn16 = zeros(size(conn16));
reor_conn16(1,:) = conn16(1,:);
num_1 = reor_conn16(1,3);
count = 2;
while num_1 ~= reor_conn16(1,2)
num_1 = reor_conn16(count-1,3);
num_1 = find(conn16(:,2) == num_1);
reor_conn16(count,:) = conn16(num_1,:);
count = count + 1;
num_1 = reor_conn16(count-1,3);
end
X = xyz(reor_conn16(:,2),1);
Y = xyz(reor_conn16(:,2),2);
Z = xyz(reor_conn16(:,2),3);
end
% disp(ring_size)
Ax = polyarea(Y,Z);
Ay = polyarea(X,Z);
Az = polyarea(X,Y);
if ~ispolycw(Z,Y)
Ax = -1*Ax;
end
if ~ispolycw(X,Z)
Ay = -1*Ay;
end
if ~ispolycw(Y,X)
Az = -1*Az;
end
scale_factor = sqrt(Ax^2+Ay^2+Az^2);
Ax = Ax/scale_factor;
Ay = Ay/scale_factor;
Az = Az/scale_factor;
end