********>Bugfix 6:
Authors: Junmei Wang
Date: 04/28/2004

Programs: antechamber

Description: When the input is a mol2 file ("-fi mol2") antechamber gets
             confused, and will give wrong atom types and charges.  Other
             fixups allow cm2 charges to be obtained, and to do some
             additional error checking, and better identification of
             aromatic rings

Fix:  copy this file to "$AMBERHOME/src/antechamber/patchfile".  Then:
         cd $AMBERHOME/src/antechamber
         patch -p0 < patchfile

------------------------------------------------------------------------------
diff -c -r1.4 am1bcc.c
*** am1bcc.c	2004/02/02 21:46:47	1.4
--- am1bcc.c	2004/04/28 23:11:49
***************
*** 44,49 ****
--- 44,50 ----
  char *system_env;
  char line[MAXCHAR];
  int i, j, k, l;
+ int intstatus =1;
  double bccparm[MAX_BCCATOMTYPENUM][MAX_BCCATOMTYPENUM][MAX_BCCBONDTYPENUM];
  double totalcharge = 0.0;
  
***************
*** 143,148 ****
--- 144,150 ----
  				 "              -o output file name \n"
  				 "              -f output file format(pdb or ac, optional, default is ac)\n"
  				 "              -p bcc parm file name (optional))\n"
+ 				 "              -s status information, can be 0 (brief), 1 (the default) and 2 (verbose)\n"
  				 "              -j atom and bond type judge option, default is 0)\n"
  				 "                 0: No judgement\n"
  				 "                 1: Atom type\n"
***************
*** 152,163 ****
  				 "                 5: Atom and partial bond type\n");
  			exit(0);
  		}
! 		if (argc != 7 && argc != 9 && argc != 11) {
  			printf
  				("Usage: am1bcc -i input file name in ac format \n"
  				 "              -o output file name \n"
  				 "              -f output file format(pdb or ac, optional, default is ac)\n"
  				 "              -p bcc parm file name (optional))\n"
  				 "              -j atom and bond type judge option, default is 0)\n"
  				 "                 0: No judgement\n"
  				 "                 1: Atom type\n"
--- 154,166 ----
  				 "                 5: Atom and partial bond type\n");
  			exit(0);
  		}
! 		if (argc != 7 && argc != 9 && argc != 11 &argc != 13) {
  			printf
  				("Usage: am1bcc -i input file name in ac format \n"
  				 "              -o output file name \n"
  				 "              -f output file format(pdb or ac, optional, default is ac)\n"
  				 "              -p bcc parm file name (optional))\n"
+ 				 "              -s status information, can be 0 (brief), 1 (the default) and 2 (verbose)\n"
  				 "              -j atom and bond type judge option, default is 0)\n"
  				 "                 0: No judgement\n"
  				 "                 1: Atom type\n"
***************
*** 175,180 ****
--- 178,184 ----
  				   "              -o output file name \n"
  				   "              -f output file format(pdb or ac, optional, default is ac)\n"
  				   "              -p bcc parm file name (optional))\n"
+ 				   "              -s status information, can be 0 (brief), 1 (the default) and 2 (verbose)\n"
  				   "              -j atom and bond type judge option, default is 0)\n"
  				   "                 0: No judgement\n"
  				   "                 1: Atom type\n"
***************
*** 184,194 ****
  				   "                 5: Atom and partial bond type\n");
  			exit(0);
  		}
! 		if (argc != 7 && argc != 9 && argc != 11) {
  			printf("Usage: am1bcc -i input file name in ac format \n"
  				   "              -o output file name \n"
  				   "              -f output file format(pdb or ac, optional, default is ac)\n"
  				   "              -p bcc parm file name (optional))\n"
  				   "              -j atom and bond type judge option, default is 0)\n"
  				   "                 0: No judgement\n"
  				   "                 1: Atom type\n"
--- 188,199 ----
  				   "                 5: Atom and partial bond type\n");
  			exit(0);
  		}
! 		if (argc != 7 && argc != 9 && argc != 11 && argc != 13) {
  			printf("Usage: am1bcc -i input file name in ac format \n"
  				   "              -o output file name \n"
  				   "              -f output file format(pdb or ac, optional, default is ac)\n"
  				   "              -p bcc parm file name (optional))\n"
+ 				   "              -s status information, can be 0 (brief), 1 (the default) and 2 (verbose)\n"
  				   "              -j atom and bond type judge option, default is 0)\n"
  				   "                 0: No judgement\n"
  				   "                 1: Atom type\n"
***************
*** 209,214 ****
--- 214,221 ----
  			strcpy(ofilename, argv[i + 1]);
  		if (strcmp(argv[i], "-j") == 0)
  			judge_flag = atoi(argv[i + 1]);
+ 		if (strcmp(argv[i], "-s") == 0)
+ 			intstatus = atoi(argv[i + 1]);
  		if (strcmp(argv[i], "-f") == 0)
  			if (strcmp(argv[i + 1], "PDB") == 0
  				|| strcmp(argv[i + 1], "pdb") == 0)
***************
*** 244,284 ****
  
  	if (judge_flag == 1) {
  		strcat(command_at, ifilename);
! 		if (cinfo.intstatus == 2)
  			fprintf(stderr, "\nRunning: %s\n", command_at);
  		system(command_at);
  	}
  	if (judge_flag == 2) {
  		strcat(command_bt, ifilename);
  		strcat(command_bt, " -j full");
! 		if (cinfo.intstatus == 2)
  			fprintf(stderr, "\nRunning: %s\n", command_bt);
  		system(command_bt);
  	}
  	if (judge_flag == 3) {
  		strcat(command_bt, ifilename);
! 		if (cinfo.intstatus == 2)
  			fprintf(stderr, "\nRunning: %s\n", command_bt);
  		system(command_bt);
  	}
  	if (judge_flag == 4) {
  		strcat(command_bt, ifilename);
  		strcat(command_bt, " -j full");
! 		if (cinfo.intstatus == 2)
  			fprintf(stderr, "\nRunning: %s\n", command_bt);
  		system(command_bt);
  		strcat(command_at, "ANTECHAMBER_AM1BCC.AC");
! 		if (cinfo.intstatus == 2)
  			fprintf(stderr, "\nRunning: %s\n", command_at);
  		system(command_at);
  	}
  	if (judge_flag == 5) {
  		strcat(command_bt, ifilename);
! 		if (cinfo.intstatus == 2)
  			fprintf(stderr, "\nRunning: %s\n", command_bt);
  		system(command_bt);
  		strcat(command_at, "ANTECHAMBER_AM1BCC.AC");
! 		if (cinfo.intstatus == 2)
  			fprintf(stderr, "\nRunning: %s\n", command_at);
  		system(command_at);
  	}
--- 251,291 ----
  
  	if (judge_flag == 1) {
  		strcat(command_at, ifilename);
! 		if (intstatus == 2)
  			fprintf(stderr, "\nRunning: %s\n", command_at);
  		system(command_at);
  	}
  	if (judge_flag == 2) {
  		strcat(command_bt, ifilename);
  		strcat(command_bt, " -j full");
! 		if (intstatus == 2)
  			fprintf(stderr, "\nRunning: %s\n", command_bt);
  		system(command_bt);
  	}
  	if (judge_flag == 3) {
  		strcat(command_bt, ifilename);
! 		if (intstatus == 2)
  			fprintf(stderr, "\nRunning: %s\n", command_bt);
  		system(command_bt);
  	}
  	if (judge_flag == 4) {
  		strcat(command_bt, ifilename);
  		strcat(command_bt, " -j full");
! 		if (intstatus == 2)
  			fprintf(stderr, "\nRunning: %s\n", command_bt);
  		system(command_bt);
  		strcat(command_at, "ANTECHAMBER_AM1BCC.AC");
! 		if (intstatus == 2)
  			fprintf(stderr, "\nRunning: %s\n", command_at);
  		system(command_at);
  	}
  	if (judge_flag == 5) {
  		strcat(command_bt, ifilename);
! 		if (intstatus == 2)
  			fprintf(stderr, "\nRunning: %s\n", command_bt);
  		system(command_bt);
  		strcat(command_at, "ANTECHAMBER_AM1BCC.AC");
! 		if (intstatus == 2)
  			fprintf(stderr, "\nRunning: %s\n", command_at);
  		system(command_at);
  	}
===================================================================
*** antechamber.c	2004/02/02 21:46:47	1.51
--- antechamber.c	2004/04/28 23:12:00
***************
*** 299,305 ****
  	char tmpchar[MAXCHAR];
  	char *system_env;
  
! 	wac("ANTECHAMBER_BOND_TYPE.AC", atomnum, atom, bondnum, bond, cinfo,
  		minfo);
  	system_env = (char *) getenv("AMBERHOME");
  	if (system_env != NULL) {
--- 299,305 ----
  	char tmpchar[MAXCHAR];
  	char *system_env;
  
! 	wac("ANTECHAMBER_BOND_TYPE.AC0", atomnum, atom, bondnum, bond, cinfo,
  		minfo);
  	system_env = (char *) getenv("AMBERHOME");
  	if (system_env != NULL) {
***************
*** 310,316 ****
  		strcpy(tmpchar, "bondtype");
  
  	strcat(tmpchar,
! 		   " -i ANTECHAMBER_BOND_TYPE.AC -o ANTECHAMBER_BOND_TYPE.AC -f ac -j ");
  	if (bondtype_flag == 1)
  		strcat(tmpchar, "part");
  	else
--- 310,316 ----
  		strcpy(tmpchar, "bondtype");
  
  	strcat(tmpchar,
! 		   " -i ANTECHAMBER_BOND_TYPE.AC0 -o ANTECHAMBER_BOND_TYPE.AC -f ac -j ");
  	if (bondtype_flag == 1)
  		strcat(tmpchar, "part");
  	else
***************
*** 922,928 ****
  		judgebondtype(atomnum, atom, bondnum, bond, cinfo, minfo,
  					  bondtype_flag);
  		if(cinfo.prediction_index ==2||cinfo.prediction_index ==3) cinfo.prediction_index = 0;
! 		if(cinfo.prediction_index ==3||cinfo.prediction_index ==4) cinfo.prediction_index = 1;
  	}
  
  	if (duplicatedname_flag)
--- 922,928 ----
  		judgebondtype(atomnum, atom, bondnum, bond, cinfo, minfo,
  					  bondtype_flag);
  		if(cinfo.prediction_index ==2||cinfo.prediction_index ==3) cinfo.prediction_index = 0;
! 		if(cinfo.prediction_index ==4||cinfo.prediction_index ==5) cinfo.prediction_index = 1;
  	}
  
  	if (duplicatedname_flag)
***************
*** 944,954 ****
  		system(tmpchar);
  		rac("ANTECHAMBER_AC.AC", &atomnum, atom, &bondnum, bond, &cinfo,
  			&minfo);
- 		if(strcmp("bcc", cinfo.chargetype) != 0 && strcmp("2", cinfo.chargetype) != 0) {
- 			if(cinfo.prediction_index ==1) cinfo.prediction_index = 0;
- 			if(cinfo.prediction_index ==4) cinfo.prediction_index = 2;
- 			if(cinfo.prediction_index ==5) cinfo.prediction_index = 3;
- 		}
  	}
  
  /*     the following code readin or calculate charges */
--- 944,949 ----
***************
*** 966,972 ****
  		bcc(ifilename, atomnum, atom, bondnum, bond, arom, &cinfo, &minfo);
  	if (strcmp("cm2", cinfo.chargetype) == 0
  		|| strcmp("3", cinfo.chargetype) == 0)
! 		cm2(atomnum, atom, cinfo, minfo);
  	if (strcmp("esp", cinfo.chargetype) == 0
  		|| strcmp("4", cinfo.chargetype) == 0)
  		esp(ifilename, atomnum, atom, cinfo, minfo);
--- 961,967 ----
  		bcc(ifilename, atomnum, atom, bondnum, bond, arom, &cinfo, &minfo);
  	if (strcmp("cm2", cinfo.chargetype) == 0
  		|| strcmp("3", cinfo.chargetype) == 0)
! 		cm2(atomnum, atom, &cinfo, &minfo);
  	if (strcmp("esp", cinfo.chargetype) == 0
  		|| strcmp("4", cinfo.chargetype) == 0)
  		esp(ifilename, atomnum, atom, cinfo, minfo);
Index: charge.c
===================================================================
RCS file: /thr/gamow/cvsroot/amber8/src/antechamber/charge.c,v
retrieving revision 1.8
diff -c -r1.8 charge.c
*** charge.c	2004/02/02 21:44:42	1.8
--- charge.c	2004/04/28 23:12:10
***************
*** 5,11 ****
  
  
  
! void rmopcharge(char *filename, int atomnum, ATOM atom[], MOLINFO *minfo)
  {
  
  	/* now modified for divcon.out output */
--- 5,11 ----
  
  
  
! void rmopcharge(char *filename, int atomnum, ATOM atom[], MOLINFO *minfo, int flag)
  {
  
  	/* now modified for divcon.out output */
***************
*** 24,29 ****
--- 24,30 ----
  	char line[MAXCHAR];
  	double tmpfloat1;
  	double tmpfloat2;
+ 	double tmpfloat3;
  
  	if ((fpout = fopen(filename, "r")) == NULL) {
  		fprintf(stderr, "Cannot open %s , exit\n", filename);
***************
*** 54,62 ****
  			break;
  		}
  		if (index == 2) {
! 			sscanf(line, "%d%s%lf%lf", &tmpint, tmpchar, &tmpfloat1,
! 				   &tmpfloat2);
! 			atom[number].charge = tmpfloat1;
  			number++;
  		}
  	}
--- 55,68 ----
  			break;
  		}
  		if (index == 2) {
! 			sscanf(line, "%d%s%lf%lf%lf", &tmpint, tmpchar, &tmpfloat1,
! 				   &tmpfloat2, &tmpfloat3);
! 			if(flag == 1) 
! 				atom[number].charge = tmpfloat1;
! 			if(flag == 2) 
! 				atom[number].charge = tmpfloat2;
! 			if(flag == 3) 
! 				atom[number].charge = tmpfloat3;
  			number++;
  		}
  	}
***************
*** 273,278 ****
--- 279,288 ----
  	strcat(tmpchar1,
  		   " -i ANTECHAMBER_AM1BCC_PRE.AC -o ANTECHAMBER_AM1BCC.AC -f ac -p ");
  	strcat(tmpchar1, tmpchar2);
+ 	strcat(tmpchar1, " -s ");
+ 	newitoa((*cinfo).intstatus, tmpchar2);
+ 	strcat(tmpchar1, tmpchar2);
+ /*
  	if (strcmp((*cinfo).intype, "ac") == 0 || strcmp((*cinfo).intype, "1") == 0
  		|| strcmp((*cinfo).intype, "mol2") == 0
  		|| strcmp((*cinfo).intype, "2") == 0) {
***************
*** 283,288 ****
--- 293,305 ----
  		strcat(tmpchar1, tmpchar);
  	} else
  		strcat(tmpchar1, " -j 4");
+ */
+ 	if ((*cinfo).prediction_index == -1)
+ 		(*cinfo).prediction_index = 0;
+ 	newitoa((*cinfo).prediction_index, tmpchar);
+ 	strcat(tmpchar1, " -j ");
+ 	strcat(tmpchar1, tmpchar);
+ 
  	if ((*cinfo).intstatus == 2)
  		fprintf(stderr, "\nRunning: %s\n", tmpchar1);
  	system(tmpchar1);
***************
*** 318,324 ****
  
  	if (strcmp((*cinfo).intype, "mopout") == 0
  		|| strcmp((*cinfo).intype, "12") == 0)
! 		rmopcharge(filename, atomnum, atom, minfo);
  	else {
  		wmopcrt("divcon.in", atomnum, atom, *minfo);
  
--- 335,341 ----
  
  	if (strcmp((*cinfo).intype, "mopout") == 0
  		|| strcmp((*cinfo).intype, "12") == 0)
! 		rmopcharge(filename, atomnum, atom, minfo, 1);
  	else {
  		wmopcrt("divcon.in", atomnum, atom, *minfo);
  
***************
*** 332,366 ****
  		if ((*cinfo).intstatus == 2 || (*cinfo).intstatus == 1)
  			fprintf(stderr, "\nRunning: %s\n", tmpchar);
  		system(tmpchar);
! 		rmopcharge("divcon.out", atomnum, atom, minfo);
  	}
  	bccharge(atomnum, atom, bondnum, bond, arom, cinfo, minfo);
  }
  
  
  /* CHARGE METHOD : CM2 */
! void cm2(int atomnum, ATOM atom[], CONTROLINFO cinfo, MOLINFO minfo)
  {
! 	char tmpchar[200];
! 	char keyword[MAXCHAR];
! 	char *system_env;
! 	strcpy(keyword, minfo.mkeyword);
! 	strcat(keyword, " CM2 ");
! 	wmopcrt("ANTECHAMBER_CM2", atomnum, atom, minfo);
! 	system_env = (char *) getenv("AMBERHOME");
! 	if (system_env != NULL) {
! 		strcpy(tmpchar, system_env);
! 		strcat(tmpchar, "/exe/");
! 		strcat(tmpchar, minfo.mopac_prog);
! 	} else {
! 		strcpy(tmpchar, minfo.mopac_prog);
! 	}
! 	strcat(tmpchar, " ANTECHAMBER_CM2  ANTECHAMBER_CM2_OUT");
! 	if (cinfo.intstatus == 2 || cinfo.intstatus == 1)
! 		fprintf(stderr, "\nRunning: %s\n", tmpchar);
! 
! 	system(tmpchar);
! 	rmopcharge("ANTECHAMBER_CM2_OUT", atomnum, atom, &minfo);
  }
  
  /* CHARGE METHOD : Mulliken  */
--- 349,376 ----
  		if ((*cinfo).intstatus == 2 || (*cinfo).intstatus == 1)
  			fprintf(stderr, "\nRunning: %s\n", tmpchar);
  		system(tmpchar);
! 		rmopcharge("divcon.out", atomnum, atom, minfo, 1);
  	}
  	bccharge(atomnum, atom, bondnum, bond, arom, cinfo, minfo);
  }
  
  
  /* CHARGE METHOD : CM2 */
! void cm2(int atomnum, ATOM atom[], CONTROLINFO *cinfo, MOLINFO *minfo)
  {
!         char tmpchar[200];
!         char *system_env;
!          wmopcrt("divcon.in", atomnum, atom, *minfo);
!          system_env = (char *) getenv("AMBERHOME");
!          if (system_env != NULL) {
!          	strcpy(tmpchar, system_env);
!                 strcat(tmpchar, "/exe/divcon");
!          } else 
!                 strcpy(tmpchar, "divcon");
!          if ((*cinfo).intstatus == 2 || (*cinfo).intstatus == 1)
!          	fprintf(stderr, "\nRunning: %s\n", tmpchar);
!                 system(tmpchar);
!                 rmopcharge("divcon.out", atomnum, atom, minfo, 3);
  }
  
  /* CHARGE METHOD : Mulliken  */
***************
*** 375,381 ****
  		rgaucharge(filename, "mul", atomnum, atom, minfo);
  	else if (strcmp((*cinfo).intype, "mopout") == 0
  			 || strcmp((*cinfo).intype, "12") == 0)
! 		rmopcharge(filename, atomnum, atom, minfo);
  	else {
  		wmopcrt("divcon.in", atomnum, atom, *minfo);
  		system_env = (char *) getenv("AMBERHOME");
--- 385,391 ----
  		rgaucharge(filename, "mul", atomnum, atom, minfo);
  	else if (strcmp((*cinfo).intype, "mopout") == 0
  			 || strcmp((*cinfo).intype, "12") == 0)
! 		rmopcharge(filename, atomnum, atom, minfo, 1);
  	else {
  		wmopcrt("divcon.in", atomnum, atom, *minfo);
  		system_env = (char *) getenv("AMBERHOME");
***************
*** 388,394 ****
  		if ((*cinfo).intstatus == 2 || (*cinfo).intstatus == 1)
  			fprintf(stderr, "\nRunning: %s\n", tmpchar);
  		system(tmpchar);
! 		rmopcharge("divcon.out", atomnum, atom, minfo);
  	}
  }
  
--- 398,404 ----
  		if ((*cinfo).intstatus == 2 || (*cinfo).intstatus == 1)
  			fprintf(stderr, "\nRunning: %s\n", tmpchar);
  		system(tmpchar);
! 		rmopcharge("divcon.out", atomnum, atom, minfo, 1);
  	}
  }
  
===================================================================
*** ring.c	2003/06/11 05:30:53	1.1
--- ring.c	2004/04/28 23:12:23
***************
*** 235,244 ****
  	}
  
  	for (i = 0; i < ringnum; i++) {
- /* for pure aliphatic rings*/
  		tmpint = 0;
  		for (j = 0; j < ring[i].num; j++)
  			tmpint += initarom[ring[i].atomno[j]];
  		if (tmpint == -2 * ring[i].num) {
  			for (j = 0; j < ring[i].num; j++)
  				arom[ring[i].atomno[j]].ar5++;
--- 235,244 ----
  	}
  
  	for (i = 0; i < ringnum; i++) {
  		tmpint = 0;
  		for (j = 0; j < ring[i].num; j++)
  			tmpint += initarom[ring[i].atomno[j]];
+ /* for pure aliphatic rings*/
  		if (tmpint == -2 * ring[i].num) {
  			for (j = 0; j < ring[i].num; j++)
  				arom[ring[i].atomno[j]].ar5++;
***************
*** 293,302 ****
  					index0 = 0;
  					for (k = 0; k < bondnum; k++) {
  						if (bond[k].bondi == tmpint1
! 							&& (bond[k].type == 8 || bond[k].type == 2))
  							index0 = 1;
  						if (bond[k].bondj == tmpint1
! 							&& (bond[k].type == 8 || bond[k].type == 2))
  							index0 = 1;
  					}
  					if (index0 == 0)
--- 293,302 ----
  					index0 = 0;
  					for (k = 0; k < bondnum; k++) {
  						if (bond[k].bondi == tmpint1
! 							&& (bond[k].type == 8 || bond[k].type == 2 || bond[k].type == 10))
  							index0 = 1;
  						if (bond[k].bondj == tmpint1
! 							&& (bond[k].type == 8 || bond[k].type == 2 || bond[k].type == 10))
  							index0 = 1;
  					}
  					if (index0 == 0)
===================================================================
*** bondtype.C	2004/02/26 22:31:28	1.7
--- bondtype.C	2004/04/28 23:12:34
***************
*** 1154,1159 ****
--- 1154,1165 ----
  		exit(1);
  
  	}
+ 	for(i=0;i