mol.c

来自「最经典的分子对结软件」· C语言 代码 · 共 2,539 行 · 第 1/5 页

C
2,539 行
字号
  int i;  for (i = 0; i < molecule->max.layers; i++)    reset_layer (molecule, i);  molecule->total.layers = 0;}/* ///////////////////////////////////////////////////////////// */void reset_layer (MOLECULE *molecule, int layer){  int segment;  int segment_id;  for  (    segment_id = 0;    segment_id < molecule->layer[layer].segment_total;    segment_id++  )  {    segment = molecule->layer[layer].segment[segment_id];    molecule->segment[segment].layer_id = NEITHER;  }  molecule->layer[layer].id = NEITHER;  molecule->layer[layer].active_flag = FALSE;  molecule->layer[layer].conform_total = 1;  reset_score (&molecule->layer[layer].score);  molecule->layer[layer].segment_total = 0;  memset  (    molecule->layer[layer].segment,    0,    molecule->layer[layer].segment_max * sizeof (int)  );}/* ///////////////////////////////////////////////////////////// */void free_layers (MOLECULE *molecule){  int i;  for (i = 0; i < molecule->max.layers; i++)    free_layer_segments (&molecule->layer[i]);  efree ((void **) &molecule->layer);  molecule->max.layers = 0;}/* ///////////////////////////////////////////////////////////// */void free_layer_segments (LAYER *layer){  efree ((void **) &layer->segment);  layer->segment_max = 0;}/* ///////////////////////////////////////////////////////////// */void reallocate_layers (MOLECULE *molecule){  if (molecule->total.layers > molecule->max.layers)  {    free_layers (molecule);    molecule->max.layers = molecule->total.layers;    allocate_layers (molecule);  }}/* ///////////////////////////////////////////////////////////// */void reallocate_layer_segments (LAYER *layer){  if (layer->segment_total > layer->segment_max)  {    free_layer_segments (layer);    layer->segment_max = layer->segment_total;    allocate_layer_segments (layer);  }}/* ///////////////////////////////////////////////////////////// */void copy_layers (MOLECULE *copy, MOLECULE *original){  int i, j;  int segment;  copy->total.layers = original->total.layers;  reallocate_layers (copy);  for (i = 0; i < original->total.layers; i++)  {    copy_layer (&copy->layer[i], &original->layer[i]);    for (j = 0; j < copy->layer[i].segment_total; j++)    {      segment = copy->layer[i].segment[j];      if ((segment >= 0) && (segment < copy->total.segments))        copy->segment[segment].layer_id = i;      else        exit (fprintf (global.outfile,          "ERROR copy_layers: unable to update segments\n"));    }  }}/* ///////////////////////////////////////////////////////////// */void copy_layer (LAYER *copy, LAYER *original){  copy->id = original->id;  copy->active_flag = original->active_flag;  copy->conform_total = original->conform_total;  copy_score (&copy->score, &original->score);  copy->segment_total = original->segment_total;  reallocate_layer_segments (copy);  memcpy    (copy->segment, original->segment,    original->segment_total * sizeof (int));}/* ///////////////////////////////////////////////////////////// */void save_layers (MOLECULE *molecule, FILE *file){  int i;  for (i = 0; i < molecule->max.layers; i++)    save_layer (&molecule->layer[i], file);}/* ///////////////////////////////////////////////////////////// */void save_layer (LAYER *layer, FILE *file){  efwrite (&layer->id, sizeof (int), 1, file);  efwrite (&layer->active_flag, sizeof (int), 1, file);  efwrite (&layer->conform_total, sizeof (int), 1, file);  save_score (&layer->score, file);  efwrite (&layer->segment_total, sizeof (int), 1, file);  efwrite (&layer->segment_max, sizeof (int), 1, file);  efwrite (layer->segment, sizeof (int), layer->segment_max, file);}/* ///////////////////////////////////////////////////////////// */void load_layers (MOLECULE *molecule, FILE *file){  int i;  for (i = 0; i < molecule->max.layers; i++)    load_layer (&molecule->layer[i], file);}/* ///////////////////////////////////////////////////////////// */void load_layer (LAYER *layer, FILE *file){  efread (&layer->id, sizeof (int), 1, file);  efread (&layer->active_flag, sizeof (int), 1, file);  efread (&layer->conform_total, sizeof (int), 1, file);  load_score (&layer->score, file);  efread (&layer->segment_total, sizeof (int), 1, file);  efread (&layer->segment_max, sizeof (int), 1, file);  allocate_layer_segments (layer);  efread (layer->segment, sizeof (int), layer->segment_max, file);}/* ///////////////////////////////////////////////////////////// *//* ///////////////////////////////////////////////////////////// */void allocate_sets (MOLECULE *molecule){  int i;  if (molecule->max.sets > 0)    ecalloc    (      (void **) &molecule->set,      molecule->max.sets,      sizeof (SET),      molecule->info.name,      global.outfile    );  for (i = 0; i < molecule->max.sets; i++)    reset_set (&molecule->set[i]);}/* ///////////////////////////////////////////////////////////// */void reset_sets (MOLECULE *molecule){  int i;  for (i = 0; i < molecule->max.sets; i++)    reset_set (&molecule->set[i]);  molecule->total.sets = 0;}/* ///////////////////////////////////////////////////////////// */void reset_set (SET *set){  efree ((void **) &set->name);  efree ((void **) &set->type);  efree ((void **) &set->obj_type);  efree ((void **) &set->sub_type);  efree ((void **) &set->status);  efree ((void **) &set->comment);  efree ((void **) &set->member);  memset (set, 0, sizeof (SET));}/* ///////////////////////////////////////////////////////////// */void free_sets (MOLECULE *molecule){  int i;  for (i = 0; i < molecule->max.sets; i++)    free_set (&molecule->set[i]);  efree ((void **) &molecule->set);  molecule->max.sets = 0;}/* ///////////////////////////////////////////////////////////// */void free_set (SET *set){  efree ((void **) &set->name);  efree ((void **) &set->type);  efree ((void **) &set->obj_type);  efree ((void **) &set->sub_type);  efree ((void **) &set->status);  efree ((void **) &set->comment);  efree ((void **) &set->member);  set->member_total = 0;}/* ///////////////////////////////////////////////////////////// */void reallocate_sets (MOLECULE *molecule){  if (molecule->total.sets > molecule->max.sets)  {    free_sets (molecule);    molecule->max.sets = molecule->total.sets;    allocate_sets (molecule);  }}/* ///////////////////////////////////////////////////////////// */void copy_sets (MOLECULE *copy, MOLECULE *original){  int i;  copy->total.sets = original->total.sets;  reallocate_sets (copy);  for (i = 0; i < original->total.sets; i++)    copy_set (&copy->set[i], &original->set[i]);  copy->total.sets = original->total.sets;}/* ///////////////////////////////////////////////////////////// */void copy_set (SET *copy, SET *original){  int i;  vstrcpy (&copy->name, original->name);  vstrcpy (&copy->type, original->type);  vstrcpy (&copy->obj_type, original->obj_type);  vstrcpy (&copy->sub_type, original->sub_type);  vstrcpy (&copy->status, original->status);  vstrcpy (&copy->comment, original->comment);  if (copy->member_total != original->member_total)  {    efree ((void **) &copy->member);    ecalloc    (      (void **) &copy->member,      original->member_total,      sizeof (int),      "set members",      global.outfile    );    copy->member_total = original->member_total;  }  for (i = 0; i < original->member_total; i++)    copy->member[i] = original->member[i];}/* ///////////////////////////////////////////////////////////// */void save_sets (MOLECULE *molecule, FILE *file){  int i;  for (i = 0; i < molecule->max.sets; i++)    save_set (&molecule->set[i], file);}/* ///////////////////////////////////////////////////////////// */void save_set (SET *set, FILE *file){  efwrite (set, sizeof (SET), 1, file);  save_string (&set->name, file);  save_string (&set->type, file);  save_string (&set->obj_type, file);  save_string (&set->sub_type, file);  save_string (&set->status, file);  save_string (&set->comment, file);  efwrite (set->member, sizeof (int), set->member_total, file);}/* ///////////////////////////////////////////////////////////// */void load_sets (MOLECULE *molecule, FILE *file){  int i;  for (i = 0; i < molecule->max.sets; i++)    load_set (&molecule->set[i], file);}/* ///////////////////////////////////////////////////////////// */void load_set (SET *set, FILE *file){  efread (set, sizeof (SET), 1, file);  set->name = NULL;  set->type = NULL;  set->obj_type = NULL;  set->sub_type = NULL;  set->status = NULL;  set->comment = NULL;  set->member = NULL;  load_string (&set->name, file);  load_string (&set->type, file);  load_string (&set->obj_type, file);  load_string (&set->sub_type, file);  load_string (&set->status, file);  load_string (&set->comment, file);  emalloc  (    (void **) &set->member,    set->member_total * sizeof (int),    "loaded set members",    global.outfile  );  efread (set->member, sizeof (int), set->member_total, file);}/* ///////////////////////////////////////////////////////////// *//* ///////////////////////////////////////////////////////////// */void allocate_keys (MOLECULE *molecule){  int i;  if (molecule->max.keys > 0)  {    ecalloc    (      (void **) &molecule->key,      molecule->max.keys,      sizeof (KEY *),      molecule->info.name,      global.outfile    );    for (i = 0; i < molecule->max.keys; i++)      ecalloc      (        (void **) &molecule->key[i],        molecule->max.keys,        sizeof (KEY),        molecule->info.name,        global.outfile      );  }}/* ///////////////////////////////////////////////////////////// */void reset_keys (MOLECULE *molecule){  int i, j;  for (i = 0; i < molecule->max.keys; i++)    for (j = 0; j < molecule->max.keys; j++)    {      molecule->key[i][j].count = 0;      molecule->key[i][j].distance = (MASK) 0;    }  molecule->total.keys = 0;}/* ///////////////////////////////////////////////////////////// */void free_keys (MOLECULE *molecule){  int i;  for (i = 0; i < molecule->max.keys; i++)    efree ((void **) &molecule->key[i]);  efree ((void **) &molecule->key);  molecule->max.keys = 0;}/* ///////////////////////////////////////////////////////////// */void reallocate_keys (MOLECULE *molecule){  if (molecule->total.keys > molecule->max.keys)  {    free_keys (molecule);    molecule->max.keys = molecule->total.keys;    allocate_keys (molecule);  }}/* ///////////////////////////////////////////////////////////// */void copy_keys (MOLECULE *copy, MOLECULE *original){  int i;  copy->total.keys = original->total.keys;  reallocate_keys (copy);  for (i = 0; i < original->total.keys; i++)    memcpy    (      copy->key[i],      original->key[i],      original->total.keys * sizeof (KEY)    );}/* ///////////////////////////////////////////////////////////// */void save_keys (MOLECULE *molecule, FILE *file){  int i;  for (i = 0; i < molecule->max.keys; i++)    efwrite (molecule->key[i], sizeof (KEY), molecule->max.keys, file);}/* ///////////////////////////////////////////////////////////// */void load_keys (MOLECULE *molecule, FILE *file){  int i;  for (i = 0; i < molecule->max.keys; i++)    efread (molecule->key[i], sizeof (KEY), molecule->max.keys, file);}/* //////////////////////////////////////////////////////////// *//*Routine to save the contents of a dynamically allocated characterstring.2/96 te*/void save_string (char **string, FILE *file){  int length;/** If the string has been allocated, then find the length + 1 (for* the null character)* 2/96 te*/  if (*string)    length = strlen (*string) + 1;

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?