How to draw smooth balls (spheres) and sticks (cylinders) around my XYZ points.
20 views (last 30 days)
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
[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);
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 )) ;
%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.
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).
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
% Plot spheres
surf(SPHERE_RAD*xb+v(i,1), SPHERE_RAD*yb+v(i,2), SPHERE_RAD*zb+v(i,3), 'facecolor', 'b', 'edgealpha', 0);
% Make sure they're smooth and shaded