Add PDB voxelization visualization script#1
Open
yeonsungk1m wants to merge 1 commit into
Hidden character warning
The head ref may contain hidden characters: "codex/pdb-\ub370\uc774\ud130\ub85c-voxelization-\ubc0f-\uc2dc\uac01\ud654-\ucf54\ub4dc-\uc791\uc131"
Open
Conversation
Reviewer's GuideAn example script has been added to parse PDB files, discretize atomic coordinates into a padded 3D voxel grid, and visualize the occupied voxels with matplotlib. Class diagram for voxelization and visualization scriptclassDiagram
class voxelize {
+voxelize(coords, voxel_size=1.0, padding=2.0)
}
class load_atoms {
+load_atoms(pdb_file)
}
class visualize {
+visualize(voxels)
}
class main {
+main()
}
main --> load_atoms : calls
main --> voxelize : calls
main --> visualize : calls
Flow diagram for PDB voxelization and visualization processflowchart TD
A[Start: User runs script with PDB file] --> B[Parse PDB file and extract atomic coordinates]
B --> C[Discretize coordinates into 3D voxel grid]
C --> D[Visualize occupied voxels in 3D]
D --> E[Show plot to user]
File-Level Changes
Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
There was a problem hiding this comment.
Hey @yeonsungk1m - I've reviewed your changes - here's some feedback:
- The voxelize function returns both
originandvoxel_sizebut these aren’t used downstream—consider removing them or using them to correctly position or label the grid in the visualization. - Right now atoms are treated as point samples; you might improve the volume rendering by accounting for atomic radii or using a Gaussian kernel to better approximate occupied space.
- Voxel grids can grow very large for small voxel sizes or big structures—consider adding a CLI warning or limit for grid dimensions to prevent excessive memory usage.
Prompt for AI Agents
Please address the comments from this code review:
## Overall Comments
- The voxelize function returns both `origin` and `voxel_size` but these aren’t used downstream—consider removing them or using them to correctly position or label the grid in the visualization.
- Right now atoms are treated as point samples; you might improve the volume rendering by accounting for atomic radii or using a Gaussian kernel to better approximate occupied space.
- Voxel grids can grow very large for small voxel sizes or big structures—consider adding a CLI warning or limit for grid dimensions to prevent excessive memory usage.
## Individual Comments
### Comment 1
<location> `example/voxelize_view.py:46` </location>
<code_context>
+ return voxels, min_c, voxel_size
+
+
+def visualize(voxels):
+ fig = plt.figure()
+ ax = fig.add_subplot(111, projection='3d')
</code_context>
<issue_to_address>
No axis scaling or aspect ratio adjustment in visualization.
Setting axis limits or aspect ratio can help ensure the 3D plot accurately represents the voxel grid's proportions.
</issue_to_address>
<suggested_fix>
<<<<<<< SEARCH
def visualize(voxels):
fig = plt.figure()
ax = fig.add_subplot(111, projection='3d')
ax.voxels(voxels, edgecolor='k', facecolors='cyan', alpha=0.7)
ax.set_xlabel('X')
ax.set_ylabel('Y')
ax.set_zlabel('Z')
plt.tight_layout()
plt.show()
=======
def visualize(voxels):
fig = plt.figure()
ax = fig.add_subplot(111, projection='3d')
ax.voxels(voxels, edgecolor='k', facecolors='cyan', alpha=0.7)
ax.set_xlabel('X')
ax.set_ylabel('Y')
ax.set_zlabel('Z')
# Set axis limits based on voxel grid shape
shape = voxels.shape
ax.set_xlim(0, shape[0])
ax.set_ylim(0, shape[1])
ax.set_zlim(0, shape[2])
# Set aspect ratio to match voxel grid proportions
max_range = max(shape)
ax.set_box_aspect((shape[0]/max_range, shape[1]/max_range, shape[2]/max_range))
plt.tight_layout()
plt.show()
>>>>>>> REPLACE
</suggested_fix>
### Comment 2
<location> `example/voxelize_view.py:60` </location>
<code_context>
+def main():
+ parser = argparse.ArgumentParser(description='Voxelize PDB and visualize.')
+ parser.add_argument('pdb', help='Input PDB file')
+ parser.add_argument('--size', type=float, default=1.0, help='Voxel size in angstroms')
+ args = parser.parse_args()
+
</code_context>
<issue_to_address>
No validation for non-positive voxel size.
Validate that voxel_size is positive to prevent failures or unexpected behavior when users provide invalid values.
</issue_to_address>Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.
Comment on lines
+46
to
+54
| def visualize(voxels): | ||
| fig = plt.figure() | ||
| ax = fig.add_subplot(111, projection='3d') | ||
| ax.voxels(voxels, edgecolor='k', facecolors='cyan', alpha=0.7) | ||
| ax.set_xlabel('X') | ||
| ax.set_ylabel('Y') | ||
| ax.set_zlabel('Z') | ||
| plt.tight_layout() | ||
| plt.show() |
There was a problem hiding this comment.
suggestion: No axis scaling or aspect ratio adjustment in visualization.
Setting axis limits or aspect ratio can help ensure the 3D plot accurately represents the voxel grid's proportions.
Suggested change
| def visualize(voxels): | |
| fig = plt.figure() | |
| ax = fig.add_subplot(111, projection='3d') | |
| ax.voxels(voxels, edgecolor='k', facecolors='cyan', alpha=0.7) | |
| ax.set_xlabel('X') | |
| ax.set_ylabel('Y') | |
| ax.set_zlabel('Z') | |
| plt.tight_layout() | |
| plt.show() | |
| def visualize(voxels): | |
| fig = plt.figure() | |
| ax = fig.add_subplot(111, projection='3d') | |
| ax.voxels(voxels, edgecolor='k', facecolors='cyan', alpha=0.7) | |
| ax.set_xlabel('X') | |
| ax.set_ylabel('Y') | |
| ax.set_zlabel('Z') | |
| # Set axis limits based on voxel grid shape | |
| shape = voxels.shape | |
| ax.set_xlim(0, shape[0]) | |
| ax.set_ylim(0, shape[1]) | |
| ax.set_zlim(0, shape[2]) | |
| # Set aspect ratio to match voxel grid proportions | |
| max_range = max(shape) | |
| ax.set_box_aspect((shape[0]/max_range, shape[1]/max_range, shape[2]/max_range)) | |
| plt.tight_layout() | |
| plt.show() |
| def main(): | ||
| parser = argparse.ArgumentParser(description='Voxelize PDB and visualize.') | ||
| parser.add_argument('pdb', help='Input PDB file') | ||
| parser.add_argument('--size', type=float, default=1.0, help='Voxel size in angstroms') |
There was a problem hiding this comment.
issue (bug_risk): No validation for non-positive voxel size.
Validate that voxel_size is positive to prevent failures or unexpected behavior when users provide invalid values.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary by Sourcery
New Features: