home *** CD-ROM | disk | FTP | other *** search
/ Nebula 1 / Nebula One.iso / Educational / MolViewer / Source / Inspector.m < prev    next >
Encoding:
Text File  |  1995-06-12  |  9.6 KB  |  458 lines

  1. /* Inspector.m - Copyright 1993  Steve Ludtke */
  2. /* Nothing too exciting here. This just acts as a connection between */
  3. /* the inspector panel and the rest of the program. Most of the */
  4. /* actual work is done elsewhere */
  5. /* No comments here, see Inspector.h for brief descriptions */
  6.  
  7. #import "Mtypes.h"
  8. #import "Inspector.h"
  9. #import "MolObj.h"
  10. #import "SelectView.h"
  11. #import "AminoView.h"
  12.  
  13. extern ACID acid[AADEF];
  14.  
  15. @implementation Inspector
  16.  
  17. - startup:(Molecule *)Mol :(int)Nmol :(struct ELINFO *)Elinfo
  18. {
  19. mol=Mol;
  20. nmol=Nmol;
  21. elinfo=Elinfo;
  22. aminoIns=[aminoIns contentView];
  23. atabIns=[atabIns contentView];
  24. atomIns=[atomIns contentView];
  25. mode= -1;
  26. nlist=nsel=0;
  27. size=1.3;
  28. list=NULL;
  29. return self;
  30. }
  31.  
  32. -update:(int)Nmol :(int)level
  33. {
  34. nmol=Nmol;
  35. if (nmol==0) {
  36.     [[abcount cellAt:0 :0] setStringValue:""];
  37.     [[abcount cellAt:1 :0] setStringValue:""];
  38. }
  39. else {
  40.     [[abcount cellAt:0 :0] setIntValue:mol[0].numa];
  41.     [[abcount cellAt:1 :0] setIntValue:mol[0].numlb];
  42. }
  43.  
  44. if (mode==0||mode==-1) [self a_insp:self];
  45. else if (mode==1&&level>=U_BONDS) [self m_insp:self];
  46. else if (mode==1) [self m_upd:self];
  47. /*else if (mode==2) [self t_insp:self];*/
  48. return self;
  49. }
  50.  
  51. -newMol
  52. {
  53. mode= -1;
  54. return self;
  55. }
  56.  
  57. - a_bondAng:sender
  58. {
  59. float d;
  60. char s[80];
  61. int i,n[3];
  62.  
  63. if (nsel!=3) { [a_message setStringValue:"Select 3 atoms first"]; return self;}
  64.  
  65. for (i=0; i<3; i++) n[i]=list[i].stab;
  66.  
  67. d=[molobj bondAng:n[0] :n[1] :n[2]]*180.0/M_PI;
  68.  
  69. for (i=0; i<2; i++) {
  70.     if (mol[0].atom[n[i]].bnd[0]!=n[i+1]&&mol[0].atom[n[i]].bnd[1]!=n[i+1]&& mol[0].atom[n[i]].bnd[2]!=n[i+1]&&mol[0].atom[n[i]].bnd[3]!=n[i+1]) break;
  71. }
  72. if (i==2) sprintf(s,"Angle=%-5.2f deg",d);
  73. else sprintf(s,"Nonbonded, angle=%5.2f",d);
  74.  
  75. [a_message setStringValue:s];
  76. return self;
  77. }
  78.  
  79. - a_bondLen:sender
  80. {
  81. int n,n1;
  82. float d;
  83. char s[80];
  84.  
  85. if (nsel!=2) { [a_message setStringValue:"Select 2 atoms first"]; return self;}
  86. n=list[0].stab;
  87. n1=list[1].stab;
  88.  
  89. d=sqrt(SQR(mol[0].coord[n][0]-mol[0].coord[n1][0])+SQR(mol[0].coord[n][1]-mol[0].coord[n1][1])+SQR(mol[0].coord[n][2]-mol[0].coord[n1][2]));
  90.  
  91. if (mol[0].atom[n].bnd[0]!=n1&&mol[0].atom[n].bnd[1]!=n1&& mol[0].atom[n].bnd[2]!=n1&&mol[0].atom[n].bnd[3]!=n1) {
  92.     sprintf(s,"Nonbonded distance=%4.2fÅ",d);
  93. }
  94. else sprintf(s,"Distance=%4.2fÅ",d);
  95.  
  96. [a_message setStringValue:s];
  97. return self;
  98. }
  99.  
  100. - a_dihedral:sender
  101. {
  102. float d;
  103. char s[80];
  104. int i,n[4];
  105.  
  106. if (nsel!=4) { [a_message setStringValue:"Select 4 atoms first"]; return self;}
  107.  
  108. for (i=0; i<4; i++) n[i]=list[i].stab;
  109.  
  110. d=[molobj dihedral:n[0] :n[1] :n[2] :n[3]]*180.0/M_PI;
  111.  
  112. for (i=0; i<3; i++) {
  113.     if (mol[0].atom[n[i]].bnd[0]!=n[i+1]&&mol[0].atom[n[i]].bnd[1]!=n[i+1]&& mol[0].atom[n[i]].bnd[2]!=n[i+1]&&mol[0].atom[n[i]].bnd[3]!=n[i+1]) break;
  114. }
  115. if (i==3) sprintf(s,"dihedral=%-5.2f deg",d);
  116. else sprintf(s,"nonbonded, angle=%5.2f",d);
  117.  
  118. [a_message setStringValue:s];
  119. return self;
  120. }
  121.  
  122. - a_insp:sender
  123. {
  124. int i,j;
  125. [self newInsp];
  126. mode=0;
  127. [inspectBox setContentView:atomIns];
  128. if (nlist!=mol[0].numa) {
  129.     if (list!=NULL) free(list);
  130.     list=malloc(sizeof(struct SELDAT)*mol[0].numa);
  131.     nlist=mol[0].numa;
  132. }
  133.  
  134. for (i=0; i<nlist; i++) {
  135.     j=mol[0].atom[i].anum;
  136.     sprintf(list[i].text,"%3d  %c%c",i, elinfo[j].name[0],elinfo[j].name[1]);
  137. }
  138. nsel=0;
  139.  
  140. [a_select setData:nlist :list :self];
  141. [a_select setHeader:" N  ATOM"];
  142. [inspectBox display];
  143. return self;
  144. }
  145.  
  146. - t_insp:sender
  147. {
  148. int i;
  149.  
  150. [self newInsp];
  151. mode=2;
  152. [inspectBox setContentView:atabIns];
  153. if (list!=NULL) free(list);
  154. list=malloc(sizeof(struct SELDAT)*NEL);
  155. nlist=NEL;
  156.  
  157. for (i=0; i<nlist; i++) {
  158.     sprintf(list[i].text,"%-3d  %c%c",i+1, elinfo[i].name[0],elinfo[i].name[1]);
  159. }
  160.  
  161. [t_select setData:nlist :list :self];
  162. [t_select setHeader:"N   SYMB"];
  163. [inspectBox display];
  164. return self;
  165. }
  166.  
  167. - newInsp
  168. {
  169. switch (mode) 
  170. {
  171. case 0:
  172.     [a_select deselectAll];
  173.     [self deselected:0 :0];
  174.     break;
  175. case 1:
  176.     break;
  177. case 2:
  178.     [t_select deselectAll];
  179.     [self deselected:0 :0];
  180.     break;
  181. }
  182. return self;
  183. }
  184.  
  185. - t_newSize:sender
  186. {
  187. int i;
  188.  
  189. size=[sender floatValue];
  190. for (i=0; i<NEL; i++) elinfo[i].rad=size*elinfo[i].arad;
  191. [molobj update:U_POS];
  192. return self;
  193. }
  194.  
  195. - t_newColor:sender
  196. {
  197. int i;
  198. float c;
  199.  
  200. for (i=0; i<3; i++) {
  201.     c=[[t_color cellAt:i :0] floatValue];
  202.     if (c<0.0) [[t_color cellAt:i :0] setFloatValue:0.0];
  203.     if (c>1.0) [[t_color cellAt:i :0] setFloatValue:1.0];
  204. }
  205.  
  206. if (nsel!=1) return self;
  207. for (i=0; i<3; i++) 
  208.     elinfo[list[0].stab].color[i]=[[t_color cellAt:i :0] floatValue];
  209. return self;
  210. }
  211.  
  212. - t_newRad:sender
  213. {
  214. float f;
  215. if (nsel!=1) return self;
  216. f=[[t_radii cellAt:0 :0] floatValue];
  217. if (f<.01) [[t_radii cellAt:0 :0] setFloatValue:.01];
  218. if (f>4.0) [[t_radii cellAt:0 :0] setFloatValue:4.0];
  219. elinfo[list[0].stab].arad=[[t_radii cellAt:0 :0] floatValue];
  220. elinfo[list[0].stab].rad=elinfo[list[0].stab].arad*size;
  221. return self;
  222. }
  223.  
  224. - t_revert:sender
  225. {
  226. char *bpath;
  227. char s[80],t[100];
  228. int i;
  229. FILE *in;
  230.  
  231. bpath=(char *)[[NXBundle mainBundle] directory];
  232. sprintf(t,"%s/Library/MolViewer.dat",getenv("HOME"));
  233. in=fopen(t,"r");
  234. if (in==NULL) {
  235.     sprintf(t,"%s/MolViewer.dat",bpath);
  236.     in=fopen(t,"r");
  237.     if (in==NULL) { printf("No .rad\n"); exit(0); }
  238. }
  239. for (i=0; fgets(s,79,in)!=NULL&&i<NEL; i++) {
  240.     elinfo[i].color[0]=elinfo[i].color[1]=elinfo[i].color[2]=.7;
  241.     elinfo[i].name[0]=s[0];
  242.     if (s[1]!='\t') elinfo[i].name[1]=s[1];
  243.     else elinfo[i].name[1]=' ';
  244.     sscanf(&s[2],"%f %f %f %f",&elinfo[i].arad,&elinfo[i].color[0],&elinfo[i].
  245.         color[1],&elinfo[i].color[2]);
  246.     elinfo[i].rad=size*elinfo[i].arad;
  247. }
  248. fclose(in);
  249.  
  250. if (t[0]=='\n') t[0]=' ';
  251. sprintf(s,"Reverted to %s",t);
  252. [t_message setStringValue:s];
  253. [molobj update:U_POS];
  254. return self;
  255. }
  256.  
  257. - t_save:sender
  258. {
  259. char s[80];
  260. FILE *out;
  261. int i;
  262.  
  263. sprintf(s,"%s/Library/MolViewer.dat",getenv("HOME"));
  264. out=fopen(s,"w");
  265. if (out==NULL) {
  266.     [t_message setStringValue:"Can't write to $HOME/Library"];
  267.     return self;
  268. }
  269. for (i=0; i<NEL; i++) fprintf(out,"%c%c\t%5.3f\t%4.2f\t%4.2f\t%4.2f\n", 
  270.     elinfo[i].name[0],elinfo[i].name[1],elinfo[i].arad,elinfo[i].color[0], 
  271.     elinfo[i].color[1],elinfo[i].color[2]);
  272. fclose(out);
  273. strcat(s," written.");
  274. [t_message setStringValue:s];
  275. return self;
  276. }
  277.  
  278. -t_update:sender
  279. {
  280. [molobj update:U_POS];
  281. return self;
  282. }
  283.  
  284. - m_insp:sender
  285. {
  286. int i;
  287. [self newInsp];
  288. mode=1;
  289. [inspectBox setContentView:aminoIns];
  290. [molobj findAA:self];
  291. if (nlist!=mol[0].numaa) {
  292.     if (list!=NULL) free(list);
  293.     list=malloc(sizeof(struct SELDAT)*mol[0].numaa);
  294.     nlist=mol[0].numaa;
  295. }
  296.  
  297. for (i=0; i<nlist; i++) {
  298.     sprintf(list[i].text,"%3d  %s  %7.2f  %7.2f  %7.2f",i+1, acid[mol[0].am[i].anum].d2,mol[0].am[i].omega/DRC,mol[0].am[i].phi/DRC, mol[0].am[i].psi/DRC);
  299. }
  300. nsel=0;
  301.  
  302. [m_select setData:nlist :list :self];
  303. [m_select setHeader:" N   AA    omega     phi      psi"];
  304. /*[m_select setGHeader:"                  w         f        y"]; */ 
  305.  
  306. [inspectBox display];
  307. return self;
  308. }
  309.  
  310. - m_upd:sender
  311. {
  312. int i;
  313.  
  314. for (i=0; i<nlist; i++) {
  315.     sprintf(list[i].text,"%3d  %s  %7.2f  %7.2f  %7.2f",i+1, acid[mol[0].am[i].anum].d2,mol[0].am[i].omega/DRC,mol[0].am[i].phi/DRC, mol[0].am[i].psi/DRC);
  316. }
  317. nsel=0;
  318.  
  319. [inspectBox display];
  320. return self;
  321. }
  322.  
  323. -m_setAngS:sender
  324. {
  325. int n;
  326. float a;
  327.  
  328. n=[sender selectedRow];
  329. a=[[sender selectedCell] floatValue];
  330. switch(n) {
  331. case 0:
  332.     [[m_angT cellAt:0 :0] setFloatValue:a];
  333.     [molobj setOmega:a];
  334.     break;
  335. case 1:
  336.     [[m_angT cellAt:1 :0] setFloatValue:a];
  337.     [molobj setPhi:a];
  338.     break;
  339. case 2:
  340.     [[m_angT cellAt:2 :0] setFloatValue:a];
  341.     [molobj setPsi:a];
  342.     break;
  343. }
  344.  
  345. return self;
  346. }
  347.  
  348. -m_setAngT:sender
  349. {
  350. int n;
  351. float a;
  352.  
  353. n=[sender selectedRow];
  354. a=[[sender selectedCell] floatValue];
  355. switch(n) {
  356. case 0:
  357.     [[m_angS cellAt:0 :0] setFloatValue:a];
  358.     [molobj setOmega:a];
  359.     break;
  360. case 1:
  361.     [[m_angS cellAt:1 :0] setFloatValue:a];
  362.     [molobj setPhi:a];
  363.     break;
  364. case 2:
  365.     [[m_angS cellAt:2 :0] setFloatValue:a];
  366.     [molobj setPsi:a];
  367.     break;
  368. }
  369.  
  370. return self;
  371. }
  372.  
  373. -m_xfer:sender
  374. {
  375. char s[MAXSEQ+1];
  376. int i;
  377.  
  378. for (i=0; i<nlist; i++) {
  379.     s[i]=acid[mol[0].am[i].anum].d1[0];
  380. }
  381. s[i]=0;
  382. [m_amview setSeqStr:self :s];
  383. return self;
  384. }
  385.  
  386. - selected:(int)n :(int)Nsel
  387. {
  388. int i,j;
  389.  
  390. nsel=Nsel;
  391.  
  392. switch (mode) {
  393. case 0:
  394.     [molobj setSelAtom:list];
  395.     if (nsel>1) {
  396.         for (i=0; i<4; i++) [[a_bond cellAt:i :0] setStringValue:""];
  397.         for (i=0; i<3; i++) [[a_pos1 cellAt:i :0] setStringValue:""];
  398.         for (i=0; i<2; i++) [[a_pos2 cellAt:i :0] setStringValue:""];
  399.     } else {
  400.         for (i=0; i<4; i++) {
  401.             if ((j=mol[0].atom[n].bnd[i])==-1) 
  402.                 [[a_bond cellAt:i :0] setStringValue:""];
  403.             else [[a_bond cellAt:i :0] setIntValue:j];
  404.         }
  405.         for (i=0; i<3; i++) [[a_pos1 cellAt:i :0] setFloatValue: 
  406.             mol[0].coord[n][i]];
  407.     }
  408.     break;
  409. case 1:
  410.     for (i=0; i<nlist; i++) mol[0].am[i].sel=list[i].sel;
  411.     if (nsel==1) {
  412.         [[m_angS cellAt:0 :0] setFloatValue:mol[0].am[list[0].stab].omega/DRC];
  413.         [[m_angS cellAt:1 :0] setFloatValue:mol[0].am[list[0].stab].phi/DRC];
  414.         [[m_angS cellAt:2 :0] setFloatValue:mol[0].am[list[0].stab].psi/DRC];
  415.         [[m_angT cellAt:0 :0] setFloatValue:mol[0].am[list[0].stab].omega/DRC];
  416.         [[m_angT cellAt:1 :0] setFloatValue:mol[0].am[list[0].stab].phi/DRC];
  417.         [[m_angT cellAt:2 :0] setFloatValue:mol[0].am[list[0].stab].psi/DRC];
  418.     }
  419.     break;
  420. case 2:    
  421.     if (nsel>1) {
  422.         for (i=0; i<3; i++) [[t_color cellAt:i :0] setStringValue:""];
  423.         for (i=0; i<2; i++) [[t_radii cellAt:i :0] setStringValue:""];
  424.     }
  425.     else {
  426.         for (i=0; i<3; i++) [[t_color cellAt:i :0] setFloatValue:elinfo[n].color[i]];
  427.         [[t_radii cellAt:0 :0] setFloatValue:elinfo[n].arad];
  428. /*        [[t_radii cellAt:1 :0] setFloatValue:];*/
  429.     }
  430.     break;        
  431. }
  432. return self;
  433.  
  434.  
  435. - deselected:(int)n :(int)Nsel
  436. {
  437. int i;
  438. nsel=Nsel;
  439. switch (mode) {
  440. case 0:
  441.     for (i=0; i<4; i++) [[a_bond cellAt:i :0] setStringValue:""];
  442.     for (i=0; i<3; i++) [[a_pos1 cellAt:i :0] setStringValue:""];
  443.     for (i=0; i<2; i++) [[a_pos2 cellAt:i :0] setStringValue:""];
  444.     [molobj setSelAtom:list];
  445.     break;
  446. case 1:
  447.     for (i=0; i<nlist; i++) mol[0].am[i].sel=list[i].sel;
  448.     break;    
  449. case 2:
  450.     for (i=0; i<3; i++) [[t_color cellAt:i :0] setStringValue:""];
  451.     for (i=0; i<2; i++) [[t_radii cellAt:i :0] setStringValue:""];
  452.     break;
  453. }
  454. return self;
  455. }
  456. @end
  457.