label_chem.c

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

C
621
字号
/*                                                                    *//*                        Copyright UCSF, 1997                        *//*                                                                    *//*Written by Todd Ewing10/95*/#include "define.h"#include "utility.h"#include "mol.h"#include "global.h"#include "label_node.h"#include "label_chem.h"/* ==================================================================== */void get_chemical_labels (LABEL_CHEMICAL *label_chemical){  int i, definition_total, definition_count;  int values_read;  STRING100 line;  FILE *chemical_file;  label_chemical->init_flag = TRUE;  chemical_file = efopen (label_chemical->file_name, "r", global.outfile);/** Count up the number of chemical label declarations and definitions,* then allocate memory* 6/95 te*/  label_chemical->total = 1;  definition_count = 0;  while (fgets (line, 100, chemical_file) != NULL)  {    if (!strncmp (line, "name", 4))      label_chemical->total++;    if (!strncmp (line, "definition", 10))      definition_count++;  }  rewind (chemical_file);  definition_total = definition_count;  ecalloc  (    (void **) &label_chemical->member,    label_chemical->total,    sizeof (CHEMICAL_MEMBER),    "chemical labels",    global.outfile  );  ecalloc  (    (void **) &label_chemical->definition,    definition_count,    sizeof (NODE),    "chemical label definitions",    global.outfile  );/** Read in the atom label definitions* 6/95 te*/  strcpy (label_chemical->member[0].name, "null");  label_chemical->member[0].definition_total = 0;  label_chemical->member[0].definition = &label_chemical->definition[0];  strcpy (label_chemical->member[0].definition[0].type, "*");  label_chemical->member[0].radius = label_chemical->member[0].tolerance = 0;  label_chemical->total = 1;  definition_count = definition_total = 0;  while (fgets (line, 100, chemical_file) != NULL)  {/**   Process chemical label declaration*   6/95 te*/    if (!strncmp (line, "name", 4))    {      label_chemical->member[label_chemical->total - 1].definition_total =        definition_total;      label_chemical->member[label_chemical->total].definition =        &label_chemical->definition[definition_count];      definition_total = 0;      if (sscanf        (line, "%*s %s", label_chemical->member[label_chemical->total].name) <        1)        exit (fprintf (global.outfile,          "ERROR get_chemical_labels: Incomplete label declaration in %s\n",          label_chemical->file_name));/**     Convert label_chemical->member name to lowercase*     6/95 te*/      for (i = 0; i < strlen        (label_chemical->member[label_chemical->total].name); i++)        label_chemical->member[label_chemical->total].name[i] =          (char) tolower            (label_chemical->member[label_chemical->total].name[i]);/**     Make sure that "null" label was not in input*     6/95 te*/      if (!strncmp        (label_chemical->member[label_chemical->total].name, "null", 7))        exit (fprintf (global.outfile,          "ERROR get_chemical_labels: <null> specified if %s\n",          label_chemical->file_name));       label_chemical->total++;    }/**   Process label_chemical->member radius*   10/95 te*/    else if (!strncmp (line, "radius", 5))    {      values_read = sscanf (line, "%*s %f %f",        &label_chemical->member[label_chemical->total - 1].radius,        &label_chemical->member[label_chemical->total - 1].tolerance);      if (values_read < 1)        exit (fprintf (global.outfile,          "ERROR get_chemical_labels: Incomplete radius specification in %s\n",          label_chemical->file_name));      if (values_read < 2)        label_chemical->member[label_chemical->total - 1].tolerance = 0.0;    }/**   Process label_chemical->member definition*   6/95 te*/    else if (!strncmp (line, "definition", 10))    {      strtok (white_line (line), " ");      if (!assign_node (&label_chemical->definition[definition_count],        TRUE))        exit (fprintf (global.outfile,          "ERROR get_chemical_labels: Improper label definition in %s\n",          label_chemical->file_name));      label_chemical->definition[definition_count].weight = 1.0;      definition_count++;      definition_total++;    }    else if (!strncmp (line, "weight", 6))      if (sscanf (line, "%*s %f",        &label_chemical->definition[definition_count - 1].weight) < 1)        label_chemical->definition[definition_count - 1].weight = 1.0;  }/** Update last label_chemical->member info also* 6/95 te*/  label_chemical->member[label_chemical->total - 1].definition_total =    definition_total;  efclose (&chemical_file);/** Print out the label_chemical->members and their definitions* 6/95 te  if (global.output_volume == 'v')  {    fprintf (global.outfile, "\n____Chemical_Label_Definitions____\n\n");    for (i = 0; i < label_chemical->total; i++)    {      MFPUTC ('_', 40);      fprintf (global.outfile, "\n");      fprintf (global.outfile, "%-20s%s\n", "name",        label_chemical->member[i].name);      fprintf (global.outfile, "%-20s%-7.2f", "radius",        label_chemical->member[i].radius);      if (label_chemical->member[i].tolerance)        fprintf (global.outfile, "%-7.2f", label_chemical->member[i].tolerance);      fprintf (global.outfile, "\n");      for (j = 0; j < label_chemical->member[i].definition_total; j++)      {        fprintf (global.outfile, "%-20s", "definition");        print_node (&label_chemical->member[i].definition[j], 0);        fprintf (global.outfile, "\n");        fprintf (global.outfile, "%-20s%-7.2f\n", "weight",            label_chemical->member[i].definition[j].weight);        fprintf (global.outfile, "\n");      }      fprintf (global.outfile, "\n");    }    fprintf (global.outfile, "\n\n");  }*/}/* ////////////////////////////////////////////////////////////////////// */void free_chemical_labels (LABEL_CHEMICAL *label_chemical){  int i, j;  for (i = 0; i < label_chemical->total; i++)    for (j = 0; j < label_chemical->member[i].definition_total; j++)      free_node (&label_chemical->member[i].definition[j]);  efree ((void **) &label_chemical->member);  efree ((void **) &label_chemical->definition);}/* ============================================================= */void get_table(  LABEL_CHEMICAL	*label_chemical,  FILE_NAME		table_file_name,  float			***table){  int i, j;  int continue_loop;  STRING20 receptor_axis = "RECEPTOR", value;  FILE *table_file;  STRING100 line;  STRING20 *table_label = NULL;  int label_count, label_match, *label_conversion = NULL;  char *token, *token_arg;  if (!label_chemical->init_flag)    get_chemical_labels (label_chemical);/** Allocate memory (and set elements to zero) for chemical matching table* 6/95 te*/  ecalloc  (    (void **) table,    label_chemical->total,    sizeof (float *),    "chemical table",    global.outfile  );  for (i = 0; i < label_chemical->total; i++)    ecalloc    (      (void **) &(*table)[i],      label_chemical->total,      sizeof (float),      "chemical table",      global.outfile    ); /** Read in interaction table* 10/95 te*/  table_file = efopen (table_file_name, "r", global.outfile);  for (label_count = 0; fgets (line, 100, table_file);)    if (!strncmp (line, "label", 5))      label_count++;  rewind (table_file);  emalloc  (    (void **) &label_conversion,    label_count * sizeof (int),    "label conversion array",    global.outfile  );  ecalloc  (    (void **) &table_label,    label_count,    sizeof (STRING20),    "label name array",    global.outfile  );  for (label_count = 0; fgets (line, 100, table_file);)    if (!strncmp (line, "label", 5))    {      if (sscanf (line, "%*s %s", table_label[label_count]))      {        for (i = 0, label_match = FALSE; i < label_chemical->total; i++)        {          if (!strcmp            (table_label[label_count], label_chemical->member[i].name))          {            label_conversion[label_count] = i;            label_match = TRUE;          }        }        if (label_match)

⌨️ 快捷键说明

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