Creating a smooth surface in 3D

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|

Creating a smooth surface in 3D

Bala subramanian-2

Dear mpl friends,

My objective is to create a molecular surface using matplotlib. I used the snippet pasted below to create a series of spheres (attached png), drawn using the atom attributes (their positions and radius). From here, I would like to create a smooth surface which can depict the shape of the molecule surface (curves,cavities etc). Based on examples in net, I get a mixed feeling that either triangulation or making 3D grids are some directions to proceed. If anyone has some suggestions or better protocols for such task with some example data, it would be of great help to me.

fig = plt.figure(figsize=(6,6),dpi=140)

ax1 = fig.add_subplot(111, projection='3d')

# Define spherical coordinates

u, v = np.mgrid[0:2*np.pi:20j, 0:np.pi:10j]

S = np.cos(u)*np.sin(v)

C = np.sin(u)*np.sin(v)

T = np.cos(v)

for P,R in zip(positions,radii):

         ax1.plot_wireframe(R*S+P[0],R*C+P[1],R*T+P[2],color='r',alpha=0.4)


Thanks in advance,

Bala



--
C. Balasubramanian

_______________________________________________
Matplotlib-users mailing list
[hidden email]
https://mail.python.org/mailman/listinfo/matplotlib-users

test.png (633K) Download Attachment
Reply | Threaded
Open this post in threaded view
|

Re: Creating a smooth surface in 3D

Benjamin Root
mplot3d is good for real simple 3d scenes, but it falls apart when you start composing things like this. You might want to consider using something like glumpy or mayavi for better results. There are some discussions in the past on the problems inherent in creating spheres in mplot3d. There are some interesting solutions, but they get fairly complex pretty quickly.

Cheers!
Ben Root

On Mon, May 28, 2018 at 8:16 AM, Bala subramanian <[hidden email]> wrote:

Dear mpl friends,

My objective is to create a molecular surface using matplotlib. I used the snippet pasted below to create a series of spheres (attached png), drawn using the atom attributes (their positions and radius). From here, I would like to create a smooth surface which can depict the shape of the molecule surface (curves,cavities etc). Based on examples in net, I get a mixed feeling that either triangulation or making 3D grids are some directions to proceed. If anyone has some suggestions or better protocols for such task with some example data, it would be of great help to me.

fig = plt.figure(figsize=(6,6),dpi=140)

ax1 = fig.add_subplot(111, projection='3d')

# Define spherical coordinates

u, v = np.mgrid[0:2*np.pi:20j, 0:np.pi:10j]

S = np.cos(u)*np.sin(v)

C = np.sin(u)*np.sin(v)

T = np.cos(v)

for P,R in zip(positions,radii):

         ax1.plot_wireframe(R*S+P[0],R*C+P[1],R*T+P[2],color='r',alpha=0.4)


Thanks in advance,

Bala



--
C. Balasubramanian

_______________________________________________
Matplotlib-users mailing list
[hidden email]
https://mail.python.org/mailman/listinfo/matplotlib-users



_______________________________________________
Matplotlib-users mailing list
[hidden email]
https://mail.python.org/mailman/listinfo/matplotlib-users
Reply | Threaded
Open this post in threaded view
|

Re: Creating a smooth surface in 3D

Bala subramanian-2
Thanks for the inputs. After some efforts, I managed to create the surface by generating vertex and faces using an external program and mpl tools.

ax1.plot_trisurf(x, y, z, triangles=faces,color='w', lw=10)

ax1.scatter3D(x, y, z, c= cols,s=10)

However, i am now trying to figure out the simple way to color the triangles using the vertex colors.

For each vertex, I have assigned a color (ranges from blue to red) which in my case represents a calculated property. So basically I have a color array (cols in the above snippet) that I passed to the scatter function. I would like to know how I can color the triangle by interpolating to the colors of the vertex it belongs to. The available examples in net show the usage of colormaps. In my case, the triangles should adopt vertex colors.

Any tricks to achieve this could be of much help. I have attached a sample figure, which i believe, could better elucidate the problem.






On Mon, May 28, 2018 at 3:19 PM, Benjamin Root <[hidden email]> wrote:
mplot3d is good for real simple 3d scenes, but it falls apart when you start composing things like this. You might want to consider using something like glumpy or mayavi for better results. There are some discussions in the past on the problems inherent in creating spheres in mplot3d. There are some interesting solutions, but they get fairly complex pretty quickly.

Cheers!
Ben Root

On Mon, May 28, 2018 at 8:16 AM, Bala subramanian <[hidden email]> wrote:

Dear mpl friends,

My objective is to create a molecular surface using matplotlib. I used the snippet pasted below to create a series of spheres (attached png), drawn using the atom attributes (their positions and radius). From here, I would like to create a smooth surface which can depict the shape of the molecule surface (curves,cavities etc). Based on examples in net, I get a mixed feeling that either triangulation or making 3D grids are some directions to proceed. If anyone has some suggestions or better protocols for such task with some example data, it would be of great help to me.

fig = plt.figure(figsize=(6,6),dpi=140)

ax1 = fig.add_subplot(111, projection='3d')

# Define spherical coordinates

u, v = np.mgrid[0:2*np.pi:20j, 0:np.pi:10j]

S = np.cos(u)*np.sin(v)

C = np.sin(u)*np.sin(v)

T = np.cos(v)

for P,R in zip(positions,radii):

         ax1.plot_wireframe(R*S+P[0],R*C+P[1],R*T+P[2],color='r',alpha=0.4)


Thanks in advance,

Bala



--
C. Balasubramanian

_______________________________________________
Matplotlib-users mailing list
[hidden email]
https://mail.python.org/mailman/listinfo/matplotlib-users





--
C. Balasubramanian

_______________________________________________
Matplotlib-users mailing list
[hidden email]
https://mail.python.org/mailman/listinfo/matplotlib-users

Surface.png (387K) Download Attachment
Reply | Threaded
Open this post in threaded view
|

Re: Creating a smooth surface in 3D

Bala subramanian-2
I managed to interpolate the face colors based on vertex property following the example given below.

https://stackoverflow.com/questions/24218543/colouring-the-surface-of-a-sphere-with-a-set-of-scalar-values-in-matplotlib

I am just updating here so as to direct anyone looking trying similar stuff. Thanks.

On Fri, Jun 1, 2018 at 10:52 AM, Bala subramanian <[hidden email]> wrote:
Thanks for the inputs. After some efforts, I managed to create the surface by generating vertex and faces using an external program and mpl tools.

ax1.plot_trisurf(x, y, z, triangles=faces,color='w', lw=10)

ax1.scatter3D(x, y, z, c= cols,s=10)

However, i am now trying to figure out the simple way to color the triangles using the vertex colors.

For each vertex, I have assigned a color (ranges from blue to red) which in my case represents a calculated property. So basically I have a color array (cols in the above snippet) that I passed to the scatter function. I would like to know how I can color the triangle by interpolating to the colors of the vertex it belongs to. The available examples in net show the usage of colormaps. In my case, the triangles should adopt vertex colors.

Any tricks to achieve this could be of much help. I have attached a sample figure, which i believe, could better elucidate the problem.






On Mon, May 28, 2018 at 3:19 PM, Benjamin Root <[hidden email]> wrote:
mplot3d is good for real simple 3d scenes, but it falls apart when you start composing things like this. You might want to consider using something like glumpy or mayavi for better results. There are some discussions in the past on the problems inherent in creating spheres in mplot3d. There are some interesting solutions, but they get fairly complex pretty quickly.

Cheers!
Ben Root

On Mon, May 28, 2018 at 8:16 AM, Bala subramanian <[hidden email]> wrote:

Dear mpl friends,

My objective is to create a molecular surface using matplotlib. I used the snippet pasted below to create a series of spheres (attached png), drawn using the atom attributes (their positions and radius). From here, I would like to create a smooth surface which can depict the shape of the molecule surface (curves,cavities etc). Based on examples in net, I get a mixed feeling that either triangulation or making 3D grids are some directions to proceed. If anyone has some suggestions or better protocols for such task with some example data, it would be of great help to me.

fig = plt.figure(figsize=(6,6),dpi=140)

ax1 = fig.add_subplot(111, projection='3d')

# Define spherical coordinates

u, v = np.mgrid[0:2*np.pi:20j, 0:np.pi:10j]

S = np.cos(u)*np.sin(v)

C = np.sin(u)*np.sin(v)

T = np.cos(v)

for P,R in zip(positions,radii):

         ax1.plot_wireframe(R*S+P[0],R*C+P[1],R*T+P[2],color='r',alpha=0.4)


Thanks in advance,

Bala



--
C. Balasubramanian

_______________________________________________
Matplotlib-users mailing list
[hidden email]
https://mail.python.org/mailman/listinfo/matplotlib-users





--
C. Balasubramanian



--
C. Balasubramanian

_______________________________________________
Matplotlib-users mailing list
[hidden email]
https://mail.python.org/mailman/listinfo/matplotlib-users