@@ -88,89 +88,86 @@ def transform_points_to_C0(points: np.ndarray, base_point: np.ndarray, axis_poin
88
88
return points_transformed
89
89
90
90
91
- RCSB_ID = '3J7Z'
92
- radius = 40
93
- height = 80
94
- voxel_size = 1
95
-
96
- # residues, base, axis = get_npet_cylinder_residues(RCSB_ID, radius=radius, height=height)
97
-
98
- base_point = np .array (PTC_location (RCSB_ID ).location )
99
- axis_point = np .array ( get_constriction (RCSB_ID ) )
100
- # translation, rotation = get_transformation_to_C0(base, axis)
101
- # t_base = ( base + translation ) @ rotation.T
102
- # t_axis = ( axis + translation ) @ rotation.T
103
-
104
- if os .path .exists ('points.npy' ):
105
- points = np .load ('points.npy' )
106
- print ("Loaded" )
107
- else :
108
- residues = filter_residues_parallel ( ribosome_entities (RCSB_ID , 'R' ), base_point , axis_point , radius , height , )
109
- points = np .array ([atom .get_coord () for residue in residues for atom in residue .child_list ])
110
- np .save ('points.npy' , points )
111
- print ("Saved" )
112
- ...
113
-
114
-
115
- nx = ny = int (2 * radius / voxel_size ) + 1
116
- nz = int (height / voxel_size ) + 1
117
- x = np .linspace (- radius , radius , nx )
118
- y = np .linspace (- radius , radius , ny )
119
- z = np .linspace (0 , height , nz )
120
- X , Y , Z = np .meshgrid (x , y , z , indexing = 'ij' )
121
-
122
-
123
- transformed = transform_points_to_C0 (points , base , axis )
124
- X_I = np .round (transformed [:,0 ])
125
- Y_I = np .round (transformed [:,1 ])
126
- Z_I = np .round (transformed [:,2 ])
127
-
128
- cylinder_mask = (np .sqrt (X ** 2 + Y ** 2 ) <= radius )
129
- hollow_cylinder = ~ cylinder_mask
130
-
131
- # !-------------
132
- # 3. Create point cloud mask
133
- # point_cloud_mask = np.zeros_like(X, dtype=bool)
134
- # for point in zip(X_I, Y_I, Z_I):
135
- # point_cloud_mask |= (X == point[0]) & (Y == point[1]) & (Z == point[2])
136
-
137
-
138
- # !-------------
139
- radius_around_point = 2.0 # radius of sphere around each point
140
- # point_cloud_mask = np.zeros_like(X, dtype=bool)
141
- # for point in zip(X_I, Y_I, Z_I):
142
- # distance_to_point = np.sqrt(
143
- # (X - point[0])**2 +
144
- # (Y - point[1])**2 +
145
- # (Z - point[2])**2
146
- # )
147
- # point_cloud_mask |= (distance_to_point <= radius_around_point)
148
-
149
-
150
- # !-------------
151
- points = np .column_stack ((X_I , Y_I , Z_I )) # Shape: (N, 3)
152
- point_cloud_mask = np .zeros_like (X , dtype = bool )
153
-
154
- # Reshape grid coordinates for broadcasting
155
- grid_coords = np .stack ([X , Y , Z ]) # Shape: (3, nx, ny, nz)
156
- grid_coords = grid_coords .reshape (3 , - 1 ) # Shape: (3, nx*ny*nz)
157
-
158
- for point in points :
159
- # Calculate distances using broadcasting
160
- distances = np .sqrt (np .sum ((grid_coords .T - point )** 2 , axis = 1 ))
161
- # Reshape back to grid shape and add to mask
162
- point_cloud_mask |= (distances .reshape (X .shape ) <= radius_around_point )
163
-
164
-
165
- # !-------------
166
-
167
- final_mask = hollow_cylinder | point_cloud_mask
168
- occupied = np .where (final_mask )
169
-
170
- points = np .column_stack ((
171
- x [occupied [0 ]],
172
- y [occupied [1 ]],
173
- z [occupied [2 ]]
174
- ))
175
- occupied_points = pv .PolyData (points )
176
- visualize_pointcloud (occupied_points )
91
+ if __name__ == '__main__' :
92
+ RCSB_ID = '3J7Z'
93
+ radius = 40
94
+ height = 80
95
+ voxel_size = 1
96
+
97
+
98
+ base_point = np .array (PTC_location (RCSB_ID ).location )
99
+ axis_point = np .array ( get_constriction (RCSB_ID ) )
100
+
101
+ if os .path .exists ('points.npy' ):
102
+ points = np .load ('points.npy' )
103
+ print ("Loaded" )
104
+ else :
105
+ residues = filter_residues_parallel ( ribosome_entities (RCSB_ID , 'R' ), base_point , axis_point , radius , height , )
106
+ points = np .array ([atom .get_coord () for residue in residues for atom in residue .child_list ])
107
+ np .save ('points.npy' , points )
108
+ print ("Saved" )
109
+ ...
110
+
111
+
112
+ nx = ny = int (2 * radius / voxel_size ) + 1
113
+ nz = int (height / voxel_size ) + 1
114
+ x = np .linspace (- radius , radius , nx )
115
+ y = np .linspace (- radius , radius , ny )
116
+ z = np .linspace (0 , height , nz )
117
+ X , Y , Z = np .meshgrid (x , y , z , indexing = 'ij' )
118
+
119
+
120
+ transformed = transform_points_to_C0 (points , base_point , axis_point )
121
+ X_I = np .round (transformed [:,0 ])
122
+ Y_I = np .round (transformed [:,1 ])
123
+ Z_I = np .round (transformed [:,2 ])
124
+
125
+ cylinder_mask = (np .sqrt (X ** 2 + Y ** 2 ) <= radius )
126
+ hollow_cylinder = ~ cylinder_mask
127
+
128
+ # !-------------
129
+ # 3. Create point cloud mask
130
+ # point_cloud_mask = np.zeros_like(X, dtype=bool)
131
+ # for point in zip(X_I, Y_I, Z_I):
132
+ # point_cloud_mask |= (X == point[0]) & (Y == point[1]) & (Z == point[2])
133
+
134
+
135
+ # !-------------
136
+ radius_around_point = 2.0 # radius of sphere around each point
137
+ # point_cloud_mask = np.zeros_like(X, dtype=bool)
138
+ # for point in zip(X_I, Y_I, Z_I):
139
+ # distance_to_point = np.sqrt(
140
+ # (X - point[0])**2 +
141
+ # (Y - point[1])**2 +
142
+ # (Z - point[2])**2
143
+ # )
144
+ # point_cloud_mask |= (distance_to_point <= radius_around_point)
145
+
146
+
147
+ # !-------------
148
+ points = np .column_stack ((X_I , Y_I , Z_I )) # Shape: (N, 3)
149
+ point_cloud_mask = np .zeros_like (X , dtype = bool )
150
+
151
+ # Reshape grid coordinates for broadcasting
152
+ grid_coords = np .stack ([X , Y , Z ]) # Shape: (3, nx, ny, nz)
153
+ grid_coords = grid_coords .reshape (3 , - 1 ) # Shape: (3, nx*ny*nz)
154
+
155
+ for point in points :
156
+ # Calculate distances using broadcasting
157
+ distances = np .sqrt (np .sum ((grid_coords .T - point )** 2 , axis = 1 ))
158
+ # Reshape back to grid shape and add to mask
159
+ point_cloud_mask |= (distances .reshape (X .shape ) <= radius_around_point )
160
+
161
+
162
+ # !-------------
163
+
164
+ final_mask = hollow_cylinder | point_cloud_mask
165
+ occupied = np .where (final_mask )
166
+
167
+ points = np .column_stack ((
168
+ x [occupied [0 ]],
169
+ y [occupied [1 ]],
170
+ z [occupied [2 ]]
171
+ ))
172
+ occupied_points = pv .PolyData (points )
173
+ visualize_pointcloud (occupied_points )
0 commit comments