score_dock.c

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

C
2,053 行
字号
  efree ((void **) &list->member[type]);  list->max[type] = 0;}/* //////////////////////////////////////////////////////////////////// */void reallocate_lists (SCORE *score, LIST *list){  int i;  for (i = 0; i < SCORE_TOTAL; i++)    if (score->type[i].flag == TRUE)      reallocate_list (list, i);}/* //////////////////////////////////////////////////////////////////// */void reallocate_list (LIST *list, int type){  if (list->max[type] < list->total[type])  {    free_list (list, type);    list->max[type] = list->total[type];    allocate_list (list, type);  }}/* //////////////////////////////////////////////////////////////////// */void copy_lists (SCORE *score, LIST *copy, LIST *original){  int i;  for (i = 0; i < SCORE_TOTAL; i++)    if (score->type[i].flag == TRUE)      copy_list (copy, original, i);}/* //////////////////////////////////////////////////////////////////// */void copy_list (LIST *copy, LIST *original, int type){  int i;  copy->total[type] = original->total[type];  reallocate_list (copy, type);  for (i = 0; i < original->total[type]; i++)    copy_member      (original->lite_flag, copy->member[type][i], original->member[type][i]);  copy->total[type] = original->total[type];}/* //////////////////////////////////////////////////////////////////// */void inter_lists (SCORE *score, LIST *list, MOLECULE *reference){  int i, j;  for (i = 0; i < SCORE_TOTAL; i++)    if (score->type[i].flag == TRUE)    {      for (j = 0; j < list->total[i]; j++)        list->member[i][j]->score.total =           list->member[i][j]->score.inter.total +          list->member[i][j]->transform.heavy_total *            score->type[i].size_penalty;      sort_list (list, i);      if (i != RMSD)      {        for (j = 0; j < list->total[i]; j++)          if (list->member[i][j]->score.total > 0)            list->total[i] = j;        if (list->total[i] == 0)        {          reference->score.type = i;          reference->score.total = 0;          update_list (list, reference);        }      }    }}/* //////////////////////////////////////////////////////////////////// */void merge_lists (SCORE *score, LIST *list, LIST *add_list){  int i, j;  for (i = 0; i < SCORE_TOTAL; i++)    if (score->type[i].flag == TRUE)      for (j = 0; (j < add_list->total[i]) && (j < list->max[i]); j++)        update_list (list, add_list->member[i][j]);}/* //////////////////////////////////////////////////////////////////// */void update_list(  LIST *list,  MOLECULE *molecule){  int type;  type = molecule->score.type;  if ((type < 0) || (type >= SCORE_TOTAL))  {    fprintf (global.outfile, "ERROR update_list: Accessing illegal list.\n");    exit (EXIT_FAILURE);  }  if (list->total[type] < list->max[type])    copy_member    (      list->lite_flag,      list->member[type][list->total[type]++],      molecule    );  else if (type == 0)    copy_member    (      list->lite_flag,      list->member[type][list->max[type] - 1],      molecule    );  else if (molecule->score.total <    list->member[type][list->max[type] - 1]->score.total)    copy_member    (      list->lite_flag,      list->member[type][list->max[type] - 1],      molecule    );  else    return;  sort_list (list, type);}/* //////////////////////////////////////////////////////////////////// */int compare_score (MOLECULE *reference, MOLECULE *candidate){  if  (    (reference->info.name != NULL) &&    (candidate->info.name != NULL) &&    !strcmp (reference->info.name, candidate->info.name)  )  {    if (candidate->score.total < reference->score.total)      return TRUE;  }  else  {    if (candidate->score.inter.total < reference->score.inter.total)      return TRUE;  }  return FALSE;}/* //////////////////////////////////////////////////////////////////// */void sort_list (LIST *list, int type){  if (list->total[type] > 1)    qsort    (      list->member[type],       list->total[type],       sizeof (MOLECULE *),      (int (*)()) compare_member    );}/* //////////////////////////////////////////////////////////////////// */void copy_member (int lite_flag, MOLECULE *old, MOLECULE *new){  if (lite_flag == TRUE)  {    copy_info (old, new);    copy_transform (old, new);    copy_score (&old->score, &new->score);    copy_torsions (old, new);    copy_keys (old, new);  }  else    copy_molecule (old, new);}/* //////////////////////////////////////////////////////////////////// */int compare_member (MOLECULE **mol1, MOLECULE **mol2){  return ((*mol1)->score.total == (*mol2)->score.total) ? 0 :    (((*mol1)->score.total > (*mol2)->score.total) ? 1 : -1);} /* //////////////////////////////////////////////////////////////////// */int print_lists (SCORE *score, LIST *list, FILE *file){  int i;  if (file == NULL)    return FALSE;  for (i = 0; i < SCORE_TOTAL; i++)    if (score->type[i].flag == TRUE)      print_list (score, list, i, file);  return TRUE;} /* //////////////////////////////////////////////////////////////////// */int print_list (SCORE *score, LIST *list, int type, FILE *file){  int i;  if (file == NULL)    return FALSE;  if (score->type[type].flag == TRUE)  {    fprintf (file, "%-4s %8s %8s\n", "rank", score->type[type].name, "rmsd");    for (i = 0; i < list->total[type]; i++)      fprintf (file, "%4d %8.2f %8.2f\n",        i + 1, list->member[type][i]->score.total,        list->member[type][i]->transform.rmsd);  }  else    return FALSE;  return TRUE;}/* //////////////////////////////////////////////////////////////////// */int save_lists (SCORE *score, LIST *list, FILE *file){  int i, j;  for (i = 0; i < SCORE_TOTAL; i++)  {    if (score->type[i].flag == TRUE)    {      efwrite (&list->total[i], sizeof (int), 1, file);      for (j = 0; j < list->total[i]; j++)        save_molecule (list->member[i][j], file);    }  }  return TRUE;}/* //////////////////////////////////////////////////////////////////// */int load_lists (SCORE *score, LIST *list, FILE *file){  int i, j;  for (i = 0; i < SCORE_TOTAL; i++)  {    if (score->type[i].flag == TRUE)    {      efread (&list->total[i], sizeof (int), 1, file);      if (list->total[i] > list->max[i])        return FALSE;      for (j = 0; j < list->total[i]; j++)        load_molecule (list->member[i][j], file);    }  }  return TRUE;}/* //////////////////////////////////////////////////////////////////// */void shrink_list(  LIST		*full,  LIST		*shrunk,  int		type,  float		rank_rmsd_cutoff){  int i, j;  int remainder;  static int *discard = NULL;  static int size = 0;  int discard_member;  float rmsd;  if (full->total[type] <= 0)  {    fprintf (global.outfile,      "WARNING shrink_list: No members provided\n");    return;  }/** Eliminate members with extremely repulsive scores* 1/98 te*/  for (i = 0; i < full->total[type]; i++)    if (full->member[type][i]->score.total >= INITIAL_SCORE)      full->total[type] = i;  /** Allocate arrays* 3/97 te*/  if (size < full->total[type])  {    efree ((void **) &discard);    size = full->total[type];    ecalloc    (      (void **) &discard,      size,      sizeof (int),      "shrink discard array",      global.outfile    );  }  else    memset (discard, 0, size * sizeof (int));/** Discard members outside rank/rmsd cutoff of better scoring members* 1/98 te*/  for (i = 0; i < full->total[type]; i++)    if (!discard[i])      for (j = i + 1; j < full->total[type]; j++)        if (!discard[j])        {          rmsd = calc_layer_rmsd (full->member[type][i], full->member[type][j]);          rmsd = MAX (rmsd, 0.001);          if ((float) j / rmsd > rank_rmsd_cutoff)            discard[j] = TRUE;        }/** Transfer remainder over to shrunk list* 3/97 te*/  if (shrunk->total[type] < full->total[type])  {    shrunk->total[type] = full->total[type];    reallocate_list (shrunk, type);    shrunk->total[type] = 0;  }  else    reset_list (shrunk, type);  for (i = 0; i < full->total[type]; i++)    if (!discard[i])      update_list (shrunk, full->member[type][i]);}/* /////////////////////////////////////////////////////////////////// */void initialize_near(  NEAR		*near,  MOLECULE	*molecule) {  int i, j, k;  int ni, nni;/** Check if near data is up-to-date* 3/97 te*/  if  (    (near->total == molecule->total.atoms) &&    (near->name != NULL) &&    (molecule->info.name != NULL) &&    !strcmp (near->name, molecule->info.name)  )    return;/** Either reallocate space for the flags or reset them* 3/97 te*/  if (near->total < molecule->total.atoms)  {    free_near (near);    near->total = molecule->total.atoms;    allocate_near (near);  }  else    for (i = 0; i < near->total; i++)      memset (near->flag[i], 0, near->total * sizeof (int));  vstrcpy (&near->name, molecule->info.name);  for (i = 0; i < molecule->total.atoms; i++)    for (j = 0; j < molecule->atom[i].neighbor_total; j++)    {      ni = molecule->atom[i].neighbor[j].id;      near->flag[i][ni] = near->flag[ni][i] = TRUE;      for (k = 0; k < molecule->atom[ni].neighbor_total; k++)      {        nni = molecule->atom[ni].neighbor[k].id;        near->flag[i][nni] = near->flag[nni][i] = TRUE;      }    }}/* /////////////////////////////////////////////////////////////////// */void allocate_near (NEAR *near){  int i;  ecalloc  (    (void **) &near->flag,    near->total,    sizeof (int *),    "near flag array",    global.outfile  );  for (i = 0; i < near->total; i++)    ecalloc    (      (void **) &near->flag[i],      near->total,      sizeof (int *),      "near flag array",      global.outfile    );}/* /////////////////////////////////////////////////////////////////// */void free_near (NEAR *near){  int i;  for (i = 0; i < near->total; i++)    efree ((void **) &near->flag[i]);  efree ((void **) &near->flag);  efree ((void **) &near->name);}/* /////////////////////////////////////////////////////////////////// */void free_scores (LABEL *label, SCORE *score){  free_near (&score->near);  if (score->grid.flag)    free_grids    (      &score->grid,      &score->bump,      &score->contact,      &score->chemical,      &score->energy,      &label->chemical    );  if (score->energy.flag || score->chemical.flag)    free_vdw_energy (&score->energy);  if (score->chemical.flag)    free_table (&label->chemical, &label->chemical.score_table);}

⌨️ 快捷键说明

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