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); }
static PyObject* rdparm(PyObject *self, PyObject *args) { char *filename; if (!PyArg_ParseTuple(args, "s", &filename)) return NULL; std::string fname(filename); std::string error_message; // The data we are parsing from the prmtop ParmDataMap parmData; ParmStringMap parmComments, unkParmData; ParmFormatMap parmFormats; std::vector<std::string> flagList; std::string version; ExitStatus retval; Py_BEGIN_ALLOW_THREADS retval = readparm(fname, flagList, parmData, parmComments, unkParmData, parmFormats, version); Py_END_ALLOW_THREADS if (retval == NOOPEN) { error_message = "Could not open " + fname + " for reading"; PyErr_SetString(PyExc_IOError, error_message.c_str()); return NULL; } if (retval == NOVERSION) { error_message = "Could not find %VERSION in " + fname; PyErr_SetString(PyExc_TypeError, error_message.c_str()); return NULL; } if (retval == EMPTY) { error_message = fname + " was empty"; PyErr_SetString(PyExc_ValueError, error_message.c_str()); return NULL; } if (retval == ERR) { error_message = "Prmtop parsing error parsing " + fname; PyErr_SetString(PyExc_RuntimeError, error_message.c_str()); return NULL; } // If we got here, the parsing must have been OK. Create the parm_data, // formats, and comments dicts to pass back to Python PyObject *parm_data = PyDict_New(); PyObject *comments = PyDict_New(); PyObject *formats = PyDict_New(); PyObject *unknown_flags = PyList_New((Py_ssize_t) unkParmData.size()); PyObject *flag_list = PyList_New((Py_ssize_t) flagList.size()); Py_ssize_t unkFlagNum = 0; for (size_t i = 0; i < flagList.size(); i++) { std::string flag = flagList[i]; Py_ssize_t listSize; PyObject *list; if (parmFormats[flag].dataType == UNKNOWN) listSize = (Py_ssize_t) unkParmData[flag].size(); else listSize = (Py_ssize_t) parmData[flag].size(); list = PyList_New(listSize); // Now see what type this is and fill the list up accordingly switch (parmFormats[flag].dataType) { case INTEGER: for (Py_ssize_t j = 0; j < listSize; j++) { long val = (long) parmData[flag][(size_t)j].i; PyList_SET_ITEM(list, j, PyInt_FromLong(val)); } break; case FLOAT: for (Py_ssize_t j = 0; j < listSize; j++) { double val = parmData[flag][(size_t)j].f; PyList_SET_ITEM(list, j, PyFloat_FromDouble(val)); } break; case HOLLERITH: for (Py_ssize_t j = 0; j < listSize; j++) { PyList_SET_ITEM(list, j, PyString_FromString(parmData[flag][(size_t)j].c)); } break; case UNKNOWN: for (Py_ssize_t j = 0; j < listSize; j++) { std::string line = unkParmData[flag][(size_t) j]; PyList_SET_ITEM(list, j, PyString_FromString(line.c_str())); } // Add this to the list of unknown flags PyList_SET_ITEM(unknown_flags, unkFlagNum++, PyString_FromString(flag.c_str())); break; default: // Should not be here PyErr_SetString(PyExc_RuntimeError, "This should be unreachable"); return NULL; } SetItem_PyDict_AndDecref(parm_data, flag.c_str(), list); // Now comments if (parmComments.count(flag) == 0) { SetItem_PyDict_AndDecref(comments, flag.c_str(), PyList_New(0)); } else { int ncom = parmComments[flag].size(); PyObject *commentList = PyList_New(ncom); for (Py_ssize_t j = 0; j < ncom; j++) { std::string line = parmComments[flag][(size_t)j]; PyList_SET_ITEM(commentList, j, PyString_FromString(line.c_str())); } SetItem_PyDict_AndDecref(comments, flag.c_str(), commentList); } // Now formats PyObject *fmt = PyString_FromString(parmFormats[flag].fmt.c_str()); SetItem_PyDict_AndDecref(formats, flag.c_str(), fmt); // Now flag list PyList_SET_ITEM(flag_list, (Py_ssize_t)i, PyString_FromString(flag.c_str())); } PyObject *ret = PyTuple_New(6); PyTuple_SET_ITEM(ret, 0, parm_data); PyTuple_SET_ITEM(ret, 1, comments); PyTuple_SET_ITEM(ret, 2, formats); PyTuple_SET_ITEM(ret, 3, unknown_flags); PyTuple_SET_ITEM(ret, 4, flag_list); PyTuple_SET_ITEM(ret, 5, PyString_FromString(version.c_str())); return ret; }