void FixQEqReax::pertype_parameters(char *arg) { if (strcmp(arg,"reax/c") == 0) { reaxflag = 1; Pair *pair = force->pair_match("reax/c",1); if (pair == NULL) pair = force->pair_match("reax/c/kk",1); if (pair == NULL) error->all(FLERR,"No pair reax/c for fix qeq/reax"); int tmp; chi = (double *) pair->extract("chi",tmp); eta = (double *) pair->extract("eta",tmp); gamma = (double *) pair->extract("gamma",tmp); if (chi == NULL || eta == NULL || gamma == NULL) error->all(FLERR, "Fix qeq/reax could not extract params from pair reax/c"); return; } int i,itype,ntypes; double v1,v2,v3; FILE *pf; reaxflag = 0; ntypes = atom->ntypes; memory->create(chi,ntypes+1,"qeq/reax:chi"); memory->create(eta,ntypes+1,"qeq/reax:eta"); memory->create(gamma,ntypes+1,"qeq/reax:gamma"); if (comm->me == 0) { if ((pf = fopen(arg,"r")) == NULL) error->one(FLERR,"Fix qeq/reax parameter file could not be found"); for (i = 1; i <= ntypes && !feof(pf); i++) { fscanf(pf,"%d %lg %lg %lg",&itype,&v1,&v2,&v3); if (itype < 1 || itype > ntypes) error->one(FLERR,"Fix qeq/reax invalid atom type in param file"); chi[itype] = v1; eta[itype] = v2; gamma[itype] = v3; } if (i <= ntypes) error->one(FLERR,"Invalid param file for fix qeq/reax"); fclose(pf); } MPI_Bcast(&chi[1],ntypes,MPI_DOUBLE,0,world); MPI_Bcast(&eta[1],ntypes,MPI_DOUBLE,0,world); MPI_Bcast(&gamma[1],ntypes,MPI_DOUBLE,0,world); }
void FixQEqSlater::extract_streitz() { Pair *pair = force->pair_match("coul/streitz",1); if (pair == NULL) error->all(FLERR,"No pair coul/streitz for fix qeq/slater"); int tmp; chi = (double *) pair->extract("chi",tmp); eta = (double *) pair->extract("eta",tmp); gamma = (double *) pair->extract("gamma",tmp); zeta = (double *) pair->extract("zeta",tmp); zcore = (double *) pair->extract("zcore",tmp); if (chi == NULL || eta == NULL || gamma == NULL || zeta == NULL || zcore == NULL) error->all(FLERR, "Fix qeq/slater could not extract params from pair coul/streitz"); }
void ComputeFEP::init() { int i,j; if (!fepinitflag) // avoid init to run entirely when called by write_data fepinitflag = 1; else return; // setup and error checks pairflag = 0; for (int m = 0; m < npert; m++) { Perturb *pert = &perturb[m]; pert->ivar = input->variable->find(pert->var); if (pert->ivar < 0) error->all(FLERR,"Variable name for compute fep does not exist"); if (!input->variable->equalstyle(pert->ivar)) error->all(FLERR,"Variable for compute fep is of invalid style"); if (force->pair == NULL) error->all(FLERR,"compute fep pair requires pair interactions"); if (pert->which == PAIR) { pairflag = 1; Pair *pair = force->pair_match(pert->pstyle,1); if (pair == NULL) error->all(FLERR,"compute fep pair style " "does not exist"); void *ptr = pair->extract(pert->pparam,pert->pdim); if (ptr == NULL) error->all(FLERR,"compute fep pair style param not supported"); pert->array = (double **) ptr; // if pair hybrid, test that ilo,ihi,jlo,jhi are valid for sub-style if ((strcmp(force->pair_style,"hybrid") == 0 || strcmp(force->pair_style,"hybrid/overlay") == 0)) { PairHybrid *pair = (PairHybrid *) force->pair; for (i = pert->ilo; i <= pert->ihi; i++) for (j = MAX(pert->jlo,i); j <= pert->jhi; j++) if (!pair->check_ijtype(i,j,pert->pstyle)) error->all(FLERR,"compute fep type pair range is not valid for " "pair hybrid sub-style"); } } else if (pert->which == ATOM) { if (pert->aparam == CHARGE) { if (!atom->q_flag) error->all(FLERR,"compute fep requires atom attribute charge"); } } } if (tailflag) { if (force->pair->tail_flag == 0) error->all(FLERR,"Compute fep tail when pair style does not " "compute tail corrections"); } // detect if package gpu is present int ifixgpu = modify->find_fix("package_gpu"); if (ifixgpu >= 0) fixgpu = modify->fix[ifixgpu]; if (comm->me == 0) { if (screen) { fprintf(screen, "FEP settings ...\n"); fprintf(screen, " temperature = %f\n", temp_fep); fprintf(screen, " tail %s\n", (tailflag ? "yes":"no")); for (int m = 0; m < npert; m++) { Perturb *pert = &perturb[m]; if (pert->which == PAIR) fprintf(screen, " %s %s %d-%d %d-%d\n", pert->pstyle, pert->pparam, pert->ilo, pert->ihi, pert->jlo, pert->jhi); else if (pert->which == ATOM) fprintf(screen, " %d-%d charge\n", pert->ilo, pert->ihi); } } if (logfile) { fprintf(logfile, "FEP settings ...\n"); fprintf(logfile, " temperature = %f\n", temp_fep); fprintf(logfile, " tail %s\n", (tailflag ? "yes":"no")); for (int m = 0; m < npert; m++) { Perturb *pert = &perturb[m]; if (pert->which == PAIR) fprintf(logfile, " %s %s %d-%d %d-%d\n", pert->pstyle, pert->pparam, pert->ilo, pert->ihi, pert->jlo, pert->jhi); else if (pert->which == ATOM) fprintf(logfile, " %d-%d charge\n", pert->ilo, pert->ihi); } } } }
void EwaldN::init() { nkvec = nkvec_max = nevec = nevec_max = 0; nfunctions = nsums = sums = 0; nbox = -1; bytes = 0.0; if (!comm->me) { // output message if (screen) fprintf(screen,"EwaldN initialization ...\n"); if (logfile) fprintf(logfile,"EwaldN initialization ...\n"); } if (domain->dimension == 2) // check for errors error->all(FLERR,"Cannot use EwaldN with 2d simulation"); if (slabflag == 0 && domain->nonperiodic > 0) error->all(FLERR,"Cannot use nonperiodic boundaries with EwaldN"); if (slabflag == 1) { if (domain->xperiodic != 1 || domain->yperiodic != 1 || domain->boundary[2][0] != 1 || domain->boundary[2][1] != 1) error->all(FLERR,"Incorrect boundaries with slab EwaldN"); } scale = 1.0; //mumurd2e = force->mumurd2e; //dielectric = force->dielectric; mumurd2e = dielectric = 1.0; int tmp; Pair *pair = force->pair; int *ptr = pair ? (int *) pair->extract("ewald_order",tmp) : NULL; double *cutoff = pair ? (double *) pair->extract("cut_coul",tmp) : NULL; if (!(ptr||cutoff)) error->all(FLERR,"KSpace style is incompatible with Pair style"); int ewald_order = ptr ? *((int *) ptr) : 1<<1; int ewald_mix = ptr ? *((int *) pair->extract("ewald_mix",tmp)) : GEOMETRIC; memset(function, 0, EWALD_NFUNCS*sizeof(int)); for (int i=0; i<=EWALD_NORDER; ++i) // transcribe order if (ewald_order&(1<<i)) { // from pair_style int n[] = EWALD_NSUMS, k = 0; char str[128]; switch (i) { case 1: k = 0; break; case 3: k = 3; break; case 6: if (ewald_mix==GEOMETRIC) { k = 1; break; } else if (ewald_mix==ARITHMETIC) { k = 2; break; } sprintf(str, "%s pair_style %s", KSPACE_MIX, force->pair_style); error->all(FLERR,str); default: sprintf(str, "%s pair_style %s", KSPACE_ORDER, force->pair_style); error->all(FLERR,str); } nfunctions += function[k] = 1; nsums += n[k]; } double qsum, qsqsum; qsum = qsqsum = 0.0; for (int i = 0; i < atom->nlocal; i++) { qsum += atom->q[i]; qsqsum += atom->q[i]*atom->q[i]; } double qsum_tmp; MPI_Allreduce(&qsum,&qsum_tmp,1,MPI_DOUBLE,MPI_SUM,world); qsum = qsum_tmp; MPI_Allreduce(&qsqsum,&qsum_tmp,1,MPI_DOUBLE,MPI_SUM,world); qsqsum = qsum_tmp; if (qsqsum == 0.0) error->all(FLERR,"Cannot use kspace solver on system with no charge"); if (fabs(qsum) > SMALL && comm->me == 0) { char str[128]; sprintf(str,"System is not charge neutral, net charge = %g",qsum); error->warning(FLERR,str); } // set accuracy (force units) from accuracy_relative or accuracy_absolute if (accuracy_absolute >= 0.0) accuracy = accuracy_absolute; else accuracy = accuracy_relative * two_charge_force; // setup K-space resolution q2 = qsqsum * force->qqrd2e / force->dielectric; bigint natoms = atom->natoms; g_ewald = sqrt(-log(accuracy*sqrt(natoms*(*cutoff)*shape_det(domain->h)) / (2.0*q2))) / *cutoff; if (!comm->me) { // output results if (screen) fprintf(screen, " G vector = %g\n", g_ewald); if (logfile) fprintf(logfile, " G vector = %g\n", g_ewald); } deallocate_peratom(); peratom_allocate_flag = 0; }
void FixAdapt::init() { int i,j; // allow a dynamic group only if ATOM attribute not used if (group->dynamic[igroup]) for (int i = 0; i < nadapt; i++) if (adapt[i].which == ATOM) error->all(FLERR,"Cannot use dynamic group with fix adapt atom"); // setup and error checks anypair = 0; for (int m = 0; m < nadapt; m++) { Adapt *ad = &adapt[m]; ad->ivar = input->variable->find(ad->var); if (ad->ivar < 0) error->all(FLERR,"Variable name for fix adapt does not exist"); if (!input->variable->equalstyle(ad->ivar)) error->all(FLERR,"Variable for fix adapt is invalid style"); if (ad->which == PAIR) { anypair = 1; Pair *pair = NULL; // if ad->pstyle has trailing sub-style annotation ":N", // strip it for pstyle arg to pair_match() and set nsub = N // this should work for appended suffixes as well int n = strlen(ad->pstyle) + 1; char *pstyle = new char[n]; strcpy(pstyle,ad->pstyle); char *cptr; int nsub = 0; if ((cptr = strchr(pstyle,':'))) { *cptr = '\0'; nsub = force->inumeric(FLERR,cptr+1); } if (lmp->suffix_enable) { int len = 2 + strlen(pstyle) + strlen(lmp->suffix); char *psuffix = new char[len]; strcpy(psuffix,pstyle); strcat(psuffix,"/"); strcat(psuffix,lmp->suffix); pair = force->pair_match(psuffix,1,nsub); delete[] psuffix; } if (pair == NULL) pair = force->pair_match(pstyle,1,nsub); if (pair == NULL) error->all(FLERR,"Fix adapt pair style does not exist"); void *ptr = pair->extract(ad->pparam,ad->pdim); if (ptr == NULL) error->all(FLERR,"Fix adapt pair style param not supported"); ad->pdim = 2; if (ad->pdim == 0) ad->scalar = (double *) ptr; if (ad->pdim == 2) ad->array = (double **) ptr; // if pair hybrid, test that ilo,ihi,jlo,jhi are valid for sub-style if (ad->pdim == 2 && (strcmp(force->pair_style,"hybrid") == 0 || strcmp(force->pair_style,"hybrid/overlay") == 0)) { PairHybrid *pair = (PairHybrid *) force->pair; for (i = ad->ilo; i <= ad->ihi; i++) for (j = MAX(ad->jlo,i); j <= ad->jhi; j++) if (!pair->check_ijtype(i,j,pstyle)) error->all(FLERR,"Fix adapt type pair range is not valid for " "pair hybrid sub-style"); } delete [] pstyle; } else if (ad->which == KSPACE) { if (force->kspace == NULL) error->all(FLERR,"Fix adapt kspace style does not exist"); kspace_scale = (double *) force->kspace->extract("scale"); } else if (ad->which == ATOM) { if (ad->aparam == DIAMETER) { if (!atom->radius_flag) error->all(FLERR,"Fix adapt requires atom attribute diameter"); } if (ad->aparam == CHARGE) { if (!atom->q_flag) error->all(FLERR,"Fix adapt requires atom attribute charge"); } } } // make copy of original pair array values for (int m = 0; m < nadapt; m++) { Adapt *ad = &adapt[m]; if (ad->which == PAIR && ad->pdim == 2) { for (i = ad->ilo; i <= ad->ihi; i++) for (j = MAX(ad->jlo,i); j <= ad->jhi; j++) ad->array_orig[i][j] = ad->array[i][j]; } } // fixes that store initial per-atom values if (id_fix_diam) { int ifix = modify->find_fix(id_fix_diam); if (ifix < 0) error->all(FLERR,"Could not find fix adapt storage fix ID"); fix_diam = (FixStore *) modify->fix[ifix]; } if (id_fix_chg) { int ifix = modify->find_fix(id_fix_chg); if (ifix < 0) error->all(FLERR,"Could not find fix adapt storage fix ID"); fix_chg = (FixStore *) modify->fix[ifix]; } if (strstr(update->integrate_style,"respa")) nlevels_respa = ((Respa *) update->integrate)->nlevels; }
void FixAdapt::init() { int i,j; // setup and error checks anypair = 0; for (int m = 0; m < nadapt; m++) { Adapt *ad = &adapt[m]; ad->ivar = input->variable->find(ad->var); if (ad->ivar < 0) error->all("Variable name for fix adapt does not exist"); if (!input->variable->equalstyle(ad->ivar)) error->all("Variable for fix adapt is invalid style"); if (ad->which == PAIR) { anypair = 1; Pair *pair = force->pair_match(ad->pstyle,1); if (pair == NULL) error->all("Fix adapt pair style does not exist"); void *ptr = pair->extract(ad->pparam,ad->pdim); if (ptr == NULL) error->all("Fix adapt pair style param not supported"); ad->pdim = 2; if (ad->pdim == 0) ad->scalar = (double *) ptr; if (ad->pdim == 2) ad->array = (double **) ptr; // if pair hybrid, test that ilo,ihi,jlo,jhi are valid for sub-style if (ad->pdim == 2 && (strcmp(force->pair_style,"hybrid") == 0 || strcmp(force->pair_style,"hybrid/overlay") == 0)) { PairHybrid *pair = (PairHybrid *) force->pair; for (i = ad->ilo; i <= ad->ihi; i++) for (j = MAX(ad->jlo,i); j <= ad->jhi; j++) if (!pair->check_ijtype(i,j,ad->pstyle)) error->all("Fix adapt type pair range is not valid for " "pair hybrid sub-style"); } } else if (ad->which == KSPACE) { if (force->kspace == NULL) error->all("Fix adapt is incompatible with KSpace style"); kspace_scale = (double *) force->kspace->extract("scale"); } else if (ad->which == ATOM) { if (ad->aparam == DIAMETER) { if (!atom->radius_flag) error->all("Fix adapt requires atom attribute diameter"); } } } // make copy of original pair array values for (int m = 0; m < nadapt; m++) { Adapt *ad = &adapt[m]; if (ad->which == PAIR && ad->pdim == 2) { for (i = ad->ilo; i <= ad->ihi; i++) for (j = MAX(ad->jlo,i); j <= ad->jhi; j++) ad->array_orig[i][j] = ad->array[i][j]; } } }
void FixAdaptFEP::init() { int i,j; // setup and error checks anypair = 0; for (int m = 0; m < nadapt; m++) { Adapt *ad = &adapt[m]; ad->ivar = input->variable->find(ad->var); if (ad->ivar < 0) error->all(FLERR,"Variable name for fix adapt/fep does not exist"); if (!input->variable->equalstyle(ad->ivar)) error->all(FLERR,"Variable for fix adapt/fep is invalid style"); if (ad->which == PAIR) { anypair = 1; Pair *pair = force->pair_match(ad->pstyle,1); if (pair == NULL) error->all(FLERR,"Fix adapt/fep pair style does not exist"); void *ptr = pair->extract(ad->pparam,ad->pdim); if (ptr == NULL) error->all(FLERR,"Fix adapt/fep pair style param not supported"); ad->pdim = 2; if (ad->pdim == 0) ad->scalar = (double *) ptr; if (ad->pdim == 2) ad->array = (double **) ptr; // if pair hybrid, test that ilo,ihi,jlo,jhi are valid for sub-style if (ad->pdim == 2 && (strcmp(force->pair_style,"hybrid") == 0 || strcmp(force->pair_style,"hybrid/overlay") == 0)) { PairHybrid *pair = (PairHybrid *) force->pair; for (i = ad->ilo; i <= ad->ihi; i++) for (j = MAX(ad->jlo,i); j <= ad->jhi; j++) if (!pair->check_ijtype(i,j,ad->pstyle)) error->all(FLERR,"Fix adapt/fep type pair range is not valid for " "pair hybrid sub-style"); } } else if (ad->which == KSPACE) { if (force->kspace == NULL) error->all(FLERR,"Fix adapt/fep kspace style does not exist"); kspace_scale = (double *) force->kspace->extract("scale"); } else if (ad->which == ATOM) { if (ad->aparam == DIAMETER) { if (!atom->radius_flag) error->all(FLERR,"Fix adapt/fep requires atom attribute diameter"); } if (ad->aparam == CHARGE) { if (!atom->q_flag) error->all(FLERR,"Fix adapt/fep requires atom attribute charge"); } } } // make copy of original pair array values for (int m = 0; m < nadapt; m++) { Adapt *ad = &adapt[m]; if (ad->which == PAIR && ad->pdim == 2) { for (i = ad->ilo; i <= ad->ihi; i++) for (j = MAX(ad->jlo,i); j <= ad->jhi; j++) ad->array_orig[i][j] = ad->array[i][j]; } } #ifdef ADAPT_DEBUG if (comm->me == 0 && screen) { for (int m = 0; m < nadapt; m++) { Adapt *ad = &adapt[m]; if (ad->which == PAIR && ad->pdim == 2) { fprintf(screen, "###ADAPT original %s %s\n", ad->pstyle, ad->pparam); fprintf(screen, "###ADAPT I J old_param\n"); for (i = ad->ilo; i <= ad->ihi; i++) for (j = MAX(ad->jlo,i); j <= ad->jhi; j++) fprintf(screen, "###ADAPT %2d %2d %9.5f\n", i, j, ad->array_orig[i][j]); } } } #endif }
void EwaldDisp::init() { nkvec = nkvec_max = nevec = nevec_max = 0; nfunctions = nsums = sums = 0; nbox = -1; bytes = 0.0; if (!comm->me) { if (screen) fprintf(screen,"EwaldDisp initialization ...\n"); if (logfile) fprintf(logfile,"EwaldDisp initialization ...\n"); } triclinic_check(); if (domain->dimension == 2) error->all(FLERR,"Cannot use EwaldDisp with 2d simulation"); if (slabflag == 0 && domain->nonperiodic > 0) error->all(FLERR,"Cannot use nonperiodic boundaries with EwaldDisp"); if (slabflag == 1) { if (domain->xperiodic != 1 || domain->yperiodic != 1 || domain->boundary[2][0] != 1 || domain->boundary[2][1] != 1) error->all(FLERR,"Incorrect boundaries with slab EwaldDisp"); } scale = 1.0; mumurd2e = force->qqrd2e; dielectric = force->dielectric; int tmp; Pair *pair = force->pair; int *ptr = pair ? (int *) pair->extract("ewald_order",tmp) : NULL; double *cutoff = pair ? (double *) pair->extract("cut_coul",tmp) : NULL; if (!(ptr||cutoff)) error->all(FLERR,"KSpace style is incompatible with Pair style"); int ewald_order = ptr ? *((int *) ptr) : 1<<1; int ewald_mix = ptr ? *((int *) pair->extract("ewald_mix",tmp)) : GEOMETRIC; memset(function, 0, EWALD_NFUNCS*sizeof(int)); for (int i=0; i<=EWALD_NORDER; ++i) // transcribe order if (ewald_order&(1<<i)) { // from pair_style int n[] = EWALD_NSUMS, k = 0; char str[128]; switch (i) { case 1: k = 0; break; case 3: k = 3; break; case 6: if (ewald_mix==GEOMETRIC) { k = 1; break; } else if (ewald_mix==ARITHMETIC) { k = 2; break; } error->all(FLERR, "Unsupported mixing rule in kspace_style ewald/disp"); default: error->all(FLERR,"Unsupported order in kspace_style ewald/disp"); } nfunctions += function[k] = 1; nsums += n[k]; } if (!gewaldflag) g_ewald = 0.0; pair->init(); // so B is defined init_coeffs(); init_coeff_sums(); double qsum, qsqsum, bsbsum; qsum = qsqsum = bsbsum = 0.0; if (function[0]) { qsum = sum[0].x; qsqsum = sum[0].x2; } // turn off coulombic if no charge if (function[0] && qsqsum == 0.0) { function[0] = 0; nfunctions -= 1; nsums -= 1; } if (function[1]) bsbsum = sum[1].x2; if (function[2]) bsbsum = sum[2].x2; if (function[3]) M2 = sum[9].x2; if (function[3] && strcmp(update->unit_style,"electron") == 0) error->all(FLERR,"Cannot (yet) use 'electron' units with dipoles"); if (qsqsum == 0.0 && bsbsum == 0.0 && M2 == 0.0) error->all(FLERR,"Cannot use Ewald/disp solver " "on system with no charge, dipole, or LJ particles"); if (fabs(qsum) > SMALL && comm->me == 0) { char str[128]; sprintf(str,"System is not charge neutral, net charge = %g",qsum); error->warning(FLERR,str); } if (!function[1] && !function[2]) dispersionflag = 0; if (!function[3]) dipoleflag = 0; pair_check(); // set accuracy (force units) from accuracy_relative or accuracy_absolute if (accuracy_absolute >= 0.0) accuracy = accuracy_absolute; else accuracy = accuracy_relative * two_charge_force; // setup K-space resolution q2 = qsqsum * force->qqrd2e / force->dielectric; M2 *= mumurd2e / force->dielectric; b2 = bsbsum; //Are these units right? bigint natoms = atom->natoms; if (!gewaldflag) { if (function[0]) { g_ewald = accuracy*sqrt(natoms*(*cutoff)*shape_det(domain->h)) / (2.0*q2); if (g_ewald >= 1.0) g_ewald = (1.35 - 0.15*log(accuracy))/(*cutoff); else g_ewald = sqrt(-log(g_ewald)) / (*cutoff); } else if (function[1] || function[2]) { //Try Newton Solver //Use old method to get guess g_ewald = (1.35 - 0.15*log(accuracy))/ *cutoff; double g_ewald_new = NewtonSolve(g_ewald,(*cutoff),natoms,shape_det(domain->h),b2); if (g_ewald_new > 0.0) g_ewald = g_ewald_new; else error->warning(FLERR,"Ewald/disp Newton solver failed, " "using old method to estimate g_ewald"); } else if (function[3]) { //Try Newton Solver //Use old method to get guess g_ewald = (1.35 - 0.15*log(accuracy))/ *cutoff; double g_ewald_new = NewtonSolve(g_ewald,(*cutoff),natoms,shape_det(domain->h),M2); if (g_ewald_new > 0.0) g_ewald = g_ewald_new; else error->warning(FLERR,"Ewald/disp Newton solver failed, " "using old method to estimate g_ewald"); } } if (!comm->me) { if (screen) fprintf(screen, " G vector = %g\n", g_ewald); if (logfile) fprintf(logfile, " G vector = %g\n", g_ewald); } g_ewald_6 = g_ewald; deallocate_peratom(); peratom_allocate_flag = 0; }