Example #1
0
gint core_undelete(struct model_pak *model, GSList *list)
{
struct core_pak *core;
struct shel_pak *shell;

g_assert(model != NULL);
g_assert(list != NULL);

core = list->data;

core->status &= ~DELETED;

model->cores = g_slist_prepend(model->cores, core);
if (core->shell)
  {
  shell = core->shell;

  shell->status &= ~DELETED;
  model->shels = g_slist_prepend(model->shels, core->shell);
  }

/* FIXME - this doesnt work */
/*
connect_atom_compute(core, model);
*/

/* TODO - more fine grained molecule recalc (ie recalc of affected molecules only) */
connect_bonds(model);
connect_molecules(model);

return(TRUE);
}
Example #2
0
void core_delete_single(struct core_pak *core, struct model_pak *model)
{
GSList *list;

/* flag the core as deleted */
delete_core(core);

/* remove core references */
connect_atom_clear(core, model);

/* register the undo */
/* TODO - when a model is deleted - flush related undo's to avoid mem leaks */
list = NULL;
list = g_slist_prepend(list, core);
undo_register(model, core_undelete, list);

/* remove from lists */
model->cores = g_slist_remove(model->cores, core);
if (core->shell)
  model->shels = g_slist_remove(model->shels, core->shell);

/* TODO - more fine grained molecule recalc (ie recalc of affected molecules only) */
connect_molecules(model);
}
Example #3
0
void delete_commit(struct model_pak *data)
{
gint flag1=FALSE, flag2=FALSE;
gpointer m;
GSList *list1, *list2;
struct core_pak *core;
struct shel_pak *shell;
struct bond_pak *bond;

g_assert(data != NULL);

/* delete flaged cores in list */
list1 = data->cores;
while (list1)
  {
  core = list1->data;
  list1 = g_slist_next(list1);

  if (core->status & DELETED)
    {
#if DEBUG_DELETE_COMMIT
printf("Deleting %s core [%p] ...\n", core->label, core);
#endif
    flag1 = TRUE;

/* flag assoc. shell */
    if (core->shell)
      {
      shell = core->shell;
      shell->status |= DELETED;
      }

/* update connectivity */
    connect_atom_clear(core, data);
    list2 = data->ubonds;
    while (list2)
      {
      bond = list2->data;
      list2 = g_slist_next(list2);

      if (bond->atom1 == core || bond->atom2 == core)
        {
        data->ubonds = g_slist_remove(data->ubonds, bond);
        g_free(bond);
        }
      }

/* update selection */
    data->selection = g_slist_remove(data->selection, core);

/* delete any labels that reference the deleted core */
    list2 = data->measure_list;
    while (list2)
      {
      m = list2->data;
      list2 = g_slist_next(list2);
      if (measure_has_core(core, m))
        measure_free(m, data);
      }
/* update main list */
    data->cores = g_slist_remove(data->cores, core);
    g_free(core);
    }
  }

/* delete flaged shells in list */
list1 = data->shels;
while (list1)
  {
  shell = list1->data;
  list1 = g_slist_next(list1);

  if (shell->status & DELETED)
    {
    flag2 = TRUE;
/* update main list */
    data->shels = g_slist_remove(data->shels, shell);
    g_free(shell);
    }
  }

/* refresh totals */
data->num_atoms = g_slist_length(data->cores);
data->num_shells = g_slist_length(data->shels);

/* refresh spatial partitioning */
/* it's probably best to refresh the partitioning here, rather than */
/* incrementally as it's speedups for large models we're targeting */
zone_init(data);

/* cope with deleted bonds - expensive, so only do if required */
if (flag1)
  {
  connect_bonds(data);
  connect_molecules(data);
  }

/* refresh net charge calc */
calc_emp(data);

/* refresh unique atom list */
g_slist_free(data->unique_atom_list);
data->unique_atom_list = find_unique(ELEMENT, data);

/* refresh widgets */
meas_graft_model(data);
gui_refresh(GUI_MODEL_PROPERTIES);

/* reset functions with static pointers to cores */
data->state = 0;
}
Example #4
0
gint read_frame(FILE *fp, gint n, struct model_pak *model)
{
    gint status;
    gdouble rmax, v1[3], v2[3];
    gpointer camera=NULL;
    GString *err_text;

    g_assert(model != NULL);

    rmax = model->rmax;

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

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

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

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

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

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

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

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

    return(0);
}