stride/rdpdb.c

145 lines
4.6 KiB
C

/*
* Copyright (C) 1992-1994 Dmitrij Frishman <d.frishman at wzw.tum.de>
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
#include "stride.h"
int ReadPDBFile(CHAIN **Chain, int *Cn, COMMAND *Cmd)
{
int ChainCnt, InfoCnt, i;
enum METHOD Method = XRay;
BOOLEAN First_ATOM, Published=YES, DsspAssigned=NO;
float Resolution = 0.0;
FILE *pdb;
BUFFER Buffer;
char *Info[MAX_INFO], PdbIdent[5];
RESIDUE *r;
CHAIN *c;
*Cn= 0;
InfoCnt = 0;
strcpy(PdbIdent,"~~~~");
if( !(pdb = fopen(Cmd->InputFile,"r")) )
return(FAILURE);
First_ATOM = YES;
while( fgets(Buffer,BUFSZ,pdb) ) {
if(!strncmp(Buffer,"HEADER",6)) {
Info[InfoCnt] = (char *)ckalloc(BUFSZ*sizeof(char));
strcpy(Info[InfoCnt],"HDR ");
strcat(Info[InfoCnt++],Buffer+10);
strncpy(PdbIdent,Buffer+62,4);
PdbIdent[4] = '\0';
}
else
if(!strncmp(Buffer,"AUTHOR",6)) {
Info[InfoCnt] = (char *)ckalloc(BUFSZ*sizeof(char));
strcpy(Info[InfoCnt],"AUT ");
strcat(Info[InfoCnt++],Buffer+10);
}
else
if(!strncmp(Buffer,"SOURCE",6)) {
Info[InfoCnt] = (char *)ckalloc(BUFSZ*sizeof(char));
strcpy(Info[InfoCnt],"SRC ");
strcat(Info[InfoCnt++],Buffer+10);
}
else
if(!strncmp(Buffer,"COMPND",6)) {
if( !Process_COMPND(Buffer,&Method) )
return(FAILURE);
else {
Info[InfoCnt] = (char *)ckalloc(BUFSZ*sizeof(char));
strcpy(Info[InfoCnt],"CMP ");
strcat(Info[InfoCnt++],Buffer+10);
}
}
else if(!strncmp(Buffer,"JRNL",4) && !Process_JRNL(Buffer,&Published))
return(FAILURE);
else if(!strncmp(Buffer,"REMARK",6) && !Process_REMARK(Buffer,&Method,&Resolution,
&DsspAssigned))
return(FAILURE);
else if(!strncmp(Buffer,"EXPDTA",6) && !Process_EXPDTA(Buffer,&Method))
return(FAILURE);
else if(!strncmp(Buffer,"MODEL",5) && !Process_MODEL(&Method))
return(FAILURE);
else if(!strncmp(Buffer,"ENDMDL",6)) {
Process_ENDMDL(Buffer,Chain,Cn);
break;
}
else if(!strncmp(Buffer,"HELIX",5) && !Process_HELIX(Buffer,Chain,Cn,Cmd))
return(FAILURE);
else if(!strncmp(Buffer,"SHEET",5) && !Process_SHEET(Buffer,Chain,Cn,Cmd))
return(FAILURE);
else if(!strncmp(Buffer,"TURN",4) && !Process_TURN(Buffer,Chain,Cn,Cmd))
return(FAILURE);
else if(!strncmp(Buffer,"SSBOND",6) && !Process_SSBOND(Buffer,Chain,Cn,Cmd))
return(FAILURE);
else if(!strncmp(Buffer,"ATOM",4) && !Process_ATOM(Buffer,Chain,Cn,&First_ATOM,Cmd))
return(FAILURE);
}
fclose(pdb);
for( ChainCnt=0; ChainCnt< *Cn; ChainCnt++ ) {
c = Chain[ChainCnt];
if( c->NRes != 0 && !FindAtom(c,c->NRes,"CA",&i) )
c->NRes--;
strcpy(c->File,Cmd->InputFile);
strcpy(c->PdbIdent,PdbIdent);
if( c->NRes != 0 ) c->NRes++;
if( c->NSheet != -1 ) c->NSheet++;
c->Resolution = Resolution;
c->Method = Method;
c->Published = Published;
c->DsspAssigned = DsspAssigned;
c->NInfo = InfoCnt;
for(i=0; i<InfoCnt; i++) {
c->Info[i] = (char *)ckalloc(BUFSZ*sizeof(char));
strcpy(c->Info[i],Info[i]);
c->Info[i][71] = '\0';
}
for( i=0; i<c->NRes; i++ ) {
r = c->Rsd[i];
r->Inv = (INVOLVED *)ckalloc(sizeof(INVOLVED));
r->Prop = (PROPERTY *)ckalloc(sizeof(PROPERTY));
r->Inv->NBondDnr = 0;
r->Inv->NBondAcc = 0;
r->Inv->InterchainHBonds = NO;
r->Prop->Asn = 'C';
r->Prop->PdbAsn = 'C';
r->Prop->DsspAsn = 'C';
r->Prop->Solv = 0.0;
r->Prop->Phi = 360.0;
r->Prop->Psi = 360.0;
}
}
for(i=0; i<InfoCnt; i++)
free(Info[i]);
return(SUCCESS);
}