89 #define NUM_STRAND_CHARS 26
91 #define MAX_NUM_HBOND 4
92 #define MAX_NUM_CHN 200
105 #define NUM_STRAND_PAIR 2
106 #define NUM_BRIDGE_PAIR 2
108 #define NUM_DIHED_DATA 3
109 #define RESTYPE_PROLINE 15
113 #define NUM_MC_ATOM_TYPES 6
121 #define MAX_NUM_ANGLES 7
122 #define NUM_STANDARD_DIHEDRALS 4
125 #define DIHED_OMEGA 2
126 #define DIHED_CHIRAL 3
127 #define DIHED_IMPLD 4
128 #define DIHED_KAPPA 5
131 #define NUM_STRUC_SYMS (11)
132 #define SECSTR_IDX_ALPHAH 0
133 #define SECSTR_IDX_SHEET1 1
134 #define SECSTR_IDX_SHEET 2
135 #define SECSTR_IDX_BRIDGE 3
136 #define SECSTR_IDX_BRIDG1 4
137 #define SECSTR_IDX_BRIDG2 5
138 #define SECSTR_IDX_THRTNH 6
139 #define SECSTR_IDX_PIH 7
140 #define SECSTR_IDX_TURN 8
141 #define SECSTR_IDX_BEND 9
142 #define SECSTR_IDX_CHISGN 10
144 #define NUM_HELIX_TYPE 3
145 #define HELIX_CHUNK_SIZE 4
146 #define THREE_TEN_CHUNK_SIZE 3
147 #define PIH_CHUNK_SIZE 5
150 #define BULGE_SIZE_L 5
151 #define BULGE_SIZE_S 2
156 #define NUM_TURN_TYPE 3
158 #define RADIAN (180.0/3.141592)
159 #define NULLVAL 999.9
161 #define MAX_PEPTIDE_BOND 2.5
162 #define MAX_CA_DISTANCE 5.0
164 #define BEND_SIZE 70.0
168 #define MAX_HBOND_ENERGY -0.5
169 #define HBOND_ENERGY_LIMIT -9.9
170 #define HBOND_MAX_CA_DIST 8.0
171 #define HBOND_Q1 0.42
176 #define ACCURACY 0.0001
177 #define APPROXEQ(x, y) (ABS((x)-(y)) < ACCURACY)
178 #define APPROXNE(x, y) (ABS((x)-(y)) >= ACCURACY)
181 #define ATDIST(a, b) \
182 sqrt(((a)[0]-(b)[0])*((a)[0]-(b)[0]) + \
183 ((a)[1]-(b)[1])*((a)[1]-(b)[1]) + \
184 ((a)[2]-(b)[2])*((a)[2]-(b)[2]))
187 #define ANINT(x) ((REAL)(int)((x) + (((x) >= 0.0)?0.5:(-0.5))))
190 #define FREE_SECSTR_MEMORY \
192 if(gotAtom != NULL) \
193 blFreeArray2D((char **)gotAtom, NUM_MC_ATOM_TYPES, seqlenMalloc); \
194 if(mcCoords != NULL) \
195 blFreeArray3D((char ***)mcCoords, NUM_MC_ATOM_TYPES, seqlenMalloc, \
197 if(hbondEnergy != NULL) \
198 blFreeArray2D((char **)hbondEnergy, seqlenMalloc, MAX_NUM_HBOND); \
199 if(mcAngles != NULL) \
200 blFreeArray2D((char **)mcAngles, MAX_NUM_ANGLES, seqlenMalloc); \
201 if(detailSS != NULL) free(detailSS); \
202 if(finalSS != NULL) free(finalSS); \
203 if(breakSymbol != NULL) free(breakSymbol); \
204 if(ssTable != NULL) \
205 blFreeArray2D((char **)ssTable, NUM_STRUC_SYMS, seqlenMalloc); \
206 if(residueID != NULL) \
207 blFreeArray2D((char **)residueID, seqlenMalloc, 16); \
208 if(residueTypes != NULL) free(residueTypes); \
210 blFreeArray2D((char **)hbond, seqlenMalloc, MAX_NUM_HBOND); \
211 if(bridgePoints != NULL) \
212 blFreeArray2D((char **)bridgePoints, NUM_BRIDGE_PAIR, \
224 static void ExtractPDBData(
PDB *pdbStart,
PDB *pdbStop,
226 char **seqbcd,
BOOL *caOnly,
int *seqlen,
227 int *residueTypes,
char *KnownResidueIndex);
228 static void SetPDBSecStruc(
PDB *pdbStart,
PDB *pdbStop,
char *finalSS);
229 static int CountResidues(
PDB *pdbStart,
PDB *pdbStop);
230 static int FindResidueCode(
char *resnam,
char *KnownResidueIndex);
231 static void MarkBends(
char **ssTable,
char *detailSS,
char *finalSS,
233 static void SetChainEnds(
char *breakSymbol,
int *chainSize,
234 int *numChains,
int *chainEnd,
235 int numberInChain,
char **residueID,
236 int resIndex,
int seqlen,
BOOL verbose);
237 static REAL CalcDihedral(
int angnum,
REAL *atoma,
REAL *atomb,
239 static int FindHBondOffset(
REAL energy,
REAL bonde1,
REAL bonde2);
240 static void SetHBond(
REAL **hbondEnergy,
int **hbond,
REAL energy,
241 int donorResIndex,
int acceptorResIndex,
242 int *bondCount,
BOOL verbose);
243 static void FindNextPartialSheet(
int startPoint,
int sheetNum,
244 char **ssTable,
int *sheetCode,
245 int **bridgePoints,
BOOL *found,
247 static void FindFirstUnsetSheet(
int startPoint,
char **ssTable,
248 int *sheetCode,
int *startOfSheet,
249 int *endOfSheet,
int seqlen);
250 static void MarkHelicesInSummary(
char *summ,
char helixChar,
251 char altHelixChar,
char turnChar,
252 char altTurnChar,
int helixSize,
254 static void MarkHelices(
char **ssTable,
char *detailSS,
char *finalSS,
255 int helixPos,
int helixSize,
char helixCharacter,
256 char altHelixCharacter,
int seqlen);
257 static void MarkSheetsAndBridges(
int seqlen,
char **ssTable,
258 char *detailSS,
char *finalSS,
259 char *ssSymbols,
char *altSSSymbols);
260 static void RejectHBond(
int resIndex,
int *bond,
REAL *bonde);
261 static void SetSheet(
int bridgePoint,
int sheetNum,
int *sheetCode,
262 char **ssTable,
int seqlen);
263 static void LabelSheets(
char **ssTable,
int **bridgePoints,
264 int *sheetCode,
int seqlen,
BOOL verbose);
265 static int FindNextCodeOccurrence(
int strandStart,
int strandEnd,
266 int code,
int **strandCode);
267 static void MarkTurns(
char **ssTable,
char *detailSS,
char *finalSS,
268 char turnChar,
char altTurnChar,
int seqlen);
269 static void FindNextStrand(
int **strandCode,
int sheetStart,
270 int sheetEnd,
int *strandCount,
271 int *startIndex,
int lastStrand,
273 static void FindChainBreaks(
REAL ***mcCoords,
BOOL **gotAtom,
274 char **residueID,
char *breakSymbol,
275 int *chainSize,
int *numChains,
int *chainEnd,
276 BOOL caOnly,
int seqlen,
BOOL verbose);
277 static void AddHydrogens(
REAL ***mcCoords,
BOOL **gotAtom,
int *chainSize,
278 int numChains,
BOOL verbose);
279 static void MakeHBonds(
REAL ***mcCoords,
BOOL **gotAtom,
int **hbond,
280 REAL **hbondEnergy,
int *residueTypes,
281 int *chainEnd,
int seqlen,
BOOL verbose);
282 static void CalcMCAngles(
REAL ***mcCoords,
REAL **mcAngles,
283 BOOL **gotAtom,
int *chainSize,
int numChains,
284 BOOL caOnly,
int seqlen);
285 static BOOL MakeTurnsAndBridges(
int **hbond,
char **ssTable,
286 REAL **mcAngles,
int **bridgePoints,
287 int *chainEnd,
int seqlen,
289 static void MakeSummary(
char **ssTable,
char *detailSS,
char *finalSS,
291 static void SetBendResidues(
REAL **mcAngles,
char **ssTable,
int seqlen);
317 char **ssTable =
NULL,
331 **bridgePoints =
NULL,
332 *residueTypes =
NULL;
336 **hbondEnergy =
NULL,
342 static char KnownResidueIndex[] =
"ALAASXCYSASPGLUPHEGLYHISILEXXX\
343 LYSLEUMETASNXXXPROGLNARGSERTHRXXXVALTRPXXXTYRGLXUNKPCAINI";
345 seqlenMalloc = CountResidues(pdbStart, pdbStop);
348 detailSS = (
char *)malloc(
sizeof(
char) * seqlenMalloc);
349 finalSS = (
char *)malloc(
sizeof(
char) * seqlenMalloc);
350 breakSymbol = (
char *)malloc(
sizeof(
char) * seqlenMalloc);
351 residueTypes = (
int *)malloc(
sizeof(
int) * seqlenMalloc);
361 residueID = (
char **)
blArray2D(
sizeof(
char), seqlenMalloc,
363 hbond = (
int **)
blArray2D(
sizeof(
int), seqlenMalloc,
371 if((detailSS !=
NULL) &&
373 (breakSymbol !=
NULL) &&
374 (residueTypes !=
NULL) &&
376 (hbondEnergy !=
NULL) &&
377 (mcAngles !=
NULL) &&
379 (residueID !=
NULL) &&
381 (bridgePoints !=
NULL) &&
385 ExtractPDBData(pdbStart, pdbStop, mcCoords, gotAtom, residueID,
386 &caOnly, &seqlen, residueTypes, KnownResidueIndex);
390 for(resCount=0; resCount<seqlen; resCount++)
392 finalSS[resCount] =
'?';
397 fprintf(stderr,
"Sec Struc: (warning) protein chain %c is \
398 CA-only. Secondary structure undefined.\n", pdbStart->
chain[0]);
404 FindChainBreaks(mcCoords, gotAtom, residueID, breakSymbol,
405 chainSize, &numChains, chainEnd, caOnly, seqlen,
408 AddHydrogens(mcCoords, gotAtom, chainSize, numChains, verbose);
411 MakeHBonds(mcCoords, gotAtom, hbond, hbondEnergy, residueTypes,
412 chainEnd, seqlen, verbose);
415 CalcMCAngles(mcCoords, mcAngles, gotAtom, chainSize, numChains,
419 if(!MakeTurnsAndBridges(hbond, ssTable, mcAngles, bridgePoints,
420 chainEnd, seqlen, verbose))
427 SetBendResidues(mcAngles, ssTable, seqlen);
430 MakeSummary(ssTable, detailSS, finalSS, seqlen);
434 SetPDBSecStruc(pdbStart, pdbStop, finalSS);
462 static void SetPDBSecStruc(
PDB *pdbStart,
PDB *pdbStop,
char *finalSS)
470 for(p=pdbStart; p!=pdbStop; p=nextRes)
476 for(r=p; r!=nextRes;
NEXT(r))
478 if(!strncmp(r->
atnam,
"N ", 4))
488 ssChar = ((gotN) ? finalSS[i++] :
'?');
491 for(r=p; r!=nextRes;
NEXT(r))
513 static int CountResidues(
PDB *pdbStart,
PDB *pdbStop)
520 for(p=pdbStart; p!=pdbStop; p = nextRes)
545 static int FindResidueCode(
char *resnam,
char *KnownResidueIndex)
549 codLen = strlen(KnownResidueIndex);
551 for(i=0; i<codLen; i+=3)
553 if(!strncmp(resnam, KnownResidueIndex+i, 3))
589 static void ExtractPDBData(
PDB *pdbStart,
PDB *pdbStop,
591 char **residueID,
BOOL *caOnly,
592 int *seqlen,
int *residueTypes,
593 char *KnownResidueIndex)
598 prevResnum = (-99999999),
605 strncpy(prevInsert,
"-", 8);
612 for(p=pdbStart; p!=pdbStop;
NEXT(p))
620 strcpy(prevInsert, p->
insert);
625 gotAtom[i][resCount] =
FALSE;
629 strncpy(residueID[resCount], buffer, 16);
630 residueTypes[resCount] = FindResidueCode(p->
resnam,
635 if(!strncmp(p->
atnam,
"N ",4))
640 else if(!strncmp(p->
atnam,
"CA ",4))
645 else if(!strncmp(p->
atnam,
"C ",4))
649 else if(!strncmp(p->
atnam,
"O ",4))
653 else if(!strncmp(p->
atnam,
"CB ",4))
657 else if(!strncmp(p->
atnam,
"H ",4))
669 gotAtom[atomIdx][resCount] =
TRUE;
670 mcCoords[atomIdx][resCount][0] = p->
x;
671 mcCoords[atomIdx][resCount][1] = p->
y;
672 mcCoords[atomIdx][resCount][2] = p->
z;
676 if(nCount < caCount/2)
681 *seqlen = resCount+1;
701 static void MarkBends(
char **ssTable,
char *detailSS,
char *finalSS,
706 for(resCount=0; resCount<seqlen; resCount++)
762 static void FindChainBreaks(
REAL ***mcCoords,
BOOL **gotAtom,
763 char **residueID,
char *breakSymbol,
764 int *chainSize,
int *numChains,
int *chainEnd,
765 BOOL caOnly,
int seqlen,
BOOL verbose)
770 for(resIndex=0; resIndex<seqlen; resIndex++)
777 for(resIndex=1; resIndex<seqlen; resIndex++)
784 SetChainEnds(breakSymbol, chainSize, numChains, chainEnd,
785 numberInChain, residueID, resIndex, seqlen,
796 if(gotAtom[
ATOM_C][resIndex-1] && gotAtom[
ATOM_N][resIndex])
801 SetChainEnds(breakSymbol, chainSize, numChains, chainEnd,
802 numberInChain, residueID, resIndex, seqlen,
813 SetChainEnds(breakSymbol, chainSize, numChains, chainEnd,
814 numberInChain, residueID, resIndex, seqlen,
820 SetChainEnds(breakSymbol, chainSize, numChains, chainEnd,
821 numberInChain, residueID, seqlen, seqlen, verbose);
855 static void SetChainEnds(
char *breakSymbol,
int *chainSize,
856 int *numChains,
int *chainEnd,
857 int numberInChain,
char **residueID,
858 int resIndex,
int seqlen,
BOOL verbose)
860 chainSize[*numChains-1] = numberInChain;
864 chainEnd[*numChains] = numberInChain;
868 chainEnd[*numChains] = chainEnd[*numChains-1] + numberInChain;
871 if(resIndex < seqlen)
878 fprintf(stderr,
"Sec Struc: (info) Chain break between %d(%s) \
880 resIndex-1, residueID[resIndex-1], resIndex,
881 residueID[resIndex]);
890 fprintf(stderr,
"Sec Struc: (warning) Maximum number of \
891 chain-breaks exceeded (MAX_NUM_CHN = %d)\n",
MAX_NUM_CHN);
918 static void AddHydrogens(
REAL ***mcCoords,
BOOL **gotAtom,
int *chainSize,
919 int numChains,
BOOL verbose)
929 for(chainNumber=0; chainNumber<numChains; chainNumber++)
931 for(resCount=chainStart+1;
932 resCount<chainStart+chainSize[chainNumber];
935 if(gotAtom[
ATOM_N][resCount] &&
936 gotAtom[
ATOM_C][resCount-1] &&
937 gotAtom[
ATOM_O][resCount-1])
942 atvec[i] = mcCoords[
ATOM_C][resCount-1][i] -
943 mcCoords[
ATOM_O][resCount-1][i];
944 colen += atvec[i] * atvec[i];
955 mcCoords[
ATOM_H][resCount][i] =
956 mcCoords[
ATOM_N][resCount][i] + atvec[i];
965 fprintf(stderr,
"Sec Struc: (warning) Hydrogen atom not \
966 generated for residue %d\n",
972 chainStart += chainSize[chainNumber];
1000 static REAL CalcDihedral(
int angnum,
1028 return(
RADIAN *
blPhi(atoma[0], atoma[1], atoma[2],
1029 atomb[0], atomb[1], atomb[2],
1030 atomc[0], atomc[1], atomc[2],
1031 atomd[0], atomd[1], atomd[2]));
1042 atomDistance[i] =
ATDIST(dihatm[i],dihatm[i+1]);
1045 codist[j][i] = dihatm[i+1][j] - dihatm[i][j];
1053 dotProduct[i][j] = 0.0;
1057 for(i=0; i<NUM_DIHED_DATA-1; i++)
1063 dotProduct[i][j] += (codist[k][i] * codist[k][j]);
1068 for(i=0; i<NUM_DIHED_DATA-1; i++)
1072 if(
APPROXEQ(atomDistance[i], 0.0) ||
1075 dotProduct[i][j] = 1.0;
1079 dotProduct[i][j] = (dotProduct[i][j] / atomDistance[i]) /
1085 cosAngle = dotProduct[0][2];
1087 if(fabs(cosAngle) > 1.0)
1089 REAL tmp = cosAngle/fabs(cosAngle);
1091 cosAngle =
ANINT(tmp);
1094 ang = acos(cosAngle) *
RADIAN;
1115 static int FindHBondOffset(
REAL energy,
REAL bonde1,
REAL bonde2)
1121 else if(energy < bonde2)
1158 static void SetHBond(
REAL **hbondEnergy,
1162 int acceptorResIndex,
1170 donorOffset = FindHBondOffset(energy,
1171 hbondEnergy[donorResIndex][
NST],
1172 hbondEnergy[donorResIndex][NST+1]);
1173 acceptorOffset = FindHBondOffset(energy,
1174 hbondEnergy[acceptorResIndex][
CST],
1175 hbondEnergy[acceptorResIndex][CST+1]);
1177 if(acceptorOffset == 0 || donorOffset == 0)
1181 fprintf(stderr,
"Sec Struc: (info) Third H-bond skipped. \
1182 Donor index: %4d; Acceptor Index: %4d; Energy: %6.2f\n",
1183 donorResIndex+1, acceptorResIndex+1, energy);
1188 if(hbond[donorResIndex][
NST+1] != 0)
1192 fprintf(stderr,
"Sec Struc: (info) Third H-bond skipped. \
1193 Donor index: %4d; Acceptor index: %4d; Energy %6.2f\n",
1195 hbond[donorResIndex][
NST+1],
1196 hbondEnergy[donorResIndex][
NST+1]);
1198 rejectOffset = hbond[donorResIndex][
NST+1];
1199 RejectHBond(donorResIndex+1,
1200 &(hbond[rejectOffset-1][
CST]),
1201 &(hbondEnergy[rejectOffset-1][
CST]));
1205 if(hbond[acceptorResIndex][
CST+1] != 0)
1209 fprintf(stderr,
"Sec Struc: (info) Third H-bond skipped. \
1210 Donor index: %4d; Acceptor index: %4d; Energy %6.2f\n",
1211 hbond[acceptorResIndex][
CST+1],
1213 hbondEnergy[acceptorResIndex][
CST+1]);
1215 rejectOffset = hbond[acceptorResIndex][
CST+1];
1216 RejectHBond(acceptorResIndex+1,
1217 &(hbond[rejectOffset-1][
NST]),
1218 &(hbondEnergy[rejectOffset-1][
NST]));
1222 if(acceptorOffset == 1)
1224 hbond[acceptorResIndex][
CST+1] = hbond[acceptorResIndex][
CST];
1226 hbondEnergy[acceptorResIndex][
CST+1] =
1227 hbondEnergy[acceptorResIndex][
CST];
1230 if(donorOffset == 1)
1232 hbond[donorResIndex][
NST+1] = hbond[donorResIndex][
NST];
1234 hbondEnergy[donorResIndex][
NST+1] =
1235 hbondEnergy[donorResIndex][
NST];
1238 hbond[acceptorResIndex][
CST+acceptorOffset-1] =
1240 hbondEnergy[acceptorResIndex][
CST+acceptorOffset-1] =
1242 hbond[donorResIndex][
NST+donorOffset-1] =
1244 hbondEnergy[donorResIndex][
NST+donorOffset-1] =
1274 static void FindNextPartialSheet(
int startPoint,
1288 resCount = startPoint - 1;
1290 while (sheetCode[resCount] != (-sheetNum))
1293 if(resCount >= seqlen)
1297 startOfSheet = resCount;
1300 while(sheetCode[resCount] == (-sheetNum))
1303 if(resCount >= seqlen)
1307 endOfSheet = resCount-1;
1309 for(resCount = startOfSheet; resCount <= endOfSheet; resCount++)
1311 sheetCode[resCount] = sheetNum;
1314 if(bridgePoints[i][resCount] != 0)
1316 if(sheetCode[bridgePoints[i][resCount]-1] == 0)
1318 SetSheet(bridgePoints[i][resCount], sheetNum, sheetCode,
1346 static void FindFirstUnsetSheet(
int startPoint,
char **ssTable,
1347 int *sheetCode,
int *startOfSheet,
1348 int *endOfSheet,
int seqlen)
1353 resCount = startPoint-1;
1356 (sheetCode[resCount] != 0))
1359 if(resCount >= seqlen)
1362 *startOfSheet = resCount+1;
1367 }
while((resCount <= seqlen-1) &&
1370 *endOfSheet = resCount;
1395 static void MarkHelicesInSummary(
char *summ,
char helixChar,
1396 char altHelixChar,
char turnChar,
1397 char altTurnChar,
int helixSize,
1404 for(resCount=1; resCount<seqlen; resCount++)
1406 if((summ[resCount] == helixChar) ||
1407 (summ[resCount] == altHelixChar))
1410 startPos = resCount;
1416 if((resCount - startPos) < helixSize)
1418 for(posInHelix = startPos;
1419 posInHelix <= (resCount - 1);
1422 if(summ[posInHelix] == helixChar)
1424 summ[posInHelix] = turnChar;
1428 summ[posInHelix] = altTurnChar;
1439 if((seqlen - startPos + 1) < helixSize)
1441 for(posInHelix=startPos; posInHelix <= seqlen; posInHelix++)
1443 if(summ[resCount] == helixChar)
1445 summ[posInHelix] = turnChar;
1449 summ[posInHelix] = altTurnChar;
1479 static void MarkHelices(
char **ssTable,
char *detailSS,
char *finalSS,
1480 int helixPos,
int helixSize,
char helixCharacter,
1481 char altHelixCharacter,
int seqlen)
1486 for(resCount=1; resCount < (seqlen - helixSize); resCount++)
1494 for(posInHelix = 0; posInHelix < helixSize; posInHelix++)
1498 detailSS[resCount+posInHelix] = helixCharacter;
1502 finalSS[resCount+posInHelix] == altHelixCharacter)
1504 finalSS[resCount+posInHelix] = helixCharacter;
1511 finalSS[resCount-1] = altHelixCharacter;
1516 finalSS[resCount+helixSize] = altHelixCharacter;
1544 static void CalcMCAngles(
REAL ***mcCoords,
REAL **mcAngles,
1545 BOOL **gotAtom,
int *chainSize,
int numChains,
1546 BOOL caOnly,
int seqlen)
1579 {2, 2, 2, 4, 1, 5, 2};
1597 for(angleIndex=firstAngle; angleIndex<=finalAngle; angleIndex++)
1601 for(chainCount=0; chainCount<numChains; chainCount++)
1604 if(chainSize[chainCount] < numAtomsRequired[angleIndex])
1606 for(resCount = chainStart;
1607 resCount < (chainStart + chainSize[chainCount]);
1610 mcAngles[angleIndices[angleIndex][2]][resCount] =
NULLVAL;
1615 for(resCount = (chainStart + angleIndices[angleIndex][0]);
1616 resCount <= (chainStart + chainSize[chainCount] +
1617 angleIndices[angleIndex][1]);
1620 if(gotAtom[angleAtoms[angleIndex][0]]
1621 [resCount+angleOffsets[angleIndex][0]] &&
1622 gotAtom[angleAtoms[angleIndex][1]]
1623 [resCount+angleOffsets[angleIndex][1]] &&
1624 gotAtom[angleAtoms[angleIndex][2]]
1625 [resCount+angleOffsets[angleIndex][2]] &&
1626 gotAtom[angleAtoms[angleIndex][3]]
1627 [resCount+angleOffsets[angleIndex][3]])
1632 mcAngles[angleIndices[angleIndex][2]][resCount-1] =
1633 CalcDihedral(angleIndex,
1634 mcCoords[angleAtoms[angleIndex][0]]
1636 angleOffsets[angleIndex][0]],
1637 mcCoords[angleAtoms[angleIndex][1]]
1639 angleOffsets[angleIndex][1]],
1640 mcCoords[angleAtoms[angleIndex][2]]
1642 angleOffsets[angleIndex][2]],
1643 mcCoords[angleAtoms[angleIndex][3]]
1645 angleOffsets[angleIndex][3]])
1650 mcAngles[angleIndices[angleIndex][2]][resCount-1] =
1655 for(resCount = chainStart;
1656 resCount < chainStart + angleIndices[angleIndex][0] - 1;
1659 mcAngles[angleIndices[angleIndex][2]][resCount] =
NULLVAL;
1662 for(resCount = chainStart +
1663 chainSize[chainCount] +
1664 angleIndices[angleIndex][1];
1665 resCount < (chainStart + chainSize[chainCount]);
1668 mcAngles[angleIndices[angleIndex][2]][resCount] =
1672 chainStart += chainSize[chainCount];
1692 static void SetBendResidues(
REAL **mcAngles,
char **ssTable,
int seqlen)
1696 for(resCount=0; resCount<seqlen; resCount++)
1748 static void MakeHBonds(
REAL ***mcCoords,
BOOL **gotAtom,
int **hbond,
1749 REAL **hbondEnergy,
int *residueTypes,
1750 int *chainEnd,
int seqlen,
BOOL verbose)
1766 for(resCount=0; resCount<seqlen; resCount++)
1770 hbond[resCount][i] = 0;
1771 hbondEnergy[resCount][i] = 0.0;
1777 for(resCount=0; resCount<seqlen; resCount++)
1779 if(resCount > chainEnd[firstChain])
1783 if(gotAtom[
ATOM_N][resCount] &&
1784 gotAtom[
ATOM_H][resCount] &&
1788 for(otherRes=0; otherRes<seqlen; otherRes++)
1790 if(otherRes >= chainEnd[otherChain])
1793 if(((abs(resCount - otherRes) == 1) &&
1794 (firstChain != otherChain)) ||
1795 abs(resCount - otherRes) >= 2)
1797 if(gotAtom[
ATOM_CA][resCount] &&
1804 if(gotAtom[
ATOM_C][otherRes] &&
1805 gotAtom[
ATOM_O][otherRes])
1808 mcCoords[
ATOM_N][resCount]);
1810 mcCoords[
ATOM_H][resCount]);
1812 mcCoords[
ATOM_H][resCount]);
1814 mcCoords[
ATOM_N][resCount]);
1823 fprintf(stderr,
"Sec Struc: (warning) \
1824 Coincident atoms in hydrogen bonding, donor %4d acceptor %4d\n",
1825 resCount+1, otherRes+1);
1840 fprintf(stderr,
"Sec Struc: (warning) \
1841 Atom indices %d and %d too close O-N: %8.3f C-H: %8.3f O-H: %8.3f \
1843 resCount+1, otherRes+1,
1844 distON, distCH, distOH, distCN);
1851 SetHBond(hbondEnergy, hbond, energy,
1852 resCount, otherRes, &nbonds,
1866 fprintf(stderr,
"Sec Struc: (info) Total Number of H-bonds: %5d\n",
1888 static void MakeSummary(
char **ssTable,
1893 static char ssSymbols[] =
"H EB GITS+";
1894 static char altSSSymbols[] =
"h eb gits+";
1898 for(resCount = 0; resCount < seqlen; resCount++)
1907 altSSSymbols[SECSTR_IDX_ALPHAH], seqlen);
1910 MarkSheetsAndBridges(seqlen, ssTable, detailSS, finalSS, ssSymbols,
1916 altSSSymbols[SECSTR_IDX_THRTNH], seqlen);
1925 altSSSymbols[SECSTR_IDX_THRTNH],
1927 altSSSymbols[SECSTR_IDX_TURN],
1930 altSSSymbols[SECSTR_IDX_THRTNH],
1932 altSSSymbols[SECSTR_IDX_TURN],
1935 altSSSymbols[SECSTR_IDX_PIH],
1940 altSSSymbols[SECSTR_IDX_PIH],
1947 altSSSymbols[SECSTR_IDX_TURN], seqlen);
1950 MarkBends(ssTable, detailSS, finalSS, seqlen);
1982 static BOOL MakeTurnsAndBridges(
int **hbond,
char **ssTable,
1983 REAL **mcAngles,
int **bridgePoints,
1984 int *chainEnd,
int seqlen,
1992 static int baseOfSt[
NRULES][4] =
1997 static int baseOffsets[
NRULES][2] =
2002 static int bridgeOffsets[
NRULES] =
2005 static char upperCaseLetters[] =
2006 " ABCDEFGHIJKLMNOPQRSTUVWXYZ";
2007 static char lowerCaseLetters[] =
2008 " abcdefghijklmnopqrstuvwxyz";
2009 static char nstchp[] =
2010 " ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz1234567890";
2012 static int bridgeRules[2][
NRULES] =
2050 **strandCode =
NULL,
2057 seqlenMalloc = seqlen;
2062 sheetCode = (
int *)malloc(
sizeof(
int) * seqlenMalloc);
2064 if((bridge ==
NULL) || (strandCode ==
NULL) || (sheetCode ==
NULL))
2068 if(strandCode !=
NULL)
2071 if(sheetCode !=
NULL)
2078 for(resCount = 0; resCount < seqlen; resCount++)
2088 for(resCount=0; resCount<seqlen; resCount++)
2090 if(resCount >= chainEnd[firstChain])
2093 for(bondCount=0; bondCount<2; bondCount++)
2097 if(hbond[resCount][bondCount] != 0)
2099 if((hbond[resCount][bondCount]-resCount-1 ==
2100 turnSize[turnCount]) &&
2101 (hbond[resCount][bondCount] <= chainEnd[firstChain]))
2103 if(ssTable[turnIndex[turnCount]][resCount] ==
2106 ssTable[turnIndex[turnCount]][resCount] =
2111 ssTable[turnIndex[turnCount]][resCount] =
2114 ssTable[turnIndex[turnCount]]
2117 for(i = resCount + 1;
2118 i < resCount + turnSize[turnCount];
2121 if(ssTable[turnIndex[turnCount]][i] ==
SECSTR_COIL)
2123 ssTable[turnIndex[turnCount]][i] =
2124 turnChar[turnCount];
2129 i<= resCount + turnSize[turnCount];
2141 for(resCount = 0; resCount < seqlen; resCount++)
2143 for(bondCount = 0; bondCount < 4; bondCount++)
2145 bridge[bondCount][resCount] = 0;
2149 for(ruleCount = 0; ruleCount<
NRULES; ruleCount++)
2151 for(resCount = baseOffsets[ruleCount][0];
2152 resCount <= (seqlen + baseOffsets[ruleCount][1]);
2157 for(bond_i = 0; bond_i < 2; bond_i++)
2160 hbond[resCount+baseOfSt[ruleCount][0]-1][bond_i];
2162 if((ruleCount <=
PARLEL) || (bondPointer > resCount))
2164 bridgePointer = bondPointer + baseOfSt[ruleCount][1];
2166 if((bondPointer > -baseOfSt[ruleCount][2]) &&
2167 (abs(resCount - bridgePointer) >
BRIDGE_SEP))
2171 for(bond_j = 0; bond_j < 2; bond_j++)
2173 if(hbond[bondPointer+baseOfSt[ruleCount][2]-1]
2175 resCount+baseOfSt[ruleCount][3])
2181 if(bridge[bridgeIndex][resCount-1] != 0)
2184 bridge[bridgeIndex][resCount-1] =
2185 bridgeOffsets[ruleCount] * bridgePointer;
2187 bridge[bridgeIndex+2][resCount-1] =
2188 bridgeRules[0][ruleCount];
2192 if(bridge[altBridgeIndex-1][bridgePointer-1] !=0)
2195 bridge[altBridgeIndex-1][bridgePointer-1] =
2196 bridgeOffsets[ruleCount] * resCount;
2198 bridge[altBridgeIndex+2-1][bridgePointer-1] =
2199 bridgeRules[1][ruleCount];
2208 for(resCount = 0; resCount < seqlen; resCount++)
2223 for(resCount = 0; resCount < seqlen; resCount++)
2225 sheetCode[resCount] = 0;
2226 strandCode[0][resCount] = 0;
2227 strandCode[1][resCount] = 0;
2228 bridgePoints[0][resCount] = 0;
2229 bridgePoints[1][resCount] = 0;
2233 for(resCount=0; resCount<seqlen; resCount++)
2235 for(bridgeIndex=0; bridgeIndex<2; bridgeIndex++)
2237 if((bridge[bridgeIndex][resCount] != 0) &&
2238 (abs(bridge[bridgeIndex][resCount]) >= resCount))
2241 theBridge = abs(bridge[bridgeIndex][resCount]) - 1;
2242 bridgeDirection = bridge[bridgeIndex][resCount] /
2246 if(abs(bridge[0][theBridge]) == resCount+1)
2249 for(resCountInSS = (resCount + 2);
2253 for(newBridgeIndex = 0;
2257 if((bridge[newBridgeIndex][resCountInSS-1] *
2258 bridgeDirection) > 0)
2261 theNewBridge = abs(bridge[newBridgeIndex]
2262 [resCountInSS-1]) - 1;
2264 if(abs(theNewBridge-theBridge)!=0)
2266 if((theNewBridge-theBridge) /
2267 abs(theNewBridge-theBridge) ==
2271 abs(theNewBridge-theBridge) <=
2274 abs(theNewBridge-theBridge) <=
2278 if(abs(bridge[0][theNewBridge]) ==
2284 for(i = resCount; i< resCountInSS; i++)
2294 if(bridge[bridgeIndex+2][resCount] < 0)
2300 if(bridge[newBridgeIndex+2][resCountInSS-1]
2308 (bridgeDirection < 0) ?
2321 if(bridge[bridgePoint+2][theBridge] < 0)
2327 if(bridge[newBridgePoint+2][theNewBridge] <
2334 if(strandCode[bridgeIndex][resCount] == 0)
2337 strandCode[bridgeIndex][resCount] =
2338 strandNumber * bridgeDirection;
2339 strandCode[bridgePoint][theBridge] =
2340 strandNumber * bridgeDirection;
2343 strandCode[newBridgeIndex][resCountInSS-1] =
2344 strandCode[bridgeIndex][resCount];
2345 strandCode[newBridgePoint][theNewBridge] =
2346 strandCode[bridgePoint][theBridge];
2351 resCountInSS =
MAX(seqlen,
2362 if(bridgeDirection < 0)
2377 if(resCount >= seqlen)
2378 goto RES_COUNT_ERROR;
2381 startOfSheet = resCount;
2382 resCount = startOfSheet + 1;
2387 if(resCount >= seqlen)
2390 endOfSheet = (resCount - 1);
2393 FindNextStrand(strandCode, startOfSheet, endOfSheet, &strandCount,
2394 &newBridgeIndex, lastStrand, &bestValue);
2396 while(bestValue != 0)
2398 lastStrand = fabs(strandCode[newBridgeIndex][strandCount]);
2404 if(strandCode[newBridgeIndex][strandCount] < 0)
2406 strandChar = upperCaseLetters[charCode];
2410 strandChar = lowerCaseLetters[charCode];
2420 thisStrandOffset = strandCount+1;
2425 FindNextCodeOccurrence(thisStrandOffset, endOfSheet,
2426 strandCode[newBridgeIndex]
2429 if(nextStrandOffset <= 0)
2438 thisStrandOffset = nextStrandOffset;
2442 ssTable[strandCharOffset][strandCount] = strandChar;
2445 fabs(bridge[newBridgeIndex][strandCount]);
2447 thisStrandOffset = strandCount+1;
2452 FindNextCodeOccurrence(thisStrandOffset,endOfSheet,
2453 strandCode[newBridgeIndex]
2457 if(nextStrandOffset <= 0)
2460 for(bulgeCount = thisStrandOffset;
2461 bulgeCount < (nextStrandOffset - 1);
2467 ssTable[strandCharOffset][nextStrandOffset-1] = strandChar;
2470 if(strandCode[0][nextStrandOffset-1] !=
2471 strandCode[newBridgeIndex][strandCount])
2477 [nextStrandOffset-1] =
2478 fabs(bridge[strandOffset][nextStrandOffset-1]);
2480 thisStrandOffset = nextStrandOffset;
2483 FindNextStrand(strandCode, startOfSheet, endOfSheet,
2484 &strandCount, &newBridgeIndex, lastStrand,
2487 resCount = endOfSheet + 1;
2488 }
while (resCount < seqlen);
2494 fprintf(stderr,
"Sec Struc: (warning) There are %3d strands. Labels \
2499 LabelSheets(ssTable, bridgePoints, sheetCode, seqlen, verbose);
2501 for(resCount=0; resCount<seqlen; resCount++)
2503 if(sheetCode[resCount] != 0)
2505 charCode = sheetCode[resCount];
2512 for(resCount=0; resCount<seqlen; resCount++)
2514 for(newBridgeIndex=0;
2518 if((bridge[newBridgeIndex][resCount] != 0) &&
2519 (strandCode[newBridgeIndex][resCount] == 0) &&
2520 (fabs(bridge[newBridgeIndex][resCount]) >= resCount))
2523 theBridgePoint = fabs(bridge[newBridgeIndex][resCount]);
2529 if(bridge[newBridgeIndex][resCount] < 0)
2531 bridgeChar = upperCaseLetters[charCode];
2535 bridgeChar = lowerCaseLetters[charCode];
2543 ssTable[bridgeArrayIndex][resCount] = bridgeChar;
2554 ssTable[bridgeArrayIndex][theBridgePoint-1] = bridgeChar;
2557 [theBridgePoint-1] = resCount+1;
2564 fprintf(stderr,
"Sec Struc: (warning) There are %3d bridges. Labels \
2571 if(strandCode !=
NULL)
2572 blFreeArray2D((
char **)strandCode, NUM_STRAND_PAIR, seqlenMalloc);
2573 if(sheetCode !=
NULL)
2593 static void RejectHBond(
int resIndex,
int *bond,
REAL *bonde)
2597 if(bond[0] != resIndex)
2603 bonde[0] = bonde[1];
2628 static void SetSheet(
int bridgePoint,
2639 resCount = bridgePoint-1;
2644 if(resCount >= seqlen)
2648 sheetEnd = resCount - 1;
2649 resCount = bridgePoint-1;
2658 sheetStart = resCount + 1;
2660 for(resCount = sheetStart; resCount <= sheetEnd; resCount++)
2662 sheetCode[resCount] = (-sheetNum);
2685 static void LabelSheets(
char **ssTable,
int **bridgePoints,
2686 int *sheetCode,
int seqlen,
BOOL verbose)
2696 for(resCount=0; resCount<seqlen; resCount++)
2698 sheetCode[resCount] = 0;
2706 FindFirstUnsetSheet(resCount, ssTable, sheetCode, &sheetStart,
2711 for(resCountInSheet = sheetStart;
2712 resCountInSheet <= sheetEnd;
2715 sheetCode[resCountInSheet-1] = sheetNum;
2717 for(bridgeIndex = 0;
2721 if(bridgePoints[bridgeIndex][resCountInSheet-1] != 0)
2723 if(sheetCode[bridgePoints[bridgeIndex]
2724 [resCountInSheet-1]-1] == 0)
2726 SetSheet(bridgePoints[bridgeIndex][resCountInSheet-1],
2727 sheetNum, sheetCode, ssTable, seqlen);
2735 FindNextPartialSheet(sheetEnd+1, sheetNum, ssTable,
2736 sheetCode, bridgePoints, &found, seqlen);
2739 resCount = sheetEnd + 1;
2741 if(resCount > seqlen)
2752 fprintf(stderr,
"Sec Struc: (warning) There are %3d sheets. Labels \
2775 static int FindNextCodeOccurrence(
int strandStart,
int strandEnd,
2776 int code,
int **strandCode)
2780 for(nxpl=strandStart; nxpl<strandEnd; nxpl++)
2782 if((strandCode[0][nxpl] == code) ||
2783 (strandCode[1][nxpl] == code))
2810 static void MarkTurns(
char **ssTable,
char *detailSS,
char *finalSS,
2811 char turnChar,
char altTurnChar,
int seqlen)
2831 for(symbolCount = 1;
2832 symbolCount < helixSize[helixCount];
2837 detailSS[symbolCount] = turnChar;
2841 finalSS[symbolCount] == altTurnChar)
2843 finalSS[symbolCount] = turnChar;
2848 finalSS[0] = altTurnChar;
2851 finalSS[helixSize[helixCount]] = altTurnChar;
2855 resCount < seqlen - helixSize[helixCount];
2858 if((ssTable[helixPri[helixCount]][resCount] ==
2860 ssTable[helixPri[helixCount]][resCount] ==
2862 (ssTable[helixPri[helixCount]][resCount-1] !=
2864 ssTable[helixPri[helixCount]][resCount-1] !=
2866 (ssTable[helixPri[helixCount]][resCount+1] !=
2868 ssTable[helixPri[helixCount]][resCount+1] !=
2871 for(symbolCount = resCount + 1;
2872 symbolCount < (resCount + helixSize[helixCount]);
2877 detailSS[symbolCount] = turnChar;
2881 finalSS[symbolCount] == altTurnChar)
2883 finalSS[symbolCount] = turnChar;
2888 finalSS[resCount] = altTurnChar;
2890 if(finalSS[resCount+helixSize[helixCount]] ==
SECSTR_COIL)
2891 finalSS[resCount+helixSize[helixCount]] = altTurnChar;
2917 static void MarkSheetsAndBridges(
int seqlen,
char **ssTable,
2918 char *detailSS,
char *finalSS,
2919 char *ssSymbols,
char *altSSSymbols)
2923 for(resCount = 0; resCount < seqlen; resCount++)
2946 if(resCount < seqlen-1)
2949 finalSS[resCount-1] == ssSymbols[SECSTR_IDX_BRIDGE])
2957 if(ssTable[SECSTR_IDX_BRIDGE][resCount] !=
SECSTR_COIL)
2989 static void FindNextStrand(
int **strandCode,
int sheetStart,
int sheetEnd,
2990 int *strandCount,
int *startIndex,
2991 int lastStrand,
int *bestValue)
2997 for(nxstr=sheetStart; nxstr<=sheetEnd; nxstr++)
3001 if(abs(strandCode[nxpl][nxstr]) > lastStrand)
3005 *bestValue = abs(strandCode[nxpl][nxstr]);
3007 *strandCount = nxstr;
3011 if(abs(strandCode[nxpl][nxstr]) < *bestValue)
3013 *bestValue = abs(strandCode[nxpl][nxstr]);
3015 *strandCount = nxstr;
#define SECSTR_IDX_BRIDGE
#define SECSTR_SHEET_SMALL
Include file for PDB routines.
#define SECSTR_BRIDGE_BACKWD
Header for secondary structure calculation.
#define MAXBUFF
Secondary structure calculation.
char ** blArray2D(int size, int dim1, int dim2)
#define HBOND_ENERGY_LIMIT
#define SECSTR_IDX_BRIDG2
#define FREE_SECSTR_MEMORY
#define SECSTR_IDX_SHEET1
Include file for 2D/3D array functions.
#define SECSTR_IDX_THRTNH
char *** blArray3D(int size, int dim1, int dim2, int dim3)
REAL blPhi(REAL xi, REAL yi, REAL zi, REAL xj, REAL yj, REAL zj, REAL xk, REAL yk, REAL zk, REAL xl, REAL yl, REAL zl)
#define SECSTR_BRIDGE_FWD
void blFreeArray2D(char **array, int dim1, int dim2)
#define THREE_TEN_CHUNK_SIZE
#define NUM_STANDARD_DIHEDRALS
#define INSERTMATCH(ins1, ins2)
Include file for angle functions.
#define HBOND_MAX_CA_DIST
#define SECSTR_IDX_ALPHAH
#define SECSTR_BEND_START
#define SECSTR_IDX_BRIDG1
System-type variable type definitions.
PDB * blFindNextResidue(PDB *pdb)
#define NUM_MC_ATOM_TYPES
Type definitions for maths.
#define SECSTR_IDX_CHISGN
char chain[blMAXCHAINLABEL]
int blCalcSecStrucPDB(PDB *pdbStart, PDB *pdbStop, BOOL verbose)