float vdw(ATOM atom1, ATOM atom2) { float e = 0; float d2, d6, d12; /* distance with power 2, 6, and 12 */ float C12, C6; char pair[4]; VECTOR v1, v2; FILE *debug_fp; if (!atom1.on) return e; if (!atom2.on) return e; v1 = atom1.xyz; v2 = atom2.xyz; d2 = ddvv(v1, v2); if (d2 > cutoff_far2) e = VDW_ELIMIT_FAR; /* Cutoff */ else if (d2 < cutoff_near2) e = VDW_ELIMIT_NEAR; /* Cutoff */ else { /* 12-6 L-J potential */ pair[0] = atom1.name[1]; /* element name */ pair[1] = '-'; pair[2] = atom2.name[1]; /* element name */ pair[3] = '\0'; if (param_get("VDWAMBER", "C12", pair, &C12)) { param_get("VDWAMBER", "C12", "X-X", &C12); debug_fp = fopen(env.debug_log,"a"); fprintf(debug_fp, "VDWAMBER C12 %s %16.6f\n", pair, C12); fclose(debug_fp); param_sav("VDWAMBER", "C12", pair, &C12,sizeof(C12)); } if(param_get("VDWAMBER", "C6", pair, &C6)) { param_get("VDWAMBER", "C6", "X-X", &C6); debug_fp = fopen(env.debug_log,"a"); fprintf(debug_fp, "VDWAMBER C6 %s %16.6f\n", pair, C6); fclose(debug_fp); param_sav("VDWAMBER", "C6", pair, &C6,sizeof(C6)); } d6 = d2*d2*d2; d12 = d6*d6; e = C12/d12 - C6/d6; } return e; }
int assign_crg(PROT prot) { int k_res,k_conf,k_atom; CONF *conf_p; ATOM *atom_p; FILE *debug_fp; int err=0; for (k_res=0; k_res<prot.n_res; k_res++) { for (k_conf=0; k_conf<prot.res[k_res].n_conf; k_conf++) { conf_p = &prot.res[k_res].conf[k_conf]; for (k_atom=0; k_atom<prot.res[k_res].conf[k_conf].n_atom; k_atom++) { atom_p = &conf_p->atom[k_atom]; if (!atom_p->on) continue; if ( param_get( "CHARGE", conf_p->confName, atom_p->name, &atom_p->crg) ) { debug_fp = fopen(env.debug_log,"a"); if (!debug_fp) debug_fp = stdout; fprintf(debug_fp, "CHARGE %s %s 0.000\n", conf_p->confName, atom_p->name); fclose(debug_fp); err = 1; atom_p->crg = 0; param_sav("CHARGE", conf_p->confName, atom_p->name, &atom_p->crg, sizeof(float)); } //printf(" Debugging! residue %s%4d,conformer %s atom %s crg %f\n", prot.res[k_res].resName,prot.res[k_res].resSeq,conf_p->confName,atom_p->name,atom_p->crg); } } } if (err) printf(" Warning! assign_crg(): missing parameter(s), default value is used and saved in %s.\n", env.debug_log); return 0; }
int get_connect12_conf(int i_res, int i_conf, PROT prot) { CONNECT connect; FILE *debug_fp; int i_atom; int j_connect, k_connect, n_connect; int j_res, j_conf, j_atom; int k_lig, l_connect; int n_ligs, n_conf; int connect_found, lig_treated; RES *res_p; CONF *conf_p; ATOM *atom_p,*jatom_p, *ligs[MAX_LIGS]; int ligs_res[MAX_LIGS]; int err = 0; res_p = &prot.res[i_res]; conf_p = &prot.res[i_res].conf[i_conf]; /* Looping over all atoms */ for (i_atom=0; i_atom<prot.res[i_res].conf[i_conf].n_atom; i_atom++) { atom_p = &prot.res[i_res].conf[i_conf].atom[i_atom]; if (!atom_p->on) continue; for (j_connect=0; j_connect<MAX_CONNECTED; j_connect++) { atom_p->connect12[j_connect] = NULL; } /* Error checking for connectivity parameter */ memset(atom_p->connect12, 0, MAX_CONNECTED*sizeof(void *)); if( param_get("CONNECT", conf_p->confName, atom_p->name, &connect) ) { debug_fp = fopen(env.debug_log, "a"); fprintf(debug_fp, " Error! get_connect12(): Can't find CONNECT parameter of conformer \"%s\" atom \"%s\"\n", conf_p->confName, atom_p->name); fclose(debug_fp); err++; continue; } if( connect.n > MAX_CONNECTED ) { debug_fp = fopen(env.debug_log, "a"); fprintf(debug_fp, " Error! get_connect12(): Error in CONNECT parameter for conformer \"%s\" atom \"%s\", number of connected atoms is bigger than array size\nCheck parameter file or fix mcce.h with a bigger MAX_CONNECTED \n", conf_p->confName, atom_p->name); fclose(debug_fp); return USERERR; } lig_treated = 0; /* for each atom, ligand connectivy is checked at most once, no matter how many connectivities this atom has */ /* Looping over each connectivity member */ for (j_connect=0; j_connect<connect.n; j_connect++) { connect_found = 0; /* Ligand type connectivity or not */ if (!connect.atom[j_connect].ligand) { /* NOT ligand type */ if (!connect.atom[j_connect].res_offset) { /* If within the same residue (off_set is 0) */ j_res = i_res; if ( !param_get("IATOM", conf_p->confName, connect.atom[j_connect].name, &j_atom) ) { /* First search atom in the same conformer */ j_conf = i_conf; atom_p->connect12[j_connect] = &prot.res[j_res].conf[j_conf].atom[j_atom]; atom_p->connect12_res[j_connect] = j_res; connect_found = 1; } else { /* If not in same conformer, there are two situations: 1. atom is in side chain conformer, connecting to backbone; 2. atom is in backbone conformer, connecting to side chain; */ for (j_conf = 0; j_conf < prot.res[j_res].n_conf; j_conf++) { if (j_conf == i_conf) continue; if ( !param_get("IATOM", prot.res[j_res].conf[j_conf].confName, connect.atom[j_connect].name, &j_atom) ) { atom_p->connect12[j_connect] = &prot.res[j_res].conf[j_conf].atom[j_atom]; atom_p->connect12_res[j_connect] = j_res; connect_found = 1; break; } } if (!connect_found) { char err_msg1[MAXCHAR_LINE]; char err_msg2[MAXCHAR_LINE]; sprintf(err_msg1," Error! get_connect12(): connectivity of atom \"%s %s %c%04d\" is not complete", atom_p->name, conf_p->confName, res_p->chainID, res_p->resSeq); sprintf(err_msg2," get_connect12(): atom %s in the same residue is not found", connect.atom[j_connect].name); if (param_exist(err_msg1, "", "")) { if (param_exist(err_msg2, "", "")) { continue; } } param_sav(err_msg1, "", "", "", 0); param_sav(err_msg2, "", "", "", 0); debug_fp = fopen(env.debug_log, "a"); fprintf(debug_fp,"%s\n",err_msg1); fprintf(debug_fp,"%s\n",err_msg2); fclose(debug_fp); err++; } } } else { /* Not in the same reside. */ j_res = i_res + connect.atom[j_connect].res_offset; if (j_res < 0 || j_res >= prot.n_res) { /* j_res is out of residue list */ char err_msg1[MAXCHAR_LINE]; char err_msg2[MAXCHAR_LINE]; sprintf(err_msg1, " Error! get_connect12(): connectivity of atom \"%s %s %c%04d\" is not complete:\n", atom_p->name, res_p->resName, res_p->chainID, res_p->resSeq); sprintf(err_msg2, " get_connect12(): atom %s of residue i%+d is not found \n", connect.atom[j_connect].name,connect.atom[j_connect].res_offset); if (param_exist(err_msg1, "", "")) { if (param_exist(err_msg2, "", "")) { continue; } } param_sav(err_msg1, "", "", "", 0); param_sav(err_msg2, "", "", "", 0); debug_fp = fopen(env.debug_log, "a"); fprintf(debug_fp,"%s\n",err_msg1); fprintf(debug_fp,"%s\n",err_msg2); fclose(debug_fp); err++; continue; } for (j_conf = 0; j_conf < prot.res[j_res].n_conf; j_conf++) { if ( !param_get("IATOM", prot.res[j_res].conf[j_conf].confName, connect.atom[j_connect].name, &j_atom) ) { if (!prot.res[j_res].conf[j_conf].atom[j_atom].on) { atom_p->connect12[j_connect] = &prot.res[j_res].conf[j_conf].atom[j_atom]; atom_p->connect12_res[j_connect] = j_res; connect_found = 1; debug_fp = fopen(env.debug_log, "a"); fprintf(debug_fp, " WARNING! get_connect12(): atom %s of residue i%+d is in connectivity list of atom \"%s %s %c%04d\", but it's not on\n", connect.atom[j_connect].name,connect.atom[j_connect].res_offset,atom_p->name, res_p->resName, res_p->chainID, res_p->resSeq); fclose(debug_fp); break; } if (BOND_THR > dvv(atom_p->xyz, prot.res[j_res].conf[j_conf].atom[j_atom].xyz)) { atom_p->connect12[j_connect] = &prot.res[j_res].conf[j_conf].atom[j_atom]; atom_p->connect12_res[j_connect] = j_res; connect_found = 1; break; } } } if (!connect_found) { char err_msg1[MAXCHAR_LINE]; char err_msg2[MAXCHAR_LINE]; sprintf(err_msg1, " Error! get_connect12(): connectivity of atom \"%s %s %c%04d\" is not complete:\n", atom_p->name, res_p->resName, res_p->chainID, res_p->resSeq); sprintf(err_msg2, " get_connect12(): atom %s of residue i%+d is not found \n", connect.atom[j_connect].name,connect.atom[j_connect].res_offset); if (param_exist(err_msg1, "", "")) { if (param_exist(err_msg2, "", "")) { continue; } } param_sav(err_msg1, "", "", "", 0); param_sav(err_msg2, "", "", "", 0); debug_fp = fopen(env.debug_log, "a"); fprintf(debug_fp,"%s\n",err_msg1); fprintf(debug_fp,"%s\n",err_msg2); fclose(debug_fp); err++; } } } else { /* Ligand type connectivity */ if (lig_treated) continue; /* Loop over all atoms and find all atom within bond threshold */ n_ligs = 0; for (j_res=0; j_res < prot.n_res; j_res++) { if (j_res == i_res) continue; if ( prot.res[j_res].n_conf>2 ) n_conf=2; else n_conf = prot.res[j_res].n_conf; for (j_conf=0; j_conf < n_conf; j_conf++) { /* searching is localized in backbone and first side chain */ for (j_atom=0; j_atom<prot.res[j_res].conf[j_conf].n_atom; j_atom++) { jatom_p = &prot.res[j_res].conf[j_conf].atom[j_atom]; if (!jatom_p->on) continue; if (BOND_THR > dvv(atom_p->xyz, jatom_p->xyz)) { n_ligs++; ligs[n_ligs-1] = jatom_p; ligs_res[n_ligs-1] = j_res; } } } } /* Go over connectivity list and put connected atoms in for those atom name is defined */ for (k_connect=j_connect; k_connect<connect.n; k_connect++) { if (!connect.atom[k_connect].ligand) continue; if (atom_p->connect12[k_connect]) continue; if (strchr(connect.atom[k_connect].name, '?')) continue; /* If atom name in parameter is a '?', then go to next one */ for (k_lig=0; k_lig<n_ligs; k_lig++) { if (strcmp(ligs[k_lig]->name, connect.atom[k_connect].name)) continue; /* Check if ligand atom is already in the connectivity list, this is for the case one atom connect to over one atom with same name */ for (l_connect=j_connect; l_connect<connect.n; l_connect++) { if (ligs[k_lig] == atom_p->connect12[l_connect]) break; } if (l_connect < connect.n) continue; /* Adding ligs[k_lig] into list */ atom_p->connect12[k_connect] = ligs[k_lig]; atom_p->connect12_res[k_connect] = ligs_res[k_lig]; break; } } /* Then go over connectivity list again and put atoms in for those atom name is not defined */ for (k_connect=j_connect; k_connect<connect.n; k_connect++) { int k_lig_add; float lig_dist; if (!connect.atom[k_connect].ligand) continue; if (atom_p->connect12[k_connect]) continue; if (!strchr(connect.atom[k_connect].name, '?')) continue; /* If atom name in parameter is not a '?', then go to next one */ k_lig_add = -1; lig_dist = BOND_THR; for (k_lig=0; k_lig<n_ligs; k_lig++) { if (ligs[k_lig]->name[1] == 'H') continue; /* If it's a proton, then not considered */ /* Check if ligand atom is already in the connectivity list, this is for the case one atom connect to over one atom with same name */ for (l_connect=j_connect; l_connect<connect.n; l_connect++) { if (ligs[k_lig] == atom_p->connect12[l_connect]) break; } if (l_connect < connect.n) continue; if (dvv(atom_p->xyz,ligs[k_lig]->xyz) < lig_dist) { lig_dist = dvv(atom_p->xyz,ligs[k_lig]->xyz); k_lig_add = k_lig; } } /* Adding ligs[k_lig] into list */ if (k_lig_add >= 0) { atom_p->connect12[k_connect] = ligs[k_lig_add]; atom_p->connect12_res[k_connect] = ligs_res[k_lig_add]; } } /* Go over connectivity list to check if there is empty slot */ for (k_connect=j_connect; k_connect<connect.n; k_connect++) { if (!connect.atom[k_connect].ligand) continue; if (atom_p->connect12[k_connect]) continue; char err_msg1[MAXCHAR_LINE]; sprintf(err_msg1, " Warning! get_connect12(): An empty ligand connectivity slot found for atom %s in residue %s %d to atom %s\n", atom_p->name, res_p->resName, res_p->resSeq, connect.atom[k_connect].name); if (param_exist(err_msg1, "", "")) { continue; } param_sav(err_msg1, "", "", "", 0); debug_fp = fopen(env.debug_log, "a"); fprintf(debug_fp,"%s\n",err_msg1); fclose(debug_fp); } /* Check if all ligand atoms are in the connectivity list */ for (k_lig=0; k_lig<n_ligs; k_lig++) { if (ligs[k_lig]->name[1] == 'H') continue; /* If it's a proton, then not considered */ /* Check if ligand atom is already in the connectivity list, this is for the case one atom connect to over one atom with same name */ for (l_connect=j_connect; l_connect<connect.n; l_connect++) { if (ligs[k_lig] == atom_p->connect12[l_connect]) break; } if (l_connect < connect.n) continue; char err_msg1[MAXCHAR_LINE]; sprintf(err_msg1, " Warning! get_connect12(): An atom (%s in residue %s %d) within bond threshold to atom %s in residue %s %d is not put in the connectivity list \n",ligs[k_lig]->name, ligs[k_lig]->resName, ligs[k_lig]->resSeq, atom_p->name, res_p->resName, res_p->resSeq); if (param_exist(err_msg1, "", "")) { continue; } param_sav(err_msg1, "", "", "", 0); debug_fp = fopen(env.debug_log, "a"); fprintf(debug_fp,"%s\n",err_msg1); fclose(debug_fp); } lig_treated = 1; /* END of treating ligand type */ } /* If connecting to a dummy atom, it could be the case connecting to NTR or CTR */ if (!atom_p->connect12[j_connect]) continue; if ( atom_p->connect12[j_connect]->on) continue; if (strcmp(connect.atom[j_connect].name, " CA ") && strcmp(connect.atom[j_connect].name, " C ")) continue; //printf(" Debugging! residue %s%4d,conformer %s, on=%d\n", res_p->resName,res_p->resSeq,conf_p->confName,atom_p->connect12[j_connect]->on); connect_found = 0; for (j_res=0; j_res<prot.n_res; j_res++) { if (strcmp(prot.res[j_res].resName, "NTR")) if (strcmp(prot.res[j_res].resName, "NTG")) if (strcmp(prot.res[j_res].resName, "CTR")) continue; for (j_conf=0; j_conf<prot.res[j_res].n_conf; j_conf++) { for (j_atom=0; j_atom<prot.res[j_res].conf[j_conf].n_atom; j_atom++) { jatom_p = &prot.res[j_res].conf[j_conf].atom[j_atom]; if (!jatom_p->on) continue; if (strcmp(connect.atom[j_connect].name, jatom_p->name)) continue; if (BOND_THR > dvv(atom_p->xyz, jatom_p->xyz)) { atom_p->connect12[j_connect] = jatom_p; atom_p->connect12_res[j_connect] = j_res; connect_found = 1; break; } } if (connect_found) break; } if (connect_found) break; } } /* Move NULL pointer to the end of the array */ n_connect = connect.n; for (j_connect=0; j_connect < n_connect-1; j_connect++) { if (!atom_p->connect12[j_connect]) { for (k_connect=j_connect; k_connect<n_connect-1; k_connect++) { atom_p->connect12[k_connect] = atom_p->connect12[k_connect+1]; atom_p->connect12_res[k_connect] = atom_p->connect12_res[k_connect+1]; } atom_p->connect12[n_connect-1] = NULL; atom_p->connect12_res[n_connect-1] = 0; j_connect--; n_connect--; } } } return 0; }
int head3lst_param(EMATRIX ematrix) { int kc; float rxn0, extra, em0, pka0; char sbuff[6]; int H, e; for (kc=0; kc<ematrix.n; kc++) { strncpy(sbuff, ematrix.conf[kc].uniqID, 5); sbuff[5] = '\0'; if (param_get("EM", sbuff, "", &em0)) { printf(" WARNING: No EM entry for %s, set to 0.\n", sbuff); fflush(stdout); em0 = 0.0; param_sav("EM", sbuff, "", &em0, sizeof(float)); } ematrix.conf[kc].Em = em0; if (param_get("PKA", sbuff, "", &pka0)) { printf(" WARNING: No PKA entry for %s, set to 0.\n",sbuff); fflush(stdout); pka0 = 0.0; param_sav("PKA",sbuff, "", &pka0, sizeof(float)); } ematrix.conf[kc].pKa = pka0; if (param_get("PROTON",sbuff, "", &H)) { printf(" WARNING: no PROTON for %s, 0 assumed\n",sbuff); H = 0; param_sav("PROTON",sbuff, "", &H, sizeof(int)); } ematrix.conf[kc].H = H; if (param_get("ELECTRON",sbuff, "", &e)) { printf(" WARNING: no ELECTRON for %s, 0 assumed\n",sbuff); e = 0; param_sav("ELECTRON",sbuff, "", &e, sizeof(int)); } ematrix.conf[kc].e = e; if (!strcmp(env.pbe_solver, "delphi") && !strcmp(env.rxn_method, "surface")) { if (param_get("RXN",sbuff, "", &rxn0)) { printf(" WARNING: No RXN entry for %s, set to 0.\n",sbuff); fflush(stdout); rxn0 = 0.0; param_sav("RXN",sbuff, "", &rxn0, sizeof(float)); } ematrix.conf[kc].E_rxn0 = rxn0; /*this is the case with delphi*/ } else ematrix.conf[kc].E_rxn0 = 0.0; /*this is the case with apbs*/ if (param_get("EXTRA",sbuff, "", &extra)) { /* printf(" WARNING: No EXTRA entry for %s, set to 0.\n",sbuff); */ fflush(stdout); extra = 0.0; param_sav("EXTRA",sbuff, "", &extra, sizeof(float)); } ematrix.conf[kc].E_extra = extra; /*if we calculate rxn with self energies, then we don't need rxn0*/ ematrix.conf[kc].E_dsolv = ematrix.conf[kc].E_rxn - ematrix.conf[kc].E_rxn0; /* label unrealistic values */ if (ematrix.conf[kc].E_vdw0 > 999.0) ematrix.conf[kc].E_vdw0 = 999.0; if (ematrix.conf[kc].E_vdw1 > 999.0) ematrix.conf[kc].E_vdw1 = 999.0; } return 0; }
int make_matrices(PROT prot, char *dir) { int i, kr, kc, counter, verbose; int n_conf, n_dummies; char fname[MAXCHAR_LINE]; FILE *fp; char sbuff[MAXCHAR_LINE]; char sbuff2[MAXCHAR_LINE]; char confName[6]; int natom; int serial; char uniqID[15]; char dummy; EMATRIX ematrix; if (verbose != 1) { verbose = 0; } n_conf = 0; for (kr=0; kr<prot.n_res; kr++) { n_conf+=(prot.res[kr].n_conf-1); } /* Try to load an existing energy table */ ematrix.n = 0; /* the load_energies program relies on n to determine the validation of pointers */ if (load_energies(&ematrix, dir, verbose) == n_conf) { /* partial run exits */ printf(" File %s/%s exists, energy calculation will update this file\n", dir, ENERGY_TABLE); } else { /* initialize a new one with current run */ free_ematrix(&ematrix); /* if ematrix.n is 0, nothing would happen */ ematrix.n = n_conf; if (!(ematrix.conf = (CONF_HEAD *) calloc(ematrix.n, sizeof(CONF_HEAD)))) { printf(" Allocate memory error\n"); return USERERR; } if (!(ematrix.pw = (PAIRWISE **) calloc(ematrix.n, sizeof(PAIRWISE *)))) { printf(" Allocate memory error\n"); return USERERR; } for (i=0; i<ematrix.n; i++) { if (!(ematrix.pw[i] = (PAIRWISE *) calloc(ematrix.n, sizeof(PAIRWISE)))) { printf(" Allocate memory error\n"); return USERERR; } } for (i=0; i<ematrix.n; i++) { ematrix.conf[i].on = 'f'; } } counter = 0; n_dummies = 0; for (kr=0; kr<prot.n_res; kr++) { for (kc=1; kc<prot.res[kr].n_conf; kc++) { strcpy(ematrix.conf[counter].uniqID, prot.res[kr].conf[kc].uniqID); strcpy(ematrix.conf[counter].history, prot.res[kr].conf[kc].history); strncpy(confName, ematrix.conf[counter].uniqID, 5); confName[5] = '\0'; if (param_get("NATOM", confName, "", &natom)) { printf(" WARNING: no NATOM for %s, 0 assumed\n", confName); natom = 0; param_sav("NATOM", confName, "", &natom, sizeof(int)); } if (natom == 0) { /* dummy */ n_dummies ++; ematrix.conf[counter].on = 't'; counter ++; continue; } ematrix.conf[counter].netcrg = prot.res[kr].conf[kc].netcrg; if (env.recalc_tors) ematrix.conf[counter].E_tors = torsion_conf(&prot.res[kr].conf[kc]); /* other parameters will be updated by head3lst_update once uniqID is defined*/ counter++; } } /* updating self energy terms for conformers in current delphi */ refresh_prot(prot); counter = 0; n_dummies = 0; for (kr=0; kr<prot.n_res;kr++) { for (kc=1; kc<prot.res[kr].n_conf; kc++) { strncpy(confName, ematrix.conf[counter].uniqID, 5); confName[5] = '\0'; if (param_get("NATOM", confName, "", &natom)) { printf(" WARNING: no NATOM for %s, 0 assumed\n", confName); natom = 0; param_sav("NATOM", confName, "", &natom, sizeof(int)); } if (natom == 0) { /* dummy */ n_dummies ++; ematrix.conf[counter].on = 't'; counter ++; continue; } if (((counter-n_dummies+1) >= env.pbe_start && (counter-n_dummies+1) <= env.pbe_end)) { ematrix.conf[counter].E_vdw0 = prot.res[kr].conf[kc].E_vdw0; ematrix.conf[counter].E_vdw1 = prot.res[kr].conf[kc].E_vdw1; ematrix.conf[counter].E_tors = prot.res[kr].conf[kc].E_tors; ematrix.conf[counter].E_epol = prot.res[kr].conf[kc].E_epol; ematrix.conf[counter].E_rxn = prot.res[kr].conf[kc].E_rxn; if (!strcmp(env.pbe_solver, "apbs") || !strcmp(env.rxn_method, "self")) ematrix.conf[counter].E_rxn0 = 0.0; ematrix.conf[counter].E_dsolv = ematrix.conf[counter].E_rxn - ematrix.conf[counter].E_rxn0; } counter++; } } head3lst_param(ematrix); /* fine tune and complete the rest param */ /* updating the pw of matrix */ n_dummies = 0; for (kc=0; kc<ematrix.n; kc++) { /* dummy conformer doesn't have opp file */ strncpy(confName, ematrix.conf[kc].uniqID, 5); confName[5] = '\0'; if (param_get("NATOM", confName, "", &natom)) { printf(" WARNING: no NATOM for %s, 0 assumed\n", confName); natom = 0; param_sav("NATOM", confName, "", &natom, sizeof(int)); } if (natom == 0) { /* dummy */ n_dummies ++; ematrix.conf[kc].on = 't'; for (i=0; i<ematrix.n; i++) { ematrix.pw[kc][i].ele = ematrix.pw[kc][i].vdw = ematrix.pw[kc][i].crt = ematrix.pw[kc][i].ori = 0.0; ematrix.pw[kc][i].mark[0] = '\0'; } continue; } if (((kc-n_dummies+1) >= env.pbe_start && (kc-n_dummies+1) <= env.pbe_end)) { /* in current calculation */ ematrix.conf[kc].on = 't'; sprintf(fname, "%s.opp", ematrix.conf[kc].uniqID); if (!(fp = fopen(fname, "r"))) { printf(" FATAL: read file error %s\n", fname); return USERERR; } /* load pairwise energy */ for (i=0; i<ematrix.n; i++) { /* Skip dummies */ while (1) { /* a mismatch, dummy */ strncpy(confName, ematrix.conf[i].uniqID, 5); confName[5] = '\0'; if (param_get("NATOM", confName, "", &natom)) { printf(" FATAL: no NATOM for %s\n", confName); return USERERR; } if (natom == 0) { ematrix.pw[kc][i].ele = ematrix.pw[kc][i].vdw = ematrix.pw[kc][i].crt = ematrix.pw[kc][i].ori = 0.0; ematrix.pw[kc][i].mark[0] = '\0'; dummy = 1; i++; /* skip to the next valid */ } else { dummy = 0; break; /* break as non dummy */ } if (i>=ematrix.n) break; /* break as done, dummy would continue */ } if (dummy) break; /* everything reaches here is non dummy */ if (!fgets(sbuff, sizeof(sbuff), fp)) { printf(" FATAL: Unexpected end of file %s.\n", fname); return USERERR; } strncpy(sbuff2, sbuff, 5); sbuff2[5] = '\0'; serial = atoi(sbuff2); strncpy(uniqID, sbuff+6, 14); uniqID[14] = '\0'; strncpy(sbuff2, sbuff+20, 10); sbuff2[10] = '\0'; ematrix.pw[kc][i].crt = atof(sbuff2); strncpy(sbuff2, sbuff+30, 10); sbuff2[10] = '\0'; ematrix.pw[kc][i].vdw = atof(sbuff2); strncpy(sbuff2, sbuff+40, 10); sbuff2[10] = '\0'; ematrix.pw[kc][i].ori = atof(sbuff2); strncpy(ematrix.pw[kc][i].mark, sbuff+50, 3); *(strchr(ematrix.pw[kc][i].mark,'\n')) = '\0'; //sscanf(sbuff, "%d %s %f %f %f %s", &serial, uniqID, &pairwise_raw[kc][i].ele, &pairwise_raw[kc][i].vdw, &pairwise_raw[kc][i].ori, pairwise_raw[kc][i].mark); if (strcmp(uniqID, ematrix.conf[i].uniqID)) { printf(" FATAL: Mismatch %s in protein structure and %s in %s.\n", ematrix.conf[i].uniqID, uniqID, fname); return USERERR; } } fclose(fp); } } if (write_energies(&ematrix, dir, verbose)) { printf(" Error in writing energy lookuptable %s/%s\n", dir, ENERGY_TABLE); return USERERR; } free_ematrix(&ematrix); return 0; }