Skip to content

Add PDB voxelization visualization script#1

Open
yeonsungk1m wants to merge 1 commit into
kehan777:mainfrom
yeonsungk1m:codex/pdb-데이터로-voxelization-및-시각화-코드-작성

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

Add PDB voxelization visualization script#1
yeonsungk1m wants to merge 1 commit into
kehan777:mainfrom
yeonsungk1m:codex/pdb-데이터로-voxelization-및-시각화-코드-작성

Conversation

@yeonsungk1m
Copy link
Copy Markdown

@yeonsungk1m yeonsungk1m commented Jun 19, 2025

Summary by Sourcery

New Features:

  • Add example script (voxelize_view.py) with CLI support to parse PDB files, perform voxelization, and render a 3D voxel plot.

@sourcery-ai
Copy link
Copy Markdown

sourcery-ai Bot commented Jun 19, 2025

Reviewer's Guide

An 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 script

classDiagram
    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
Loading

Flow diagram for PDB voxelization and visualization process

flowchart 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]
Loading

File-Level Changes

Change Details Files
Create a new CLI script with necessary imports and entry point
  • Add argparse, numpy, Bio.PDB, and matplotlib imports
  • Set up main guard and argument parsing
  • Wire load, voxelize, and visualize functions into main
example/voxelize_view.py
Implement load_atoms to extract atomic coordinates
  • Use PDBParser to load structure quietly
  • Iterate over atoms and collect 3D coordinates
  • Return coordinates as a NumPy array
example/voxelize_view.py
Implement voxelize to build a boolean 3D grid
  • Compute padded bounding box (min/max minus/plus padding)
  • Calculate grid dimensions by dividing range by voxel size
  • Convert coordinates to integer voxel indices
  • Populate a boolean array marking occupied voxels
example/voxelize_view.py
Implement visualize for 3D voxel rendering
  • Create a matplotlib 3D axes figure
  • Call ax.voxels with facecolors, edgecolor, and alpha
  • Label axes and display the plot
example/voxelize_view.py

Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

Copy link
Copy Markdown

@sourcery-ai sourcery-ai Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey @yeonsungk1m - I've reviewed your changes - here's some feedback:

  • 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.
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>

Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

Comment thread example/voxelize_view.py
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()
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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()

Comment thread example/voxelize_view.py
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')
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant