How to draw smooth balls (spheres) and sticks (cylinders) around my XYZ points.
    14 views (last 30 days)
  
       Show older comments
    
Hi,
I generate the xyz coordinate of a molecule using simulation in C++. Now i have 250 atoms of xyz coordinate in one molecule. (the file attached) I want to draw the smooth surface over my atoms. So, I had written MATLAB code to draw blobby surface in my molecules. The code is following
v=load(molecule.txt);
Radius=1.5, B=-1; 
x=v(:,1);
y=v(:,2);
z=v(:,3);
[xg,yg,zg] = meshgrid(min(x)-2 : 1 : max(x)+2,min(y)-2 : 1 : max(y)+2,min(z)-2 : 1 : max(z)+2);
xd=size(xg,1);yd=size(xg,2);zd=size(xg,3);
for ii=1:xd
    for jj=1:yd
        for kk=1:zd
        blobby=0;
            for pp=1:length(v)              
                c=[xg(ii,jj,kk),yg(ii,jj,kk),zg(ii,jj,kk)] - [x(pp) y(pp) z(pp)];
                blobby=blobby+exp(B*(   (sum(c.^2 )/(Radius^2))  -1     )) ;  
            end
        G(ii,jj,kk)=blobby;
        end
    end
end
%isosurface(xg,yg,zg,G)
p=patch(isosurface(xg,yg,zg,G));
isonormals(xg,yg,zg,G,p);
set(p,'FaceColor','red','EdgeColor','none');
%daspect([2 2 2])
view(3); axis tight
camlight; lighting phong
The figure is attached for blobby parameter B = -1 and Radius =1.5

Some of the atoms are very far in my case so its not covered in single surface. If i increase the Radius and decrease B then it becomes too much smooth (it becomes sphere).
Now i wanted some new technique like to connect the bond in cylinder and atoms in sphere such that overall structure should be smooth. There is representation in vmd called CPK where i can make such image.

But i cannot make this molecule smooth. Is anyone know how to make such figures in MATLAB with good smoothness?
Thanks in advance.
3 Comments
  Chris McComb
      
 on 10 Apr 2015
				Can you also provide information regarding which atoms are bonded? This will be necessary to draw the appropriate cylinders.
Answers (1)
  Chris McComb
      
 on 10 Apr 2015
        
      Edited: Chris McComb
      
 on 10 Apr 2015
  
      This should do what you're looking for regarding the spheres (but see my above comment for cylinders).
% Parameters
SPHERE_RES = 20; % resolution for your spheres
SPHERE_RAD = 2.0; % radius of spheres
% Load the data
v = load('molecule.txt');
% Make base sphere data
[xb, yb, zb] = sphere(SPHERE_RES);
% Make a figure
figure;
hold on;
% Plot spheres
for i=1:1:length(v)
    surf(SPHERE_RAD*xb+v(i,1), SPHERE_RAD*yb+v(i,2), SPHERE_RAD*zb+v(i,3), 'facecolor', 'b', 'edgealpha', 0);
end
% Make sure they're smooth and shaded
light;
lighting gouraud;
2 Comments
  Chris McComb
      
 on 10 Apr 2015
				Happy to help! What you're seeing are the edges between panels on the surface. The way I handled that for the spheres was just to make them transparent. In your code, just replace
surf(xc,yc,zc);
with
surf(xc, yc, zc, 'facecolor', 'b', 'edgealpha', 0);
This will make the surface blue ('b'), and make the edges 0% opaque.
See Also
Categories
				Find more on Surface and Mesh Plots in Help Center and File Exchange
			
	Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!

