/tags/R2002-04-20/octave-forge/extra/pdb/write_pdb_quick.m

# · Objective C · 138 lines · 125 code · 13 blank · 0 comment · 19 complexity · ee6a5d004b2e0a01bf919b874c9dee3c MD5 · raw file

  1. function write_pdb_quick(p, fname)
  2. #function write_pdb_quick(p, fname)
  3. #
  4. # Writes (only) the atomic coordinates from pdb struct p
  5. # (see read_pdb.m) to a pdb-file fname
  6. ## Created: 3.8.2001
  7. ## Author: Teemu Ikonen <tpikonen@pcu.helsinki.fi>
  8. if(!is_struct(p)) # || !struct_contains(p, "acoord"))
  9. error("p must be a pdb struct");
  10. endif
  11. [f, err] = fopen(fname, "w");
  12. if(f < 0)
  13. error("Could not open output file: %s", err);
  14. endif
  15. buf = blanks(80);
  16. if(struct_contains(p, "acoord"))
  17. natoms = size(p.acoord, 1);
  18. if(struct_contains(p, "atomname"))
  19. atomname = toupper(p.atomname);
  20. else
  21. for i = 1:natoms,
  22. atomname(i, :) = " ";
  23. endfor
  24. endif
  25. if(struct_contains(p, "aresname"))
  26. aresname = toupper(p.aresname);
  27. else
  28. for i = 1:natoms,
  29. aresname(i, :) = " ";
  30. endfor
  31. endif
  32. if(struct_contains(p, "aresseq"))
  33. aresseq = p.aresseq;
  34. else
  35. aresseq = ones(natoms, 1);
  36. endif
  37. if(struct_contains(p, "aoccupancy"))
  38. aoccupancy = p.aoccupancy;
  39. else
  40. aoccupancy = ones(natoms, 1);
  41. endif
  42. if(struct_contains(p, "atempfactor"))
  43. atempfactor = p.atempfactor;
  44. else
  45. atempfactor = zeros(natoms, 1);
  46. endif
  47. j = 1;
  48. while(j <= natoms)
  49. buf = blanks(80);
  50. buf(1:6) = "ATOM ";
  51. buf(7:11) = sprintf("%5d", j);
  52. buf(13:16) = sprintf("%4s", atomname(j,:));
  53. buf(18:20) = aresname(j,:);
  54. buf(23:26) = sprintf("%4d", aresseq(j));
  55. buf(31:54) = sprintf(" %7.3f %7.3f %7.3f", p.acoord(j,:));
  56. buf(55:60) = sprintf(" %5.2f", aoccupancy(j,:));
  57. buf(61:66) = sprintf("%6.2f", atempfactor(j,:));
  58. buf(77:78) = sprintf("%s", atomname(j,1:2));
  59. buf(80) = "\n";
  60. fprintf(f, "%s", buf);
  61. j++;
  62. endwhile
  63. buf = blanks(80);
  64. buf(1:6) = "TER ";
  65. buf(7:11) = sprintf("%5d", j);
  66. buf(18:20) = aresname(natoms, :);
  67. buf(23:26) = sprintf("%4d", aresseq(natoms));
  68. buf(80) = "\n";
  69. fprintf(f, "%s", buf);
  70. j++;
  71. endif
  72. if(struct_contains(p,"hetcoord"))
  73. nhet = size(p.hetcoord, 1);
  74. if(struct_contains(p, "hetname"))
  75. hetname = toupper(p.hetname);
  76. else
  77. for i = 1:nhet
  78. hetname(i, :) = " ";
  79. endfor
  80. endif
  81. if(struct_contains(p, "hetresname"))
  82. hetresname = toupper(p.hetresname);
  83. else
  84. for i = 1:nhet,
  85. hetresname(i, :) = " ";
  86. endfor
  87. endif
  88. if(struct_contains(p, "hetresseq"))
  89. hetresseq = p.hetresseq;
  90. else
  91. hetresseq = ones(nhet, 1);
  92. endif
  93. if(struct_contains(p, "hetoccupancy"))
  94. hetoccupancy = p.hetoccupancy;
  95. else
  96. hetoccupancy = ones(nhet, 1);
  97. endif
  98. if(struct_contains(p, "hettempfactor"))
  99. hettempfactor = p.hettempfactor;
  100. else
  101. hettempfactor = zeros(nhet, 1);
  102. endif
  103. i = 1;
  104. while(i <= nhet)
  105. buf = blanks(80);
  106. buf(1:6) = "HETATM";
  107. buf(7:11) = sprintf("%5d", j);
  108. buf(13:16) = sprintf("%s", hetname(i,:));
  109. buf(18:20) = hetresname(i, :);
  110. buf(23:26) = sprintf("%4d", hetresseq(i));
  111. buf(31:54) = sprintf(" %7.3f %7.3f %7.3f", p.hetcoord(i,:));
  112. buf(55:60) = sprintf(" %5.2f", hetoccupancy(i,:));
  113. buf(61:66) = sprintf("%6.2f", hettempfactor(i,:));
  114. buf(80) = "\n";
  115. fprintf(f, "%s", buf);
  116. i++;
  117. j++;
  118. endwhile
  119. endif
  120. buf = blanks(80);
  121. buf(1:6) = "END ";
  122. buf(80) = "\n";
  123. fprintf(f, "%s", buf);
  124. fclose(f);
  125. endfunction