125 #define NUMAAKNOWN 20
128 #define ERROR_NOMEM 1
129 #define ERROR_ATOMS 2
130 #define ERROR_UNKNOWNAA 3
135 static int sFirstCall =
TRUE;
136 static FILE *sFp_RefCoords;
137 static int **sChiTab =
NULL;
142 static PDB *DoReplace(
PDB *ResStart,
PDB *NextRes,
char seq,
int **chitab,
144 static int ReplaceWithGly(
PDB *ResStart,
PDB *NextRes);
145 static int ReplaceWithAla(
PDB *ResStart,
PDB *NextRes);
146 static int ReplaceGly(
PDB *ResStart,
PDB *NextRes,
char seq,
148 static int FitByFragment(
PDB *destination,
PDB *fragment,
PDB *mobile);
149 static int InsertSC(
PDB *insert,
PDB *ResStart,
PDB *NextRes,
BOOL doCB);
150 static int Replace(
PDB *ResStart,
PDB *NextRes,
char seq,
int **chitab,
152 static PDB *ReadRefCoords(FILE *fp,
char seq);
153 static void ReadChiTable(FILE *fp,
int **chitab);
154 static int FindChiIndex(
char *resnam);
155 static PDB *FixTorsions(
PDB *pdb,
PDB *ResStart,
PDB *NextRes,
157 static BOOL doRepOneSChain(
PDB *pdb,
char *ResSpec,
char aa,
158 char *ChiTable,
char *RefCoords,
BOOL force);
159 static BOOL gotCBeta(
PDB *ResStart,
PDB *NextRes);
216 if((fp_ChiTable =
blOpenFile(ChiTable,
"DATADIR",
"r",&noenv)) ==
NULL)
220 sprintf(
gRSCError,
"DATADIR environment variable not set\n");
224 sprintf(
gRSCError,
"Unable to open chi link table: %s\n",
230 if((sFp_RefCoords =
blOpenFile(RefCoords,
"DATADIR",
"r",&noenv)) ==
235 sprintf(
gRSCError,
"DATADIR environment variable not set\n");
239 sprintf(
gRSCError,
"Unable to open reference coordinates: \
246 ReadChiTable(fp_ChiTable, sChiTab);
258 for(p=pdb, seq = sequence; p && *seq !=
'\0';
NEXT(p))
271 if(!strncmp(ResStart->
resnam,
"DEL",3))
273 while(*seq ==
'-') seq++;
279 p = DoReplace(ResStart,NextRes,*seq,sChiTab,sFp_RefCoords);
283 while(*(++seq) ==
'-') ;
322 return(doRepOneSChain(pdb, ResSpec, aa, ChiTable, RefCoords,
FALSE));
351 char *ChiTable,
char *RefCoords)
353 return(doRepOneSChain(pdb, ResSpec, aa, ChiTable, RefCoords,
TRUE));
387 static BOOL doRepOneSChain(
PDB *pdb,
char *ResSpec,
char aa,
388 char *ChiTable,
char *RefCoords,
BOOL force)
404 if((fp_ChiTable =
blOpenFile(ChiTable,
"DATADIR",
"r",&noenv)) ==
NULL)
408 sprintf(
gRSCError,
"DATADIR environment variable not set\n");
412 sprintf(
gRSCError,
"Unable to open chi link table: %s\n",
418 if((sFp_RefCoords =
blOpenFile(RefCoords,
"DATADIR",
"r",&noenv)) ==
423 sprintf(
gRSCError,
"DATADIR environment variable not set\n");
427 sprintf(
gRSCError,
"Unable to open reference coordinates: \
434 ReadChiTable(fp_ChiTable, sChiTab);
445 sprintf(
gRSCError,
"Residue specification not in PDB list\n");
455 if(DoReplace(ResStart, NextRes, aa, sChiTab, sFp_RefCoords) ==
485 if(sFp_RefCoords !=
NULL)
487 fclose(sFp_RefCoords);
488 sFp_RefCoords =
NULL;
520 static PDB *DoReplace(
PDB *ResStart,
532 if(!strncmp(ResStart->
resnam,
"GLY",3))
534 retval = ReplaceGly(ResStart,NextRes,seq,fp_RefCoords);
541 if(gotCBeta(ResStart, NextRes))
544 retval = ReplaceWithGly(ResStart, NextRes);
546 retval = ReplaceWithAla(ResStart, NextRes);
548 retval = Replace(ResStart,NextRes,seq,chitab,fp_RefCoords);
552 retval = ReplaceGly(ResStart,NextRes,seq,fp_RefCoords);
563 strcpy(
gRSCError,
"Memory allocation failed");
566 strcpy(
gRSCError,
"Could not build sidechain as backbone atoms \
570 strcpy(
gRSCError,
"Unknown replacement amino acid");
580 for(p=ResStart; p && p->
next != NextRes;
NEXT(p));
598 static BOOL gotCBeta(
PDB *ResStart,
PDB *NextRes)
602 for(p=ResStart; p!=NextRes;
NEXT(p))
604 if(!strncmp(p->
atnam,
"CB ", 4))
627 static int ReplaceWithGly(
PDB *ResStart,
659 static int ReplaceWithAla(
PDB *ResStart,
697 static int ReplaceGly(
PDB *ResStart,
716 reference = ReadRefCoords(fp_RefCoords, seq);
717 if(reference ==
NULL)
725 for(p=ResStart; p && p!=NextRes;
NEXT(p))
727 if(!strncmp(p->
atnam,
"N ",4) ||
728 !strncmp(p->
atnam,
"CA ",4) ||
729 !strncmp(p->
atnam,
"C ",4))
733 if(parent_mc ==
NULL)
763 for(p=reference; p;
NEXT(p))
765 if(!strncmp(p->
atnam,
"N ",4) ||
766 !strncmp(p->
atnam,
"CA ",4) ||
767 !strncmp(p->
atnam,
"C ",4))
798 if(FitByFragment(parent_mc, ref_mc, reference))
807 if(InsertSC(reference, ResStart, NextRes,
TRUE))
842 static int FitByFragment(
PDB *destination,
866 cg_fragment.
x = -cg_fragment.
x;
867 cg_fragment.
y = -cg_fragment.
y;
868 cg_fragment.
z = -cg_fragment.
z;
905 static int InsertSC(
PDB *insert,
919 for(p=ResStart; p && p != NextRes;
NEXT(p))
921 if(!strncmp(p->
atnam,
"CB ",4))
923 if(prev ==
NULL)
return(1);
932 for(start=ResStart; start && start->
next != NextRes;
NEXT(start));
937 for(p=insert; p;
NEXT(p))
939 if(strcmp(p->
atnam,
"N ") &&
940 strcmp(p->
atnam,
"CA ") &&
941 strcmp(p->
atnam,
"C ") &&
942 strcmp(p->
atnam,
"O ") &&
943 strcmp(p->
atnam,
"CB "))
946 if(start ==
NULL)
return(1);
951 if(doCB && !strcmp(p->
atnam,
"CB "))
954 if(start ==
NULL)
return(1);
960 start->
next = NextRes;
988 static int Replace(
PDB *ResStart,
1008 reference = ReadRefCoords(fp_RefCoords, seq);
1009 if(reference ==
NULL)
1017 for(p=ResStart; p && p!=NextRes;
NEXT(p))
1019 if(!strncmp(p->
atnam,
"N ",4) ||
1020 !strncmp(p->
atnam,
"CA ",4) ||
1021 !strncmp(p->
atnam,
"CB ",4) ||
1022 !strncmp(p->
atnam,
"C ",4))
1026 if(parent_mc ==
NULL)
1053 printf(
"Parent mainchain:\n");
1059 for(p=reference; p;
NEXT(p))
1061 if(!strncmp(p->
atnam,
"N ",4) ||
1062 !strncmp(p->
atnam,
"CA ",4) ||
1063 !strncmp(p->
atnam,
"CB ",4) ||
1064 !strncmp(p->
atnam,
"C ",4))
1095 printf(
"Reference mainchain:\n");
1100 if(FitByFragment(parent_mc, ref_mc, reference))
1107 printf(
"Reference structure after fitting to parent:\n");
1114 ResStart = FixTorsions(reference, ResStart, NextRes, chitab);
1117 printf(
"Reference structure matching torsions:\n");
1128 if(InsertSC(reference, ResStart, NextRes,
TRUE))
1129 retval = ERROR_NOMEM;
1168 static PDB *ReadRefCoords(FILE *fp,
1183 while(fgets(buffer,
MAXBUFF, fp))
1188 if(!strncmp(buffer,
"ATOM ",6) && !strncmp(buffer+17, three, 3))
1217 sscanf(ptr,
"%d",&(p->
atnum));
1222 strncpy(p->
atnam,ptr,4);
1236 strncpy(p->
resnam,ptr,4);
1242 strncpy(p->
chain,ptr,1);
1248 sscanf(ptr,
"%d",&(p->
resnum));
1254 strncpy(p->
insert,ptr,1);
1260 sscanf(ptr,
"%lf",&(p->
x));
1265 sscanf(ptr,
"%lf",&(p->
y));
1270 sscanf(ptr,
"%lf",&(p->
z));
1307 static void ReadChiTable(FILE *fp,
1312 int StarFound =
FALSE,
1316 while(fgets(buffer,160,fp))
1321 for(col = 0; col<
NUMAAKNOWN; col++, ptr += 4)
1322 sscanf(ptr,
"%d",&(chitab[row][col]));
1323 if(row++ >= NUMAAKNOWN)
break;
1325 if(buffer[0] ==
'*') StarFound =
TRUE;
1331 for(col=0; col<
NUMAAKNOWN; col++) printf(
"%3d",chitab[row][col]);
1349 static int FindChiIndex(
char *resnam)
1353 if(!strncmp(resnam,
"ALA",3)) ret = 0;
1354 if(!strncmp(resnam,
"ARG",3)) ret = 1;
1355 if(!strncmp(resnam,
"ASN",3)) ret = 2;
1356 if(!strncmp(resnam,
"ASP",3)) ret = 3;
1357 if(!strncmp(resnam,
"CYS",3)) ret = 4;
1358 if(!strncmp(resnam,
"GLN",3)) ret = 5;
1359 if(!strncmp(resnam,
"GLU",3)) ret = 6;
1360 if(!strncmp(resnam,
"GLY",3)) ret = 7;
1361 if(!strncmp(resnam,
"HIS",3)) ret = 8;
1362 if(!strncmp(resnam,
"ILE",3)) ret = 9;
1363 if(!strncmp(resnam,
"LEU",3)) ret = 10;
1364 if(!strncmp(resnam,
"LYS",3)) ret = 11;
1365 if(!strncmp(resnam,
"MET",3)) ret = 12;
1366 if(!strncmp(resnam,
"PHE",3)) ret = 13;
1367 if(!strncmp(resnam,
"PRO",3)) ret = 14;
1368 if(!strncmp(resnam,
"SER",3)) ret = 15;
1369 if(!strncmp(resnam,
"THR",3)) ret = 16;
1370 if(!strncmp(resnam,
"TRP",3)) ret = 17;
1371 if(!strncmp(resnam,
"TYR",3)) ret = 18;
1372 if(!strncmp(resnam,
"VAL",3)) ret = 19;
1400 static PDB *FixTorsions(
PDB *pdb,
1412 strcpy(chain, ResStart->
chain);
1418 for(p=ResStart; p!=NextRes;
NEXT(p))
1420 strcpy(p->
chain, chain);
1423 i = FindChiIndex(pdb->
resnam);
1424 j = FindChiIndex(ResStart->
resnam);
1427 if(i<0 || j<0)
return(ResStart);
1430 nchi = chitab[i][j];
1435 if((ParentChi =
blCalcChi(ResStart, j)) < 9998.0)
PDB * blKillPDB(PDB *pdb, PDB *prev)
void blSetChi(PDB *pdb, PDB *next, REAL chi, int type)
Include file for PDB routines.
BOOL blFitCaCbPDB(PDB *ref_pdb, PDB *fit_pdb, REAL rm[3][3])
void blSetResnam(PDB *ResStart, PDB *NextRes, char *resnam, int resnum, char *insert, char *chain)
char ** blArray2D(int size, int dim1, int dim2)
char * blOnethr(char one)
Include file for 2D/3D array functions.
FILE * blOpenFile(char *filename, char *envvar, char *mode, BOOL *noenv)
Header file for sequence handling.
PDB * blFindResidueSpec(PDB *pdb, char *resspec)
void blFreeArray2D(char **array, int dim1, int dim2)
void blEndRepSChain(void)
Include file for angle functions.
REAL blCalcChi(PDB *pdb, int type)
PDB * blShuffleBB(PDB *pdb)
BOOL blKillSidechain(PDB *ResStart, PDB *NextRes, BOOL doCB)
int blWritePDB(FILE *fp, PDB *pdb)
BOOL blRepOneSChain(PDB *pdb, char *ResSpec, char aa, char *ChiTable, char *RefCoords)
char blThrone(char *three)
void blCopyPDB(PDB *out, PDB *in)
Header file for general purpose routines.
void blGetCofGPDB(PDB *pdb, VEC3F *cg)
System-type variable type definitions.
PDB * blFindNextResidue(PDB *pdb)
BOOL blRepOneSChainForce(PDB *pdb, char *ResSpec, char aa, char *ChiTable, char *RefCoords)
Type definitions for maths.
char chain[blMAXCHAINLABEL]
void blTranslatePDB(PDB *pdb, VEC3F tvect)
void blSetElementSymbolFromAtomName(char *element, char *atom_name)
BOOL blRepSChain(PDB *pdb, char *sequence, char *ChiTable, char *RefCoords)
void blRenumAtomsPDB(PDB *pdb, int offset)
void blApplyMatrixPDB(PDB *pdb, REAL matrix[3][3])