mol.c

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

C
2,539 行
字号
  molecule->total.substs = 0;}/* ///////////////////////////////////////////////////////////// */void reset_subst (SUBST *subst){  efree ((void **) &subst->name);  efree ((void **) &subst->type);  efree ((void **) &subst->chain);  efree ((void **) &subst->sub_type);  efree ((void **) &subst->status);  memset (subst, 0, sizeof (SUBST));}/* ///////////////////////////////////////////////////////////// */void free_substs (MOLECULE *molecule){  int i;  for (i = 0; i < molecule->max.substs; i++)    free_subst (&molecule->subst[i]);  efree ((void **) &molecule->subst);  molecule->max.substs = 0;}/* ///////////////////////////////////////////////////////////// */void free_subst (SUBST *subst){  efree ((void **) &subst->name);  efree ((void **) &subst->type);  efree ((void **) &subst->chain);  efree ((void **) &subst->sub_type);  efree ((void **) &subst->status);}/* ///////////////////////////////////////////////////////////// */void reallocate_substs (MOLECULE *molecule){  if (molecule->total.substs > molecule->max.substs)  {    free_substs (molecule);    molecule->max.substs = molecule->total.substs;    allocate_substs (molecule);  }}/* ///////////////////////////////////////////////////////////// */void copy_substs (MOLECULE *copy, MOLECULE *original){  int i;  copy->total.substs = original->total.substs;  reallocate_substs (copy);  for (i = 0; i < original->total.substs; i++)    copy_subst (&copy->subst[i], &original->subst[i]);  copy->total.substs = original->total.substs;}/* ///////////////////////////////////////////////////////////// */void copy_subst (SUBST *copy, SUBST *original){  copy->number = original->number;  copy->root_atom = original->root_atom;  copy->dict_type = original->dict_type;  copy->inter_bonds = original->inter_bonds;  vstrcpy (&copy->name, original->name);  vstrcpy (&copy->type, original->type);  vstrcpy (&copy->chain, original->chain);  vstrcpy (&copy->sub_type, original->sub_type);  vstrcpy (&copy->status, original->status);}/* ///////////////////////////////////////////////////////////// */void save_substs (MOLECULE *molecule, FILE *file){  int i;  for (i = 0; i < molecule->max.substs; i++)    save_subst (&molecule->subst[i], file);}/* ///////////////////////////////////////////////////////////// */void save_subst (SUBST *subst, FILE *file){  efwrite (subst, sizeof (SUBST), 1, file);  save_string (&subst->name, file);  save_string (&subst->type, file);  save_string (&subst->chain, file);  save_string (&subst->sub_type, file);  save_string (&subst->status, file);}/* ///////////////////////////////////////////////////////////// */void load_substs (MOLECULE *molecule, FILE *file){  int i;  for (i = 0; i < molecule->max.substs; i++)    load_subst (&molecule->subst[i], file);}/* ///////////////////////////////////////////////////////////// */void load_subst (SUBST *subst, FILE *file){  efread (subst, sizeof (SUBST), 1, file);  subst->name = NULL;  subst->type = NULL;  subst->chain = NULL;  subst->sub_type = NULL;  subst->status = NULL;  load_string (&subst->name, file);  load_string (&subst->type, file);  load_string (&subst->chain, file);  load_string (&subst->sub_type, file);  load_string (&subst->status, file);}/* ///////////////////////////////////////////////////////////// *//* ///////////////////////////////////////////////////////////// */void allocate_segments (MOLECULE *molecule){  int i, j;  ecalloc  (    (void **) &molecule->segment,    molecule->max.segments,    sizeof (SEGMENT),    molecule->info.name,    global.outfile  );  for (i = 0; i < molecule->max.segments; i++)    reset_segment (&molecule->segment[i]);}/* ///////////////////////////////////////////////////////////// */void allocate_segment_atoms (SEGMENT *segment){  if (segment->atom_max > 0)  {    ecalloc    (      (void **) &segment->atom,      segment->atom_max,      sizeof (int),      "segment atoms",      global.outfile    );  }}/* ///////////////////////////////////////////////////////////// */void allocate_segment_neighbors (SEGMENT *segment){  int i;  if (segment->neighbor_max > 0)  {    ecalloc    (      (void **) &segment->neighbor,      segment->neighbor_max,      sizeof (LINK),      "segment neighbors",      global.outfile    );    for (i = 0; i < segment->neighbor_max; i++)    {      segment->neighbor[i].id = NEITHER;      segment->neighbor[i].bond_id = NEITHER;      segment->neighbor[i].out_flag = FALSE;    }  }}/* ///////////////////////////////////////////////////////////// */void reset_segments (MOLECULE *molecule){  int i;  for (i = 0; i < molecule->max.segments; i++)    reset_segment (&molecule->segment[i]);  molecule->total.segments = 0;}/* ///////////////////////////////////////////////////////////// */void reset_segment (SEGMENT *segment){  segment->id = NEITHER;  segment->torsion_id = NEITHER;  segment->layer_id = NEITHER;  segment->periph_flag = NEITHER;  segment->heavy_total = 0;  segment->active_flag = FALSE;  segment->min_flag = FALSE;  segment->conform_count = 0;  segment->conform_total = 1;  reset_score (&segment->score);  memset (segment->atom, 0, segment->atom_max * sizeof (int));  segment->atom_total = 0;  reset_segment_neighbors (segment);}/* ///////////////////////////////////////////////////////////// */void reset_segment_neighbors (SEGMENT *segment){  int i;  for (i = 0; i < segment->neighbor_max; i++)  {    segment->neighbor[i].id = NEITHER;    segment->neighbor[i].bond_id = NEITHER;    segment->neighbor[i].out_flag = FALSE;  }  segment->neighbor_total = 0;}/* ///////////////////////////////////////////////////////////// */void free_segments (MOLECULE *molecule){  int i;  for (i = 0; i < molecule->max.segments; i++)  {    free_segment_atoms (&molecule->segment[i]);    free_segment_neighbors (&molecule->segment[i]);  }  efree ((void **) &molecule->segment);  molecule->max.segments = 0;}/* ///////////////////////////////////////////////////////////// */void free_segment_atoms (SEGMENT *segment){  efree ((void **) &segment->atom);  segment->atom_max = 0;}/* ///////////////////////////////////////////////////////////// */void free_segment_neighbors (SEGMENT *segment){  efree ((void **) &segment->neighbor);  segment->neighbor_max = 0;}/* ///////////////////////////////////////////////////////////// */void reallocate_segments (MOLECULE *molecule){  if (molecule->total.segments > molecule->max.segments)  {    free_segments (molecule);    molecule->max.segments = molecule->total.segments;    allocate_segments (molecule);  }}/* ///////////////////////////////////////////////////////////// */void reallocate_segment_atoms (SEGMENT *segment){  if (segment->atom_total > segment->atom_max)  {    free_segment_atoms (segment);    segment->atom_max = segment->atom_total;    allocate_segment_atoms (segment);  }}/* ///////////////////////////////////////////////////////////// */void reallocate_segment_neighbors (SEGMENT *segment){  if (segment->neighbor_total > segment->neighbor_max)  {    free_segment_neighbors (segment);    segment->neighbor_max = segment->neighbor_total;    allocate_segment_neighbors (segment);  }}/* ///////////////////////////////////////////////////////////// */void copy_segments (MOLECULE *copy, MOLECULE *original){  int i, j;  int atom;  copy->total.segments = original->total.segments;  reallocate_segments (copy);  for (i = 0; i < original->total.segments; i++)  {    copy_segment (&copy->segment[i], &original->segment[i]);    for (j = 0; j < copy->segment[i].atom_total; j++)    {      atom = copy->segment[i].atom[j];      if ((atom >= 0) && (atom < copy->total.atoms))        copy->atom[atom].segment_id = i;      else        exit (fprintf (global.outfile,          "ERROR copy_segments: unable to copy atoms\n"));    }  }  if ((copy->total.atoms > 0) &&    (copy->total.segments > 1) &&    (copy->transform.anchor_atom != NEITHER))    revise_atom_neighbors (copy);/**/}/* ///////////////////////////////////////////////////////////// */void copy_segment (SEGMENT *copy, SEGMENT *original){  copy->id = original->id;  copy->torsion_id = original->torsion_id;  copy->layer_id = original->layer_id;  copy->periph_flag = original->periph_flag;  copy->heavy_total = original->heavy_total;  copy->active_flag = original->active_flag;  copy->min_flag = original->min_flag;  copy->conform_count = original->conform_count;  copy->conform_total = original->conform_total;  copy_score (&copy->score, &original->score);  copy->atom_total = original->atom_total;  reallocate_segment_atoms (copy);  memcpy    (copy->atom, original->atom,    original->atom_total * sizeof (int));  copy->neighbor_total = original->neighbor_total;  reallocate_segment_neighbors (copy);  memcpy    (copy->neighbor, original->neighbor,    original->neighbor_total * sizeof (LINK));}/* ///////////////////////////////////////////////////////////// */void save_segments (MOLECULE *molecule, FILE *file){  int i;  for (i = 0; i < molecule->max.segments; i++)    save_segment (&molecule->segment[i], file);}/* ///////////////////////////////////////////////////////////// */void save_segment (SEGMENT *segment, FILE *file){  efwrite (&segment->id, sizeof (int), 1, file);  efwrite (&segment->torsion_id, sizeof (int), 1, file);  efwrite (&segment->layer_id, sizeof (int), 1, file);  efwrite (&segment->heavy_total, sizeof (int), 1, file);  efwrite (&segment->periph_flag, sizeof (int), 1, file);  efwrite (&segment->active_flag, sizeof (int), 1, file);  efwrite (&segment->min_flag, sizeof (int), 1, file);  efwrite (&segment->conform_count, sizeof (int), 1, file);  efwrite (&segment->conform_total, sizeof (int), 1, file);  save_score (&segment->score, file);  efwrite (&segment->atom_total, sizeof (int), 1, file);  efwrite (&segment->atom_max, sizeof (int), 1, file);  efwrite (segment->atom, sizeof (int), segment->atom_max, file);  efwrite (&segment->neighbor_total, sizeof (int), 1, file);  efwrite (&segment->neighbor_max, sizeof (int), 1, file);  efwrite (segment->neighbor, sizeof (LINK), segment->neighbor_max, file);}/* ///////////////////////////////////////////////////////////// */void load_segments (MOLECULE *molecule, FILE *file){  int i;  for (i = 0; i < molecule->max.segments; i++)    load_segment (&molecule->segment[i], file);}/* ///////////////////////////////////////////////////////////// */void load_segment (SEGMENT *segment, FILE *file){  efread (&segment->id, sizeof (int), 1, file);  efread (&segment->torsion_id, sizeof (int), 1, file);  efread (&segment->layer_id, sizeof (int), 1, file);  efread (&segment->heavy_total, sizeof (int), 1, file);  efread (&segment->periph_flag, sizeof (int), 1, file);  efread (&segment->active_flag, sizeof (int), 1, file);  efread (&segment->min_flag, sizeof (int), 1, file);  efread (&segment->conform_count, sizeof (int), 1, file);  efread (&segment->conform_total, sizeof (int), 1, file);  load_score (&segment->score, file);  efread (&segment->atom_total, sizeof (int), 1, file);  efread (&segment->atom_max, sizeof (int), 1, file);  allocate_segment_atoms (segment);  efread (segment->atom, sizeof (int), segment->atom_max, file);  efread (&segment->neighbor_total, sizeof (int), 1, file);  efread (&segment->neighbor_max, sizeof (int), 1, file);  allocate_segment_neighbors (segment);  efread (segment->neighbor, sizeof (LINK), segment->neighbor_max, file);}/* ///////////////////////////////////////////////////////////// */int get_segment_neighbor(  void		*segment,  int		segment_id,  int		neighbor_id){  if (neighbor_id < ((SEGMENT *) segment)[segment_id].neighbor_total)    return ((SEGMENT *) segment)[segment_id].neighbor[neighbor_id].id;  else    return EOF;}/* ///////////////////////////////////////////////////////////// *//* ///////////////////////////////////////////////////////////// */void allocate_layers (MOLECULE *molecule){  int i;  if (molecule->max.layers > 0)  {    ecalloc    (      (void **) &molecule->layer,      molecule->max.layers,      sizeof (LAYER),      molecule->info.name,      global.outfile    );  }  for (i = 0; i < molecule->max.layers; i++)    reset_layer (molecule, i);}/* ///////////////////////////////////////////////////////////// */void allocate_layer_segments (LAYER *layer){  if (layer->segment_max > 0)  {    ecalloc    (      (void **) &layer->segment,      layer->segment_max,      sizeof (int),      "layer atoms",      global.outfile    );  }}/* ///////////////////////////////////////////////////////////// */void reset_layers (MOLECULE *molecule){

⌨️ 快捷键说明

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