Visualize the Protein Mesh with pyvista© Karobben

Visualize the Protein Mesh with pyvista

Prerrequirement

pymol
collada
pyvista

All libraries could be installed by pip

Save the Mesh Information with Pymol

after loaded your model:

Example file: 2a6d
Target: Extract the mesh information of CDR region from a antibody
PS: output may takes a while.

bg_color white
color deepblue, 2a6d

select CDR1, 2a6d and chain B and resi 31-35
select CDR2, 2a6d and chain B and resi 50-66
select CDR3, 2a6d and chain B and resi 99-110
create cdr, CDR1 CDR2 CDR3

show mesh, cdr
color hotpink, cdr

hide all
show surface, cdr
save object.stl, cdr

Select a target area from pymol

Load It with pyvista

import pyvista as pv
mesh = pv.read('object.stl')

mesh.plot()

plotter = pv.Plotter(off_screen=True)
plotter.add_mesh(mesh)
plotter.show(screenshot="myscreenshot.png")

stl file visualize by pyvista

Model Manipulation

Rotate the Model

# Rotate the mesh
angle = 45 # Angle in degrees

mesh.rotate_x(angle) # Rotate 45 degrees around the x-axis
# mesh.rotate_y(angle) # Rotate around the y-axis
# mesh.rotate_z(angle) # Rotate around the z-axis

# For rotation around an arbitrary axis (e.g., [1, 1, 1]), use:
# mesh.rotate_vector([1, 1, 1], angle)

# Now you can plot the rotated mesh
plotter = pv.Plotter()
plotter.add_mesh(mesh)
plotter.show()

Move the Model

import pyvista as pv

# Assume 'mesh' is your PyVista mesh
# ...

# Translate the mesh
translation_vector = [10, 0, 0] # This will move the mesh 10 units along the x-axis
mesh.translate(translation_vector)

# Now you can plot the translated mesh
plotter = pv.Plotter()
plotter.add_mesh(mesh)
plotter.show()
Author

Karobben

Posted on

2023-12-06

Updated on

2023-12-19

Licensed under

Comments