void mk_bonds(int nnm, t_nm2type nmt[], t_atoms *atoms, rvec x[], t_params *bond, int nbond[], gmx_bool bPBC, matrix box) { t_param b; int i, j; t_pbc pbc; rvec dx; real dx2; for (i = 0; (i < MAXATOMLIST); i++) { b.a[i] = -1; } for (i = 0; (i < MAXFORCEPARAM); i++) { b.c[i] = 0.0; } if (bPBC) { set_pbc(&pbc, -1, box); } for (i = 0; (i < atoms->nr); i++) { if ((i % 10) == 0) { fprintf(stderr, "\ratom %d", i); } for (j = i+1; (j < atoms->nr); j++) { if (bPBC) { pbc_dx(&pbc, x[i], x[j], dx); } else { rvec_sub(x[i], x[j], dx); } dx2 = iprod(dx, dx); if (is_bond(nnm, nmt, *atoms->atomname[i], *atoms->atomname[j], sqrt(dx2))) { b.AI = i; b.AJ = j; b.C0 = sqrt(dx2); add_param_to_list (bond, &b); nbond[i]++; nbond[j]++; if (debug) { fprintf(debug, "Bonding atoms %s-%d and %s-%d\n", *atoms->atomname[i], i+1, *atoms->atomname[j], j+1); } } } } fprintf(stderr, "\ratom %d\n", i); }
enc_params *parse_config_params(int argc, char **argv) { FILE *infile; param_list list; enc_params *params; char *default_argv[MAX_PARAMS*2]; int default_argc; int i; params = (enc_params *)malloc(sizeof(enc_params)); if (params == NULL) { fprintf(stderr, "Memory allocation failed\n"); return NULL; } memset(params, 0, sizeof(enc_params)); memset(&list, 0, sizeof(param_list)); add_param_to_list(&list, "-cf", NULL, ARG_FILENAME, NULL); add_param_to_list(&list, "-if", NULL, ARG_FILENAME, ¶ms->infilestr); add_param_to_list(&list, "-ph", "0", ARG_INTEGER, ¶ms->file_headerlen); add_param_to_list(&list, "-fh", "0", ARG_INTEGER, ¶ms->frame_headerlen); add_param_to_list(&list, "-of", NULL, ARG_FILENAME, ¶ms->outfilestr); add_param_to_list(&list, "-rf", NULL, ARG_FILENAME, ¶ms->reconfilestr); add_param_to_list(&list, "-stat", NULL, ARG_FILENAME, ¶ms->statfilestr); add_param_to_list(&list, "-n", "600", ARG_INTEGER, ¶ms->num_frames); add_param_to_list(&list, "-skip", "0", ARG_INTEGER, ¶ms->skip); add_param_to_list(&list, "-width", "1920", ARG_INTEGER, ¶ms->width); add_param_to_list(&list, "-height", "1080", ARG_INTEGER, ¶ms->height); add_param_to_list(&list, "-qp", "32", ARG_INTEGER, ¶ms->qp); add_param_to_list(&list, "-f", "60", ARG_FLOAT, ¶ms->frame_rate); add_param_to_list(&list, "-lambda_coeffI", "1.0", ARG_FLOAT, ¶ms->lambda_coeffI); add_param_to_list(&list, "-lambda_coeffP", "1.0", ARG_FLOAT, ¶ms->lambda_coeffP); add_param_to_list(&list, "-lambda_coeffB", "1.0", ARG_FLOAT, ¶ms->lambda_coeffB); add_param_to_list(&list, "-lambda_coeffB0", "1.0", ARG_FLOAT, ¶ms->lambda_coeffB0); add_param_to_list(&list, "-lambda_coeffB1", "1.0", ARG_FLOAT, ¶ms->lambda_coeffB1); add_param_to_list(&list, "-lambda_coeffB2", "1.0", ARG_FLOAT, ¶ms->lambda_coeffB2); add_param_to_list(&list, "-lambda_coeffB3", "1.0", ARG_FLOAT, ¶ms->lambda_coeffB3); add_param_to_list(&list, "-early_skip_thr", "0.0", ARG_FLOAT, ¶ms->early_skip_thr); add_param_to_list(&list, "-enable_tb_split", "0", ARG_INTEGER, ¶ms->enable_tb_split); add_param_to_list(&list, "-enable_pb_split", "0", ARG_INTEGER, ¶ms->enable_pb_split); add_param_to_list(&list, "-max_num_ref", "1", ARG_INTEGER, ¶ms->max_num_ref); add_param_to_list(&list, "-HQperiod", "1", ARG_INTEGER, ¶ms->HQperiod); add_param_to_list(&list, "-num_reorder_pics", "0", ARG_INTEGER, ¶ms->num_reorder_pics); add_param_to_list(&list, "-dyadic_coding", "1", ARG_INTEGER, ¶ms->dyadic_coding); add_param_to_list(&list, "-interp_ref", "0", ARG_INTEGER, ¶ms->interp_ref); add_param_to_list(&list, "-dqpP", "0", ARG_INTEGER, ¶ms->dqpP); add_param_to_list(&list, "-dqpB", "0", ARG_INTEGER, ¶ms->dqpB); add_param_to_list(&list, "-dqpB0", "0", ARG_INTEGER, ¶ms->dqpB0); add_param_to_list(&list, "-dqpB1", "0", ARG_INTEGER, ¶ms->dqpB1); add_param_to_list(&list, "-dqpB2", "0", ARG_INTEGER, ¶ms->dqpB2); add_param_to_list(&list, "-dqpB3", "0", ARG_INTEGER, ¶ms->dqpB3); add_param_to_list(&list, "-mqpP", "1.0", ARG_FLOAT, ¶ms->mqpP); add_param_to_list(&list, "-mqpB", "1.0", ARG_FLOAT, ¶ms->mqpB); add_param_to_list(&list, "-mqpB0", "1.0", ARG_FLOAT, ¶ms->mqpB0); add_param_to_list(&list, "-mqpB1", "1.0", ARG_FLOAT, ¶ms->mqpB1); add_param_to_list(&list, "-mqpB2", "1.0", ARG_FLOAT, ¶ms->mqpB2); add_param_to_list(&list, "-mqpB3", "1.0", ARG_FLOAT, ¶ms->mqpB3); add_param_to_list(&list, "-dqpI", "0", ARG_INTEGER, ¶ms->dqpI); add_param_to_list(&list, "-intra_period", "0", ARG_INTEGER, ¶ms->intra_period); add_param_to_list(&list, "-intra_rdo", "0", ARG_INTEGER, ¶ms->intra_rdo); add_param_to_list(&list, "-rdoq", "0", ARG_INTEGER, ¶ms->rdoq); add_param_to_list(&list, "-max_delta_qp", "0", ARG_INTEGER, ¶ms->max_delta_qp); add_param_to_list(&list, "-delta_qp_step", "1", ARG_INTEGER, ¶ms->delta_qp_step); add_param_to_list(&list, "-encoder_speed", "0", ARG_INTEGER, ¶ms->encoder_speed); add_param_to_list(&list, "-sync", "0", ARG_INTEGER, ¶ms->sync); add_param_to_list(&list, "-deblocking", "1", ARG_INTEGER, ¶ms->deblocking); add_param_to_list(&list, "-clpf", "1", ARG_INTEGER, ¶ms->clpf); add_param_to_list(&list, "-snrcalc", "1", ARG_INTEGER, ¶ms->snrcalc); add_param_to_list(&list, "-use_block_contexts", "0", ARG_INTEGER, ¶ms->use_block_contexts); add_param_to_list(&list, "-enable_bipred", "0", ARG_INTEGER, ¶ms->enable_bipred); add_param_to_list(&list, "-bitrate", "0", ARG_INTEGER, ¶ms->bitrate); add_param_to_list(&list, "-max_qp", "51", ARG_INTEGER, ¶ms->max_qp); add_param_to_list(&list, "-min_qp", "1", ARG_INTEGER, ¶ms->min_qp); add_param_to_list(&list, "-max_qpI", "32", ARG_INTEGER, ¶ms->max_qpI); add_param_to_list(&list, "-min_qpI", "32", ARG_INTEGER, ¶ms->min_qpI); /* Generate "argv" and "argc" for default parameters */ default_argc = 1; for (i = 0; i < list.num; i++) { if (list.params[i].default_string != NULL) { default_argv[default_argc++] = list.params[i].name; default_argv[default_argc++] = list.params[i].default_string; } } /* Parse default parameters */ parse_params(default_argc, default_argv, params, &list); /* Parse parameters from command line and config files */ if (parse_params(argc, argv, params, &list) < 0) return NULL; /* Check if input file is y4m and if so use its geometry */ if ((infile = fopen(params->infilestr, "rb"))) { char buf[256]; int len = fread(buf, 1, sizeof(buf), infile); int pos = 10; int num, den; buf[255] = 0; if (!strncmp(buf, "YUV4MPEG2 ", 10)) { char *end; while (pos < len && buf[pos] != '\n') { switch (buf[pos++]) { case 'W': params->width = strtol(buf+pos, &end, 10); pos = end-buf+1; break; case 'H': params->height = strtol(buf+pos, &end, 10); pos = end-buf+1; break; case 'F': den = strtol(buf+pos, &end, 10); pos = end-buf+1; num = strtol(buf+pos, &end, 10); pos = end-buf+1; params->frame_rate = (double)den/num; break; case 'I': if (buf[pos] != 'p') { fprintf(stderr, "Only progressive input supported\n"); return NULL; } break; case 'C': if (strcmp(buf+pos, "C420")) { } /* Fallthrough */ case 'A': /* Ignored */ case 'X': default: while (buf[pos] != ' ' && buf[pos] != '\n' && pos < len) pos++; break; } } if (strncmp(buf+pos, "\nFRAME\n", 7)) { fprintf(stderr, "Corrupt Y4M file\n"); return NULL; } params->file_headerlen = pos + 1; params->frame_headerlen = 6; } fclose(infile); } return params; }
int generate_gb_exclusion_interactions(t_molinfo *mi,gpp_atomtype_t atype,t_nextnb *nnb) { int i,j,k,n,ai,aj,ti,tj; int n12,n13,n14; int ftype; t_param param; t_params * plist; t_atoms * at; real radiusi,radiusj; real gb_radiusi,gb_radiusj; real param_c2,param_c4; real distance; plist = mi->plist; at = &mi->atoms; for(n=1;n<=nnb->nrex;n++) { switch(n) { case 1: ftype=F_GB12; param_c2 = STILL_P2; param_c4 = 0.8875; break; case 2: ftype=F_GB13; param_c2 = STILL_P3; param_c4 = 0.3516; break; default: /* Put all higher-order exclusions into 1,4 list so we dont miss them */ ftype=F_GB14; param_c2 = STILL_P3; param_c4 = 0.3516; break; } for(ai=0;ai<nnb->nr;ai++) { ti = at->atom[ai].type; radiusi = get_atomtype_radius(ti,atype); gb_radiusi = get_atomtype_gb_radius(ti,atype); for(j=0;j<nnb->nrexcl[ai][n];j++) { aj = nnb->a[ai][n][j]; /* Only add the interactions once */ if(aj>ai) { tj = at->atom[aj].type; radiusj = get_atomtype_radius(tj,atype); gb_radiusj = get_atomtype_gb_radius(tj,atype); /* There is an exclusion of type "ftype" between atoms ai and aj */ param.a[0] = ai; param.a[1] = aj; /* Reference distance, not used for 1-4 interactions */ switch(ftype) { case F_GB12: if(find_gb_bondlength(plist,ai,aj,&distance)!=0) { gmx_fatal(FARGS,"Cannot find bond length for atoms %d-%d",ai,aj); } break; case F_GB13: if(find_gb_anglelength(plist,ai,aj,&distance)!=0) { gmx_fatal(FARGS,"Cannot find length for atoms %d-%d involved in angle",ai,aj); } break; default: distance=-1; break; } /* Assign GB parameters */ /* Sum of radii */ param.c[0] = radiusi+radiusj; /* Reference distance distance */ param.c[1] = distance; /* Still parameter */ param.c[2] = param_c2; /* GB radius */ param.c[3] = gb_radiusi+gb_radiusj; /* Parameter */ param.c[4] = param_c4; /* Add it to the parameter list */ add_param_to_list(&plist[ftype],¶m); } } } } return 0; }
void make_shake (t_params plist[], t_atoms *atoms, int nshake) { char ***info = atoms->atomname; t_params *pr; t_params *bonds; t_param p, *bond, *ang; real b_ij, b_jk; int i, j, ftype, ftype_a; gmx_bool bFound; if (nshake != eshNONE) { switch (nshake) { case eshHBONDS: printf("turning H bonds into constraints...\n"); break; case eshALLBONDS: printf("turning all bonds into constraints...\n"); break; case eshHANGLES: printf("turning all bonds and H angles into constraints...\n"); break; case eshALLANGLES: printf("turning all bonds and angles into constraints...\n"); break; default: gmx_fatal(FARGS, "Invalid option for make_shake (%d)", nshake); } if ((nshake == eshHANGLES) || (nshake == eshALLANGLES)) { /* Add all the angles with hydrogens to the shake list * and remove them from the bond list */ for (ftype = 0; (ftype < F_NRE); ftype++) { if (interaction_function[ftype].flags & IF_BTYPE) { bonds = &(plist[ftype]); for (ftype_a = 0; (bonds->nr > 0 && ftype_a < F_NRE); ftype_a++) { if (interaction_function[ftype_a].flags & IF_ATYPE) { pr = &(plist[ftype_a]); for (i = 0; (i < pr->nr); ) { int numhydrogens; ang = &(pr->param[i]); #ifdef DEBUG printf("Angle: %d-%d-%d\n", ang->ai(), ang->aj(), ang->ak()); #endif numhydrogens = count_hydrogens(info, 3, ang->a); if ((nshake == eshALLANGLES) || (numhydrogens > 1) || (numhydrogens == 1 && toupper(**(info[ang->a[1]])) == 'O')) { /* Can only add hydrogen angle shake, if the two bonds * are constrained. * append this angle to the shake list */ p.ai() = ang->ai(); p.aj() = ang->ak(); /* Calculate length of constraint */ bFound = FALSE; b_ij = b_jk = 0.0; for (j = 0; !bFound && (j < bonds->nr); j++) { bond = &(bonds->param[j]); if (((bond->ai() == ang->ai()) && (bond->aj() == ang->aj())) || ((bond->ai() == ang->aj()) && (bond->aj() == ang->ai()))) { b_ij = bond->c0(); } if (((bond->ai() == ang->ak()) && (bond->aj() == ang->aj())) || ((bond->ai() == ang->aj()) && (bond->aj() == ang->ak()))) { b_jk = bond->c0(); } bFound = (b_ij != 0.0) && (b_jk != 0.0); } if (bFound) { /* apply law of cosines */ p.c0() = std::sqrt( b_ij*b_ij + b_jk*b_jk - 2.0*b_ij*b_jk*cos(DEG2RAD*ang->c0()) ); p.c1() = p.c0(); #ifdef DEBUG printf("p: %d, q: %d, dist: %12.5e\n", p.ai(), p.aj(), p.c0()); #endif add_param_to_list (&(plist[F_CONSTR]), &p); /* move the last bond to this position */ copy_bond (pr, i, pr->nr-1); /* should free memory here!! */ pr->nr--; } } else { i++; } } } /* if IF_ATYPE */ } /* for ftype_A */ } /* if IF_BTYPE */ } /* for ftype */ } /* if shake angles */ /* Add all the bonds with hydrogens to the shake list * and remove them from the bond list */ for (ftype = 0; (ftype < F_NRE); ftype++) { if (interaction_function[ftype].flags & IF_BTYPE) { pr = &(plist[ftype]); j = 0; for (i = 0; i < pr->nr; i++) { if ( (nshake != eshHBONDS) || (count_hydrogens (info, 2, pr->param[i].a) > 0) ) { /* append this bond to the shake list */ p.ai() = pr->param[i].ai(); p.aj() = pr->param[i].aj(); p.c0() = pr->param[i].c0(); p.c1() = pr->param[i].c2(); add_param_to_list (&(plist[F_CONSTR]), &p); } else { copy_bond(pr, j++, i); } } pr->nr = j; } } } }