int CalcE12()
{
    int i,j,lj,lig[3],frag;
    float etot,emin;

    emin = 10000.0;
    frag = -1;

//    e12_calculated = 1;

    for (i=0; i < ntris; i++) {
	if (TriArr[i] != NULL) {
	   
	   TriArr[i]->done = 0;

	   etot = 0.0;

	   if (TriArr[i]->spec) {
		for (j=0; j < 2; j++) {
		   lj = TriArr[i]->lig[j];
 		   etot = etot + 
			CalInt(TriArr[i]->prot[j],lj,ligtyp[lj]->points,
				TriArr[i]->t,
				TriArr[i]->R1,TriArr[i]->R2,
				TriArr[i]->OutO,TriArr[i]->OutOrg,0);
		}
	   } else {
		for (j=0; j < 3; j++) {
		   lj = TriArr[i]->lig[j];
 		   etot = etot + 
			CalInt(TriArr[i]->prot[j],lj,ligtyp[lj]->points,
				TriArr[i]->t,
				TriArr[i]->R1,TriArr[i]->R2,
				TriArr[i]->OutO,TriArr[i]->OutOrg,0);
		}
	   }


	   TriArr[i]->e12 = etot;

	   if (etot < emin) {
		emin = etot;
		frag = TriArr[i]->frag;
		lig[0] = TriArr[i]->lig[0];
		lig[1] = TriArr[i]->lig[1];
		lig[2] = TriArr[i]->lig[2];
	   }

	}
    }
    return(frag);
}

