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); } }
void graphics::NgoiNhaTiHon(QPainter& painter) { QPoint A(150,450); QPoint B(350,450); QPoint C(350,200); QPoint D(250,100); QPoint E(150,200); QPolygon poly1; poly1 << A << B << C << D << E; painter.drawPolygon(poly1); // cai cua QPoint A1(250,450); QPoint B1(250,300); QPoint C1(200,300); QPoint D1(200,450); QPolygon poly11; poly11 << A1 << B1 << C1 << D1; painter.drawPolygon(poly11); painter.drawRect(300,250,30,30); // ong khoi QPoint A12(200,150); QPoint B12(200,90); QPoint C12(175,90); QPoint D12(175,175); QPolygon poly12; poly12 << A12 << B12 << C12 << D12; painter.drawPolyline(poly12); }
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; }
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)); } } } }
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 */
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 */
inline void GemmNNDot ( T alpha, const DistMatrix<T>& A, const DistMatrix<T>& B, T beta, DistMatrix<T>& C ) { #ifndef RELEASE PushCallStack("internal::GemmNNDot"); if( A.Grid() != B.Grid() || B.Grid() != C.Grid() ) throw std::logic_error ("{A,B,C} must be distributed over the same grid"); if( A.Height() != C.Height() || B.Width() != C.Width() || A.Width() != B.Height() ) { std::ostringstream msg; msg << "Nonconformal GemmNNDot: \n" << " A ~ " << A.Height() << " x " << A.Width() << "\n" << " B ~ " << B.Height() << " x " << B.Width() << "\n" << " C ~ " << C.Height() << " x " << C.Width() << "\n"; throw std::logic_error( msg.str().c_str() ); } #endif const Grid& g = A.Grid(); if( A.Height() > B.Width() ) { // Matrix views DistMatrix<T> AT(g), AB(g), A0(g), A1(g), A2(g); DistMatrix<T> BL(g), B0(g), BR(g), B1(g), B2(g); DistMatrix<T> CT(g), C0(g), C1L(g), C1R(g), CB(g), C1(g), C10(g), C11(g), C12(g), C2(g); // Temporary distributions DistMatrix<T,STAR,VC> A1_STAR_VC(g); DistMatrix<T,VC,STAR> B1_VC_STAR(g); DistMatrix<T,STAR,STAR> C11_STAR_STAR(g); // Star the algorithm Scale( beta, C ); LockedPartitionDown ( A, AT, AB, 0 ); PartitionDown ( C, CT, CB, 0 ); while( AB.Height() > 0 ) { LockedRepartitionDown ( AT, A0, /**/ /**/ A1, AB, A2 ); RepartitionDown ( CT, C0, /**/ /**/ C1, CB, C2 ); A1_STAR_VC = A1; B1_VC_STAR.AlignWith( A1_STAR_VC ); LockedPartitionRight( B, BL, BR, 0 ); PartitionRight( C1, C1L, C1R, 0 ); while( BR.Width() > 0 ) { LockedRepartitionRight ( BL, /**/ BR, B0, /**/ B1, B2 ); RepartitionRight ( C1L, /**/ C1R, C10, /**/ C11, C12 ); Zeros( C11.Height(), C11.Width(), C11_STAR_STAR ); //------------------------------------------------------------// B1_VC_STAR = B1; LocalGemm ( NORMAL, NORMAL, alpha, A1_STAR_VC, B1_VC_STAR, T(0), C11_STAR_STAR ); C11.SumScatterUpdate( T(1), C11_STAR_STAR ); //------------------------------------------------------------// SlideLockedPartitionRight ( BL, /**/ BR, B0, B1, /**/ B2 ); SlidePartitionRight ( C1L, /**/ C1R, C10, C11, /**/ C12 ); } B1_VC_STAR.FreeAlignments(); SlideLockedPartitionDown ( AT, A0, A1, /**/ /**/ AB, A2 ); SlidePartitionDown ( CT, C0, C1, /**/ /**/ CB, C2 ); } } else { // Matrix views DistMatrix<T> AT(g), AB(g), A0(g), A1(g), A2(g); DistMatrix<T> BL(g), B0(g), BR(g), B1(g), B2(g); DistMatrix<T> CL(g), CR(g), C1T(g), C01(g), C0(g), C1(g), C2(g), C1B(g), C11(g), C21(g); // Temporary distributions DistMatrix<T,STAR,VR> A1_STAR_VR(g); DistMatrix<T,VR,STAR> B1_VR_STAR(g); DistMatrix<T,STAR,STAR> C11_STAR_STAR(g); // Star the algorithm Scale( beta, C ); LockedPartitionRight( B, BL, BR, 0 ); PartitionRight( C, CL, CR, 0 ); while( BR.Width() > 0 ) { LockedRepartitionRight ( BL, /**/ BR, B0, /**/ B1, B2 ); RepartitionRight ( CL, /**/ CR, C0, /**/ C1, C2 ); B1_VR_STAR = B1; A1_STAR_VR.AlignWith( B1_VR_STAR ); LockedPartitionDown ( A, AT, AB, 0 ); PartitionDown ( C1, C1T, C1B, 0 ); while( AB.Height() > 0 ) { LockedRepartitionDown ( AT, A0, /**/ /**/ A1, AB, A2 ); RepartitionDown ( C1T, C01, /***/ /***/ C11, C1B, C21 ); Zeros( C11.Height(), C11.Width(), C11_STAR_STAR ); //------------------------------------------------------------// A1_STAR_VR = A1; LocalGemm ( NORMAL, NORMAL, alpha, A1_STAR_VR, B1_VR_STAR, T(0), C11_STAR_STAR ); C11.SumScatterUpdate( T(1), C11_STAR_STAR ); //------------------------------------------------------------// SlideLockedPartitionDown ( AT, A0, A1, /**/ /**/ AB, A2 ); SlidePartitionDown ( C1T, C01, C11, /***/ /***/ C1B, C21 ); } A1_STAR_VR.FreeAlignments(); SlideLockedPartitionRight ( BL, /**/ BR, B0, B1, /**/ B2 ); SlidePartitionRight ( CL, /**/ CR, C0, C1, /**/ C2 ); } } #ifndef RELEASE PopCallStack(); #endif }
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]; } }
void sirius_v500(std::vector<Element>& the_ring) { int harmonic_number = 864; //double energy = 3e9; // AC10_5 double qaf_strength = 2.536876; double qad_strength = -2.730416; double qbd2_strength = -3.961194; double qbf_strength = 3.902838; double qbd1_strength = -2.966239; double qf1_strength = 2.367821; double qf2_strength = 3.354286; double qf3_strength = 3.080632; double qf4_strength = 2.707639; double sa1_strength = -115.7829759411277/2; double sa2_strength = 49.50386128829739/2; double sb1_strength = -214.5386552515188/2; double sb2_strength = 133.1252391065637/2; double sd1_strength = -302.6188062085843/2; double sf1_strength = 369.5045185071228/2; double sd2_strength = -164.3042864671946/2; double sd3_strength = -289.9270429064217/2; double sf2_strength = 333.7039740852999/2; //""" --- drift spaces --- """ double id_length = 2.0; // [m] Element dia1 = Element::drift("dia", id_length/2); Element dia2 = Element::drift("dia", 3.26920 + 3.65e-3 - id_length/2); Element dib1 = Element::drift("dib", id_length/2); Element dib2 = Element::drift("dib", 2.909200 + 3.65e-3 - id_length/2); Element d10 = Element::drift("d10", 0.100000); Element d11 = Element::drift("d11", 0.110000); Element d12 = Element::drift("d12", 0.120000); Element d13 = Element::drift("d13", 0.130000); Element d15 = Element::drift("d15", 0.150000); Element d17 = Element::drift("d17", 0.170000); Element d18 = Element::drift("d18", 0.180000); Element d20 = Element::drift("d20", 0.200000); Element d22 = Element::drift("d22", 0.220000); Element d23 = Element::drift("d23", 0.230000); Element d26 = Element::drift("d26", 0.260000); Element d32 = Element::drift("d32", 0.320000); Element d44 = Element::drift("d44", 0.440000); //""" --- markers --- """ Element mc = Element::marker("mc"); Element mia = Element::marker("mia"); Element mib = Element::marker("mib"); Element mb1 = Element::marker("mb1"); Element mb2 = Element::marker("mb2"); Element mb3 = Element::marker("mb3"); Element inicio = Element::marker("inicio"); Element fim = Element::marker("fim"); Element mida = Element::marker("id_enda"); Element midb = Element::marker("id_endb"); //""" --- beam position monitors --- """ Element mon = Element::marker("BPM"); //""" --- quadrupoles --- """ Element qaf = Element::quadrupole("qaf", 0.340000, qaf_strength); Element qad = Element::quadrupole("qad", 0.140000, qad_strength); Element qbd2 = Element::quadrupole("qbd2", 0.140000, qbd2_strength); Element qbf = Element::quadrupole("qbf", 0.340000, qbf_strength); Element qbd1 = Element::quadrupole("qbd1", 0.140000, qbd1_strength); Element qf1 = Element::quadrupole("qf1", 0.250000, qf1_strength); Element qf2 = Element::quadrupole("qf2", 0.250000, qf2_strength); Element qf3 = Element::quadrupole("qf3", 0.250000, qf3_strength); Element qf4 = Element::quadrupole("qf4", 0.250000, qf4_strength); //""" --- bending magnets --- """ double deg_2_rad = (M_PI/180.0); std::string dip_nam; double dip_len, dip_ang, dip_K, dip_S; Element h1, h2; //""" -- b1 -- """ dip_nam = "b1"; dip_len = 0.828080; dip_ang = 2.766540 * deg_2_rad; dip_K = -0.78; dip_S = 0; h1 = Element::rbend(dip_nam, dip_len/2, dip_ang/2, 1*dip_ang/2, 0*dip_ang/2, dip_K, dip_S); h2 = Element::rbend(dip_nam, dip_len/2, dip_ang/2, 0*dip_ang/2, 1*dip_ang/2, dip_K, dip_S); std::vector<Element> B1 = {h1, mb1, h2}; //""" -- b2 -- """ dip_nam = "b2"; dip_len = 1.228262; dip_ang = 4.103510 * deg_2_rad; dip_K = -0.78; dip_S = 0.00; h1 = Element::rbend(dip_nam, dip_len/2, dip_ang/2, 1*dip_ang/2, 0*dip_ang/2, dip_K, dip_S); h2 = Element::rbend(dip_nam, dip_len/2, dip_ang/2, 0*dip_ang/2, 1*dip_ang/2, dip_K, dip_S); std::vector<Element> B2 = {h1, mb2, h2}; //""" -- b3 -- """ dip_nam = "b3"; dip_len = 0.428011; dip_ang = 1.429950 * deg_2_rad; dip_K = -0.78; dip_S = 0.00; h1 = Element::rbend(dip_nam, dip_len/2, dip_ang/2, 1*dip_ang/2, 0*dip_ang/2, dip_K, dip_S); h2 = Element::rbend(dip_nam, dip_len/2, dip_ang/2, 0*dip_ang/2, 1*dip_ang/2, dip_K, dip_S); std::vector<Element> B3 = {h1, mb3, h2}; //""" -- bc -- """ dip_nam = "bc"; dip_len = 0.125394; dip_ang = 1.4 * deg_2_rad; dip_K = 0.00; dip_S = -18.93; Element bce = Element::rbend(dip_nam, dip_len/2, dip_ang/2, 1*dip_ang/2, 0*dip_ang/2, dip_K, dip_S); Element bcs = Element::rbend(dip_nam, dip_len/2, dip_ang/2, 0*dip_ang/2, 1*dip_ang/2, dip_K, dip_S); std::vector<Element> BC = {bce, mc, bcs}; //""" --- correctors --- """ Element ch = Element::hcorrector("hcm", 0, 0); Element cv = Element::vcorrector("vcm", 0, 0); Element crhv = Element::corrector ("crhv", 0, 0, 0); //""" --- sextupoles --- """ Element sa1 = Element::sextupole("sa1", 0.150000, sa1_strength); Element sa2 = Element::sextupole("sa2", 0.150000, sa2_strength); Element sb1 = Element::sextupole("sb1", 0.150000, sb1_strength); Element sb2 = Element::sextupole("sb2", 0.150000, sb2_strength); Element sd1 = Element::sextupole("sd1", 0.150000, sd1_strength); Element sf1 = Element::sextupole("sf1", 0.150000, sf1_strength); Element sd2 = Element::sextupole("sd2", 0.150000, sd2_strength); Element sd3 = Element::sextupole("sd3", 0.150000, sd3_strength); Element sf2 = Element::sextupole("sf2", 0.150000, sf2_strength); //""" --- rf cavity --- """ Element cav = Element::rfcavity("cav", 0, 500e6, 2.5e6); //""" lines """ std::vector<Element> insa = { dia1, mida, dia2, crhv, cv, d12, ch, d12, sa2, d12, mon, d12, qaf, d23, qad, d17, sa1, d17}; std::vector<Element> insb = { dib1, midb, dib2, d10, crhv, qbd2, d12, cv, d12, ch, d12, sb2, d12, mon, d12, qbf, d23, qbd1, d17, sb1, d17}; std::vector<Element> cline1 = { d32, cv, d12, ch, d15, sd1, d17, qf1, d12, mon, d11, sf1, d20, qf2, d17, sd2, d12, ch, d10, mon, d10}; std::vector<Element> cline2 = { d18, cv, d26, sd3, d17, qf3, d12, mon, d11, sf2, d20, qf4, d15, ch, crhv, d12, mon, d44}; std::vector<Element> cline3 = { d44, mon, d12, ch, d15, qf4, d20, sf2, d11, mon, d12, qf3, d17, sd3, d26, cv, crhv, d18}; std::vector<Element> cline4 = { d20, ch, d12, sd2, d17, qf2, d20, sf1, d11, mon, d12, qf1, d17, sd1, d15, ch, d12, cv, d22, mon, d10}; //""" Injection Section """ Element dmiainj = Element::drift("dmiainj", 0.3); Element dinjk3 = Element::drift("dinjk3" , 0.3); Element dk3k4 = Element::drift("dk3k4" , 0.6); Element dk4pmm = Element::drift("dk4pmm" , 0.2); Element dpmmcv = Element::drift("dpmmcv" , (3.2692 + 3.65e-3 - 0.3 - 0.3 - 0.6 - 0.2 - 3*0.6)); Element dcvk1 = Element::drift("dcvk1" , (3.2692 + 3.65e-3 - 0.6 - 1.4 - 2*0.6)); Element dk1k2 = Element::drift("dk1k2" , 0.6); Element sef = Element::sextupole("sef", 0.6, 0.0, 5); Element dk2sef = Element::drift("dk2mia" , 0.8); Element kick = Element::corrector("kick", 0.6, 0, 0); Element pmm = Element::sextupole("pmm", 0.6, 0.0, 5); Element inj = Element::marker("inj"); std::vector<Element> insaend = {cv, d12, ch, d12, sa2, d12, mon, d12, qaf, d23, qad, d17, sa1, d17}; std::vector<Element> insainj = latt_join({{dmiainj, inj, dinjk3, kick, dk3k4, kick, dk4pmm, pmm, dpmmcv}, insaend}); std::vector<Element> injinsa = latt_join({latt_reverse(insaend), {dcvk1, kick, dk1k2, kick, dk2sef, sef}}); std::vector<Element> B3BCB3 = latt_join({B3,{d13},BC,{d13},B3}); std::vector<Element> R01 = latt_join({injinsa, {fim, inicio, mia}, insainj}); //#% injection sector, marker of the lattice model starting element std::vector<Element> R03 = latt_join({latt_reverse(insa), {mia, cav}, insa}); //#% sector with cavities std::vector<Element> R05 = latt_join({latt_reverse(insa), {mia}, insa}); std::vector<Element> R07(R05); std::vector<Element> R09(R05); std::vector<Element> R11(R05); std::vector<Element> R13(R05); std::vector<Element> R15(R05); std::vector<Element> R17(R05); std::vector<Element> R19(R05); std::vector<Element> R02 = latt_join({latt_reverse(insb), {mib}, insb}); std::vector<Element> R04(R02); std::vector<Element> R06(R02); std::vector<Element> R08(R02); std::vector<Element> R10(R02); std::vector<Element> R12(R02); std::vector<Element> R14(R02); std::vector<Element> R16(R02); std::vector<Element> R18(R02); std::vector<Element> R20(R02); std::vector<Element> C01 = latt_join({B1, cline1, B2, cline2, B3BCB3, cline3, B2, cline4, B1}); std::vector<Element> C02(C01); std::vector<Element> C03(C01); std::vector<Element> C04(C01); std::vector<Element> C05(C01); std::vector<Element> C06(C01); std::vector<Element> C07(C01); std::vector<Element> C08(C01); std::vector<Element> C09(C01); std::vector<Element> C10(C01); std::vector<Element> C11(C01); std::vector<Element> C12(C01); std::vector<Element> C13(C01); std::vector<Element> C14(C01); std::vector<Element> C15(C01); std::vector<Element> C16(C01); std::vector<Element> C17(C01); std::vector<Element> C18(C01); std::vector<Element> C19(C01); std::vector<Element> C20(C01); the_ring = latt_join({ R01, C01, R02, C02, R03, C03, R04, C04, R05, C05, R06, C06, R07, C07, R08, C08, R09, C09, R10, C10, R11, C11, R12, C12, R13, C13, R14, C14, R15, C15, R16, C16, R17, C17, R18, C18, R19, C19, R20, C20, }); //""" shift lattice to start at the marker "inicio" """ std::vector<int> idx = latt_findcells_fam_name(the_ring, "inicio"); if (idx.size() > 0) { std::vector<Element>::iterator it = the_ring.begin() + idx[0]; std::rotate(the_ring.begin(), it, the_ring.end()); }; //""" check if there are elements with negative lengths """ std::vector<double> lens = latt_getcellstruct<double>(the_ring, "length", latt_range(the_ring)); for(unsigned int i=0; i<lens.size(); ++i) { if (lens[i] < 0) { std::cerr << "negative drift in lattice!" << std::endl; } } //""" sets cavity frequency according to lattice length """ double C = latt_findspos(the_ring, 1+the_ring.size()); double rev_freq = light_speed / C; std::vector<int> rf_idx = latt_findcells_fam_name(the_ring, "cav"); for(unsigned int idx = 0; idx<rf_idx.size(); ++idx) { the_ring[rf_idx[idx]].frequency = rev_freq * harmonic_number; } latt_setcavity(the_ring, "on"); //latt_setradiation(the_ring, "on", 3e9); //""" adjusts number of integraton steps for each element family """ the_ring = latt_set_num_integ_steps(the_ring); }
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; } }
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)); } } } }
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); } }