00001 00002 #include "../headers/writepdb.h" 00003 /* 00004 00005 ## GENERAL INFORMATION 00006 ## 00007 ## FILE writepdb.c 00008 ## AUTHORS P. Schmidtke and V. Le Guilloux 00009 ## LAST MODIFIED 02-12-08 00010 ## 00011 ## SPECIFICATIONS 00012 ## 00013 ## Routine to write several data in the PDB/PQR format 00014 ## 00015 ## MODIFICATIONS HISTORY 00016 ## 00017 ## 02-12-08 (v) Comments UTD 00018 ## 01-04-08 (v) Added template for comments and creation of history 00019 ## 01-01-08 (vp) Created (random date...) 00020 ## 00021 ## TODO or SUGGESTIONS 00022 ## 00023 ## (v) Handle (unlakely) error when entries are actually writen (using fprinf) 00024 ## 00025 00026 */ 00027 00028 /* 00029 COPYRIGHT DISCLAIMER 00030 00031 Vincent Le Guilloux, Peter Schmidtke and Pierre Tuffery, hereby 00032 disclaim all copyright interest in the program “fpocket” (which 00033 performs protein cavity detection) written by Vincent Le Guilloux and Peter 00034 Schmidtke. 00035 00036 Vincent Le Guilloux 28 November 2008 00037 Peter Schmidtke 28 November 2008 00038 Pierre Tuffery 28 November 2008 00039 00040 GNU GPL 00041 00042 This file is part of the fpocket package. 00043 00044 fpocket is free software: you can redistribute it and/or modify 00045 it under the terms of the GNU General Public License as published by 00046 the Free Software Foundation, either version 3 of the License, or 00047 (at your option) any later version. 00048 00049 fpocket is distributed in the hope that it will be useful, 00050 but WITHOUT ANY WARRANTY; without even the implied warranty of 00051 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00052 GNU General Public License for more details. 00053 00054 You should have received a copy of the GNU General Public License 00055 along with fpocket. If not, see <http://www.gnu.org/licenses/>. 00056 00057 **/ 00058 00059 /** 00060 ## FUNCTION: 00061 write_pdb_atom_line 00062 00063 ## SPECIFICATION: 00064 Write an atom in the following pdb format 2.3. 00065 00066 COLUMNS DATA TYPE FIELD DEFINITION 00067 00068 1 - 6 Record name "ATOM " 00069 7 - 11 Integer serial Atom serial number. 00070 13 - 16 Atom name Atom name. 00071 17 Character altLoc Alternate location indicator. 00072 18 - 20 Residue name resName Residue name. 00073 22 Character chainID Chain identifier. 00074 23 - 26 Integer resSeq Residue sequence number. 00075 27 AChar iCode Code for insertion of residues. 00076 31 - 38 Real(8.3) x Orthogonal coordinates for X in 00077 Angstroms 00078 39 - 46 Real(8.3) y Orthogonal coordinates for Y in 00079 Angstroms 00080 47 - 54 Real(8.3) z Orthogonal coordinates for Z in 00081 Angstroms 00082 55 - 60 Real(6.2) occupancy Occupancy. 00083 61 - 66 Real(6.2) tempFactor Temperature factor. 00084 77 - 78 LString(2) element Element symbol, right-justified. 00085 79 - 80 LString(2) charge Charge on the atom. 00086 00087 00088 ## PARAMETRES: 00089 00090 ## RETURN: 00091 00092 */ 00093 void write_pdb_atom_line(FILE *f, const char rec_name[], int id, const char atom_name[], 00094 char alt_loc, const char res_name[], const char chain[], 00095 int res_id, const char insert, float x, float y, float z, float occ, 00096 float bfactor, const char *symbol, int charge) 00097 { 00098 /* Example of pdb record: */ 00099 /* Position: 1 2 3 4 5 6 */ 00100 /* Position: 123456789012345678901234567890123456789012345678901234567890 */ 00101 /* Record: ATOM 145 N VAL A 25 32.433 16.336 57.540 1.00 */ 00102 00103 /* Position: 6 7 8 */ 00104 /* Position: 012345678901234567890 */ 00105 /* Record: 0 11.92 N */ 00106 00107 int status = 0 ; 00108 char id_buf[6] = "*****", 00109 res_id_buf[5] = "****", 00110 charge_buf[3] = " "; 00111 00112 if (id < 100000) sprintf(id_buf, "%5d", id); 00113 else sprintf(id_buf, "%05x", id); 00114 00115 if (res_id < 10000) sprintf(res_id_buf, "%4d", res_id); 00116 else if (res_id < 65536) sprintf(res_id_buf, "%04x", res_id); 00117 else sprintf(res_id_buf, "****"); 00118 00119 alt_loc = (alt_loc == '\0')? ' ': alt_loc; 00120 00121 if(charge == -1) sprintf(charge_buf, " ") ; 00122 else sprintf(charge_buf, "%2d", charge) ; 00123 00124 status = fprintf(f, "%-6s%5s %4s%c%-4s%c%4s%c %8.3f%8.3f%8.3f%6.2f%6.2f %2s%2s\n", 00125 rec_name, id_buf, atom_name, alt_loc, res_name, chain[0], 00126 res_id_buf, insert, x, y, z, occ, bfactor, symbol, charge_buf); 00127 00128 } 00129 00130 00131 /** 00132 ## FUNCTION: 00133 write_pqr_atom_line 00134 00135 ## SPECIFICATION: 00136 Write an atom in pqr format. 00137 00138 COLUMNS DATA TYPE FIELD DEFINITION 00139 00140 1 - 6 Record name "ATOM " 00141 7 - 11 Integer serial Atom serial number. 00142 13 - 16 Atom name Atom name. 00143 17 Character altLoc Alternate location indicator. 00144 18 - 20 Residue name resName Residue name. 00145 22 Character chainID Chain identifier. 00146 23 - 26 Integer resSeq Residue sequence number. 00147 27 AChar iCode Code for insertion of residues. 00148 31 - 38 Real(8.3) x Orthogonal coordinates for X in 00149 Angstroms 00150 39 - 46 Real(8.3) y Orthogonal coordinates for Y in 00151 Angstroms 00152 47 - 54 Real(8.3) z Orthogonal coordinates for Z in 00153 Angstroms 00154 charge 00155 vdw radius 00156 00157 ## PARAMETRES: 00158 00159 ## RETURN: 00160 00161 */ 00162 void write_pqr_atom_line(FILE *f, const char *rec_name, int id, const char *atom_name, 00163 char alt_loc, const char *res_name, const char *chain, 00164 int res_id, const char insert, float x, float y, float z, float charge, 00165 float radius) 00166 { 00167 /* Example of pdb record: */ 00168 /* Position: 1 2 3 4 5 6 */ 00169 /* Position: 123456789012345678901234567890123456789012345678901234567890 */ 00170 /* Record: ATOM 145 N VAL A 25 32.433 16.336 57.540 1.00 */ 00171 00172 /* Position: 6 7 8 */ 00173 /* Position: 012345678901234567890 */ 00174 /* Record: 0 11.92 N */ 00175 00176 int status ; 00177 char id_buf[7], 00178 res_id_buf[6]; 00179 /* charge_buf[3] ; */ 00180 00181 if (id < 100000) sprintf(id_buf, "%5d", id); 00182 else sprintf(id_buf, "%05x", id); 00183 00184 if (res_id < 10000) sprintf(res_id_buf, "%4d", res_id); 00185 else if (res_id < 65536) sprintf(res_id_buf, "%04x", res_id); 00186 00187 alt_loc = (alt_loc == '\0')? ' ': alt_loc; 00188 00189 /* if(charge == -1) { 00190 charge_buf[0] = charge_buf[1] = ' ' ; 00191 charge_buf[2] = '\0' ; 00192 } 00193 else sprintf(charge_buf, "%2d", charge) ; 00194 */ 00195 status = fprintf(f, "%-6s%5s %4s%c%-4s%c%4s%c %8.3f%8.3f%8.3f %6.2f %6.2f\n", 00196 rec_name, id_buf, atom_name, alt_loc, res_name, chain[0], 00197 res_id_buf, insert, x, y, z, charge,radius) ; 00198 } 00199