Calculating OpenGL Face Normals of Polygon - c

I am trying to add lighting to a polygon created from a point polygon file. My problem is when creating vectors from the points I only get a certain section of the polygons lit, then if I inverse the calculation for normals, (From A.x - C.x to C.x - A.x) it lights the section that was not previously lit. Code and pictures below.
h_vector V1;//= (p2 - p1);
// A = 0 B = 1 C = 2 D =3
V1.x = vertices[1].x - vertices[0].x;
V1.y = vertices[1].y - vertices[0].y;
V1.z = vertices[1].z - vertices[0].z;
h_vector V2;// = (p3 - p1);
V2.x = vertices[3].x - vertices[0].x;
V2.y = vertices[3].y - vertices[0].y;
V2.z = vertices[3].z - vertices[0].z;
/*
h_vector V1;//= (p2 - p1);
V1.x = vertices[0].x - vertices[1].x;
V1.y = vertices[0].y - vertices[1].y;
V1.z = vertices[0].z - vertices[1].z;
h_vector V2;// = (p3 - p1);
V2.x = vertices[0].x - vertices[3].x;
V2.y = vertices[0].y - vertices[3].y;
V2.z = vertices[0].z - vertices[3].z;
*/
surfaceNormal.x = (V1.y*V2.z) - (V1.z-V2.y);
surfaceNormal.y = - ( (V2.z * V1.x) - (V2.x * V1.z) );
surfaceNormal.z = (V1.x-V2.y) - (V1.y-V2.x);
float normalize = sqrtf((pow(surfaceNormal.x,2) + pow(surfaceNormal.y,2) + pow(surfaceNormal.z,2)));
surfaceNormal.x = surfaceNormal.x/normalize;
surfaceNormal.y = surfaceNormal.y/normalize;
surfaceNormal.z = surfaceNormal.z/normalize;

This cross product code is badly broken:
surfaceNormal.x = (V1.y*V2.z) - (V1.z-V2.y);
surfaceNormal.y = - ( (V2.z * V1.x) - (V2.x * V1.z) );
surfaceNormal.z = (V1.x-V2.y) - (V1.y-V2.x);
The expressions within the parentheses should all have a multiplication operator, but half of them are subtractions instead in the code above.
The cross product calculation should be:
surfaceNormal.x = V1.y * V2.z - V1.z * V2.y;
surfaceNormal.y = V1.z * V2.x - V1.x * V2.z;
surfaceNormal.z = V1.x * V2.y - V1.y * V2.x;
You may want to look into using a matrix/vector library. There are many of them freely available if you do some searching.

Related

Error solving a system of differential equations with one third order differential equation in Matlab. Dimensions of array are not consistent

J1 = 18.041;
J2 = 1.99;
J3 = 6.58;
J4 = 1.46;
J5 = 7.50;
J6 = 15.46;
J7 = 4.21;
J8 = 7.68;
J9 = 24.84;
J10 = 8.58;
J11 = 6.57;
J12 = 4.20;
J13 = 4.63;
J14 = 0.7648;
J15 = 0.3607;
J16 = 68.48;
Js1 = 145.09;
Js2 = 128.58;
Js3 = 138.841;
Js4 = 145.09;
Jcar = 1.7916;
Jhollow = 1.478;
r1 = 45;
r2 = 46;
r3 = 38;
r4 = 15;
r5 = 37;
r6 = 68;
r7 = 29;
r8 = 37;
r9 = 60;
r10 = 33;
r11 = 29;
r12 = 27;
r13 = 52;
r14 = 19;
r15 = 16;
r16 = 57;
k0 = 241.32;
w2 = 1000;
kcar = 0.356;
khollow = 6.091;
D = 4867.91;
%syms h3(t) x3(t) theta2(t) theta1(t) x2(t) h4(t) h5(t) h1(t) h2(t) x1(t)
%ode1 = diff(h3)- (J4*r9*(diff(theta2,2)))/r4 == (theta2*khollow*r9)/r4 - kcar*theta1;
%ode2 = diff(x3,t) - (h3/J8)*r8 + w2*r3 == 0;
%ode3 = diff(x2,t) - (h2/J10)*r10 + w2*r5 == 0;
%ode4 = diff(theta2,t)*(r4- 1/(k0*r4)) - (diff(theta2,t,3)/(k0*r4)) - h3*r9/(J9 + Js1) + w2*r4 == 0;
%ode5 = diff(h1,t) - D*r16*(diff(x1)) == k0*x1*r16 - D*r16*((h4*r14)/(Js2 + J1 + (Jcar/3)));
%ode6 = diff(x1,t) - (h4)*r14/(Js2 + J1 + (Jcar/3)) + h1*r16/J16 == 0;
%ode7 = diff(h5,t) - x3*k0*r8 == 0;
%ode8 = diff(h2,t) - x2*k0*r10 == 0;
%ode9 = diff(h4,t) - kcar*theta1 - (2*h4*D)/(Js2 + J1 + (Jcar/3)) + k0*x1*r14 == 0;
%ode10 = diff(theta1,t) - h3/(J9 + Js1) + (h4)/(Js2 + J1 + (Jcar/3)) == 0;
%odes = [ode1; ode2; ode3; ode4; ode5; ode6; ode7; ode8; ode9; ode10];
%S = dsolve(odes);
f = #(t,x) [(J4*r9*(diff(x(4),2)))/r4 + (x(4)*khollow*r9)/r4 - kcar*x(10);
(x(1)*r8)/(J8) - w2*r3;
(x(8)/J10)*r10 - w2*r5;
(x(1)*r9)/(J9 + Js1)*r4 + (diff(x(4)) + diff(x(4),3))/(k0*r4*r4) - w2;
k0*x(6)*r16 - D*r16*(((x(9))*r14)/(Js2 + J1 + (Jcar/3)) - diff(x(6)));
(x(9)*r14)/(Js2 + J1 + (Jcar/3)) - (x(5)*r16)/J16;
x(2)*k0*r8;
x(3)*k0*r10;
kcar*x(10) - x(9)*2*D/(Js1 + J1 + (Jcar/3)) -k0*x(6)*r14;
x(1)/(J9 + Js1) - x(9)/(Js2 + J1 + (Jcar/3))];
[t,xa] = ode45(f,[0 1.5], [0 2 2 2 2 3 1 9 9 1])
Array dimensions are not consistent matlab output error. The commented out code runs for a long time and has not outputted results after running it for 15-20 minutes. The differentials equations are solved using ODE 45. Would really appreciate some help on this. The differential equations come from analyzing a dual clutch manual transmission using the bond graph technique.
Before putting a function like f into ode, try it. It is already broken and you get the same error when calling f(t,x). Further debugging it, evaluate the lines of f one by one:
>> (J4*r9*(diff(x(4),2)))/r4 + (x(4)*khollow*r9)/r4 - kcar*x(10)
ans =
[]
>> (x(1)*r8)/(J8) - w2*r3
ans =
-38000
The first row holds 0 elements, the second 1 element. I did not continue but this is already a problem. Each row has to have the same number of elements, probably 1 in your case.

Intercept values of two lines plotted with an array

I am trying to get the values intercept of two lines, t70_bot_inf and t70_top_0, and would like to mark it with a horizontal and vertical line. Are there any modules with could help me with this? I have tried Shapley which was unfortunately unsuccessful. Cheers!
import pandas as pd
import numpy as np
import matplotlib.pyplot as plt
#global values
sigma_ct_inf = 0
sigma_ct_0 = 0
sigma_c_inf = 30
sigma_c_0 = 12
beta = 0.8
#values T 70
A = 359000
Wb = 40830202.33
Wt = 72079066.94
Mmin = 701.17
Mmax = 978.52
#Magnel Diagram
e = np.arange(-200, 1001)
t70_top_0 = pd.Series({'y': ((e - (Wt / A)) / ((Mmin * 10 ** 6) + sigma_ct_0 * Wt)) * 10 ** 6})
t70_bot_0 = pd.Series({'y': ((e + (Wb / A)) / ((Mmin * 10 ** 6) + sigma_c_0 * Wb)) * 10 ** 6})
t70_top_inf = pd.Series({'y': (((e - (Wt / A)) * beta) / ((Mmax * 10 ** 6) - sigma_c_inf * Wt)) * 10 ** 6})
t70_bot_inf = pd.Series({'y': (((e + (Wb / A)) * beta) / ((Mmax * 10 ** 6) - sigma_ct_inf * Wb)) * 10 ** 6})
bot = np.min([t70_bot_0['y'], t70_bot_inf['y']], axis=0)
top = np.max([t70_top_0['y'], t70_top_inf['y']], axis=0)
fig, ax = plt.subplots()
ax.set_title('Magnel Diagram, T-70')
ax.plot(e, t70_top_0['y'], lw=0.5, label='Top, t = 0')
ax.plot(e, t70_bot_0['y'], lw=0.5, label='Bottom, t = 0')
ax.plot(e, t70_top_inf['y'], lw=0.5, label='Top, t = \u221E')
ax.plot(e, t70_bot_inf['y'], lw=0.5, label='Bottom, t = \u221E')
ax.fill_between(e, bot, top, where=top < bot, color='r', alpha=0.4)
ax.spines['top'].set_visible(False)
ax.spines['right'].set_visible(False)
plt.ylabel('1/P0 [1/MN]')
plt.xlabel('Eccentricity [mm]')
ax.grid()
plt.legend()
plt.show()

Partial differentiation/gradient of anonymous function with array input

I have following anonymous function (with x as an array):
f = #(x) 312*x(2) - 240*x(1) + 30*x(3) - 24*x(4) + 282*x(1)*x(2) + 30*x(1)*x(3) + 18*x(1)*x(4) + 54*x(2)*x(3) + 6*x(2)*x(4) + 6*x(3)*x(4) + 638*x(1)^2 + 207*x(2)^2 + 6*x(3)^2 + 3*x(4)^2 + 4063
I want to make gradient of this function and save it for future use. Also with array input.
X = [ 0;...
0;...
0;...
0];
F = f(X)
G = g(X)
Is it possible to archive this with this type of function? Or maybe it is possible to somehow make it via diff command? Something like this:
g = [diff(f, x(1));...
diff(f, x(2));...
diff(f, x(3));...
diff(f, x(4))]
I guess the following is what you want. I'm afraid, you need the Symbolic Math Toolbox for a simple solution, otherwise I'd rather calculate the derivatives by hand.
x = [1 2 3 4];
%// define function
syms a b c d
f = 312*b - 240*a + 30*c - 24*d + 282*a*b + 30*a*c + 18*a*d + 54*b*c + ...
6*b*d + 6*c*d + 638*a^2 + 207*b^2 + 6*c^2 + 3*d^2 + 4063
%// symbolic gradient
g = gradient(f,[a,b,c,d])
%// eval symbolic function
F = subs(f,[a,b,c,d],x)
G = subs(g,[a,b,c,d],x)
%// convert symbolic value to double
Fd = double(F)
Gd = double(G)
or alternatively:
%// convert symbolic function to anonymous function
fd = matlabFunction(f)
gd = matlabFunction(g)
%// eval anonymous function
x = num2cell(x)
Fd = fd(x{:})
Gd = gd(x{:})
f =
638*a^2 + 282*a*b + 30*a*c + 18*a*d - 240*a + 207*b^2 + 54*b*c +
6*b*d + 312*b + 6*c^2 + 6*c*d + 30*c + 3*d^2 - 24*d + 4063
g =
1276*a + 282*b + 30*c + 18*d - 240
282*a + 414*b + 54*c + 6*d + 312
30*a + 54*b + 12*c + 6*d + 30
18*a + 6*b + 6*c + 6*d - 24
F =
7179
G =
1762
1608
228
48
fd =
#(a,b,c,d)a.*-2.4e2+b.*3.12e2+c.*3.0e1-d.*2.4e1+a.*b.*2.82e2+a.*c.*3.0e1+a.*d.*1.8e1+b.*c.*5.4e1+b.*d.*6.0+c.*d.*6.0+a.^2.*6.38e2+b.^2.*2.07e2+c.^2.*6.0+d.^2.*3.0+4.063e3
gd =
#(a,b,c,d)[a.*1.276e3+b.*2.82e2+c.*3.0e1+d.*1.8e1-2.4e2;a.*2.82e2+b.*4.14e2+c.*5.4e1+d.*6.0+3.12e2;a.*3.0e1+b.*5.4e1+c.*1.2e1+d.*6.0+3.0e1;a.*1.8e1+b.*6.0+c.*6.0+d.*6.0-2.4e1]
x =
[1] [2] [3] [4]
Fd =
7179
Gd =
1762
1608
228
48

opengl matrix math multiplication

I am writing a simple c 4x4 matrix math library and wanted some feedback, especially from people with opengl experience.
Typically there's two ways to do matrix multiplication. I tested this code and it works, according to results from wolfram alpha but my main concern is that this matrix is in the right order.
My matrix is just an array of 16 doubles.
The code to do the multiplication is below
out->m[0] = ( a->m[0] * b->m[0]) + (a->m[1] * b->m[4]) + (a->m[2] * b->m[8]) + (a->m[3] * b->m[12] );
out->m[4] = ( a->m[4] * b->m[0]) + (a->m[5] * b->m[4]) + (a->m[6] * b->m[8]) + (a->m[7] * b->m[12] );
out->m[8] = ( a->m[8] * b->m[0]) + (a->m[9] * b->m[4]) + (a->m[10] * b->m[8]) + (a->m[11] * b->m[12] );
out->m[12] = ( a->m[12] * b->m[0]) + (a->m[13] * b->m[4]) + (a->m[14] * b->m[8]) + (a->m[15] * b->m[12] );
out->m[1] = ( a->m[0] * b->m[1]) + (a->m[1] * b->m[5]) + (a->m[2] * b->m[9]) + (a->m[3] * b->m[13] );
out->m[5] = ( a->m[4] * b->m[1]) + (a->m[5] * b->m[5]) + (a->m[6] * b->m[9]) + (a->m[7] * b->m[13] );
out->m[9] = ( a->m[8] * b->m[1]) + (a->m[9] * b->m[5]) + (a->m[10] * b->m[9]) + (a->m[11] * b->m[13] );
out->m[13] = ( a->m[12] * b->m[1]) + (a->m[13] * b->m[5]) + (a->m[14] * b->m[9]) + (a->m[15] * b->m[13] );
out->m[2] = ( a->m[0] * b->m[2]) + (a->m[1] * b->m[6]) + (a->m[2] * b->m[10]) + (a->m[3] * b->m[14] );
out->m[6] = ( a->m[4] * b->m[2]) + (a->m[5] * b->m[6]) + (a->m[6] * b->m[10]) + (a->m[7] * b->m[14] );
out->m[10] = ( a->m[8] * b->m[2]) + (a->m[9] * b->m[6]) + (a->m[10] * b->m[10]) + (a->m[11] * b->m[14] );
out->m[14] = ( a->m[12] * b->m[2]) + (a->m[13] * b->m[6]) + (a->m[14] * b->m[10]) + (a->m[15] * b->m[14] );
out->m[3] = ( a->m[0] * b->m[3]) + (a->m[1] * b->m[7]) + (a->m[2] * b->m[11]) + (a->m[3] * b->m[15] );
out->m[7] = ( a->m[4] * b->m[3]) + (a->m[5] * b->m[7]) + (a->m[6] * b->m[11]) + (a->m[7] * b->m[15] );
out->m[11] = ( a->m[8] * b->m[3]) + (a->m[9] * b->m[7]) + (a->m[10] * b->m[11]) + (a->m[11] * b->m[15] );
out->m[15] = ( a->m[12] * b->m[3]) + (a->m[13] * b->m[7]) + (a->m[14] * b->m[11]) + (a->m[15] * b->m[15] );
I wanted to make sure that this will give me the correct results for setting up my transformation matrix.
matrix m = 1,3,4,-1,5,6,7,-1,8,8,8,-1,0,0,0,1
which is arranged in memory like this:
1,3,4,-1
5,6,7,-1
8,8,8,-1
0,0,0,1
which I think is the way opengl lays out it's matrix as 16 numbers.
using my code my answer comes out to be
[ 48.000000 53.000000 57.000000 -9.000000 ]
[ 91.000000 107.000000 118.000000 -19.000000 ]
[ 112.000000 136.000000 152.000000 -25.000000 ]
[ 0.000000 0.000000 0.000000 1.000000 ]
which is the transpose of wolfram alpha's answer.
(48 | 91 | 112 | 0
53 | 107 | 136 | 0
57 | 118 | 152 | 0
-9 | -19 | -25 | 1)
Typically it looks like this, vertex point v model, view, projection matrices
position = projection * view * model * v
I can't say you why your results differ but one help is, if you send the matrix into a GLSL uniform dMat4, you can use the build in transpose functionallity of OpenGL to get the right matrix alignment:
glUniformMatrix4fv( Uniform_Location, 1, GL_TRUE, MatrixPointer );
The third parameter means, if OpenGL should transpose the matrix before setting the uniform.

Matlab : How to highlight GLYCINE residues in my Ramachandran plot? [duplicate]

This question already has an answer here:
MATLAB : What is the mistake in my Ramachandran plot?
(1 answer)
Closed 8 years ago.
I am trying matlab to plot ramachandran plot, without using built in command. I have succeeded too. Now I wanted to spot the GLYCINEs alone in the scatter array. Any ideas how to do this? (link to 1UBQ.pdb file : http://www.rcsb.org/pdb/download/downloadFile.do?fileFormat=pdb&compression=NO&structureId=1UBQ)
% Program to plot Ramanchandran plot of Ubiquitin
close all; clear ; clc; % close all figure windows, clear variables, clear screen
pdb1 ='/home/devanandt/Documents/VMD/1UBQ.pdb';
p=pdbread(pdb1); % read pdb file corresponding to ubiquitin protein
atom={p.Model.Atom.AtomName};
n_i=find(strcmp(atom,'N')); % Find indices of atoms
ca_i=find(strcmp(atom,'CA'));
c_i=find(strcmp(atom,'C'));
X = [p.Model.Atom.X];
Y = [p.Model.Atom.Y];
Z = [p.Model.Atom.Z];
X_n = X(n_i(2:end)); % X Y Z coordinates of atoms
Y_n = Y(n_i(2:end));
Z_n = Z(n_i(2:end));
X_ca = X(ca_i(2:end));
Y_ca = Y(ca_i(2:end));
Z_ca = Z(ca_i(2:end));
X_c = X(c_i(2:end));
Y_c = Y(c_i(2:end));
Z_c = Z(c_i(2:end));
X_c_ = X(c_i(1:end-1)); % the n-1 th C (C of cabonyl)
Y_c_ = Y(c_i(1:end-1));
Z_c_ = Z(c_i(1:end-1));
V_c_ = [X_c_' Y_c_' Z_c_'];
V_n = [X_n' Y_n' Z_n'];
V_ca = [X_ca' Y_ca' Z_ca'];
V_c = [X_c' Y_c' Z_c'];
V_ab = V_n - V_c_;
V_bc = V_ca - V_n;
V_cd = V_c - V_ca;
phi=0;
for k=1:numel(X_c)
n1=cross(V_ab(k,:),V_bc(k,:))/norm(cross(V_ab(k,:),V_bc(k,:)));
n2=cross(V_bc(k,:),V_cd(k,:))/norm(cross(V_bc(k,:),V_cd(k,:)));
x=dot(n1,n2);
m1=cross(n1,(V_bc(k,:)/norm(V_bc(k,:))));
y=dot(m1,n2);
phi=cat(2,phi,-atan2d(y,x));
end
phi=phi(1,2:end);
X_n_ = X(n_i(2:end)); % (n+1) nitrogens
Y_n_ = Y(n_i(2:end));
Z_n_ = Z(n_i(2:end));
X_ca = X(ca_i(1:end-1));
Y_ca = Y(ca_i(1:end-1));
Z_ca = Z(ca_i(1:end-1));
X_n = X(n_i(1:end-1));
Y_n = Y(n_i(1:end-1));
Z_n = Z(n_i(1:end-1));
X_c = X(c_i(1:end-1));
Y_c = Y(c_i(1:end-1));
Z_c = Z(c_i(1:end-1));
V_n_ = [X_n_' Y_n_' Z_n_'];
V_n = [X_n' Y_n' Z_n'];
V_ca = [X_ca' Y_ca' Z_ca'];
V_c = [X_c' Y_c' Z_c'];
V_ab = V_ca - V_n;
V_bc = V_c - V_ca;
V_cd = V_n_ - V_c;
psi=0;
for k=1:numel(X_c)
n1=cross(V_ab(k,:),V_bc(k,:))/norm(cross(V_ab(k,:),V_bc(k,:)));
n2=cross(V_bc(k,:),V_cd(k,:))/norm(cross(V_bc(k,:),V_cd(k,:)));
x=dot(n1,n2);
m1=cross(n1,(V_bc(k,:)/norm(V_bc(k,:))));
y=dot(m1,n2);
psi=cat(2,psi,-atan2d(y,x));
end
psi=psi(1,2:end);
scatter(phi,psi)
box on
axis([-180 180 -180 180])
title('Ramachandran Plot for Ubiquitn Protein','FontSize',16)
xlabel('\Phi^o','FontSize',20)
ylabel('\Psi^o','FontSize',20)
grid
The output is :
EDIT : Is my plot correct? Biopython: How to avoid particular amino acid sequences from a protein so as to plot Ramachandran plot? has an answer which has slightly different plot.
The modified code is as below :
% Program to plot Ramanchandran plot of Ubiquitin with no glycines
close all; clear ; clc; % close all figure windows, clear variables, clear screen
pdb1 ='/home/devanandt/Documents/VMD/1UBQ.pdb';
p=pdbread(pdb1); % read pdb file corresponding to ubiquitin protein
atom={p.Model.Atom.AtomName};
n_i=find(strcmp(atom,'N')); % Find indices of atoms
ca_i=find(strcmp(atom,'CA'));
c_i=find(strcmp(atom,'C'));
X = [p.Model.Atom.X];
Y = [p.Model.Atom.Y];
Z = [p.Model.Atom.Z];
X_n = X(n_i(2:end)); % X Y Z coordinates of atoms
Y_n = Y(n_i(2:end));
Z_n = Z(n_i(2:end));
X_ca = X(ca_i(2:end));
Y_ca = Y(ca_i(2:end));
Z_ca = Z(ca_i(2:end));
X_c = X(c_i(2:end));
Y_c = Y(c_i(2:end));
Z_c = Z(c_i(2:end));
X_c_ = X(c_i(1:end-1)); % the n-1 th C (C of cabonyl)
Y_c_ = Y(c_i(1:end-1));
Z_c_ = Z(c_i(1:end-1));
V_c_ = [X_c_' Y_c_' Z_c_'];
V_n = [X_n' Y_n' Z_n'];
V_ca = [X_ca' Y_ca' Z_ca'];
V_c = [X_c' Y_c' Z_c'];
V_ab = V_n - V_c_;
V_bc = V_ca - V_n;
V_cd = V_c - V_ca;
phi=0;
for k=1:numel(X_c)
n1=cross(V_ab(k,:),V_bc(k,:))/norm(cross(V_ab(k,:),V_bc(k,:)));
n2=cross(V_bc(k,:),V_cd(k,:))/norm(cross(V_bc(k,:),V_cd(k,:)));
x=dot(n1,n2);
m1=cross(n1,(V_bc(k,:)/norm(V_bc(k,:))));
y=dot(m1,n2);
phi=cat(2,phi,-atan2d(y,x));
end
phi=phi(1,2:end);
X_n_ = X(n_i(2:end)); % (n+1) nitrogens
Y_n_ = Y(n_i(2:end));
Z_n_ = Z(n_i(2:end));
X_ca = X(ca_i(1:end-1));
Y_ca = Y(ca_i(1:end-1));
Z_ca = Z(ca_i(1:end-1));
X_n = X(n_i(1:end-1));
Y_n = Y(n_i(1:end-1));
Z_n = Z(n_i(1:end-1));
X_c = X(c_i(1:end-1));
Y_c = Y(c_i(1:end-1));
Z_c = Z(c_i(1:end-1));
V_n_ = [X_n_' Y_n_' Z_n_'];
V_n = [X_n' Y_n' Z_n'];
V_ca = [X_ca' Y_ca' Z_ca'];
V_c = [X_c' Y_c' Z_c'];
V_ab = V_ca - V_n;
V_bc = V_c - V_ca;
V_cd = V_n_ - V_c;
psi=0;
for k=1:numel(X_c)
n1=cross(V_ab(k,:),V_bc(k,:))/norm(cross(V_ab(k,:),V_bc(k,:)));
n2=cross(V_bc(k,:),V_cd(k,:))/norm(cross(V_bc(k,:),V_cd(k,:)));
x=dot(n1,n2);
m1=cross(n1,(V_bc(k,:)/norm(V_bc(k,:))));
y=dot(m1,n2);
psi=cat(2,psi,-atan2d(y,x));
end
psi=psi(1,2:end);
res=strsplit(p.Sequence.ResidueNames,' ');
angle =[phi;psi];
angle(:,find(strcmp(res,'GLY'))-1)=[];
scatter(angle(1,:),angle(2,:))
box on
axis([-180 180 -180 180])
title('Ramachandran Plot for Ubiquitn Protein','FontSize',16)
xlabel('\Phi^o','FontSize',20)
ylabel('\Psi^o','FontSize',20)
grid
which gives output (with no GLY) as below :
I would change this code block to use logical indexing
res=strsplit(p.Sequence.ResidueNames,' ');
angle =[phi;psi];
angle(:,find(strcmp(res,'GLY'))-1)=[];
Instead:
residues = strsplit(p.Sequency.ResidueNames,' ');
glycine = ismember(residues,'GLY');
angle = [phi;psi];
angleNoGLY= angle(:,~glycine);
Doing it this way, if you wanted to highlight glycine (or any other residue) you can easily call it out:
angleGLY = angle(:,glycine);
plot(angleNoGLY(1,:),angleNoGLY(2,:),'ob')
line(angleGLY(1,:),angleGLY(2,:),'Marker','o','Color','r','LineStyle','none')

Resources