struct core_pak *new_core(gchar *elem, struct model_pak *model) { struct core_pak *core; core = core_new(elem, NULL, model); return(core); }
void core_trace(char* path, char* binpath) { core_obj_t* core = NULL; bin_handler_t* binh = NULL; backtrace_t* backtrace = NULL; backt_t* backt = NULL; core = core_new(path); if (core == NULL) errexit("ftrace: core_new:, %s", ftrace_strerror(errno)); /* ** Init binaries. */ if (binpath) binh = bin_create_handler(binpath); else binh = bin_create_handler(core_get_bin_path(core)); if (binh == NULL) errexit("ftrace: bin_create_handler, %s", ftrace_strerror(errno)); if (binh->tracee) bin_refresh_depends_list(core_get_depends_list(core, binh->tracee->obj), binh); backtrace = core_backtrace(core); if (backtrace == NULL) errexit("ftrace: core_backtrace, %s", ftrace_strerror(errno)); /* ** Start backtrace. */ pverbose(1, "\nStarting backtrace of %s\n\n", path); for (; backtrace; ) { backt = (backt_t*) backtrace->value; print_backt(binh, backt->addr); backtrace = list_del(backtrace, backt); free(backt); } pverbose(1, "\n"); }
void zmat_build(void) { gint i, j, k, n, type; gdouble r, a, d, x[4][3], v[3]; gdouble zaxis[3] = {0.0, 0.0, 1.0}; gchar *line; GSList *list, *species; struct zmat_pak *zmat; struct core_pak *core[4] = {NULL, NULL, NULL, NULL}; struct model_pak *model; model = sysenv.active_model; if (!model) return; /* CURRENT - using selection as our list of cores to generate a zmatrix from */ if (!model->selection) { gui_text_show(WARNING, "ZMATRIX: please select a molecule.\n"); return; } /* destroy old zmatrix */ /* TODO - prompt if non null */ zmat_free(model->zmatrix); zmat = model->zmatrix = zmat_new(); zmat_angle_units_set(model->zmatrix, DEGREES); /* setup SIESTA species type */ species = fdf_species_build(model); /* sort the list so it follows molecular connectivity */ model->selection = zmat_connect_sort(model->selection); n=0; for (list=model->selection ; list ; list=g_slist_next(list)) { /* current atom/zmatrix line init */ core[0] = list->data; type = fdf_species_index(core[0]->atom_label, species); line = NULL; zmat->zcores = g_slist_append(zmat->zcores, core[0]); /* build a ZMATRIX line for processing */ switch (n) { case 0: if (core[0]) { ARR3SET(x[0], core[0]->x); vecmat(model->latmat, x[0]); } line = g_strdup_printf("%d 0 0 0 %f %f %f 0 0 0\n", type, x[0][0], x[0][1], x[0][2]); break; case 1: if (core[0]) { ARR3SET(x[0], core[0]->x); vecmat(model->latmat, x[0]); } if (core[1]) { ARR3SET(x[1], core[1]->x); vecmat(model->latmat, x[1]); } r = measure_distance(x[0], x[1]); /* angle with z axis */ ARR3SET(v, x[0]); ARR3SUB(v, x[1]); a = R2D * via(v, zaxis, 3); /* angle between xy projection and x axis */ d = R2D * angle_x_compute(v[0], v[1]); line = g_strdup_printf("%d 1 0 0 %f %f %f 0 0 0\n", type, r, a, d); break; case 2: /* coords init */ for (i=3 ; i-- ; ) { if (core[i]) { ARR3SET(x[i], core[i]->x); vecmat(model->latmat, x[i]); } else g_assert_not_reached(); } r = measure_distance(x[0], x[1]); a = measure_angle(x[0], x[1], x[2]); /* create a fake core -> 1 unit displaced in the z direction */ g_assert(core[3] == NULL); core[3] = core_new("x", NULL, model); ARR3SET(core[3]->rx, core[2]->rx); ARR3ADD(core[3]->rx, zaxis); d = measure_torsion(core); core_free(core[3]); line = g_strdup_printf("%d 2 1 0 %f %f %f 0 0 0\n", type,r,a,d); break; default: /* connectivity test */ if (!zmat_bond_check(core[0], core[1])) { #if DEBUG_ZMAT_BUILD printf("[%d] non-connected atoms [%f]\n", n, measure_distance(x[0], x[1])); #endif /* need to build a new connectivity chain starting from core[0] */ core[1] = core[2] = core[3] = NULL; if (!zmat_connect_find(n, core, zmat)) { gui_text_show(WARNING, "ZMATRIX: bad connectivity (molecule will be incomplete)\n"); goto zmat_build_done; } } /* coords init */ for (i=3 ; i-- ; ) { if (core[i]) { ARR3SET(x[i], core[i]->x); vecmat(model->latmat, x[i]); } else g_assert_not_reached(); } r = measure_distance(x[0], x[1]); a = measure_angle(x[0], x[1], x[2]); d = measure_torsion(core); /* NB: indexing starts from 0, siesta starts from 1 (naturally) */ i = 1+g_slist_index(zmat->zcores, core[1]); j = 1+g_slist_index(zmat->zcores, core[2]); k = 1+g_slist_index(zmat->zcores, core[3]); line = g_strdup_printf("%d %d %d %d %f %f %f 0 0 0\n", type,i,j,k,r,a,d); } /* process a successfully constructed ZMATRIX line */ if (line) { zmat_core_add(line, model->zmatrix); g_free(line); } /* shuffle */ core[3] = core[2]; core[2] = core[1]; core[1] = core[0]; n++; } zmat_build_done: /* do the species typing */ zmat_type(model->zmatrix, species); free_slist(species); }
gint read_about(gchar *filename, struct model_pak *model) { gint i, flag, frame, num_tokens, tot_tokens; gint natom=0, ntype=0; GString *title; gchar **buff, **curr_token, *ptr, *tmp, line[LINELEN]; struct core_pak *core; GSList *clist; FILE *fp; fp = fopen(filename, "rt"); if (!fp) return(1); flag=frame=0; while (!fgetline(fp, line)) { /* space group info */ if (g_ascii_strncasecmp(" Symmetries :", line, 13) == 0) { ptr = g_strrstr(line, "(#"); model->sginfo.spacenum = (gint) str_to_float(ptr+2); } /* default cell dimensions */ /* NB: gdis wants transposed ABINIT matrix */ if (g_ascii_strncasecmp(" Real(R)+Recip(G)", line, 17) == 0) { for (i=0; i<3; i++) { if (fgetline(fp, line)) { gui_text_show(ERROR, "unexpected end of file reading cell dimensions\n"); fclose(fp); return(2); } buff = tokenize(line, &num_tokens); model->latmat[0+i] = str_to_float(*(buff+1))*AU2ANG; model->latmat[3+i] = str_to_float(*(buff+2))*AU2ANG; model->latmat[6+i] = str_to_float(*(buff+3))*AU2ANG; g_strfreev(buff); } model->construct_pbc = TRUE; model->periodic = 3; /* last part of data in output file before minimisation */ break; } /* optimisation type */ if (g_ascii_strncasecmp(" optcell", line, 10) == 0) { buff = tokenize(line, &num_tokens); optcell = (gint) str_to_float(*(buff+1)); g_strfreev(buff); } /* coordinates */ if (g_ascii_strncasecmp(" natom", line, 10) == 0) { buff = tokenize(line, &num_tokens); natom = (gint) str_to_float(*(buff+1)); g_strfreev(buff); } /* NEW - cope with format change and avoid false positives */ // if (g_ascii_strncasecmp(" ntype", line, 10) == 0) if (g_strrstr(line, " ntyp")) { buff = tokenize(line, &num_tokens); ntype = (gint) str_to_float(*(buff+1)); g_strfreev(buff); } /* NEW - cope with format change and avoid false positives */ // if (g_ascii_strncasecmp(" type", line, 10) == 0) if (g_strrstr(line, " typ")) { tot_tokens = 0; buff = tokenize(line, &num_tokens); curr_token = buff + 1; while (tot_tokens < natom) { if (*curr_token == NULL) { g_strfreev(buff); buff = get_tokenized_line(fp, &num_tokens); curr_token = buff; } /* NB: number here is the internal reference to pseudopotential number */ core = core_new(*curr_token, NULL, model); model->cores = g_slist_prepend(model->cores, core); tot_tokens++; curr_token++; } model->cores = g_slist_reverse(model->cores); g_strfreev(buff); flag++; } if (g_ascii_strncasecmp(" xangst", line, 10) == 0) { clist = model->cores; if (clist == NULL) { gui_text_show(ERROR, "no atoms found\n"); fclose(fp); return(2); } buff = tokenize(line+10, &num_tokens); for (i=0; i<natom; i++) { core = clist->data; core->x[0] = str_to_float(*(buff+0)); core->x[1] = str_to_float(*(buff+1)); core->x[2] = str_to_float(*(buff+2)); g_strfreev(buff); buff = get_tokenized_line(fp, &num_tokens); clist = g_slist_next(clist); } } /* process the list of atom nuc charges to get atomic numbers */ if (g_ascii_strncasecmp(" znucl", line, 10) == 0) { buff = tokenize(line, &num_tokens); for (clist=model->cores ; clist ; clist=g_slist_next(clist)) { core = clist->data; if (core->atom_code > 0 && core->atom_code < num_tokens) { /* assign the atomic number */ core->atom_code = str_to_float(*(buff+core->atom_code)); /* wipe the label clean so the element symbol is used */ g_free(core->atom_label); core->atom_label = NULL; /* refresh atom's element data */ elem_init(core, model); } } } } /* Additional info */ while (!fgetline(fp, line)) { /* energy */ /* NEW - cope with format change */ if (g_strrstr(line, "Etotal=")) { buff = g_strsplit(line, "=", 2); if (buff) { model->abinit.energy = str_to_float(*(buff+1)); /* display energy in properties panel */ tmp = g_strdup_printf("%f Hartrees", model->abinit.energy); property_add_ranked(1, "Total energy", tmp, model); g_free(tmp); } g_strfreev(buff); } /* gradient */ else if ((g_ascii_strncasecmp(line, " frms,max,avg=", 14) == 0) && g_strrstr(line, "h/b")) { // printf("reading gradient\n"); buff = tokenize(line, &num_tokens); if (num_tokens > 2) { model->abinit.max_grad = str_to_float(*(buff+2)); model->abinit.rms_grad = str_to_float(*(buff+1)); property_add_ranked(1, "Gradient", *(buff+2), model); } g_strfreev(buff); // printf("gradient is %lf\n", model->abinit.max_grad); } /* coordinates */ else if ((g_ascii_strncasecmp(line, " Cartesian coordinates (bohr)", 29) == 0 && optcell == 0) || (g_ascii_strncasecmp(line, " Unit cell characteristics :", 28) == 0 && optcell > 0)) { /* go through all frames to count them */ read_about_block(fp, model); animate_frame_store(model); frame++; } } fclose(fp); /* done */ if (flag) { g_free(model->filename); model->filename = g_strdup(filename); g_free(model->basename); model->basename = parse_strip(filename); model->num_frames = model->cur_frame = frame; model->cur_frame--; title = g_string_new(""); g_string_append_printf(title, "E"); g_string_append_printf(title, " = %.4f Ha, ", model->abinit.energy); g_string_append_printf(title, "max grad = %.5f", model->abinit.max_grad); model->title = g_strdup(title->str); g_string_free(title, TRUE); model_prep(model); } else return(2); return(0); }
gint read_nwchem_geometry(gpointer scan, struct model_pak *model) { gint n, zmode=0, end_count=0; gchar **buff; struct core_pak *core; #if DEBUG_READ_NWCHEM_GEOMETRY printf("read_nwchem_geometry(): start\n"); #endif // TODO - rewrite this using symbol scanning functionality while (!scan_complete(scan)) { buff = scan_get_tokens(scan, &n); // zmatrix? if (g_ascii_strncasecmp(*buff, "zmatrix", 7) == 0) { zmode = 1; g_strfreev(buff); continue; } if (g_ascii_strncasecmp(*buff, "variables", 9) == 0) { zmode = 2; g_strfreev(buff); continue; } if (g_ascii_strncasecmp(*buff, "constants", 9) == 0) { zmode = 3; g_strfreev(buff); continue; } // end? if (n) { if (g_ascii_strncasecmp(*buff, "end", 3) == 0) { g_strfreev(buff); /* if we processed zmatrix entries - expect 2 x end */ if (zmode && !end_count) { /* keep going until we hit a second end ... */ end_count++; continue; } /* exit */ break; } } /* main parse */ switch (zmode) { // cartesian coords case 0: // can cart coord line have >4 tokens? if (n == 4) { if (elem_test(*buff)) { core = core_new(*buff, NULL, model); model->cores = g_slist_prepend(model->cores, core); core->x[0] = str_to_float(*(buff+1)); core->x[1] = str_to_float(*(buff+2)); core->x[2] = str_to_float(*(buff+3)); #if DEBUG_READ_NWCHEM_GEOMETRY printf("Added [%s] ", *buff); P3VEC(": ", core->x); #endif } } break; // zmatrix coords case 1: #if DEBUG_READ_NWCHEM_GEOMETRY printf("zcoord: %s", scan_cur_line(scan)); #endif zmat_nwchem_core_add(scan_cur_line(scan), model->zmatrix); break; // zmatrix vars case 2: #if DEBUG_READ_NWCHEM_GEOMETRY printf("zvar: %s", scan_cur_line(scan)); #endif zmat_var_add(scan_cur_line(scan), model->zmatrix); break; // zmatrix consts case 3: #if DEBUG_READ_NWCHEM_GEOMETRY printf("zconst: %s", scan_cur_line(scan)); #endif zmat_const_add(scan_cur_line(scan), model->zmatrix); break; } g_strfreev(buff); } if (zmode) { #if DEBUG_READ_NWCHEM_GEOMETRY printf("Creating zmatrix cores...\n"); #endif zmat_angle_units_set(model->zmatrix, DEGREES); zmat_process(model->zmatrix, model); } #if DEBUG_READ_NWCHEM_GEOMETRY printf("read_nwchem_geometry(): stop\n"); #endif return(0); }