Exemple #1
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("Usage: respgen -i input file name(ac)\n"
				   "               -o output file name\n"
				   "               -l 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"
				   "               -f output file format (resp1 or resp2) \n"
				   "                  resp0 - evaluation the current charges \n"
				   "                  resp1 - first stage resp fitting \n"
				   "                  resp2 - second stage resp fitting\n"
				   "                  iresp0 - evaluation the current charges for polarizable model\n"
				   "                  iresp1- first stage of i_resp fitting \n"
				   "                  iresp2- second stage of i_resp fitting\n"
				   "                  resp3 - one-stage resp fitting\n"
				   "                  resp4 - calculating ESP from point charges\n"
				   "                  resp5 - no-equalization\n"
				   "               -e equalizing atomic charge, default is 1\n"
				   "                  0 not use \n"
				   "                  1 by atomic paths\n"
				   "                  2 by atomic paths and structural information, i.e. E/Z confirgurations\n"
				   "               -a additional input data (predefined charges, atom groups etc).)\n"
				   "               -n number of conformations (default is 1)\n"
				   "               -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"
				   "               -o output file name\n"
				   "               -l 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"
				   "               -f output file format (resp1 or resp2) \n"
				   "                  resp0 - evaluation the current charges \n"
				   "                  resp1 - first stage resp fitting \n"
				   "                  resp2 - second stage resp fitting\n"
				   "                  iresp0 - evaluation the current charges for polarizable model\n"
				   "                  iresp1- first stage of i_resp fitting \n"
				   "                  iresp2- second stage of i_resp fitting\n"
				   "                  resp3 - one-stage resp fitting\n"
				   "                  resp4 - calculating ESP from point charges\n"
				   "                  resp5 - no-equalization\n"
				   "               -e equalizing atomic charge, default is 1\n"
				   "                  0 not use \n"
				   "                  1 by atomic paths\n"
				   "                  2 by atomic paths and structural information, i.e. E/Z confirgurations\n"
				   "               -a additional input data (predefined charges, atom groups etc).)\n"
				   "               -n number of conformations (default is 1)\n"
				   "               -w 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);

}
Exemple #2
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("Usage: respgen -i input file name(ac)\n"
				   "               -o output file name\n"
				   "               -f output file format (resp1 or resp2) \n"
				   "                  resp1 - first stage resp fitting \n"
				   "                  resp2 - second stage resp fitting\n");
			exit(0);
		}
		if (argc != 7) {
			printf("Usage: respgen -i input file name(ac)\n"
				   "               -o output file name\n"
				   "               -f output file format (resp1 or resp2) \n"
				   "                  resp1 - first stage resp fitting \n"
				   "                  resp2 - 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);

}