How to draw smooth balls (spheres) and sticks (cylinders) around my XYZ points.

16 views (last 30 days)
ankit agrawal
ankit agrawal on 9 Apr 2015
Commented: Chris McComb on 10 Apr 2015
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);
forii=1:xd
forjj=1:yd
forkk=1:zd
点点= 0;
forpp=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',“红色”,'EdgeColor','none');
%daspect([2 2 2])
view(3); axistight
camlight; lightingphong
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
ankit agrawal
ankit agrawal on 10 Apr 2015
Hi Chris McComb The atoms are bonded in order of appearance in the data file. Like atom i is bonded to i+1, where i range from 1 to 249.

Sign in to comment.

Answers (1)

Chris McComb
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
%加载数据
v = load('molecule.txt');
% Make base sphere data
[xb, yb, zb] = sphere(SPHERE_RES);
% Make a figure
figure;
holdon;
% Plot spheres
fori=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;
lightinggouraud;
2 Comments
Chris McComb
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.

Sign in to comment.

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!