Exemplo n.º 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);
}
Exemplo n.º 2
0
gint read_nwout(gchar *filename, struct model_pak *model)
{
gchar line[LINELEN];
FILE *fp;

fp = fopen(filename, "rt");
if (!fp)
  return(1);

while (!fgetline(fp, line))
  {
  if (g_strrstr(line, "Geometry \"geometry\" -> \"geometry\"") != NULL)
    {
/* go through all frames to count them */
    read_nwout_block(fp, model);
    animate_frame_store(model);
    }
  }

/* done */
g_free(model->filename);
model->filename = g_strdup(filename);

g_free(model->basename);
model->basename = parse_strip(filename);

model_prep(model);

fclose(fp);

return(0);
}
Exemplo n.º 3
0
gint read_gmf(gchar *filename, struct model_pak *data)
{
/* checks */
g_assert(data != NULL);
g_assert(filename != NULL);

/* setup model parameters */
data->mode = FREE;
data->id = MORPH;
data->axes_type = OTHER;
data->morph_label = TRUE;

g_free(data->filename);
data->filename = g_strdup(filename);

g_free(data->basename);
data->basename = parse_strip(filename);

/* read from a gmf file */
if (load_planes(filename, data))
  {
  printf("File load failed, check %s.\n", data->filename);
  model_delete(data);
  return(1);
  }

/* construct the hull (convert to H representation) */
data->num_vertices=0;

/* FIXME - signature change */
/*
if (morph_build(data))
  return(3);
*/

#if DEBUG_READ_GMF
printf("-------------------------\n");
printf("       Input planes: %d\n", data->num_planes);
printf("Calculated vertices: %d\n", data->num_vertices);
printf("-------------------------\n");
#endif

/* test success */
if (!g_slist_length(data->planes))
  return(4);

/* vertices are cartesian - so a fudge is needed */
model_prep(data);

/* proper rmax scaling & visibility calc */
coords_init(REDO_COORDS, data);

return(0);
}
Exemplo n.º 4
0
void docking_execute(struct dock_pak *dock, struct task_pak *task)
{
gchar *path, *cmd, *base, *input, *output;
GSList *list, *dir_list;
struct file_pak *file;

path = dock->path;

/*
printf("expected files: %d\n", dock->n);
*/

/* NB: have to change to the project directory in order to run GULP jobs in it */
/* TODO - save sysenv.cwd and restore after? */
if (chdir(path))
  {
  printf("Failed to change to project directory.\n");
  return;
  }

/* submit all GULP jobs in the project directory */
dir_list = file_dir_list(path, 0);
task->progress = 0.0;
for (list=dir_list ; list ; list=g_slist_next(list))
  {
  file = get_file_info(list->data, BY_EXTENSION);
  if (file)
    {
    if (file->id == GULP)
      {
      input = list->data;
      base = parse_strip(input);
      output = g_strconcat(base, ".got", NULL);

/* this doesn't work - why? */
/*
if (exec_gulp(input, output))
  printf(" >>> exec failed!!!\n");
*/

/* run the GULP jobs (NOT in bg as we're already a task) */
      cmd = g_strdup_printf("%s < %s > %s", sysenv.gulp_path, input, output);
      system(cmd);

      g_free(cmd);
      g_free(base);
      g_free(output);
      }
    }
  }
g_slist_free(dir_list);
}
Exemplo n.º 5
0
gint read_dmol(gchar *filename, struct model_pak *model)
{
gint flag;
FILE *fp;

/* checks */
g_return_val_if_fail(model != NULL, 1);
g_return_val_if_fail(filename != NULL, 2);

fp = fopen(filename,"rt");
if (!fp)
  return(3);

/* loop while there's data */
flag=0;
model->num_frames = 0;

read_dmol_frame(fp, model);

for (;;)
  {
  add_frame_offset(fp, model);

  if (read_dmol_frame(fp, NULL))
    break;

  model->num_frames++;
  }

/* get rid of frame list if only one frame */
if (model->num_frames == 1)
  {
  free_list(model->frame_list);
  model->frame_list = NULL;
  }

/* model setup */
strcpy(model->filename, filename);
g_free(model->basename);
model->basename = parse_strip(filename);
model_prep(model);

return(0);
}
Exemplo n.º 6
0
gint read_dmol(gchar *filename, struct model_pak *model)
{
gint flag;
FILE *fp;

/* checks */
g_return_val_if_fail(model != NULL, 1);
g_return_val_if_fail(filename != NULL, 2);

fp = fopen(filename,"rt");
if (!fp)
  return(3);

/* loop while there's data */
flag=0;
model->num_frames = 0;

read_dmol_frame(fp, model);

for (;;)
  {
  if (read_dmol_frame(fp, NULL))
    break;

  animate_frame_store(model);
  }

/* model setup */
model_prep(model);

g_free(model->filename);
model->filename = g_strdup(filename);

g_free(model->basename);
model->basename = parse_strip(filename);

fclose(fp);

return(0);
}
Exemplo n.º 7
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);
}
Exemplo n.º 8
0
gint read_cel(gchar *filename, struct model_pak *model)
{
gchar *line;
FILE *fp;
int i;
gint num_tokens, natom=0;
gchar **buff;

struct core_pak *core;

/* checks */
g_return_val_if_fail(model != NULL, 1);
g_return_val_if_fail(filename != NULL, 2);

fp = fopen(filename, "rt");
if (!fp)
  return 3;

/* 1st line  - cell parameters */
line = file_read_line(fp);
if (!line || strlen(line) < 5 || g_ascii_strncasecmp("cell", line, 4) != 0)
  {
  printf("The first line should start with the keyword CELL.\n");
  return 4;
  }
buff = tokenize(line+4, &num_tokens);
g_free(line);
if (num_tokens < 6)
  {
  g_strfreev(buff);
  printf("Keyword CELL should be followed by six numbers.\n");
  return 5;
  }
for (i=0; i<3; ++i)
  model->pbc[i] = str_to_float(buff[i]);
for (i=3; i<6; ++i)
  model->pbc[i] = str_to_float(buff[i]) * D2R;
g_strfreev(buff);

/* next lines - atomic positions */
for (;;)
  {
  line = file_read_line(fp);
  if (!line) /*the end of file*/
    {
    printf("No 'rgnr' symmetry line found.\n");
    return 6;
    }
  else if (g_ascii_strncasecmp("rgnr", line, 4) == 0) /*no more atomic pos.*/
    {
    break;
    }
  else if (g_ascii_strncasecmp("natom", line, 5) == 0)/*number of atoms */
    /*some old .cel files have second line with number of atoms eg. "natom 6"*/
    {
    buff = tokenize(line, &num_tokens);
    if (num_tokens > 1)
      natom = str_to_float(buff[1]);
    else
      printf("Warning: ignoring `natom' line:\n%s\n", line);
    g_free(line);
    g_strfreev(buff);
    }
  else if (strncmp("    ", line, 4) != 0) /* atomic position */
    {
    buff = tokenize(line, &num_tokens);
    g_free(line);
    if (num_tokens < 5)
      {
      g_strfreev(buff);
      continue;
      }
    core = new_core(*buff, model);
    core->atom_label = g_strdup(buff[0]);

    /* in second column there is either atomic number 
     * or something like "Mg2+" or "K+". The second form is for
     * " the use of different bonding states of one and the same 
     *   element (e.g. Fe2+ and Fe3+ in Fe3O4)"
     * FIXME how these bonding states can be interpreted in GDIS */
    if (g_ascii_isdigit(buff[1][0]))
      core->atom_code = str_to_float(buff[1]);
    else 
      {
      core->atom_code = elem_symbol_test(buff[1]);
      }
    for (i=0; i<3; ++i)
      core->x[i] = str_to_float(buff[2+i]);
    /* TODO interpret 2 next optional numbers:
     *   so-called multiplied substitution and replacement factor (SOF)
     *   and isotropic Debye-Waller factor
     * FIXME can they be interpreted by GDIS? -MW */
    model->cores = g_slist_prepend(model->cores, core);
    g_strfreev(buff);
    }
  else /* replacement atom */
    {
    /*FIXME replacement atoms are now silently ignored 
     *  how can I use this information in GDIS? - MW*/ 
    g_free(line);
    }
  }

/* last line - symmetry */
buff = tokenize(line, &num_tokens);
model->sginfo.spacenum = str_to_float(buff[1]);
/* FIXME/TODO how to interpret the second (optional) number?
 * From fileformat docs: 
 * "sometimes there exists more than one setting of a space-group type. 
 * Thus, a further number must be given if the structure hasn't been described 
 * using a conventional setting (standard setting)."
 * http://users.omskreg.ru/~kolosov/bam/a_v/v_1/powder/details/strucdat.htm
 * http://users.omskreg.ru/~kolosov/bam/a_v/v_1/powder/details/setting.htm
 * Unfortunatelly I'm ignorant about space-groups - MW
 */
g_free(line);
g_strfreev(buff);

if (natom>0 && natom != g_slist_length(model->cores))
  printf("Warning: expected %i atoms, have %i.", natom, 
		                                 g_slist_length(model->cores));

/* model setup */
model->fractional = TRUE;
model->periodic = 3;
strcpy(model->filename, filename);
g_free(model->basename);
model->basename = parse_strip(filename);

model_prep(model);

return 0;
}
Exemplo n.º 9
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);
}
Exemplo n.º 10
0
gint read_diffax(gchar *filename, struct model_pak *model)
{
gint num_tokens, num_layer, tot_layer;
gdouble offset;
gchar **buff;
GSList *list1, *list2;
struct core_pak *core;
struct layer_pak *layer;
FILE *fp;

/* checks */
g_return_val_if_fail(model != NULL, 1);
g_return_val_if_fail(filename != NULL, 2);
fp = fopen(filename, "rt");
if (!fp)
  return(3);

/* setup */
model->id = DIFFAX_INP;
model->fractional = TRUE;
model->periodic = 3;
model->colour_scheme = REGION;

strcpy(model->filename, filename);
g_free(model->basename);
model->basename = parse_strip(filename);

/* scan the file */
while ((buff = get_tokenized_line(fp, &num_tokens)))
  {
  diffax_keyword_search:;

/* restricted unit cell */
  if (g_ascii_strncasecmp("structural", *buff, 10) == 0)
    {
    g_strfreev(buff);
    buff = get_tokenized_line(fp, &num_tokens);
    if (num_tokens > 3)
      {
      model->pbc[0] = str_to_float(*(buff+0));
      model->pbc[1] = str_to_float(*(buff+1));
      model->pbc[2] = str_to_float(*(buff+2));
      model->pbc[3] = PI/2.0;
      model->pbc[4] = PI/2.0;
      model->pbc[5] = D2R*str_to_float(*(buff+3));
      }
    }

/* layer testing */
  if (g_ascii_strncasecmp("layer", *buff, 5) == 0)
    {
    layer = g_malloc(sizeof(struct model_pak));
    layer->width = 1.0;
    VEC3SET(layer->centroid, 0.5, 0.5, 0.5);
    layer->cores = NULL;
    model->layer_list = g_slist_prepend(model->layer_list, layer);

    g_strfreev(buff);
    buff = get_tokenized_line(fp, &num_tokens);
    if (buff)
      {
/* TODO - if centrosymmetric : add a -1 operation */
      }

/* get layer data */
    g_strfreev(buff);
    buff = get_tokenized_line(fp, &num_tokens);
    while (buff)
      {
      if (elem_symbol_test(*buff))
        {
        if (num_tokens > 6)
          {
/*
printf("[%s] [%s  %s  %s]\n", *buff, *(buff+2), *(buff+3), *(buff+4));
*/
          core = new_core(*buff, model);
          model->cores = g_slist_prepend(model->cores, core);
          layer->cores = g_slist_prepend(layer->cores, core);

          core->x[0] = str_to_float(*(buff+2));
          core->x[1] = str_to_float(*(buff+3));
          core->x[2] = str_to_float(*(buff+4));

          core->sof = str_to_float(*(buff+5));
          }
        }
      else
        goto diffax_keyword_search;

/* get next line of tokens */
      g_strfreev(buff);
      buff = get_tokenized_line(fp, &num_tokens);
      }
    }

  g_strfreev(buff);
  }

/* TODO - enumerate layers and scale, so they are stacked 1..n in a single cell */
/* also label the layers as different region types */
model->layer_list = g_slist_reverse(model->layer_list);
num_layer = 0;
tot_layer = g_slist_length(model->layer_list);

model->pbc[2] *= tot_layer;

#if DEBUG_READ_DIFFAX
printf("Read in %d layers.\n", tot_layer);
#endif

for (list1=model->layer_list ; list1 ; list1=g_slist_next(list1))
  {
  layer = (struct layer_pak *) list1->data;
  layer->width = 1.0 / (gdouble) tot_layer;

  offset = (gdouble) num_layer * layer->width;

  VEC3SET(layer->centroid, 0.0, 0.0, offset);

  for (list2=layer->cores ; list2 ; list2=g_slist_next(list2))
    {
    core = (struct core_pak *) list2->data;

/* scale to within the big cell (encloses all DIFFAX layers) */
    core->x[2] *= layer->width;

/* offset each particular layer */
    core->x[2] += offset;

    core->region = num_layer;
    }
  num_layer++;
  }

/* end of read */
fclose(fp);

/* post read setup */
model->cores = g_slist_reverse(model->cores);
model_prep(model);

return(0);
}
Exemplo n.º 11
0
gint nwchem_input_import(gpointer import)
{
gint *symbols, num_symbols, num_tokens, value;
gchar *line, **buff;
gpointer scan, config;
GString *unparsed;
struct model_pak *model=NULL; // CURRENT - will break if more than one in a file
struct nwchem_pak *nwchem;

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

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

config = config_new(NWCHEM, NULL);
nwchem = config_data(config);

unparsed = g_string_new(NULL);

while (!scan_complete(scan))
  {
  symbols = scan_get_symbols(scan, &num_symbols);

  if (num_symbols)
    {
/* process first recognized symbol */
    value = symbols[0];
    switch (value)
      {
      case NWCHEM_START:
/* TODO - could this serve as title? */
        nwchem->start = parse_strip(scan_cur_line(scan));
        break;

      case NWCHEM_BASIS:
// TODO - don't want to use this for predefined basis sets
        read_nwchem_basis_library(scan, config);
        break;

      case NWCHEM_CHARGE:
        line = scan_cur_line(scan);
        buff = tokenize(line, &num_tokens);
        if (num_tokens > 1)
          nwchem->charge = g_strdup(buff[1]);
        g_strfreev(buff);
        break;

      case NWCHEM_GEOMETRY:
        if (!model)
          {
          model = model_new();
          import_object_add(IMPORT_MODEL, model, import);
          }
        read_nwchem_geometry(scan, model);
        break;

      case NWCHEM_SYSTEM:
        if (!model)
          {
          model = model_new();
          import_object_add(IMPORT_MODEL, model, import);
          }
        read_nwchem_system(scan, model);
        break;

      case NWCHEM_TASK:
        read_nwchem_task(scan, config, symbols, num_symbols);
        break;

      default:
/* add lines that have recognized symbols (but no special trigger) to unparsed */
/* this'll happen for symbols that occur in multiple locations (eg dft) */
        line = scan_cur_line(scan);
        if (line)
          g_string_append(unparsed, line);
      }

    g_free(symbols);
    }
  else
    {
/* add non-NULL lines to unparsed list */
    line = scan_cur_line(scan);
    if (line)
      g_string_append(unparsed, line);
    }
  }

config_unparsed_set(g_string_free(unparsed, FALSE), config);
import_object_add(IMPORT_CONFIG, config, import);

scan_free(scan);

import_init(import);

return(0);
}