示例#1
0
void help_init(void)
{
gint n;
gchar *filename, *line, *topic;
gpointer scan;
GString *buffer;

/* hash table with topic label as the key */
sysenv.manual = g_hash_table_new(g_str_hash, g_str_equal);

/* open the manual file for scanning */
filename = g_build_filename(sysenv.gdis_path, MANUAL_FILE, NULL);
printf("scanning: %s\n", filename);
scan = scan_new(filename);
g_free(filename);
if (!scan)
  {
  help_topic_new(NULL, NULL);
  return;
  }

/* process the manual file */
topic=NULL;
buffer = g_string_new(NULL);
line = scan_get_line(scan);
while (!scan_complete(scan))
  {
  if (g_ascii_strncasecmp(line, "%topic ", 7) == 0)
    {
/* add any old data */
    if (topic && buffer->len)
      {
      help_topic_new(topic, buffer->str);
      buffer = g_string_set_size(buffer, 0);
      g_free(topic);
      }
/* remove trailing <cr> */
    n = strlen(&line[7]);
    topic = g_strndup(&line[7], n-1);
    }
  else
    {
/* append everything that's not a topic to the current buffer */
    if (topic)
      g_string_append(buffer, line);
    }

  line = scan_get_line(scan);
  }

/* done - add the last topic found */
if (topic)
  help_topic_new(topic, buffer->str);

g_string_free(buffer, TRUE);
g_free(topic);

scan_free(scan);
}
示例#2
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);
}
示例#3
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);
}
示例#4
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);
}
示例#5
0
gint read_rietica(gchar *filename, struct model_pak *model)
{
gint i, phases=0, skip, num_tokens;
gchar **buff, *line;
float x, y, z;
gpointer scan;
GSList *list;
struct core_pak *core;

/* checks */
g_assert(model != NULL);
scan = scan_new(filename);
if (!scan)
  return(1);

/* FIXME - stop the previous file routines setting this */
model->id = -1;

while (!scan_complete(scan))
  {
  buff = scan_get_tokens(scan, &num_tokens);
  
/* search for structure start */
  if (num_tokens)
    {
    if (g_ascii_strncasecmp(*buff, "***", 3) == 0)
      {
      if (phases)
        model = model_new();
      phases++;

/* structure name - omit the 1st and last tokens (ie "***") */
      if (num_tokens > 1)
        {
        g_free(*(buff+num_tokens-1));
        *(buff+num_tokens-1) = NULL;
        g_free(model->basename);
        model->basename = g_strjoinv(" ", buff+1);
        }

/* parse spacegroup */
      line = scan_get_line(scan);
      line = scan_get_line(scan);
      model->sginfo.spacename = g_strstrip(g_strdup(line));
      model->sginfo.spacenum = -1;

/* parse a structure */
      skip = 0;
      while (!scan_complete(scan))
        {
        g_strfreev(buff);
        buff = scan_get_tokens(scan, &num_tokens);

        if (num_tokens)
          {
          if (elem_symbol_test(*buff))
            {
/* new core */
/*
            if (num_tokens > 6)
*/
              {
              core = new_core(*buff, model);
              model->cores = g_slist_prepend(model->cores, core);

/* formatted output can result in -ve signs "joining" tokens */
              line = scan_cur_line(scan);
/* no doubt some fortran programmer thought this was a clever format */
              sscanf(line, "%*16c%8f%8f%8f", &x, &y, &z);
              VEC3SET(core->x, x, y, z);

/*
printf("> %s", line);
P3VEC(" - ", core->x);
              core->x[0] = str_to_float(*(buff+2));
              core->x[1] = str_to_float(*(buff+3));
              core->x[2] = str_to_float(*(buff+4));
              core->sof = str_to_float(*(buff+6));
*/

              skip = 0;
              }
            }
          else
            skip++;
          }

/* 4 lines after the last core - parse cell info and terminate structure */
        if (skip == 4)
          {
          if (num_tokens > 5)
            {
            for (i=6 ; i-- ; )
              model->pbc[i] = str_to_float(*(buff+i));
            model->pbc[3] *= D2R;
            model->pbc[4] *= D2R;
            model->pbc[5] *= D2R;
            }
          break;
          }
        }
      }
    }
  g_strfreev(buff);
  }

/* setup all new structures */
for (list=sysenv.mal ; list ; list=g_slist_next(list))
  {
  model = list->data;

  if (model->id == -1)
    {
    model->id = RIETICA;
    model->periodic = 3;
    model->fractional = TRUE;
    strcpy(model->filename, filename);
    model->cores = g_slist_reverse(model->cores);
    model_prep(model);
    }
  }

scan_free(scan);

return(0);
}