int main(int argc, char *argv[]) { int i,j; int index; int num_sep_bond_type1 = 0; int num_sep_bond_type2 = 0; int overflow_flag = 0; /*if overflow_flag ==1, reallocate memory */ amberhome = (char *) getenv("AMBERHOME"); if( amberhome == NULL ){ fprintf( stdout, "AMBERHOME is not set!\n" ); exit(1); } if (strcmp(COLORTEXT, "YES") == 0 || strcmp(COLORTEXT, "yes") == 0) { if (argc == 2 && (strcmp(argv[1], "-h") == 0 || strcmp(argv[1], "-H") == 0)) { printf("[31mUsage: residuegen [0m input_file \n"); exit(1); } if (argc != 2) { printf("[31mUsage: residuegen [0m input_file \n"); exit(1); } } else { if (argc == 2 && (strcmp(argv[1], "-h") == 0 || strcmp(argv[1], "-H") == 0)) { printf("Usage residuegen input_file\n"); exit(1); } if (argc != 2) { printf("Usage residuegen input_file\n"); exit(1); } } if ((fpin = fopen(argv[1], "r")) == NULL) { fprintf(stdout, "Cannot open input file: %s, exit\n", argv[1]); exit(1); } for(i=0; i<MAXSEPBOND; i++) sepbond[i].type = 0; for (;;) { if (fgets(line, MAXCHAR, fpin) == NULL) break; if (strncmp("ESP_FILE", line, 8) == 0) { sscanf(&line[9], "%s", espfile); continue; } if (strncmp("INPUT_FILE", line, 10) == 0) { sscanf(&line[11], "%s", inputfile); continue; } if (strncmp("CONF_NUM", line, 8) == 0) { sscanf(&line[9], "%d", &confnum); continue; } if (strncmp("SEP_BOND", line, 8) == 0) { sscanf(&line[9], "%s%s%d", sepbond[sepbondnum].resat, sepbond[sepbondnum].capat, &sepbond[sepbondnum].type); sepbondnum++; continue; } if (strncmp("PSEUDO_HEAD_ATOM", line, 16) == 0) { sscanf(&line[17], "%s", pseudo_head_name); continue; } if (strncmp("PSEUDO_TAIL_ATOM", line, 16) == 0) { sscanf(&line[17], "%s", pseudo_tail_name); continue; } if (strncmp("NET_CHARGE", line, 10) == 0) { sscanf(&line[11], "%lf", &netcharge); continue; } if (strncmp("PREP_FILE", line, 9) == 0) { sscanf(&line[10], "%s", prepfile); continue; } if (strncmp("RESIDUE_FILE_NAME", line, 17) == 0) { sscanf(&line[18], "%s", residue_file_name); continue; } if (strncmp("RESIDUE_SYMBOL", line, 14) == 0) { sscanf(&line[15], "%s", residue_symbol); continue; } if (strncmp("ATOM_CHARGE", line, 11) == 0) { if ( chargenum >= MAXCHARGE ) { fprintf(stdout, "Error: MAXCHARGE is too small in residuegen.c\n" " Increase MAXCHARGE and reinstall antechamber\n" ); exit(1); } sscanf(&line[12], "%s%lf", charge[chargenum].name, &charge[chargenum].charge); chargenum++; continue; } } fclose(fpin); printf("\nINPUT_FILE:\t\t%s", inputfile); printf("\nESP_FILE:\t\t%s", espfile); printf("\nCONF_NUM:\t\t%d", confnum); printf("\nNET_CHARGE:\t\t%-9.5lf", netcharge); if(strcmp(pseudo_head_name, "PSEUDO_HEAD") != 0) printf("\nPSEUDO_HEAD_NAME:\t\t%s", pseudo_head_name); if(strcmp(pseudo_tail_name, "PSEUDO_TAIL") != 0) printf("\nPSEUDO_TAIL_NAME:\t\t%s", pseudo_tail_name); printf("\nThere are %d separating bonds", sepbondnum); for(i=0;i<sepbondnum;i++) printf("\nSEPBOND\t\t\t%d\t%s\t%s\t%d", i+1, sepbond[i].resat, sepbond[i].capat, sepbond[i].type); printf("\nThere are %d predefined charges", chargenum); for(i=0;i<chargenum;i++) printf("\nATOM_CHARGE\t\t%d\t%s\t%9.5lf", i+1, charge[i].name, charge[i].charge); printf("\nPREP_FILE: %s", prepfile); /* read molecule information */ default_cinfo(&cinfo); default_minfo(&minfo); atom = (ATOM *) malloc(sizeof(ATOM) * cinfo.maxatom); if (atom == NULL) { fprintf(stdout, "memory allocation error for *atom\n"); exit(1); } bond = (BOND *) malloc(sizeof(BOND) * cinfo.maxbond); if (bond == NULL) { fprintf(stdout, "memory allocation error for *bond\n"); exit(1); } for (i = 0; i < cinfo.maxbond; ++i) { bond[i].jflag = -1; /* bond type has not been assigned */ } overflow_flag = rac(inputfile, &atomnum, atom, &bondnum, bond, &cinfo, &minfo); if (overflow_flag) { cinfo.maxatom = atomnum + 10; cinfo.maxbond = bondnum + 10; free(atom); free(bond); atom = (ATOM *) malloc(sizeof(ATOM) * cinfo.maxatom); if (atom == NULL) { fprintf(stdout, "memory allocation error for *atom\n"); exit(1); } bond = (BOND *) malloc(sizeof(BOND) * cinfo.maxbond); if (bond == NULL) { fprintf(stdout, "memory allocation error for *bond\n"); exit(1); } int i; for (i = 0; i < cinfo.maxbond; ++i) { bond[i].jflag = -1; /* bond type has not been assigned */ } overflow_flag = rac(ifilename, &atomnum, atom, &bondnum, bond, &cinfo, &minfo); } atomicnum(atomnum, atom); /* allocate memory*/ selectelement = (int *) malloc(sizeof(int) * atomnum); if (selectelement == NULL) { fprintf(stdout, "memory allocation error for *selectelement\n"); exit(1); } selectelement2 = (int *) malloc(sizeof(int) * atomnum); if (selectelement2 == NULL) { fprintf(stdout, "memory allocation error for *selectelement2\n"); exit(1); } flag = (int *) malloc(sizeof(int) * atomnum); if (flag == NULL) { fprintf(stdout, "memory allocation error for *flag\n"); exit(1); } /* find atom ids for predefined charges*/ for(i =0; i< chargenum; i++) { charge[i].id = -1; index = 0; length = strlen(charge[i].name); for(j =0; j< atomnum; j++) if(strncmp(atom[j].name, charge[i].name,length) == 0) { charge[i].id = j; index = 1; break; } if(index == 0) { fprintf(stdout, "Error: the charge name, %s does not show up in the molecule\n", charge[i].name); exit(1); } } /* find atom ids for separted bonds*/ for(i =0; i<sepbondnum; i++) { sepbond[i].resid = -1; sepbond[i].capid = -1; for(j =0; j< atomnum; j++) { length = strlen(sepbond[i].resat); if(strncmp(atom[j].name, sepbond[i].resat, length) == 0) { sepbond[i].resid = j; continue; } length = strlen(sepbond[i].capat); if(strncmp(atom[j].name, sepbond[i].capat, length) == 0) { sepbond[i].capid = j; continue; } if(sepbond[i].resid != -1 && sepbond[i].capid != -1) break; } if(sepbond[i].resid == -1) { fprintf(stdout, "Error: the ATOM_NAME1 %s of %d does not show up in the molecule\n", sepbond[i].resat, i+1); exit(1); } if(sepbond[i].capid == -1) { fprintf(stdout, "Error: the ATOM_NAME2 %s of %d does not show up in the molecule\n", sepbond[i].capat, i+1); exit(1); } if(sepbond[i].type == 1) { head_id = sepbond[i].resid; pre_head_id = sepbond[i].capid; num_sep_bond_type1 ++; } if(sepbond[i].type ==-1) { tail_id = sepbond[i].resid; post_tail_id = sepbond[i].capid; num_sep_bond_type2 ++; } } if(num_sep_bond_type1 > 1) { fprintf(stdout, "Error: only one or none SEP_BOND has a type of '1'\n"); exit(1); } if(num_sep_bond_type2 > 1) { fprintf(stdout, "Error: only one or none SEP_BOND has a type of '-1'\n"); exit(1); } /* find atom ids for terminal atoms */ num_terminal_atom = 0; if(num_sep_bond_type1 == 1) num_terminal_atom ++; if(num_sep_bond_type2 == 1) num_terminal_atom ++; if(head_id == -1 && strcmp(pseudo_head_name, "PSEUDO_HEAD") != 0) { for(i=0;i<atomnum;i++) if(strcmp(atom[i].name, pseudo_head_name) == 0) { head_id = i; num_terminal_atom ++; break; } } if(tail_id == -1 && strcmp(pseudo_tail_name, "PSEUDO_TAIL") != 0) { for(i=0;i<atomnum;i++) if(strcmp(atom[i].name, pseudo_tail_name) == 0) { tail_id = i; num_terminal_atom ++; break; } } /* Now we allow a residue only has one cap (either the N or C-terminal) */ /* if(num_terminal_atom != 0 && num_terminal_atom != 2) { fprintf(stdout, "Error, the total number of terminal atoms must be zero or 2 (HEAD_ATOM / PSEUDO_HEAD_ATOM + TAIL_ATOM / PSEUDO_TAIL_ATOM)\n"); exit(0); } */ /* find cap atoms and residue atoms*/ if(sepbondnum > 0) { for(i=0;i<sepbondnum;i++) { printf("\n\nCap Atoms for #%d separating bond (%s - %s) with a type of %d", i+1, sepbond[i].capat, sepbond[i].resat, sepbond[i].type); group_atom1(i); for (j = 0; j<atomnum; j++) if(flag[j] == 1) printf("\nATOM\t %d\t%s", j+1, atom[j].name); } printf("\n\nResidue Atoms"); group_atom2(); residueatnum = 0; for (i = 0; i<atomnum; i++) if(flag[i] == 1) { residueatnum ++; printf("\nATOM\t %d\t%s", i+1, atom[i].name); } } else { for (i = 0; i<atomnum; i++) flag[i] = 1; } /* find main chain atoms when num_terminal_atom is 2, otherwise no main chain atoms are determined*/ if(num_terminal_atom == 2) { printf("\n\n(PSEUDO) HEAD ATOM: %s", atom[head_id].name); printf("\n\n(PSEUDO) TAIL ATOM: %s", atom[tail_id].name); selectnum = 0; for (i = 0; i<atomnum; i++) { selectelement[i] = -1; selectelement2[i] = -1; } findpath(atom, 0, head_id); printf("\n\nMain Chain Atoms"); for (j = 0; j < selectnum2 ; j++) printf("\nATOM\t%d\t%s", j+1, atom[selectelement2[j]].name); } /* generate charge input file for respgen */ printf("\nGenerate charge input file for respgen ... \n"); if ((fpout = fopen("RESIDUE_GEN_RESPGEN.DAT", "w")) == NULL) { fprintf(stdout, "Cannot open input file RESIDUE_GEN_RESPGEN.DAT, exit\n"); exit(1); } fprintf(fpout, "//predefined charges in a format of (CHARGE partical_charge atom_ID atom_name)"); for(i=0;i<chargenum;i++) fprintf(fpout, "\nCHARGE %9.6lf\t%d\t%s", charge[i].charge, charge[i].id + 1, charge[i].name); fprintf(fpout, "\n//charge groups in a format of (GROUP num_atom net_charge)"); fprintf(fpout, "\nGROUP\t%d\t%9.5lf\n", residueatnum, netcharge); fprintf(fpout, "//atoms in the group in a format of (ATOM atom_ID atom_name)"); for (i = 0; i<atomnum; i++) if(flag[i] == 1) fprintf(fpout, "\nATOM\t%d\t%s", i+1, atom[i].name); fclose(fpout); /* generate main chain file for prepgen */ printf("\nGenerate main chain atom file for prepgen ... \n"); if ((fpout = fopen("RESIDUE_GEN_MAINCHAIN.DAT", "w")) == NULL) { fprintf(stdout, "Cannot open input file RESIDUE_GEN_MAINCHAIN.DAT, exit\n"); exit(1); } if(head_id != -1 && pre_head_id != -1) fprintf(fpout, "HEAD_NAME\t%s\n", atom[head_id].name); if(tail_id != -1 && post_tail_id != -1) fprintf(fpout, "TAIL_NAME\t%s\n", atom[tail_id].name); for (i = 0; i < selectnum2 ; i++) { if(head_id != -1 && pre_head_id != -1) { length = strlen(atom[head_id].name); if(strncmp(atom[selectelement2[i]].name, atom[head_id].name, length) == 0) continue; } if(tail_id != -1 && post_tail_id != -1) { length = strlen(atom[tail_id].name); if(strncmp(atom[selectelement2[i]].name, atom[tail_id].name, length) == 0) continue; } fprintf(fpout, "MAIN_CHAIN\t%s\n", atom[selectelement2[i]].name); } for (i = 0; i<atomnum; i++) if(flag[i] == 1) continue; else fprintf(fpout, "OMIT_NAME\t%s\n", atom[i].name); if(pre_head_id != -1) fprintf(fpout, "PRE_HEAD_TYPE\t%s\n", atom[pre_head_id].ambername); if(post_tail_id != -1) fprintf(fpout, "POST_TAIL_TYPE\t%s\n", atom[post_tail_id].ambername); fprintf(fpout, "CHARGE\t%9.5lf\n", netcharge); fflush(stdout); fclose(fpout); proceed(); printf("\n"); return (0); }
int main(int argc, char *argv[]) { int i; int status = 0; char command[MAXCHAR]; size_t copied_size; amberhome = (char *) getenv("AMBERHOME"); if( amberhome == NULL ){ fprintf( stdout, "AMBERHOME is not set!\n" ); exit(1); } if (strcmp(COLORTEXT, "YES") == 0 || strcmp(COLORTEXT, "yes") == 0) { if (argc == 2 && (strcmp(argv[1], "-h") == 0 || strcmp(argv[1], "-H") == 0)) { printf("[31mUsage: respgen -i[0m input file name(ac)\n" "[31m -o[0m output file name\n" "[31m -l[0m maximum path length (default is -1, only recommand to use\n" " when the program takes long time to finish or causes core dump.)\n" " If applied, a value of 8 to 10 should good)\n" "[31m -f[0m output file format (resp1 or resp2) \n" "[32m resp0[0m - evaluation the current charges \n" "[32m resp1[0m - first stage resp fitting \n" "[32m resp2[0m - second stage resp fitting\n" "[32m iresp0[0m - evaluation the current charges for polarizable model\n" "[32m iresp1[0m- first stage of i_resp fitting \n" "[32m iresp2[0m- second stage of i_resp fitting\n" "[32m resp3[0m - one-stage resp fitting\n" "[32m resp4[0m - calculating ESP from point charges\n" "[32m resp5[0m - no-equalization\n" "[31m -e[0m equalizing atomic charge, default is 1\n" "[32m 0[0m not use \n" "[32m 1[0m by atomic paths\n" "[32m 2[0m by atomic paths and structural information, i.e. E/Z confirgurations\n" "[31m -a[0m additional input data (predefined charges, atom groups etc).)\n" "[31m -n[0m number of conformations (default is 1)\n" "[31m -w[0m weight of charge constraint, in default, 0.0005 for resp1 and 0.001 fore resp2\n"); exit(1); } if (argc != 7 && argc != 9 && argc != 11 && argc != 13 && argc != 15 && argc != 17) { printf("[31mUsage: respgen -i[0m input file name(ac)\n" "[31m -o[0m output file name\n" "[31m -l[0m maximum path length (default is -1, only recommand to use\n" " when the program takes long time to finish or causes core dump.)\n" " If applied, a value of 8 to 10 should good)\n" "[31m -f[0m output file format (resp1 or resp2) \n" "[32m resp0[0m - evaluation the current charges \n" "[32m resp1[0m - first stage resp fitting \n" "[32m resp2[0m - second stage resp fitting\n" "[32m iresp0[0m - evaluation the current charges for polarizable model\n" "[32m iresp1[0m- first stage of i_resp fitting \n" "[32m iresp2[0m- second stage of i_resp fitting\n" "[32m resp3[0m - one-stage resp fitting\n" "[32m resp4[0m - calculating ESP from point charges\n" "[32m resp5[0m - no-equalization\n" "[31m -e[0m equalizing atomic charge, default is 1\n" "[32m 0[0m not use \n" "[32m 1[0m by atomic paths\n" "[32m 2[0m by atomic paths and structural information, i.e. E/Z confirgurations\n" "[31m -a[0m additional input data (predefined charges, atom groups etc).)\n" "[31m -n[0m number of conformations (default is 1)\n" "[31m -w[0m weight of charge constraint, in default, 0.0005 for resp1 and 0.001 fore resp2\n"); exit(1); } } else { if (argc == 2 && (strcmp(argv[1], "-h") == 0 || strcmp(argv[1], "-H") == 0)) { printf("Usage respgen -i input file name(ac)\n"); printf(" -o output file name\n"); printf(" -l maximum path length (default is -1, only recommand to use\n"); printf(" when the program takes long time to finish or causes core dump.)\n"); printf(" If applied, a value of 8 to 10 should good)\n"); printf(" -f output file format (resp1 or resp2)\n"); printf(" resp0 - evaluation the current charges \n"); printf(" resp1 - first stage resp fitting\n"); printf(" resp2 - second stage resp fitting \n"); printf(" iresp0 - evaluation the current charges for polarizable model \n"); printf(" iresp1- first stage of i_resp fitting\n"); printf(" iresp2- second stage of i_resp fitting \n"); printf(" resp3 - one-stage resp fitting\n"); printf(" resp4 - calculating ESP from point charges \n"); printf(" resp5 - no-equalization \n"); printf(" -e equalizing atomic charge, default is 1\n"); printf(" 0 not use \n"); printf(" 1 by atomic paths\n"); printf(" 2 by atomic paths and structural information, i.e. E/Z confirgurations\n"); printf(" -a additional input data (predefined charges, atom groups etc).)\n"); printf(" -n number of conformations (default is 1)\n"); printf(" -w weight of charge constraint, in default, 0.0005 for resp1 and 0.001 fore resp2\n"); exit(1); } if (argc != 7 && argc != 9 && argc != 11 && argc != 13 && argc != 15 && argc != 17) { printf("Usage respgen -i input file name(ac)\n"); printf(" -o output file name\n"); printf(" -l maximum path length (default is -1, only recommand to use\n"); printf(" when the program takes long time to finish or causes core dump.)\n"); printf(" If applied, a value of 8 to 10 should good)\n"); printf(" -f output file format (resp1 or resp2)\n"); printf(" resp0 - evaluation the current charges \n"); printf(" resp1 - first stage resp fitting\n"); printf(" resp2 - second stage resp fitting \n"); printf(" iresp0 - evaluation the current charges for polarizable model \n"); printf(" iresp1- first stage of i_resp fitting\n"); printf(" iresp2- second stage of i_resp fitting \n"); printf(" resp3 - one-stage resp fitting\n"); printf(" resp4 - calculating ESP from point charges \n"); printf(" resp5 - no-equalization \n"); printf(" -e equalizing atomic charge, default is 1\n"); printf(" 0 not use \n"); printf(" 1 by atomic paths\n"); printf(" 2 by atomic paths and structural information, i.e. E/Z confirgurations\n"); printf(" -a additional input data (predefined charges, atom groups etc).)\n"); printf(" -w weight of charge constraint, in default, 0.0005 for resp1 and 0.001 fore resp2\n"); exit(1); } } method = -1; max_path_length = -1; for (i = 1; i < argc; i += 2) { if (strcmp(argv[i], "-i") == 0) strcpy(ifilename, argv[i + 1]); if (strcmp(argv[i], "-o") == 0) strcpy(ofilename, argv[i + 1]); if (strcmp(argv[i], "-a") == 0) { strcpy(afilename, argv[i + 1]); iaddinfo = 1; } if (strcmp(argv[i], "-n") == 0) nconf = atoi(argv[i+1]); if (strcmp(argv[i], "-l") == 0) max_path_length = atoi(argv[i+1]); if (strcmp(argv[i], "-f") == 0) { if (strcmp("resp", argv[i + 1]) == 0) method = -1; if (strcmp("resp0", argv[i + 1]) == 0) method = 0; if (strcmp("resp1", argv[i + 1]) == 0) { method = 1; weight = 0.0005; } if (strcmp("resp2", argv[i + 1]) == 0) { method = 2; weight = 0.001; } if (strcmp("resp3", argv[i + 1]) == 0) method = 3; if (strcmp("iresp1", argv[i + 1]) == 0) { method = 4; weight = 0.0005; } if (strcmp("iresp2", argv[i + 1]) == 0) { method = 5; weight = 0.001; } if (strcmp("resp4", argv[i + 1]) == 0) { method = 6; weight = 0.000; } if (strcmp("iresp0", argv[i + 1]) == 0) method = 7; if (strcmp("resp5", argv[i + 1]) == 0) { method = 8; weight = 0.0005; } } if (strcmp(argv[i], "-w") == 0) weight = atof(argv[i+1]); if (strcmp(argv[i], "-e") == 0) iequ = atoi(argv[i+1]); } if(nconf < 1) { printf("\nNumber of conformations must be equal to or larger than 1"); exit(1); } if(iequ != 0 && iequ != 1 && iequ !=2) iequ = 1; default_cinfo(&cinfo); default_minfo(&minfo); atom = (ATOM *) malloc(sizeof(ATOM) * cinfo.maxatom); if (atom == NULL) { fprintf(stdout, "memory allocation error for *atom\n"); exit(1); } bond = (BOND *) malloc(sizeof(BOND) * cinfo.maxbond); if (bond == NULL) { fprintf(stdout, "memory allocation error for *bond\n"); exit(1); } for (i = 0; i < cinfo.maxbond; ++i) { bond[i].jflag = -1; /* bond type has not been assigned */ } overflow_flag = rac(ifilename, &atomnum, atom, &bondnum, bond, &cinfo, &minfo); if (overflow_flag) { cinfo.maxatom = atomnum + 10; cinfo.maxbond = bondnum + 10; free(atom); free(bond); atom = (ATOM *) malloc(sizeof(ATOM) * cinfo.maxatom); if (atom == NULL) { fprintf(stdout, "memory allocation error for *atom\n"); exit(1); } bond = (BOND *) malloc(sizeof(BOND) * cinfo.maxbond); if (bond == NULL) { fprintf(stdout, "memory allocation error for *bond\n"); exit(1); } int i; for (i = 0; i < cinfo.maxbond; ++i) { bond[i].jflag = -1; /* bond type has not been assigned */ } overflow_flag = rac(ifilename, &atomnum, atom, &bondnum, bond, &cinfo, &minfo); } atomicnum(atomnum, atom); adjustatomname(atomnum, atom, 1); if(minfo.dcharge >= -9990) charge = minfo.dcharge; equ_atom_id = (int *) malloc(sizeof(int) * atomnum); if (equ_atom_id == NULL) { fprintf(stdout, "memory allocation error for *equ_atom_id\n"); exit(1); } for (i = 0; i < atomnum; i++) equ_atom_id[i] = -1; if(method == 3) { atqwt = (double *) malloc(sizeof(double) * atomnum); if (atqwt == NULL) { fprintf(stdout, "memory allocation error for *atqwt\n"); exit(1); } refcharge = (double *) malloc(sizeof(double) * atomnum); if (refcharge == NULL) { fprintf(stdout, "memory allocation error for *refcharge\n"); exit(1); } for(i=0;i<atomnum;i++) { atqwt[i] = 0; refcharge[i] = 0; } // now read in atomic weights and reference charge parameters pfilename[0] = '\0'; strcpy(pfilename, amberhome); strcat(pfilename, "/dat/antechamber/RESPPARM.DAT"); readparm(pfilename); wac("ANTECHAMBER_RESP.AC", atomnum, atom, bondnum, bond, cinfo, minfo); copied_size = build_exe_path(command, "atomtype -i ANTECHAMBER_RESP.AC -o ANTECHAMBER_RESP_AT.AC -d ", sizeof command, 1 ); dfilename[0] = '\0'; strcpy(dfilename, amberhome); strcat(dfilename, "/dat/antechamber/ATOMTYPE_RESP.DEF"); strncat(command, dfilename, MAXCHAR - copied_size ); if (cinfo.intstatus == 2) fprintf(stdout, "Running: %s\n", command); status = system(command); if(status != 0) { fprintf(stdout, "Error: cannot run \"%s\" in respgen.c properly, exit\n", command); exit(1); } assignparm("ANTECHAMBER_RESP_AT.AC"); } if(iequ == 1) identify_equatom(atomnum, atom, equ_atom_id, max_path_length, bondnum, bond, 0); if(iequ == 2) identify_equatom(atomnum, atom, equ_atom_id, max_path_length, bondnum, bond, 1); icharge = (int *) malloc(sizeof(int) * atomnum); if (icharge == NULL) { fprintf(stdout, "memory allocation error for *icharge in respin()\n"); exit(1); } pcharge = (double *) malloc(sizeof(double) * atomnum); if (pcharge == NULL) { fprintf(stdout, "memory allocation error for *pcharge in respin()\n"); exit(1); } for(i=0;i<atomnum;i++) { pcharge[i] = 0.0; icharge[i] = 0; } if(iaddinfo == 1) { if ((fpaddinfo = fopen(afilename, "r")) == NULL) { fprintf(stdout, "Cannot open the additional file %s to read in main(), exit\n", afilename); exit(1); } if ((fpcharge = fopen("QIN", "w")) == NULL) { fprintf(stdout, "Cannot open file QIN, exit\n"); exit(1); } readinfo(); } respin(method); if(iaddinfo == 1) { fclose(fpcharge); fclose(fpaddinfo); } printf("\n"); /* free(atom); free(selectindex); free(selectelement); free(equ_atom_id); free(pathnum); free(pathatomnum); for (i =0 ;i <atomnum; i++) free(pathscore[i]); */ return (0); }
int main(int argc, char *argv[]) { if (strcmp(COLORTEXT, "YES") == 0 || strcmp(COLORTEXT, "yes") == 0) { if (argc == 2 && (strcmp(argv[1], "-h") == 0 || strcmp(argv[1], "-H") == 0)) { printf("[31mUsage: respgen -i[0m input file name(ac)\n" "[31m -o[0m output file name\n" "[31m -f[0m output file format (resp1 or resp2) \n" "[32m resp1[0m - first stage resp fitting \n" "[32m resp2[0m - second stage resp fitting\n"); exit(0); } if (argc != 7) { printf("[31mUsage: respgen -i[0m input file name(ac)\n" "[31m -o[0m output file name\n" "[31m -f[0m output file format (resp1 or resp2) \n" "[32m resp1[0m - first stage resp fitting \n" "[32m resp2[0m - second stage resp fitting\n"); exit(0); } } else { if (argc == 2 && (strcmp(argv[1], "-h") == 0 || strcmp(argv[1], "-H") == 0)) { printf("Usage respgen -i input file name(ac)\n"); printf(" -o output file name\n"); printf(" -f output file format (resp1 or resp2)\n"); printf(" resp1 - first stage resp fitting\n"); printf (" resp2 - second stage resp fitting \n"); exit(0); } if (argc != 7) { printf("Usage respgen -i input file name(ac)\n"); printf(" -o output file name\n"); printf(" -f output file format (resp1 or resp2)\n"); printf(" resp1 - first stage resp fitting\n"); printf (" resp2 - second stage resp fitting \n"); exit(0); } } method = 0; for (i = 1; i < argc; i += 2) { if (strcmp(argv[i], "-i") == 0) strcpy(ifilename, argv[i + 1]); if (strcmp(argv[i], "-o") == 0) strcpy(ofilename, argv[i + 1]); if (strcmp(argv[i], "-f") == 0) { if (strcmp("resp", argv[i + 1]) == 0) method = 0; if (strcmp("resp1", argv[i + 1]) == 0) method = 1; if (strcmp("resp2", argv[i + 1]) == 0) method = 2; } } default_minfo(&minfo); default_cinfo(&cinfo); atom = (ATOM *) malloc(sizeof(ATOM) * cinfo.maxatom); if (atom == NULL) { fprintf(stderr, "memory allocation error for *atom\n"); exit(0); } bond = (BOND *) malloc(sizeof(BOND) * cinfo.maxbond); if (bond == NULL) { fprintf(stderr, "memory allocation error for *bond\n"); exit(0); } overflow_flag = rac(ifilename, &atomnum, atom, &bondnum, bond, &cinfo, &minfo); if (overflow_flag) { cinfo.maxatom = atomnum + 10; cinfo.maxbond = bondnum + 10; free(atom); free(bond); atom = (ATOM *) malloc(sizeof(ATOM) * cinfo.maxatom); if (atom == NULL) { fprintf(stderr, "memory allocation error for *atom\n"); exit(0); } bond = (BOND *) malloc(sizeof(BOND) * cinfo.maxbond); if (bond == NULL) { fprintf(stderr, "memory allocation error for *bond\n"); exit(0); } overflow_flag = rac(ifilename, &atomnum, atom, &bondnum, bond, &cinfo, &minfo); } atomicnum(atomnum, atom); adjustatomname(atomnum, atom, 1); if(minfo.dcharge >= -9990) charge = minfo.dcharge; selectindex = (int *) malloc(sizeof(int) * atomnum); if (selectindex == NULL) { fprintf(stderr, "memory allocation error for *selectindex\n"); exit(0); } equatomno = (int *) malloc(sizeof(int) * atomnum); if (equatomno == NULL) { fprintf(stderr, "memory allocation error for *equatomno\n"); exit(0); } pathnum = (int *) malloc(sizeof(int) * atomnum); if (pathnum == NULL) { fprintf(stderr, "memory allocation error for *pathnum\n"); exit(0); } selectelement = (int *) malloc(sizeof(int) * atomnum); if (selectelement == NULL) { fprintf(stderr, "memory allocation error for *selectelement\n"); exit(0); } pathatomnum = (int *) malloc(sizeof(int) * atomnum); if (pathatomnum == NULL) { fprintf(stderr, "memory allocation error for *pathatomnum\n"); exit(0); } if(atomnum > MAX_RESP_ATOM) { fprintf(stderr, "The number of atoms (%d) exceed the MAX_RESP_ATOM (%d) defined in respgen.c, extend MAX_RESP_ATOM and recompile the program\n, atomnum, MAX_RESP_ATOM"); exit(0); } for (i = 0; i < atomnum; i++) { pathatomnum[i] = MAXPATHATOMNUM; pathscore[i] = (double *) calloc(pathatomnum[i], sizeof(double)); if (pathscore == NULL) { fprintf(stderr, "memory allocation error for *pathscore[%d]\n", i + 1); exit(0); } } equatom(); respin(method); printf("\n"); /* free(atom); free(selectindex); free(selectelement); free(equatomno); free(pathnum); free(pathatomnum); for (i =0 ;i <atomnum; i++) free(pathscore[i]); */ return (0); }