gint read_aims(gchar *filename, struct model_pak *model) { gint i, num_tokens; gchar **buff; gpointer scan; struct core_pak *core; g_assert(model != NULL); scan = scan_new(filename); if (!scan) return(1); while (!scan_complete(scan)) { buff = scan_get_tokens(scan, &num_tokens); /* for debugging purposes produces a compiler warning about an implicit declaration of function 'g_printf' though this is a valid glib function since 2.2 http://library.gnome.org/devel/glib/2.18/glib-String-Utility-Functions.html#g-printf */ /* for (i=0; i<num_tokens; i++) { g_printf(" %s ", buff[i]); } printf("\n"); */ if (!buff) break; /* read cell vectors */ if ( g_strrstr(*buff, "lattice_vector") != NULL ) { for (i=0 ; i<3 ; i++) { if (num_tokens >= 3) { model->latmat[i] = str_to_float(*(buff+1)); model->latmat[i+3] = str_to_float(*(buff+2)); model->latmat[i+6] = str_to_float(*(buff+3)); } else { gui_text_show(ERROR, "error reading AIMS lattice vectors \n"); return(2); } g_strfreev(buff); buff = scan_get_tokens(scan, &num_tokens); } model->periodic = 3; model->construct_pbc = TRUE; } /* read coordinates */ if ( g_strrstr(*buff, "atom") != NULL ) { if ( ( num_tokens >= 4 ) && ( elem_symbol_test(*(buff+4)) ) ) { core = new_core(*(buff+4), model); core->x[0] = str_to_float(*(buff+1)); core->x[1] = str_to_float(*(buff+2)); core->x[2] = str_to_float(*(buff+3)); model->cores = g_slist_prepend(model->cores, core); } else { gui_text_show(ERROR, "error reading AIMS lattice vectors \n"); return(2); } } g_strfreev(buff); } /* done reading */ scan_free(scan); /* model setup */ g_free(model->filename); model->filename = g_strdup(filename); g_free(model->basename); model->basename = g_path_get_basename(filename); model->fractional = FALSE; model_prep(model); return(0); }
gint read_nwchem_system(gpointer scan, struct model_pak *model) { gint *symbols, num_symbols, num_tokens; gchar **buff; // rewind scan_put_line(scan); while (!scan_complete(scan)) { symbols = scan_get_symbols(scan, &num_symbols); if (num_symbols) { /* process first recognized symbol */ switch (symbols[0]) { case NWCHEM_SYSTEM: if (num_symbols > 1) { switch (symbols[1]) { case NWCHEM_CRYSTAL: model->periodic = 3; model->fractional = TRUE; /* lengths */ buff = scan_get_tokens(scan, &num_tokens); if (num_tokens > 5) { model->pbc[0] = str_to_float(buff[1]); model->pbc[1] = str_to_float(buff[3]); model->pbc[2] = str_to_float(buff[5]); } g_strfreev(buff); /* angles */ buff = scan_get_tokens(scan, &num_tokens); if (num_tokens > 5) { model->pbc[3] = D2R*str_to_float(buff[1]); model->pbc[4] = D2R*str_to_float(buff[3]); model->pbc[5] = D2R*str_to_float(buff[5]); } g_strfreev(buff); break; case NWCHEM_SURFACE: model->periodic = 2; model->fractional = TRUE; /* lengths */ buff = scan_get_tokens(scan, &num_tokens); if (num_tokens > 3) { model->pbc[0] = str_to_float(buff[1]); model->pbc[1] = str_to_float(buff[3]); } g_strfreev(buff); /* angles */ buff = scan_get_tokens(scan, &num_tokens); if (num_tokens > 1) model->pbc[5] = D2R*str_to_float(buff[1]); g_strfreev(buff); break; case NWCHEM_POLYMER: model->periodic = 1; model->fractional = TRUE; /* length */ buff = scan_get_tokens(scan, &num_tokens); if (num_tokens > 1) model->pbc[0] = str_to_float(buff[1]); g_strfreev(buff); break; default: model->periodic = 0; model->fractional = FALSE; } } break; case NWCHEM_END: g_free(symbols); return(0); } g_free(symbols); } } 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); }
gint read_rietica(gchar *filename, struct model_pak *model) { gint i, phases=0, skip, num_tokens; gchar **buff, *line; float x, y, z; gpointer scan; GSList *list; struct core_pak *core; /* checks */ g_assert(model != NULL); scan = scan_new(filename); if (!scan) return(1); /* FIXME - stop the previous file routines setting this */ model->id = -1; while (!scan_complete(scan)) { buff = scan_get_tokens(scan, &num_tokens); /* search for structure start */ if (num_tokens) { if (g_ascii_strncasecmp(*buff, "***", 3) == 0) { if (phases) model = model_new(); phases++; /* structure name - omit the 1st and last tokens (ie "***") */ if (num_tokens > 1) { g_free(*(buff+num_tokens-1)); *(buff+num_tokens-1) = NULL; g_free(model->basename); model->basename = g_strjoinv(" ", buff+1); } /* parse spacegroup */ line = scan_get_line(scan); line = scan_get_line(scan); model->sginfo.spacename = g_strstrip(g_strdup(line)); model->sginfo.spacenum = -1; /* parse a structure */ skip = 0; while (!scan_complete(scan)) { g_strfreev(buff); buff = scan_get_tokens(scan, &num_tokens); if (num_tokens) { if (elem_symbol_test(*buff)) { /* new core */ /* if (num_tokens > 6) */ { core = new_core(*buff, model); model->cores = g_slist_prepend(model->cores, core); /* formatted output can result in -ve signs "joining" tokens */ line = scan_cur_line(scan); /* no doubt some fortran programmer thought this was a clever format */ sscanf(line, "%*16c%8f%8f%8f", &x, &y, &z); VEC3SET(core->x, x, y, z); /* printf("> %s", line); P3VEC(" - ", core->x); core->x[0] = str_to_float(*(buff+2)); core->x[1] = str_to_float(*(buff+3)); core->x[2] = str_to_float(*(buff+4)); core->sof = str_to_float(*(buff+6)); */ skip = 0; } } else skip++; } /* 4 lines after the last core - parse cell info and terminate structure */ if (skip == 4) { if (num_tokens > 5) { for (i=6 ; i-- ; ) model->pbc[i] = str_to_float(*(buff+i)); model->pbc[3] *= D2R; model->pbc[4] *= D2R; model->pbc[5] *= D2R; } break; } } } } g_strfreev(buff); } /* setup all new structures */ for (list=sysenv.mal ; list ; list=g_slist_next(list)) { model = list->data; if (model->id == -1) { model->id = RIETICA; model->periodic = 3; model->fractional = TRUE; strcpy(model->filename, filename); model->cores = g_slist_reverse(model->cores); model_prep(model); } } scan_free(scan); return(0); }