在不使用Bioinformatics工具箱的情况下在Matlab中可视化分子的3D结构

时间:2013-05-14 23:16:46

标签: matlab 3d

我想用“球和棒”制作一个分子的三维结构图。 Matlab Bioinformatics Toolbox展示了如何使用例如:

来实现这一目标(以及更多)
 ubi = getpdb('1ubi');
 h1 = molviewer(ubi);

有没有办法在不使用Bioinformatics Toolbox的情况下将pdb文件加载到matlab和\或可视化3d结构?

1 个答案:

答案 0 :(得分:3)

以下是在Matlab中绘制pdb文件的两个示例:

  1. Publication-quality protein and molecule rendering in MATLAB”(作者:Keith Callenberg)
  2. Molecule Viewer(作者:Joe Hicklin)
  3. 上述(1)的示例代码:

    function draw_protein(pdbfile)
    pdb=fopen(pdbfile,'r');
    l=fgets(pdb);
    q=1;
    resolution = 5;
    
    while l~=-1
        if (l(1:4) == 'ATOM') & (l(14) ~= 'H' & l(13) ~= 'H')
    
            if  (strncmp('PHE',l(18:20),3)==1 & strncmp('C',l(14),1)==1) | ...
                (strncmp('TYR',l(18:20),3)==1 & strncmp('C',l(14),1)==1) | ...
                (strncmp('TRP',l(18:20),3)==1 & strncmp('C',l(14),1)==1)
                if strncmp('CG',l(14:15),2)==1 | strncmp('CD ',l(14:16),3)==1 | ...
                   strncmp('CE',l(14:15),2)==1 | strncmp('CZ',l(14:15),2)==1 | ...
                   strncmp('CD2',l(14:16),3)==1
                   r(q,4)=1.85; 
                elseif strncmp('C',l(14),1)==1
                   r(q,4)=2.0;         
                end
            elseif strncmp('N',l(14),1)==1
                r(q,4)=1.5;     
            elseif strncmp('C',l(14),1)==1
                r(q,4)=2.0;   
            elseif strncmp('O',l(14),1)==1
                r(q,4)=1.4;     
            elseif strncmp('S',l(14),1)==1
                r(q,4)=1.85;
            elseif strncmp('POT',l(14:16),3)==1
                r(q,4)=1.49
                %r(q,4)=3.31
            elseif (l(14) == 'H' | l(13) == 'H')
                if l(64) == '1'
                    r(q,4) = 1;
                %else
                %    r(q,4) = 0;
                end
            else
                %display('Unknown atom type')
                l
                r(q,4)=2.0;     % CALL UNKNOWN ATOM A CARBON
            end
    
            r(q,1)=str2num(l(31:38));  % x
            r(q,2)=str2num(l(39:46));  % y
            r(q,3)=str2num(l(47:54));  % z
    
    
            if strncmp('ARG',l(18:20),3)==1 | strncmp('LYS',l(18:20),3)==1 | strncmp('HSP',l(18:20),3)==1
                r(q,5:7)=[0.2 0.1 0.90]; %blue for positively charged
            elseif strncmp('THR',l(18:20),3)==1 | strncmp('ASN',l(18:20),3)==1 | strncmp('SER',l(18:20),3)==1 | strncmp('GLN',l(18:20),3)==1
                r(q,5:7)=[0.2 0.90 0.1]; %green for uncharged polar
            elseif strncmp('ASP',l(18:20),3)==1 | strncmp('GLU',l(18:20),3)==1
                r(q,5:7)=[0.90 0.2 0.1]; %red for negatively charged
            else
                r(q,5:7)=[1 0.95 0.9]; %white for hydrophobic
            end
    
            q=q+1;
        end
        l=fgets(pdb);
    end
    
    display 'done loading pdb coordinates';
    
    figure;
    hold all;
    
    for i=1:length(r(:,1)) 
        draw_sphere(r(i,1),r(i,2),r(i,3),r(i,4),r(i,5:7),resolution);
    end
    
    light
    camlight('right');
    end
    
    function draw_sphere(xd,yd,zd,rad,color,resolution)
    n = resolution;
    
    % -pi to theta to pi is a row vector.
    % -pi/2 to phi to pi/2 is a column vector.
    theta = (-n:2:n)/n*pi;
    phi = (-n:2:n)'/n*pi/2;
    cosphi = cos(phi); cosphi(1) = 0; cosphi(n+1) = 0;
    sintheta = sin(theta); sintheta(1) = 0; sintheta(n+1) = 0;
    
    x = cosphi*cos(theta);
    y = cosphi*sintheta;
    z = sin(phi)*ones(1,n+1);
    surf(rad*x+xd,rad*y+yd,rad*z+zd,'EdgeColor','none','FaceColor',color,'FaceLighting','phong','AmbientStrength',0.1,'DiffuseStrength',0.8,'SpecularStrength',0.2);
    
    end