Example 2

Back to Index


% Script File: eg2
%
% Plot various attributes of a protein.
%
% Keywords: close, norm, input, plot, length, 
% xlabel, ylabel, grid, axis, figure

close all

% Read in coordinates of the amino acids

fid = fopen('1.CRD');
A = fscanf(fid,'%g %g %g',[3 inf]);

% For simplicity, let us store the x, y, and z coordinates
% in separate arrays.

x = A(1,:);
y = A(2,:);
z = A(3,:);

% The length of any of these arrays equals the number of
% amino acids.

n = length(x);

% Look at the distances between the amino acids.

% Plot the function d(i), i=1:n-1 where d(i) is the
% separation between the ith and i+1st amino acid.

d = zeros(n-1,1);
for i=1:n-1
   d(i) = norm([x(i) y(i) z(i)] - [x(i+1) y(i+1) z(i+1)]);
end
plot(d)
title('Separations')
xlabel('i')
ylabel('d(i)')


% Plot the function d(i), i=1:n-p where d(i) is the
% separation between the ith and (i+p)-th amino acid.

p = input('Enter spacing factor p:');
d = zeros(n-p,1);
for i=1:n-p
   d(i) = norm([x(i) y(i) z(i)] - [x(i+p) y(i+p) z(i+p)]);
end
figure
plot(d)
title(sprintf('Distance to the amino acid i+%1d',p))
xlabel('i')

% Plot a portion of the protein
figure
idx = 110:130;
plot3(x(idx),y(idx),z(idx),x(idx),y(idx),z(idx),'.r')
axis('equal')
grid on

% Look at "turns" in the chain
cos_theta = zeros(n-2,1);
for i=2:n-2
   vminus = [x(i-1)-x(i); y(i-1)-y(i); z(i-1)-z(i)];
   vplus  = [x(i+1)-x(i); y(i+1)-y(i); z(i+1)-z(i)];
   cos_theta(i) = vminus'*vplus/(norm(vminus)*norm(vplus));
end
figure
plot(cos_theta)
title('Cosine of the interior angles')
ylabel('cos of angle i')
xlabel('i')

   

Q1. Augment the script so that it prints the average spacing between two adjacent amino acids.

Q2. Augment the script so that it prints the smallest "interior angle" in degrees. (Check out the min function and the inverse cosine function acos and work with the vector cos_theta above.)