/* This function is crap. */ static void parse_pdb_data (molecule *m, const char *data, const char *filename, int line) { const char *s = data; char *ss; while (*s) { if ((!m->label || !*m->label) && (!strncmp (s, "HEADER", 6) || !strncmp (s, "COMPND", 6))) { char *name = calloc (1, 100); char *n2 = name; int L = strlen(s); if (L > 99) L = 99; strncpy (n2, s, L); n2 += 7; while (isspace(*n2)) n2++; ss = strchr (n2, '\n'); if (ss) *ss = 0; ss = strchr (n2, '\r'); if (ss) *ss = 0; ss = n2+strlen(n2)-1; while (isspace(*ss) && ss > n2) *ss-- = 0; if (strlen (n2) > 4 && !strcmp (n2 + strlen(n2) - 4, ".pdb")) n2[strlen(n2)-4] = 0; if (m->label) free ((char *) m->label); m->label = strdup (n2); free (name); } else if (!strncmp (s, "TITLE ", 6) || !strncmp (s, "HEADER", 6) || !strncmp (s, "COMPND", 6) || !strncmp (s, "AUTHOR", 6) || !strncmp (s, "REVDAT", 6) || !strncmp (s, "SOURCE", 6) || !strncmp (s, "EXPDTA", 6) || !strncmp (s, "JRNL ", 6) || !strncmp (s, "REMARK", 6) || !strncmp (s, "SEQRES", 6) || !strncmp (s, "HET ", 6) || !strncmp (s, "FORMUL", 6) || !strncmp (s, "CRYST1", 6) || !strncmp (s, "ORIGX1", 6) || !strncmp (s, "ORIGX2", 6) || !strncmp (s, "ORIGX3", 6) || !strncmp (s, "SCALE1", 6) || !strncmp (s, "SCALE2", 6) || !strncmp (s, "SCALE3", 6) || !strncmp (s, "MASTER", 6) || !strncmp (s, "KEYWDS", 6) || !strncmp (s, "DBREF ", 6) || !strncmp (s, "HETNAM", 6) || !strncmp (s, "HETSYN", 6) || !strncmp (s, "HELIX ", 6) || !strncmp (s, "LINK ", 6) || !strncmp (s, "MTRIX1", 6) || !strncmp (s, "MTRIX2", 6) || !strncmp (s, "MTRIX3", 6) || !strncmp (s, "SHEET ", 6) || !strncmp (s, "CISPEP", 6) || /* !strncmp (s, "SEQADV", 6) || !strncmp (s, "SITE ", 5) || !strncmp (s, "FTNOTE", 6) || !strncmp (s, "MODEL ", 5) || !strncmp (s, "ENDMDL", 6) || !strncmp (s, "SPRSDE", 6) || !strncmp (s, "MODRES", 6) || */ !strncmp (s, "GENERATED BY", 12) || !strncmp (s, "TER ", 4) || !strncmp (s, "END ", 4) || !strncmp (s, "TER\n", 4) || !strncmp (s, "END\n", 4) || !strncmp (s, "\n", 1)) /* ignored. */ ; else if (!strncmp (s, "ATOM ", 7)) { int id; const char *end = strchr (s, '\n'); int L = end - s; char *name = (char *) calloc (1, 4); GLfloat x = -999, y = -999, z = -999; if (1 != sscanf (s+7, " %d ", &id)) parse_error (filename, line, s); /* Use the "atom name" field if that is all that is available. */ strncpy (name, s+12, 3); /* But prefer the "element" field. */ if (L > 77 && !isspace(s[77])) { /* fprintf(stderr, " \"%s\" -> ", name); */ name[0] = s[76]; name[1] = s[77]; name[2] = 0; /* fprintf(stderr, "\"%s\"\n", name); */ } while (isspace(*name)) name++; ss = name + strlen(name)-1; while (isspace(*ss) && ss > name) *ss-- = 0; ss = name + 1; while(*ss) { *ss = tolower(*ss); ss++; } if (3 != sscanf (s + 32, " %f %f %f ", &x, &y, &z)) parse_error (filename, line, s); /* fprintf (stderr, "%s: %s: %d: atom: %d \"%s\" %9.4f %9.4f %9.4f\n", progname, filename, line, id, name, x, y, z); */ push_atom (m, id, name, x, y, z); } else if (!strncmp (s, "HETATM ", 7)) { int id; char *name = (char *) calloc (1, 4); GLfloat x = -999, y = -999, z = -999; if (1 != sscanf (s+7, " %d ", &id)) parse_error (filename, line, s); strncpy (name, s+12, 3); while (isspace(*name)) name++; ss = name + strlen(name)-1; while (isspace(*ss) && ss > name) *ss-- = 0; if (3 != sscanf (s + 30, " %f %f %f ", &x, &y, &z)) parse_error (filename, line, s); /* fprintf (stderr, "%s: %s: %d: atom: %d \"%s\" %9.4f %9.4f %9.4f\n", progname, filename, line, id, name, x, y, z); */ push_atom (m, id, name, x, y, z); } else if (!strncmp (s, "CONECT ", 7)) { int atoms[11]; int i = sscanf (s + 8, " %d %d %d %d %d %d %d %d %d %d %d %d ", &atoms[0], &atoms[1], &atoms[2], &atoms[3], &atoms[4], &atoms[5], &atoms[6], &atoms[7], &atoms[8], &atoms[9], &atoms[10], &atoms[11]); int j; for (j = 1; j < i; j++) if (atoms[j] > 0) { /* fprintf (stderr, "%s: %s: %d: bond: %d %d\n", progname, filename, line, atoms[0], atoms[j]); */ push_bond (m, atoms[0], atoms[j]); } } else { char *s1 = strdup (s); for (ss = s1; *ss && *ss != '\n'; ss++) ; *ss = 0; fprintf (stderr, "%s: %s: %d: unrecognised line: %s\n", progname, filename, line, s1); } while (*s && *s != '\n') s++; if (*s == '\n') s++; line++; } }
/* This function is crap. */ static void parse_pdb_data (molecule *m, const char *data, const char *filename, int line) { const char *s = data; char *ss; while (*s) { if ((!m->label || !*m->label) && (!strncmp (s, "HEADER", 6) || !strncmp (s, "COMPND", 6))) { char *name = (char *) calloc (1, 100); char *n2 = name; int L = strlen(s); if (L > 99) L = 99; (void) strncpy(n2, s, L); n2 += 7; while (isspace((int) *n2)) n2++; ss = strchr (n2, '\n'); if (ss) *ss = 0; ss = strchr (n2, '\r'); if (ss) *ss = 0; ss = n2 + strlen(n2)-1; while (isspace((int) *ss) && ss > n2) *ss-- = 0; if (strlen(n2) > 4 && !strcmp (n2 + strlen(n2) - 4, ".pdb")) n2[strlen(n2)-4] = 0; if (m->label) free((char *) m->label); m->label = (char *) strdup (n2); free(name); } else if (!strncmp (s, "TITLE ", 6) || !strncmp (s, "HEADER", 6) || !strncmp (s, "COMPND", 6) || !strncmp (s, "AUTHOR", 6) || !strncmp (s, "REVDAT", 6) || !strncmp (s, "SOURCE", 6) || !strncmp (s, "EXPDTA", 6) || !strncmp (s, "JRNL ", 6) || !strncmp (s, "REMARK", 6) || !strncmp (s, "SEQRES", 6) || !strncmp (s, "HET ", 6) || !strncmp (s, "FORMUL", 6) || !strncmp (s, "CRYST1", 6) || !strncmp (s, "ORIGX1", 6) || !strncmp (s, "ORIGX2", 6) || !strncmp (s, "ORIGX3", 6) || !strncmp (s, "SCALE1", 6) || !strncmp (s, "SCALE2", 6) || !strncmp (s, "SCALE3", 6) || !strncmp (s, "MASTER", 6) || !strncmp (s, "KEYWDS", 6) || !strncmp (s, "DBREF ", 6) || !strncmp (s, "HETNAM", 6) || !strncmp (s, "HETSYN", 6) || !strncmp (s, "HELIX ", 6) || !strncmp (s, "LINK ", 6) || !strncmp (s, "MTRIX1", 6) || !strncmp (s, "MTRIX2", 6) || !strncmp (s, "MTRIX3", 6) || !strncmp (s, "SHEET ", 6) || !strncmp (s, "CISPEP", 6) || !strncmp (s, "GENERATED BY", 12) || !strncmp (s, "TER ", 4) || !strncmp (s, "END ", 4) || !strncmp (s, "TER\n", 4) || !strncmp (s, "END\n", 4) || !strncmp (s, "\n", 1)) /* ignored. */ ; else if (!strncmp (s, "ATOM ", 7)) { int id; /* PURIFY reports a cumulative potential memory leak on the next line */ char *name = (char *) calloc (1, 4); GLfloat x = -999, y = -999, z = -999; (void) sscanf (s+7, " %d ", &id); (void) strncpy (name, s+12, 3); while (isspace((int) *name)) name++; ss = name + strlen(name)-1; while (isspace((int) *ss) && ss > name) *ss-- = 0; (void) sscanf (s + 32, " %f %f %f ", &x, &y, &z); /* (void) fprintf (stderr, "molecule: %s: %d: atom: %d \"%s\" %9.4f %9.4f %9.4f\n", filename, line, id, name, x, y, z); */ push_atom (m, id, name, x, y, z); } else if (!strncmp (s, "HETATM ", 7)) { int id; /* PURIFY reports a cumulative potential memory leak on the next line */ char *name = (char *) calloc (1, 4); GLfloat x = -999, y = -999, z = -999; (void) sscanf (s+7, " %d ", &id); (void) strncpy (name, s+12, 3); while (isspace((int) *name)) name++; ss = name + strlen(name)-1; while (isspace((int) *ss) && ss > name) *ss-- = 0; (void) sscanf (s + 30, " %f %f %f ", &x, &y, &z); /* (void) fprintf (stderr, "molecule: %s: %d: atom: %d \"%s\" %9.4f %9.4f %9.4f\n", filename, line, id, name, x, y, z); */ push_atom (m, id, name, x, y, z); } else if (!strncmp (s, "CONECT ", 7)) { int atoms[11]; int i = sscanf (s + 8, " %d %d %d %d %d %d %d %d %d %d %d %d ", &atoms[0], &atoms[1], &atoms[2], &atoms[3], &atoms[4], &atoms[5], &atoms[6], &atoms[7], &atoms[8], &atoms[9], &atoms[10], &atoms[11]); int j; for (j = 1; j < i; j++) if (atoms[j] > 0) { /* (void) fprintf (stderr, "molecule: %s: %d: bond: %d %d\n", filename, line, atoms[0], atoms[j]); */ push_bond (m, atoms[0], atoms[j]); } } else { char *s1 = (char *) strdup (s); for (ss = s1; *ss && *ss != '\n'; ss++) ; *ss = 0; (void) fprintf (stderr, "molecule: %s: %d: unrecognised line: %s\n", filename, line, s1); } while (*s && *s != '\n') s++; if (*s == '\n') s++; line++; } }