
/*
	file:		convert.c
	purpose:	to convert between one type to another

	author: leigh willard 
	date:	August 1994	
	place:	Protein Engineering Network of Centres of Excellence
			Department of Biochemistry
			University of Alberta
        modify: August 2001
*/


#include "main.h"

/*************************************************************/
char long2short(ss)
char *ss;
{

   if (0 == strcmp(ss, "GLY"))
		return('G');
   else if (0 == strcmp(ss, "ALA"))
		return('A');
   else if (0 == strcmp(ss, "VAL"))
		return('V');
   else if (0 == strcmp(ss, "LEU"))
		return('L');
   else if (0 == strcmp(ss, "ILE"))
		return('I');
   else if (0 == strcmp(ss, "SER"))
		return('S');
   else if (0 == strcmp(ss, "CYS"))
		return('C');
   else if (0 == strcmp(ss, "THR"))
		return('T');
   else if (0 == strcmp(ss, "MET"))
		return('M');
   else if (0 == strcmp(ss, "PHE"))
		return('F');
   else if (0 == strcmp(ss, "TYR"))
		return('Y');
   else if (0 == strcmp(ss, "TRP"))
		return('W');
   else if (0 == strcmp(ss, "PRO"))
		return('P');
   else if (0 == strcmp(ss, "HIS"))
		return('H');
   else if (0 == strcmp(ss, "LYS"))
		return('K');
   else if (0 == strcmp(ss, "ARG"))
		return('R');
   else if (0 == strcmp(ss, "ASP"))
		return('D');
   else if (0 == strcmp(ss, "GLU"))
		return('E');
   else if (0 == strcmp(ss, "ASN"))
		return('N');
   else if (0 == strcmp(ss, "GLN")) /* add by Haiyan Zhang */
		return('Q');
   else return('X');
   
}	/* long2short */


/*************************************************************/
/* get index into aaAve table 
*/
int atm2num(atmName)
char atmName[MAX_NAME_LEN];
{
	if (strcmp(atmName, "BB") == 0)
		return(BB);
	else if (strcmp(atmName, "C") == 0)
		return(C);
	else if (strcmp(atmName, "CA") == 0)
		return(CA);
	else if (strcmp(atmName, "CB") == 0)
		return(CB);
	else if (strcmp(atmName, "CD") == 0)
		return(CD);
	else if (strcmp(atmName, "CD1") == 0)
		return(CD1);
	else if (strcmp(atmName, "CD2") == 0)
		return(CD2);
	else if (strcmp(atmName, "CE") == 0)
		return(CE);
	else if (strcmp(atmName, "CE1") == 0)
		return(CE1);
	else if (strcmp(atmName, "CE2") == 0)
		return(CE2);
	else if (strcmp(atmName, "CE3") == 0)
		return(CE3);
	else if (strcmp(atmName, "CG") == 0)
		return(CG);
	else if (strcmp(atmName, "CG1") == 0)
		return(CG1);
	else if (strcmp(atmName, "CG2") == 0)
		return(CG2);
	else if (strcmp(atmName, "CH") == 0)
		return(CH);
	else if (strcmp(atmName, "CH2") == 0)
		return(CH2);
	else if (strcmp(atmName, "CH3") == 0)
		return(CA);
	else if (strcmp(atmName, "CZ") == 0)
		return(CZ);
	else if (strcmp(atmName, "CZ1") == 0)
		return(CZ1);
	else if (strcmp(atmName, "CZ2") == 0)
		return(CZ2);
	else if (strcmp(atmName, "CZ3") == 0)
		return(CZ3);
	else if (strcmp(atmName, "N") == 0)
		return(N);
	else if (strcmp(atmName, "ND1") == 0)
		return(ND1);
	else if (strcmp(atmName, "ND2") == 0)
		return(ND2);
	else if (strcmp(atmName, "NE") == 0)
		return(NE);
	else if (strcmp(atmName, "NE1") == 0)
		return(NE1);
	else if (strcmp(atmName, "NE2") == 0)
		return(NE2);
	else if (strcmp(atmName, "NH1") == 0)
		return(NH1);
	else if (strcmp(atmName, "NH2") == 0)
		return(NH2);
	else if (strcmp(atmName, "NZ") == 0)
		return(NZ);
	else if (strcmp(atmName, "O") == 0)
		return(O);
	else if (strcmp(atmName, "OD1") == 0)
		return(OD1);
	else if (strcmp(atmName, "OD2") == 0)
		return(OD2);
	else if (strcmp(atmName, "OE1") == 0)
		return(OE1);
	else if (strcmp(atmName, "OE2") == 0)
		return(OE2);
	else if (strcmp(atmName, "OG") == 0)
		return(OG);
	else if (strcmp(atmName, "OG1") == 0)
		return(OG1);
	else if (strcmp(atmName, "OH") == 0)
		return(OH);
	else if ((strcmp(atmName, "OXT") == 0) ||
		(strcmp(atmName, "OT") == 0) )
		return(OXT);
	else if (strcmp(atmName, "SC") == 0)
		return(SC);
	else if (strcmp(atmName, "SD") == 0)
		return(SD);
	else if (strcmp(atmName, "SG") == 0)
		return(SG);
	else {
		printf("ERROR: undefined atom name %s in atm2num\n", atmName);
		vadar_finish(TRUE);
	}

}	/* atm2num */


/*************************************************************/
/* get index into standardAsa table 
*/
int res2num(resName)
char resName[MAX_NAME_LEN];
{
	if (strcmp(resName, "ALA") == 0)
		return(ALA);
	else if (strcmp(resName, "ARG") == 0)
		return(ARG);
	else if (strcmp(resName, "ASN") == 0)
		return(ASN);
	else if (strcmp(resName, "ASP") == 0)
		return(ASP);
	else if (strcmp(resName, "CYS") == 0)
		return(CYS);
	else if (strcmp(resName, "GLN") == 0)
		return(GLN);
	else if (strcmp(resName, "GLU") == 0)
		return(GLU);
	else if (strcmp(resName, "GLY") == 0)
		return(GLY);
	else if (strcmp(resName, "HIS") == 0)
		return(HIS);
	else if (strcmp(resName, "ILE") == 0)
		return(ILE);
	else if (strcmp(resName, "LEU") == 0)
		return(LEU);
	else if (strcmp(resName, "LYS") == 0)
		return(LYS);
	else if (strcmp(resName, "MET") == 0)
		return(MET);
	else if (strcmp(resName, "SME") == 0)
	        return(MET);
	else if (strcmp(resName, "SEM") == 0)
	        return(MET);
	else if (strcmp(resName, "MSE") == 0)
	        return(MET);
	else if (strcmp(resName, "PHE") == 0)
		return(PHE);
	else if (strcmp(resName, "PRO") == 0)
		return(PRO);
	else if (strcmp(resName, "SER") == 0)
		return(SER);
	else if (strcmp(resName, "THR") == 0)
		return(THR);
	else if (strcmp(resName, "TRP") == 0)
		return(TRP);
	else if (strcmp(resName, "TYR") == 0)
		return(TYR);
	else if (strcmp(resName, "VAL") == 0)
		return(VAL);
	else if (strcmp(resName, "ACE") == 0)
		return(ACE);
	else if (strcmp(resName, "NH2") == 0)
		return(NH2_RES);
	else if (strcmp(resName, "DEU") == 0)
		return(DEU);
	else if (strcmp(resName, "PCA") == 0) /* add by Haiyan Zhang */
		return(PCA);
	else if (strcmp(resName, "n/a") == 0)
		return(NA);
	else if (strcmp(resName, "NA") == 0)
		return(NA);
	else if (strcmp(resName, "") == 0)
		return(NA);
	else return(NA);
	/*else {
		printf("ERROR: undefined res name %s in res2num\n", resName);
		vadar_finish(TRUE);
	}*/

}	/* res2num */


/*************************************************************/
/* get index into standardAsa array 
*/
int struct2num(strucName)
char strucName;
{
	/* convert struct to integer value */
	switch (strucName) {
		case 'B' : return(BETA);
		case 'C' : return(COIL);
		case 'H' : return(HELIX);
		case 'T' : return(TURN);
		default  : return(-1);
	}

}	/* struct2num */


/*************************************************************
* convert from environment class to an integer
*/
int env2num(envclass)
char *envclass;
{

	if (strcmp(envclass, "B1H") == 0)
		return(B1H);
	else if (strcmp(envclass, "B1B") == 0)
		return(B1B);
	else if (strcmp(envclass, "B1C") == 0)
		return(B1C);

	else if (strcmp(envclass, "B2H") == 0)
		return(B2H);
	else if (strcmp(envclass, "B2B") == 0)
		return(B2B);
	else if (strcmp(envclass, "B2C") == 0)
		return(B2C);

	else if (strcmp(envclass, "B3H") == 0)
		return(B3H);
	else if (strcmp(envclass, "B3B") == 0)
		return(B3B);
	else if (strcmp(envclass, "B3C") == 0)
		return(B3C);

	else if (strcmp(envclass, "P1H") == 0)
		return(P1H);
	else if (strcmp(envclass, "P1B") == 0)
		return(P1B);
	else if (strcmp(envclass, "P1C") == 0)
		return(P1C);

	else if (strcmp(envclass, "P2H") == 0)
		return(P2H);
	else if (strcmp(envclass, "P2B") == 0)
		return(P2B);
	else if (strcmp(envclass, "P2C") == 0)
		return(P2C);

	else if (strcmp(envclass, "E0H") == 0)
		return(E0H);
	else if (strcmp(envclass, "E0B") == 0)
		return(E0B);
	else if (strcmp(envclass, "E0C") == 0)
		return(E0C);

	else return(E0C);

}	/* env2num */


/*************************************************************
* PURPOSE:	to map the non-standard amino acids to something.
*/
int envFixIdx(idx)
int idx;
{
	if (idx == DEU)
		return(LEU);
	if ( (idx == NH2_RES) || (idx == ACE) || (idx == NA) )
		return(-1);
	else return(idx);

}	/* envFix */


/*********************************************************************
* PURPOSE:  to convert the integer residue number into a name
*/
char *get_coord_name(coord_idx)
int coord_idx;
{

	switch(coord_idx) {

	case H_COORD:  return("H  ");
	case N_COORD:  return("N  ");
	case NH1_COORD:  return("NH1");
	case NH2_COORD:  return("NH2");
	case NZ_COORD:  return("NZ");
	case NE_COORD:  return("NE");
	case NE1_COORD:  return("NE1");
	case NE2_COORD:  return("NE2");
	case ND1_COORD:  return("ND1");
	case ND2_COORD:  return("ND2");
	case O_COORD:  return("O");
	case OD1_COORD:  return("OD1");
	case OD2_COORD:  return("OD2");
	case OE1_COORD: return("OE1");
	case OE2_COORD: return("OE2");
	case OG_COORD: return("OG");
	case OG1_COORD: return("OG1");
	case OH_COORD: return("OH");
	case C_COORD: return("C");
	case CG_COORD: return("CG");
	case CD_COORD: return("CD");
	case SG_COORD: return("SG");
	case CZ_COORD: return("CZ");
	case CE_COORD: return("CE");
	case CB_COORD: return("CB");
	default: return("NA");

	}

}	/* get_coord_name */
