Beispiel #1
0
gint read_gms(gchar *filename, struct model_pak *model)
{
FILE *fp;
gchar line[LINELEN], *name;
gint have_basis = FALSE;

fp = fopen(filename, "rt");
if (!fp)
  {
  sprintf(line, "Unable to open file %s\n", filename);
  gui_text_show(ERROR, line);
  return(1);
  }
else
  {
  name = g_path_get_basename(filename);
  sprintf(line, "Opening %s: \n", name);
  g_free(name);
  gui_text_show(STANDARD, line);
  }

while (get_next_group(fp, model, &have_basis));

gui_text_show(STANDARD, "\n");

strcpy(model->filename, filename);
g_free(model->basename);
model->basename = parse_strip(filename);
model_prep(model);
return(0);
}
Beispiel #2
0
void anim_start(GtkWidget *w, gpointer data)
{
    gint freq;
    struct model_pak *model;

    /* don't allow more than one */
    model = dialog_model(data);
    g_assert(model != NULL);
    if (model->animating)
        return;

    /* timeout frequency */
    /* NB: we can't refresh any faster than units of 25 (ie the canvas redraw frequency) */
    freq = 25 * model->anim_speed;

    if (!model->transform_list)
    {
        model->afp = fopen(model->filename, "r");
        if (!model->afp)
        {
            gui_text_show(ERROR, "Failed to open animation stream.\n");
            return;
        }
    }

    g_timeout_add(freq, (GSourceFunc) &anim_next_frame, model);
    model->animating = TRUE;
}
gint reaxmd_output_coords_read(gpointer import)
{
gchar *fullname, *line;
FILE *fp;

#if DEBUG_READ_DCD
printf("Adding [dcd] data to file: %s\n", import_fullpath(import));
#endif

fullname = parse_extension_set(import_fullpath(import), "dcd");
if (!g_file_test(fullname, G_FILE_TEST_EXISTS))
  {
  gui_text_show(ERROR, "Failed to find associated .dcd file.\n");
  g_free(fullname);
  return(1);
  }

// TODO - if existing frames - assume replace mode
// otherwise create new frame at each step

/* NB: binary file data */
fp = fopen(fullname, "rb");
while (fp)
  {
  line = file_read_line(fp);
  if (!line)
    break;

  g_free(line);
  }

return(1);
}
Beispiel #4
0
gint get_system(gchar *keyword, struct model_pak *model)
{
int len;

if (g_ascii_strncasecmp(keyword, GMS_TIMLIM_TXT, len=strlen(GMS_TIMLIM_TXT)) == 0)
  model->gamess.time_limit = (gint) (str_to_float(&keyword[len]));
else if (g_ascii_strncasecmp(keyword, GMS_MWORDS_TXT, len=strlen(GMS_MWORDS_TXT)) == 0)
  model->gamess.mwords = (gint) (str_to_float(&keyword[len]));
else 
  {
  gui_text_show(ERROR, " unknown keyword ");
  gui_text_show(ERROR, keyword);
  gui_text_show(ERROR, " ");
  return(1);
  }
return(0);
}
Beispiel #5
0
void analysis_export(gchar *name)
{
struct model_pak *model;

model = sysenv.active_model;
g_assert(model != NULL);

dialog_destroy_type(FILE_SELECT);

if (model->graph_active)
  {
  graph_write(name, model->graph_active);
  gui_text_show(STANDARD, "Successfully exported graph.\n");
  }
else
  gui_text_show(WARNING, "Current model is not a graph.\n");
}
Beispiel #6
0
gint get_statpt(gchar *keyword, struct model_pak *model)
{
int len, tmp;

if (g_ascii_strncasecmp(GMS_METHOD_TXT, keyword, len=strlen(GMS_METHOD_TXT)) == 0)
  {
  tmp = model->gamess.opt_type;
  if (read_keyword(&keyword[len], method_types, &tmp) > 0)
    {
    gui_text_show(ERROR, " unknown method ");
    gui_text_show(ERROR, &keyword[len]);
    gui_text_show(ERROR, " ");
    return(1);
    }
  return(0);
  }
else if (g_ascii_strncasecmp(keyword, GMS_NSTEP_TXT, len=strlen(GMS_NSTEP_TXT)) == 0)
  model->gamess.nstep = str_to_float(&keyword[len]);
else
  {
  gui_text_show(ERROR, " unknown keyword ");
  gui_text_show(ERROR, keyword);
  gui_text_show(ERROR, " ");
  return(1);
  }
return(0);
}
Beispiel #7
0
gint get_basis(gchar *keyword, struct model_pak *model)
{
gint len, basis;

if (g_ascii_strncasecmp(GMS_BASIS_TXT, keyword, len=strlen(GMS_BASIS_TXT)) == 0)
  {
  if (read_keyword(&keyword[len], basis_types, &basis) > 0)
    {
    gui_text_show(ERROR, " unknown basis ");
    gui_text_show(ERROR, &keyword[len]);
    gui_text_show(ERROR, " ");
    return(1);
    }
  model->gamess.basis = basis;
  return(0);
  }
else if (g_ascii_strncasecmp(keyword, GMS_NGAUSS_TXT, len=strlen(GMS_NGAUSS_TXT)) == 0)
  model->gamess.ngauss = (gint) (str_to_float(&keyword[len]));
else if (g_ascii_strncasecmp(keyword, GMS_NUM_P_TXT, len=strlen(GMS_NUM_P_TXT)) == 0)
  model->gamess.num_p = str_to_float(&keyword[len]);
else if (g_ascii_strncasecmp(keyword, GMS_NUM_D_TXT, len=strlen(GMS_NUM_D_TXT)) == 0)
  model->gamess.num_d = str_to_float(&keyword[len]);
else if (g_ascii_strncasecmp(keyword, GMS_NUM_F_TXT, len=strlen(GMS_NUM_F_TXT)) == 0)
  model->gamess.num_f = str_to_float(&keyword[len]);
else if (g_ascii_strncasecmp(keyword, GMS_DIFFSP_TXT, len=strlen(GMS_DIFFSP_TXT)) == 0)
  model->gamess.have_heavy_diffuse = TRUE;
else if (g_ascii_strncasecmp(keyword, GMS_DIFFS_TXT, len=strlen(GMS_DIFFS_TXT)) == 0)
  model->gamess.have_hydrogen_diffuse = TRUE;
else 
  {
  gui_text_show(ERROR, " unknown keyword ");
  gui_text_show(ERROR, keyword);
  gui_text_show(ERROR, " ");
  return(1);
  }
return(0);
}
gint read_about_block(FILE *fp, struct model_pak *model)
{
gint i, num_tokens;
gchar **buff, line[LINELEN];
gdouble acell[3];
GString *title;
GSList *clist;
struct core_pak *core;

clist = model->cores;
if (optcell > 0)
  {
  /* go to acell line and read it */
  if (fgetline(fp, line))
    {
    gui_text_show(ERROR, "unexpected end of file reading cell dimensions in animation\n");
    return(2);
    }
  buff = tokenize(line, &num_tokens);
  acell[0] = str_to_float(*(buff+1)) * AU2ANG;
  acell[1] = str_to_float(*(buff+2)) * AU2ANG;
  acell[2] = str_to_float(*(buff+3)) * AU2ANG;
  g_strfreev(buff);

  /* get the cell vectors i.e. rprim.acell */
  /* NB: gdis wants transposed ABINIT matrix */
  for (i=0; i<3; i++)
    {
    if (fgetline(fp, line))
      {
      gui_text_show(ERROR, "unexpected end of file reading cell dimensions\n");
      return(2);
      }
    buff = tokenize(line + 8, &num_tokens);
    model->latmat[0+i] = acell[i] * str_to_float(*(buff+0));
    model->latmat[3+i] = acell[i] * str_to_float(*(buff+1));
    model->latmat[6+i] = acell[i] * str_to_float(*(buff+2));
    g_strfreev(buff);
    }

  for (i=0; i<4; i++)
    {
    if (fgetline(fp, line))
      {
      gui_text_show(ERROR, "unexpected end of file skipping to coordinates in animation\n");
      return(2);
      }
    }
  }
  
/* get 1st line of coords */
if (fgetline(fp, line))
  return(1);
buff = tokenize(line, &num_tokens);

while (g_ascii_strncasecmp(line, " Cartesian forces", 17) != 0)
  {
  if (clist)
    {
    core = (struct core_pak *) clist->data;
    clist = g_slist_next(clist);
    }
  else
    {
    core = new_core(*(buff+4), model);
    model->cores = g_slist_append(model->cores, core);
    }

  core->x[0] = AU2ANG*str_to_float(*(buff+0));
  core->x[1] = AU2ANG*str_to_float(*(buff+1));
  core->x[2] = AU2ANG*str_to_float(*(buff+2));
  #if DEBUG_READ_ABOUT
  printf("new coords %f %f %f\n", core->x[0],  core->x[1], core->x[2]);
  #endif

/* get next line */
  g_strfreev(buff);
  if (fgetline(fp, line))
    return(2);
  buff = tokenize(line, &num_tokens);
  }
  
/* get gradients */
model->abinit.max_grad = str_to_float(*(buff+4));
model->abinit.rms_grad = str_to_float(*(buff+5));
g_strfreev(buff);

/* get energy */
if (fgetline(fp, line))
  return(2);
while (g_ascii_strncasecmp(line, " At the end of Broyden", 22) != 0)
  {
  if (fgetline(fp, line))
    return(2);
  }
buff = tokenize(line, &num_tokens);
model->abinit.energy = str_to_float(*(buff+9));

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);
return(0);
}
Beispiel #9
0
gint anim_next_frame(struct model_pak *model)
{
    gulong time;
    gchar *text, *name;

    g_assert(model != NULL);

    /* increment and test if should we return to the start */
    model->cur_frame += model->anim_step;
    if (model->cur_frame >= model->num_frames)
        if (model->anim_loop)
            model->cur_frame = 1;

    /* continue until we run out of frames (or a stop is flagged) */
    if (model->cur_frame < model->num_frames && model->animating)
    {
#if DEBUG_DISPLAY_NEXT_FRAME
        printf("displaying [%d]\n", model->cur_frame);
#endif

        time = mytimer();

        /* if a dialog exists - update via the current frame spinner */
        if (dialog_exists(ANIM, model))
            gui_relation_update(model);
        else
        {
            /* otherwise, update manually */
            read_frame(model->afp, model->cur_frame, model);
            meas_graft_model(model);
            gui_active_refresh();
            redraw_canvas(SINGLE);
        }

        /* animation adjusted redraw time */
        time = mytimer() - time;
        model->redraw_cumulative += time;

        /* NEW - render to file */
        if (sysenv.render.animate)
        {
            text = g_strdup_printf("%s_%06d.pov", sysenv.render.animate_file, model->cur_frame);
            name = g_build_filename(sysenv.cwd, text, NULL);

            write_povray(name, model);

            /* NB: added this as jago keeps locking up on multi-frame renders */
            if (!sysenv.render.no_povray_exec)
                povray_exec(name);

            g_free(text);
            g_free(name);
        }

        return(TRUE);
    }

    /* FIXME - find a better way to do this... */
    if (!model->transform_list)
        fclose(model->afp);

    /* done animation */
    model->animating = FALSE;
    model->cur_frame--;

    /* create movie? */
    if (sysenv.render.animate && !sysenv.render.no_povray_exec)
    {
        text = NULL;
        switch (sysenv.render.animate_type)
        {
        case ANIM_GIF:
            text = g_strdup_printf("%s -delay %d %s_*.tga %s.gif",
                                   sysenv.convert_path,
                                   (gint) sysenv.render.delay,
                                   sysenv.render.animate_file, sysenv.render.animate_file);
            break;

        case ANIM_MPEG:
            text = g_strdup_printf("%s -quality %d -delay %d %s_*.tga %s.mpg",
                                   sysenv.convert_path, (gint) sysenv.render.mpeg_quality,
                                   (gint) sysenv.render.delay,
                                   sysenv.render.animate_file, sysenv.render.animate_file);
            break;
        }

        if (text)
        {
            system(text);
            g_free(text);
            gui_text_show(DEFAULT, "Completed movie creation.\n");
        }
    }

    /* cleanup */
    if (sysenv.render.no_keep_tempfiles)
    {
#ifndef __WIN32
        text = g_strdup_printf("rm -rf %s_*.pov", sysenv.render.animate_file);
        system(text);
        g_free(text);
        text = g_strdup_printf("rm -rf %s_*.tga", sysenv.render.animate_file);
        system(text);
        g_free(text);
#endif
        /* TODO - windows equivalents */
    }

    /* done - return FALSE to terminate the timer */
    return(FALSE);
}
Beispiel #10
0
gint get_control(gchar *keyword, struct model_pak *model)
{
gint len, bad_andrew;

if (g_ascii_strncasecmp(GMS_UNITS_TXT, keyword, len=strlen(GMS_UNITS_TXT)) == 0)
  {
  if (read_keyword(&keyword[len], units, &bad_andrew) > 0)
    {
    gui_text_show(ERROR, " unknown units ");
    gui_text_show(ERROR, &keyword[len]);
    gui_text_show(ERROR, " ");
    return(1);
    }
  model->gamess.units = bad_andrew;
  return(0);
  }
if (g_ascii_strncasecmp(GMS_EXETYPE_TXT, keyword, len=strlen(GMS_EXETYPE_TXT)) == 0)
  {
  if (read_keyword(&keyword[len], exe_types, &bad_andrew) > 0)
    {
    gui_text_show(ERROR, " unknown exetyp ");
    gui_text_show(ERROR, &keyword[len]);
    gui_text_show(ERROR, " ");
    return(1);
    }
  model->gamess.exe_type = bad_andrew;
  return(0);
  }

if (g_ascii_strncasecmp(GMS_RUNTYPE_TXT, keyword, len=strlen(GMS_RUNTYPE_TXT)) == 0)
  {
  if (read_keyword(&keyword[len], run_types, &bad_andrew) > 0)
    {
    gui_text_show(ERROR, " unknown runtyp ");
    gui_text_show(ERROR, &keyword[len]);
    gui_text_show(ERROR, " ");
    return(1);
    }
  model->gamess.run_type = bad_andrew;
  return(0);
  }

if (g_ascii_strncasecmp(GMS_SCFTYPE_TXT, keyword, len=strlen(GMS_SCFTYPE_TXT)) == 0)
  {
  if (read_keyword(&keyword[len], scf_types, &bad_andrew) > 0)
    {
    gui_text_show(ERROR, " unknown scftyp ");
    gui_text_show(ERROR, &keyword[len]);
    gui_text_show(ERROR, " ");
    return(1);
    }
  model->gamess.scf_type = bad_andrew;
  return(0);
  }

else if (g_ascii_strncasecmp(keyword, GMS_MAXIT_TXT, len=strlen(GMS_MAXIT_TXT)) == 0)
  model->gamess.maxit = (gint) (str_to_float(&keyword[len]));
else if (g_ascii_strncasecmp(keyword, GMS_TOTAL_Q_TXT, len=strlen(GMS_TOTAL_Q_TXT)) == 0)
  model->gamess.total_charge = (gint) (str_to_float(&keyword[len]));
else if (g_ascii_strncasecmp(keyword, GMS_MULT_TXT, len=strlen(GMS_MULT_TXT)) == 0)
  model->gamess.multiplicity = (gint) (str_to_float(&keyword[len]));
else if (g_ascii_strncasecmp(keyword, GMS_WIDE_OUTPUT_TXT, len=strlen(GMS_WIDE_OUTPUT_TXT)) == 0)
  model->gamess.wide_output = (((gint) (str_to_float(&keyword[len]))) == 6);
else if (g_ascii_strncasecmp(keyword, GMS_COORD_TXT, len=strlen(GMS_COORD_TXT)) == 0)
  ; /* TODO handle different coordinate types */
else 
  {
  gui_text_show(ERROR, " unknown keyword ");
  gui_text_show(ERROR, keyword);
  gui_text_show(ERROR, " ");
  return(1);
  }
return(0);
}
Beispiel #11
0
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);
}
Beispiel #12
0
gint get_data(FILE *fp, struct model_pak *model, gint have_basis)
{
gchar **buff, *line;
gint num_tokens;
struct core_pak *core;

/* process title line */
line = file_read_line(fp);
if (!line)
  {
  gui_text_show(ERROR, "unexpected end of file reading title\n");
  return(2);
  }
model->gamess.title = g_strstrip(line);

/* process symmetry line */
line = file_read_line(fp);
if (!line)
  {
  gui_text_show(ERROR, "unexpected end of file reading symmetry\n");
  return(2);
  }
if (g_ascii_strncasecmp(line, "c1", 2) != 0)
  {
  /* TODO handle symmetry! */
  gui_text_show(WARNING, "only C1 symmetry understood at present\n");
  }
g_free(line);

/* process coordinates */
line = file_read_line(fp);
if (!line)
  {
  gui_text_show(ERROR, "unexpected end of file reading coordinates\n");
  return(2);
  }

while (g_ascii_strncasecmp(line, " $end", 5) != 0)
  {
  buff = tokenize(line, &num_tokens);
  /* TODO Store GAMESS label and use in .inp files */

  if (num_tokens > 4)
    {
    core = new_core(elements[(int) str_to_float(*(buff+1))].symbol, model);
    if (model->gamess.units == GMS_ANGS)
      {
      core->x[0] = str_to_float(*(buff+2));
      core->x[1] = str_to_float(*(buff+3));
      core->x[2] = str_to_float(*(buff+4));
      }
    else
      {
      core->x[0] = str_to_float(*(buff+2)) * BOHR_TO_ANGS;
      core->x[1] = str_to_float(*(buff+3)) * BOHR_TO_ANGS;
      core->x[2] = str_to_float(*(buff+4)) * BOHR_TO_ANGS;
      }
    model->cores = g_slist_append(model->cores, core);
    g_strfreev(buff);
    if (!have_basis)
      {
      model->gamess.basis = GMS_USER;

/* TODO - read instead of skipping */
      for(;;)
        {
        line = file_read_line(fp);
        if (!line)
          break;

        buff = tokenize(line, &num_tokens);
        g_strfreev(buff);
        if (!num_tokens)
          break;
        }
      }
    }
/* get the next line */
  g_free(line);
  line = file_read_line(fp);
  if (!line)
    {
    gui_text_show(ERROR, "unexpected end of file reading coordinates\n");
    return(2);
    }
  }
g_free(line);
return(0);
}
Beispiel #13
0
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);
}
Beispiel #14
0
gint read_frame(FILE *fp, gint n, struct model_pak *model)
{
    gint status;
    gdouble rmax, v1[3], v2[3];
    gpointer camera=NULL;
    GString *err_text;

    g_assert(model != NULL);

    rmax = model->rmax;

    /* conventional or transformation style animation */
    if (model->transform_list)
    {
        /* NEW - process transformation list as an animation */
        status = read_transform(n, model);
    }
    else
    {
        g_assert(fp != NULL);

        ARR3SET(v1, model->centroid);
        ARR3SET(v2, model->offset);

        status = read_raw_frame(fp, n, model);
        if (status)
        {
            err_text = g_string_new("");
            g_string_printf(err_text, "Error reading frame: %d\n", n);
            gui_text_show(ERROR, err_text->str);
            g_string_free(err_text, TRUE);
            return(1);
        }

        /* setup (have to save camera) */
        camera = camera_dup(model->camera);
        model_prep(model);
        model->camera = camera;
        g_free(model->camera_default);
        model->camera_default = camera;

        ARR3SET(model->centroid, v1);
        ARR3SET(model->offset, v2);
    }

    /* apply desired constraint */
    if (model->periodic && !model->anim_fix)
    {
        switch (model->anim_confine)
        {
        case PBC_CONFINE_ATOMS:
            coords_confine_cores(model->cores, model);

        case PBC_CONFINE_MOLS:
            coords_compute(model);
            connect_bonds(model);
            connect_molecules(model);
            break;
        }
    }

    if (model->anim_noscale)
        model->rmax = rmax;

    return(0);
}
Beispiel #15
0
gint read_gms_out(gchar *filename, struct model_pak *model)
{
gint flag, frame, num_tokens, len, i, index, bad_andrew;
gchar **buff, line[LINELEN], *keyword, *option;
GString *property_string;
FILE *fp;

fp = fopen(filename, "rt");
if (!fp)
  {
  sprintf(line, "Unable to open file %s\n", filename);
  gui_text_show(ERROR, line);
  return(1);
  }

model->periodic = 0;
flag=frame=0;

/* read in BASIS OPTIONS */
while (!fgetline(fp, line))
  {
  if (g_ascii_strncasecmp(line, "     BASIS OPTIONS", 18) == 0)
    {
    /* skip line */
    if (fgetline(fp, line))
      {
      gui_text_show(ERROR, "unexpected end of file reading basis options\n");
      return(2);
      }
    if (fgetline(fp, line))
      {
      gui_text_show(ERROR, "unexpected end of file reading basis options\n");
      return(2);
      }
    /* get first line of options i.e. basis set */
    buff = tokenize(line, &num_tokens); 
    /* GBASIS=STO          IGAUSS=       3      POLAR=NONE */
    keyword = *(buff+0);
    if (g_ascii_strncasecmp(keyword, GMS_BASIS_TXT, len = strlen(GMS_BASIS_TXT)) == 0)
      {
      if (read_keyword(&keyword[len], basis_types, &bad_andrew) > 0)
        {
        sprintf(line, "invalid basis %s\n", &keyword[len]);
        gui_text_show(ERROR, line);
        return(3);
        }
      model->gamess.basis = bad_andrew;
      }
    model->gamess.ngauss = (gint) str_to_float(*(buff+2));
    g_strfreev(buff);
    
    /* get 2nd line of options i.e. NDFUNC and DIFFSP */
    if (fgetline(fp, line))
      {
      gui_text_show(ERROR, "unexpected end of file reading basis options\n");
      return(2);
      }
    buff = tokenize(line, &num_tokens);
    /* NDFUNC=       0     DIFFSP=       F */
    model->gamess.num_d = str_to_float(*(buff+1));
    if (g_ascii_strncasecmp(*(buff+3), "F", 1) == 0)
      model->gamess.have_heavy_diffuse = FALSE;
    else
      model->gamess.have_heavy_diffuse = TRUE;
    g_strfreev(buff);
      
    /* get 3rd line of options i.e. MULT and ICHARG */
    if (fgetline(fp, line))
      {
      gui_text_show(ERROR, "unexpected end of file reading basis options\n");
      return(2);
      }
    buff = tokenize(line, &num_tokens);
    /* NPFUNC=       0      DIFFS=       F */
    model->gamess.num_p = (gint) str_to_float(*(buff+1));
    if (g_ascii_strncasecmp(*(buff+3), "F", 1) == 0)
      model->gamess.have_hydrogen_diffuse = FALSE;
    else
      model->gamess.have_hydrogen_diffuse = TRUE;
    g_strfreev(buff);
      
    /* TODO f functions */
	flag++;
	break;
	}
  }

if (!flag)
  {
   /* no basis present so set to user defined and rewind file */
   model->gamess.basis = GMS_USER;
   rewind(fp);
  }
flag=0;

/* read in RUN TITLE */
while (!fgetline(fp, line))
  {
  if (g_ascii_strncasecmp(line, "     RUN TITLE", 14) == 0)
    {
    if (fgetline(fp, line))
      {
      gui_text_show(ERROR, "unexpected end of file reading title\n");
      return(2);
      }
    if (fgetline(fp, line))
      {
      gui_text_show(ERROR, "unexpected end of file reading title\n");
      return(2);
      }
    model->gamess.title = g_strdup(g_strstrip(line));
    flag++;
    break;
    }
  }

if (!flag)
  {
   gui_text_show(ERROR, "RUN TITLE not found\n");
   return(2);
  }
flag=0;

/* read in $CONTRL OPTIONS */
while (!fgetline(fp, line))
  {
  if (g_ascii_strncasecmp(line, "     $CONTRL OPTIONS", 20) == 0)
    {
    flag++;
    if (fgetline(fp, line))
      /* skip line of dashes */
      {
      gui_text_show(ERROR, "unexpected end of file reading contrl options\n");
      return(3);
      }
    while (TRUE)
      {
      if (fgetline(fp, line))
        {
        gui_text_show(ERROR, "unexpected end of file reading contrl options\n");
        return(3);
        }
      /* is the line the blank line signalling end of control options? */
      if (strlen(g_strchug(line)) == 0)
        break;
      /* break up line into option pairs */
      /* each pair takes 15 characters with 5 characters between them */
      /* note that we have already removed the single space in front of the lines with the g_strchug */
      index = 0;
      while (index+15 <= strlen(line))
        {
        option = g_strndup(line+index, 15);
        /* split into pair */
        buff = g_strsplit(option, "=", 2);
        g_free(option);
        /* remove whitespace */
        g_strstrip(buff[0]);
        g_strstrip(buff[1]);
        /* the compare strings end in = which we have stripped off so compare on strlen-1 */
        if (g_ascii_strncasecmp(buff[0], GMS_SCFTYPE_TXT, strlen(GMS_SCFTYPE_TXT) - 1) == 0)
          {
          if (read_keyword(buff[1], scf_types, &bad_andrew) > 0)
            {
            sprintf(line, "invalid scf type %s\n", buff[1]);
            gui_text_show(ERROR, line);
            return(3);
            }
          model->gamess.scf_type = bad_andrew;
          }
        else if (g_ascii_strncasecmp(buff[0], GMS_RUNTYPE_TXT, strlen(GMS_RUNTYPE_TXT) - 1) == 0)
          {
          if (read_keyword(buff[1], run_types, &bad_andrew) > 0)
            {
            sprintf(line, "invalid run type %s\n", buff[1]);
            gui_text_show(ERROR, line);
            return(3);
            }
          model->gamess.run_type = bad_andrew;
            property_string = g_string_new("");
            i=0;
            while (run_types[i].label)
              {
              if (model->gamess.run_type == run_types[i].id)
                g_string_append_printf(property_string, "%s", run_types[i].label);
              i++;
              }
            property_string->str[0] = g_ascii_toupper(property_string->str[0]);
            property_add_ranked(2, "Calculation", property_string->str, model);
            g_string_free(property_string, TRUE); 
          }
        else if (g_ascii_strncasecmp(buff[0], GMS_EXETYPE_TXT, strlen(GMS_EXETYPE_TXT) - 1) == 0)
          {
          if (read_keyword(buff[1], exe_types, &bad_andrew) > 0)
            {
            sprintf(line, "invalid execution type %s\n", buff[1]);
            gui_text_show(ERROR, line);
            return(3);
            }
          model->gamess.exe_type = bad_andrew;
          }
        else if (g_ascii_strncasecmp(buff[0], GMS_MPLEVEL_TXT, strlen(GMS_MPLEVEL_TXT) - 1) == 0)
        	model->gamess.MP_level = (gint) str_to_float(buff[1]);
        else if (g_ascii_strncasecmp(buff[0], GMS_CITYP_TXT, strlen(GMS_CITYP_TXT) - 1) == 0)
          if (g_ascii_strncasecmp(buff[1], "none", 4) == 0)
            model->gamess.have_CI = FALSE;
          else
            model->gamess.have_CI = TRUE;
        else if (g_ascii_strncasecmp(buff[0], GMS_CCTYP_TXT, strlen(GMS_CCTYP_TXT) - 1) == 0)
          if (g_ascii_strncasecmp(buff[1], "none", 4) == 0)
            model->gamess.have_CC = FALSE;
          else
            model->gamess.have_CC = TRUE;
        else if (g_ascii_strncasecmp(buff[0], GMS_TOTAL_Q_TXT, strlen(GMS_TOTAL_Q_TXT) - 1) == 0)
          model->gamess.total_charge = (gint) str_to_float(buff[1]);
        else if (g_ascii_strncasecmp(buff[0], GMS_MULT_TXT, strlen(GMS_MULT_TXT) - 1) == 0)
          model->gamess.multiplicity = (gint) str_to_float(buff[1]);
        else if (g_ascii_strncasecmp(buff[0], GMS_MAXIT_TXT, strlen(GMS_MAXIT_TXT) - 1) == 0)
          model->gamess.maxit = ((gint) str_to_float(buff[1]));
        else if (g_ascii_strncasecmp(buff[0], GMS_WIDE_OUTPUT_TXT, strlen(GMS_WIDE_OUTPUT_TXT) - 1) == 0)   
         model->gamess.wide_output = ((gint) str_to_float(buff[1]) == 6);

        g_strfreev(buff);
        index += 20;
        }
      }
      break;
    }
  }

if (!flag)
  {
/* don't return... model_prep() needs to be called to avoid crashing */
   gui_text_show(WARNING, "$CONTRL OPTIONS not found\n");
  }
flag=0;

/* read in $SYSTEM OPTIONS */
while (!fgetline(fp, line))
  {
  if (g_ascii_strncasecmp(line, "     $SYSTEM OPTIONS", 20) == 0)
    {
    if (fgetline(fp, line))
      {
      gui_text_show(ERROR, "unexpected end of file reading system options\n");
      return(4);
      }
    if (fgetline(fp, line))
      {
      gui_text_show(ERROR, "unexpected end of file reading system options\n");
      return(4);
      }
    buff = tokenize(line, &num_tokens);
    model->gamess.mwords = (gint) (str_to_float(*(buff+2))/1000000);
    g_strfreev(buff);
    
    for (i=0; i<4; i++)
      {
      if (fgetline(fp, line))
        {
        gui_text_show(ERROR, "unexpected end of file reading system options\n");
        return(4);
        }
      }
    buff = tokenize(line, &num_tokens);
    model->gamess.time_limit = (gint) (str_to_float(*(buff+1))/60.0);
    g_strfreev(buff);
    flag++;
    break;
    }
  }

if (!flag)
  {
/* don't return... model_prep() needs to be called to avoid crashing */
   gui_text_show(WARNING, "$SYSTEM OPTIONS not found\n");
  }
flag=0;

/* anything else to find ? */
while (!fgetline(fp, line))
  {
  if (g_ascii_strncasecmp(line, "                         GRADIENT OF THE ENERGY", 47) == 0)
    {
    if (fgetline(fp, line))
      {
      gui_text_show(ERROR, "unexpected end of file reading gradient\n");
      return(5);
      }
    while (g_ascii_strncasecmp(line, "                   MAXIMUM GRADIENT", 35) != 0) 
      {
      if (fgetline(fp, line))
        {
        gui_text_show(ERROR, "unexpected end of file reading gradient\n");
        return(5);
        }
      }
      buff = tokenize(line, &num_tokens);
      model->gamess.max_grad = str_to_float(*(buff+3));
      model->gamess.have_max_grad = TRUE;
      g_strfreev(buff);
      if (fgetline(fp, line))
        {
        gui_text_show(ERROR, "unexpected end of file reading gradient\n");
        return(5);
        }
      buff = tokenize(line, &num_tokens);
      model->gamess.rms_grad = str_to_float(*(buff+3));
      model->gamess.have_rms_grad = TRUE;
      g_strfreev(buff);
    }
  }

rewind(fp);

/* Read the input coordinates - single frame has different format to multiframe */
if (model->gamess.run_type < GMS_OPTIMIZE) { /* is it a single frame job? */
  while (!fgetline(fp, line))
    {
    if (g_ascii_strncasecmp(line, " ATOM      ATOMIC                      COORDINATES (BOHR)", 57) == 0)
      {
      read_gms_out_block(fp, model, 1, TRUE);
      flag++;
      break;
      }
    }
  }

else
  {
  /* get optimisation parameters */
  while (!fgetline(fp, line))
    {
    if (g_ascii_strncasecmp(line, "          STATIONARY POINT LOCATION RUN", 39) == 0)
      {
      for (i=0; i<7; i++)
        {
        if (fgetline(fp, line))
          {
          gui_text_show(ERROR, "unexpected end of file reading optimizer options\n");
          return(5);
          }
        }
      if (model->gamess.exe_type == GMS_CHECK)
        if (fgetline(fp, line))
          {
          gui_text_show(ERROR, "unexpected end of file reading optimizer options\n");
          return(5);
          }
      buff = tokenize(line, &num_tokens);
      if (read_keyword(&(*(buff+1))[1], method_types, &bad_andrew) > 0)
        {
        sprintf(line, "invalid method %s\n",&(*(buff+1))[1]);
        gui_text_show(ERROR, line);
        return(5);
        }
      model->gamess.opt_type = bad_andrew;
      g_strfreev(buff);
      flag++;
      if (fgetline(fp, line))
        {
        gui_text_show(ERROR, "unexpected end of file reading optimizer options\n");
        return(5);
        }
      if (fgetline(fp, line))
        {
        gui_text_show(ERROR, "unexpected end of file reading optimizer options\n");
        return(5);
        }
      buff = tokenize(line, &num_tokens);
      model->gamess.nstep = str_to_float(*(buff+2));
      g_strfreev(buff);
      flag++;
      break;
      }
    }
  if (!flag)
    {
    gui_text_show(ERROR, "optimizer options not found\n");
    return(5);
    }
  /* Are there any coordinates from a minimisation? */
  flag=0;
  while (!fgetline(fp, line) && !model->gamess.converged)
    {
    /* coordinates */
    if (g_ascii_strncasecmp(line, " COORDINATES OF ALL ATOMS ARE", 29) == 0)
      {
      /* go through all frames to count them */
      add_frame_offset(fp, model);
      read_gms_out_block(fp, model, 2, FALSE);
      flag++;
      frame++;
      }
    }
  }

/*  property_string = g_string_new("");
  g_string_append_printf(property_string, "%.0f", model->gamess.total_charge);
  property_add_ranked(2, "Total Charge", property_string->str, model);
  g_string_free(property_string, TRUE); 
  property_string = g_string_new("");
  g_string_append_printf(property_string, "%.0f", model->gamess.multiplicity);
  property_add_ranked(3, "Multiplicity", property_string->str, model);
  g_string_free(property_string, TRUE); */

  property_string = g_string_new("");
  i=0;
  while (basis_sets[i].label)
    {
    if ((basis_sets[i].basis == model->gamess.basis) && (basis_sets[i].ngauss == model->gamess.ngauss))
      g_string_append_printf(property_string, "%s", basis_sets[i].label);
    i++;
    }
  property_add_ranked(7, "Basis", property_string->str, model);
  g_string_free(property_string, TRUE); 

/* done */

if (flag)
  {
  /* set frame if don't want last? */
  strcpy(model->filename, filename);
  g_free(model->basename);
  model->basename = parse_strip(filename);

  model->num_frames = model->cur_frame = frame;
  model->cur_frame--;
  
  model_prep(model);
  }
else
  return(2);

return(0);
}
Beispiel #16
0
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);
}
Beispiel #17
0
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);
}
Beispiel #18
0
void gui_dock_dialog(void)
{
gchar *text;
gpointer dialog;
GtkWidget *window, *label, *spin;
GtkWidget *frame, *vbox, *vbox1, *hbox, *hbox2, *vbox_left, *vbox_right;
struct model_pak *model;

/* checks */
model = sysenv.active_model;
if (!model)
  {
  gui_text_show(ERROR, "Please load a surface first.\n");
  return;
  }
if (model->periodic != 2)
  {
  gui_text_show(ERROR, "Your model is not a surface.\n");
  return;
  }

/* request a dialog */
dialog = dialog_request(DOCKING, "Docking setup", NULL, NULL, model);
if (!dialog)
  return;
window = dialog_window(dialog);

/* title display */
frame = gtk_frame_new(NULL);
gtk_box_pack_start(GTK_BOX(GTK_DIALOG(window)->vbox), frame, FALSE, FALSE, 0);
vbox = gtk_vbox_new(TRUE, 0);
gtk_container_add(GTK_CONTAINER(frame), vbox);

gtk_container_set_border_width(GTK_CONTAINER(vbox), PANEL_SPACING);

hbox = gtk_hbox_new(FALSE, PANEL_SPACING);
gtk_box_pack_start(GTK_BOX(vbox), hbox, FALSE, FALSE, 0);
text = g_strdup_printf("Docking setup: %s", model->basename);
label = gtk_label_new(text);
gtk_box_pack_start(GTK_BOX(hbox), label, FALSE, FALSE, 0);
g_free(text);

/* NEW - split pane display */
hbox2 = gtk_hbox_new(FALSE, 0);
gtk_box_pack_start(GTK_BOX(GTK_DIALOG(window)->vbox), hbox2, TRUE, TRUE, 0);
vbox_left = gtk_vbox_new(FALSE, 0);
gtk_box_pack_start(GTK_BOX(hbox2), vbox_left, FALSE, FALSE, PANEL_SPACING);
vbox_right = gtk_vbox_new(FALSE, 0);
gtk_box_pack_start(GTK_BOX(hbox2), vbox_right, FALSE, FALSE, PANEL_SPACING);

/* translational sampling */
frame = gtk_frame_new(NULL);
gtk_box_pack_start(GTK_BOX(vbox_left), frame, FALSE, FALSE, 0);
vbox = gtk_vbox_new(FALSE, 0);
gtk_container_add(GTK_CONTAINER(frame), vbox);

vbox1 = gtk_vbox_new(FALSE, 0);
gui_direct_check("Translational sampling", &dock_grid_on,
                   dock_toggle_refresh, vbox1, vbox);
gtk_box_pack_start(GTK_BOX(vbox), vbox1, FALSE, FALSE, PANEL_SPACING);

/* axes sampling fraction */
hbox = gtk_hbox_new(FALSE, 0);
gtk_box_pack_start(GTK_BOX(vbox1), hbox, FALSE, FALSE, PANEL_SPACING);

label = gtk_label_new("axes fractions");
gtk_box_pack_start(GTK_BOX(hbox), label, FALSE, FALSE, PANEL_SPACING);

spin = gui_direct_spin(NULL, &dock_cell[0], 0.0, 1.0, 0.05, NULL, NULL, NULL);
gtk_box_pack_end(GTK_BOX(hbox), spin, FALSE, FALSE, PANEL_SPACING);

spin = gui_direct_spin(NULL, &dock_cell[1], 0.0, 1.0, 0.05, NULL, NULL, NULL);
gtk_box_pack_end(GTK_BOX(hbox), spin, FALSE, FALSE, PANEL_SPACING);

/* grid points */
hbox = gtk_hbox_new(FALSE, 0);
gtk_box_pack_start(GTK_BOX(vbox1), hbox, FALSE, FALSE, PANEL_SPACING);

label = gtk_label_new("grid size");
gtk_box_pack_start(GTK_BOX(hbox), label, FALSE, FALSE, PANEL_SPACING);

spin = gui_direct_spin(NULL, &dock_grid[0], 1, 10, 1, NULL, NULL, NULL);
gtk_box_pack_end(GTK_BOX(hbox), spin, FALSE, FALSE, PANEL_SPACING);

spin = gui_direct_spin(NULL, &dock_grid[1], 1, 10, 1, NULL, NULL, NULL);
gtk_box_pack_end(GTK_BOX(hbox), spin, FALSE, FALSE, PANEL_SPACING);

/* rotational sampling */
frame = gtk_frame_new(NULL);
gtk_box_pack_start(GTK_BOX(vbox_left), frame, TRUE, TRUE, 0);
vbox = gtk_vbox_new(FALSE, 0);
gtk_container_add(GTK_CONTAINER(frame), vbox);

vbox1 = gtk_vbox_new(TRUE, PANEL_SPACING);
gui_direct_check("Rotational sampling", &dock_rotate_on, dock_toggle_refresh, vbox1, vbox);
gtk_box_pack_start(GTK_BOX(vbox), vbox1, FALSE, FALSE, PANEL_SPACING);
gui_direct_spin("  x axis ", &dock_rotate[0], 1, 60, 1, NULL, NULL, vbox1);
gui_direct_spin("  y axis ", &dock_rotate[1], 1, 60, 1, NULL, NULL, vbox1);
gui_direct_spin("  z axis ", &dock_rotate[2], 1, 60, 1, NULL, NULL, vbox1);

/* rigid body docking */
frame = gtk_frame_new(NULL);
gtk_box_pack_start(GTK_BOX(vbox_right), frame, FALSE, FALSE, 0);
vbox = gtk_vbox_new(FALSE, 0);
gtk_container_add(GTK_CONTAINER(frame), vbox);

vbox1 = gtk_vbox_new(TRUE, PANEL_SPACING);
gui_direct_check("Treat as a rigid body", &dock_rigid_on, dock_toggle_refresh, vbox1, vbox);
gtk_box_pack_start(GTK_BOX(vbox), vbox1, FALSE, FALSE, PANEL_SPACING);

gui_direct_check("Allow translation in x", &dock_rigid_x, NULL, NULL, vbox1);
gui_direct_check("Allow translation in y", &dock_rigid_y, NULL, NULL, vbox1);
gui_direct_check("Allow translation in z", &dock_rigid_z, NULL, NULL, vbox1);

/* control options */
frame = gtk_frame_new(NULL);
gtk_box_pack_start(GTK_BOX(vbox_right), frame, FALSE, FALSE, 0);
vbox = gtk_vbox_new(TRUE, 0);
gtk_container_add(GTK_CONTAINER(frame), vbox);
hbox = gtk_hbox_new(FALSE, PANEL_SPACING);
gui_direct_check("Create project files then stop", &dock_no_execute, NULL, NULL, vbox);

/* CURRRENT - executing the project has not been implemented yet */
gtk_widget_set_sensitive(GTK_WIDGET(vbox), FALSE);

/* control buttons */
gui_stock_button(GTK_STOCK_EXECUTE, docking_project_create, model,
                   GTK_DIALOG(window)->action_area);
gui_stock_button(GTK_STOCK_CLOSE, dialog_destroy, dialog,
                   GTK_DIALOG(window)->action_area);

gtk_widget_show_all(window);
}
Beispiel #19
0
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);
*/
}
Beispiel #20
0
gint read_gms_out_block(FILE *fp, struct model_pak *model, gint num_skip, gint bohr)
{
gint i, num_tokens;
gchar **buff, line[LINELEN];
GString *title, *energy_string, *grad_string;
GSList *clist;
struct core_pak *core;

clist = model->cores;

/* ignore first num_skip lines */
for (i=0 ; i<num_skip; i++)
  if (fgetline(fp, line))
    {
    gui_text_show(ERROR, "unexpected end of file reading coordinates\n");
    return(11);
    }

model->construct_pbc = FALSE;
model->fractional = FALSE;

/* get 1st line of coords */
if (fgetline(fp, line))
    {
    gui_text_show(ERROR, "unexpected end of file reading coordinates\n");
    return(11);
    }
buff = tokenize(line, &num_tokens);

while (num_tokens > 4)
  {
  if (clist)
    {
    core = clist->data;
    clist = g_slist_next(clist);
    }
  else
    {
    core = new_core(elements[(int) str_to_float(*(buff+1))].symbol, model);
    model->cores = g_slist_append(model->cores, core);
    }

  if (bohr)
    {
    core->x[0] = BOHR_TO_ANGS*str_to_float(*(buff+2));
    core->x[1] = BOHR_TO_ANGS*str_to_float(*(buff+3));
    core->x[2] = BOHR_TO_ANGS*str_to_float(*(buff+4));
    }
  else
    {
    core->x[0] = str_to_float(*(buff+2));
    core->x[1] = str_to_float(*(buff+3));
    core->x[2] = str_to_float(*(buff+4));
    }

/* get next line */
  g_strfreev(buff);
  if (fgetline(fp, line))
    {
    gui_text_show(ERROR, "unexpected end of file reading coordinates\n");
    return(11);
    }
  buff = tokenize(line, &num_tokens);
  }
g_strfreev(buff);
  
/* search for energy */
while (!fgetline(fp, line))
  {
  if (g_ascii_strncasecmp(line, " FINAL", 6) == 0)
    {
    buff = tokenize(line, &num_tokens);
    if (g_ascii_strncasecmp(*(buff+1), "ENERGY", 6) == 0)
      model->gamess.energy = str_to_float(*(buff+3));
    else
      model->gamess.energy = str_to_float(*(buff+4));
    model->gamess.have_energy = TRUE;
    g_strfreev(buff);
    break;
    }
  }

/* update for MP? */
if (model->gamess.MP_level > 0)
  {
  while (!fgetline(fp, line))
    {
    if (g_strrstr(line ,"E(MP2)") != NULL)
      {
      buff = tokenize(line, &num_tokens);
      model->gamess.energy = str_to_float(*(buff+1));
      model->gamess.have_energy = TRUE;
      g_strfreev(buff);
      break;
      }
    }
  }

/* search for gradient and read any properties */
while (!fgetline(fp, line))
  {
  if (g_ascii_strncasecmp(line, " NET CHARGES:", 13) == 0)
    {
    clist = model->cores;
    /* skip forward four lines */
    for (i=0 ; i<4; i++)
      if (fgetline(fp, line))
        {
        gui_text_show(ERROR, "unexpected end of file reading fitted charges\n");
        return(11);
        }
    while (clist != NULL)
      {
      buff = tokenize(line, &num_tokens);
      core = clist->data;
      core->lookup_charge = FALSE;
      core->charge = str_to_float(*(buff+1));
      g_strfreev(buff);
      clist = g_slist_next(clist);
      if (fgetline(fp, line))
        {
        gui_text_show(ERROR, "unexpected end of file reading fitted charges\n");
        return(11);
        }
      }
    }
  if (g_ascii_strncasecmp(line, "          MAXIMUM GRADIENT", 26) == 0)
    {
    buff = tokenize(line, &num_tokens);
    model->gamess.max_grad = str_to_float(*(buff+3));
    model->gamess.have_max_grad = TRUE;
    model->gamess.rms_grad = str_to_float(*(buff+7));
    model->gamess.have_rms_grad = TRUE;
    g_strfreev(buff);
    /* check next line to see if converged */
    if (fgetline(fp, line))
      {
      gui_text_show(ERROR, "unexpected end of file reading equilibrium status\n");
      return(11);
      }
    if (g_ascii_strncasecmp(line, "1     ***** EQUILIBRIUM GEOMETRY LOCATED *****", 46) == 0)
      model->gamess.converged = TRUE;
    break;
    }
  }
g_free(model->title);
title = g_string_new("");
if (model->gamess.have_energy)
  {
  energy_string = g_string_new("");
  g_string_append_printf(energy_string, "%.5f H", model->gamess.energy);
  property_add_ranked(3, "Energy", energy_string->str, model);
  g_string_free(energy_string, TRUE); 
  g_string_append_printf(title, "E");
  if (model->gamess.MP_level > 0)
    g_string_append_printf(title, "(MP%d)", model->gamess.MP_level);
  g_string_append_printf(title, " = %.5f H", model->gamess.energy);
  }
if (model->gamess.have_rms_grad)
  {
  grad_string = g_string_new("");
  g_string_append_printf(grad_string, "%.4f H/B", model->gamess.rms_grad);
  property_add_ranked(4, "RMS Gradient", grad_string->str, model);
  g_string_free(grad_string, TRUE); 
  g_string_append_printf(title, ", grad = %.5f", model->gamess.rms_grad);
  }
if (model->gamess.have_max_grad)
  {
  grad_string = g_string_new("");
  g_string_append_printf(grad_string, "%.4f H/B", model->gamess.max_grad);
  property_add_ranked(4, "Maximum Gradient", grad_string->str, model);
  g_string_free(grad_string, TRUE); 
  }
model->title = g_strdup(title->str);
g_string_free(title, TRUE);

return(0);
}
Beispiel #21
0
// no coords - just control data for the run
// coords - .pdb file
// topology - .frx file
gint reaxmd_input_import(gpointer import)
{
gint *symbols, num_symbols, unknown;
gchar *line, *fullname_model;
gchar *filename, *filepath;
gpointer scan, config;
GString *unparsed;
struct reaxmd_pak *reaxmd;
struct model_pak *model;
FILE *fp;

scan = scan_new(import_fullpath(import));
if (!scan)
  return(1);

/* populate symbol table */
reaxmd_symbols_init(scan);

config = config_new(REAXMD, NULL);
reaxmd = config_data(config);

unparsed = g_string_new(NULL);

while (!scan_complete(scan))
  {
  symbols = scan_get_symbols(scan, &num_symbols);
  if (num_symbols)
    {
    unknown = FALSE;
/* process first recognized symbol */
    switch (symbols[0])
      {
      case REAXMD_NSTEPS:
        reaxmd->total_steps = parse_nth_token_dup(1, scan_cur_line(scan));
        break;

      case REAXMD_TIMESTEP:
      case REAXMD_TEMPERATURE:
      case REAXMD_THERMOSTAT:
      case REAXMD_BAROSTAT:
      case REAXMD_CUTOFF:
      case REAXMD_UPDATE:
      case REAXMD_NWRITE:
      case REAXMD_GRID:
        break;

      case REAXMD_PLUMED_FILE:
        filename = parse_nth_token_dup(1, scan_cur_line(scan));
        filepath = g_build_filename(import_path(import), filename, NULL);
//printf("Looking for: %s\n", filepath);
        if (g_file_test(filepath, G_FILE_TEST_EXISTS))
          project_job_file_append(NULL, filepath, sysenv.workspace);
        else
          gui_text_show(ERROR, "REAXMD plumed file was not found!\n"); 
        g_free(filename);
        g_free(filepath);
        break;

      default:
        unknown = TRUE;
      }
    g_free(symbols);
    }
  else
    unknown=TRUE;

  if (unknown)
    {
    line = scan_cur_line(scan);
    if (line)
      g_string_append(unparsed, line);
    }
  }

config_unparsed_set(g_string_free(unparsed, FALSE), config);
/* CURRENT - free this, until we add a GUI */
//import_object_add(IMPORT_CONFIG, config, import);
config_free(config);

/* done irx parse */
scan_free(scan);

/* NEW - attempt to load reference coordinates */
fullname_model = parse_extension_set(import_fullpath(import), "pdb");
fp = fopen(fullname_model, "rt");
if (fp)
  {
  model = model_new();
  read_pdb_block(fp, model);
  fclose(fp);
  import_object_add(IMPORT_MODEL, model, import);
  }
else
  {
  gui_text_show(WARNING, "Failed to open reference PDB model for ReaxMD.\n");
  }
g_free(fullname_model);

/* init */
import_init(import);

return(0);
}
Beispiel #22
0
gint region_move_atom(struct core_pak *core, gint direction,
                                    struct model_pak *data)
{
gint flag, primary, secondary, mov[2];
gdouble vec[3], tmp[3], d[3];
GSList *list;
struct core_pak *comp;

#if DEBUG_REGION_SWITCH_ATOM
printf("       model: %s\n", data->basename);
printf(" periodicity: %d\n", data->periodic);
printf("         hkl: %f %f %f\n", data->surface.miller[0],
          data->surface.miller[1], data->surface.miller[2]);
printf("        dhkl: %f\n", data->surface.dspacing);
printf("region sizes: %f %f\n", data->surface.region[0], data->surface.region[1]);
printf("      moving: ");
if (direction == UP)
  printf("UP\n");
else
  printf("DOWN\n");
#endif

/* checks */
g_return_val_if_fail(data != NULL, 1);
g_return_val_if_fail(data->periodic == 2, 1);
if (data->surface.region[0] < 1)
  {
  gui_text_show(ERROR, "region 1 is empty.\n");
  return(1);
  }

/* setup region switching labels */
if (direction == UP)
  {
  primary = REGION1A;
  secondary = REGION2A;
  }
else
  {
  primary = REGION2A;
  secondary = REGION1A;
  }

/* get fractional depth translation vector */
ARR3SET(vec, data->surface.depth_vec);
vecmat(data->ilatmat, vec);

/* calculate offset to region boundary */
ARR3SET(tmp, vec);
if (direction == DOWN)
  {
  VEC3MUL(tmp, data->surface.region[0]);
  VEC3MUL(tmp, -1.0);
  }
else
  {
  if (data->surface.region[1] == 0)
    {
    VEC3MUL(tmp, data->surface.region[0]);
    }
  else
    {
    VEC3MUL(tmp, data->surface.region[1]);
    }
  }

/* if region 2 is empty, just move core to the bottom */
if (data->surface.region[1] == 0.0)
  {
  ARR3ADD(core->x, tmp);
  if (core->shell)
    {
    ARR3ADD((core->shell)->x, tmp);
    }
  atom_colour_scheme(data->colour_scheme, core, data);
  return(0);
  }

/* get coordinates of target atom */
ARR3ADD(tmp, core->x);

#if DEBUG_REGION_SWITCH_ATOM
P3VEC("    translation: ", vec);
P3VEC("  target coords: ", tmp);
#endif

/* find the target */
flag=0;
for (list=data->cores ; list ; list=g_slist_next(list))
  {
  comp = list->data;

/* only atoms of the same type need apply */
  if (core->atom_code != comp->atom_code)
    continue;

/* get difference vector */
  ARR3SET(d, comp->x);
  ARR3SUB(d, tmp);

/* pbc constraint */
  while(d[0] < -FRACTION_TOLERANCE)
    d[0] += 1.0;
  while(d[0] > 0.5)
    d[0] -= 1.0;
  while(d[1] < -FRACTION_TOLERANCE)
    d[1] += 1.0;
  while(d[1] > 0.5)
    d[1] -= 1.0;

/* test difference vector's magnitude */
  if (VEC3MAGSQ(d) < FRACTION_TOLERANCE)
    {
/* change its labelling */
#if DEBUG_REGION_SWITCH_ATOM
printf("Matched core: %p\n", comp);
#endif
    comp->region = secondary;
    if (comp->shell)
      {
      (comp->shell)->region = secondary;
      }
    atom_colour_scheme(data->colour_scheme, comp, data);
    flag++;
    break;
    }
  }

if (!flag)
  {
  gui_text_show(ERROR, "Failed to find a boundary image.\n");
  return(1);
  }

/* now move selected atom to bottom of region 2 */
ARR3SET(tmp, vec);
VEC3MUL(tmp, (data->surface.region[0] + data->surface.region[1]));
if (direction == UP)
  VEC3MUL(tmp, -1.0);
ARR3SUB(core->x, tmp);
core->region = primary;
/* pbc constrain */
fractional_clamp(core->x, mov, 2);

if (core->shell)
  {
  ARR3SUB((core->shell)->x, tmp);
  ARR2ADD((core->shell)->x, mov);
  (core->shell)->region = primary;
  }

atom_colour_scheme(data->colour_scheme, core, data);

return(0);
}
Beispiel #23
0
gint reaxmd_output_import(gpointer import)
{
gint status=0;
gchar *fullname_model, *fullname_energy, *fullname_coords, *fullname_velos;
struct model_pak *model=NULL;
FILE *fp_m, *fp_c, *fp_e, *fp_v;

if (!import)
  return(1);

fullname_model = parse_extension_set(import_fullpath(import), "pdb");
fullname_coords = parse_extension_set(import_fullpath(import), "dcd");
fullname_energy = parse_extension_set(import_fullpath(import), "erx");
fullname_velos = parse_extension_set(import_fullpath(import), "vrx");

fp_m = fopen(fullname_model, "rt");
fp_e = fopen(fullname_energy, "rt");
fp_c = fopen(fullname_coords, "rb");
fp_v = fopen(fullname_velos, "rb");

// bare minimum parse
if (fp_m)
  {
  model = model_new();
  read_pdb_block(fp_m, model);
  fclose(fp_m);
  }
else
  {
  status = 1;
  gui_text_show(ERROR, "Failed to open reference PDB model for ReaxMD.\n");
  goto reaxmd_output_import_cleanup;
  }

// main extra data (coords)
if (fp_c)
  {
  reaxmd_parse_coordinates(fp_c, model);
  fclose(fp_c);
  }

// optional extra data (velocities)
if (fp_v)
  {
  reaxmd_parse_velocities(fp_v, model);
  fclose(fp_v);
  }

// optional extra data (energy, temp, etc)
// CURRENT - only read corresponding values for which we have coord frames
if (fp_e)
  {
  reaxmd_parse_properties(fp_e, model, import);
  fclose(fp_e);
  }

// init
if (model)
  import_object_add(IMPORT_MODEL, model, import);

import_init(import);

#if DEBUG_REAXMD_OUTPUT
animate_debug(model);
#endif

// done
reaxmd_output_import_cleanup:

g_free(fullname_model);
g_free(fullname_coords);
g_free(fullname_energy);
g_free(fullname_velos);

return(status);
}
Beispiel #24
0
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);
}
Beispiel #25
0
/* TODO - relocate */
gint siesta_phonon_calc(struct model_pak *model)
{
    gint num_tokens, num_atoms, num_lines, i, j, k, l;
    gchar ** buff;
    gchar * modelFCname, *modelFCnameCSV;
    gdouble wi, wj, value;
    gpointer bigmat, correction_mat, mini_correction_zerooooo_mat;
    GSList *list_i, *list_j;
    struct core_pak *core_i;
    struct core_pak *core_j;
    FILE *fp, *matout=NULL;

    g_assert(model != NULL);

    /* check atom labels (since we must be able to do a valid weight lookup) */
    for (list_i=model->cores ; list_i ; list_i=g_slist_next(list_i))
    {
        core_i = list_i->data;
        if (core_i->atom_code == 0)
        {
            gchar *text;

            text = g_strdup_printf("Unknown atom label: [%s]\n", core_i->atom_label);
            gui_text_show(ERROR, text);
            g_free(text);

            return(1);
        }
    }

    num_atoms = model->num_atoms;

//lines = 3 *    N * N     * 2;
//       xyz, each atom, back/forward
//
    num_lines = 3*2*num_atoms*num_atoms;

    modelFCname = g_strdup_printf("%s/%s.FC", sysenv.cwd, model->basename);
    modelFCnameCSV = g_strdup_printf("%s.csv", modelFCname);

    fp = fopen(modelFCname, "rt");

    if (siestafileWRITE)
    {
        matout = fopen(modelFCnameCSV, "w");
        if (!matout)
        {
            gui_text_show(ERROR, "bugger - no save files\n");
            return(2);
        }
    }

    if (!fp)
    {
        gchar * text;
        text = g_strdup_printf("*ERROR* - modelFCname file not opened\n");
        gui_text_show(ERROR, text);
        gui_text_show(ERROR, modelFCname);
        gui_text_show(ERROR, "\n");
        g_free(text);
        return(3);
    }

//no need for names anymore
    g_free(modelFCname);

//initalise bigmat
    bigmat = mesch_mat_new(3*num_atoms, 3*num_atoms);

//first line is crap.
    buff = get_tokenized_line(fp, &num_tokens);

//FILE reading into bigmat
    for (i = 0; i<num_lines; i++)
    {
        g_strfreev(buff);
        buff = get_tokenized_line(fp, &num_tokens);
        if (!buff)
        {
//error not enough lines in file...
//matrix_2d_free(bigmat);
        }

        if (num_tokens > 2)
        {
            if ( (i/num_atoms)%2 == 0)
            {
//first pass at row?

                mesch_me_set(bigmat, i/(2*num_atoms), (3*i)%(3*num_atoms), str_to_float(*buff));
                mesch_me_set(bigmat, i/(2*num_atoms), ((3*i)+1)%(3*num_atoms), str_to_float(*(buff+1)));
                mesch_me_set(bigmat, i/(2*num_atoms), ((3*i)+2)%(3*num_atoms), str_to_float(*(buff+2)));

            }
            else
            {
//second pass - do the average

                value = 0.5*(mesch_me_get(bigmat, i/(2*num_atoms), (3*i)%(3*num_atoms)) + str_to_float(*buff));
                mesch_me_set(bigmat, i/(2*num_atoms), (3*i)%(3*num_atoms), value);

                value = 0.5*(mesch_me_get(bigmat, i/(2*num_atoms), ((3*i)+1)%(3*num_atoms)) + str_to_float(*(buff+1)));
                mesch_me_set(bigmat, i/(2*num_atoms), ((3*i)+1)%(3*num_atoms), value);

                value = 0.5*(mesch_me_get(bigmat, i/(2*num_atoms), ((3*i)+2)%(3*num_atoms)) + str_to_float(*(buff+2)));
                mesch_me_set(bigmat, i/(2*num_atoms), ((3*i)+2)%(3*num_atoms), value);

            }
        }
        else
        {
//what happened - why is there not 3 things on the line?
//matrix_2d_free(bigmat);
        }
//next line?
    }

//Symmetricalise? -> to make symmetric
    for (i=0; i<(3*num_atoms); i++)
    {
        for (j=0; j<(3*num_atoms); j++)
        {
            value = mesch_me_get(bigmat, i, j) + mesch_me_get(bigmat, j, i);
            value *= 0.5;
            mesch_me_set(bigmat, i, j, value);
            mesch_me_set(bigmat, j, i, value);
        }
    }

    correction_mat = mesch_mat_new(3*num_atoms,3);
    mini_correction_zerooooo_mat = mesch_mat_new(3,3);

    mesch_m_zero(correction_mat);
    mesch_m_zero(mini_correction_zerooooo_mat);


//build the correction_matrix

    for (i=0; i<mesch_rows_get(bigmat); i++)
    {
        for (j=0; j<mesch_cols_get(bigmat)/3; j++)
        {
//[3n][3] -> [i][0], [i][1], [i][2]

            value = mesch_me_get(bigmat, i, 3*j);
            mesch_me_add(correction_mat, i, 0, value);

            value = mesch_me_get(bigmat, i, (3*j)+1);
            mesch_me_add(correction_mat, i, 1, value);

            value = mesch_me_get(bigmat, i, (3*j)+2);
            mesch_me_add(correction_mat, i, 2, value);
        }

//average each cell per row in the correction matrix
        value = 1.0 / (gdouble) num_atoms;

        mesch_me_mul(correction_mat, i, 0, value);
        mesch_me_mul(correction_mat, i, 1, value);
        mesch_me_mul(correction_mat, i, 2, value);
    }


//built mini matrix - [3][3]
    for (i=0; i<mesch_rows_get(correction_mat); i++)
    {
        for (j=0; j<mesch_cols_get(correction_mat); j++)
        {
            value = mesch_me_get(correction_mat, i, j);
            mesch_me_add(mini_correction_zerooooo_mat, i%3, j, value);
        }
    }

//average the cells in mini_correction_zerooooo_mat

    value = 1.0 / (gdouble) num_atoms;

    for (i=0; i<mesch_rows_get(mini_correction_zerooooo_mat); i++)
    {
        for (j=0; j<mesch_cols_get(mini_correction_zerooooo_mat); j++)
        {
            mesch_me_mul(mini_correction_zerooooo_mat, i, j, value);
        }
    }

//zero point correction
//    crappy crappy fortran loop that i dont understand
//       do i=1,natoms
//         do j=1,natoms
//           do ii=1,3
//             do ij=1,3
//               correct = (zeroo(ii,ij)+zeroo(ij,ii))/2.0d0 -
//                         (zero(ii,ij,j)+zero(ij,ii,i))
//               do lx=-lxmax,lxmax
//               do ly=-lymax,lymax
//               do lz=-lzmax,lzmax
//                 phi(ii,i,ij,j,lx,ly,lz) = phi(ii,i,ij,j,lx,ly,lz) +
//                                           correct
//               enddo
//               enddo
//               enddo
//             enddo
//           enddo
//         enddo
//       enddo

    gdouble correction;
    for (i=0; i<num_atoms; i++)
    {
        for (j=0; j<num_atoms; j++)
        {
            for (k=0; k<3; k++) //(ii)
            {
                for (l=0; l<3; l++) //(ij)
                {
// THIS WORKS - I HAVE TESTED IT - MANY TIMES......
                    correction = mesch_me_get(mini_correction_zerooooo_mat, k, l);
                    correction += mesch_me_get(mini_correction_zerooooo_mat, l, k);
                    correction *= 0.5;
                    correction -= mesch_me_get(correction_mat, 3*i+k, l);
                    correction -= mesch_me_get(correction_mat, 3*j+l, k);

                    mesch_me_add(bigmat, 3*i+k, 3*j+l, correction);
                }
            }
        }
    }

    i=j=0;

    for (list_i=model->cores ; list_i ; list_i=g_slist_next(list_i))
    {
        core_i = list_i->data;
        if (core_i->status & DELETED)
        {
            i++;
            continue;
        }

        wi = elements[core_i->atom_code].weight;
        g_assert(wi > G_MINDOUBLE);

        for (list_j=model->cores ; list_j ; list_j=g_slist_next(list_j))
        {
            core_j = list_j->data;
            if (core_j->status & DELETED)
            {
                j++;
                continue;
            }
//multi i rows.... 3 of them....

            wj = elements[core_j->atom_code].weight;
            g_assert(wj > G_MINDOUBLE);
            value  = 1.0 / sqrt(wi * wj);

            for (k=0; k<3; k++)
            {
                mesch_me_mul(bigmat, (3*i)+k, 3*j, value);
                mesch_me_mul(bigmat, (3*i)+k, (3*j)+1, value);
                mesch_me_mul(bigmat, (3*i)+k, (3*j)+2, value);
            }

            j++;
        }
        i++;
        j=0;
    }

    model->siesta.eigen_xyz_atom_mat = mesch_mat_new(3*num_atoms, 3*num_atoms);
    model->siesta.eigen_values = mesch_vec_new(3*num_atoms);

//external library call.

    mesch_sev_compute(bigmat, model->siesta.eigen_xyz_atom_mat, model->siesta.eigen_values);

// stupid sort routine -> this is going to need a rewrite - its a bubble sort - O(n^2).
    model->siesta.sorted_eig_values = g_malloc(sizeof(int[mesch_dim_get(model->siesta.eigen_values)]));

    for (i=0; i<mesch_dim_get(model->siesta.eigen_values); i++)
    {
        model->siesta.sorted_eig_values[i] = i;
    }

    gint temp_int;
    gdouble freq_i, freq_ii;

    gint sizeofeig = mesch_dim_get(model->siesta.eigen_values);

    for (j=sizeofeig-1; j>1; j--)
    {
        for (i=0; i < j; i++)
        {
            freq_i = make_eigvec_freq(mesch_ve_get(model->siesta.eigen_values, model->siesta.sorted_eig_values[i]));

            freq_ii = make_eigvec_freq(mesch_ve_get(model->siesta.eigen_values, model->siesta.sorted_eig_values[i+1]));


            if (freq_i > freq_ii )
            {
                temp_int = model->siesta.sorted_eig_values[i];
                model->siesta.sorted_eig_values[i] = model->siesta.sorted_eig_values[i+1];
                model->siesta.sorted_eig_values[i+1] = temp_int;
            }
        }
    }

//PRINT METHOD FOR UWA VISIT
    if (siestafileWRITE && matout)
    {
        fprintf(matout, "eig vectors 3N*3N\n-------------\n");
        for (j=0; j<(3*num_atoms); j++)
        {
            for (i=0; i<(3*num_atoms); i++)
            {
                fprintf(matout, "%f, ", mesch_me_get(bigmat, j, i));
            }
            fprintf(matout, "\n");
        }

        fprintf(matout, "\n\neig_vals\n-------------\n");
        for (i=0; i<mesch_dim_get(model->siesta.eigen_values); i++)
        {
            fprintf(matout, "%f, ", mesch_ve_get(model->siesta.eigen_values, i));
        }

        fprintf(matout, "\n\nfreqs\n-------------\n");
        for (i=0; i<mesch_dim_get(model->siesta.eigen_values); i++)
        {
            fprintf(matout, "%f, ", make_eigvec_freq(mesch_ve_get(model->siesta.eigen_values, i)));
        }

        fclose(matout);
    }

    fclose(fp);

    mesch_m_free(bigmat);
    mesch_m_free(correction_mat);
    mesch_m_free(mini_correction_zerooooo_mat);

    model->siesta.current_animation = 0;

//Lookup using index array.
    model->siesta.current_frequency = make_eigvec_freq(mesch_ve_get(model->siesta.eigen_values, model->siesta.sorted_eig_values[0]));
    model->siesta.freq_disp_str = g_strdup_printf("%.2f", model->siesta.current_frequency);
    model->siesta.num_animations = mesch_dim_get(model->siesta.eigen_values);
    model->siesta.vibration_calc_complete = TRUE;

    return(0);
}