GLYLIB
0.3.0b
|
00001 /* Author: Michael Tessier 00002 Extended and updated by BLFoley */ 00003 #include <molecules.h> 00004 #include <mylib.h> 00005 #define TRUE 1 00006 #define FALSE 0 00007 00008 void outputMolPDB(molecule* mol, char* file_name) 00009 { 00010 /* Tells the user what's going on */ 00011 printf("Writting file: %s...\n",file_name); 00012 FILE* file; 00013 char current_line[80] = ""; char temporary[40] = ""; 00014 char* curLine = current_line; char* temp = temporary; 00015 char* resName; char* atmName; 00016 int i; int j; int atmTot; int resNum; int resTot = (*mol).nr; 00017 atom curAtm; 00018 file = myfopen(file_name,"w"); 00019 00020 for(i = 0; i < resTot; i++) 00021 { 00022 resName = (*((*mol).r+i)).N; 00023 resNum = (*((*mol).r+i)).n; 00024 atmTot = (*((*mol).r+i)).na; 00025 for(j = 0; j < atmTot; j++) 00026 { 00027 curAtm = (*((*((*mol).r+i)).a+j)); 00028 atmName = curAtm.N; 00029 strcpy(curLine,""); 00030 strcat(curLine,"ATOM"); 00031 00032 sprintf(temp,"%d", curAtm.n); 00033 //Based on how large the atom # is, depends on the # of spaces 00034 strcat(curLine,spacing(strlen(temp),7)); 00035 //"ATOM atom# atom_name" 00036 sprintf(temp,"%d %s", curAtm.n, atmName); 00037 strcat(curLine,temp); 00038 00039 //Based on how many char are in the residue name, " " spaces 00040 strcat(curLine,spacing(strlen(atmName),4)); 00041 //"ATOM atom# atom_name res_name" 00042 strcat(curLine,resName); 00043 00044 sprintf(temp,"%d",resNum); 00045 //Based on how large the residue # is, " " spaces 00046 strcat(curLine,spacing(strlen(temp),6)); 00047 //"ATOM atom# atom_name res_name res#" 00048 strcat(curLine,temp); 00049 00050 sprintf(temp,"%.3lf",curAtm.x.i); 00051 //Based on how large the x cordinate is, " " spaces 00052 strcat(curLine,spacing(strlen(temp),12)); 00053 //"ATOM atom# atom_name res_name x" 00054 strcat(curLine,temp); 00055 00056 sprintf(temp,"%.3lf",curAtm.x.j); 00057 //Based on how large the y cordinate is, " " spaces 00058 strcat(curLine,spacing(strlen(temp),8)); 00059 //"ATOM atom# atom_name res_name x y" 00060 strcat(curLine,temp); 00061 00062 sprintf(temp,"%.3lf",curAtm.x.k); 00063 //Based on how large the z cordinate is, " " spaces 00064 strcat(curLine,spacing(strlen(temp),8)); 00065 //"ATOM atom# atom_name res_name x y z 1.00 0.00" 00066 sprintf(temp,"%.3lf 1.00 0.00",curAtm.x.k); 00067 strcat(curLine,temp); 00068 00069 //Output the line to the new .pbd file 00070 fprintf(file,"%s\n",curLine); 00071 } 00072 } 00073 fclose(file); 00074 } 00075 void outputAsmblPDB(assembly* asmbl, char* file_name) 00076 { 00077 //Tells the user what's going on 00078 printf("Writting file: %s...\n",file_name); 00079 FILE* file; 00080 char current_line[80] = ""; char temporary[40] = ""; 00081 char* curLine = current_line; char* temp = temporary; 00082 char* resName; char* atmName; 00083 int i,j,k,atmTot,resNum,resTot; 00084 atom curAtm; molecule* mol; 00085 file = myfopen(file_name,"w"); 00086 for(k = 0; k < (*asmbl).nm; k++) 00087 { 00088 mol = ((*asmbl).m+k)[0]; // changed by BLF on 20080622 -- might need revisiting 00089 resTot = (*mol).nr; 00090 for(i = 0; i < resTot; i++) 00091 { 00092 resName = (*((*mol).r+i)).N; 00093 resNum = (*((*mol).r+i)).n; 00094 atmTot = (*((*mol).r+i)).na; 00095 for(j = 0; j < atmTot; j++) 00096 { 00097 curAtm = (*((*((*mol).r+i)).a+j)); 00098 atmName = curAtm.N; 00099 strcpy(curLine,""); 00100 strcat(curLine,"ATOM"); 00101 00102 sprintf(temp,"%d", curAtm.n); 00103 //Based on how large the atom # is, depends on the # of spaces 00104 strcat(curLine,spacing(strlen(temp),7)); 00105 //"ATOM atom# atom_name" 00106 sprintf(temp,"%d %s", curAtm.n, atmName); 00107 strcat(curLine,temp); 00108 00109 //Based on how many char are in the residue name, " " spaces 00110 strcat(curLine,spacing(strlen(atmName),4)); 00111 //"ATOM atom# atom_name res_name" 00112 strcat(curLine,resName); 00113 00114 sprintf(temp,"%d",resNum); 00115 //Based on how large the residue # is, " " spaces 00116 strcat(curLine,spacing(strlen(temp),6)); 00117 //"ATOM atom# atom_name res_name res#" 00118 strcat(curLine,temp); 00119 00120 sprintf(temp,"%.3lf",curAtm.x.i); 00121 //Based on how large the x cordinate is, " " spaces 00122 strcat(curLine,spacing(strlen(temp),12)); 00123 //"ATOM atom# atom_name res_name x" 00124 strcat(curLine,temp); 00125 00126 sprintf(temp,"%.3lf",curAtm.x.j); 00127 //Based on how large the y cordinate is, " " spaces 00128 strcat(curLine,spacing(strlen(temp),8)); 00129 //"ATOM atom# atom_name res_name x y" 00130 strcat(curLine,temp); 00131 00132 sprintf(temp,"%.3lf",curAtm.x.k); 00133 //Based on how large the z cordinate is, " " spaces 00134 strcat(curLine,spacing(strlen(temp),8)); 00135 //"ATOM atom# atom_name res_name x y z 1.00 0.00" 00136 sprintf(temp,"%.3lf 1.00 0.00",curAtm.x.k); 00137 strcat(curLine,temp); 00138 00139 //Output the line to the new .pbd file 00140 fprintf(file,"%s\n",curLine); 00141 } 00142 } 00143 fprintf(file,"TER \n"); 00144 } 00145 fclose(file); 00146 } 00147 char* spacing(int strLen, int totLen) 00148 { 00149 char returning[15] = ""; char* ret = returning; 00150 int i; 00151 for(i = 0; i < totLen - strLen; i++) 00152 strcat(ret," "); 00153 return ret; 00154 } 00155