Esempio n. 1
0
Liste al(Arbin a)//Parcours infixe inverse : d r g
{
    Liste l=listenouv();
    Listea tmp=listenouv_a();
    Arbin atmp;
    tmp=desd(a,tmp);
    while(tailleliste_a(tmp)>0)
    {
        atmp=tete_a(tmp);
        tmp=supt_a(tmp);
        l=adjt(l,rac(atmp));
        tmp=desd(ag(atmp),tmp);
    }
    freeListe_a(tmp);
    return l;
}
Esempio n. 2
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);

}
bool test(bool is_kernel_exact = true)
{
	// types
  typedef typename K::FT FT;
  typedef typename K::Line_3 Line;
  typedef typename K::Point_3 Point;
  typedef typename K::Segment_3 Segment;
  typedef typename K::Ray_3 Ray;
  typedef typename K::Line_3 Line;
  typedef typename K::Triangle_3 Triangle;

  /* -------------------------------------
  // Test data is something like that (in t supporting plane)
  // Triangle is (p1,p2,p3)
  //
  //       +E          +1
  //                 /   \
  //        +C     6+  +8  +4      +B
  //              /   9++7  \
  //            3+-------+5--+2
  //     
  //         +F        +A      
  ------------------------------------- */
  
  Point p1(FT(1.), FT(0.), FT(0.));
  Point p2(FT(0.), FT(1.), FT(0.));
  Point p3(FT(0.), FT(0.), FT(1.));
  
  Triangle t(p1,p2,p3);
  
  // Edges of t 
  Segment s12(p1,p2);
  Segment s21(p2,p1);
  Segment s13(p1,p3);
  Segment s23(p2,p3);
  Segment s32(p3,p2);
  Segment s31(p3,p1);
  
  bool b = test_aux(is_kernel_exact,t,s12,"t-s12",s12);
  b &= test_aux(is_kernel_exact,t,s21,"t-s21",s21);
  b &= test_aux(is_kernel_exact,t,s13,"t-s13",s13);
  b &= test_aux(is_kernel_exact,t,s23,"t-s23",s23);

  // Inside points
  Point p4(FT(0.5), FT(0.5), FT(0.));
  Point p5(FT(0.), FT(0.75), FT(0.25));
  Point p6(FT(0.5), FT(0.), FT(0.5));
  Point p7(FT(0.25), FT(0.625), FT(0.125));
  Point p8(FT(0.5), FT(0.25), FT(0.25));
  
  Segment s14(p1,p4);
  Segment s41(p4,p1);
  Segment s24(p2,p4);
  Segment s42(p4,p2);
  Segment s15(p1,p5);
  Segment s25(p2,p5);
  Segment s34(p3,p4);
  Segment s35(p3,p5);
  Segment s36(p3,p6);
  Segment s45(p4,p5);
  Segment s16(p1,p6);
  Segment s26(p2,p6);
  Segment s62(p6,p2);
  Segment s46(p4,p6);
  Segment s48(p4,p8);
  Segment s56(p5,p6);
  Segment s65(p6,p5);
  Segment s64(p6,p4);
  Segment s17(p1,p7);
  Segment s67(p6,p7);
  Segment s68(p6,p8);
  Segment s86(p8,p6);
  Segment s78(p7,p8);
  Segment s87(p8,p7);
  
  b &= test_aux(is_kernel_exact,t,s14,"t-s14",s14);
  b &= test_aux(is_kernel_exact,t,s41,"t-s41",s41);
  b &= test_aux(is_kernel_exact,t,s24,"t-s24",s24);
  b &= test_aux(is_kernel_exact,t,s42,"t-s42",s42);
  b &= test_aux(is_kernel_exact,t,s15,"t-s15",s15);
  b &= test_aux(is_kernel_exact,t,s25,"t-s25",s25);
  b &= test_aux(is_kernel_exact,t,s34,"t-s34",s34);
  b &= test_aux(is_kernel_exact,t,s35,"t-s35",s35);
  b &= test_aux(is_kernel_exact,t,s36,"t-s36",s36);
  b &= test_aux(is_kernel_exact,t,s45,"t-s45",s45);
  b &= test_aux(is_kernel_exact,t,s16,"t-s16",s16);
  b &= test_aux(is_kernel_exact,t,s26,"t-s26",s26);
  b &= test_aux(is_kernel_exact,t,s62,"t-s62",s62);
  b &= test_aux(is_kernel_exact,t,s46,"t-s46",s46);
  b &= test_aux(is_kernel_exact,t,s65,"t-s65",s65);
  b &= test_aux(is_kernel_exact,t,s64,"t-s64",s64);
  b &= test_aux(is_kernel_exact,t,s48,"t-s48",s48);
  b &= test_aux(is_kernel_exact,t,s56,"t-s56",s56);
  b &= test_aux(is_kernel_exact,t,s17,"t-t17",s17);
  b &= test_aux(is_kernel_exact,t,s67,"t-t67",s67);
  b &= test_aux(is_kernel_exact,t,s68,"t-s68",s68);
  b &= test_aux(is_kernel_exact,t,s86,"t-s86",s86);
  b &= test_aux(is_kernel_exact,t,s78,"t-t78",s78);
  b &= test_aux(is_kernel_exact,t,s87,"t-t87",s87);
  
  // Outside points (in triangle plane)
  Point pA(FT(-0.5), FT(1.), FT(0.5));
  Point pB(FT(0.5), FT(1.), FT(-0.5));
  Point pC(FT(0.5), FT(-0.5), FT(1.));
  Point pE(FT(1.), FT(-1.), FT(1.));
  Point pF(FT(-1.), FT(0.), FT(2.));
  
  Segment sAB(pA,pB);
  Segment sBC(pB,pC);
  Segment s2E(p2,pE);
  Segment sE2(pE,p2);
  Segment s2A(p2,pA);
  Segment s6E(p6,pE);
  Segment sB8(pB,p8);
  Segment sC8(pC,p8);
  Segment s8C(p8,pC);
  Segment s1F(p1,pF);
  Segment sF6(pF,p6);
  
  b &= test_aux(is_kernel_exact,t,sAB,"t-sAB",p2);
  b &= test_aux(is_kernel_exact,t,sBC,"t-sBC",s46);
  b &= test_aux(is_kernel_exact,t,s2E,"t-s2E",s26);
  b &= test_aux(is_kernel_exact,t,sE2,"t-sE2",s62);
  b &= test_aux(is_kernel_exact,t,s2A,"t-s2A",p2);
  b &= test_aux(is_kernel_exact,t,s6E,"t-s6E",p6);
  b &= test_aux(is_kernel_exact,t,sB8,"t-sB8",s48);
  b &= test_aux(is_kernel_exact,t,sC8,"t-sC8",s68);
  b &= test_aux(is_kernel_exact,t,s8C,"t-s8C",s86);
  b &= test_aux(is_kernel_exact,t,s1F,"t-s1F",s13);
  b &= test_aux(is_kernel_exact,t,sF6,"t-sF6",s36);
  
  // Outside triangle plane
  Point pa(FT(0.), FT(0.), FT(0.));
  Point pb(FT(2.), FT(0.), FT(0.));
  Point pc(FT(1.), FT(0.), FT(1.));
  Point pe(FT(1.), FT(0.5), FT(0.5));
  
  Segment sab(pa,pb);
  Segment sac(pa,pc);
  Segment sae(pa,pe);
  Segment sa8(pa,p8);
  Segment sb2(pb,p2);
  
  b &= test_aux(is_kernel_exact,t,sab,"t-sab",p1);
  b &= test_aux(is_kernel_exact,t,sac,"t-sac",p6);
  b &= test_aux(is_kernel_exact,t,sae,"t-sae",p8);
  b &= test_aux(is_kernel_exact,t,sa8,"t-sa8",p8);
  b &= test_aux(is_kernel_exact,t,sb2,"t-sb2",p2);
  
  // -----------------------------------
  // ray queries
  // -----------------------------------
  // Edges of t 
  Ray r12(p1,p2);
  Ray r21(p2,p1);
  Ray r13(p1,p3);
  Ray r23(p2,p3);
  
  b &= test_aux(is_kernel_exact,t,r12,"t-r12",s12);
  b &= test_aux(is_kernel_exact,t,r21,"t-r21",s21);
  b &= test_aux(is_kernel_exact,t,r13,"t-r13",s13);
  b &= test_aux(is_kernel_exact,t,r23,"t-r23",s23);
  
  // In triangle
  Point p9_(FT(0.), FT(0.5), FT(0.5));
  Point p9(FT(0.25), FT(0.375), FT(0.375));
  
  Ray r14(p1,p4);
  Ray r41(p4,p1);
  Ray r24(p2,p4);
  Ray r42(p4,p2);
  Ray r15(p1,p5);
  Ray r25(p2,p5);
  Ray r34(p3,p4);
  Ray r35(p3,p5);
  Ray r36(p3,p6);
  Ray r45(p4,p5);
  Ray r16(p1,p6);
  Ray r26(p2,p6);
  Ray r62(p6,p2);
  Ray r46(p4,p6);
  Ray r48(p4,p8);
  Ray r56(p5,p6);
  Ray r47(p4,p7);
  Ray r89(p8,p9);
  Ray r86(p8,p6);
  Ray r68(p6,p8);
  Segment r89_res(p8,p9_);
  
  b &= test_aux(is_kernel_exact,t,r14,"t-r14",s12);
  b &= test_aux(is_kernel_exact,t,r41,"t-r41",s41);
  b &= test_aux(is_kernel_exact,t,r24,"t-r24",s21);
  b &= test_aux(is_kernel_exact,t,r42,"t-r42",s42);
  b &= test_aux(is_kernel_exact,t,r15,"t-r15",s15);
  b &= test_aux(is_kernel_exact,t,r25,"t-r25",s23);
  b &= test_aux(is_kernel_exact,t,r34,"t-r34",s34);
  b &= test_aux(is_kernel_exact,t,r35,"t-r35",s32);
  b &= test_aux(is_kernel_exact,t,r36,"t-r36",s31);
  b &= test_aux(is_kernel_exact,t,r45,"t-r45",s45);
  b &= test_aux(is_kernel_exact,t,r16,"t-r16",s13);
  b &= test_aux(is_kernel_exact,t,r26,"t-r26",s26);
  b &= test_aux(is_kernel_exact,t,r62,"t-r62",s62);
  b &= test_aux(is_kernel_exact,t,r46,"t-r46",s46);
  b &= test_aux(is_kernel_exact,t,r48,"t-r48",s46);
  b &= test_aux(is_kernel_exact,t,r56,"t-r56",s56);
  b &= test_aux(is_kernel_exact,t,r47,"t-r47",s45);
  b &= test_aux(is_kernel_exact,t,r89,"t-t89",r89_res);
  b &= test_aux(is_kernel_exact,t,r68,"t-r68",s64);
  b &= test_aux(is_kernel_exact,t,r86,"t-r86",s86);
  
  
  // Outside points (in triangre prane)
  Ray rAB(pA,pB);
  Ray rBC(pB,pC);
  Ray r2E(p2,pE);
  Ray rE2(pE,p2);
  Ray r2A(p2,pA);
  Ray r6E(p6,pE);
  Ray rB8(pB,p8);
  Ray rC8(pC,p8);
  Ray r8C(p8,pC);
  Ray r1F(p1,pF);
  Ray rF6(pF,p6);
  
  b &= test_aux(is_kernel_exact,t,rAB,"t-rAB",p2);
  b &= test_aux(is_kernel_exact,t,rBC,"t-rBC",s46);
  b &= test_aux(is_kernel_exact,t,r2E,"t-r2E",s26);
  b &= test_aux(is_kernel_exact,t,rE2,"t-rE2",s62);
  b &= test_aux(is_kernel_exact,t,r2A,"t-r2A",p2);
  b &= test_aux(is_kernel_exact,t,r6E,"t-r6E",p6);
  b &= test_aux(is_kernel_exact,t,rB8,"t-rB8",s46);
  b &= test_aux(is_kernel_exact,t,rC8,"t-rC8",s64);
  b &= test_aux(is_kernel_exact,t,r8C,"t-r8C",s86);
  b &= test_aux(is_kernel_exact,t,r1F,"t-r1F",s13);
  b &= test_aux(is_kernel_exact,t,rF6,"t-rF6",s31);
  
  // Outside triangle plane
  Ray rab(pa,pb);
  Ray rac(pa,pc);
  Ray rae(pa,pe);
  Ray ra8(pa,p8);
  Ray rb2(pb,p2);
  
  b &= test_aux(is_kernel_exact,t,rab,"t-rab",p1);
  b &= test_aux(is_kernel_exact,t,rac,"t-rac",p6);
  b &= test_aux(is_kernel_exact,t,rae,"t-rae",p8);
  b &= test_aux(is_kernel_exact,t,ra8,"t-ra8",p8);
  b &= test_aux(is_kernel_exact,t,rb2,"t-rb2",p2);
  
  // -----------------------------------
  // Line queries
  // -----------------------------------
  // Edges of t 
  Line l12(p1,p2);
  Line l21(p2,p1);
  Line l13(p1,p3);
  Line l23(p2,p3);
  
  b &= test_aux(is_kernel_exact,t,l12,"t-l12",s12);
  b &= test_aux(is_kernel_exact,t,l21,"t-l21",s21);
  b &= test_aux(is_kernel_exact,t,l13,"t-l13",s13);
  b &= test_aux(is_kernel_exact,t,l23,"t-l23",s23);
  
  // In triangle
  Line l14(p1,p4);
  Line l41(p4,p1);
  Line l24(p2,p4);
  Line l42(p4,p2);
  Line l15(p1,p5);
  Line l25(p2,p5);
  Line l34(p3,p4);
  Line l35(p3,p5);
  Line l36(p3,p6);
  Line l45(p4,p5);
  Line l16(p1,p6);
  Line l26(p2,p6);
  Line l62(p6,p2);
  Line l46(p4,p6);
  Line l48(p4,p8);
  Line l56(p5,p6);
  Line l47(p4,p7);
  Line l89(p8,p9);
  Line l86(p8,p6);
  Line l68(p6,p8);
  Segment l89_res(p1,p9_);

  
  b &= test_aux(is_kernel_exact,t,l14,"t-l14",s12);
  b &= test_aux(is_kernel_exact,t,l41,"t-l41",s21);
  b &= test_aux(is_kernel_exact,t,l24,"t-l24",s21);
  b &= test_aux(is_kernel_exact,t,l42,"t-l42",s12);
  b &= test_aux(is_kernel_exact,t,l15,"t-l15",s15);
  b &= test_aux(is_kernel_exact,t,l25,"t-l25",s23);
  b &= test_aux(is_kernel_exact,t,l34,"t-l34",s34);
  b &= test_aux(is_kernel_exact,t,l35,"t-l35",s32);
  b &= test_aux(is_kernel_exact,t,l36,"t-l36",s31);
  b &= test_aux(is_kernel_exact,t,l45,"t-l45",s45);
  b &= test_aux(is_kernel_exact,t,l16,"t-l16",s13);
  b &= test_aux(is_kernel_exact,t,l26,"t-l26",s26);
  b &= test_aux(is_kernel_exact,t,l62,"t-l62",s62);
  b &= test_aux(is_kernel_exact,t,l46,"t-l46",s46);
  b &= test_aux(is_kernel_exact,t,l48,"t-l48",s46);
  b &= test_aux(is_kernel_exact,t,l56,"t-l56",s56);
  b &= test_aux(is_kernel_exact,t,l47,"t-l47",s45);
  b &= test_aux(is_kernel_exact,t,l89,"t-t89",l89_res);
  b &= test_aux(is_kernel_exact,t,l68,"t-l68",s64);
  b &= test_aux(is_kernel_exact,t,l86,"t-l86",s46);

  
  // Outside points (in triangle plane)
  Line lAB(pA,pB);
  Line lBC(pB,pC);
  Line l2E(p2,pE);
  Line lE2(pE,p2);
  Line l2A(p2,pA);
  Line l6E(p6,pE);
  Line lB8(pB,p8);
  Line lC8(pC,p8);
  Line l8C(p8,pC);
  Line l1F(p1,pF);
  Line lF6(pF,p6);
  
  b &= test_aux(is_kernel_exact,t,lAB,"t-lAB",p2);
  b &= test_aux(is_kernel_exact,t,lBC,"t-lBC",s46);
  b &= test_aux(is_kernel_exact,t,l2E,"t-l2E",s26);
  b &= test_aux(is_kernel_exact,t,lE2,"t-lE2",s62);
  b &= test_aux(is_kernel_exact,t,l2A,"t-l2A",p2);
  b &= test_aux(is_kernel_exact,t,l6E,"t-l6E",s26);
  b &= test_aux(is_kernel_exact,t,lB8,"t-lB8",s46);
  b &= test_aux(is_kernel_exact,t,lC8,"t-lC8",s64);
  b &= test_aux(is_kernel_exact,t,l8C,"t-l8C",s46);
  b &= test_aux(is_kernel_exact,t,l1F,"t-l1F",s13);
  b &= test_aux(is_kernel_exact,t,lF6,"t-lF6",s31);
  
  // Outside triangle plane
  Line lab(pa,pb);
  Line lac(pa,pc);
  Line lae(pa,pe);
  Line la8(pa,p8);
  Line lb2(pb,p2);
  
  b &= test_aux(is_kernel_exact,t,lab,"t-lab",p1);
  b &= test_aux(is_kernel_exact,t,lac,"t-lac",p6);
  b &= test_aux(is_kernel_exact,t,lae,"t-lae",p8);
  b &= test_aux(is_kernel_exact,t,la8,"t-la8",p8);
  b &= test_aux(is_kernel_exact,t,lb2,"t-lb2",p2);
  
  
	return b;
}
Esempio n. 4
0
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("Usage: residuegen  input_file \n");
			exit(1);
		}
		if (argc != 2) {
			printf("Usage: residuegen  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);

}
Esempio n. 5
0
int main(int argc, char *argv[]) {
	int i,j,k;
	int overflow_flag = 0;
	int count;
	int atid1, atid2;
	int resid1, resid2;
	int oldresid;
	int suc;
	double sum;
	double x,y,z;
	char line[MAXCHAR];
	char defstr[MAXCHAR];
	char atomname[MAXCHAR];

    	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: match  -i  input file name \n"
				 "              -r  reference file name \n"
				 "              -f  format: 1-pdb (the default), 2-ac, 3-mol2, 4-sdf, 5-crd/rst\n"
				 "              -o  output file name\n"
				 "              -l  run log file name, default is \"match.log\"\n"
				 "              -s  selection mode\n"
				 "                  0: use all atoms (the default)\n"
				 "                  1: specify atom names\n"
				 "                  2: use atom defination file\n"
				 "                  3: use residue defination file - original residue IDs\n"
				 "                  4: use residue defination file - renumbered residue IDs\n"
				 "              -ds definition string if selection modes of '1' or '3' or '4'\n"
				 "                  e.g. 'C,N,O,CA', or 'HET' which stands for heavy atoms for '-ds 1')\n"
				 "              -df definition file if selection mode of '2' or '3' or '4'\n"
				 "                  records take a form of 'ATOM atom_id_input atom_id_reference'\n"
				 "                  or 'RES res_id_input res_id_reference'\n"
				 "              -n  number of atoms participating ls-fitting,\n"
				 "                  default is -1, which implies to use all the selected atoms\n"
				 "              -m  matrix file, default is \"match.matrix\"\n"
				 "              -t  job type:\n"
				 "                  0: calculate rms only, need -i and -r\n"    
				 "                  1: lsfit, need -i, -r and -o the default\n"    
				 "                  2: translation/rotation, need -i, -o and -m\n"); 
			exit(0);
		}
		if (argc != 23 && argc != 21 && argc != 19 && argc != 17 && argc != 15 && argc != 13 && argc != 11 && argc !=9 && argc !=7 && argc !=5) {
			printf
				("Usage: match  -i  input file name \n"
				 "              -r  reference file name \n"
				 "              -f  format: 1-pdb (the default), 2-ac, 3-mol2, 4-sdf, 5-crd/rst\n"
				 "              -o  output file name\n"
				 "              -l  run log file name, default is \"match.log\"\n"
				 "              -s  selection mode\n"
				 "                  0: use all atoms (the default)\n"
				 "                  1: specify atom names\n"
				 "                  2: use atom defination file\n"
				 "                  3: use residue defination file - original residue IDs\n"
				 "                  4: use residue defination file - renumbered residue IDs\n"
				 "              -ds definition string if selection modes of '1' or '3' or '4'\n"
				 "                  e.g. 'C,N,O,CA', or 'HET' which stands for heavy atoms for '-ds 1')\n"
				 "              -df definition file if selection mode of '2' or '3' or '4'\n"
				 "                  records take a form of 'ATOM atom_id_input atom_id_reference'\n"
				 "                  or 'RES res_id_input res_id_reference'\n"
				 "              -n  number of atoms participating ls-fitting,\n"
				 "                  default is -1, which implies to use all the selected atoms\n"
				 "              -m  matrix file, default is \"match.matrix\"\n"
				 "              -t  job type:\n"
				 "                  0: calculate rms only, need -i and -r\n"    
				 "                  1: lsfit, need -i, -r and -o the default\n"    
				 "                  2: translation/rotation, need -i, -o and -m\n"); 
			exit(0);
		}
	} else {
		if (argc == 2
			&& (strcmp(argv[1], "-h") == 0
				|| strcmp(argv[1], "-H") == 0)) {
			printf
				("Usage: match  -i  input file name \n"
				 "              -r  reference file name \n"
				 "              -f  format: 1-pdb (the default), 2-ac, 3-mol2, 4-sdf, 5-crd/rst\n"
				 "              -o  output file name\n"
				 "              -l  run log file name, default is \"match.log\"\n"
				 "              -s  selection mode\n"
				 "                  0: use all atoms (the default)\n"
				 "                  1: specify atom names\n"
				 "                  2: use atom defination file\n"
				 "                  3: use residue defination file - original residue IDs\n"
				 "                  4: use residue defination file - renumbered residue IDs\n"
				 "              -ds definition string if selection modes of '1' or '3' or '4'\n"
				 "                  e.g. 'C,N,O,CA', or 'HET' which stands for heavy atoms for '-ds 1')\n"
				 "              -df definition file if selection mode of '2' or '3' or '4'\n"
				 "                  records take a form of 'ATOM atom_id_input atom_id_reference'\n"
				 "                  or 'RES res_id_input res_id_reference'\n"
				 "              -n  number of atoms participating ls-fitting,\n"
				 "                  default is -1, which implies to use all the selected atoms\n"
				 "              -m  matrix file, default is \"match.matrix\"\n"
				 "              -t  job type:\n"
				 "                  0: calculate rms only, need -i and -r\n"    
				 "                  1: lsfit, need -i, -r and -o the default\n"    
				 "                  2: translation/rotation, need -i, -o and -m\n"); 
			exit(0);
		}
		if (argc != 23 && argc != 21 && argc != 19 && argc != 17 && argc != 15 && argc != 13 && argc != 11 && argc !=9 && argc !=7 && argc !=5) {
			printf
				("Usage: match  -i  input file name \n"
				 "              -r  reference file name \n"
				 "              -f  format: 1-pdb (the default), 2-ac, 3-mol2, 4-sdf, 5-crd/rst\n"
				 "              -o  output file name\n"
				 "              -l  run log file name, default is \"match.log\"\n"
				 "              -s  selection mode\n"
				 "                  0: use all atoms (the default)\n"
				 "                  1: specify atom names\n"
				 "                  2: use atom defination file\n"
				 "                  3: use residue defination file - original residue IDs\n"
				 "                  4: use residue defination file - renumbered residue IDs\n"
				 "              -ds definition string if selection modes of '1' or '3' or '4'\n"
				 "                  e.g. 'C,N,O,CA', or 'HET' which stands for heavy atoms for '-ds 1')\n"
				 "              -df definition file if selection mode of '2' or '3' or '4'\n"
				 "                  records take a form of 'ATOM atom_id_input atom_id_reference'\n"
				 "                  or 'RES res_id_input res_id_reference'\n"
				 "              -n  number of atoms participating ls-fitting,\n"
				 "                  default is -1, which implies to use all the selected atoms\n"
				 "              -m  matrix file, default is \"match.matrix\"\n"
				 "              -t  job type:\n"
				 "                  0: calculate rms only, need -i and -r\n"    
				 "                  1: lsfit, need -i, -r and -o the default\n"    
				 "                  2: translation/rotation, need -i, -o and -m\n"); 
			exit(0);
		}

	}

	for (i = 1; i < argc; i += 2) {
		if (strcmp(argv[i], "-i") == 0) {
			strcpy(ifilename, argv[i + 1]);
			iinput = 1;
		}
		if (strcmp(argv[i], "-f") == 0) 
			format=atoi(argv[i+1]);
		if (strcmp(argv[i], "-o") == 0) {
			strcpy(ofilename, argv[i + 1]);
			ioutput = 1;
		}
		if (strcmp(argv[i], "-r") == 0) {
			strcpy(rfilename, argv[i + 1]);
			iref = 1;
		}
		if (strcmp(argv[i], "-s") == 0) 
			stype = atoi(argv[i+1]);
		if (strcmp(argv[i], "-ds") == 0) 
			strcpy(def_atomname_str, argv[i + 1]);
		if (strcmp(argv[i], "-df") == 0) 
			strcpy(def_filename, argv[i + 1]);
		if (strcmp(argv[i], "-m") == 0) {
			strcpy(mfilename, argv[i + 1]);
			imatrix = 1;
		}
		if (strcmp(argv[i], "-t") == 0)
			jobtype = atoi(argv[i+1]);
		if (strcmp(argv[i], "-n") == 0)
			nsel = atoi(argv[i+1]);
		if (strcmp(argv[i], "-l") == 0) 
			strcpy(lfilename, argv[i + 1]);
	}

	if(jobtype !=0 && jobtype != 1 && jobtype != 2) jobtype = 1;
	if(format != 1 && format != 2 && format != 3 && format != 4 && format != 5) format = 1;
	if(jobtype == 0) 
		if(iinput == 0 || iref == 0) {
			fprintf(stderr, "RMS calculation needs an input and a reference files, exit\n");
			exit(0);
		}
	if(jobtype == 1) 
		if(iinput == 0 || ioutput == 0 || iref == 0) {
			fprintf(stderr, "The least-square fitting calculation needs an input, an output and a reference files, exit\n");
			exit(0);
		}

	if(jobtype == 2) 
		if(iinput == 0 || ioutput == 0) {
			fprintf(stderr, "The translation/rotation job needs an input and an output files, exit\n");
			exit(0);
		}
	if(jobtype == 0 || jobtype == 1) {
		if ((fplog = fopen(lfilename, "w")) == NULL) {
			fprintf(stderr, "Cannot open log file %s to write, exit\n", lfilename);
			exit(1);
		}
	}
/*	read in input files*/
        memory(0, MAXATOM, MAXBOND, MAXRING);
	if(format == 1) {
                overflow_flag = rpdb(ifilename, &atomnum, atom, cinfo, minfo, 0);
                if (overflow_flag) {
                        cinfo.maxatom = atomnum + 10;
                        cinfo.maxbond = bondnum + 10;
                        memory(7, cinfo.maxatom, cinfo.maxbond, cinfo.maxring);
                        overflow_flag = rpdb(ifilename, &atomnum, atom, cinfo, minfo, 0);
                }
	}
	if(format == 2) {
                overflow_flag = rac(ifilename, &atomnum, atom, &bondnum, bond, &cinfo, &minfo);
                if (overflow_flag) {
                        cinfo.maxatom = atomnum + 10;
                        cinfo.maxbond = bondnum + 10;
                        memory(7, cinfo.maxatom, cinfo.maxbond, cinfo.maxring);
                	overflow_flag = rac(ifilename, &atomnum, atom, &bondnum, bond, &cinfo, &minfo);
                }
	}
	if(format == 3) {
                overflow_flag = rmol2(ifilename, &atomnum, atom, &bondnum, bond, &cinfo, &minfo, 0);
                if (overflow_flag) {
                        cinfo.maxatom = atomnum + 10;
                        cinfo.maxbond = bondnum + 10;
                        memory(7, cinfo.maxatom, cinfo.maxbond, cinfo.maxring);
                        overflow_flag =
                		rmol2(ifilename, &atomnum, atom, &bondnum, bond, &cinfo, &minfo, 0);
                }
	}
	if(format == 4) {
                overflow_flag = rmdl(ifilename, &atomnum, atom, &bondnum, bond, cinfo, minfo);
                if (overflow_flag) {
                        cinfo.maxatom = atomnum + 10;
                        cinfo.maxbond = bondnum + 10;
                        memory(7, cinfo.maxatom, cinfo.maxbond, cinfo.maxring);
                        overflow_flag = rmdl(ifilename, &atomnum, atom, &bondnum, bond, cinfo, minfo);
                }
	}
	if(format == 5) {
                overflow_flag = rrst(ifilename, &atomnum, atom, cinfo);
                if (overflow_flag) {
                        cinfo.maxatom = atomnum + 10;
                        memory(7, cinfo.maxatom, cinfo.maxbond, cinfo.maxring);
                        overflow_flag = rrst(ifilename, &atomnum, atom, cinfo);
                }
	}
	free(bond);
	free(ring);
	free(arom);
	cinfo.maxatom = MAXATOM;
	cinfo.maxbond = MAXBOND;
	cinfo.maxring = MAXRING;
        ref_memory(0, MAXATOM, MAXBOND, MAXRING);
	if(format == 1) {
                overflow_flag = rpdb(rfilename, &refatomnum, refatom, cinfo, minfo, 0);
                if (overflow_flag) {
                        cinfo.maxatom = refatomnum + 10;
                        cinfo.maxbond = refbondnum + 10;
                        ref_memory(7, cinfo.maxatom, cinfo.maxbond, cinfo.maxring);
                        overflow_flag = rpdb(rfilename, &refatomnum, refatom, cinfo, minfo, 0);
                }
	}
	if(format == 2) {
               	overflow_flag = rac(rfilename, &refatomnum, refatom, &refbondnum, refbond, &cinfo, &minfo);
                if (overflow_flag) {
                        cinfo.maxatom = refatomnum + 10;
                        cinfo.maxbond = refbondnum + 10;
                        ref_memory(7, cinfo.maxatom, cinfo.maxbond, cinfo.maxring);
               		overflow_flag = rac(rfilename, &refatomnum, refatom, &refbondnum, refbond, &cinfo, &minfo);
                }
	}
	if(format == 3) {
                overflow_flag = rmol2(rfilename, &refatomnum, refatom, &refbondnum, refbond, &cinfo, &minfo, 0);
                if (overflow_flag) {
                        cinfo.maxatom = refatomnum + 10;
                        cinfo.maxbond = refbondnum + 10;
                        ref_memory(7, cinfo.maxatom, cinfo.maxbond, cinfo.maxring);
                        overflow_flag = rmol2(rfilename, &refatomnum, refatom, &refbondnum, refbond, &cinfo, &minfo, 0);
                }
	}
	if(format == 4) {
                overflow_flag = rmdl(rfilename, &refatomnum, refatom, &refbondnum, refbond, cinfo, minfo);
                if (overflow_flag) {
                        cinfo.maxatom = refatomnum + 10;
                        cinfo.maxbond = refbondnum + 10;
                        ref_memory(7, cinfo.maxatom, cinfo.maxbond, cinfo.maxring);
                        overflow_flag = rmdl(rfilename, &refatomnum, refatom, &refbondnum, refbond, cinfo, minfo);
                }
	}
	if(format == 5) {
                overflow_flag = rrst(rfilename, &refatomnum, refatom, cinfo);
                if (overflow_flag) {
                        cinfo.maxatom = refatomnum + 10;
                        ref_memory(7, cinfo.maxatom, cinfo.maxbond, cinfo.maxring);
                        overflow_flag = rrst(rfilename, &refatomnum, refatom, cinfo);
                }
	}
	free(refbond);
	free(refring);
	free(refarom);
	if(debug == 1) {
		for(i=0;i<atomnum;i++)
			printf("ATOM %5d %5s %5s %5d %8.3lf %8.3lf %8.3lf\n", i+1, atom[i].name, atom[i].aa, atom[i].resno, atom[i].x, atom[i].y, atom[i].z);
		for(i=0;i<refatomnum;i++)
			printf("ATOM %5d %5s %5s %5d %8.3lf %8.3lf %8.3lf\n", i+1, refatom[i].name, refatom[i].aa, refatom[i].resno, refatom[i].x, refatom[i].y, refatom[i].z);
	}
	
if(jobtype == 0 || jobtype == 1) {
        fit_atom = (FITATOM *) malloc(sizeof(FITATOM) * atomnum);
        if (fit_atom == NULL) {
        	fprintf(stderr, "memory allocation error for *fit_atom\n");
                exit(1);
        }
        fit_refatom = (FITATOM *) malloc(sizeof(FITATOM) * refatomnum);
        if (fit_refatom == NULL) {
        	fprintf(stderr, "memory allocation error for *fit_refatom\n");
                exit(1);
        }
	if(stype == 0) {
		for(i=0;i<atomnum;i++) {
			fit_atom[i].x=atom[i].x;
			fit_atom[i].y=atom[i].y;
			fit_atom[i].z=atom[i].z;
		}
		for(i=0;i<refatomnum;i++) {
			fit_refatom[i].x=refatom[i].x;
			fit_refatom[i].y=refatom[i].y;
			fit_refatom[i].z=refatom[i].z;
		}
		fit_atomnum = atomnum;
		fit_refatomnum = refatomnum;
	}
	if(stype == 1) {
		count = 0;
		for(i=0;i <= strlen(def_atomname_str);i++) {
			if(def_atomname_str[i]==' ') continue;
			if(def_atomname_str[i]==',') def_atomname_str[i] = ' ';
			defstr[count] = def_atomname_str[i];
			count++;
		}
		sscanf(defstr, "%s", atomname);	
		strcpy(def_atomname[ndef_atomname].str, atomname);
		ndef_atomname++;
		for(i=1;i<strlen(defstr);i++) 
			if(defstr[i] == ' ') {
				sscanf(&defstr[i], "%s", atomname);
				strcpy(def_atomname[ndef_atomname].str, atomname);
				ndef_atomname++;
			}
		for(i=0;i<atomnum;i++) {
			suc = 0;
			for(j=0;j<ndef_atomname;j++) {
				if(strcmp(def_atomname[j].str, atom[i].name) == 0) {
					suc = 1;
					break;
				}
				if(strcmp(def_atomname[j].str, "HET") == 0) 
					if(atom[i].name[0] != 'H') {
						suc = 1;
						break;
					}
			}
			if(suc == 1) {
				fit_atom[fit_atomnum].x=atom[i].x;
				fit_atom[fit_atomnum].y=atom[i].y;
				fit_atom[fit_atomnum].z=atom[i].z;
				fit_atomnum++;
			}
				
		}
		for(i=0;i<refatomnum;i++) {
			suc = 0;
			for(j=0;j<ndef_atomname;j++) {
				if(strcmp(def_atomname[j].str, refatom[i].name) == 0) {
					suc = 1;
					break;
				}
				if(strcmp(def_atomname[j].str, "HET") == 0) 
					if(refatom[i].name[0] != 'H') {
						suc = 1;
						break;
					}
			}
			if(suc == 1) {
				fit_refatom[fit_refatomnum].x=refatom[i].x;
				fit_refatom[fit_refatomnum].y=refatom[i].y;
				fit_refatom[fit_refatomnum].z=refatom[i].z;
				fit_refatomnum++;
			}
		}
	}
	if(stype == 2) {
		if ((fpdef = fopen(def_filename, "r")) == NULL) {
			fprintf(stderr, "Cannot open file %s, exit\n", def_filename);
			exit(1);
		}
		count = 0;
		for(;;) {
			if (fgets(line, MAXCHAR, fpdef) == NULL) break;
			if(strncmp(line, "ATOM", 4) == 0) {
				sscanf(&line[4], "%d%d", &atid1, &atid2);
				atid1--;
				atid2--;
				fit_atom[count].x=atom[atid1].x;
				fit_atom[count].y=atom[atid1].y;
				fit_atom[count].z=atom[atid1].z;
				fit_refatom[count].x=refatom[atid2].x;
				fit_refatom[count].y=refatom[atid2].y;
				fit_refatom[count].z=refatom[atid2].z;
				count++;
			}
		}
		fit_atomnum = count;
		fit_refatomnum = count;
		fclose(fpdef);
	}

	if(stype == 3 || stype == 4) {
/*first of all, read in atom name definition strings*/
		count = 0;
		for(i=0;i <= strlen(def_atomname_str);i++) {
			if(def_atomname_str[i]==' ') continue;
			if(def_atomname_str[i]==',') def_atomname_str[i] = ' ';
			defstr[count] = def_atomname_str[i];
			count++;
		}
		sscanf(defstr, "%s", atomname);	
		strcpy(def_atomname[ndef_atomname].str, atomname);
		ndef_atomname++;
		for(i=1;i<strlen(defstr);i++) 
			if(defstr[i] == ' ') {
				sscanf(&defstr[i], "%s", atomname);
				if(strcmp(atomname, "HET") == 0) {
					fprintf(stderr, "Warning: HET cannot be defined with -s of 3\n");
					continue;
				}
				strcpy(def_atomname[ndef_atomname].str, atomname);
				ndef_atomname++;
			}
		if(debug == 1) {
			for(i=0;i<ndef_atomname;i++)
				printf("DEF %5d %5s\n", i+1, def_atomname[i].str);

		}
		if(stype == 4) {
			count = 0;
			oldresid = -99999;
			for(i=0;i<atomnum;i++) {
				if(atom[i].resno != oldresid) {
					oldresid = atom[i].resno;
					count++;
				}
				atom[i].resno = count;
			}

			count = 0;
			oldresid = -99999;
			for(i=0;i<refatomnum;i++) {
				if(refatom[i].resno != oldresid) {
					oldresid = refatom[i].resno;
					count++;
				}
				refatom[i].resno = count;
			}
		}
/* now working on residue definition file */
		if ((fpdef = fopen(def_filename, "r")) == NULL) {
			fprintf(stderr, "Cannot open file %s, exit\n", def_filename);
			exit(1);
		}
		count = 0;
		for(;;) {
			if (fgets(line, MAXCHAR, fpdef) == NULL) break;
			if(strncmp(line, "RES", 3) == 0) {
				sscanf(&line[3], "%d%d", &resid1, &resid2);
				if(debug == 1) 
					printf("RES %5d %5d\n", resid1, resid2);	
				for(i=0; i< ndef_atomname; i++) {
					atid1 = -1;
					atid2 = -1;
					for(j=0;j<atomnum;j++) 
						if(strcmp(def_atomname[i].str, atom[j].name) == 0 && atom[j].resno == resid1) {
							atid1 = j;	
							break;
						}
					for(j=0;j<refatomnum;j++) 
						if(strcmp(def_atomname[i].str, refatom[j].name) == 0 && refatom[j].resno == resid2) {
							atid2 = j;	
							break;
						}
					
					if(atid1 >= 0 && atid2 >= 0) {	
						fit_atom[count].x=atom[atid1].x;
						fit_atom[count].y=atom[atid1].y;
						fit_atom[count].z=atom[atid1].z;
						fit_refatom[count].x=refatom[atid2].x;
						fit_refatom[count].y=refatom[atid2].y;
						fit_refatom[count].z=refatom[atid2].z;
						count++;
					}
				}
			}
		}

		fit_atomnum = count;
		fit_refatomnum = count;
		fclose(fpdef);
	}


	if(fit_atomnum != fit_refatomnum || fit_atomnum <=0) {
		fprintf(stderr, "\nThe numumber of fitting atoms in input file (%d) is different from the number of fitting atoms in ref file (%d)", fit_atomnum, fit_refatomnum);
		exit(0);
	}
	if(nsel > 0 && fit_atomnum > nsel) fit_atomnum = nsel;	
	if(fit_atomnum <= 0) {
		fprintf(stderr, "\nThe number of fitting atoms is smaller than or equal to zero, exit!");
		exit(1);
	}
	sum = 0;
	for(i=0;i<fit_atomnum;i++) {
		sum+=(fit_atom[i].x-fit_refatom[i].x) * (fit_atom[i].x-fit_refatom[i].x); 
		sum+=(fit_atom[i].y-fit_refatom[i].y) * (fit_atom[i].y-fit_refatom[i].y); 
		sum+=(fit_atom[i].z-fit_refatom[i].z) * (fit_atom[i].z-fit_refatom[i].z); 
	}
	rms = sqrt(sum/fit_atomnum);
	fprintf(fplog, "The rmsd before least-square fitting is %9.4lf\n", rms);
	fprintf(fplog, "Number of atoms participate least-square fitting is %9d\n", fit_atomnum);
	fprintf(stdout, "\nThe rmsd before least-square fitting is %9.4lf", rms);
	fprintf(stdout, "\nNumber of atoms participate least-square fitting is %9d", fit_atomnum);
	if(jobtype == 0) {
		fclose(fplog);
		return 0;
	}
	if ((fpmatrix = fopen(mfilename, "w")) == NULL) {
		fprintf(stderr, "Cannot open file %s, exit\n", mfilename);
		exit(1);
	}
	rms = lsfit(fit_refatom, fit_atom, fit_atomnum) ;
	for(i=0;i<fit_atomnum;i++) {
               	x=CG0[0]+ROT[0][0]*(fit_atom[i].x-CG1[0])+ ROT[0][1]*(fit_atom[i].y-CG1[1])+ ROT[0][2]*(fit_atom[i].z-CG1[2]);
               	y=CG0[1]+ROT[1][0]*(fit_atom[i].x-CG1[0])+ ROT[1][1]*(fit_atom[i].y-CG1[1])+ ROT[1][2]*(fit_atom[i].z-CG1[2]);
               	z=CG0[2]+ROT[2][0]*(fit_atom[i].x-CG1[0])+ ROT[2][1]*(fit_atom[i].y-CG1[1])+ ROT[2][2]*(fit_atom[i].z-CG1[2]);

		sum =(x-fit_refatom[i].x) * (x-fit_refatom[i].x);
		sum+=(y-fit_refatom[i].y) * (y-fit_refatom[i].y);
		sum+=(z-fit_refatom[i].z) * (z-fit_refatom[i].z);
		sum = sqrt(sum);
		fprintf(fplog, "ATOM    %5d %9.3lf %9.3lf %9.3lf ", i+1,  fit_atom[i].x, fit_atom[i].y, fit_atom[i].z);
		fprintf(fplog, "REFATOM %9.3lf %9.3lf %9.3lf %9.3lf\n", fit_refatom[i].x, fit_refatom[i].y, fit_refatom[i].z, sum);
	}
	fclose(fpmatrix);
	fprintf(fplog, "\nThe rmsd after least-square fitting is %9.4lf\n", rms);
	fprintf(stdout, "\nThe rmsd after least-square fitting is %9.4lf\n", rms);
	fclose(fplog);
}
if(jobtype == 2) 
	rmatrix(mfilename);
if(jobtype == 1 || jobtype == 2) {
	for(i=0;i<atomnum;i++) {
                x=CG0[0]+ROT[0][0]*(atom[i].x-CG1[0])+ ROT[0][1]*(atom[i].y-CG1[1])+ ROT[0][2]*(atom[i].z-CG1[2]);
                y=CG0[1]+ROT[1][0]*(atom[i].x-CG1[0])+ ROT[1][1]*(atom[i].y-CG1[1])+ ROT[1][2]*(atom[i].z-CG1[2]);
                z=CG0[2]+ROT[2][0]*(atom[i].x-CG1[0])+ ROT[2][1]*(atom[i].y-CG1[1])+ ROT[2][2]*(atom[i].z-CG1[2]);
		atom[i].x = x;
		atom[i].y = y;
		atom[i].z = z;
	}
	if(format == 1) wpdb(ofilename, atomnum, atom);
	if(format == 2) wac(ofilename, atomnum, atom, bondnum, bond, cinfo, minfo);
	if(format == 3) wmol2(ofilename, atomnum, atom, bondnum, bond, arom, cinfo, minfo);
	if(format == 4) wmdl(ofilename, atomnum, atom, bondnum, bond, cinfo);
	if(format == 5) wrst(ofilename, atomnum, atom);
}
return 0;
}
Esempio n. 6
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);

}