/* Cleanup the data structures associated with recursive retrieving (the variables above). */ void recursive_cleanup (void) { free_slist (ulist); ulist = NULL; free_vec (forbidden); forbidden = NULL; free_slist (urls_html); urls_html = NULL; free_urlpos (urls_downloaded); urls_downloaded = NULL; FREE_MAYBE (base_dir); FREE_MAYBE (robots_host); first_time = 1; }
void free_ramfli_data(Ramfli *rf) { free_slist((Slnode *)(rf->frames)); rf->frames = NULL; pj_freez(&(rf->fhead)); }
void anim_free_all_frames(struct model_pak *model) { GSList *list; struct frame_pak *frame; g_assert(model != NULL); for (list = model->frame_data_list ; list ; list=g_slist_next(list)) { frame = list->data; free_slist(frame->core_list); free_slist(frame->shell_list); g_free(frame); } g_slist_free(model->frame_data_list); model->frame_data_list = NULL; }
void file_cleanup(void) { /* NB: since the tree store is independant of the model's geom list */ /* it must be completely removed (and then restored) with the dialog */ gtk_list_store_clear(file_path_ts); gtk_list_store_clear(file_name_ts); free_slist(dir_list); /* TODO - free row data (ie FILE_PATH/FILE_NAME strings) */ file_path_tv = NULL; file_path_ts = NULL; file_name_tv = NULL; file_name_ts = NULL; }
static void check_for_held(void) { struct state_list *slist; struct sm_state *tmp; slist = get_all_states(my_id); FOR_EACH_PTR(slist, tmp) { if (slist_has_state(tmp->possible, &held)) { sm_msg("warn: '%s' held on error path.", tmp->name); } } END_FOR_EACH_PTR(tmp); free_slist(&slist); }
void camera_rotate_animate(gint axis, gdouble *angle, gint overwrite, struct model_pak *model) { gdouble a, radian[3]; GSList *journey; struct camera_pak *camera; g_assert(model != NULL); dialog_destroy_type(ANIM); /* TODO - angle checks */ ARR3SET(radian, angle); VEC3MUL(radian, D2R); journey = NULL; for (a=radian[0] ; a<radian[1]+0.5*radian[2] ; a+=radian[2]) { camera = camera_dup(model->camera); switch (axis) { case 1: quat_concat_euler(camera->q, ROLL, a); break; case 2: quat_concat_euler(camera->q, YAW, a); break; default: quat_concat_euler(camera->q, PITCH, a); } journey = g_slist_prepend(journey, camera); } journey = g_slist_reverse(journey); if (overwrite) { free_slist(model->transform_list); model->transform_list = journey; } else model->transform_list = g_slist_concat(model->transform_list, journey); model->num_frames = g_slist_length(model->transform_list); model->animation = TRUE; redraw_canvas(SINGLE); }
void zmat_free(gpointer data) { struct zmat_pak *zmat = data; g_assert(zmat != NULL); g_free(zmat->distance_units); g_free(zmat->angle_units); free_slist(zmat->zlines); /* NB: zcores is a subset of the model's main core list - don't free its data */ g_slist_free(zmat->zcores); g_hash_table_destroy(zmat->vars); g_hash_table_destroy(zmat->consts); g_free(zmat); }
/* NB: leave symmetry / pbc structure intact */ void core_delete_all(struct model_pak *model) { g_assert(model != NULL); /* free core reference lists */ free_mol_list(model); wipe_bonds(model); g_slist_free(model->unique_atom_list); model->unique_atom_list = NULL; /* free cores */ free_slist(model->cores); model->cores = NULL; /* redo dependancies */ zone_init(model); calc_emp(model); gui_refresh(GUI_MODEL_PROPERTIES); model->state = 0; }
// Generate a slist of directory entries in specified path. Then // print the to stdout. void list (char *path) { DIR *dir = opendir (path); struct dirent *ent; slist_ref slist = new_slist (); if (dir != NULL) { for (;;) { ent = readdir (dir); if (ent == NULL) break; insert (slist, path, ent->d_name); } closedir (dir); if (flags.recursive) push_subdir (slist, path); if (flags.opct > 1 && !flags.recursive) printf ("%s:\n", path); print_directory (slist); }else { print_error (path, strerror (errno)); } free_slist (slist); }
/* after argument number n combine all arguments to the curl type curl_slist */ static union luaValueT get_slist(lua_State* L, int n, const char** key) { int i; union luaValueT v; struct curl_slist *slist=0; /* free the previous slist if any */ free_slist(L, key); /* check if all parameters are strings */ for (i=n; i<lua_gettop(L); i++) luaL_checkstring(L, i); for (i=n; i<lua_gettop(L); i++) { slist = curl_slist_append(slist, lua_tostring(L, i)); } /* set the new slist in registry */ lua_pushlightuserdata(L, (void*)key); lua_pushlightuserdata(L, (void *)slist); lua_rawset(L, LUA_REGISTRYINDEX); v.slist=slist; return v; }
gint update_file_pane(void) { gint filter; gchar *name, *full; GSList *list; GtkTreeIter iter; struct stat buff; /* NEW */ filter = sysenv.file_type; /* getting from this directory */ gtk_label_set_text(GTK_LABEL(curr_path), sysenv.cwd); /* clear old data */ gtk_list_store_clear(file_path_ts); gtk_list_store_clear(file_name_ts); free_slist(dir_list); /* get directory listing */ /* NB: success will always return something, even if only ".." */ dir_list = file_dir_list(sysenv.cwd, TRUE); if (!dir_list) { gui_text_show(ERROR, "No directory listing; check your permissions.\n"); gtk_list_store_append(file_path_ts, &iter); gtk_list_store_set(file_path_ts, &iter, FILE_PATH, "..", -1); } list = dir_list; while (list) { /* stat the file (MUST have the full path) */ name = (gchar *) list->data; full = g_build_filename(sysenv.cwd, list->data, NULL); stat(full, &buff); #if DEBUG_UPDATE_FILE_PANE printf("[%s] : %d\n",full,buff.st_mode); #endif /* convert and check if directory */ if ((buff.st_mode & S_IFMT) == S_IFDIR) { gtk_list_store_append(file_path_ts, &iter); gtk_list_store_set(file_path_ts, &iter, FILE_PATH, name, -1); } else { /* is it a recognized type? */ if (file_extension_valid(list->data)) { gtk_list_store_append(file_name_ts, &iter); gtk_list_store_set(file_name_ts, &iter, FILE_NAME, name, -1); } #if OLD_GOK /* FIXME: can it be deleted? I haven't changed this code below to handle empty extensions */ file_data = get_file_info((gpointer *) list->data, BY_EXTENSION); if (file_data) { /* display name if matches current file filter */ if (filter == DATA) { /* don't add filetypes with no read/write routines - pictures */ if (file_data->read_file || file_data->write_file) { gtk_list_store_append(file_name_ts, &iter); gtk_list_store_set(file_name_ts, &iter, FILE_NAME, name, -1); } } else { /* add if specifically requested (ie even if not in menu) */ if (filter == file_data->group) { gtk_list_store_append(file_name_ts, &iter); gtk_list_store_set(file_name_ts, &iter, FILE_NAME, name, -1); } } } #endif } list = g_slist_next(list); g_free(full); } return(TRUE); }
Errcode load_ramfli(Ramfli *rfl, Flifile *flif) { Errcode err; int frame_ix; Ramframe frame; Ramframe *rf; Names first_one; Ramframe *tail = (Ramframe *)&first_one; LONG allocsize; ULONG flags; extern long mem_free; long mem_needed; Boolean ram_required = TRUE; /* size to read in initially */ #define CHECK_SIZE (sizeof(Ramframe) - OFFSET(Ramframe,frame)) first_one.next = NULL; free_ramfli_data(rfl); /* load header from input one */ if((rfl->fhead = pj_malloc(sizeof(Fli_head))) == NULL) { err = Err_no_memory; goto no_mem_error; } *(rfl->fhead) = flif->hdr; /* read in the frames */ flags = rfl->flags; clear_struct(&frame); frame.frame.size = flif->hdr.frame1_oset; frame_ix = -1; mem_needed = flif->hdr.size; while(++frame_ix <= (SHORT)(flif->hdr.frame_count)) { frame.doff += frame.frame.size; /* the last frame if it is an empty frame will only be * sizeof(Fli_frame) so we may have an Err_eof on the last * frame */ if((err = pj_readoset(flif->fd,&frame.frame, frame.doff,CHECK_SIZE)) < Success) { if(frame_ix != flif->hdr.frame_count) goto error; if((err = pj_readoset(flif->fd,&frame.frame, frame.doff,sizeof(frame.frame))) < Success) { goto error; } } if( (!(flags & RF_LOAD_FIRST)) && frame_ix == 0) goto add_empty_frame; if( (!(flags & RF_LOAD_RING)) && frame_ix == flif->hdr.frame_count) goto load_empty_frame; /* simple memory test does not account for an un-needed ring frame */ if((mem_needed - frame.doff) >= mem_free) goto no_mem_error; allocsize = OFFSET(Ramframe,frame)+frame.frame.size; if((rf = pj_malloc(allocsize)) == NULL) { if(ram_required) goto no_mem_error; goto add_empty_frame; } /* add next frame to list */ rf->next = NULL; tail->next = rf; tail = rf; memcpy(rf,&frame,Min(allocsize,sizeof(frame))); if(allocsize < sizeof(frame)) goto add_full_frame; /* read in data: It there is a pstamp chunk we don't need it so * bypass it and adjust frame data. Otherwise read whole chunk */ #ifdef DOESNT_WORK if(frame.first_chunk.type == FLI_PSTAMP) { rf->frame.size -= frame.first_chunk.size; rf->doff += frame.first_chunk.size; if(rf->frame.size > sizeof(Fli_frame) && (err = pj_readoset(flif->fd,&(rf->first_chunk), rf->doff + sizeof(Fli_frame), rf->frame.size - sizeof(Fli_frame))) < Success) { goto error; } --rf->frame.chunks; /* one less chunk */ } else #endif if(frame.frame.size > CHECK_SIZE && (err = pj_read_ecode(flif->fd,(rf + 1), frame.frame.size - CHECK_SIZE)) < Success) { goto error; } add_full_frame: rf->doff = -frame.doff; /* negative offset means we have a * good ram record */ continue; add_empty_frame: if(rfl->fhead) pj_freez(&(rfl->fhead)); load_empty_frame: /* this is a little truncated ramframe only up to doff which is * is positive in this case negative for a ram record */ if((rf = pj_malloc(POSTOSET(Ramframe,doff))) == NULL) goto no_mem_error; rf->doff = frame.doff; rf->next = NULL; tail->next = rf; tail = rf; } rfl->frames = (Ramframe *)first_one.next; return(Success); no_mem_error: /* if specified as required and not ok off disk ERROR out */ free_slist(first_one.next); /* we need enough ram to have requestor */ first_one.next = NULL; if(ram_required && !ask_ok_off_disk(rfl)) err = Err_reported; else err = Success; error: pj_freez(&(rfl->fhead)); free_slist(first_one.next); return(err); #undef CHECK_SIZE }
void command_main_loop(int argc, char **argv) { gint n, status, num_tokens; gchar *inp, *out, *ext, *tmp, *line, *base, **buff; gboolean exit=FALSE; GSList *list, *files, *item, *structures; struct file_pak *inp_pak, *out_pak; struct model_pak *model; if (argc < 2) printf("gdis> Commandline interface. Enter ? for help.\n"); /* command line */ do { /* if additional keywords - process as single command line */ if (argc > 1) { /* convert options into single string for processing */ buff = g_malloc(argc*sizeof(gchar *)); for (n=1 ; n<argc ; n++) *(buff+n-1) = g_strdup(argv[n]); *(buff+argc-1) = NULL; line = g_strjoinv(" ", buff); g_strfreev(buff); exit = TRUE; } else { /* standard repeating prompt */ printf("gdis> "); line = file_read_line(stdin); } /* quit primitive */ if (g_ascii_strncasecmp("qu", line, 2) == 0 || g_ascii_strncasecmp("ex", line, 2) == 0) exit=TRUE; /* test primitive */ if (g_ascii_strncasecmp("te", line, 2) == 0) { buff = tokenize(line, &num_tokens); for (n=1 ; n<num_tokens ; n++) test_run(*(buff+n)); g_strfreev(buff); } /* copy primitive */ if (g_ascii_strncasecmp("co", line, 2) == 0 || g_ascii_strncasecmp("cp", line, 2) == 0) { buff = tokenize(line, &num_tokens); if (num_tokens > 2) { out_pak = get_file_info(*(buff+2), BY_EXTENSION); if (!out_pak) { printf("Error: unrecognized output filetype.\n"); break; } if (!out_pak->write_file) { printf("Error: write method for this filetype does not exist.\n"); break; } /* FIXME! - this is all wrong - should be no dependence on sysenv.cwd for path */ /* since this falls over with something like prompt:>gdis cp /tmp/gok.sot /tmp/dest/gok.meta */ ext = file_extension_get(*(buff+2)); files = file_dir_list_pattern(sysenv.cwd, *(buff+1)); for (list=files ; list ; list=g_slist_next(list)) { inp_pak = get_file_info(list->data, BY_EXTENSION); inp = g_build_filename(sysenv.cwd, list->data, NULL); /* FIXME - changed to correct a problem with Florian's metadata store */ // base = parse_strip(list->data); base = g_strdup(list->data); if (inp_pak) { if (inp_pak->read_file) { model = model_new(); status = inp_pak->read_file(inp, model); structures = g_slist_find(sysenv.mal, model); #if DEBUG_COMMAND_MAIN_LOOP printf("Items loaded = %d [status = %d]\n", g_slist_length(structures), status); #endif if (g_slist_length(structures) > 1) { /* multiple output for input files that contain more than one structure */ n = 1; for (item=structures ; item ; item=g_slist_next(item)) { model = item->data; tmp = g_strdup_printf("%s_%d.%s", base, n, ext); out = g_build_filename(sysenv.cwd, tmp, NULL); status = out_pak->write_file(out, model); #if DEBUG_COMMAND_MAIN_LOOP printf("a [%s] -> [%s]\n", inp, out); #endif g_free(out); g_free(tmp); model_free(model); n++; } } else { tmp = g_strdup_printf("%s.%s", base, ext); out = g_build_filename(sysenv.cwd, tmp, NULL); g_free(tmp); status = out_pak->write_file(out, model); #if DEBUG_COMMAND_MAIN_LOOP printf("b [%s] -> [%s]\n", inp, out); #endif g_free(out); model_free(model); } } else printf("Error: read method for this filetype does not exist.\n"); } else { printf("Error: unrecognized input filetype.\n"); } g_free(base); g_free(inp); } /* CURRENT hack */ if (!files) { /* FIXME */ } g_free(ext); free_slist(files); } else printf("Error: insufficient tokens for <copy> command\n"); g_strfreev(buff); } if (g_ascii_strncasecmp("ls", line, 2) == 0) { buff = tokenize(line, &num_tokens); if (num_tokens > 1) files = file_dir_list_pattern(sysenv.cwd, *(buff+1)); else files = file_dir_list(sysenv.cwd, FALSE); for (list=files ; list ; list=g_slist_next(list)) { printf("%s\n", (gchar *) list->data); } g_strfreev(buff); } if (g_ascii_strncasecmp("cd", line, 2) == 0) { buff = tokenize(line, &num_tokens); if (num_tokens > 1) { inp = g_build_path(DIR_SEP, sysenv.cwd, *(buff+1), NULL); set_path(inp); g_free(inp); } printf("%s\n", sysenv.cwd); g_strfreev(buff); } if (g_ascii_strncasecmp("pwd", line, 3) == 0) { printf("%s\n", sysenv.cwd); } if (g_ascii_strncasecmp("?", line, 1) == 0 || g_ascii_strncasecmp("h", line, 1) == 0) { printf("GDIS v%4.2f available commands\n\n", VERSION); printf("cd <destination>\n"); printf(" - changes to target directory\n"); printf("pwd\n"); printf(" - prints the current working directory\n"); printf("ls\n"); printf(" - lists the files in the current working directory\n"); printf("copy <source> <destination>\n"); printf(" - convert between filetypes, based on extension (wildcards allowed)\n"); printf("quit\n"); printf(" - exit program\n"); } /* done -> next line */ g_free(line); } while (!exit); }
gint get_next_group(FILE *fp, struct model_pak *model, gint *have_basis) { gchar *line, *keyword; gint ret; GSList *keywords = NULL, *list; line = file_read_line(fp); if (!line) return(FALSE); /* TODO not a valid keyword so for the moment skip but could store */ if (g_ascii_strncasecmp(line, " $", 2) != 0) return(TRUE); if (g_ascii_strncasecmp(line, " $data", 6) == 0) { ret = get_data(fp, model, *have_basis); } else if (g_ascii_strncasecmp(line, " $basis", 7) == 0) { *have_basis = TRUE; keywords = get_gamess_keywords(fp, line+7, &ret); for (list=keywords ; list ; list=g_slist_next(list)) { keyword = (gchar *) list->data; ret = get_basis(keyword, model); } } else if (g_ascii_strncasecmp(line, " $contrl", 8) == 0) { keywords = get_gamess_keywords(fp, line+8, &ret); for (list=keywords; list ; list=g_slist_next(list)) { keyword = (gchar *) list->data; ret = get_control(keyword, model); } } else if (g_ascii_strncasecmp(line, " $system", 8) == 0) { keywords = get_gamess_keywords(fp, line+8, &ret); for (list=keywords; list ; list=g_slist_next(list)) { keyword = (gchar *) list->data; ret = get_system(keyword, model); } } else if (g_ascii_strncasecmp(line, " $statpt", 8) == 0) { keywords = get_gamess_keywords(fp, line+8, &ret); for (list=keywords; list ; list=g_slist_next(list)) { keyword = (gchar *) list->data; ret = get_statpt(keyword, model); } } else if (g_ascii_strncasecmp(line, " $dft", 5) == 0) { model->gamess.dft = TRUE; /* TODO - process functional */ } else { /* TODO - Unknown keyword, just pass through */ } free_slist(keywords); g_free(line); return(TRUE); }
void camera_waypoint_animate(gint frames, gint overwrite, struct model_pak *model) { gint i; gdouble a, af, v[3], e[3], o[3], tmp[3]; gdouble jf, jv[3], x[3], mat[9]; GSList *list, *journey; struct camera_pak *cam, *cam1, *cam2; /* checks */ g_assert(model != NULL); g_assert(frames > 0); if (g_slist_length(model->waypoint_list) < 2) { gui_text_show(ERROR, "You need to make at least 2 waypoint.\n"); return; } /* close any active animation dialog */ dialog_destroy_type(ANIM); #if DEBUG_CAMERA_ANIMATE printf("frames for each traversal: %d\n", frames); #endif list = model->waypoint_list; cam1 = list->data; list = g_slist_next(list); /* create the camera journey */ journey = NULL; while (list) { cam2 = list->data; /* setup camera journey vector */ ARR3SET(jv, cam2->x); ARR3SUB(jv, cam1->x); /* add starting camera over journey leg */ for (i=0 ; i<frames ; i++) { /* journey fraction */ jf = i; jf /= frames; ARR3SET(x, jv); VEC3MUL(x, jf); cam = camera_dup(cam1); ARR3ADD(cam->x, x); journey = g_slist_prepend(journey, cam); } /* approx 5 degrees */ #define ROTATION_INCREMENT 0.08727 /* (v x e plane alignment) */ proj_vop(v, cam2->v, cam1->o); a = via(v, cam1->v, 3); /* compute rotation increment */ af = (gint) nearest_int(a / ROTATION_INCREMENT); if (!af) af = 1.0; /* test rotation sense */ matrix_v_rotation(mat, cam1->o, a); ARR3SET(tmp, cam1->v); vecmat(mat, tmp); if (via(tmp, v, 3) > 0.1) a *= -1.0; /* build rotaton */ matrix_v_rotation(mat, cam1->o, a/af); /* apply to camera */ ARR3SET(v, cam1->v); ARR3SET(e, cam1->e); for (i=af ; i-- ; ) { cam = camera_dup(cam1); ARR3SET(cam->x, cam2->x); vecmat(mat, v); vecmat(mat, e); ARR3SET(cam->v, v); ARR3SET(cam->e, e); journey = g_slist_prepend(journey, cam); } /* TODO - apply elevation to get v in complete coincidence */ /* rotate about e to achieve coincidence */ a = via(v, cam2->v, 3); /* compute rotation increment */ af = (gint) nearest_int(a / ROTATION_INCREMENT); if (!af) af = 1.0; /* test rotation sense */ matrix_v_rotation(mat, e, a); ARR3SET(tmp, v); vecmat(mat, tmp); if (via(tmp, cam2->v, 3) > 0.1) a *= -1.0; /* build rotaton */ matrix_v_rotation(mat, e, a/af); /* apply to camera */ ARR3SET(o, cam1->o); for (i=af ; i-- ; ) { cam = camera_dup(cam1); ARR3SET(cam->x, cam2->x); vecmat(mat, v); vecmat(mat, o); ARR3SET(cam->v, v); ARR3SET(cam->o, o); ARR3SET(cam->e, e); journey = g_slist_prepend(journey, cam); } /* endpoint camera */ journey = g_slist_prepend(journey, camera_dup(cam2)); /* get next journey leg */ cam1 = cam2; list = g_slist_next(list); } journey = g_slist_reverse(journey); if (overwrite) { free_slist(model->transform_list); model->transform_list = journey; } else model->transform_list = g_slist_concat(model->transform_list, journey); model->num_frames = g_slist_length(model->transform_list); model->animation = TRUE; redraw_canvas(SINGLE); }
gint reaxmd_parse_properties(FILE *fp, struct model_pak *model, gpointer import) { gint i, j, k, n=1, time_column=0, num_tokens, num_properties; gdouble frame_time=0.0, time, start, stop, value; gchar *line, *label, **buff; const gchar *xlabel, *ylabel; GSList *item, *list; GArray **property_array; #if DEBUG_REAXMD_PARSE_PROPERTIES printf("file_reaxmd(): parsing energy file...\n"); #endif /* checks */ if (!fp) return(FALSE); if (!import) return(FALSE); /* setup internal frame counter */ if (model) { n = g_list_length(model->animate_list); i=0; frame_time = str_to_float(animate_frame_property_get(i, "Time", model)); } // NB: file_read_line() skips comments by default, so it'll auto skip the header line file_skip_comment(FALSE); // process first line for column locations of time, energy, etc ... line = file_read_line(fp); // error handling if (!line) { return(FALSE); } if (strlen(line) < 2) { return(FALSE); } buff = g_strsplit(&line[1], "|", -1); list = NULL; if (buff) { j=0; while (buff[j]) { label = g_strstrip(buff[j]); if (strlen(label)) { if (g_strrstr(label, "Time")) { time_column = j; } list = g_slist_prepend(list, g_strdup(label)); } j++; } } g_strfreev(buff); g_free(line); line = file_read_line(fp); list = g_slist_reverse(list); #if DEBUG_REAXMD_PARSE_PROPERTIES for (item=list ; item ; item=g_slist_next(item)) { printf("[%s]\n", (gchar *) item->data); } printf("Allocating %d property arrays, with start size %d\n", g_slist_length(list), n); #endif // NB: exclude the first - time /* init arrays for properties */ num_properties = g_slist_length(list); property_array = g_malloc(num_properties * sizeof(GArray)); for (k=0 ; k<num_properties ; k++) { property_array[k] = g_array_sized_new(FALSE, FALSE, sizeof(gdouble), n); } /* iterate over all output data lines */ while (line) { buff = tokenize(line, &num_tokens); if (num_tokens > time_column) { time = str_to_float(buff[time_column]); /* NEW - grab all values for property graphs */ for (j=0 ; j<num_tokens ; j++) { if (j < num_properties) { value = str_to_float(buff[j]); g_array_append_val(property_array[j], value); } } /* if output data time matches internal frame frame - store */ if (model) { if (time >= frame_time) { /* add current output data to the internally stored frame */ item = list; for (j=0 ; j<num_tokens ; j++) { if (item) { //printf("[%d][%s][%s]\n", i, (gchar *) item->data, buff[j]); // add to actual model property list (reference frame only) // leave this out now, since we're auto constructing graphs anyway /* if (!i) { property_add_ranked(j, item->data, buff[j], model); } */ animate_frame_property_put(i, item->data, buff[j], model); } else break; item = g_slist_next(item); } /* update the internal frame count */ i++; frame_time = str_to_float(animate_frame_property_get(i, "Time", model)); } } } g_strfreev(buff); g_free(line); line = file_read_line(fp); } /* iterate property arrays and construct graphs */ xlabel = g_slist_nth_data(list, time_column); for (j=0 ; j<num_properties ; j++) { // don't graph time column if (j != time_column) { gpointer data, graph; k = property_array[j]->len; data = g_array_free(property_array[j], FALSE); start = g_array_index(property_array[time_column],gdouble,0); stop = g_array_index(property_array[time_column],gdouble,k-1); #if DEBUG_REAXMD_PARSE_PROPERTIES printf("Building graph for: %s with %d data points and ", (gchar *) g_slist_nth_data(list, j), k); printf("range: %f - %f\n", start, stop); #endif /* add graph if no ! prefix */ ylabel = g_slist_nth_data(list, j); if (!g_strrstr(ylabel, "!")) { /* create and attach graph object */ label = g_strndup(ylabel, 8); graph = graph_new(label); g_free(label); graph_set_data(k, data, start, stop, graph); graph_x_label_set(xlabel, graph); graph_y_label_set(ylabel, graph); import_object_add(IMPORT_GRAPH, graph, import); } } } g_array_free(property_array[time_column], TRUE); g_free(property_array); /* cleanup */ free_slist(list); return(0); }
static void match_end_func(void) { free_slist(&start_states); }
static void match_restore_states(struct expression *expr) { free_slist(&start_states); start_states = pop_slist(&saved_stack); }
void docking_project_create(GtkWidget *w, struct model_pak *model) { gint a, b, i, m, n, rx, ry, rz, size, rigid_save; gint a_max, b_max, rx_max, ry_max, rz_max; gchar *file, *dump, *dump_save, *rigid_move_save; gdouble dx, dy, dz, x[3], scale[3], mat[9], dock_centroid[3], q[4]; GString *name, *rigid; GSList *list, *core_list, *shell_list; struct dock_pak *dock; struct core_pak *core, *core2; struct shel_pak *shell, *shell2; FILE *fp; /* checks */ g_assert(model != NULL); size = g_slist_length(model->selection); if (!size) { gui_text_show(WARNING, "Please select the subset you wish to dock.\n"); return; } /* create new docking project */ dock = g_malloc(sizeof(struct dock_pak)); /* NEW - setup project path */ /* g_path_get_dirname(model->fullpath); g_get_current_dir(); */ /* seek a file name that doesn't exist (avoid background overwriting) */ name = g_string_new(NULL); i=0; do { g_string_sprintf(name, "project_%06d", i); i++; } while (g_file_test(name->str, G_FILE_TEST_EXISTS)); dock->path = g_build_path(sysenv.cwd, name->str, NULL); printf("creating new project: [%s]\n", dock->path); #if WIN32 if (mkdir(dock->path)) #else if (mkdir(dock->path, 0700)) #endif { gui_text_show(ERROR, "Failed to create project directory.\n"); g_free(dock->path); g_free(dock); return; } /* project control file */ g_string_sprintf(name, "%s%sproject.pcf", dock->path, DIR_SEP); fp = fopen(name->str, "wt"); /* save original variables */ dump_save = model->gulp.dump_file; model->gulp.dump_file = NULL; rigid_save = model->gulp.rigid; model->gulp.rigid = dock_rigid_on; rigid_move_save = model->gulp.rigid_move; model->gulp.rigid_move = NULL; if (model->gulp.rigid) { rigid = g_string_new(NULL); if (dock_rigid_x) g_string_sprintf(rigid, "x"); if (dock_rigid_y) g_string_sprintfa(rigid, "y"); if (dock_rigid_z) g_string_sprintfa(rigid, "z"); model->gulp.rigid_move = g_string_free(rigid, FALSE); } /* duplicate selection for docking */ core_list = NULL; shell_list = NULL; VEC3SET(dock_centroid, 0.0, 0.0, 0.0); for (list=model->selection ; list ; list=g_slist_next(list)) { core2 = dup_core(list->data); core_list = g_slist_prepend(core_list, core2); if (core2->shell) shell_list = g_slist_prepend(shell_list, core2->shell); /* compute centroid */ ARR3ADD(dock_centroid, core2->x); } /* NB: lists must have the same order as original selection */ core_list = g_slist_reverse(core_list); shell_list = g_slist_reverse(shell_list); VEC3MUL(dock_centroid, 1.0/(gdouble) size); /* fractional translation grid units */ scale[0] = dock_cell[0] / dock_grid[0]; scale[1] = dock_cell[1] / dock_grid[1]; /* rotational increments */ dx = PI/dock_rotate[0]; dy = PI/dock_rotate[1]; dz = PI/dock_rotate[2]; /* translational sampling */ if (dock_grid_on) { a_max = dock_grid[0]; b_max = dock_grid[1]; } else { a_max = 1; b_max = 1; } /* rotational sampling */ if (dock_rotate_on) { rx_max = dock_rotate[0]; ry_max = dock_rotate[1]; rz_max = dock_rotate[2]; } else { rx_max = 1; ry_max = 1; rz_max = 1; } /* project header */ fprintf(fp, "%%title solvent mapping project\n"); fprintf(fp, "%%set %d %d %f %f\n", a_max, b_max, dock_cell[0], dock_cell[1]); /* loop over all grid translations */ m = n = 0; for (a=0 ; a<a_max ; a++) { for (b=0 ; b<b_max ; b++) { VEC3SET(x, a, b, 0.0); x[0] *= scale[0]; x[1] *= scale[1]; /* loop over rotations */ VEC4SET(q, 1.0, 0.0, 0.0, 0.0); for (rx=0 ; rx<rx_max ; rx++) { if (rx) quat_concat_euler(q, PITCH, dx); for (ry=0 ; ry<ry_max ; ry++) { if (ry) quat_concat_euler(q, ROLL, dy); for (rz=0 ; rz<rz_max ; rz++) { if (rz) quat_concat_euler(q, YAW, dz); /* build total rotation matrix */ quat_matrix(mat, q); /* transform the cores and shells */ i = 0; for (list=model->selection ; list ; list=g_slist_next(list)) { core = list->data; /* FIXME - should we restore this after? how? */ core->region = 2; /* get original selection core coordinates */ core2 = g_slist_nth_data(core_list, i); ARR3SET(core->x, core2->x); /* perform the rotation (NB: must be done about origin in cartesian space) */ ARR3SUB(core->x, dock_centroid); vecmat(model->latmat, core->x); vecmat(mat, core->x); vecmat(model->ilatmat, core->x); ARR3ADD(core->x, dock_centroid); /* add the current translation offset */ ARR3ADD(core->x, x); /* as above, for the associated shell */ if (core->shell) { shell = core->shell; shell->region = 2; shell2 = core2->shell; g_assert(shell2 != NULL); ARR3SET(shell->x, shell2->x); ARR3SUB(shell->x, dock_centroid); vecmat(model->latmat, shell->x); vecmat(mat, shell->x); vecmat(model->ilatmat, shell->x); ARR3ADD(shell->x, dock_centroid); ARR3ADD(shell->x, x); } i++; } /* write docking configuration */ /* file = g_strdup_printf("%s_%06d.gin", model->basename, n); */ /* m identifies grid points (for later minimum check) */ fprintf(fp, "%s_%06d.gin %f %f %d\n", model->basename, n, x[0], x[1], m); file = g_strdup_printf("%s%s%s_%06d.gin", dock->path, DIR_SEP, model->basename, n); dump = g_strdup_printf("%s_%06d.res", model->basename, n); model->gulp.dump_file = dump; write_gulp(file, model); g_free(file); g_free(dump); n++; } } } m++; } } /* restore original variables */ model->gulp.dump_file = dump_save; model->gulp.rigid = rigid_save; g_free(model->gulp.rigid_move); model->gulp.rigid_move = rigid_move_save; /* restore original selection (delete, then concat saved list) */ i = 0; for (list=model->selection ; list ; list=g_slist_next(list)) { core = list->data; core2 = g_slist_nth_data(core_list, i); ARR3SET(core->x, core2->x); if (core->shell) { shell = core->shell; shell2 = core2->shell; g_assert(shell2 != NULL); ARR3SET(shell->x, shell2->x); } i++; } /* free docking core/shell lists */ free_slist(core_list); free_slist(shell_list); g_string_free(name, TRUE); fclose(fp); /* run docking in background unless told to stop after setup */ /* if (!dock_no_execute) submit_task("Docking", &docking_execute, dock, &docking_cleanup, dock, model); */ }
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); }