예제 #1
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);
}
예제 #2
0
파일: main2.c 프로젝트: tlazaro/cg-ucu
int main(int argc, char* argv[])
{
    // Crear una ventana de 500x500 pixels:
    int cw = 640;
    int ch = 480;
    cg_init(cw, ch, NULL);
    init_cggl(cw, ch);

    Model* model = model_new("knight");

    int done = 0;
    while (!done)
    {
        SDL_Event event;
        while(SDL_PollEvent(&event))
        {
            switch (event.type)
            {
            case SDL_KEYDOWN:
                switch(event.key.keysym.sym)
                {
                case SDLK_ESCAPE:
                    done = 1;
                    break;
                case SDLK_UP:
                    rot_speed += 5.0f;
                    break;
                case SDLK_DOWN:
                    rot_speed -= 5.0f;
                    break;
                case SDLK_RIGHT:
                    frame += 1;
                    if (frame >= model->md2_model->header.num_frames)
                        frame = 0;
                    break;
                case SDLK_LEFT:
                    frame -= 1;
                    if (frame < 0)
                        frame = model->md2_model->header.num_frames - 1;
                    break;
                case SDLK_m:
                    if (mode == CG_TRIANGLES)
                        mode = CG_LINES;
                    else
                        mode = CG_TRIANGLES;
                    break;
                default:
                    break;
                }
                break;
            case SDL_QUIT :
                done = 1;
                break;
            default:
                break;
            }
        }
        cg_clear();

        paint_model(model);

        // Actualizar la pantalla:
        cg_repaint();

        double delta = get_delta();

        rot_x += rot_speed*delta;
        rot_y += rot_speed*delta;
        rot_z += rot_speed*delta;

    }

    // Liberar recursos:
    model_free(model);
    cgCloseCGGL();
    cg_close();

    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
model_t *model_parse_pmf(int len, const char *data)
{
	int i,j;
	
	const char *p = data;
	const char *dend = data + len;
	
	// and now we crawl through the spec.
	
	// start with the header of "PMF",0x1A,1,0,0,0
	char head[8];
	
	if(memcmp(p, "PMF\x1A\x01\x00\x00\x00", 8))
	{
		fprintf(stderr, "model_load_pmf: not a valid PMF v1 file\n");
		return NULL;
	}
	p += 8;
	
	// then there's a uint32_t denoting how many body parts there are
	uint32_t bone_count = *(uint32_t *)p;
	p += 4;
	if(bone_count > MODEL_BONE_MAX)
	{
		fprintf(stderr, "model_parse_pmf: too many bones (%i > %i)\n"
			, bone_count, MODEL_BONE_MAX);
		return NULL;
	}
	
	model_t *pmf = model_new(bone_count);
	if(pmf == NULL)
	{
		error_perror("model_parse_pmf");
		return NULL;
	}
	pmf->udtype = UD_PMF;
	
	// then, for each body part,
	for(i = 0; i < (int)bone_count; i++)
	{
		// there's a null-terminated 16-byte string (max 15 chars) denoting the part
		const char *namebuf = p;
		p += 16;
		
		if(namebuf[15] != '\x00')
		{
			fprintf(stderr, "model_load_pmf: name not null terminated\n");
			model_free(pmf);
			return NULL;
		}
		
		// then there's a uint32_t denoting how many points there are in this body part
		uint32_t pt_count = *(uint32_t *)p;
		p += 4;
		
		// (just allocating the bone here)
		model_bone_t *bone = model_bone_new(pmf, pt_count);
		pmf = bone->parent;
		memcpy(bone->name, namebuf, 16);
		if(bone == NULL)
		{
			error_perror("model_parse_pmf");
			model_free(pmf);
			return NULL;
		}
		
		// then there's a whole bunch of this:
		//   uint16_t radius;
		//   int16_t x,y,z;
		//   uint8_t b,g,r,reserved;
		int bonelen = sizeof(model_point_t)*pt_count;
		memcpy(bone->pts, p, bonelen);
		p += bonelen;
		bone->ptlen = pt_count;
		
		// "reserved" needs to be 0 or else you suck
		// NO SIDECHANNELING YOUR NAME IN THERE
		// i'm going to enforce this in the loader
		// and will outright reject files which don't have 0 in ALL of these slots
		for(j = 0; j < bone->ptmax; j++)
			if(bone->pts[j].resv1 != 0)
			{
				fprintf(stderr, "model_load_pmf: file corrupted or made by a smartass\n");
				model_free(pmf);
				return NULL;
			}
		
		// rinse, lather, repeat
		
		// units are 8:8 fixed point in terms of the vxl grid by default
	}
	
	return pmf;
}
예제 #5
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);
}
예제 #6
0
파일: command.c 프로젝트: Bhattiasif/gdis
void command_main_loop(int argc, char **argv)
{
gint n, status, num_tokens;
gchar *inp, *out, *ext, *tmp, *line, *base, **buff;
gboolean exit=FALSE;
GSList *list, *files, *item, *structures;
struct file_pak *inp_pak, *out_pak;
struct model_pak *model;

if (argc < 2)
  printf("gdis> Commandline interface. Enter ? for help.\n");

/* command line */
do
  {
/* if additional keywords - process as single command line */
  if (argc > 1)
    {
/* convert options into single string for processing */
    buff = g_malloc(argc*sizeof(gchar *));
    for (n=1 ; n<argc ; n++)
      *(buff+n-1) = g_strdup(argv[n]);
    *(buff+argc-1) = NULL;
    line = g_strjoinv(" ", buff);
    g_strfreev(buff);
    exit = TRUE;
    }
  else
    {
/* standard repeating prompt */
    printf("gdis> ");
    line = file_read_line(stdin);
    }

/* quit primitive */
  if (g_ascii_strncasecmp("qu", line, 2) == 0 ||
      g_ascii_strncasecmp("ex", line, 2) == 0)
    exit=TRUE;

/* test primitive */
  if (g_ascii_strncasecmp("te", line, 2) == 0)
    {
    buff = tokenize(line, &num_tokens);
    for (n=1 ; n<num_tokens ; n++)
      test_run(*(buff+n));
    g_strfreev(buff);
    }

/* copy primitive */
  if (g_ascii_strncasecmp("co", line, 2) == 0 || g_ascii_strncasecmp("cp", line, 2) == 0)
    {
    buff = tokenize(line, &num_tokens);

    if (num_tokens > 2)
      {

      out_pak = get_file_info(*(buff+2), BY_EXTENSION);
      if (!out_pak)
        {
        printf("Error: unrecognized output filetype.\n");
        break;
        }
      if (!out_pak->write_file)
        {
        printf("Error: write method for this filetype does not exist.\n");
        break;
        }

/* FIXME! - this is all wrong - should be no dependence on sysenv.cwd for path */
/* since this falls over with something like prompt:>gdis cp /tmp/gok.sot /tmp/dest/gok.meta */
      ext = file_extension_get(*(buff+2));
      files = file_dir_list_pattern(sysenv.cwd, *(buff+1));
      for (list=files ; list ; list=g_slist_next(list))
        {
        inp_pak = get_file_info(list->data, BY_EXTENSION);

        inp = g_build_filename(sysenv.cwd, list->data, NULL);

/* FIXME - changed to correct a problem with Florian's metadata store */
//        base = parse_strip(list->data);
        base = g_strdup(list->data);

        if (inp_pak)
          {
          if (inp_pak->read_file)
            {
            model = model_new();

            status = inp_pak->read_file(inp, model);

            structures = g_slist_find(sysenv.mal, model);

#if DEBUG_COMMAND_MAIN_LOOP
printf("Items loaded = %d [status = %d]\n", g_slist_length(structures), status);
#endif

            if (g_slist_length(structures) > 1)
              {
/* multiple output for input files that contain more than one structure */
              n = 1;
              for (item=structures ; item ; item=g_slist_next(item))
                {
                model = item->data;

                tmp = g_strdup_printf("%s_%d.%s", base, n, ext);
                out = g_build_filename(sysenv.cwd, tmp, NULL);

                status = out_pak->write_file(out, model);

#if DEBUG_COMMAND_MAIN_LOOP
printf("a [%s] -> [%s]\n", inp, out);
#endif
                g_free(out);
                g_free(tmp);
                model_free(model);
                n++;
                }
              }
            else
              {
              tmp = g_strdup_printf("%s.%s", base, ext);

              out = g_build_filename(sysenv.cwd, tmp, NULL);
              g_free(tmp);

              status = out_pak->write_file(out, model);

#if DEBUG_COMMAND_MAIN_LOOP
printf("b [%s] -> [%s]\n", inp, out);
#endif
              g_free(out);
              model_free(model);
              }
            }
          else
            printf("Error: read method for this filetype does not exist.\n");
          }
        else
          {
          printf("Error: unrecognized input filetype.\n");
          }
        g_free(base);
        g_free(inp);
        }


/* CURRENT hack */
if (!files)
  {
/* FIXME */

  }




      g_free(ext);

      free_slist(files);
      }
    else
      printf("Error: insufficient tokens for <copy> command\n");

    g_strfreev(buff);
    }

  if (g_ascii_strncasecmp("ls", line, 2) == 0)
    {
    buff = tokenize(line, &num_tokens);

    if (num_tokens > 1)
      files = file_dir_list_pattern(sysenv.cwd, *(buff+1));
    else
      files = file_dir_list(sysenv.cwd, FALSE);

    for (list=files ; list ; list=g_slist_next(list))
      {
      printf("%s\n", (gchar *) list->data);
      }

    g_strfreev(buff);
    }

  if (g_ascii_strncasecmp("cd", line, 2) == 0)
    {
    buff = tokenize(line, &num_tokens);

    if (num_tokens > 1)
      {
      inp = g_build_path(DIR_SEP, sysenv.cwd, *(buff+1), NULL);
      set_path(inp);
      g_free(inp);
      }

    printf("%s\n", sysenv.cwd);

    g_strfreev(buff);
    }

  if (g_ascii_strncasecmp("pwd", line, 3) == 0)
    {
    printf("%s\n", sysenv.cwd);
    }

  if (g_ascii_strncasecmp("?", line, 1) == 0 || g_ascii_strncasecmp("h", line, 1) == 0)
    {
    printf("GDIS v%4.2f available commands\n\n", VERSION);

    printf("cd <destination>\n");
    printf("    - changes to target directory\n");

    printf("pwd\n");
    printf("    - prints the current working directory\n");

    printf("ls\n");
    printf("    - lists the files in the current working directory\n");

    printf("copy <source> <destination>\n");
    printf("    - convert between filetypes, based on extension (wildcards allowed)\n");
    printf("quit\n");
    printf("    - exit program\n");
    }

/* done -> next line */
  g_free(line);
  }
while (!exit);
}
예제 #7
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);
}
예제 #8
0
파일: model_dos.c 프로젝트: rzel/dim3
bool model_file_new(void)
{
	char		file_name[256],err_str[256],
				base_path[1024],path[1024];

		// close model

	state.model.texture_edit_idx=-1;

	if (!model_file_close()) return(FALSE);
	
		// get name
	
	strcpy(file_name,"NewModel");
	if (!dialog_new_model_run(file_name)) {
		model_file_reset_state();
		return(FALSE);
	}

		// create model

	os_set_wait_cursor();
		
	model_new(&model,file_name);
	
	model.nmesh=1;
	strcpy(model.meshes[0].name,"Default");
	
	model.view_box.size.x=model.view_box.size.y=model.view_box.size.z=100;

	os_select_window();
	
	os_set_wait_cursor();
	
		// create new folders
		
	file_paths_data_default(&file_path_setup,base_path,"Models",NULL,NULL);
		
	strcat(base_path,"/");
	strcat(base_path,file_name);
	os_create_directory(base_path);
	
	sprintf(path,"%s/Textures",base_path);
	os_create_directory(path);

        // write the XML
	
	if (!model_save(&model,err_str)) {
		os_set_arrow_cursor();
		os_dialog_alert("dim3 Animator could not save model.",err_str);
		model_file_reset_state();
		return(FALSE);
	}
	
	os_set_arrow_cursor();
	
		// finish
		
	state.model.model_open=TRUE;
	strcpy(state.model.model_file_name,file_name);
	
	model_file_reset_state();
	
	return(TRUE);
}