32 #define MIN_DEBUG_LEVEL 3 40 #define M_PI 3.14159265358979323846 42 #ifndef CODE_REDUNDANT 43 #define CODE_REDUNDANT 0 82 #ifdef MEM_OPT_VERSION 83 NAMD_die(
"Go forces are not supported in memory-optimized builds.");
85 build_lists_by_atom();
90 iout <<
iINFO <<
"Reading Go File: " << iterator <<
"\n" <<
endi;
94 }
while ( g != NULL && iterator < 100);
126 char first_word[512];
137 int restrictionCount = 0;
167 if ( (pfile = fopen(fname,
"r")) == NULL)
171 sprintf(err_msg,
"UNABLE TO OPEN GO PARAMETER FILE %s\n", fname);
186 (strncmp(first_word,
"!", 1) != 0) &&
187 (strncmp(first_word,
"*", 1) != 0) &&
188 (strncasecmp(first_word,
"END", 3) != 0))
191 iout <<
iWARN <<
"SKIPPING PART OF GO PARAMETER FILE AFTER RETURN STATEMENT\n" <<
endi;
195 if (strncasecmp(first_word,
"chaintypes", 10)==0)
197 read_count=sscanf(buffer,
"%s %d %d\n", first_word, &int1, &int2);
198 if (read_count != 3) {
200 sprintf(err_msg,
"UNKNOWN PARAMETER IN GO PARAMETER FILE %s\nLINE=*%s*\nread_count=%d, int1=%d, int2=%d", fname, buffer, read_count, int1, int2);
208 sprintf(err_msg,
"GO PARAMETER FILE: CHAIN INDEX MUST BE [1-%d] %s\nLINE=*%s*\nread_count=%d, int1=%d, int2=%d",
MAX_GO_CHAINS, fname, buffer, read_count, int1, int2);
219 if (chain1 == chain2) {
231 restrictionCount = 0;
233 else if (strncasecmp(first_word,
"epsilonRep", 10)==0)
235 read_count=sscanf(buffer,
"%s %f\n", first_word, &r1);
236 if (read_count != 2) {}
242 else if (strncasecmp(first_word,
"epsilon", 7)==0)
245 read_count=sscanf(buffer,
"%s %f\n", first_word, &r1);
246 if (read_count != 2) {}
252 else if (strncasecmp(first_word,
"exp_a", 5)==0)
254 read_count=sscanf(buffer,
"%s %d\n", first_word, &int1);
255 if (read_count != 2) {}
256 goValue1->
exp_a = int1;
258 goValue2->
exp_a = int1;
261 else if (strncasecmp(first_word,
"exp_b", 5)==0)
263 read_count=sscanf(buffer,
"%s %d\n", first_word, &int1);
264 if (read_count != 2) {}
265 goValue1->
exp_b = int1;
267 goValue2->
exp_b = int1;
270 else if (strncasecmp(first_word,
"exp_rep", 5)==0)
272 read_count=sscanf(buffer,
"%s %d\n", first_word, &int1);
273 if (read_count != 2) {}
279 else if (strncasecmp(first_word,
"exp_Rep", 5)==0)
281 read_count=sscanf(buffer,
"%s %d\n", first_word, &int1);
282 if (read_count != 2) {}
288 else if (strncasecmp(first_word,
"sigmaRep", 8)==0)
290 read_count=sscanf(buffer,
"%s %f\n", first_word, &r1);
291 if (read_count != 2) {}
297 else if (strncasecmp(first_word,
"cutoff", 6)==0)
299 read_count=sscanf(buffer,
"%s %f\n", first_word, &r1);
300 if (read_count != 2) {}
306 else if (strncasecmp(first_word,
"restriction", 10)==0)
308 read_count=sscanf(buffer,
"%s %d\n", first_word, &int1);
309 if (read_count != 2) {}
311 DebugM(3,
"ERROR: residue restriction value must be nonnegative. int1=" << int1 <<
"\n");
315 DebugM(3,
"ERROR: residue restrictions should not be defined between two separate chains. chain1=" << chain1 <<
", chain2=" << chain2 <<
"\n");
322 else if (strncasecmp(first_word,
"return", 4)==0)
333 sprintf(err_msg,
"UNKNOWN PARAMETER IN GO PARAMETER FILE %s\nLINE=*%s*",fname, buffer);
556 <<
"*****************************************" << std::endl);
566 DebugM(3,
"Go index=(" << i <<
"," << j <<
") epsilon=" <<
go_array[index].epsilon \
567 <<
" exp_a=" <<
go_array[index].exp_a <<
" exp_b=" <<
go_array[index].exp_b \
568 <<
" exp_rep=" <<
go_array[index].exp_rep <<
" sigmaRep=" \
569 <<
go_array[index].sigmaRep <<
" epsilonRep=" <<
go_array[index].epsilonRep \
570 <<
" cutoff=" <<
go_array[index].cutoff << std::endl);
577 #ifndef MEM_OPT_VERSION 581 DebugM(3,
"->build_go_sigmas" << std::endl);
598 BigReal nonnativeEnergy, *nonnative;
601 native = &nativeEnergy;
602 nonnative = &nonnativeEnergy;
604 long nativeContacts = 0;
605 long nonnativeContacts = 0;
610 if (goCoordFile == NULL)
613 NAMD_die(
"Error: goCoordFile is NULL - build_go_sigmas");
617 if (goCoordFile->
next != NULL)
619 NAMD_die(
"Multiple definitions of Go atoms PDB file in configuration file");
622 if ( (cwd == NULL) || (goCoordFile->
data[0] ==
'/') )
624 strcpy(filename, goCoordFile->
data);
628 strcpy(filename, cwd);
629 strcat(filename, goCoordFile->
data);
635 NAMD_die(
"Memory allocation failed in Molecule::build_go_sigmas");
640 NAMD_die(
"Number of atoms in fixed atoms PDB doesn't match coordinate PDB");
649 NAMD_die(
"memory allocation failed in Molecule::build_go_sigmas");
659 if ( chainType != 0 ) {
701 residDiff = resid2 - resid1;
703 if (residDiff < 0) residDiff = -residDiff;
717 sigma = pow(static_cast<double>(exp_b/exp_a),(1.0/(exp_a-exp_b))) * atomAtomDist;
736 iout <<
iINFO <<
"Number of UNIQUE native contacts: " << nativeContacts <<
"\n" <<
endi;
737 iout <<
iINFO <<
"Number of UNIQUE nonnative contacts: " << nonnativeContacts <<
"\n" <<
endi;
740 if (goCoordFile != NULL) {
751 DebugM(3,
"->build_go_sigmas2" << std::endl);
769 long nativeContacts = 0;
770 long nonnativeContacts = 0;
775 if (goCoordFile == NULL)
778 NAMD_die(
"Error: goCoordFile is NULL - build_go_sigmas2");
782 if (goCoordFile->
next != NULL)
784 NAMD_die(
"Multiple definitions of Go atoms PDB file in configuration file");
787 if ( (cwd == NULL) || (goCoordFile->
data[0] ==
'/') )
789 strcpy(filename, goCoordFile->
data);
793 strcpy(filename, cwd);
794 strcat(filename, goCoordFile->
data);
800 NAMD_die(
"Memory allocation failed in Molecule::build_go_sigmas2");
805 NAMD_die(
"Number of atoms in fixed atoms PDB doesn't match coordinate PDB");
816 NAMD_die(
"memory allocation failed in Molecule::build_go_sigmas2");
828 if ( chainType != 0 ) {
853 residDiff = resid2 - resid1;
854 if (residDiff < 0) residDiff = -residDiff;
863 sigma = pow(static_cast<double>(exp_b/exp_a),(1.0/(exp_a-exp_b))) * atomAtomDist;
864 double tmpA = pow(sigma,exp_a);
865 double tmpB = pow(sigma,exp_b);
887 iout <<
iINFO <<
"Number of UNIQUE native contacts: " << nativeContacts <<
"\n" <<
endi;
888 iout <<
iINFO <<
"Number of UNIQUE nonnative contacts: " << nonnativeContacts <<
"\n" <<
endi;
891 std::sort(tmpGoPair.
begin(),tmpGoPair.
end(),goPairCompare);
920 if (goCoordFile != NULL) {
928 bool Molecule::goPairCompare(
GoPair first,
GoPair second) {
954 DebugM(3,
"->build_go_arrays" << std::endl);
970 BigReal nonnativeEnergy, *nonnative;
973 native = &nativeEnergy;
974 nonnative = &nonnativeEnergy;
976 long nativeContacts = 0;
977 long nonnativeContacts = 0;
982 if (goCoordFile == NULL)
985 NAMD_die(
"Error: goCoordFile is NULL - build_go_arrays");
989 if (goCoordFile->
next != NULL)
991 NAMD_die(
"Multiple definitions of Go atoms PDB file in configuration file");
994 if ( (cwd == NULL) || (goCoordFile->
data[0] ==
'/') )
996 strcpy(filename, goCoordFile->
data);
1000 strcpy(filename, cwd);
1001 strcat(filename, goCoordFile->
data);
1005 if (
goPDB == NULL )
1007 NAMD_die(
"goPDB memory allocation failed in Molecule::build_go_arrays");
1012 NAMD_die(
"Number of atoms in fixed atoms PDB doesn't match coordinate PDB");
1020 NAMD_die(
"goSigmaIndices memory allocation failed in Molecule::build_go_arrays");
1028 if ( chainType != 0 ) {
1029 DebugM(3,
"build_go_arrays - atom:" << i << std::endl);
1054 NAMD_die(
"atomChainTypes memory allocation failed in Molecule::build_go_arrays");
1061 NAMD_die(
"goCoordinates memory allocation failed in Molecule::build_go_arrays");
1068 NAMD_die(
"goResids memory allocation failed in Molecule::build_go_arrays");
1073 if (goIndex != -1) {
1089 if (goIndex != -1) {
1093 resid1 = (
goPDB->
atom(i))->residueseq();
1094 resid2 = (
goPDB->
atom(j))->residueseq();
1095 residDiff = resid2 - resid1;
1096 if (residDiff < 0) residDiff = -residDiff;
1100 atomAtomDist = sqrt(pow((
goPDB->
atom(i))->xcoor() - (
goPDB->
atom(j))->xcoor(), 2.0) +
1106 nonnativeContacts++;
1113 iout <<
iINFO <<
"Number of UNIQUE native contacts: " << nativeContacts <<
"\n" <<
endi;
1114 iout <<
iINFO <<
"Number of UNIQUE nonnative contacts: " << nonnativeContacts <<
"\n" <<
endi;
1117 if (goCoordFile != NULL) {
1124 #endif // #ifndef MEM_OPT_VERSION 1141 DebugM(3,
"GO SIGMA ARRAY\n" \
1142 <<
"***************************" << std::endl);
1146 DebugM(3,
"GO SIGMAS HAVE NOT BEEN BUILT" << std::endl);
1156 DebugM(3,
"(" << i <<
"," << j <<
") - +" << sigma <<
" ");
1159 DebugM(3,
"(" << i <<
"," << j <<
") - " << sigma <<
" ");
1166 DebugM(3,
"-----------" << std::endl);
1180 BigReal* pairGaussEnergy)
const 1183 *pairLJEnergy = 0.0;
1184 *pairGaussEnergy = 0.0;
1190 for(
int i = LJbegin; i <= LJend; i++) {
1198 int GaussIndex = -1;
1201 for(
int i = Gaussbegin; i <= Gaussend; i++) {
1208 if( LJIndex == -1 && GaussIndex == -1) {
1215 BigReal ri6 = (ri*ri*ri*ri*ri*ri);
1221 if (LJIndex != -1) {
1223 LJ = (12*(
pairC12[LJIndex]*ri13) - 6*(
pairC6[LJIndex]*ri7));
1224 *pairLJEnergy = (
pairC12[LJIndex]*ri12 -
pairC6[LJIndex]*ri6);
1228 if (GaussIndex != -1) {
1231 BigReal tmp1 = r1prime * r1prime;
1233 BigReal tmp2 = r2prime * r2prime;
1239 tmp_gauss1 = exp(-tmp1*
giSigma1[GaussIndex]);
1240 one_gauss1 = 1 - tmp_gauss1;
1243 tmp_gauss2 = exp(-tmp2*
giSigma2[GaussIndex]);
1244 one_gauss2 = 1 - tmp_gauss2;
1247 Gauss = gr*one_gauss1*one_gauss2 - 2*A*tmp_gauss1*one_gauss2*r1prime*
giSigma1[GaussIndex] \
1248 - 2*tmp_gauss1*one_gauss2*r1prime*
giSigma1[GaussIndex]*
gRepulsive[GaussIndex]*ri12 - 2*A*tmp_gauss2*one_gauss1*r2prime*
giSigma2[GaussIndex] \
1250 *pairGaussEnergy = A*(-1+(one_gauss1)*(one_gauss2)*(1+
gRepulsive[GaussIndex]*ri12/A));
1253 return (LJ + Gauss)*ri;
1276 if (chain1 == 0 || chain2 == 0)
return 0.0;
1282 if (goCutoff == 0)
return 0.0;
1290 pow1 = pow(sigmaRep/r,exp_rep);
1291 goForce = 4*((exp_rep/(r*r)) * epsilonRep * pow1);
1293 *goNonnative = (4 * epsilonRep * pow1 );
1300 if (goSigmaIndex1 != -1 && goSigmaIndex2 != -1) {
1306 pow1 = pow(sigma_ij/r,exp_a);
1307 pow2 = pow(sigma_ij/r,exp_b);
1308 goForce = ((4/(r*r)) * epsilon * (exp_a * pow1 - exp_b * pow2));
1310 *goNative = (4 * epsilon * ( pow1 - pow2 ) );
1363 DebugM(3,
"get_go_force - (" << atom1 <<
"," << atom2 <<
")" << std::endl);
1370 DebugM(3,
" chain1:" << chain1 <<
", chain2:" << chain2 << std::endl);
1371 if (chain1 == 0 || chain2 == 0)
return 0.0;
1375 DebugM(3,
" goCutoff:" << goCutoff << std::endl);
1376 if (goCutoff == 0)
return 0.0;
1387 if ( goIndex1 != -1 && goIndex2 != -1 ) {
1390 residDiff = resid2 - resid1;
1391 if (residDiff < 0) residDiff = -residDiff;
1393 if ( !(const_cast<Molecule*>(
this)->
go_restricted(chain1,chain2,residDiff)) ) {
1397 atomAtomDist = sqrt(xcoorDiff*xcoorDiff + ycoorDiff*ycoorDiff + zcoorDiff*zcoorDiff);
1400 if ( atomAtomDist <= const_cast<Molecule*>(
this)->
get_go_cutoff(chain1,chain2) ) {
1403 sigma_ij = pow(static_cast<double>(exp_b/exp_a),(1.0/(exp_a-exp_b))) * atomAtomDist;
1409 pow1 = pow(sigma_ij/r,static_cast<double>(exp_a));
1410 pow2 = pow(sigma_ij/r,static_cast<double>(exp_b));
1412 goForce = ((4/(r*r)) * epsilon * (exp_a * pow1 - exp_b * pow2));
1413 DebugM(3,
"get_go_force - (" << atom1 <<
"," << atom2 <<
") chain1:" << chain1 <<
", chain2:" << chain2 <<
", exp_a:" << exp_a <<
", exp_b:" << exp_b <<
", sigma_ij:" << sigma_ij <<
", r:" << r <<
", goForce:" << goForce << std::endl);
1415 *goNative = (4 * epsilon * ( pow1 - pow2 ) );
1424 pow1 = pow(sigmaRep/r,(
BigReal)expRep);
1426 goForce = ((4/(r*r)) * expRep * epsilonRep * pow1);
1427 DebugM(3,
"get_go_force - (" << atom1 <<
"," << atom2 <<
") chain1:" << chain1 <<
", chain2:" << chain2 <<
", epsilonRep:" << epsilonRep <<
", sigmaRep:" << sigmaRep <<
", r:" << r <<
", goForce:" << goForce << std::endl);
1429 *goNonnative = (4 * epsilonRep * pow1);
1470 if(chain1 == 0 || chain2 == 0)
return 0.0;
1473 if(goCutoff == 0)
return 0.0;
1477 int residDiff = abs(resid1 - resid2);
1485 for(
int i = LJbegin; i <= LJend; i++) {
1494 if (LJIndex == -1) {
1498 double sigmaRepPow = pow(sigmaRep,exp_rep);
1499 BigReal LJ = (4*epsilonRep*exp_rep*sigmaRepPow*pow(r,-(exp_rep+1)));
1501 *goNonnative = (4*epsilonRep*sigmaRepPow*pow(r,-exp_rep));
1509 BigReal powA = pow(r,-(exp_a + 1));
1510 BigReal powB = pow(r,-(exp_b + 1));
1511 BigReal powaa = pow(r,-exp_a);
1512 BigReal powbb = pow(r,-exp_b);
1524 #ifndef MEM_OPT_VERSION 1551 DebugM(2,
"atoms_1to4(" << atom1 <<
"," << atom2 <<
")" << std::endl);
1555 while(bondNum != -1) {
1561 bondNum = *(++bonds);
1566 while(bondNum != -1) {
1572 bondNum = *(++bonds);
1577 while(angleNum != -1) {
1583 angleNum = *(++angles);
1588 while(angleNum != -1) {
1594 angleNum = *(++angles);
1598 dihedralNum = *dihedrals;
1599 while(dihedralNum != -1) {
1606 dihedralNum = *(++dihedrals);
1610 dihedralNum = *dihedrals;
1611 while(dihedralNum != -1) {
1618 dihedralNum = *(++dihedrals);
1624 #endif // #ifndef MEM_OPT_VERSION 1637 Real *a1, *a2, *a3, *a4;
1638 int *i1, *i2, *i3, *i4;
1647 a1 =
new Real[maxGoChainsSqr];
1648 a2 =
new Real[maxGoChainsSqr];
1649 a3 =
new Real[maxGoChainsSqr];
1650 a4 =
new Real[maxGoChainsSqr];
1651 i1 =
new int[maxGoChainsSqr];
1652 i2 =
new int[maxGoChainsSqr];
1653 i3 =
new int[maxGoChainsSqr];
1656 if ( (a1 == NULL) || (a2 == NULL) || (a3 == NULL) || (a4 == NULL) ||
1657 (i1 == NULL) || (i2 == NULL) || (i3 == NULL) || (i4 == NULL) )
1659 NAMD_die(
"memory allocation failed in Molecules::send_Molecules");
1662 for (
int i=0; i<maxGoChainsSqr; i++) {
1675 msg->
put(maxGoChainsSqr, a1);
1676 msg->
put(maxGoChainsSqr, a2);
1677 msg->
put(maxGoChainsSqr, a3);
1678 msg->
put(maxGoChainsSqr, a4);
1679 msg->
put(maxGoChainsSqr, i1);
1680 msg->
put(maxGoChainsSqr, i2);
1681 msg->
put(maxGoChainsSqr, i3);
1748 Real *a1, *a2, *a3, *a4;
1749 int *i1, *i2, *i3, *i4;
1761 a1 =
new Real[maxGoChainsSqr];
1762 a2 =
new Real[maxGoChainsSqr];
1763 a3 =
new Real[maxGoChainsSqr];
1764 a4 =
new Real[maxGoChainsSqr];
1765 i1 =
new int[maxGoChainsSqr];
1766 i2 =
new int[maxGoChainsSqr];
1767 i3 =
new int[maxGoChainsSqr];
1770 if ( (a1 == NULL) || (a2 == NULL) || (a3 == NULL) || (a4 == NULL) ||
1771 (i1 == NULL) || (i2 == NULL) || (i3 == NULL) || (i4 == NULL) )
1773 NAMD_die(
"memory allocation failed in Molecule::send_Molecule");
1776 msg->
get(maxGoChainsSqr, a1);
1777 msg->
get(maxGoChainsSqr, a2);
1778 msg->
get(maxGoChainsSqr, a3);
1779 msg->
get(maxGoChainsSqr, a4);
1780 msg->
get(maxGoChainsSqr, i1);
1781 msg->
get(maxGoChainsSqr, i2);
1782 msg->
get(maxGoChainsSqr, i3);
1785 for (
int i=0; i<maxGoChainsSqr; i++) {
int get_go_exp_a(int chain1, int chain2)
std::ostream & iINFO(std::ostream &s)
Real get_go_cutoff(int chain1, int chain2)
int32 * get_dihedrals_for_atom(int anum)
int NAMD_read_line(FILE *fd, char *buf, int bufsize)
void send_GoMolecule(MOStream *)
void receive_GoMolecule(MIStream *)
Real get_go_epsilonRep(int chain1, int chain2)
std::ostream & endi(std::ostream &s)
std::ostream & iWARN(std::ostream &s)
MIStream * get(char &data)
void NAMD_find_first_word(char *source, char *word)
#define NAMD_FILENAME_BUFFER_SIZE
int add(const Elem &elem)
Dihedral * get_dihedral(int dnum) const
void read_go_file(char *)
BigReal get_go_force(BigReal, int, int, BigReal *, BigReal *) const
Molecule stores the structural information for the system.
void build_go_arrays(StringList *, char *)
BigReal get_go_force2(BigReal, BigReal, BigReal, int, int, BigReal *, BigReal *) const
int32 * get_angles_for_atom(int anum)
Real get_go_epsilon(int chain1, int chain2)
Angle * get_angle(int anum) const
Real get_go_sigmaRep(int chain1, int chain2)
PDBAtom * atom(int place)
int NAMD_blank_string(char *str)
int get_go_exp_rep(int chain1, int chain2)
GoValue go_array[MAX_GO_CHAINS *MAX_GO_CHAINS]
int32 * get_bonds_for_atom(int anum)
Bool go_restricted(int, int, int)
void NAMD_die(const char *err_msg)
int get_go_exp_b(int chain1, int chain2)
int go_indices[MAX_GO_CHAINS+1]
void build_go_sigmas(StringList *, char *)
BigReal get_gro_force2(BigReal, BigReal, BigReal, int, int, BigReal *, BigReal *) const
MOStream * put(char data)
Bond * get_bond(int bnum) const
int restrictions[MAX_RESTRICTIONS]
Bool atoms_1to4(unsigned int, unsigned int)
BigReal get_go_force_new(BigReal, int, int, BigReal *, BigReal *) const
void build_go_params(StringList *)
void build_go_sigmas2(StringList *, char *)