1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166
|
/* Copyright (C) 2001, 2002 Damir Zucic */
/*=============================================================================
read_template_file.c
Purpose:
Read the template file (file with atomic templates). These data
will be used later to create new peptides and to replace or insert
the residues. The input file format should be compatible with PDB.
Input:
(1) Pointer to RuntimeS structure.
(2) Pointer to the template file.
(3) Pointer to ConfigS structure.
Output:
(1) Atomic data stored to RuntimeS structure.
(2) Return value.
Return value:
(1) The number of atoms read (zero or positive).
========includes:============================================================*/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <X11/Xlib.h>
#include <X11/Xutil.h>
#include <X11/Xos.h>
#include <X11/Xatom.h>
#include "defines.h"
#include "typedefs.h"
/*======function prototypes:=================================================*/
int ParsePDBAtomicData_ (AtomS *, char *);
int ExtractTemplateResidues_ (RuntimeS *);
/*======read template file:==================================================*/
int ReadTemplateFile_ (RuntimeS *runtimeSP,
FILE *template_fileP, ConfigS *configSP)
{
size_t rgb_struct_size;
int line_size;
char lineA[STRINGSIZE];
int first_char;
int rec_typeI = 0;
int template_atomI = 0;
AtomS *curr_atomSP;
int surfaceI;
/* Prepare the size of the RGBS structure: */
rgb_struct_size = sizeof (RGBS);
/* Prepare the line_size: */
line_size = sizeof (lineA);
/* Read the entire file, line by line: */
while (fgets (lineA, line_size, template_fileP))
{
/* Prepare the first character, it will be used */
/* to speed up the recognition of record type: */
first_char = *lineA;
/* Check is there a chance that input line is ATOM or HETATM record: */
rec_typeI = 0;
switch (first_char)
{
case 'A':
if (strstr (lineA, "ATOM") == lineA) rec_typeI = 1;
break;
case 'H':
if (strstr (lineA, "HETATM") == lineA) rec_typeI = 2;
break;
default:
;
}
/* Ignore this line if it is neither ATOM nor HETATM record: */
if (rec_typeI == 0) continue;
/* If this point is reached, extract data if */
/* input line contains ATOM or HETATM record: */
/* Prepare the pointer to the current atom: */
curr_atomSP = runtimeSP->template_atomSP + template_atomI;
/* Try to parse ATOM or HETATM line: */
if (ParsePDBAtomicData_ (curr_atomSP, lineA) < 0) continue;
/* If this point is reached, parsing was successful! */
/* The initial drawing style for atoms: */
curr_atomSP->raw_atomS.atom_styleI = configSP->default_atom_styleI;
/* Initialize the model serial number (trivial value): */
curr_atomSP->raw_atomS.model_serialI = 0;
/* Initialize the selection flag: */
curr_atomSP->selectedF = 1;
/* Initialize the hiddenF: */
curr_atomSP->hiddenF = 0;
/* Put the atom inside the slab: */
curr_atomSP->inside_slabF = 1;
/* Hide atomic label: */
curr_atomSP->labelF = 0;
/* Set flag which distinguishes ATOM and HETATM data: */
if (rec_typeI == 1) curr_atomSP->raw_atomS.heteroF = 0;
else curr_atomSP->raw_atomS.heteroF = 1;
/* Set the number of color fading surfaces: */
curr_atomSP->surfacesN = configSP->default_surfacesN;
/* Copy default basic colors: */
for (surfaceI = 0; surfaceI < MAXCOLORSURFACES; surfaceI++)
{
memcpy (curr_atomSP->left_rgbSA + surfaceI,
configSP->left_rgbSA + surfaceI,
rgb_struct_size);
memcpy (curr_atomSP->middle_rgbSA + surfaceI,
configSP->middle_rgbSA + surfaceI,
rgb_struct_size);
memcpy (curr_atomSP->right_rgbSA + surfaceI,
configSP->right_rgbSA + surfaceI,
rgb_struct_size);
}
/* Increment the counter: */
template_atomI++;
/* Do not allow memory leak: */
if (template_atomI >= MAXTEMPLATEATOMS) break;
}
/* Store the number of template atoms: */
runtimeSP->template_atomsN = template_atomI;
/* Initialize the residue data. If this function failes, the template */
/* file was bad; free storage and reset the number of template atoms. */
if (ExtractTemplateResidues_ (runtimeSP) < 0)
{
runtimeSP->template_atomsN = 0;
if (runtimeSP->template_atomSP)
{
free (runtimeSP->template_atomSP);
runtimeSP->template_atomSP = NULL;
}
return 0;
}
/* Return the number of template atoms on success: */
return template_atomI;
}
/*===========================================================================*/
|