/* ## ## ######### ## ########## ########## ### ### ## ########## ## #### #### ## ########## ## ## ## ## ## ## ## ########## ## ######## ## ## ## ## ## ## ###### ######## ## ## ## ## ## ###### ### ## ## ## ############## ## ### ## ########## ## ############## ## ### ################# ######## ## ########### ######### ## ######### ## ########### ## ## ## ### ## ########## ## ## ## ###### ## ## ########## ## ## ## ###### ######## ## # ## ## ######### ## # ## ## ## ## ## ### ########## ## ## ## ### ########## ########## ######### */ /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *\ * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * ** ** ** ** ** E N S E M B L E ** ** ** ** Version 2.1 ** ** ** ** ** ** Principal Investigator: Julie D. Forman-Kay ** ** ** ** Author: Mickaƫl Krzeminski ** ** ** ** Date: November 2012 ** ** ** ** ** ************************************************************************************* ** ** ** ** ** Copyright (C) The Hospital for Sick Children, 2001 ** ** ** ** Distribution of substantively modified versions of this module is prohibited ** ** without the explicit permission of the copyright holder. ** ** ** ** Any use of this work or derivative works in whole or in part for any ** ** commercial purpose or for monetary gain is prohibited. ** ** ** ** ** ** NO WARRANTY ** ** This software package is provided 'as is' without warranty of any kind, ** ** expressed or implied. ** ** ** ** ** * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * \* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ /* COMPILATION gcc -O3 -lm -o make_csp make_csp.c */ #include "Include/ens.h" enum toolsPrograms TP = __MAKE_CSP__; int main (int argc, char *argv[]) { /***********************************************************\ |* *| |* *| |* Variables declaration *| |* *| |* *| \***********************************************************/ counter count; unsigned int nbFails = 0, nbNotFound = 0, nbRecord = 0; unsigned int maxNbAtoms = 500; int32Coordinates *intAtomCoords = NULL; coordinates atomCoords; uint32_t nbFiles = 0, nbAtoms = 0; char *PDBListFileName = NULL, *outFileName = NULL; char cspExt[5]; char coord[9]; char **atomHeaders = NULL; char atomHeader[28]; char PDBFileName[250], PDBFileLine[79]; FILE *PDBListFile, *outFile, *PDBFile; /***********************************************************\ |* *| |* *| |* Arguments reading and checking *| |* *| |* *| \***********************************************************/ for (count=1; countcount) { if ((PDBListFileName = malloc((strlen(argv[count]) + 1) * CHAR_SIZE)) == NULL) { _cleanMakeCSP(intAtomCoords, atomHeaders, PDBListFileName, outFileName, nbAtoms); fatal_error("MEMORY", "create PDBListFileName variable"); } strcpy(PDBListFileName, argv[count]); } else { _cleanMakeCSP(intAtomCoords, atomHeaders, PDBListFileName, outFileName, nbAtoms); fatal_error("NO_ARGUMENT_FLAG", "-o"); } } else if (!strcmp(argv[count], "-o")) { ++count; if (argc>count) { if ((outFileName = malloc(strlen(argv[count]) * CHAR_SIZE + 1)) == NULL) { _cleanMakeCSP(intAtomCoords, atomHeaders, PDBListFileName, outFileName, nbAtoms); fatal_error("MEMORY", "create outFileName variable"); } strcpy(outFileName, argv[count]); } else { _cleanMakeCSP(intAtomCoords, atomHeaders, PDBListFileName, outFileName, nbAtoms); fatal_error("NO_ARGUMENT_FLAG", "-o"); } } else if (!strcmp(argv[count], "-h")) { _cleanMakeCSP(intAtomCoords, atomHeaders, PDBListFileName, outFileName, nbAtoms); __USAGE__ } else { warning("ARGUMENT", argv[count]); } } // Checking whether a list file has been provided if (PDBListFileName == NULL) { _cleanMakeCSP(intAtomCoords, atomHeaders, PDBListFileName, outFileName, nbAtoms); __USAGE__ } // Checking whether an output file has been provided if (outFileName == NULL) { strcpy(cspExt, ".csp"); if ((outFileName = malloc((strlen(PDBListFileName) + 4) * CHAR_SIZE)) == NULL) { fatal_error("MEMORY", "create outFileName variable"); } strcpy(outFileName, PDBListFileName); for (count=0; count 4) { if (PDBFileLine[0] == 'A' && PDBFileLine[1] == 'T' && PDBFileLine[2] == 'O' && PDBFileLine[3] == 'M') { if (nbAtoms == maxNbAtoms) { maxNbAtoms += 500; if ((atomHeaders = realloc (atomHeaders, maxNbAtoms * sizeof(char *))) == NULL) { fclose(PDBFile); fclose(PDBListFile); fclose(outFile); remove(outFileName); _cleanMakeCSP(intAtomCoords, atomHeaders, PDBListFileName, outFileName, nbAtoms); fatal_error("MEMORY", "increase atomHeaders variable size."); } if ((intAtomCoords = realloc (intAtomCoords, maxNbAtoms * INT32COORD_SIZE)) == NULL) { fclose(PDBFile); fclose(PDBListFile); fclose(outFile); remove(outFileName); _cleanMakeCSP(intAtomCoords, atomHeaders, PDBListFileName, outFileName, nbAtoms); fatal_error("MEMORY", "increase intAtomCoords variable size."); } } // Recording the atomHeader atomHeaders[nbAtoms] = malloc (28 * sizeof(char)); strncpy(atomHeaders[nbAtoms], PDBFileLine, 27); atomHeaders[nbAtoms][27] = '\0'; // Recording the coordinates strncpy(coord, &PDBFileLine[30], 8); atomCoords.x = atof(coord); intAtomCoords[nbAtoms].x = (atomCoords.x>0) ? (int32_t)(atomCoords.x * COORD_FACT + .5):(int32_t)(atomCoords.x * COORD_FACT - .5); strncpy(coord, &PDBFileLine[38], 8); atomCoords.y = atof(coord); intAtomCoords[nbAtoms].y = (atomCoords.y>0) ? (int32_t)(atomCoords.y * COORD_FACT + .5):(int32_t)(atomCoords.y * COORD_FACT - .5); strncpy(coord, &PDBFileLine[46], 8); atomCoords.z = atof(coord); intAtomCoords[nbAtoms].z = (atomCoords.z>0) ? (int32_t)(atomCoords.z * COORD_FACT + .5):(int32_t)(atomCoords.z * COORD_FACT - .5); // Incrementing the number of atoms ++nbAtoms; } } } // Writing the number of files in the output CSP file fwrite(&nbAtoms, INT32_SIZE, 1, outFile); // Writing the atom atomHeaders in the output CSP file for (count=0; count 4) { if (PDBFileLine[0] == 'A' && PDBFileLine[1] == 'T' && PDBFileLine[2] == 'O' && PDBFileLine[3] == 'M') { strncpy(atomHeader, PDBFileLine, 27); atomHeader[27] = '\0'; if (strcmp(atomHeader, atomHeaders[nbRecord])) { error("ATOM_RECORD", PDBFileName); } else { // Recording the coordinates strncpy(coord, &PDBFileLine[30], 8); atomCoords.x = atof(coord); intAtomCoords[nbRecord].x = (atomCoords.x>0) ? (int32_t)(atomCoords.x * COORD_FACT + .5):(int32_t)(atomCoords.x * COORD_FACT - .5); strncpy(coord, &PDBFileLine[38], 8); atomCoords.y = atof(coord); intAtomCoords[nbRecord].y = (atomCoords.y>0) ? (int32_t)(atomCoords.y * COORD_FACT + .5):(int32_t)(atomCoords.y * COORD_FACT - .5); strncpy(coord, &PDBFileLine[46], 8); atomCoords.z = atof(coord); intAtomCoords[nbRecord].z = (atomCoords.z>0) ? (int32_t)(atomCoords.z * COORD_FACT + .5):(int32_t)(atomCoords.z * COORD_FACT - .5); // Incrementing the number of records ++nbRecord; if (nbRecord > nbAtoms) { error("ATOM_RECORD", PDBFileName); break; } } } } } if (nbRecord == nbAtoms) // Checking whether the number of atoms is relevant { fwrite(intAtomCoords, INT32COORD_SIZE, nbAtoms, outFile); } else { error("ATOM_RECORD", PDBFileName); --nbFiles; nbFails++; } } fclose(PDBFile); ++nbFiles; } else { nbNotFound++; warning("NO_FILE", PDBFileName); } } } if (!feof(PDBListFile)) { warning("The end of the file %s has not been reached", PDBListFileName); } // Replacing the number of files that was set to 0 fseek(outFile, 3 * CHAR_SIZE, SEEK_SET); fwrite(&nbFiles, INT32_SIZE, 1, outFile); // Closing the files fclose(PDBListFile); fclose(outFile); /***********************************************************\ |* *| |* *| |* Conclusion *| |* *| |* *| \***********************************************************/ printf ("\nDONE\n\tA total of %u conformers, each made of %u atoms, have been successfully concatenated into the file %s.\n", (unsigned int)nbFiles, nbAtoms, outFileName); if (nbNotFound) { if (nbNotFound>1) { printf ("\t%u files could not be found.\n", (unsigned int)nbNotFound); } else { printf ("\t%u file could not be found.\n", (unsigned int)nbNotFound); } } if (nbFails) { if (nbFails>1) { printf ("\t%u files failed to be added into the CSP file.\n", (unsigned int)nbFails); } else { printf ("\t%u file failed to be added into the CSP file.\n", (unsigned int)nbFails); } } printf ("\n\n"); _cleanMakeCSP(intAtomCoords, atomHeaders, PDBListFileName, outFileName, nbAtoms); return 0; }