Example #1
0
/* Name: insert_core
 * Notes: See the insert_[socket|core|thread] description above
 */
int insert_core(struct cpu_socket *s, struct rawsyscpu *r)
{
   struct cpu_socket *slist;  /* for walking through list */
   struct cpu_socket *thiss;  /* The socket we belong on */
   struct cpu_core *thisc;    /* The item we are working with */
   struct cpu_core *clist;
   struct cpu_core *clast;

   /* Find the right socket */
   slist = s;
   thiss = NULL;
   while ( slist )
   {
      if ( slist->id == r->physical_package_id )
         thiss = slist;

      slist = slist->next;
   }

   if ( NULL == thiss )
      return(1);

   /* There are lots of implications of exiting here - leaving lots of 
      haning memory locations, but basically we gotta cut and run...
      If you can't malloc() then it is over. */
   if ( NULL == (thisc = new_core(r->core_id)) )
      return(1);

   /*** ordered insert ***/

   /* Top of the list (no other items) */
   if ( thiss->clist == NULL )
   {
      thiss->clist = thisc;
      return(0);
   }

   /* Top of the list (sorted first) */
   if ( thiss->clist->id > thisc->id )
   {
      thisc->next = thiss->clist;
      thiss->clist = thisc;
      return(0);
   }

   if ( thiss->clist->id == thisc->id )
   {
      /* A bit wasteful - but we only do it once */
      free(thisc);
      return(0);
   }

   /* into the middle */
   clast = thiss->clist;
   clist = clast->next;
   while ( clist )
   {
      if ( clist->id > thisc->id )
      {
         thisc->next = clast->next;
         clast->next = thisc;
         return(0);
      }

      if ( clist->id == thisc->id )
      {
         free(thisc);
         return(0);
      }

      clast = clist;
      clist = clist->next;
   }

   /* Now at the end */
   clast->next = thisc;
   return(0);
}
Example #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);
}
Example #3
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);
}
Example #4
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);
}
Example #5
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);
}
Example #6
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;
}
Example #7
0
void xml_parse_atom(const gchar **names, const gchar **values)
{
gint i, n;
gchar **buff;

g_assert(xml_model != NULL);

/* init structure */
if (!xml_core)
  {
  xml_core = new_core("X", xml_model);
  xml_model->cores = g_slist_prepend(xml_model->cores, xml_core);
  }

/* process attributes (if any) */
i=0;
while (*(names+i))
  {
  if (g_ascii_strncasecmp(*(names+i), "elementType\0", 12) == 0)
    {
/* FIXME - potential overflow bug here, since label is an array */
    g_free(xml_core->atom_label);
    xml_core->atom_label = g_strdup(*(values+i));     
    core_init(xml_core->atom_label, xml_core, xml_model);
    }
  if (g_ascii_strncasecmp(*(names+i), "xyzf", 4) == 0)
    {
    buff = tokenize(*(values+i), &n);
    if (n > 2)
      {
      xml_core->x[0] = str_to_float(*(buff+0));
      xml_core->x[1] = str_to_float(*(buff+1));
      xml_core->x[2] = str_to_float(*(buff+2));
      xml_model->fractional = TRUE;
      }
    }
  if (g_ascii_strncasecmp(*(names+i), "xf", 2) == 0)
    {
    xml_core->x[0] = str_to_float(*(values+i));
/* FIXME - inefficient to repeat this for all atoms */
/* but may be necessary if every atom is allowed to be cart or fract */
    xml_model->fractional = TRUE;
    }
  if (g_ascii_strncasecmp(*(names+i), "x3", 2) == 0)
    {
    xml_core->x[0] = str_to_float(*(values+i));
/* FIXME - inefficient to repeat this for all atoms */
/* but may be necessary if every atom is allowed to be cart or fract */
    xml_model->fractional = FALSE;
    }

  if (g_ascii_strncasecmp(*(names+i), "yf", 2) == 0 ||
      g_ascii_strncasecmp(*(names+i), "y3", 2) == 0) 
    {
    xml_core->x[1] = str_to_float(*(values+i));
    }
  if (g_ascii_strncasecmp(*(names+i), "zf", 2) == 0 ||
      g_ascii_strncasecmp(*(names+i), "z3", 2) == 0) 
    {
    xml_core->x[2] = str_to_float(*(values+i));
    }
  i++;
  }
}
Example #8
0
static void handle_one_cpu(unsigned int number, char *vendor, int family, int model)
{
	char filename[1024];
	ifstream file;
	unsigned int package_number = 0;
	unsigned int core_number = 0;
	class abstract_cpu *package, *core, *cpu;

	sprintf(filename, "/sys/devices/system/cpu/cpu%i/topology/core_id", number);
	file.open(filename, ios::in);
	if (file) {
		file >> core_number;
		file.close();
	}

	sprintf(filename, "/sys/devices/system/cpu/cpu%i/topology/physical_package_id", number);
	file.open(filename, ios::in);
	if (file) {
		file >> package_number;
		if (package_number == (unsigned int) -1)
			package_number = 0;
		file.close();
	}


	if (system_level.children.size() <= package_number)
		system_level.children.resize(package_number + 1, NULL);

	if (!system_level.children[package_number]) {
		system_level.children[package_number] = new_package(package_number, number, vendor, family, model);
		system_level.childcount++;
	}

	package = system_level.children[package_number];
	package->parent = &system_level;

	if (package->children.size() <= core_number)
		package->children.resize(core_number + 1, NULL);

	if (!package->children[core_number]) {
		package->children[core_number] = new_core(core_number, number, vendor, family, model);
		package->childcount++;
	}

	core = package->children[core_number];
	core->parent = package;

	if (core->children.size() <= number)
		core->children.resize(number + 1, NULL);
	if (!core->children[number]) {
		core->children[number] = new_cpu(number, vendor, family, model);
		core->childcount++;
	}

	cpu = core->children[number];
	cpu->parent = core;

	if (number >= all_cpus.size())
		all_cpus.resize(number + 1, NULL);
	all_cpus[number] = cpu;
}
Example #9
0
gint read_dmol_frame(FILE *fp, struct model_pak *model)
{
gint i, num_tokens;
gchar *line, **buff;
struct core_pak *core;

g_assert(fp != NULL);

line = file_read_line(fp);

while (line)
  {
/* read cell vectors */
  if (g_ascii_strncasecmp(line, "$cell", 5) == 0 && model)
    {
    for (i=0 ; i<3 ; i++)
      {
      g_free(line);
      line = file_read_line(fp);
      buff = tokenize(line, &num_tokens);
      if (num_tokens > 2)
        {
        model->latmat[i] = AU2ANG*str_to_float(*(buff));
        model->latmat[i+3] = AU2ANG*str_to_float(*(buff+1));
        model->latmat[i+6] = AU2ANG*str_to_float(*(buff+2));
        }
      g_strfreev(buff);
      }
    model->periodic = 3;
    model->construct_pbc = TRUE;
    }

/* read coordinates */
  if (g_ascii_strncasecmp(line, "$coord", 5) == 0 && model)
    {
    g_free(line);
    line = file_read_line(fp);
    buff = tokenize(line, &num_tokens);
    while (num_tokens > 3)
      {
      if (elem_symbol_test(*buff))
        {
        core = new_core(*buff, model);
        model->cores = g_slist_prepend(model->cores, core);
        core->x[0] = AU2ANG*str_to_float(*(buff+1));
        core->x[1] = AU2ANG*str_to_float(*(buff+2));
        core->x[2] = AU2ANG*str_to_float(*(buff+3));
        }
      g_free(line);
      line = file_read_line(fp);
      g_strfreev(buff);
      buff = tokenize(line, &num_tokens);
      }
    g_strfreev(buff);
    model->fractional = FALSE;
    }

/* terminate frame read */
  if (g_ascii_strncasecmp(line, "$end", 4) == 0)
    return(0);

  g_free(line);
  line = file_read_line(fp);
  }

return(1);
}
Example #10
0
/* ---- example xml handler */
void* handler (SimpleXmlParser parser, SimpleXmlEvent event, 
	const char* szName, const char* szAttribute, const char* szValue)
{
	static int nDepth= 0;
	char *tmp;
	char szHandlerName[32];
	char szHandlerAttribute[32];
	char *szHandlerValue;
	//struct socket_data *news;
	//struct core_data *newc;
	//struct thread_data *newt;
	int last_cid=0;

	szHandlerValue=malloc(32);
	memset(szHandlerValue,0,32);

	if (szName != NULL) {
		trim(szName, szHandlerName);
	}
	if (szAttribute != NULL) {
		trim(szAttribute, szHandlerAttribute);
	}
	if (szValue != NULL) {
		trim(szValue, szHandlerValue);
	}

	if (event == ADD_SUBTAG) {
		fprintf(stderr,"depth: %d, val: %s\n",nDepth,szHandlerName);
		fprintf(stderr, "%6li: %s add subtag (%s)\n", 
			simpleXmlGetLineNumber(parser), getIndent(nDepth), szHandlerName);
		nDepth++;
	} else if (event == ADD_ATTRIBUTE) {
//		printf("attribute tag:%s %s=%s\n",szHandlerName, szHandlerAttribute, szHandlerValue);
		fprintf(stderr, "%6li: %s ///add attribute to tag %s ([%s]=[%s])\n", 
			simpleXmlGetLineNumber(parser), getIndent(nDepth), szHandlerName, szHandlerAttribute, szHandlerValue);

		if ( (!strcmp(szHandlerAttribute,"cache-level")) && (!strcmp(szHandlerValue,"3")) ) {
			//attribute cache-level=3 detected: new L3 domain
			fprintf(stderr,"\n* NEW SOCKET *\n");
			new_socket(last_sid,last_sid);
			push_socket_id(last_sid);
			last_sid++;
			level=3;
		}

		if ( (!strcmp(szHandlerAttribute,"name")) && (!strcmp(szHandlerValue,"SMT")) ) {
			//attribute cache-level=2 detected: new L2 domain
			fprintf(stderr,"\n       * NEW CORE, Sock %d *     \n", last_sid - 1);
			//uncomment for noSMP:
			//level=10;

			//ucomment for SMP:
			last_cid=pop_core_id();
			new_core(0,last_cid,last_sid - 1);
		} else if ( (!strcmp(szHandlerAttribute,"name")) && (!strcmp(szHandlerValue,"THREAD")) ) {
			//attribute cache-level=2 detected: new L2 domain
			fprintf(stderr,"\n* NEW THREAD, Sock %d *\n", last_sid - 1);
			last_cid=pop_core_id();
			new_thread(0,last_cid,last_sid - 1);
		}

		if ( (!strcmp(szHandlerAttribute,"level")) && (!strcmp(szHandlerValue,"3")) ) {
			//no cpu count="2"/SMT/THREAD Routing!
			level=300;
		} else if ( (!strcmp(szHandlerAttribute,"level")) && (!strcmp(szHandlerValue,"2")) ) {
			//attribute cache-level=2 detected: new L2 domain
			fprintf(stderr,"\n* !NEW LOGICAL CORE %d!, Sock: %d*\n", last_cid,last_sid - 1);
			//We have "cpu count="2" and SMT/THREAD flag name
			level=200;
		}

	} else if (event == ADD_CONTENT) {
		fprintf(stderr,"depth: %d, LEVEL %d, context for:[%s] [%s]\n",nDepth,level,szHandlerName, szHandlerValue);

		if (level==200) {
			if (!strcmp(szHandlerName,"cpu")) {
				fprintf(stderr,"  !ROUTE LEVEL 10: Cores ID processed: %s, SOCKET: %d\n",szHandlerValue, last_sid - 1 );
				while ((tmp = strsep(&szHandlerValue, ",")) != NULL) {
					if (tmp[0] == '\0')
						break; /* XXX */
					trim_spaces(tmp);
// comment for no SMP?
					push_core_id(atoi(tmp));
					fprintf(stderr,"\n\n\nHA: [%d]\n\n\n",atoi(tmp));
// uncomment for no SMP:
//					last_cid=pop_core_id();
//					new_core(0,atoi(tmp),last_sid - 1);
				}
			// drop level
//			level=9;
			}
		} else if (level==300) {
		//no cpu count="2"/SMT/THREAD Routing!
			if (!strcmp(szHandlerName,"cpu")) {
				fprintf(stderr,"  !ROUTE LEVEL 10: Cores ID processed: %s, SOCKET: %d\n",szHandlerValue, last_sid - 1 );
				while ((tmp = strsep(&szHandlerValue, ",")) != NULL) {
					if (tmp[0] == '\0')
						break; /* XXX */
					trim_spaces(tmp);
// comment for no SMP?
					push_core_id(atoi(tmp));
					fprintf(stderr,"\n\n\nHA: [%d]\n\n\n",atoi(tmp));
// uncomment for no SMP:
					last_cid=pop_core_id();
					new_core(0,atoi(tmp),last_sid - 1);
				}
			// drop level
//			level=9;
			}
		}

		fprintf(stderr, "%6li: %s add content to tag %s (%s)\n", 
			simpleXmlGetLineNumber(parser), getIndent(nDepth), szHandlerName, szHandlerValue);
	} else if (event == FINISH_ATTRIBUTES) {
		fprintf(stderr,"finish for:%s\n",szHandlerName);
		fprintf(stderr, "%6li: %s finish attributes (%s)\n", 
			simpleXmlGetLineNumber(parser), getIndent(nDepth), szHandlerName);
	} else if (event == FINISH_TAG) {
		fprintf(stderr,"finish for:%s\n",szHandlerName);
		fprintf(stderr, "%6li: %s finish tag (%s)\n", 
			simpleXmlGetLineNumber(parser), getIndent(nDepth), szHandlerName);
		nDepth--;
		if (level==10) {
			if (!strcmp(szHandlerName,"cpu"))
				level=0;
		}
	}

	//list_sockets();
	return handler;
}
Example #11
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);
}
Example #12
0
void zmat_process(gpointer data, struct model_pak *model)
{
gint i, n;
gdouble r, a, d;
gdouble v1[3], v2[3], v3[3], m1[9], m2[9];
gpointer tmp;
GSList *list;
struct zmat_pak *zmat = data;
struct zval_pak *zval;
struct core_pak *core[4] = {NULL, NULL, NULL, NULL};

/* checks */
if (!zmat)
  return;

matrix_lattice_init(model);

#if ZMAT_PROCESS_DEBUG
printf("distance scale = %f\n", zmat->distance_scale);
printf("angle scale = %f\n", zmat->angle_scale);
#endif

/* track the core # - 1st 3 items in zmatrix are exceptions */
n = 0;
for (list=zmat->zlines ; list ; list=g_slist_next(list))
  {
  zval = list->data;

/* check for variable names */
  for (i=3 ; i-- ; )
    {
    if (zval->name[i])
      {
/* hash table lookup for variable value */
      zval->value[i] = zmat_table_lookup(zval->name[i], zmat);
      }
    }

/* create the core */
#if ZMAT_PROCESS_DEBUG
printf("[%d = %s] [%d %d %d]", zval->type, zval->elem,
                               zval->connect[0], zval->connect[1], zval->connect[2]);
P3VEC(" x: ", zval->value);

#endif

/* TODO - need to mark zmatrix generated cores as special */
/* probably have another list in the zmat struct that contains */
/* all the cores created below */

  switch (n)
    {
    case 0:
/* TODO - convert to cartesian if fractional and enforce cart model */
      core[0] = new_core(zval->elem, model);
      model->cores = g_slist_prepend(model->cores, core[0]);
      zmat->zcores = g_slist_prepend(zmat->zcores, core[0]);
      ARR3SET(core[0]->x, zval->value);
      if (zmat->fractional)
        vecmat(model->latmat, core[0]->x);
      else
        {
        VEC3MUL(core[0]->x, zmat->distance_scale);
        }
      break;

    case 1:
      core[1] = new_core(zval->elem, model);
      model->cores = g_slist_prepend(model->cores, core[1]);
      zmat->zcores = g_slist_prepend(zmat->zcores, core[1]);

      r = zmat->distance_scale * zval->value[0];
/*
      a = zmat->angle_scale * zval->value[1];
      d = zmat->angle_scale * zval->value[2];
*/

/* SIESTA hack : z-axis angle is 2nd, and theta is 3rd (last) */
      a = zmat->angle_scale * zval->value[2];
      d = zmat->angle_scale * zval->value[1];

      v1[0] = v1[1] = r * sin(d);
      v1[0] *= cos(a);
      v1[1] *= sin(a);
      v1[2] = r * cos(d);

      ARR3SET(core[1]->x, core[0]->x);
      ARR3ADD(core[1]->x, v1);
      break;

    case 2:
/* check the connection order */
      if (zval->connect[0] == 2)
        {
        tmp = core[0];
        core[0] = core[1];
        core[1] = tmp;
        }

      r = zmat->distance_scale * zval->value[0];
      a = zmat->angle_scale * zval->value[1];
      d = zmat->angle_scale * zval->value[2];

      ARR3SET(v2, core[1]->x);
      ARR3SUB(v2, core[0]->x);

/* get rotation axis for bond angle */
      VEC3SET(v3, 0.0, 0.0, 1.0);
      crossprod(v1, v3, v2);

/* rotate bondlength scaled vector into position */
      matrix_v_rotation(m2, v1, a);
      ARR3SET(v3, v2);
      normalize(v3, 3);
      VEC3MUL(v3, r);
      vecmat(m2, v3);

/* rotate to give required dihedral */
      matrix_v_rotation(m1, v2, d);
      vecmat(m1, v3);

/* generate the atom position */
      core[2] = new_core(zval->elem, model);
      model->cores = g_slist_prepend(model->cores, core[2]);
      zmat->zcores = g_slist_prepend(zmat->zcores, core[2]);

      ARR3SET(core[2]->x, core[0]->x);
      ARR3ADD(core[2]->x, v3);
      break;

    default:
/* get core connectivity (NB: prepending cores - hence n - number) */
      core[0] = g_slist_nth_data(zmat->zcores, n-zval->connect[0]); 
      core[1] = g_slist_nth_data(zmat->zcores, n-zval->connect[1]); 
      core[2] = g_slist_nth_data(zmat->zcores, n-zval->connect[2]); 
g_assert(core[0] != NULL);
g_assert(core[1] != NULL);
g_assert(core[2] != NULL);

      r = zmat->distance_scale * zval->value[0];
      a = zmat->angle_scale * zval->value[1];
      d = zmat->angle_scale * zval->value[2];

/* setup vectors */
      ARR3SET(v2, core[1]->x);
      ARR3SUB(v2, core[0]->x);
      ARR3SET(v3, core[2]->x);
      ARR3SUB(v3, core[1]->x);

/* rotate v3 about v2 to give dihedral */
      matrix_v_rotation(m1, v2, d);
      vecmat(m1, v3);

/* get rotation axis and matrix for bond angle */
      crossprod(v1, v3, v2);
      matrix_v_rotation(m2, v1, a);
      normalize(v2, 3);
      VEC3MUL(v2, r);
      vecmat(m2, v2);

/* generate the atom position */
      core[3] = new_core(zval->elem, model);
      model->cores = g_slist_prepend(model->cores, core[3]);
      zmat->zcores = g_slist_prepend(zmat->zcores, core[3]);

      ARR3SET(core[3]->x, core[0]->x);
      ARR3ADD(core[3]->x, v2);

/* TODO (maybe) - some zmatrix constructions implicitly assume */
/* some checking for duplicate atoms & reversing the torsional */
/* angle sense to accomodate this. */

      break;
    }
  n++;
  }

/* zmatrix cores are created in cartesians - revert to fractional if required */
if (model->fractional)
  {
  for (list=zmat->zcores ; list ; list=g_slist_next(list))
    {
    core[0] = list->data;
    vecmat(model->ilatmat, core[0]->x);
    }
  }
}
Example #13
0
gint read_gromacs_gro(gchar *filename, struct model_pak *model)
{
gint num_tokens;
gchar *line, **buff;
FILE *fp;

g_assert(model != NULL);

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

/* skip title */
line = file_read_line(fp);
g_free(line);
line = file_read_line(fp);

while (line)
  {

/* FIXME - properly should do formatted read, since things can be */
/* adjacent with no spaces in between -> tokenize() will fail */
/*
  fprintf(fp, "%5i%5s%5s%5i%8.3f%8.3f%8.3f%8.4f%8.4f%8.4f\n",
               n, "UNK", core->atom_label, 1, 
               x[0], x[1], x[2], 0.1*core->v[0], 0.1*core->v[1], 0.1*core->v[2]);
*/

  if (strlen(line) > 10)
    {
/* tokenize from atom label (avoids some problems with no space separation) */
    buff = tokenize(&line[10], &num_tokens);

    if (num_tokens > 4)
      {
/* TODO - deal with water properly (ie set atom_types) */
      if (g_ascii_strncasecmp(*(buff+0), "HW", 2) == 0)
        {
        g_free(*(buff+0));
        *(buff+0) = g_strdup("H");
        }
      if (g_ascii_strncasecmp(*(buff+0), "OW", 2) == 0)
        {
        g_free(*(buff+0));
        *(buff+0) = g_strdup("O");
        }

      if (elem_test(*(buff+0)))
        {
        struct core_pak *core = new_core(*(buff+0), model);

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

        model->cores = g_slist_prepend(model->cores, core);
        }
      }
    g_strfreev(buff);
    }
  g_free(line);
  line = file_read_line(fp);
  }

model->cores = g_slist_reverse(model->cores);

model_prep(model);

fclose(fp);

return(0);
}
Example #14
0
gint read_nwout_block(FILE *fp, struct model_pak *model)
{
gint num_tokens;
gchar **buff, line[LINELEN], *text;
GString *gstring;
GSList *clist;
struct core_pak *core;

clist = model->cores;
  
/* skip until get a 1 in first column for first coordinate */
if (fgetline(fp, line))
  return(1);
while (g_ascii_strncasecmp(line, "    1", 5) != 0)
  {
  if (fgetline(fp, line))
    return(1);
  }

buff = tokenize(line, &num_tokens);
while (num_tokens > 0)
  {
  if (clist)
    {
    core = clist->data;
    clist = g_slist_next(clist);
    }
  else
    {
    core = new_core(*(buff+1), model);
    model->cores = g_slist_append(model->cores, core);
    }

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

#if DEBUG_READ_NWOUT
P3VEC("coords: ", core->x);
#endif

/* get next line */
  g_strfreev(buff);
  if (fgetline(fp, line))
    return(2);
  buff = tokenize(line, &num_tokens);
  }

g_strfreev(buff);

/* read until get the details of the current optimisation step */  
while (g_ascii_strncasecmp(line, "@", 1) != 0)
  {
  if (fgetline(fp, line))
    return(0);
  }

buff = tokenize(line, &num_tokens);
while (g_ascii_strncasecmp(line, "@", 1) == 0)
  {
  if (g_ascii_isdigit(buff[1][0]))
    {
    text = format_value_and_units(*(buff+2), 5);
    gstring = g_string_new(text);
    g_free(text);
    g_string_append(gstring, " a.u.");
    property_add_ranked(3, "Energy", gstring->str, model);
    g_string_free(gstring, TRUE);
 
    text = format_value_and_units(*(buff+5), 5);
    gstring = g_string_new(text);
    g_free(text);
    g_string_append(gstring, " a.u./A");
    property_add_ranked(4, "RMS Gradient", gstring->str, model);
    g_string_free(gstring, TRUE);
    }
  /* get next line */
  g_strfreev(buff);
  if (fgetline(fp, line))
    return(2);
  buff = tokenize(line, &num_tokens);
  }

return(0);
}
Example #15
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);
}