Beispiel #1
0
static void upd_nbfplj(FILE *log,real *nbfp,int atnr,real f6[],real f12[],
		       int combrule)
{
  double *sigma,*epsilon,c6,c12,eps,sig,sig6;
  int n,m,k;
  
  /* Update the nonbonded force parameters */
  switch (combrule) {
  case 1:
    for(k=n=0; (n<atnr); n++) {
      for(m=0; (m<atnr); m++,k++) {
	C6 (nbfp,atnr,n,m) *= f6[k];
	C12(nbfp,atnr,n,m) *= f12[k];
      }
    }
    break;
  case 2:
  case 3:
    /* Convert to sigma and epsilon */
    snew(sigma,atnr);
    snew(epsilon,atnr);
    for(n=0; (n<atnr); n++) {
      k = n*(atnr+1);
      c6  = C6 (nbfp,atnr,n,n) * f6[k];
      c12 = C12(nbfp,atnr,n,n) * f12[k];
      if ((c6 == 0) || (c12 == 0))
	gmx_fatal(FARGS,"You can not use combination rule %d with zero C6 (%f) or C12 (%f)",combrule,c6,c12);
      sigma[n]   = pow(c12/c6,1.0/6.0);
      epsilon[n] = 0.25*(c6*c6/c12);
    }
    for(k=n=0; (n<atnr); n++) {
      for(m=0; (m<atnr); m++,k++) {
	eps  = sqrt(epsilon[n]*epsilon[m]);
	if (combrule == 2)
	  sig  = 0.5*(sigma[n]+sigma[m]);
	else
	  sig  = sqrt(sigma[n]*sigma[m]);
	sig6 = pow(sig,6.0);
    /* nbfp now includes the 6.0/12.0 derivative prefactors */
	C6 (nbfp,atnr,n,m) = 4*eps*sig6/6.0;
	C12(nbfp,atnr,n,m) = 4*eps*sig6*sig6/12.0;
      }
    }
    sfree(sigma);
    sfree(epsilon);
    break;
  default:
    gmx_fatal(FARGS,"Combination rule should be 1,2 or 3 instead of %d",
	      combrule);
  }
}
Beispiel #2
0
static real *mk_nbfp(t_idef *idef,bool bBHAM)
{
  real *nbfp;
  int  i,j,k,atnr;
  
  atnr=idef->atnr;
  if (bBHAM) {
    snew(nbfp,3*atnr*atnr);
    for(i=k=0; (i<atnr); i++) {
      for(j=0; (j<atnr); j++,k++) {
	BHAMA(nbfp,atnr,i,j) = idef->iparams[k].bham.a;
	BHAMB(nbfp,atnr,i,j) = idef->iparams[k].bham.b;
	BHAMC(nbfp,atnr,i,j) = idef->iparams[k].bham.c;
      }
    }
  }
  else {
    snew(nbfp,2*atnr*atnr);
    for(i=k=0; (i<atnr); i++) {
      for(j=0; (j<atnr); j++,k++) {
	C6(nbfp,atnr,i,j)   = idef->iparams[k].lj.c6;
	C12(nbfp,atnr,i,j)  = idef->iparams[k].lj.c12;
      }
    }
  }
  return nbfp;
}
Beispiel #3
0
static double calc_avcsix(FILE *log,real *nbfp,int atnr,
			  int natoms,int type[],bool bBHAM)
{
  int    i,j,tpi,tpj;
  double csix;

  /* Check this code: do we really need a double loop? */  
  csix = 0;
  for(i=0; (i<natoms); i++) {
    tpi = type[i];
#ifdef DEBUG
    if (tpi >= atnr)
      fatal_error(0,"Atomtype[%d] = %d, maximum = %d",i,tpi,atnr);
#endif
    for(j=0; (j<natoms); j++) {
      tpj   = type[j];
#ifdef DEBUG
      if (tpj >= atnr)
	fatal_error(0,"Atomtype[%d] = %d, maximum = %d",j,tpj,atnr);
#endif
      if (bBHAM)
	csix += BHAMC(nbfp,atnr,tpi,tpj);
      else
	csix += C6(nbfp,atnr,tpi,tpj);
    }
  }
  csix /= (natoms*natoms);
  if (debug)
    fprintf(debug,"Average C6 parameter is: %10g\n",csix);
  
  return csix;
}
Beispiel #4
0
static void pr_nbfp(FILE *fp,real *nbfp,bool bBHAM,int atnr)
{
  int i,j;
  
    if(fp)
    {
        for(i=0; (i<atnr); i++) {
            for(j=0; (j<atnr); j++) {
                fprintf(fp,"%2d - %2d",i,j);
                if (bBHAM)
                    fprintf(fp,"  a=%10g, b=%10g, c=%10g\n",BHAMA(nbfp,atnr,i,j),
                            BHAMB(nbfp,atnr,i,j),BHAMC(nbfp,atnr,i,j));
                else
                    fprintf(fp,"  c6=%10g, c12=%10g\n",C6(nbfp,atnr,i,j),
                            C12(nbfp,atnr,i,j));
            }
        }
    }
}
Beispiel #5
0
void whirlpool_block(WHIRLPOOL_CTX *ctx,const void *inp,size_t n)
	{
	int	r;
	const u8 *p=inp;
	union	{ u64 q[8]; u8 c[64]; } S,K,*H=(void *)ctx->H.q;

#ifdef GO_FOR_MMX
	GO_FOR_MMX(ctx,inp,n);
#endif
							do {
#ifdef OPENSSL_SMALL_FOOTPRINT
	u64	L[8];
	int	i;

	for (i=0;i<64;i++)	S.c[i] = (K.c[i] = H->c[i]) ^ p[i];
	for (r=0;r<ROUNDS;r++)
		{
		for (i=0;i<8;i++)
			{
			L[i]  = i ? 0 : RC[r];
			L[i] ^=	C0(K,i)       ^ C1(K,(i-1)&7) ^
				C2(K,(i-2)&7) ^ C3(K,(i-3)&7) ^
				C4(K,(i-4)&7) ^ C5(K,(i-5)&7) ^
				C6(K,(i-6)&7) ^ C7(K,(i-7)&7);
			}
		memcpy (K.q,L,64);
		for (i=0;i<8;i++)
			{
			L[i] ^= C0(S,i)       ^ C1(S,(i-1)&7) ^
				C2(S,(i-2)&7) ^ C3(S,(i-3)&7) ^
				C4(S,(i-4)&7) ^ C5(S,(i-5)&7) ^
				C6(S,(i-6)&7) ^ C7(S,(i-7)&7);
			}
		memcpy (S.q,L,64);
		}
	for (i=0;i<64;i++)	H->c[i] ^= S.c[i] ^ p[i];
#else
	u64	L0,L1,L2,L3,L4,L5,L6,L7;

#ifdef __STRICT_ALIGNMENT
	if ((size_t)p & 7)
		{
		memcpy (S.c,p,64);
		S.q[0] ^= (K.q[0] = H->q[0]);
		S.q[1] ^= (K.q[1] = H->q[1]);
		S.q[2] ^= (K.q[2] = H->q[2]);
		S.q[3] ^= (K.q[3] = H->q[3]);
		S.q[4] ^= (K.q[4] = H->q[4]);
		S.q[5] ^= (K.q[5] = H->q[5]);
		S.q[6] ^= (K.q[6] = H->q[6]);
		S.q[7] ^= (K.q[7] = H->q[7]);
		}
	else
#endif
		{
		const u64 *pa = (const u64*)p;
		S.q[0] = (K.q[0] = H->q[0]) ^ pa[0];
		S.q[1] = (K.q[1] = H->q[1]) ^ pa[1];
		S.q[2] = (K.q[2] = H->q[2]) ^ pa[2];
		S.q[3] = (K.q[3] = H->q[3]) ^ pa[3];
		S.q[4] = (K.q[4] = H->q[4]) ^ pa[4];
		S.q[5] = (K.q[5] = H->q[5]) ^ pa[5];
		S.q[6] = (K.q[6] = H->q[6]) ^ pa[6];
		S.q[7] = (K.q[7] = H->q[7]) ^ pa[7];
		}

	for(r=0;r<ROUNDS;r++)
		{
#ifdef SMALL_REGISTER_BANK
		L0 =	C0(K,0) ^ C1(K,7) ^ C2(K,6) ^ C3(K,5) ^
			C4(K,4) ^ C5(K,3) ^ C6(K,2) ^ C7(K,1) ^ RC[r];
		L1 =	C0(K,1) ^ C1(K,0) ^ C2(K,7) ^ C3(K,6) ^
			C4(K,5) ^ C5(K,4) ^ C6(K,3) ^ C7(K,2);
		L2 =	C0(K,2) ^ C1(K,1) ^ C2(K,0) ^ C3(K,7) ^
			C4(K,6) ^ C5(K,5) ^ C6(K,4) ^ C7(K,3);
		L3 =	C0(K,3) ^ C1(K,2) ^ C2(K,1) ^ C3(K,0) ^
			C4(K,7) ^ C5(K,6) ^ C6(K,5) ^ C7(K,4);
		L4 =	C0(K,4) ^ C1(K,3) ^ C2(K,2) ^ C3(K,1) ^
			C4(K,0) ^ C5(K,7) ^ C6(K,6) ^ C7(K,5);
		L5 =	C0(K,5) ^ C1(K,4) ^ C2(K,3) ^ C3(K,2) ^
			C4(K,1) ^ C5(K,0) ^ C6(K,7) ^ C7(K,6);
		L6 =	C0(K,6) ^ C1(K,5) ^ C2(K,4) ^ C3(K,3) ^
			C4(K,2) ^ C5(K,1) ^ C6(K,0) ^ C7(K,7);
		L7 =	C0(K,7) ^ C1(K,6) ^ C2(K,5) ^ C3(K,4) ^
			C4(K,3) ^ C5(K,2) ^ C6(K,1) ^ C7(K,0);

		K.q[0] = L0; K.q[1] = L1; K.q[2] = L2; K.q[3] = L3;
		K.q[4] = L4; K.q[5] = L5; K.q[6] = L6; K.q[7] = L7;

		L0 ^=	C0(S,0) ^ C1(S,7) ^ C2(S,6) ^ C3(S,5) ^
			C4(S,4) ^ C5(S,3) ^ C6(S,2) ^ C7(S,1);
		L1 ^=	C0(S,1) ^ C1(S,0) ^ C2(S,7) ^ C3(S,6) ^
			C4(S,5) ^ C5(S,4) ^ C6(S,3) ^ C7(S,2);
		L2 ^=	C0(S,2) ^ C1(S,1) ^ C2(S,0) ^ C3(S,7) ^
			C4(S,6) ^ C5(S,5) ^ C6(S,4) ^ C7(S,3);
		L3 ^=	C0(S,3) ^ C1(S,2) ^ C2(S,1) ^ C3(S,0) ^
			C4(S,7) ^ C5(S,6) ^ C6(S,5) ^ C7(S,4);
		L4 ^=	C0(S,4) ^ C1(S,3) ^ C2(S,2) ^ C3(S,1) ^
			C4(S,0) ^ C5(S,7) ^ C6(S,6) ^ C7(S,5);
		L5 ^=	C0(S,5) ^ C1(S,4) ^ C2(S,3) ^ C3(S,2) ^
			C4(S,1) ^ C5(S,0) ^ C6(S,7) ^ C7(S,6);
		L6 ^=	C0(S,6) ^ C1(S,5) ^ C2(S,4) ^ C3(S,3) ^
			C4(S,2) ^ C5(S,1) ^ C6(S,0) ^ C7(S,7);
		L7 ^=	C0(S,7) ^ C1(S,6) ^ C2(S,5) ^ C3(S,4) ^
			C4(S,3) ^ C5(S,2) ^ C6(S,1) ^ C7(S,0);

		S.q[0] = L0; S.q[1] = L1; S.q[2] = L2; S.q[3] = L3;
		S.q[4] = L4; S.q[5] = L5; S.q[6] = L6; S.q[7] = L7;
#else
		L0  = C0(K,0); L1  = C1(K,0); L2  = C2(K,0); L3  = C3(K,0);
		L4  = C4(K,0); L5  = C5(K,0); L6  = C6(K,0); L7  = C7(K,0);
		L0 ^= RC[r];

		L1 ^= C0(K,1); L2 ^= C1(K,1); L3 ^= C2(K,1); L4 ^= C3(K,1);
		L5 ^= C4(K,1); L6 ^= C5(K,1); L7 ^= C6(K,1); L0 ^= C7(K,1);

		L2 ^= C0(K,2); L3 ^= C1(K,2); L4 ^= C2(K,2); L5 ^= C3(K,2);
		L6 ^= C4(K,2); L7 ^= C5(K,2); L0 ^= C6(K,2); L1 ^= C7(K,2);

		L3 ^= C0(K,3); L4 ^= C1(K,3); L5 ^= C2(K,3); L6 ^= C3(K,3);
		L7 ^= C4(K,3); L0 ^= C5(K,3); L1 ^= C6(K,3); L2 ^= C7(K,3);

		L4 ^= C0(K,4); L5 ^= C1(K,4); L6 ^= C2(K,4); L7 ^= C3(K,4);
		L0 ^= C4(K,4); L1 ^= C5(K,4); L2 ^= C6(K,4); L3 ^= C7(K,4);

		L5 ^= C0(K,5); L6 ^= C1(K,5); L7 ^= C2(K,5); L0 ^= C3(K,5);
		L1 ^= C4(K,5); L2 ^= C5(K,5); L3 ^= C6(K,5); L4 ^= C7(K,5);

		L6 ^= C0(K,6); L7 ^= C1(K,6); L0 ^= C2(K,6); L1 ^= C3(K,6);
		L2 ^= C4(K,6); L3 ^= C5(K,6); L4 ^= C6(K,6); L5 ^= C7(K,6);

		L7 ^= C0(K,7); L0 ^= C1(K,7); L1 ^= C2(K,7); L2 ^= C3(K,7);
		L3 ^= C4(K,7); L4 ^= C5(K,7); L5 ^= C6(K,7); L6 ^= C7(K,7);

		K.q[0] = L0; K.q[1] = L1; K.q[2] = L2; K.q[3] = L3;
		K.q[4] = L4; K.q[5] = L5; K.q[6] = L6; K.q[7] = L7;

		L0 ^= C0(S,0); L1 ^= C1(S,0); L2 ^= C2(S,0); L3 ^= C3(S,0);
		L4 ^= C4(S,0); L5 ^= C5(S,0); L6 ^= C6(S,0); L7 ^= C7(S,0);

		L1 ^= C0(S,1); L2 ^= C1(S,1); L3 ^= C2(S,1); L4 ^= C3(S,1);
		L5 ^= C4(S,1); L6 ^= C5(S,1); L7 ^= C6(S,1); L0 ^= C7(S,1);

		L2 ^= C0(S,2); L3 ^= C1(S,2); L4 ^= C2(S,2); L5 ^= C3(S,2);
		L6 ^= C4(S,2); L7 ^= C5(S,2); L0 ^= C6(S,2); L1 ^= C7(S,2);

		L3 ^= C0(S,3); L4 ^= C1(S,3); L5 ^= C2(S,3); L6 ^= C3(S,3);
		L7 ^= C4(S,3); L0 ^= C5(S,3); L1 ^= C6(S,3); L2 ^= C7(S,3);

		L4 ^= C0(S,4); L5 ^= C1(S,4); L6 ^= C2(S,4); L7 ^= C3(S,4);
		L0 ^= C4(S,4); L1 ^= C5(S,4); L2 ^= C6(S,4); L3 ^= C7(S,4);

		L5 ^= C0(S,5); L6 ^= C1(S,5); L7 ^= C2(S,5); L0 ^= C3(S,5);
		L1 ^= C4(S,5); L2 ^= C5(S,5); L3 ^= C6(S,5); L4 ^= C7(S,5);

		L6 ^= C0(S,6); L7 ^= C1(S,6); L0 ^= C2(S,6); L1 ^= C3(S,6);
		L2 ^= C4(S,6); L3 ^= C5(S,6); L4 ^= C6(S,6); L5 ^= C7(S,6);

		L7 ^= C0(S,7); L0 ^= C1(S,7); L1 ^= C2(S,7); L2 ^= C3(S,7);
		L3 ^= C4(S,7); L4 ^= C5(S,7); L5 ^= C6(S,7); L6 ^= C7(S,7);

		S.q[0] = L0; S.q[1] = L1; S.q[2] = L2; S.q[3] = L3;
		S.q[4] = L4; S.q[5] = L5; S.q[6] = L6; S.q[7] = L7;
#endif
		}

#ifdef __STRICT_ALIGNMENT
	if ((size_t)p & 7)
		{
		int i;
		for(i=0;i<64;i++)	H->c[i] ^= S.c[i] ^ p[i];
		}
	else
#endif
		{
		const u64 *pa=(const u64 *)p;
		H->q[0] ^= S.q[0] ^ pa[0];
		H->q[1] ^= S.q[1] ^ pa[1];
		H->q[2] ^= S.q[2] ^ pa[2];
		H->q[3] ^= S.q[3] ^ pa[3];
		H->q[4] ^= S.q[4] ^ pa[4];
		H->q[5] ^= S.q[5] ^ pa[5];
		H->q[6] ^= S.q[6] ^ pa[6];
		H->q[7] ^= S.q[7] ^ pa[7];
		}
#endif
							p += 64;
							} while(--n);
	}
Beispiel #6
0
void update_QMMMrec(t_commrec *cr,
		    t_forcerec *fr,
		    rvec x[],
		    t_mdatoms *md,
		    matrix box,
		    gmx_localtop_t *top)
{
  /* updates the coordinates of both QM atoms and MM atoms and stores
   * them in the QMMMrec.
   *
   * NOTE: is NOT yet working if there are no PBC. Also in ns.c, simple
   * ns needs to be fixed!
   */
  int
    mm_max=0,mm_nr=0,mm_nr_new,i,j,is,k,shift;
  t_j_particle
    *mm_j_particles=NULL,*qm_i_particles=NULL;
  t_QMMMrec
    *qr;
  t_nblist
    QMMMlist;
  rvec
    dx,crd;
  int
    *MMatoms;
  t_QMrec
    *qm;
  t_MMrec
    *mm;
  t_pbc
    pbc;
  int
    *parallelMMarray=NULL;
  real
    c12au,c6au;

  c6au  = (HARTREE2KJ*AVOGADRO*pow(BOHR2NM,6));
  c12au = (HARTREE2KJ*AVOGADRO*pow(BOHR2NM,12));

  /* every cpu has this array. On every processor we fill this array
   * with 1's and 0's. 1's indicate the atoms is a QM atom on the
   * current cpu in a later stage these arrays are all summed. indexes
   * > 0 indicate the atom is a QM atom. Every node therefore knows
   * whcih atoms are part of the QM subsystem.
   */
  /* copy some pointers */
  qr          = fr->qr;
  mm          = qr->mm;
  QMMMlist    = fr->QMMMlist;



  /*  init_pbc(box);  needs to be called first, see pbc.h */
  set_pbc_dd(&pbc,fr->ePBC,DOMAINDECOMP(cr) ? cr->dd : NULL,FALSE,box);
  /* only in standard (normal) QMMM we need the neighbouring MM
   * particles to provide a electric field of point charges for the QM
   * atoms.
   */
  if(qr->QMMMscheme==eQMMMschemenormal){ /* also implies 1 QM-layer */
    /* we NOW create/update a number of QMMMrec entries:
     *
     * 1) the shiftQM, containing the shifts of the QM atoms
     *
     * 2) the indexMM array, containing the index of the MM atoms
     *
     * 3) the shiftMM, containing the shifts of the MM atoms
     *
     * 4) the shifted coordinates of the MM atoms
     *
     * the shifts are used for computing virial of the QM/MM particles.
     */
    qm = qr->qm[0]; /* in case of normal QMMM, there is only one group */
    snew(qm_i_particles,QMMMlist.nri);
    if(QMMMlist.nri){
      qm_i_particles[0].shift = XYZ2IS(0,0,0);
      for(i=0;i<QMMMlist.nri;i++){
	qm_i_particles[i].j     = QMMMlist.iinr[i];

	if(i){
	  qm_i_particles[i].shift = pbc_dx_aiuc(&pbc,x[QMMMlist.iinr[0]],
						x[QMMMlist.iinr[i]],dx);

	}
	/* However, since nri >= nrQMatoms, we do a quicksort, and throw
	 * out double, triple, etc. entries later, as we do for the MM
	 * list too.
	 */

	/* compute the shift for the MM j-particles with respect to
	 * the QM i-particle and store them.
	 */

	crd[0] = IS2X(QMMMlist.shift[i]) + IS2X(qm_i_particles[i].shift);
	crd[1] = IS2Y(QMMMlist.shift[i]) + IS2Y(qm_i_particles[i].shift);
	crd[2] = IS2Z(QMMMlist.shift[i]) + IS2Z(qm_i_particles[i].shift);
	is = XYZ2IS(crd[0],crd[1],crd[2]);
	for(j=QMMMlist.jindex[i];
	    j<QMMMlist.jindex[i+1];
	    j++){
	  if(mm_nr >= mm_max){
	    mm_max += 1000;
	    srenew(mm_j_particles,mm_max);
	  }

	  mm_j_particles[mm_nr].j = QMMMlist.jjnr[j];
	  mm_j_particles[mm_nr].shift = is;
	  mm_nr++;
	}
      }

      /* quicksort QM and MM shift arrays and throw away multiple entries */



      qsort(qm_i_particles,QMMMlist.nri,
	    (size_t)sizeof(qm_i_particles[0]),
	    struct_comp);
      qsort(mm_j_particles,mm_nr,
	    (size_t)sizeof(mm_j_particles[0]),
	    struct_comp);
      /* remove multiples in the QM shift array, since in init_QMMM() we
       * went through the atom numbers from 0 to md.nr, the order sorted
       * here matches the one of QMindex already.
       */
      j=0;
      for(i=0;i<QMMMlist.nri;i++){
	if (i==0 || qm_i_particles[i].j!=qm_i_particles[i-1].j){
	  qm_i_particles[j++] = qm_i_particles[i];
	}
      }
      mm_nr_new = 0;
      if(qm->bTS||qm->bOPT){
	/* only remove double entries for the MM array */
	for(i=0;i<mm_nr;i++){
	  if((i==0 || mm_j_particles[i].j!=mm_j_particles[i-1].j)
	     && !md->bQM[mm_j_particles[i].j]){
	    mm_j_particles[mm_nr_new++] = mm_j_particles[i];
	  }
	}
      }
      /* we also remove mm atoms that have no charges!
      * actually this is already done in the ns.c
      */
      else{
	for(i=0;i<mm_nr;i++){
	  if((i==0 || mm_j_particles[i].j!=mm_j_particles[i-1].j)
	     && !md->bQM[mm_j_particles[i].j]
	     && (md->chargeA[mm_j_particles[i].j]
		 || (md->chargeB && md->chargeB[mm_j_particles[i].j]))) {
	    mm_j_particles[mm_nr_new++] = mm_j_particles[i];
	  }
	}
      }
      mm_nr = mm_nr_new;
      /* store the data retrieved above into the QMMMrec
       */
      k=0;
      /* Keep the compiler happy,
       * shift will always be set in the loop for i=0
       */
      shift = 0;
      for(i=0;i<qm->nrQMatoms;i++){
	/* not all qm particles might have appeared as i
	 * particles. They might have been part of the same charge
	 * group for instance.
	 */
	if (qm->indexQM[i] == qm_i_particles[k].j) {
	  shift = qm_i_particles[k++].shift;
	}
	/* use previous shift, assuming they belong the same charge
	 * group anyway,
	 */

	qm->shiftQM[i] = shift;
      }
    }
    /* parallel excecution */
    if(PAR(cr)){
      snew(parallelMMarray,2*(md->nr));
      /* only MM particles have a 1 at their atomnumber. The second part
       * of the array contains the shifts. Thus:
       * p[i]=1/0 depending on wether atomnumber i is a MM particle in the QM
       * step or not. p[i+md->nr] is the shift of atomnumber i.
       */
      for(i=0;i<2*(md->nr);i++){
	parallelMMarray[i]=0;
      }

      for(i=0;i<mm_nr;i++){
	parallelMMarray[mm_j_particles[i].j]=1;
	parallelMMarray[mm_j_particles[i].j+(md->nr)]=mm_j_particles[i].shift;
      }
      gmx_sumi(md->nr,parallelMMarray,cr);
      mm_nr=0;

      mm_max = 0;
      for(i=0;i<md->nr;i++){
	if(parallelMMarray[i]){
	  if(mm_nr >= mm_max){
	    mm_max += 1000;
	    srenew(mm->indexMM,mm_max);
	    srenew(mm->shiftMM,mm_max);
	  }
	  mm->indexMM[mm_nr]  = i;
	  mm->shiftMM[mm_nr++]= parallelMMarray[i+md->nr]/parallelMMarray[i];
	}
      }
      mm->nrMMatoms=mm_nr;
      free(parallelMMarray);
    }
    /* serial execution */
    else{
      mm->nrMMatoms = mm_nr;
      srenew(mm->shiftMM,mm_nr);
      srenew(mm->indexMM,mm_nr);
      for(i=0;i<mm_nr;i++){
	mm->indexMM[i]=mm_j_particles[i].j;
	mm->shiftMM[i]=mm_j_particles[i].shift;
      }

    }
    /* (re) allocate memory for the MM coordiate array. The QM
     * coordinate array was already allocated in init_QMMM, and is
     * only (re)filled in the update_QMMM_coordinates routine
     */
    srenew(mm->xMM,mm->nrMMatoms);
    /* now we (re) fill the array that contains the MM charges with
     * the forcefield charges. If requested, these charges will be
     * scaled by a factor
     */
    srenew(mm->MMcharges,mm->nrMMatoms);
    for(i=0;i<mm->nrMMatoms;i++){/* no free energy yet */
      mm->MMcharges[i]=md->chargeA[mm->indexMM[i]]*mm->scalefactor;
    }
    if(qm->bTS||qm->bOPT){
      /* store (copy) the c6 and c12 parameters into the MMrec struct
       */
      srenew(mm->c6,mm->nrMMatoms);
      srenew(mm->c12,mm->nrMMatoms);
      for (i=0;i<mm->nrMMatoms;i++){
	mm->c6[i]  = C6(fr->nbfp,top->idef.atnr,
			md->typeA[mm->indexMM[i]],
			md->typeA[mm->indexMM[i]])/c6au;
	mm->c12[i] =C12(fr->nbfp,top->idef.atnr,
			md->typeA[mm->indexMM[i]],
			md->typeA[mm->indexMM[i]])/c12au;
      }
      punch_QMMM_excl(qr->qm[0],mm,&(top->excls));
    }
    /* the next routine fills the coordinate fields in the QMMM rec of
     * both the qunatum atoms and the MM atoms, using the shifts
     * calculated above.
     */

    update_QMMM_coord(x,fr,qr->qm[0],qr->mm);
    free(qm_i_particles);
    free(mm_j_particles);
  }
  else { /* ONIOM */ /* ????? */
    mm->nrMMatoms=0;
    /* do for each layer */
    for (j=0;j<qr->nrQMlayers;j++){
      qm = qr->qm[j];
      qm->shiftQM[0]=XYZ2IS(0,0,0);
      for(i=1;i<qm->nrQMatoms;i++){
	qm->shiftQM[i] = pbc_dx_aiuc(&pbc,x[qm->indexQM[0]],x[qm->indexQM[i]],
				     dx);
      }
      update_QMMM_coord(x,fr,qm,mm);
    }
  }
} /* update_QMMM_rec */
Beispiel #7
0
void init_QMMMrec(t_commrec *cr,
		  matrix box,
		  gmx_mtop_t *mtop,
		  t_inputrec *ir,
		  t_forcerec *fr)
{
  /* we put the atomsnumbers of atoms that belong to the QMMM group in
   * an array that will be copied later to QMMMrec->indexQM[..]. Also
   * it will be used to create an QMMMrec->bQMMM index array that
   * simply contains true/false for QM and MM (the other) atoms.
   */

  gmx_groups_t *groups;
  atom_id   *qm_arr=NULL,vsite,ai,aj;
  int       qm_max=0,qm_nr=0,i,j,jmax,k,l,nrvsite2=0;
  t_QMMMrec *qr;
  t_MMrec   *mm;
  t_iatom   *iatoms;
  real      c12au,c6au;
  gmx_mtop_atomloop_all_t aloop;
  t_atom    *atom;
  gmx_mtop_ilistloop_all_t iloop;
  int       a_offset;
  t_ilist   *ilist_mol;

  c6au  = (HARTREE2KJ*AVOGADRO*pow(BOHR2NM,6));
  c12au = (HARTREE2KJ*AVOGADRO*pow(BOHR2NM,12));
  fprintf(stderr,"there we go!\n");

  /* Make a local copy of the QMMMrec */
  qr = fr->qr;

  /* bQMMM[..] is an array containing TRUE/FALSE for atoms that are
   * QM/not QM. We first set all elemenst at false. Afterwards we use
   * the qm_arr (=MMrec->indexQM) to changes the elements
   * corresponding to the QM atoms at TRUE.  */

  qr->QMMMscheme     = ir->QMMMscheme;

  /* we take the possibility into account that a user has
   * defined more than one QM group:
   */
  /* an ugly work-around in case there is only one group In this case
   * the whole system is treated as QM. Otherwise the second group is
   * always the rest of the total system and is treated as MM.
   */

  /* small problem if there is only QM.... so no MM */

  jmax = ir->opts.ngQM;

  if(qr->QMMMscheme==eQMMMschemeoniom)
    qr->nrQMlayers = jmax;
  else
    qr->nrQMlayers = 1;

  groups = &mtop->groups;

  /* there are jmax groups of QM atoms. In case of multiple QM groups
   * I assume that the users wants to do ONIOM. However, maybe it
   * should also be possible to define more than one QM subsystem with
   * independent neighbourlists. I have to think about
   * that.. 11-11-2003
   */
  snew(qr->qm,jmax);
  for(j=0;j<jmax;j++){
    /* new layer */
    aloop = gmx_mtop_atomloop_all_init(mtop);
    while (gmx_mtop_atomloop_all_next(aloop,&i,&atom)) {
      if(qm_nr >= qm_max){
	qm_max += 1000;
	srenew(qm_arr,qm_max);
      }
      if (ggrpnr(groups,egcQMMM ,i) == j) {
	/* hack for tip4p */
	qm_arr[qm_nr++] = i;
      }
    }
    if(qr->QMMMscheme==eQMMMschemeoniom){
      /* add the atoms to the bQMMM array
       */

      /* I assume that users specify the QM groups from small to
       * big(ger) in the mdp file
       */
      qr->qm[j] = mk_QMrec();
      /* we need to throw out link atoms that in the previous layer
       * existed to separate this QMlayer from the previous
       * QMlayer. We use the iatoms array in the idef for that
       * purpose. If all atoms defining the current Link Atom (Dummy2)
       * are part of the current QM layer it needs to be removed from
       * qm_arr[].  */

      iloop = gmx_mtop_ilistloop_all_init(mtop);
      while (gmx_mtop_ilistloop_all_next(iloop,&ilist_mol,&a_offset)) {
	nrvsite2 = ilist_mol[F_VSITE2].nr;
	iatoms   = ilist_mol[F_VSITE2].iatoms;

	for(k=0; k<nrvsite2; k+=4) {
	  vsite = a_offset + iatoms[k+1]; /* the vsite         */
	  ai    = a_offset + iatoms[k+2]; /* constructing atom */
	  aj    = a_offset + iatoms[k+3]; /* constructing atom */
	  if (ggrpnr(groups, egcQMMM, vsite) == ggrpnr(groups, egcQMMM, ai)
	      &&
	      ggrpnr(groups, egcQMMM, vsite) == ggrpnr(groups, egcQMMM, aj)) {
	    /* this dummy link atom needs to be removed from the qm_arr
	     * before making the QMrec of this layer!
	     */
	    for(i=0;i<qm_nr;i++){
	      if(qm_arr[i]==vsite){
		/* drop the element */
		for(l=i;l<qm_nr;l++){
		  qm_arr[l]=qm_arr[l+1];
		}
		qm_nr--;
	      }
	    }
	  }
	}
      }

      /* store QM atoms in this layer in the QMrec and initialise layer
       */
      init_QMrec(j,qr->qm[j],qm_nr,qm_arr,mtop,ir);

      /* we now store the LJ C6 and C12 parameters in QM rec in case
       * we need to do an optimization
       */
      if(qr->qm[j]->bOPT || qr->qm[j]->bTS){
	for(i=0;i<qm_nr;i++){
	  qr->qm[j]->c6[i]  =  C6(fr->nbfp,mtop->ffparams.atnr,
				  atom->type,atom->type)/c6au;
	  qr->qm[j]->c12[i] = C12(fr->nbfp,mtop->ffparams.atnr,
				  atom->type,atom->type)/c12au;
	}
      }
      /* now we check for frontier QM atoms. These occur in pairs that
       * construct the vsite
       */
      iloop = gmx_mtop_ilistloop_all_init(mtop);
      while (gmx_mtop_ilistloop_all_next(iloop,&ilist_mol,&a_offset)) {
	nrvsite2 = ilist_mol[F_VSITE2].nr;
	iatoms   = ilist_mol[F_VSITE2].iatoms;

	for(k=0; k<nrvsite2; k+=4){
	  vsite = a_offset + iatoms[k+1]; /* the vsite         */
	  ai    = a_offset + iatoms[k+2]; /* constructing atom */
	  aj    = a_offset + iatoms[k+3]; /* constructing atom */
	  if(ggrpnr(groups,egcQMMM,ai) < (groups->grps[egcQMMM].nr-1) &&
	     (ggrpnr(groups,egcQMMM,aj) >= (groups->grps[egcQMMM].nr-1))){
	      /* mark ai as frontier atom */
	    for(i=0;i<qm_nr;i++){
	      if( (qm_arr[i]==ai) || (qm_arr[i]==vsite) ){
		qr->qm[j]->frontatoms[i]=TRUE;
	      }
	    }
	  }
	  else if(ggrpnr(groups,egcQMMM,aj) < (groups->grps[egcQMMM].nr-1) &&
		  (ggrpnr(groups,egcQMMM,ai) >= (groups->grps[egcQMMM].nr-1))){
	    /* mark aj as frontier atom */
	    for(i=0;i<qm_nr;i++){
	      if( (qm_arr[i]==aj) || (qm_arr[i]==vsite)){
		qr->qm[j]->frontatoms[i]=TRUE;
	      }
	    }
	  }
	}
      }
    }
  }
  if(qr->QMMMscheme!=eQMMMschemeoniom){

    /* standard QMMM, all layers are merged together so there is one QM
     * subsystem and one MM subsystem.
     * Also we set the charges to zero in the md->charge arrays to prevent
     * the innerloops from doubly counting the electostatic QM MM interaction
     */
    for (k=0;k<qm_nr;k++){
      gmx_mtop_atomnr_to_atom(mtop,qm_arr[k],&atom);
      atom->q  = 0.0;
      atom->qB = 0.0;
    }
    qr->qm[0] = mk_QMrec();
    /* store QM atoms in the QMrec and initialise
     */
    init_QMrec(0,qr->qm[0],qm_nr,qm_arr,mtop,ir);
    if(qr->qm[0]->bOPT || qr->qm[0]->bTS){
      for(i=0;i<qm_nr;i++){
	gmx_mtop_atomnr_to_atom(mtop,qm_arr[i],&atom);
	qr->qm[0]->c6[i]  =  C6(fr->nbfp,mtop->ffparams.atnr,
				atom->type,atom->type)/c6au;
	qr->qm[0]->c12[i] = C12(fr->nbfp,mtop->ffparams.atnr,
				atom->type,atom->type)/c12au;
      }

    }



    /* find frontier atoms and mark them true in the frontieratoms array.
     */
    for(i=0;i<qm_nr;i++) {
      gmx_mtop_atomnr_to_ilist(mtop,qm_arr[i],&ilist_mol,&a_offset);
      nrvsite2 = ilist_mol[F_VSITE2].nr;
      iatoms   = ilist_mol[F_VSITE2].iatoms;

      for(k=0;k<nrvsite2;k+=4){
	vsite = a_offset + iatoms[k+1]; /* the vsite         */
	ai    = a_offset + iatoms[k+2]; /* constructing atom */
	aj    = a_offset + iatoms[k+3]; /* constructing atom */
	if(ggrpnr(groups,egcQMMM,ai) < (groups->grps[egcQMMM].nr-1) &&
	   (ggrpnr(groups,egcQMMM,aj) >= (groups->grps[egcQMMM].nr-1))){
	/* mark ai as frontier atom */
	  if ( (qm_arr[i]==ai) || (qm_arr[i]==vsite) ){
	    qr->qm[0]->frontatoms[i]=TRUE;
	  }
	}
	else if (ggrpnr(groups,egcQMMM,aj) < (groups->grps[egcQMMM].nr-1) &&
		 (ggrpnr(groups,egcQMMM,ai) >=(groups->grps[egcQMMM].nr-1))) {
	  /* mark aj as frontier atom */
	  if ( (qm_arr[i]==aj) || (qm_arr[i]==vsite) ){
	    qr->qm[0]->frontatoms[i]=TRUE;
	  }
	}
      }
    }

    /* MM rec creation */
    mm               = mk_MMrec();
    mm->scalefactor  = ir->scalefactor;
    mm->nrMMatoms    = (mtop->natoms)-(qr->qm[0]->nrQMatoms); /* rest of the atoms */
    qr->mm           = mm;
  } else {/* ONIOM */
    /* MM rec creation */
    mm               = mk_MMrec();
    mm->scalefactor  = ir->scalefactor;
    mm->nrMMatoms    = 0;
    qr->mm           = mm;
  }

  /* these variables get updated in the update QMMMrec */

  if(qr->nrQMlayers==1){
    /* with only one layer there is only one initialisation
     * needed. Multilayer is a bit more complicated as it requires
     * re-initialisation at every step of the simulation. This is due
     * to the use of COMMON blocks in the fortran QM subroutines.
     */
    if (qr->qm[0]->QMmethod<eQMmethodRHF)
    {
#ifdef GMX_QMMM_MOPAC
        /* semi-empiprical 1-layer ONIOM calculation requested (mopac93) */
        init_mopac(cr,qr->qm[0],qr->mm);
#else
        gmx_fatal(FARGS,"Semi-empirical QM only supported with Mopac.");
#endif
    }
    else
    {
        /* ab initio calculation requested (gamess/gaussian/ORCA) */
#ifdef GMX_QMMM_GAMESS
        init_gamess(cr,qr->qm[0],qr->mm);
#elif defined GMX_QMMM_GAUSSIAN
        init_gaussian(cr,qr->qm[0],qr->mm);
#elif defined GMX_QMMM_ORCA
        init_orca(cr,qr->qm[0],qr->mm);
#else
        gmx_fatal(FARGS,"Ab-initio calculation only supported with Gamess, Gaussian or ORCA.");
#endif
    }
  }
} /* init_QMMMrec */
Beispiel #8
0
void do_coupling(FILE *log,int nfile,t_filenm fnm[],
		 t_coupl_rec *tcr,real t,int step,real ener[],
		 t_forcerec *fr,t_inputrec *ir,bool bMaster,
		 t_mdatoms *md,t_idef *idef,real mu_aver,int nmols,
		 t_commrec *cr,matrix box,tensor virial,
		 tensor pres,rvec mu_tot,
		 rvec x[],rvec f[],bool bDoIt)
{
#define enm2Debye 48.0321
#define d2e(x) (x)/enm2Debye
#define enm2kjmol(x) (x)*0.0143952 /* = 2.0*4.0*M_PI*EPSILON0 */

  static real *f6,*f12,*fa,*fb,*fc,*fq;
  static bool bFirst = TRUE;
  
  int         i,j,ati,atj,atnr2,type,ftype;
  real        deviation[eoObsNR],prdev[eoObsNR],epot0,dist,rmsf;
  real        ff6,ff12,ffa,ffb,ffc,ffq,factor,dt,mu_ind;
  real        Epol,Eintern,Virial,muabs,xiH=-1,xiS=-1,xi6,xi12;
  rvec        fmol[2];
  bool        bTest,bPrint;
  t_coupl_LJ  *tclj;
  t_coupl_BU  *tcbu;
  t_coupl_Q   *tcq;
  t_coupl_iparams *tip;
  
  atnr2 = idef->atnr * idef->atnr;
  if (bFirst) {
    if (PAR(cr))
      fprintf(log,"GCT: this is parallel\n");
    else
      fprintf(log,"GCT: this is not parallel\n");
    fflush(log);
    snew(f6, atnr2);
    snew(f12,atnr2);
    snew(fa, atnr2);
    snew(fb, atnr2);
    snew(fc, atnr2);
    snew(fq, idef->atnr);
    
    if (tcr->bVirial) {
      int  nrdf = 0;
      real TTT  = 0;
      real Vol  = det(box);
      
      for(i=0; (i<ir->opts.ngtc); i++) {
	nrdf += ir->opts.nrdf[i];
	TTT  += ir->opts.nrdf[i]*ir->opts.ref_t[i];
      }
      TTT /= nrdf;
      
      /* Calculate reference virial from reference temperature and pressure */
      tcr->ref_value[eoVir] = 0.5*BOLTZ*nrdf*TTT - (3.0/2.0)*
	Vol*tcr->ref_value[eoPres];
      
      fprintf(log,"GCT: TTT = %g, nrdf = %d, vir0 = %g,  Vol = %g\n",
	      TTT,nrdf,tcr->ref_value[eoVir],Vol);
      fflush(log);
    }
    bFirst = FALSE;
  }
  
  bPrint = MASTER(cr) && do_per_step(step,ir->nstlog);
  dt     = ir->delta_t;

  /* Initiate coupling to the reference pressure and temperature to start
   * coupling slowly.
   */
  if (step == 0) {
    for(i=0; (i<eoObsNR); i++)
      tcr->av_value[i] = tcr->ref_value[i];
    if ((tcr->ref_value[eoDipole]) != 0.0) {
      mu_ind = mu_aver - d2e(tcr->ref_value[eoDipole]); /* in e nm */
      Epol   = mu_ind*mu_ind/(enm2kjmol(tcr->ref_value[eoPolarizability]));
      tcr->av_value[eoEpot] -= Epol;
      fprintf(log,"GCT: mu_aver = %g(D), mu_ind = %g(D), Epol = %g (kJ/mol)\n",
	      mu_aver*enm2Debye,mu_ind*enm2Debye,Epol);
    }
  }

  /* We want to optimize the LJ params, usually to the Vaporization energy 
   * therefore we only count intermolecular degrees of freedom.
   * Note that this is now optional. switch UseEinter to yes in your gct file
   * if you want this.
   */
  dist      = calc_dist(log,x);
  muabs     = norm(mu_tot);
  Eintern   = Ecouple(tcr,ener)/nmols;
  Virial    = virial[XX][XX]+virial[YY][YY]+virial[ZZ][ZZ];

  /*calc_force(md->nr,f,fmol);*/
  clear_rvec(fmol[0]);
  
  /* Use a memory of tcr->nmemory steps, so we actually couple to the
   * average observable over the last tcr->nmemory steps. This may help
   * in avoiding local minima in parameter space.
   */
  set_act_value(tcr,eoPres, ener[F_PRES],step);
  set_act_value(tcr,eoEpot, Eintern,     step);
  set_act_value(tcr,eoVir,  Virial,      step);
  set_act_value(tcr,eoDist, dist,        step);
  set_act_value(tcr,eoMu,   muabs,       step);
  set_act_value(tcr,eoFx,   fmol[0][XX], step);
  set_act_value(tcr,eoFy,   fmol[0][YY], step);
  set_act_value(tcr,eoFz,   fmol[0][ZZ], step);
  set_act_value(tcr,eoPx,   pres[XX][XX],step);
  set_act_value(tcr,eoPy,   pres[YY][YY],step);
  set_act_value(tcr,eoPz,   pres[ZZ][ZZ],step);
  
  epot0 = tcr->ref_value[eoEpot];
  /* If dipole != 0.0 assume we want to use polarization corrected coupling */
  if ((tcr->ref_value[eoDipole]) != 0.0) {
    mu_ind = mu_aver - d2e(tcr->ref_value[eoDipole]); /* in e nm */
    
    Epol = mu_ind*mu_ind/(enm2kjmol(tcr->ref_value[eoPolarizability]));
    
    epot0 -= Epol;
    if (debug) {
      fprintf(debug,"mu_ind: %g (%g D) mu_aver: %g (%g D)\n",
	      mu_ind,mu_ind*enm2Debye,mu_aver,mu_aver*enm2Debye);
      fprintf(debug,"Eref %g Epol %g Erunav %g Eact %g\n",
	      tcr->ref_value[eoEpot],Epol,tcr->av_value[eoEpot],
	      tcr->act_value[eoEpot]);
    }
  }

  if (bPrint) {
    pr_ff(tcr,t,idef,cr,nfile,fnm);
  }
  /* Calculate the deviation of average value from the target value */
  for(i=0; (i<eoObsNR); i++) {
    deviation[i] = calc_deviation(tcr->av_value[i],tcr->act_value[i],
				  tcr->ref_value[i]);
    prdev[i]     = tcr->ref_value[i] - tcr->act_value[i];
  }
  deviation[eoEpot] = calc_deviation(tcr->av_value[eoEpot],tcr->act_value[eoEpot],
				     epot0);
  prdev[eoEpot]     = epot0 - tcr->act_value[eoEpot];
  
  if (bPrint)
    pr_dev(tcr,t,prdev,cr,nfile,fnm);
  
  /* First set all factors to 1 */
  for(i=0; (i<atnr2); i++) {
    f6[i] = f12[i] = fa[i] = fb[i] = fc[i] = 1.0;
  }
  for(i=0; (i<idef->atnr); i++) 
    fq[i] = 1.0;

  /* Now compute the actual coupling compononents */   
  if (!fr->bBHAM) {
    if (bDoIt) {
      for(i=0; (i<tcr->nLJ); i++) {
	tclj=&(tcr->tcLJ[i]);
	
	ati=tclj->at_i;
	atj=tclj->at_j;
	
	ff6 = ff12 = 1.0;	
	
	if (tclj->eObs == eoForce) {
	  gmx_fatal(FARGS,"Hack code for this to work again ");
	  if (debug)
	    fprintf(debug,"Have computed derivatives: xiH = %g, xiS = %g\n",xiH,xiS);
	  if (ati == 1) {
	    /* Hydrogen */
	    ff12 += xiH; 
	  }
	  else if (ati == 2) {
	    /* Shell */
	    ff12 += xiS; 
	  }
	  else
	    gmx_fatal(FARGS,"No H, no Shell, edit code at %s, line %d\n",
			__FILE__,__LINE__);
	  if (ff6 > 0)
	    set_factor_matrix(idef->atnr,f6, sqrt(ff6), ati,atj);
	  if (ff12 > 0)
	    set_factor_matrix(idef->atnr,f12,sqrt(ff12),ati,atj);
	}
	else {
	  if (debug)
	    fprintf(debug,"tcr->tcLJ[%d].xi_6 = %g, xi_12 = %g deviation = %g\n",i,
		    tclj->xi_6,tclj->xi_12,deviation[tclj->eObs]);
	  factor=deviation[tclj->eObs];
	  
	  upd_f_value(log,idef->atnr,tclj->xi_6, dt,factor,f6, ati,atj);
	  upd_f_value(log,idef->atnr,tclj->xi_12,dt,factor,f12,ati,atj);
	}
      }
    }
    if (PAR(cr)) {
      gprod(cr,atnr2,f6);
      gprod(cr,atnr2,f12);
#ifdef DEBUGGCT
      dump_fm(log,idef->atnr,f6,"f6");
      dump_fm(log,idef->atnr,f12,"f12");
#endif
    }
    upd_nbfplj(log,fr->nbfp,idef->atnr,f6,f12,tcr->combrule);
    
    /* Copy for printing */
    for(i=0; (i<tcr->nLJ); i++) {
      tclj=&(tcr->tcLJ[i]);
      ati = tclj->at_i;
      atj = tclj->at_j;
      if (atj == -1) 
	atj = ati;
      tclj->c6  =  C6(fr->nbfp,fr->ntype,ati,atj);
      tclj->c12 = C12(fr->nbfp,fr->ntype,ati,atj);
    }
  }
  else {
    if (bDoIt) {
      for(i=0; (i<tcr->nBU); i++) {
	tcbu   = &(tcr->tcBU[i]);
	factor = deviation[tcbu->eObs];
	ati    = tcbu->at_i;
	atj    = tcbu->at_j;
	
	upd_f_value(log,idef->atnr,tcbu->xi_a,dt,factor,fa,ati,atj);
	upd_f_value(log,idef->atnr,tcbu->xi_b,dt,factor,fb,ati,atj);
	upd_f_value(log,idef->atnr,tcbu->xi_c,dt,factor,fc,ati,atj);
      }
    }
    if (PAR(cr)) {
      gprod(cr,atnr2,fa);
      gprod(cr,atnr2,fb);
      gprod(cr,atnr2,fc);
    }
    upd_nbfpbu(log,fr->nbfp,idef->atnr,fa,fb,fc);
    /* Copy for printing */
    for(i=0; (i<tcr->nBU); i++) {
      tcbu=&(tcr->tcBU[i]);
      ati = tcbu->at_i;
      atj = tcbu->at_j;
      if (atj == -1) 
	atj = ati;
      tcbu->a = BHAMA(fr->nbfp,fr->ntype,ati,atj);
      tcbu->b = BHAMB(fr->nbfp,fr->ntype,ati,atj);
      tcbu->c = BHAMC(fr->nbfp,fr->ntype,ati,atj);
      if (debug)
	fprintf(debug,"buck (type=%d) = %e, %e, %e\n",
		tcbu->at_i,tcbu->a,tcbu->b,tcbu->c);
    }
  }
  if (bDoIt) {
    for(i=0; (i<tcr->nQ); i++) {
      tcq=&(tcr->tcQ[i]);
      if (tcq->xi_Q)     
	ffq = 1.0 + (dt/tcq->xi_Q) * deviation[tcq->eObs];
      else
	ffq = 1.0;
      fq[tcq->at_i] *= ffq;
    }
  }
  if (PAR(cr))
    gprod(cr,idef->atnr,fq);
  
  for(j=0; (j<md->nr); j++) {
    md->chargeA[j] *= fq[md->typeA[j]];
  }
  for(i=0; (i<tcr->nQ); i++) {
    tcq=&(tcr->tcQ[i]);
    for(j=0; (j<md->nr); j++) {
      if (md->typeA[j] == tcq->at_i) {
	tcq->Q = md->chargeA[j];
	break;
      }
    }
    if (j == md->nr)
      gmx_fatal(FARGS,"Coupling type %d not found",tcq->at_i);
  }  
  for(i=0; (i<tcr->nIP); i++) {
    tip    = &(tcr->tIP[i]);
    type   = tip->type;
    ftype  = idef->functype[type];
    factor = dt*deviation[tip->eObs];
      
    switch(ftype) {
    case F_BONDS:
      if (tip->xi.harmonic.krA) idef->iparams[type].harmonic.krA *= (1+factor/tip->xi.harmonic.krA);
      if (tip->xi.harmonic.rA) idef->iparams[type].harmonic.rA *= (1+factor/tip->xi.harmonic.rA);
	break;
    default:
      break;
    }
    tip->iprint=idef->iparams[type];
  }
}
Beispiel #9
0
Molecule C6H6()
{
    int nAtoms = 12;

    // These are in Angstrom
    Eigen::Vector3d C1(5.274,  1.999, -8.568);
    Eigen::Vector3d C2(6.627,  2.018, -8.209);
    Eigen::Vector3d C3(7.366,  0.829, -8.202);
    Eigen::Vector3d C4(6.752, -0.379, -8.554);
    Eigen::Vector3d C5(5.399, -0.398, -8.912);
    Eigen::Vector3d C6(4.660,  0.791, -8.919);
    Eigen::Vector3d H1(4.704,  2.916, -8.573);
    Eigen::Vector3d H2(7.101,  2.950, -7.938);
    Eigen::Vector3d H3(8.410,  0.844, -7.926);
    Eigen::Vector3d H4(7.322, -1.296, -8.548);
    Eigen::Vector3d H5(4.925, -1.330, -9.183);
    Eigen::Vector3d H6(3.616,  0.776, -9.196);
    // Scale
    C1 /= convertBohrToAngstrom;
    C2 /= convertBohrToAngstrom;
    C3 /= convertBohrToAngstrom;
    C4 /= convertBohrToAngstrom;
    C5 /= convertBohrToAngstrom;
    C6 /= convertBohrToAngstrom;
    H1 /= convertBohrToAngstrom;
    H2 /= convertBohrToAngstrom;
    H3 /= convertBohrToAngstrom;
    H4 /= convertBohrToAngstrom;
    H5 /= convertBohrToAngstrom;
    H6 /= convertBohrToAngstrom;

    Eigen::MatrixXd geom(3, nAtoms);
    geom.col(0) = C1.transpose();
    geom.col(1) = C2.transpose();
    geom.col(2) = C3.transpose();
    geom.col(3) = C4.transpose();
    geom.col(4) = C5.transpose();
    geom.col(5) = C6.transpose();
    geom.col(6) = H1.transpose();
    geom.col(7) = H2.transpose();
    geom.col(8) = H3.transpose();
    geom.col(9) = H4.transpose();
    geom.col(10) = H5.transpose();
    geom.col(11) = H6.transpose();
    Eigen::VectorXd charges(12), masses(12);
    charges << 6.0, 6.0, 6.0, 6.0, 6.0, 6.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0;
    masses  << 12.00, 12.0, 12.0, 12.0, 12.0, 12.0, 1.0078250, 1.0078250, 1.0078250,
            1.0078250, 1.0078250, 1.0078250;

    double radiusC = 1.70 / convertBohrToAngstrom;
    double radiusH = 1.20 / convertBohrToAngstrom;
    std::vector<Atom> atoms;
    atoms.push_back( Atom("Carbon",   "C",  charges(0), masses(0), radiusC, C1, 1.0) );
    atoms.push_back( Atom("Carbon",   "C",  charges(1), masses(1), radiusC, C2, 1.0) );
    atoms.push_back( Atom("Carbon",   "C",  charges(2), masses(2), radiusC, C3, 1.0) );
    atoms.push_back( Atom("Carbon",   "C",  charges(3), masses(3), radiusC, C4, 1.0) );
    atoms.push_back( Atom("Carbon",   "C",  charges(4), masses(4), radiusC, C5, 1.0) );
    atoms.push_back( Atom("Carbon",   "C",  charges(5), masses(5), radiusC, C6, 1.0) );
    atoms.push_back( Atom("Hydrogen", "H",  charges(6), masses(6), radiusH, H1, 1.0) );
    atoms.push_back( Atom("Hydrogen", "H",  charges(7), masses(7), radiusH, H2, 1.0) );
    atoms.push_back( Atom("Hydrogen", "H",  charges(8), masses(8), radiusH, H3, 1.0) );
    atoms.push_back( Atom("Hydrogen", "H",  charges(9), masses(9), radiusH, H4, 1.0) );
    atoms.push_back( Atom("Hydrogen", "H", charges(10), masses(10), radiusH, H5, 1.0) );
    atoms.push_back( Atom("Hydrogen", "H", charges(11), masses(11), radiusH, H6, 1.0) );

    std::vector<Sphere> spheres;
    Sphere sph1(C1, radiusC);
    Sphere sph2(C2, radiusC);
    Sphere sph3(C3, radiusC);
    Sphere sph4(C4, radiusC);
    Sphere sph5(C5, radiusC);
    Sphere sph6(C6, radiusC);

    Sphere sph7(H1, radiusH);
    Sphere sph8(H2, radiusH);
    Sphere sph9(H3, radiusH);
    Sphere sph10(H4, radiusH);
    Sphere sph11(H5, radiusH);
    Sphere sph12(H6, radiusH);

    spheres.push_back(sph1);
    spheres.push_back(sph2);
    spheres.push_back(sph3);
    spheres.push_back(sph4);
    spheres.push_back(sph5);
    spheres.push_back(sph6);
    spheres.push_back(sph7);
    spheres.push_back(sph8);
    spheres.push_back(sph9);
    spheres.push_back(sph10);
    spheres.push_back(sph11);
    spheres.push_back(sph12);

    // D2h as generated by Oxy, Oxz, Oyz
    Symmetry pGroup = buildGroup(0, 0, 0, 0);

    return Molecule(nAtoms, charges, masses, geom, atoms, spheres, pGroup);
};
Beispiel #10
0
void do_glas(FILE *log,int start,int homenr,rvec x[],rvec f[],
	     t_forcerec *fr,t_mdatoms *md,int atnr,t_inputrec *ir,
	     real ener[])
{
  static bool   bFirst=TRUE,bGlas;
  static real   d[2],pi6,pi12,rc9,rc4,rc10,rc3,rc;
  static real   *c6,*c12;
  real wd,wdd,zi,fz,dd,d10,d4,d9,d3,r9,r3,sign,cc6,cc12;
  int  *type;
  int  i,j,ti;
  
  type=md->typeA;
  if (bFirst) {
    pi6  = ir->userreal1;
    pi12 = ir->userreal2;
    d[0] = ir->userreal3;
    d[1] = ir->userreal4;
    
    /* Check whether these constants have been set. */
    bGlas = (pi6 != 0) && (pi12 != 0) && (d[0] != 0) && (d[1] != 0);
    
    if (bGlas) {
      if (ir->eDispCorr != edispcNO) {
	gmx_fatal(FARGS,"Can not have Long Range C6 corrections and GLASMD");
      }
      rc   = max(fr->rvdw,fr->rlist);
      rc3  = rc*rc*rc;
      rc4  = rc3*rc;
      rc9  = rc3*rc3*rc3;
      rc10 = rc9*rc;
    
      fprintf(log,
	      "Constants for GLASMD: pi6 = %10g, pi12 = %10g\n"
	      "                      d1  = %10g, d2   = %10g\n"
	      "                      rc3 = %10g, rc4  = %10g\n"
	      "                      rc9 = %10g, rc10 = %10g\n",
	      pi6,pi12,d[0],d[1],rc3,rc4,rc9,rc10);
      if (d[0] > d[1])
	gmx_fatal(FARGS,"d1 > d2 for GLASMD (check log file)");
    
      snew(c6,atnr);
      snew(c12,atnr);
    
      for(i=0; (i<atnr); i++) {
	c6[i]  = C6 (fr->nbfp,atnr,i,i);
	c12[i] = C12(fr->nbfp,atnr,i,i);
      }
    }
    else
      fprintf(stderr,"No glasmd!\n");
    bFirst = FALSE;
  }
  
  if (bGlas) {
    wd=0;
    for(i=start; (i<start+homenr); i++) {
      ti   = type[i];
      if ((c6[ti] != 0) || (c12[ti] != 0)) {
	zi   = x[i][ZZ];
	cc6  = M_PI*sqrt(c6[ti]*pi6);
	cc12 = M_PI*sqrt(c12[ti]*pi12);
	
	/* Use a factor for the sign, this saves taking absolute values */
	sign = 1;
	for(j=0; (j<2); j++) {
	  dd = sign*(zi-d[j]);
	  if (dd >= rc) {
	    d3  = dd*dd*dd;
	    d9  = d3*d3*d3;
	    wdd = cc12/(45.0*d9) - cc6/(6.0*d3);
	    d4  = d3*dd;
	    d10 = d9*dd;
	    fz  = sign*(cc12/(5.0*d10) - cc6/(2.0*d4));
	  }
	  else {
	    wdd = cc12*(2.0/(9.0*rc9) - dd/(5.0*rc10)) -
	      cc6*(2.0/(3.0*rc3) - dd/(2.0*rc4));
	    fz  = sign*(cc12/(5.0*rc10)-cc6/(2.0*rc4));
	  }
	  wd       += wdd;
	  f[i][ZZ] += fz;
	  sign      = -sign;
	}
      }
    }
    ener[F_LJ_LR] = wd;
  }
}
Beispiel #11
0
static void update_ff(t_forcerec *fr,int nparm,t_range range[],int param_val[])
{
    static double *sigma=NULL,*eps=NULL,*c6=NULL,*cn=NULL,*bhama=NULL,*bhamb=NULL,*bhamc=NULL;
    real   val,*nbfp;
    int    i,j,atnr;

    atnr = fr->ntype;
    nbfp = fr->nbfp;

    if (fr->bBHAM) {
        if (bhama == NULL) {
            snew(bhama,atnr);
            snew(bhamb,atnr);
            snew(bhamc,atnr);
        }
    }
    else {
        if (sigma == NULL) {
            snew(sigma,atnr);
            snew(eps,atnr);
            snew(c6,atnr);
            snew(cn,atnr);
        }
    }
    /* Get current values for everything */
    for(i=0; (i<nparm); i++) {
        if (ga)
            val = range[i].rval;
        else
            val = value_range(&range[i],param_val[i]);
        if(debug)
            fprintf(debug,"val = %g\n",val);
        switch (range[i].ptype) {
        case eseSIGMA:
            sigma[range[i].atype] = val;
            break;
        case eseEPSILON:
            eps[range[i].atype] = val;
            break;
        case eseBHAMA:
            bhama[range[i].atype] = val;
            break;
        case eseBHAMB:
            bhamb[range[i].atype] = val;
            break;
        case eseBHAMC:
            bhamc[range[i].atype] = val;
            break;
        case eseCELLX:
            scale[XX] = val;
            break;
        case eseCELLY:
            scale[YY] = val;
            break;
        case eseCELLZ:
            scale[ZZ] = val;
            break;
        default:
            gmx_fatal(FARGS,"Unknown ptype");
        }
    }
    if (fr->bBHAM) {
        for(i=0; (i<atnr); i++) {
            for(j=0; (j<=i); j++) {
                BHAMA(nbfp,atnr,i,j) = BHAMA(nbfp,atnr,j,i) = sqrt(bhama[i]*bhama[j]);
                BHAMB(nbfp,atnr,i,j) = BHAMB(nbfp,atnr,j,i) = sqrt(bhamb[i]*bhamb[j]);
                BHAMC(nbfp,atnr,i,j) = BHAMC(nbfp,atnr,j,i) = sqrt(bhamc[i]*bhamc[j]);
            }
        }
    }
    else {
        /* Now build a new matrix */
        for(i=0; (i<atnr); i++) {
            c6[i] = 4*eps[i]*pow(sigma[i],6.0);
            cn[i] = 4*eps[i]*pow(sigma[i],ff.npow);
        }
        for(i=0; (i<atnr); i++) {
            for(j=0; (j<=i); j++) {
                C6(nbfp,atnr,i,j)  = C6(nbfp,atnr,j,i)  = sqrt(c6[i]*c6[j]);
                C12(nbfp,atnr,i,j) = C12(nbfp,atnr,j,i) = sqrt(cn[i]*cn[j]);
            }
        }
    }

    if (debug) {
        if (!fr->bBHAM)
            for(i=0; (i<atnr); i++)
                fprintf(debug,"atnr = %2d  sigma = %8.4f  eps = %8.4f\n",i,sigma[i],eps[i]);
        for(i=0; (i<atnr); i++) {
            for(j=0; (j<atnr); j++) {
                if (fr->bBHAM)
                    fprintf(debug,"i: %2d  j: %2d  A:  %10.5e  B:  %10.5e  C:  %10.5e\n",i,j,
                            BHAMA(nbfp,atnr,i,j),BHAMB(nbfp,atnr,i,j),BHAMC(nbfp,atnr,i,j));
                else
                    fprintf(debug,"i: %2d  j: %2d  c6:  %10.5e  cn:  %10.5e\n",i,j,
                            C6(nbfp,atnr,i,j),C12(nbfp,atnr,i,j));
            }
        }
    }
}
Beispiel #12
0
int multiple_detector_fit()
{

  std::cout << "Beginning : ... " << std::endl;

  Int_t npoints = 1000;
  Double_t emin = 0.2; 
  Double_t emax = 3.0;

  bool use100m = true;
  bool use470m = true;
  bool use600m = true;


  std::vector<int> baselines;
  std::vector<double> scales;
  std::vector<std::string> names;
  std::vector<double> volume;

  if (use100m) baselines.push_back(100);
  if (use470m) baselines.push_back(470);
  if (use600m) baselines.push_back(600);


  double NULLVec[2][20];
  double OscVec[2][1001][7][20];

  for(int i = 0; i < 20; i++){
    NULLVec[0][i] = 0;
    NULLVec[1][i] = 0;

  }

  for(int u = 0; u < 1000; u++){
    for(int s = 0; s < 7; s++){
      for(int i = 0; i < 20; i++){

	OscVec[0][u][s][i] = 0;
        OscVec[1][u][s][i] = 0;

      }
    }
  }


  int nbinsE = 0;


  if (use100m){

    std::string temp_name = /*"../MatrixFiles/combined_ntuple_100m_nu_processed_numu.root";*/"../MatrixFiles/combined_ntuple_100m_nu_processed_CoreyBins_numu.root";

    TFile temp_file(temp_name.c_str());
    TH1D *NULL_100;
    NULL_100 = (TH1D*)(temp_file.Get("NumuCC"));
    nbinsE = NULL_100->GetNbinsX();
    std::cout << nbinsE << std::endl;
      for(int i = 1; i <= nbinsE; i++){
	  NULLVec[0][i-1] = (NULL_100->GetBinContent(i));
      }

    for(int u = 0; u < npoints; u++){
      for(int s = 0; s < 7; s++){
	TH1D *OSC_100;
	TString upoint = Form("%d",u);
	TString name = "Universe_";
	TString name2 = "_MultiSim_";
	TString mul = Form("%d",s);
	
	name += upoint;
	name += name2;
	name += mul;	
       
	OSC_100 = (TH1D*)(temp_file.Get(name));
          for(int i = 1; i <= nbinsE; i++){
              OscVec[0][u][s][i-1] = (OSC_100->GetBinContent(i));
	      //	      if(OscVec[0][u][s][i-1] != OscVec[0][u][s][i-1]) std::cout << "erm" <<std::endl;

	  }

	delete OSC_100;
      }
    }
    
    delete NULL_100;
    temp_file.Close();
  }

  if (use470m){
    std::string temp_name = /*"../MatrixFiles/combined_ntuple_600m_onaxis_nu_processed_numu.root";*/"../MatrixFiles/combined_ntuple_600m_onaxis_nu_processed_CoreyBins_numu.root";

    TFile temp_file(temp_name.c_str());
    TH1D *NULL_470;
    NULL_470 = (TH1D*)(temp_file.Get("NumuCC"));
    nbinsE = NULL_470->GetNbinsX();
    std::cout << nbinsE<< std::endl;
      for(int i = 1; i <= nbinsE; i++){
	  NULLVec[1][i-1] = (NULL_470->GetBinContent(i));
      }

    for(int u = 0; u < npoints; u++){
      for(int s = 0; s < 7; s++){
	TH1D *OSC_470;
	TString upoint = Form("%d",u);//std::to_string(u);
	TString name = "Universe_";
	TString name2 = "_MultiSim_";
	TString mul = Form("%d",s);// = std::to_string(s);
	
	name += upoint;
	name += name2;
	name += mul;	
       
	OSC_470 = (TH1D*)(temp_file.Get(name));
          for(int i = 1; i <= nbinsE; i++){
	    OscVec[1][u][s][i-1] = (OSC_470->GetBinContent(i));
	    if(OscVec[1][u][s][i-1] != OscVec[1][u][s][i-1])  OscVec[1][u][s][i-1] = NULLVec[1][i-1];//std::cout << "erm, u :" << u << " s : " << s << " E : " << i  <<std::endl;

	  }

	delete OSC_470;
      }
    }
    
    delete NULL_470;
    temp_file.Close();
  }

  int nL = 2;
  int mbins = (nbinsE*nL);
 
  TMatrix M6 (mbins,mbins);
  TMatrix M5 (mbins,mbins);
  TMatrix M4 (mbins,mbins);
  TMatrix M3 (mbins,mbins);
  TMatrix M2 (mbins,mbins);
  TMatrix M1 (mbins,mbins);
  TMatrix M0 (mbins,mbins);
  
  TMatrix C6 (mbins,mbins);
  TMatrix C5 (mbins,mbins);
  TMatrix C4 (mbins,mbins);
  TMatrix C3 (mbins,mbins);
  TMatrix C2 (mbins,mbins);
  TMatrix C1 (mbins,mbins);
  TMatrix C0 (mbins,mbins);

  int N = 0;

  TH1D *Fig6 = new TH1D("Fig6",";;",mbins,0,mbins);
  TH1D *Fig5 = new TH1D("Fig5",";;",mbins,0,mbins);
  TH1D *Fig4 = new TH1D("Fig4",";;",mbins,0,mbins);
  TH1D *Fig3 = new TH1D("Fig3",";;",mbins,0,mbins);
  TH1D *Fig2 = new TH1D("Fig2",";;",mbins,0,mbins);
  TH1D *Fig1 = new TH1D("Fig1",";;",mbins,0,mbins);
  TH1D *Fig0 = new TH1D("Fig0",";;",mbins,0,mbins);

  int Erri = 0, Errj = 0;

  std::cout << "Filling Error Matrix..." << std::endl;

  for(int Lrow = 0; Lrow < 2; Lrow++){
    for(int Erow = 0; Erow < nbinsE; Erow++){

      Errj = 0;

      for(int Lcol = 0; Lcol < 2; Lcol++){
        for(int Ecol = 0; Ecol < nbinsE; Ecol++){

          M6 (Erri,Errj) = 0;
          M5 (Erri,Errj) = 0;
          M4 (Erri,Errj) = 0;
          M3 (Erri,Errj) = 0;
          M2 (Erri,Errj) = 0;
          M1 (Erri,Errj) = 0;
          M0 (Erri,Errj) = 0;

	  N = 0;

	  for(int u = 0; u < npoints; u++){

	    M6 (Erri,Errj) += (NULLVec[Lrow][Erow]-OscVec[Lrow][u][6][Erow])*(NULLVec[Lcol][Ecol]-OscVec[Lcol][u][6][Ecol]);
            M5 (Erri,Errj) += (NULLVec[Lrow][Erow]-OscVec[Lrow][u][5][Erow])*(NULLVec[Lcol][Ecol]-OscVec[Lcol][u][5][Ecol]);
            M4 (Erri,Errj) += (NULLVec[Lrow][Erow]-OscVec[Lrow][u][4][Erow])*(NULLVec[Lcol][Ecol]-OscVec[Lcol][u][4][Ecol]);
            M3 (Erri,Errj) += (NULLVec[Lrow][Erow]-OscVec[Lrow][u][3][Erow])*(NULLVec[Lcol][Ecol]-OscVec[Lcol][u][3][Ecol]);
            M2 (Erri,Errj) += (NULLVec[Lrow][Erow]-OscVec[Lrow][u][2][Erow])*(NULLVec[Lcol][Ecol]-OscVec[Lcol][u][2][Ecol]);
            M1 (Erri,Errj) += (NULLVec[Lrow][Erow]-OscVec[Lrow][u][1][Erow])*(NULLVec[Lcol][Ecol]-OscVec[Lcol][u][1][Ecol]);
            M0 (Erri,Errj) += (NULLVec[Lrow][Erow]-OscVec[Lrow][u][0][Erow])*(NULLVec[Lcol][Ecol]-OscVec[Lcol][u][0][Ecol]);

	    N++;
	    
	  }

	  M6 (Erri,Errj) /= N;
          M5 (Erri,Errj) /= N;
          M4 (Erri,Errj) /= N;
          M3 (Erri,Errj) /= N;
          M2 (Erri,Errj) /= N;
          M1 (Erri,Errj) /= N;
	  M0 (Erri,Errj) /= N;


	  
	  M6 (Erri,Errj) /= NULLVec[Lrow][Erow]*NULLVec[Lcol][Ecol];
          M5 (Erri,Errj) /= NULLVec[Lrow][Erow]*NULLVec[Lcol][Ecol];
          M4 (Erri,Errj) /= NULLVec[Lrow][Erow]*NULLVec[Lcol][Ecol];
          M3 (Erri,Errj) /= NULLVec[Lrow][Erow]*NULLVec[Lcol][Ecol];
          M2 (Erri,Errj) /= NULLVec[Lrow][Erow]*NULLVec[Lcol][Ecol];
          M1 (Erri,Errj) /= NULLVec[Lrow][Erow]*NULLVec[Lcol][Ecol];
          M0 (Erri,Errj) /= NULLVec[Lrow][Erow]*NULLVec[Lcol][Ecol];
	  
	  if(Erri == Errj) Fig6->SetBinContent(Erri+1, sqrt(M6 (Erri,Errj)));
      if(Erri == Errj) Fig5->SetBinContent(Erri+1, sqrt(M5 (Erri,Errj)));
      if(Erri == Errj) Fig4->SetBinContent(Erri+1, sqrt(M4 (Erri,Errj)));
      if(Erri == Errj) Fig3->SetBinContent(Erri+1, sqrt(M3 (Erri,Errj)));
      if(Erri == Errj) Fig2->SetBinContent(Erri+1, sqrt(M2 (Erri,Errj)));
      if(Erri == Errj) Fig1->SetBinContent(Erri+1, sqrt(M1 (Erri,Errj)));
      if(Erri == Errj) Fig0->SetBinContent(Erri+1, sqrt(M0 (Erri,Errj)));

      std::cout << M6 (Erri,Errj) << "\t";

          Errj++;

	}}

      Erri++;

    }}

  for(int i = 0; i < Erri; i++){
    for(int j = 0; j < Errj; j++){

      C6 (i,j) = M6(i,j) / sqrt(M6 (i,i) * M6 (j,j));
      C5 (i,j) = M5(i,j) / sqrt(M5 (i,i) * M5 (j,j));
      C4 (i,j) = M4(i,j) / sqrt(M4 (i,i) * M4 (j,j));
      C3 (i,j) = M3(i,j) / sqrt(M3 (i,i) * M3 (j,j));
      C2 (i,j) = M2(i,j) / sqrt(M2 (i,i) * M2 (j,j));
      C1 (i,j) = M1(i,j) / sqrt(M1 (i,i) * M1 (j,j));
      C0 (i,j) = M0(i,j) / sqrt(M0 (i,i) * M0 (j,j));

    }
  }
  
  std::cout << "...Error Matrix Filled" << std::endl;


  TCanvas* c6 = new TCanvas("c6","",700,700);
  c6->SetLeftMargin(.1);
  c6->SetBottomMargin(.1);
  c6->SetTopMargin(.075);
  c6->SetRightMargin(.15);
  c6->cd();

  M6.Draw("COLZ");
  gStyle->SetPalette(56,0);
  TMatrixFBase->SetContour(999);
  //  TMatrixFBase->GetZaxis()->SetRangeUser(-0.05,0.4);
  TMatrixFBase->GetZaxis()->SetTitleFont(62);
  TMatrixFBase->GetZaxis()->SetLabelFont(62);
  TMatrixFBase->GetZaxis()->SetTitleSize(0.045);
  //  TMatrixFBase->GetZaxis()->SetTitle("Fractional Error Matrix");
  TMatrixFBase->GetZaxis()->SetTitleOffset(1.5);
  TMatrixFBase->GetXaxis()->SetTitle("");
  TMatrixFBase->GetXaxis()->SetLabelSize(0);
  TMatrixFBase->GetXaxis()->SetTitleOffset(1.5);
  TMatrixFBase->GetYaxis()->SetTitle("");
  TMatrixFBase->GetYaxis()->SetTitleOffset(1.5);
  TMatrixFBase->GetYaxis()->SetLabelSize(0);
  TMatrixFBase->SetStats(0);

  TLine *split = new TLine();
  split->SetLineStyle(2);
  split->SetLineWidth(5);
  split->SetLineColor(kBlue);
  split->DrawLineNDC(.1,.51,.849,.51);
  split->DrawLineNDC(.475,.101,.475,.930);
  add_plot_label("|            0.2 #minus 3.0 GeV            |            0.2 #minus 3.0 GeV            | ", 0.48,0.08,0.03);



  TLatex *ND = new TLatex(.15,.01,"LAr1-ND (100m) ");
  ND->SetNDC();
  ND->SetTextFont(62);
  ND->SetTextSize(0.04);
  ND->Draw();

  TLatex *MD = new TLatex(.5,.01,"T600 (600m, on axis)");
  MD->SetNDC();
  MD->SetTextFont(62);
  MD->SetTextSize(0.04);
  MD->Draw();

  TLatex *ND45 = new TLatex(.05,.15,"LAr1-ND (100m) ");
  ND45->SetNDC();
  ND45->SetTextAngle(90);
  ND45->SetTextFont(62);
  ND45->SetTextSize(0.04);
  ND45->Draw();

  TLatex *MD45 = new TLatex(.05,.54,"T600 (600m, on axis)");
  MD45->SetNDC();
  MD45->SetTextAngle(90);
  MD45->SetTextFont(62);
  MD45->SetTextSize(0.04);
  MD45->Draw();

  TLatex *Total = new TLatex(.2,.96,"#nu#lower[0.3]{#mu} Flux Fractional Error Matrix");
  Total->SetNDC();
  Total->SetTextFont(62);
  Total->SetTextSize(0.045);
  Total->Draw();

  //  c6->Print("total_matrix.pdf");



  TCanvas* c61 = new TCanvas("c61","",700,700);
  c61->SetLeftMargin(.1);
  c61->SetBottomMargin(.1);
  c61->SetTopMargin(.075);
  c61->SetRightMargin(.15);
  c61->cd();

  C6.Draw("COLZ");
  gStyle->SetPalette(56,0);
  TMatrixFBase->SetContour(999);
  TMatrixFBase->GetZaxis()->SetTitleFont(62);
  TMatrixFBase->GetZaxis()->SetLabelFont(62);
  TMatrixFBase->GetZaxis()->SetTitleSize(0.045);
  TMatrixFBase->GetZaxis()->SetTitleOffset(1.5);
  TMatrixFBase->GetXaxis()->SetTitle("");
  TMatrixFBase->GetXaxis()->SetLabelSize(0);
  TMatrixFBase->GetXaxis()->SetTitleOffset(1.5);
  TMatrixFBase->GetYaxis()->SetTitle("");
  TMatrixFBase->GetYaxis()->SetTitleOffset(1.5);
  TMatrixFBase->GetYaxis()->SetLabelSize(0);
  TMatrixFBase->SetStats(0);
  TLine *split = new TLine();
  split->SetLineStyle(2);
  split->SetLineWidth(5);
  split->SetLineColor(kYellow);
  split->DrawLineNDC(.1,.51,.849,.51);
  split->DrawLineNDC(.475,.101,.475,.930);
  add_plot_label("|            0.2 #minus 3.0 GeV            |            0.2 #minus 3.0 GeV            | ", 0.48,0.08,0.03);


  ND->Draw();
  MD->Draw();
  ND45->Draw();
  MD45->Draw();

  TLatex *Total = new TLatex(.2,.96,"#nu#lower[0.3]{#mu} Flux Correlation Matrix");
  Total->SetNDC();
  Total->SetTextFont(62);
  Total->SetTextSize(0.045);
  Total->Draw();

  //  c61->Print("total_correlation_matrix.pdf");

 

  TCanvas* c5 = new TCanvas("c5","",700,700);
  c5->SetLeftMargin(.1);
  c5->SetBottomMargin(.1);
  c5->SetTopMargin(.075);
  c5->SetRightMargin(.15);
  c5->cd();

  M5.Draw("COLZ");
  gStyle->SetPalette(56,0);
  TMatrixFBase->SetContour(999);
  //TMatrixFBase->GetZaxis()->SetRangeUser(-0.005,0.045);
  
TMatrixFBase->GetZaxis()->SetTitleFont(62);
  TMatrixFBase->GetZaxis()->SetLabelFont(62);
  TMatrixFBase->GetZaxis()->SetTitleSize(0.045);
  //  TMatrixFBase->GetZaxis()->SetTitle("K^{+} Covariance Matrix");
  TMatrixFBase->GetZaxis()->SetTitleOffset(1.5);
  TMatrixFBase->GetXaxis()->SetTitle("");
  TMatrixFBase->GetXaxis()->SetLabelSize(0);
  TMatrixFBase->GetXaxis()->SetTitleOffset(1.5);
  TMatrixFBase->GetYaxis()->SetTitle("");
  TMatrixFBase->GetYaxis()->SetTitleOffset(1.5);
  TMatrixFBase->GetYaxis()->SetLabelSize(0);
  TMatrixFBase->SetStats(0);

  TLine *split = new TLine();
  split->SetLineStyle(2);
  split->SetLineWidth(5);
  split->SetLineColor(kBlue);
  split->DrawLineNDC(.1,.51,.849,.51);
  split->DrawLineNDC(.475,.101,.475,.930);
  add_plot_label("|            0.2 #minus 3.0 GeV            |            0.2 #minus 3.0 GeV            | ", 0.48,0.08,0.03);

  TLatex *Total = new TLatex(.2,.96,"#nu#lower[0.3]{#mu} K#lower[-0.15]{+} Fractional Error Matrix");
  Total->SetNDC();
  Total->SetTextFont(62);
  Total->SetTextSize(0.045);
  Total->Draw();




  ND->Draw();
  MD->Draw();
  ND45->Draw();
  MD45->Draw();

  //  c5->Print("mult5_matrix.pdf");

  TCanvas* c51 = new TCanvas("c51","",700,700);
  c51->SetLeftMargin(.1);
  c51->SetBottomMargin(.1);
  c51->SetTopMargin(.075);
  c51->SetRightMargin(.15);
  c51->cd();

  C5.Draw("COLZ");
  gStyle->SetPalette(56,0);
  TMatrixFBase->SetContour(999);
  //TMatrixFBase->GetZaxis()->SetRangeUser(-1,1);
  TMatrixFBase->GetZaxis()->SetTitleFont(62);
  TMatrixFBase->GetZaxis()->SetLabelFont(62);
  TMatrixFBase->GetZaxis()->SetTitleSize(0.045);
  //  TMatrixFBase->GetZaxis()->SetTitle("K#lower[-0.15]{+} Correlation Matrix");
  TMatrixFBase->GetZaxis()->SetTitleOffset(1.5);
  TMatrixFBase->GetXaxis()->SetTitle("");
  TMatrixFBase->GetXaxis()->SetLabelSize(0);
  TMatrixFBase->GetXaxis()->SetTitleOffset(1.5);
  TMatrixFBase->GetYaxis()->SetTitle("");
  TMatrixFBase->GetYaxis()->SetTitleOffset(1.5);
  TMatrixFBase->GetYaxis()->SetLabelSize(0);
  TMatrixFBase->SetStats(0);

  TLine *split = new TLine();
  split->SetLineStyle(2);
  split->SetLineWidth(5);
  split->SetLineColor(kYellow);
  split->DrawLineNDC(.1,.51,.849,.51);
  split->DrawLineNDC(.475,.101,.475,.930);
  add_plot_label("|            0.2 #minus 3.0 GeV            |            0.2 #minus 3.0 GeV            | ", 0.48,0.08,0.03);

  TLatex *Total = new TLatex(.2,.96,"#nu#lower[0.3]{#mu} K#lower[-0.15]{+} Correlation Matrix");
  Total->SetNDC();
  Total->SetTextFont(62);
  Total->SetTextSize(0.045);
  Total->Draw();



  ND->Draw();
  MD->Draw();
  ND45->Draw();
  MD45->Draw();

  //  c51->Print("mult5_correlation_matrix.pdf");

  TCanvas* c4 = new TCanvas("c4","",700,700);
  c4->SetLeftMargin(.1);
  c4->SetBottomMargin(.1);
  c4->SetTopMargin(.075);
  c4->SetRightMargin(.15);
  c4->cd();

  M4.Draw("COLZ");
  gStyle->SetPalette(56,0);
  TMatrixFBase->SetContour(999);
  //TMatrixFBase->GetZaxis()->SetRangeUser(-0.005,0.045);
  TMatrixFBase->GetZaxis()->SetTitleFont(62);
  TMatrixFBase->GetZaxis()->SetLabelFont(62);
  TMatrixFBase->GetZaxis()->SetTitleSize(0.045);
  //TMatrixFBase->GetZaxis()->SetTitle("K#lower[-0.15]{-} Covariance Matrix");
  TMatrixFBase->GetZaxis()->SetTitleOffset(1.5);
  TMatrixFBase->GetXaxis()->SetTitle("");
  TMatrixFBase->GetXaxis()->SetLabelSize(0);
  TMatrixFBase->GetXaxis()->SetTitleOffset(1.5);
  TMatrixFBase->GetYaxis()->SetTitle("");
  TMatrixFBase->GetYaxis()->SetTitleOffset(1.5);
  TMatrixFBase->GetYaxis()->SetLabelSize(0);
  TMatrixFBase->SetStats(0);

  TLine *split = new TLine();
  split->SetLineStyle(2);
  split->SetLineWidth(5);
  split->SetLineColor(kBlue);
  split->DrawLineNDC(.1,.51,.849,.51);
  split->DrawLineNDC(.475,.101,.475,.930);
  add_plot_label("|            0.2 #minus 3.0 GeV            |            0.2 #minus 3.0 GeV            | ", 0.48,0.08,0.03);

  TLatex *Total = new TLatex(.2,.96,"#nu#lower[0.3]{#mu} K#lower[-0.15]{-} Fractional Error Matrix");
  Total->SetNDC();
  Total->SetTextFont(62);
  Total->SetTextSize(0.045);
  Total->Draw();



  ND->Draw();
  MD->Draw();
  ND45->Draw();
  MD45->Draw();


  //  c4->Print("mult4_matrix.pdf");

  TCanvas* c41 = new TCanvas("c41","",700,700);
  c41->SetLeftMargin(.1);
  c41->SetBottomMargin(.1);
  c41->SetTopMargin(.075);
  c41->SetRightMargin(.15);
  c41->cd();

  C4.Draw("COLZ");
  gStyle->SetPalette(56,0);
  TMatrixFBase->SetContour(999);
  //TMatrixFBase->GetZaxis()->SetRangeUser(-1,1);

  TMatrixFBase->GetZaxis()->SetTitleFont(62);
  TMatrixFBase->GetZaxis()->SetLabelFont(62);
  TMatrixFBase->GetZaxis()->SetTitleSize(0.045);
  //  TMatrixFBase->GetZaxis()->SetTitle("K#lower[-0.15]{-} Correlation Matrix");
  TMatrixFBase->GetZaxis()->SetTitleOffset(1.5);
  TMatrixFBase->GetXaxis()->SetTitle("");
  TMatrixFBase->GetXaxis()->SetLabelSize(0);
  TMatrixFBase->GetXaxis()->SetTitleOffset(1.5);
  TMatrixFBase->GetYaxis()->SetTitle("");
  TMatrixFBase->GetYaxis()->SetTitleOffset(1.5);
  TMatrixFBase->GetYaxis()->SetLabelSize(0);
  TMatrixFBase->SetStats(0);

  TLine *split = new TLine();
  split->SetLineStyle(2);
  split->SetLineWidth(5);
  split->SetLineColor(kYellow);
  split->DrawLineNDC(.1,.51,.849,.51);
  split->DrawLineNDC(.475,.101,.475,.930);
  add_plot_label("|            0.2 #minus 3.0 GeV            |            0.2 #minus 3.0 GeV            | ", 0.48,0.08,0.03);

  TLatex *Total = new TLatex(.2,.96,"#nu#lower[0.3]{#mu} K#lower[-0.15]{-} Correlation Matrix");
  Total->SetNDC();
  Total->SetTextFont(62);
  Total->SetTextSize(0.045);
  Total->Draw();

  ND->Draw();
  MD->Draw();
  ND45->Draw();
  MD45->Draw();


  //  c41->Print("mult4_correlation_matrix.pdf");



  TCanvas* c3 = new TCanvas("c3","",700,700);
  c3->SetLeftMargin(.1);
  c3->SetBottomMargin(.1);
  c3->SetTopMargin(.075);
  c3->SetRightMargin(.15);
  c3->cd();

  M3.Draw("COLZ");
  gStyle->SetPalette(56,0);
  TMatrixFBase->SetContour(999);
  //TMatrixFBase->GetZaxis()->SetRangeUser(-0.005,0.045);

  TMatrixFBase->GetZaxis()->SetTitleFont(62);
  TMatrixFBase->GetZaxis()->SetLabelFont(62);
  TMatrixFBase->GetZaxis()->SetTitleSize(0.045);
  //TMatrixFBase->GetZaxis()->SetTitle("K#lower[-0.15]{0} Covariance Matrix");
  TMatrixFBase->GetZaxis()->SetTitleOffset(1.5);
  TMatrixFBase->GetXaxis()->SetTitle("");
  TMatrixFBase->GetXaxis()->SetLabelSize(0);
  TMatrixFBase->GetXaxis()->SetTitleOffset(1.5);
  TMatrixFBase->GetYaxis()->SetTitle("");
  TMatrixFBase->GetYaxis()->SetTitleOffset(1.5);
  TMatrixFBase->GetYaxis()->SetLabelSize(0);
  TMatrixFBase->SetStats(0);

  TLine *split = new TLine();
  split->SetLineStyle(2);
  split->SetLineWidth(5);
  split->SetLineColor(kBlue);
  split->DrawLineNDC(.1,.51,.849,.51);
  split->DrawLineNDC(.475,.101,.475,.930);
  add_plot_label("|            0.2 #minus 3.0 GeV            |            0.2 #minus 3.0 GeV            | ", 0.48,0.08,0.03);

  TLatex *Total = new TLatex(.2,.96,"#nu#lower[0.3]{#mu} K#lower[-0.15]{0} Fractional Error Matrix");
  Total->SetNDC();
  Total->SetTextFont(62);
  Total->SetTextSize(0.045);
  Total->Draw();


  ND->Draw();
  MD->Draw();
  ND45->Draw();
  MD45->Draw();


  //  c3->Print("mult3_matrix.pdf");

  TCanvas* c31 = new TCanvas("c31","",700,700);
  c31->SetLeftMargin(.1);
  c31->SetBottomMargin(.1);
  c31->SetTopMargin(.075);
  c31->SetRightMargin(.15);
  c31->cd();

  C3.Draw("COLZ");
  gStyle->SetPalette(56,0);
  TMatrixFBase->SetContour(999);
  //TMatrixFBase->GetZaxis()->SetRangeUser(-1,1);

  TMatrixFBase->GetZaxis()->SetTitleFont(62);
  TMatrixFBase->GetZaxis()->SetLabelFont(62);
  TMatrixFBase->GetZaxis()->SetTitleSize(0.045);
  //TMatrixFBase->GetZaxis()->SetTitle("K#lower[-0.15]{0} Correlation Matrix");
  TMatrixFBase->GetZaxis()->SetTitleOffset(1.5);
  TMatrixFBase->GetXaxis()->SetTitle("");
  TMatrixFBase->GetXaxis()->SetLabelSize(0);
  TMatrixFBase->GetXaxis()->SetTitleOffset(1.5);
  TMatrixFBase->GetYaxis()->SetTitle("");
  TMatrixFBase->GetYaxis()->SetTitleOffset(1.5);
  TMatrixFBase->GetYaxis()->SetLabelSize(0);
  TMatrixFBase->SetStats(0);

  TLine *split = new TLine();
  split->SetLineStyle(2);
  split->SetLineWidth(5);
  split->SetLineColor(kYellow);
  split->DrawLineNDC(.1,.51,.849,.51);
  split->DrawLineNDC(.475,.101,.475,.930);
  add_plot_label("|            0.2 #minus 3.0 GeV            |            0.2 #minus 3.0 GeV            | ", 0.48,0.08,0.03);

  TLatex *Total = new TLatex(.2,.96,"#nu#lower[0.3]{#mu} K#lower[-0.15]{0} Correlation Matrix");
  Total->SetNDC();
  Total->SetTextFont(62);
  Total->SetTextSize(0.045);
  Total->Draw();



  ND->Draw();
  MD->Draw();
  ND45->Draw();
  MD45->Draw();


  //  c31->Print("mult3_correlation_matrix.pdf");


  TCanvas* c2 = new TCanvas("c2","",700,700);
  c2->SetLeftMargin(.1);
  c2->SetBottomMargin(.1);
  c2->SetTopMargin(.075);
  c2->SetRightMargin(.15);
  c2->cd();

  M2.Draw("COLZ");
  gStyle->SetPalette(56,0);
  //TMatrixFBase->GetZaxis()->SetRangeUser(-0.005,0.045);
  TMatrixFBase->SetContour(999);
  TMatrixFBase->GetZaxis()->SetTitleFont(62);
  TMatrixFBase->GetZaxis()->SetLabelFont(62);
  TMatrixFBase->GetZaxis()->SetTitleSize(0.045);
  //TMatrixFBase->GetZaxis()->SetTitle("#pi#lower[-0.15]{+} Covariance Matrix");
  TMatrixFBase->GetZaxis()->SetTitleOffset(1.5);
  TMatrixFBase->GetXaxis()->SetTitle("");
  TMatrixFBase->GetXaxis()->SetLabelSize(0);
  TMatrixFBase->GetXaxis()->SetTitleOffset(1.5);
  TMatrixFBase->GetYaxis()->SetTitle("");
  TMatrixFBase->GetYaxis()->SetTitleOffset(1.5);
  TMatrixFBase->GetYaxis()->SetLabelSize(0);
  TMatrixFBase->SetStats(0);

  TLine *split = new TLine();
  split->SetLineStyle(2);
  split->SetLineWidth(5);
  split->SetLineColor(kBlue);
  split->DrawLineNDC(.1,.51,.849,.51);
  split->DrawLineNDC(.475,.101,.475,.930);
  add_plot_label("|            0.2 #minus 3.0 GeV            |            0.2 #minus 3.0 GeV            | ", 0.48,0.08,0.03);

  TLatex *Total = new TLatex(.2,.96,"#nu#lower[0.3]{#mu} #pi#lower[-0.15]{+} Fractional Error Matrix");
  Total->SetNDC();
  Total->SetTextFont(62);
  Total->SetTextSize(0.045);
  Total->Draw();



  ND->Draw();
  MD->Draw();
  ND45->Draw();
  MD45->Draw();


  //  c2->Print("mult2_matrix.pdf");

  TCanvas* c21 = new TCanvas("c21","",700,700);
  c21->SetLeftMargin(.1);
  c21->SetBottomMargin(.1);
  c21->SetTopMargin(.075);
  c21->SetRightMargin(.15);
  c21->cd();

  C2.Draw("COLZ");
  gStyle->SetPalette(56,0);
  TMatrixFBase->SetContour(999);
  //TMatrixFBase->GetZaxis()->SetRangeUser(-1,1);

  TMatrixFBase->GetZaxis()->SetTitleFont(62);
  TMatrixFBase->GetZaxis()->SetLabelFont(62);
  TMatrixFBase->GetZaxis()->SetTitleSize(0.045);
  //TMatrixFBase->GetZaxis()->SetTitle("#pi#lower[-0.15]{+} Correlation Matrix");
  TMatrixFBase->GetZaxis()->SetTitleOffset(1.5);
  TMatrixFBase->GetXaxis()->SetTitle("");
  TMatrixFBase->GetXaxis()->SetLabelSize(0);
  TMatrixFBase->GetXaxis()->SetTitleOffset(1.5);
  TMatrixFBase->GetYaxis()->SetTitle("");
  TMatrixFBase->GetYaxis()->SetTitleOffset(1.5);
  TMatrixFBase->GetYaxis()->SetLabelSize(0);
  TMatrixFBase->SetStats(0);

  TLine *split = new TLine();
  split->SetLineStyle(2);
  split->SetLineWidth(5);
  split->SetLineColor(kYellow);
  split->DrawLineNDC(.1,.51,.849,.51);
  split->DrawLineNDC(.475,.101,.475,.930);
  add_plot_label("|            0.2 #minus 3.0 GeV            |            0.2 #minus 3.0 GeV            | ", 0.48,0.08,0.03);

  TLatex *Total = new TLatex(.2,.96,"#nu#lower[0.3]{#mu} #pi#lower[-0.15]{+} Correlation Matrix");
  Total->SetNDC();
  Total->SetTextFont(62);
  Total->SetTextSize(0.045);
  Total->Draw();

  ND->Draw();
  MD->Draw();
  ND45->Draw();
  MD45->Draw();


  //  c21->Print("mult2_correlation_matrix.pdf");


  TCanvas* c1 = new TCanvas("c1","",700,700);
  c1->SetLeftMargin(.1);
  c1->SetBottomMargin(.1);
  c1->SetTopMargin(.075);
  c1->SetRightMargin(.15);
  c1->cd();

  M1.Draw("COLZ");
  gStyle->SetPalette(56,0);
  TMatrixFBase->SetContour(999);
  //TMatrixFBase->GetZaxis()->SetRangeUser(-0.005,0.045);

  TMatrixFBase->GetZaxis()->SetTitleFont(62);
  TMatrixFBase->GetZaxis()->SetLabelFont(62);
  TMatrixFBase->GetZaxis()->SetTitleSize(0.045);
  //TMatrixFBase->GetZaxis()->SetTitle("#pi#lower[-0.15]{-} Covariance Matrix");
  TMatrixFBase->GetZaxis()->SetTitleOffset(1.5);
  TMatrixFBase->GetXaxis()->SetTitle("");
  TMatrixFBase->GetXaxis()->SetLabelSize(0);
  TMatrixFBase->GetXaxis()->SetTitleOffset(1.5);
  TMatrixFBase->GetYaxis()->SetTitle("");
  TMatrixFBase->GetYaxis()->SetTitleOffset(1.5);
  TMatrixFBase->GetYaxis()->SetLabelSize(0);
  TMatrixFBase->SetStats(0);

  TLine *split = new TLine();
  split->SetLineStyle(2);
  split->SetLineWidth(5);
  split->SetLineColor(kBlue);
  split->DrawLineNDC(.1,.51,.849,.51);
  split->DrawLineNDC(.475,.101,.475,.930);
  add_plot_label("|            0.2 #minus 3.0 GeV            |            0.2 #minus 3.0 GeV            | ", 0.48,0.08,0.03);

  TLatex *Total = new TLatex(.2,.96,"#nu#lower[0.3]{#mu} #pi#lower[-0.15]{-} Fractional Error Matrix");
  Total->SetNDC();
  Total->SetTextFont(62);
  Total->SetTextSize(0.045);
  Total->Draw();

  ND->Draw();
  MD->Draw();
  ND45->Draw();
  MD45->Draw();


  //  c1->Print("mult1_matrix.pdf");

  TCanvas* c11 = new TCanvas("c11","",700,700);
  c11->SetLeftMargin(.1);
  c11->SetBottomMargin(.1);
  c11->SetTopMargin(.075);
  c11->SetRightMargin(.15);
  c11->cd();

  C1.Draw("COLZ");
  gStyle->SetPalette(56,0);
  TMatrixFBase->SetContour(999);
  //TMatrixFBase->GetZaxis()->SetRangeUser(-1,1);

  TMatrixFBase->GetZaxis()->SetTitleFont(62);
  TMatrixFBase->GetZaxis()->SetLabelFont(62);
  TMatrixFBase->GetZaxis()->SetTitleSize(0.045);
  //  TMatrixFBase->GetZaxis()->SetTitle("#pi#lower[-0.15]{-} Correlation Matrix");
  TMatrixFBase->GetZaxis()->SetTitleOffset(1.5);
  TMatrixFBase->GetXaxis()->SetTitle("");
  TMatrixFBase->GetXaxis()->SetLabelSize(0);
  TMatrixFBase->GetXaxis()->SetTitleOffset(1.5);
  TMatrixFBase->GetYaxis()->SetTitle("");
  TMatrixFBase->GetYaxis()->SetTitleOffset(1.5);
  TMatrixFBase->GetYaxis()->SetLabelSize(0);
  TMatrixFBase->SetStats(0);

  TLine *split = new TLine();
  split->SetLineStyle(2);
  split->SetLineWidth(5);
  split->SetLineColor(kYellow);
  split->DrawLineNDC(.1,.51,.849,.51);
  split->DrawLineNDC(.475,.101,.475,.930);
  add_plot_label("|            0.2 #minus 3.0 GeV            |            0.2 #minus 3.0 GeV            | ", 0.48,0.08,0.03);

  TLatex *Total = new TLatex(.2,.96,"#nu#lower[0.3]{#mu} #pi#lower[-0.15]{-} Correlation Matrix");
  Total->SetNDC();
  Total->SetTextFont(62);
  Total->SetTextSize(0.045);
  Total->Draw();

  ND->Draw();
  MD->Draw();
  ND45->Draw();
  MD45->Draw();


  //  c11->Print("mult1_correlation_matrix.pdf");


  TCanvas* c0 = new TCanvas("c0","",700,700);
  c0->SetLeftMargin(.1);
  c0->SetBottomMargin(.1);
  c0->SetTopMargin(.075);
  c0->SetRightMargin(.15);
  c0->cd();

  M0.Draw("COLZ");
  gStyle->SetPalette(56,0);
  TMatrixFBase->SetContour(999);
  //TMatrixFBase->GetZaxis()->SetRangeUser(-0.005,0.045);

  TMatrixFBase->GetZaxis()->SetTitleFont(62);
  TMatrixFBase->GetZaxis()->SetLabelFont(62);
  TMatrixFBase->GetZaxis()->SetTitleSize(0.045);
  //  TMatrixFBase->GetZaxis()->SetTitle("Beam UniSim Covariance Matrix");
  TMatrixFBase->GetZaxis()->SetTitleOffset(1.5);
  TMatrixFBase->GetXaxis()->SetTitle("");
  TMatrixFBase->GetXaxis()->SetLabelSize(0);
  TMatrixFBase->GetXaxis()->SetTitleOffset(1.5);
  TMatrixFBase->GetYaxis()->SetTitle("");
  TMatrixFBase->GetYaxis()->SetTitleOffset(1.5);
  TMatrixFBase->GetYaxis()->SetLabelSize(0);
  TMatrixFBase->SetStats(0);

  TLine *split = new TLine();
  split->SetLineStyle(2);
  split->SetLineWidth(5);
  split->SetLineColor(kBlue);
  split->DrawLineNDC(.1,.51,.849,.51);
  split->DrawLineNDC(.475,.101,.475,.930);
  add_plot_label("|            0.2 #minus 3.0 GeV            |            0.2 #minus 3.0 GeV            | ", 0.48,0.08,0.03);

  TLatex *Total = new TLatex(.2,.96,"#nu#lower[0.3]{#mu} Beam Fractional Error Matrix");
  Total->SetNDC();
  Total->SetTextFont(62);
  Total->SetTextSize(0.045);
  Total->Draw();

  ND->Draw();
  MD->Draw();
  ND45->Draw();
  MD45->Draw();


  //  c0->Print("mult0_matrix.pdf");

  TCanvas* c01 = new TCanvas("c01","",700,700);
  c01->SetLeftMargin(.1);
  c01->SetBottomMargin(.1);
  c01->SetTopMargin(.075);
  c01->SetRightMargin(.15);
  c01->cd();

  C0.Draw("COLZ");
  gStyle->SetPalette(56,0);
  TMatrixFBase->SetContour(999);
  //TMatrixFBase->GetZaxis()->SetRangeUser(-1,1);

  TMatrixFBase->GetZaxis()->SetTitleFont(62);
  TMatrixFBase->GetZaxis()->SetLabelFont(62);
  TMatrixFBase->GetZaxis()->SetTitleSize(0.045);
  //  TMatrixFBase->GetZaxis()->SetTitle("Beam UniSim Correlation Matrix");
  TMatrixFBase->GetZaxis()->SetTitleOffset(1.5);
  TMatrixFBase->GetXaxis()->SetTitle("");
  TMatrixFBase->GetXaxis()->SetLabelSize(0);
  TMatrixFBase->GetXaxis()->SetTitleOffset(1.5);
  TMatrixFBase->GetYaxis()->SetTitle("");
  TMatrixFBase->GetYaxis()->SetTitleOffset(1.5);
  TMatrixFBase->GetYaxis()->SetLabelSize(0);
  TMatrixFBase->SetStats(0);

  TLine *split = new TLine();
  split->SetLineStyle(2);
  split->SetLineWidth(5);
  split->SetLineColor(kYellow);
  split->DrawLineNDC(.1,.51,.849,.51);
  split->DrawLineNDC(.475,.101,.475,.930);
  add_plot_label("|            0.2 #minus 3.0 GeV            |            0.2 #minus 3.0 GeV            | ", 0.48,0.08,0.03);

  TLatex *Total = new TLatex(.2,.96,"#nu#lower[0.3]{#mu} Beam Correlation Matrix");
  Total->SetNDC();
  Total->SetTextFont(62);
  Total->SetTextSize(0.045);
  Total->Draw();

  ND->Draw();
  MD->Draw();
  ND45->Draw();
  MD45->Draw();

  //  c01->Print("mult0_correlation_matrix.pdf");
 
  TCanvas* c86 = new TCanvas("c86","",800,400);
  c86->SetLeftMargin(.1);
  c86->SetBottomMargin(.1);
  c86->SetTopMargin(.05);
  c86->SetRightMargin(.05);
  c86->cd();

  Fig6->GetYaxis()->SetTitle("Fractional Error");
  Fig6->GetYaxis()->SetTitleFont(62);
  Fig6->GetXaxis()->SetTitleFont(62);
  Fig6->GetYaxis()->SetLabelFont(62);
  Fig6->GetXaxis()->SetLabelFont(62);
  Fig6->GetYaxis()->CenterTitle();
  Fig6->GetYaxis()->SetTitleSize(0.06);
  Fig6->GetYaxis()->SetTitleOffset(0.8);
  Fig6->GetXaxis()->SetLabelSize(0.06);
  Fig6->GetYaxis()->SetLabelSize(0.06);
  Fig6->GetXaxis()->SetTitleOffset(1.5);
  Fig6->SetStats(0);
  Fig6->SetMinimum(-0.01);
  Fig6->SetMaximum(0.21);
  Fig6->SetMarkerStyle(8);
  Fig6->GetYaxis()->SetNdivisions(509);
  Fig6->GetXaxis()->SetNdivisions(509);
  Fig6->Draw("P");
  split->SetLineColor(1);
  split->SetLineWidth(2);
  split->DrawLine(19,-0.01,19,0.21);

  TLatex *ND = new TLatex(.23,.85,"LAr1-ND (100m) ");
  ND->SetNDC();
  ND->SetTextFont(62);
  ND->SetTextSize(0.05);
  ND->Draw();

  TLatex *MD = new TLatex(.65,.85,"T600 (600m, on axis)");
  MD->SetNDC();
  MD->SetTextFont(62);
  MD->SetTextSize(0.05);
  MD->Draw();

  //  c86->Print("FractionalErrors_Total.pdf");

  TCanvas* c85 = new TCanvas("c85","",800,400);
  c85->SetLeftMargin(.1);
  c85->SetBottomMargin(.1);
  c85->SetTopMargin(.05);
  c85->SetRightMargin(.05);
  c85->cd();

  Fig5->GetYaxis()->SetTitle("K#lower[-0.2]{+} Fractional Error");
  Fig5->GetYaxis()->SetTitleFont(62);
  Fig5->GetXaxis()->SetTitleFont(62);
  Fig5->GetYaxis()->SetLabelFont(62);
  Fig5->GetXaxis()->SetLabelFont(62);
  Fig5->GetYaxis()->CenterTitle();
  Fig5->GetYaxis()->SetTitleSize(0.06);
  Fig5->GetYaxis()->SetTitleOffset(0.8);
  Fig5->GetXaxis()->SetLabelSize(0.06);
  Fig5->GetYaxis()->SetLabelSize(0.06);
  Fig5->GetXaxis()->SetTitleOffset(1.5);
  Fig5->SetStats(0);
  Fig5->SetMinimum(-0.01);
  Fig5->SetMaximum(0.21);
  Fig5->SetMarkerStyle(8);
  Fig5->GetYaxis()->SetNdivisions(509);
  Fig5->GetXaxis()->SetNdivisions(509);
  Fig5->Draw("P");
  split->SetLineColor(1);
  split->SetLineWidth(2);
  split->DrawLine(19,-0.01,19,0.21);
  ND->Draw();
  MD->Draw();

  //  c85->Print("FractionalErrors_Kplus.pdf");

  
  TCanvas* c84 = new TCanvas("c84","",800,400);
  c84->SetLeftMargin(.1);
  c84->SetBottomMargin(.1);
  c84->SetTopMargin(.05);
  c84->SetRightMargin(.05);
  c84->cd();

  Fig4->GetYaxis()->SetTitle("K#lower[-0.2]{-} Fractional Error");
  Fig4->GetYaxis()->SetTitleFont(62);
  Fig4->GetXaxis()->SetTitleFont(62);
  Fig4->GetYaxis()->SetLabelFont(62);
  Fig4->GetXaxis()->SetLabelFont(62);
  Fig4->GetYaxis()->CenterTitle();
  Fig4->GetYaxis()->SetTitleSize(0.06);
  Fig4->GetYaxis()->SetTitleOffset(0.8);
  Fig4->GetXaxis()->SetLabelSize(0.06);
  Fig4->GetYaxis()->SetLabelSize(0.06);
  Fig4->GetXaxis()->SetTitleOffset(1.5);
  Fig4->SetStats(0);
  Fig4->SetMinimum(-0.01);
  Fig4->SetMaximum(0.21);
  Fig4->SetMarkerStyle(8);
  Fig4->GetYaxis()->SetNdivisions(509);
  Fig4->GetXaxis()->SetNdivisions(509);
  Fig4->Draw("P");
  split->SetLineColor(1);
  split->SetLineWidth(2);
  split->DrawLine(19,-0.01,19,0.21);
  ND->Draw();
  MD->Draw();

  //  c84->Print("FractionalErrors_Kmin.pdf");


  TCanvas* c83 = new TCanvas("c83","",800,400);
  c83->SetLeftMargin(.1);
  c83->SetBottomMargin(.1);
  c83->SetTopMargin(.05);
  c83->SetRightMargin(.05);
  c83->cd();

  Fig3->GetYaxis()->SetTitle("K#lower[-0.2]{0} Fractional Error");
  Fig3->GetYaxis()->SetTitleFont(62);
  Fig3->GetXaxis()->SetTitleFont(62);
  Fig3->GetYaxis()->SetLabelFont(62);
  Fig3->GetXaxis()->SetLabelFont(62);
  Fig3->GetYaxis()->CenterTitle();
  Fig3->GetYaxis()->SetTitleSize(0.06);
  Fig3->GetYaxis()->SetTitleOffset(0.8);
  Fig3->GetXaxis()->SetLabelSize(0.06);
  Fig3->GetYaxis()->SetLabelSize(0.06);
  Fig3->GetXaxis()->SetTitleOffset(1.5);
  Fig3->SetStats(0);
  Fig3->SetMinimum(-0.01);
  Fig3->SetMaximum(0.21);
  Fig3->SetMarkerStyle(8);
  Fig3->GetYaxis()->SetNdivisions(509);
  Fig3->GetXaxis()->SetNdivisions(509);
  Fig3->Draw("P");
  split->SetLineColor(1);
  split->SetLineWidth(2);
  split->DrawLine(19,-0.01,19,0.21);
  ND->Draw();
  MD->Draw();

  //  c83->Print("FractionalErrors_K0.pdf");


  TCanvas* c82 = new TCanvas("c82","",800,400);
  c82->SetLeftMargin(.1);
  c82->SetBottomMargin(.1);
  c82->SetTopMargin(.05);
  c82->SetRightMargin(.05);
  c82->cd();

  Fig2->GetYaxis()->SetTitle("#pi#lower[-0.2]{+} Fractional Error");
  Fig2->GetYaxis()->SetTitleFont(62);
  Fig2->GetXaxis()->SetTitleFont(62);
  Fig2->GetYaxis()->SetLabelFont(62);
  Fig2->GetXaxis()->SetLabelFont(62);
  Fig2->GetYaxis()->CenterTitle();
  Fig2->GetYaxis()->SetTitleSize(0.06);
  Fig2->GetYaxis()->SetTitleOffset(0.8);
  Fig2->GetXaxis()->SetLabelSize(0.06);
  Fig2->GetYaxis()->SetLabelSize(0.06);
  Fig2->GetXaxis()->SetTitleOffset(1.5);
  Fig2->SetStats(0);
  Fig2->SetMinimum(-0.01);
  Fig2->SetMaximum(0.21);
  Fig2->SetMarkerStyle(8);
  Fig2->GetYaxis()->SetNdivisions(509);
  Fig2->GetXaxis()->SetNdivisions(509);
  Fig2->Draw("P");
  split->SetLineColor(1);
  split->SetLineWidth(2);
  split->DrawLine(19,-0.01,19,0.21);
  ND->Draw();
  MD->Draw();

  //  c82->Print("FractionalErrors_piplus.pdf");


  TCanvas* c81 = new TCanvas("c81","",800,400);
  c81->SetLeftMargin(.1);
  c81->SetBottomMargin(.1);
  c81->SetTopMargin(.05);
  c81->SetRightMargin(.05);
  c81->cd();

  Fig1->GetYaxis()->SetTitle("#pi#lower[-0.2]{-} Fractional Error");
  Fig1->GetYaxis()->SetTitleFont(62);
  Fig1->GetXaxis()->SetTitleFont(62);
  Fig1->GetYaxis()->SetLabelFont(62);
  Fig1->GetXaxis()->SetLabelFont(62);
  Fig1->GetYaxis()->CenterTitle();
  Fig1->GetYaxis()->SetTitleSize(0.06);
  Fig1->GetYaxis()->SetTitleOffset(0.8);
  Fig1->GetXaxis()->SetLabelSize(0.06);
  Fig1->GetYaxis()->SetLabelSize(0.06);
  Fig1->GetXaxis()->SetTitleOffset(1.5);
  Fig1->SetStats(0);
  Fig1->SetMinimum(-0.01);
  Fig1->SetMaximum(0.21);
  Fig1->SetMarkerStyle(8);
  Fig1->GetYaxis()->SetNdivisions(509);
  Fig1->GetXaxis()->SetNdivisions(509);
  Fig1->Draw("P");
  split->SetLineColor(1);
  split->SetLineWidth(2);
  split->DrawLine(19,-0.01,19,0.21);
  ND->Draw();
  MD->Draw();

  //  c81->Print("FractionalErrors_pimin.pdf");


  TCanvas* c80 = new TCanvas("c80","",800,400);
  c80->SetLeftMargin(.1);
  c80->SetBottomMargin(.1);
  c80->SetTopMargin(.05);
  c80->SetRightMargin(.05);
  c80->cd();

  Fig0->GetYaxis()->SetTitle("Beam Fractional Error");
  Fig0->GetYaxis()->SetTitleFont(62);
  Fig0->GetXaxis()->SetTitleFont(62);
  Fig0->GetYaxis()->SetLabelFont(62);
  Fig0->GetXaxis()->SetLabelFont(62);
  Fig0->GetYaxis()->CenterTitle();
  Fig0->GetYaxis()->SetTitleSize(0.06);
  Fig0->GetYaxis()->SetTitleOffset(0.8);
  Fig0->GetXaxis()->SetLabelSize(0.06);
  Fig0->GetYaxis()->SetLabelSize(0.06);
  Fig0->GetXaxis()->SetTitleOffset(1.5);
  Fig0->SetStats(0);
  Fig0->SetMinimum(-0.01);
  Fig0->SetMaximum(0.21);
  Fig0->SetMarkerStyle(8);
  Fig0->GetYaxis()->SetNdivisions(509);
  Fig0->GetXaxis()->SetNdivisions(509);
  Fig0->Draw("P");
  split->SetLineColor(1);
  split->SetLineWidth(2);
  split->DrawLine(19,-0.01,19,0.21);
  ND->Draw();
  MD->Draw();

  //  c80->Print("FractionalErrors_beam.pdf");

 
  cout<<"\nEnd of routine.\n";

  return 0;

}
Beispiel #13
0
int main ()
{
  return C1 () + C2 () + C3 () + C4 () + C5 () + C6 () + C7 () + C8 ();
}
Beispiel #14
0
static void check_solvent(FILE *fp,t_topology *top,t_forcerec *fr,
			  t_mdatoms *md,t_nsborder *nsb)
{
  /* This routine finds out whether a charge group can be used as
   * solvent in the innerloops. The routine should be called once
   * at the beginning of the MD program.
   */
  t_block *cgs,*excl,*mols;
  atom_id *cgid;
  int     i,j,m,j0,j1,nj,k,aj,ak,tjA,tjB,nl_m,nl_n,nl_o;
  int     warncount;
  bool    bOneCG;
  bool    *bAllExcl,bAE,bOrder;
  bool    *bHaveLJ,*bHaveCoul;
  
  cgs  = &(top->blocks[ebCGS]);
  excl = &(top->atoms.excl);
  mols = &(top->blocks[ebMOLS]);

  if (fp)
    fprintf(fp,"Going to determine what solvent types we have.\n");
  snew(fr->solvent_type,cgs->nr+1);
  snew(fr->mno_index,(cgs->nr+1)*3);
  
  /* Generate charge group number for all atoms */
  cgid = make_invblock(cgs,cgs->nra);
  
  warncount=0;

  /* Loop over molecules */
  if (fp)
    fprintf(fp,"There are %d molecules, %d charge groups and %d atoms\n",
	    mols->nr,cgs->nr,cgs->nra);
  for(i=0; (i<mols->nr); i++) {
    /* Set boolean that determines whether the molecules consists of one CG */
    bOneCG = TRUE;
    /* Set some counters */
    j0     = mols->index[i];
    j1     = mols->index[i+1];
    nj     = j1-j0;
    for(j=j0+1; (j<j1); j++) {
      bOneCG = bOneCG && (cgid[mols->a[j]] == cgid[mols->a[j-1]]);
    }
    if (fr->bSolvOpt && bOneCG && nj>1) {
      /* Check whether everything is excluded */
      snew(bAllExcl,nj);
      bAE = TRUE;
      /* Loop over all atoms in molecule */
      for(j=j0; (j<j1) && bAE; j++) {
	/* Set a flag for each atom in the molecule that determines whether
	 * it is excluded or not 
	 */
	for(k=0; (k<nj); k++)
	  bAllExcl[k] = FALSE;
	/* Now check all the exclusions of this atom */
	for(k=excl->index[j]; (k<excl->index[j+1]); k++) {
	  ak = excl->a[k];
	  /* Consistency and range check */
	  if ((ak < j0) || (ak >= j1)) 
	    fatal_error(0,"Exclusion outside molecule? ak = %d, j0 = %d, j1 = 5d, mol is %d",ak,j0,j1,i);
	  bAllExcl[ak-j0] = TRUE;
	}
	/* Now sum up the booleans */
	for(k=0; (k<nj); k++)
	  bAE = bAE && bAllExcl[k];
      }
      if (bAE) {
	snew(bHaveCoul,nj);
	snew(bHaveLJ,nj);
	for(j=j0; (j<j1); j++) {
	  /* Check for coulomb */
	  aj = mols->a[j];
	  bHaveCoul[j-j0] = ( (fabs(top->atoms.atom[aj].q ) > GMX_REAL_MIN) ||
			      (fabs(top->atoms.atom[aj].qB) > GMX_REAL_MIN));
	  /* Check for LJ. */
	  tjA = top->atoms.atom[aj].type;
	  tjB = top->atoms.atom[aj].typeB;
	  bHaveLJ[j-j0] = FALSE;
	  for(k=0; (k<fr->ntype); k++) {
	    if (fr->bBHAM) 
	      bHaveLJ[j-j0] = (bHaveLJ[j-j0] || 
			       (fabs(BHAMA(fr->nbfp,fr->ntype,tjA,k)) > GMX_REAL_MIN) ||
			       (fabs(BHAMB(fr->nbfp,fr->ntype,tjA,k)) > GMX_REAL_MIN) ||
			       (fabs(BHAMC(fr->nbfp,fr->ntype,tjA,k)) > GMX_REAL_MIN) ||
			       (fabs(BHAMA(fr->nbfp,fr->ntype,tjB,k)) > GMX_REAL_MIN) ||
			       (fabs(BHAMB(fr->nbfp,fr->ntype,tjB,k)) > GMX_REAL_MIN) ||
			       (fabs(BHAMC(fr->nbfp,fr->ntype,tjB,k)) > GMX_REAL_MIN));
	    else
	      bHaveLJ[j-j0] = (bHaveLJ[j-j0] || 
			       (fabs(C6(fr->nbfp,fr->ntype,tjA,k))  > GMX_REAL_MIN) ||
			       (fabs(C12(fr->nbfp,fr->ntype,tjA,k)) > GMX_REAL_MIN) ||
			       (fabs(C6(fr->nbfp,fr->ntype,tjB,k))  > GMX_REAL_MIN) ||
			       (fabs(C12(fr->nbfp,fr->ntype,tjB,k)) > GMX_REAL_MIN));
	  }
	}
	/* Now we have determined what particles have which interactions 
	 * In the case of water-like molecules we only check for the number
	 * of particles and the LJ, not for the Coulomb. Let's just assume
	 * that the water loops are faster than the MNO loops anyway. DvdS
	 */
	/* No - there's another problem: To optimize the water
	 * innerloop assumes the charge of the first i atom is constant
	 * qO, and charge on atoms 2/3 is constant qH. /EL
	 */
	/* I won't write any altivec versions of the general solvent inner 
         * loops. Thus, when USE_PPC_ALTIVEC is defined it is faster 
	 * to use the normal loops instead of the MNO solvent version. /EL
	 */
	aj=mols->a[j0];
	if((nj==3) && bHaveCoul[0] && bHaveLJ[0] &&
	   !bHaveLJ[1] && !bHaveLJ[2] &&
	   fabs(top->atoms.atom[aj+1].q - top->atoms.atom[aj+2].q) < GMX_REAL_MIN)
	  fr->solvent_type[cgid[aj]] = esolWATER;
	else {
#ifdef USE_PPC_ALTIVEC
          fr->solvent_type[cgid[aj]] = esolNO;
#else
	  /* Time to compute M & N & O */
	  for(k=0; (k<nj) && (bHaveLJ[k] && bHaveCoul[k]); k++)
	    ;
	  nl_n = k;
	  for(; (k<nj) && (!bHaveLJ[k] && bHaveCoul[k]); k++)
	    ;
	  nl_o = k;
	  for(; (k<nj) && (bHaveLJ[k] && !bHaveCoul[k]); k++)
	    ;
	  nl_m = k;
	  /* Now check whether we're at the end of the pack */
	  bOrder = FALSE;
	  for(; (k<nj); k++)
	    bOrder = bOrder || (bHaveLJ[k] || bHaveCoul[k]);
	  if (bOrder) {
	    /* If we have a solvent molecule with LJC everywhere, then
	     * we shouldn't issue a warning. Only if we suspect something
	     * could be better.
	     */
	    if (nl_n != nj) {
	      warncount++;
	      if(warncount<11 && fp) 
 	        fprintf(fp,"The order in molecule %d could be optimized"
		        " for better performance\n",i);
	      if(warncount==10 && fp)
              fprintf(fp,"(More than 10 molecules where the order can be optimized)\n");
	    }
	    nl_m = nl_n = nl_o = nj;
	  }
	  fr->mno_index[cgid[aj]*3]   = nl_m;
	  fr->mno_index[cgid[aj]*3+1] = nl_n;
	  fr->mno_index[cgid[aj]*3+2] = nl_o;
	  fr->solvent_type[cgid[aj]]  = esolMNO;
#endif /* MNO solvent if not using altivec */
	}

	/* Last check for perturbed atoms */
	for(j=j0; (j<j1); j++)
	  if (md->bPerturbed[mols->a[j]])
	    fr->solvent_type[cgid[mols->a[j0]]] = esolNO;
	
	sfree(bHaveLJ);
	sfree(bHaveCoul);
      }
      else {
	/* Turn off solvent optimization for all cg's in the molecule,
	 * here there is only one.
	 */
	fr->solvent_type[cgid[mols->a[j0]]] = esolNO;
      }
      sfree(bAllExcl);
    }
    else {
      /* Turn off solvent optimization for all cg's in the molecule */
      for(j=mols->index[i]; (j<mols->index[i+1]); j++) {
	fr->solvent_type[cgid[mols->a[j]]] = esolNO;
      }
    }
  }
  if (debug) {
    for(i=0; (i<cgs->nr); i++) 
      fprintf(debug,"MNO: cg = %5d, m = %2d, n = %2d, o = %2d\n",
	      i,fr->mno_index[3*i],fr->mno_index[3*i+1],fr->mno_index[3*i+2]);
  }

  /* Now compute the number of solvent molecules, could be merged with code above */
  fr->nMNOMol = 0;
  fr->nWatMol = 0;
  for(m=0; m<3; m++)
    fr->nMNOav[m] = 0;
  for(i=0; i<mols->nr; i++) {
    j = mols->a[mols->index[i]];
    if (j>=START(nsb) && j<START(nsb)+HOMENR(nsb)) {
	if (fr->solvent_type[cgid[j]] == esolMNO) {
	  fr->nMNOMol++;
	  for(m=0; m<3; m++)
	    fr->nMNOav[m] += fr->mno_index[3*cgid[j]+m];
	}
	else if (fr->solvent_type[cgid[j]] == esolWATER)
	  fr->nWatMol++;
    }
  }
  if (fr->nMNOMol > 0)
    for(m=0; (m<3); m++)
      fr->nMNOav[m] /= fr->nMNOMol;
  
  sfree(cgid);

  if (fp) {
    fprintf(fp,"There are %d optimized solvent molecules on node %d\n",
	    fr->nMNOMol,nsb->nodeid);
    if (fr->nMNOMol > 0)
      fprintf(fp,"  aver. nr. of atoms per molecule: vdwc %.1f coul %.1f vdw %.1f\n",
	      fr->nMNOav[1],fr->nMNOav[2]-fr->nMNOav[1],fr->nMNOav[0]-fr->nMNOav[2]);
    fprintf(fp,"There are %d optimized water molecules on node %d\n",
	    fr->nWatMol,nsb->nodeid);
  }
}
Beispiel #15
0
int multiple_detector_fit()
{

  std::cout << "Beginning : ... " << std::endl;

  Int_t npoints = 1000;
  Double_t emin = 0.2; 
  Double_t emax = 3.0;

  bool use100m = false;
  bool use470m = true;
  bool use600m = false;


  std::vector<int> baselines;
  std::vector<double> scales;
  std::vector<std::string> names;
  std::vector<double> volume;

  if (use100m) baselines.push_back(100);
  if (use470m) baselines.push_back(470);
  if (use600m) baselines.push_back(600);
  int nL = baselines.size();

  double NULLVec[3][20];
  double OscVec[3][1001][7][20];

  for(int i = 0; i < 20; i++){
    NULLVec[0][i] = 0;
    NULLVec[1][i] = 0;
    NULLVec[2][i] = 0;

  }

  for(int u = 0; u < 1000; u++){
    for(int s = 0; s < 7; s++){
      for(int i = 0; i < 20; i++){

	OscVec[0][u][s][i] = 0;
        OscVec[1][u][s][i] = 0;
        OscVec[2][u][s][i] = 0;

      }
    }
  }


  int nbinsE = 0;

  int counter = 0;
  if (use100m){

    std::string temp_name = "../MatrixFiles/combined_ntuple_100m_nu_processed_numu.root";

    TFile temp_file(temp_name.c_str());
    TH1D *NULL_100;
    NULL_100 = (TH1D*)(temp_file.Get("NumuCC"));
    nbinsE = NULL_100->GetNbinsX();
    std::cout << nbinsE << std::endl;
      for(int i = 1; i <= nbinsE; i++){
	  NULLVec[counter][i-1] = (NULL_100->GetBinContent(i));
      }

    for(int u = 0; u < npoints; u++){
      for(int s = 0; s < 7; s++){
	TH1D *OSC_100;
	TString upoint = Form("%d",u);
	TString name = "Universe_";
	TString name2 = "_MultiSim_";
	TString mul = Form("%d",s);
	
	name += upoint;
	name += name2;
	name += mul;	
       
	OSC_100 = (TH1D*)(temp_file.Get(name));
          for(int i = 1; i <= nbinsE; i++){
              OscVec[counter][u][s][i-1] = (OSC_100->GetBinContent(i));
	      //	      if(OscVec[0][u][s][i-1] != OscVec[0][u][s][i-1]) std::cout << "erm" <<std::endl;

	  }

	delete OSC_100;
      }
    }
    counter++;
    delete NULL_100;
    temp_file.Close();
  }

  if (use470m){
    std::string temp_name = "../MatrixFiles/combined_ntuple_470m_nu_processed_numu.root";

    TFile temp_file(temp_name.c_str());
    TH1D *NULL_470;
    NULL_470 = (TH1D*)(temp_file.Get("NumuCC"));
    nbinsE = NULL_470->GetNbinsX();
    std::cout << nbinsE<< std::endl;
      for(int i = 1; i <= nbinsE; i++){
	  NULLVec[counter][i-1] = (NULL_470->GetBinContent(i));
      }

    for(int u = 0; u < npoints; u++){
      for(int s = 0; s < 7; s++){
	TH1D *OSC_470;
	TString upoint = Form("%d",u);//std::to_string(u);
	TString name = "Universe_";
	TString name2 = "_MultiSim_";
	TString mul = Form("%d",s);// = std::to_string(s);
	
	name += upoint;
	name += name2;
	name += mul;	
       
	OSC_470 = (TH1D*)(temp_file.Get(name));
          for(int i = 1; i <= nbinsE; i++){
	    OscVec[counter][u][s][i-1] = (OSC_470->GetBinContent(i));
	  }

	delete OSC_470;
      }
    }
    counter++;
    delete NULL_470;
    temp_file.Close();
  }

  if (use600m){
    std::string temp_name = "../MatrixFiles/combined_ntuple_600m_onaxis_nu_processed_numu.root";

    TFile temp_file(temp_name.c_str());
    TH1D *NULL_600;
    NULL_600 = (TH1D*)(temp_file.Get("NumuCC"));
    nbinsE = NULL_600->GetNbinsX();
    std::cout << nbinsE<< std::endl;
      for(int i = 1; i <= nbinsE; i++){
	  NULLVec[counter][i-1] = (NULL_600->GetBinContent(i));
      }

    for(int u = 0; u < npoints; u++){
      for(int s = 0; s < 7; s++){
	TH1D *OSC_600;
	TString upoint = Form("%d",u);//std::to_string(u);
	TString name = "Universe_";
	TString name2 = "_MultiSim_";
	TString mul = Form("%d",s);// = std::to_string(s);
	
	name += upoint;
	name += name2;
	name += mul;	
       
	OSC_600 = (TH1D*)(temp_file.Get(name));
          for(int i = 1; i <= nbinsE; i++){
	    OscVec[counter][u][s][i-1] = (OSC_600->GetBinContent(i));

	  }

	delete OSC_600;
      }
    }
    counter++;    
    delete NULL_600;
    temp_file.Close();
  }


  //  int nL = 3;
  int mbins = (nbinsE*nL);
 
  TMatrix M6 (mbins,mbins);
  TMatrix M5 (mbins,mbins);
  TMatrix M4 (mbins,mbins);
  TMatrix M3 (mbins,mbins);
  TMatrix M2 (mbins,mbins);
  TMatrix M1 (mbins,mbins);
  TMatrix M0 (mbins,mbins);
  
  TMatrix C6 (mbins,mbins);
  TMatrix C5 (mbins,mbins);
  TMatrix C4 (mbins,mbins);
  TMatrix C3 (mbins,mbins);
  TMatrix C2 (mbins,mbins);
  TMatrix C1 (mbins,mbins);
  TMatrix C0 (mbins,mbins);

  int N = 0;

  TH1D *Fig6 = new TH1D("Fig6",";;",mbins,0,mbins);
  TH1D *Fig5 = new TH1D("Fig5",";;",mbins,0,mbins);
  TH1D *Fig4 = new TH1D("Fig4",";;",mbins,0,mbins);
  TH1D *Fig3 = new TH1D("Fig3",";;",mbins,0,mbins);
  TH1D *Fig2 = new TH1D("Fig2",";;",mbins,0,mbins);
  TH1D *Fig1 = new TH1D("Fig1",";;",mbins,0,mbins);
  TH1D *Fig0 = new TH1D("Fig0",";;",mbins,0,mbins);

  int Erri = 0, Errj = 0;

  std::cout << "Filling Error Matrix..." << std::endl;

  for(int Lrow = 0; Lrow < nL; Lrow++){
    for(int Erow = 0; Erow < nbinsE; Erow++){

      Errj = 0;

      for(int Lcol = 0; Lcol < nL; Lcol++){
        for(int Ecol = 0; Ecol < nbinsE; Ecol++){

          M6 (Erri,Errj) = 0;
          M5 (Erri,Errj) = 0;
          M4 (Erri,Errj) = 0;
          M3 (Erri,Errj) = 0;
          M2 (Erri,Errj) = 0;
          M1 (Erri,Errj) = 0;
          M0 (Erri,Errj) = 0;

	  N = 0;

	  for(int u = 0; u < npoints; u++){

	    M6 (Erri,Errj) += (NULLVec[Lrow][Erow]-OscVec[Lrow][u][6][Erow])*(NULLVec[Lcol][Ecol]-OscVec[Lcol][u][6][Ecol]);
            M5 (Erri,Errj) += (NULLVec[Lrow][Erow]-OscVec[Lrow][u][5][Erow])*(NULLVec[Lcol][Ecol]-OscVec[Lcol][u][5][Ecol]);
            M4 (Erri,Errj) += (NULLVec[Lrow][Erow]-OscVec[Lrow][u][4][Erow])*(NULLVec[Lcol][Ecol]-OscVec[Lcol][u][4][Ecol]);
            M3 (Erri,Errj) += (NULLVec[Lrow][Erow]-OscVec[Lrow][u][3][Erow])*(NULLVec[Lcol][Ecol]-OscVec[Lcol][u][3][Ecol]);
            M2 (Erri,Errj) += (NULLVec[Lrow][Erow]-OscVec[Lrow][u][2][Erow])*(NULLVec[Lcol][Ecol]-OscVec[Lcol][u][2][Ecol]);
            M1 (Erri,Errj) += (NULLVec[Lrow][Erow]-OscVec[Lrow][u][1][Erow])*(NULLVec[Lcol][Ecol]-OscVec[Lcol][u][1][Ecol]);
            M0 (Erri,Errj) += (NULLVec[Lrow][Erow]-OscVec[Lrow][u][0][Erow])*(NULLVec[Lcol][Ecol]-OscVec[Lcol][u][0][Ecol]);

	    N++;
	    
	  }

	  M6 (Erri,Errj) /= N;
          M5 (Erri,Errj) /= N;
          M4 (Erri,Errj) /= N;
          M3 (Erri,Errj) /= N;
          M2 (Erri,Errj) /= N;
          M1 (Erri,Errj) /= N;
	  M0 (Erri,Errj) /= N;


	  
	  M6 (Erri,Errj) /= NULLVec[Lrow][Erow]*NULLVec[Lcol][Ecol];
          M5 (Erri,Errj) /= NULLVec[Lrow][Erow]*NULLVec[Lcol][Ecol];
          M4 (Erri,Errj) /= NULLVec[Lrow][Erow]*NULLVec[Lcol][Ecol];
          M3 (Erri,Errj) /= NULLVec[Lrow][Erow]*NULLVec[Lcol][Ecol];
          M2 (Erri,Errj) /= NULLVec[Lrow][Erow]*NULLVec[Lcol][Ecol];
          M1 (Erri,Errj) /= NULLVec[Lrow][Erow]*NULLVec[Lcol][Ecol];
          M0 (Erri,Errj) /= NULLVec[Lrow][Erow]*NULLVec[Lcol][Ecol];
	  
	  if(Erri == Errj) Fig6->SetBinContent(Erri+1, sqrt(M6 (Erri,Errj)));
      if(Erri == Errj) Fig5->SetBinContent(Erri+1, sqrt(M5 (Erri,Errj)));
      if(Erri == Errj) Fig4->SetBinContent(Erri+1, sqrt(M4 (Erri,Errj)));
      if(Erri == Errj) Fig3->SetBinContent(Erri+1, sqrt(M3 (Erri,Errj)));
      if(Erri == Errj) Fig2->SetBinContent(Erri+1, sqrt(M2 (Erri,Errj)));
      if(Erri == Errj) Fig1->SetBinContent(Erri+1, sqrt(M1 (Erri,Errj)));
      if(Erri == Errj) Fig0->SetBinContent(Erri+1, sqrt(M0 (Erri,Errj)));


          Errj++;

	}}

      Erri++;

    }}

  for(int i = 0; i < Erri; i++){
    for(int j = 0; j < Errj; j++){

      C6 (i,j) = M6(i,j) / sqrt(M6 (i,i) * M6 (j,j));
      C5 (i,j) = M5(i,j) / sqrt(M5 (i,i) * M5 (j,j));
      C4 (i,j) = M4(i,j) / sqrt(M4 (i,i) * M4 (j,j));
      C3 (i,j) = M3(i,j) / sqrt(M3 (i,i) * M3 (j,j));
      C2 (i,j) = M2(i,j) / sqrt(M2 (i,i) * M2 (j,j));
      C1 (i,j) = M1(i,j) / sqrt(M1 (i,i) * M1 (j,j));
      C0 (i,j) = M0(i,j) / sqrt(M0 (i,i) * M0 (j,j));

    }
  }
  
  std::cout << "...Error Matrix Filled" << std::endl;


  TCanvas* c6 = new TCanvas("c6","",700,700);
  c6->SetLeftMargin(.1);
  c6->SetBottomMargin(.1);
  c6->SetTopMargin(.075);
  c6->SetRightMargin(.15);
  c6->cd();

  M6.Draw("COLZ");
  gStyle->SetPalette(56,0);
  TMatrixFBase->SetContour(999);
  //  TMatrixFBase->GetZaxis()->SetRangeUser(-0.05,0.4);
  TMatrixFBase->GetZaxis()->SetTitleFont(62);
  TMatrixFBase->GetZaxis()->SetLabelFont(62);
  TMatrixFBase->GetZaxis()->SetTitleSize(0.045);
  //  TMatrixFBase->GetZaxis()->SetTitle("Fractional Error Matrix");
  TMatrixFBase->GetZaxis()->SetTitleOffset(1.5);
  TMatrixFBase->GetXaxis()->SetTitle("");
  TMatrixFBase->GetXaxis()->SetLabelSize(0);
  TMatrixFBase->GetXaxis()->SetTitleOffset(1.5);
  TMatrixFBase->GetYaxis()->SetTitle("");
  TMatrixFBase->GetYaxis()->SetTitleOffset(1.5);
  TMatrixFBase->GetYaxis()->SetLabelSize(0);
  TMatrixFBase->SetStats(0);

  add_plot_label("  0.2 GeV               #minus             3.0 GeV ", 0.48,0.07,0.04);



  TLatex *MD = new TLatex(.3,.01,"MicroBooNE (470m)");
  MD->SetNDC();
  MD->SetTextFont(62);
  MD->SetTextSize(0.04);
  MD->Draw();

  TLatex *MD45 = new TLatex(.05,.3,"MicroBooNE (470m)");
  MD45->SetNDC();
  MD45->SetTextAngle(90);
  MD45->SetTextFont(62);
  MD45->SetTextSize(0.04);
  MD45->Draw();


  TLatex *Total = new TLatex(.2,.96,"#nu#lower[0.3]{#mu} Flux Fractional Error Matrix");
  Total->SetNDC();
  Total->SetTextFont(62);
  Total->SetTextSize(0.045);
  Total->Draw();

  c6->Print("total_1Det_matrix.pdf");



  TCanvas* c61 = new TCanvas("c61","",700,700);
  c61->SetLeftMargin(.1);
  c61->SetBottomMargin(.1);
  c61->SetTopMargin(.075);
  c61->SetRightMargin(.15);
  c61->cd();

  C6.Draw("COLZ");
  gStyle->SetPalette(56,0);
  TMatrixFBase->SetContour(999);
  TMatrixFBase->GetZaxis()->SetTitleFont(62);
  TMatrixFBase->GetZaxis()->SetLabelFont(62);
  TMatrixFBase->GetZaxis()->SetTitleSize(0.045);
  TMatrixFBase->GetZaxis()->SetTitleOffset(1.5);
  TMatrixFBase->GetXaxis()->SetTitle("");
  TMatrixFBase->GetXaxis()->SetLabelSize(0);
  TMatrixFBase->GetXaxis()->SetTitleOffset(1.5);
  TMatrixFBase->GetYaxis()->SetTitle("");
  TMatrixFBase->GetYaxis()->SetTitleOffset(1.5);
  TMatrixFBase->GetYaxis()->SetLabelSize(0);
  TMatrixFBase->SetStats(0);
  add_plot_label("  0.2 GeV               #minus             3.0 GeV ", 0.48,0.07,0.04);

 
  MD->Draw();

  MD45->Draw();


  TLatex *Total = new TLatex(.2,.96,"#nu#lower[0.3]{#mu} Flux Correlation Matrix");
  Total->SetNDC();
  Total->SetTextFont(62);
  Total->SetTextSize(0.045);
  Total->Draw();

  c61->Print("total_1Det_correlation_matrix.pdf");

 
  cout<<"\nEnd of routine.\n";

  return 0;

}