int main() { char s[81]; gets(s); removeSpace(s); printf("%s", s); return 0; }
int main(int argc, char * argv[]) { /* must be defined as an array */ /* if defined as a pont, it will be read only space */ char str[] = " hello world "; removeSpace(str); printf("%s\n", str); return 1; }
//if true return true, and also set the path bool plainconf::isInclude(const char *sLine, AutoStr2 &path) { if (strncasecmp(sLine, "include", 7) == 0) { char *p = (char *)sLine + 7; removeSpace(p, 0); path = p; return true; } return false; }
int main (int argc, const char * argv[]) { char string[100]; char ch; int i = 0; printf("Enter input: \n"); while (gets(string) && string[0] != '\0') { removeSpace(string); printf("The new sentence: %s\n", string); } return 0; }
int main(int argc, char* argv[]) { //表达式求值(入口) for (int i=1; i<argc; i++) { //逐一处理各命令行参数(表达式) /*DSA*/system("cls"); printf("\nPress any key to evaluate: [%s]\a\n", argv[i]); getchar(); char* rpn = (char*)malloc(sizeof(char)*1); rpn[0] = '\0'; //逆波兰表达式 float value = evaluate(removeSpace(argv[i]), rpn); //求值 /*DSA*/printf("EXPR\t: %s\n", argv[i]); //输出原表达式 /*DSA*/printf("RPN\t: [ %s]\n", rpn); //输出RPN /*DSA*/printf("Value\t= %.1f = %d\n", value, (int)value); //输出表达式的值 free(rpn); rpn = NULL; /*DSA*/getchar(); } return 0; }
Node makeNodeElements(Node new_node, char* string, int i) { char* value_for_insertion = removeSpace(string); switch (i){ case 0: strcpy(new_node->name, value_for_insertion); break; case 1: strcpy(new_node->route->bus_line, value_for_insertion); break; case 2: strcpy(new_node->start_time, value_for_insertion); break; } return new_node; }
void ParseAsset(const char* filename) { FILE* file = fopen(filename, "r"); char* start; char* end; char raw_line[256]; char line[256]; printf("Parsing...\n"); void* gameAssetPointer; //just so I remeber that we'll need such a pointer void* compoundAssetPointer; //ditto while (fgets(raw_line, 256, file) != NULL) { strncpy(line, removeSpace(raw_line), 256); //filter out whitespace if (strchr(raw_line, '#') != NULL) { //filter out comments end = strchr(raw_line, '#'); *end = '\0'; } if (line[0] == '[') { //define a section if (strchr(line, ']') == NULL) { //make sure the syntax is correct printf("Error, bad syntax in: %s\n", line); exit(1); } *strchr(line, ']') = '\0'; printf("Section: %s\n", line + 1); } else if (strchr(line, ':') != NULL) { //define a param/value pair end = strchr(line, ':'); *end = '\0'; //if (strpbrk(line, "Texture") == NULL) if (!strcmp(line, "Texture")) printf("Got Texture: %s\n", end + 1); else if (!strcmp(line, "Offset")) printf("Got Offset: %s\n", end + 1); else if (!strcmp(line, "Origin")) printf("Got Origin: %s\n", end + 1); } } }
void listInstruction(char *filepath, int n) { FILE *fp; fp = fopen(filepath,"r"); char *buffer = (char *) malloc(BUFFER_SIZE * sizeof(char)); if (fp==NULL) { perror("ERROR in opening file"); exit(EXIT_FAILURE); } while (!feof(fp) &&0<n ){ memset(buffer, 0, ((sizeof(char))*BUFFER_SIZE)); fgets (buffer, BUFFER_SIZE, fp); if(strlen(buffer)>1) n--; } if(n==0) { printf("%s", removeSpace(buffer)); } else{ perror("End of file reached before line"); } free(buffer); fclose(fp); }
//----------------------------------------------------------------------// void CIO::commVecPDB(const vector<string>& strCommPDB) { string strLine,strSubLine,strHeader,strX,strY,strZ; delphi_integer iAtomIndex = 0; CAtomPdb tmpAtomObj; for (int i = 0; i < strCommPDB.size(); ++i) { strLine = strCommPDB[i]; // to ignore possible empty lines strSubLine = removeSpace(strLine); if (0 == strSubLine.compare(0,1,"")) continue; strHeader = strLine.substr(0,6); strHeader = toUpperCase(strHeader); if (0 == strHeader.compare("ATOM ") || 0 == strHeader.compare("HETATM")) { tmpAtomObj.setAtInf(strLine.substr(11,15)); strX = strLine.substr(30,8); strX = removeSpace(strX); strY = strLine.substr(38,8); strY = removeSpace(strY); strZ = strLine.substr(46,8); strZ = removeSpace(strZ); tmpAtomObj.setPose( atof(strX.c_str()),atof(strY.c_str()),atof(strZ.c_str()) ); strSubLine = strLine.substr(54,8); strSubLine = removeSpace(strSubLine); tmpAtomObj.setCharge( (delphi_real)atof(strSubLine.c_str()) ); strSubLine = strLine.substr(62,7); strSubLine = removeSpace(strSubLine); tmpAtomObj.setRadius( (delphi_real)atof(strSubLine.c_str()) ); vctapAtomPdb.push_back(tmpAtomObj); vctiAtomMediaNum.push_back(iObjectMediaNum); iAtomIndex += 1; } else continue; } }
void readFASTA( const std::string& inPath, const std::string& outPath, const int maxLength, const int overlapLength) { std::ifstream ifs(inPath.c_str()); std::string buf; std::string label; std::string sequence; while(ifs && std::getline(ifs, buf)) { if(buf.find(">") != std::string::npos) { if(!label.empty()) { splitFASTA(label, sequence, outPath, maxLength, overlapLength); eraseData(label, sequence); } label = buf; } else if(buf.empty()) { if(!label.empty()) { splitFASTA(label, sequence, outPath, maxLength, overlapLength); eraseData(label, sequence); } } else { if(!label.empty()) { removeSpace(buf); sequence += buf; } } } if(ifs.eof()) { if(!label.empty()) { splitFASTA(label, sequence, outPath, maxLength, overlapLength); eraseData(label, sequence); } } }
//-----------------------------------------------------------------------// void CIO::readModFile1(ifstream& ifPdbFileStream) { int iObjectType = 0; // objecttype, 1-sphere, 2-cylinder delphi_real fInDielec = 0.0; // repsintmp string strLine,strSubLine,strHeader,strX,strY,strZ; delphi_integer iObjectIndex = 0,iAtomIndex = 0; ifPdbFileStream.clear(); ifPdbFileStream.seekg(0); // rewind CAtomPdb tmpAtomObj; while (!ifPdbFileStream.eof()) { getline(ifPdbFileStream,strLine); // to ignore possible empty lines strSubLine = removeSpace(strLine); if (0 == strSubLine.compare(0,1,"")) continue; strHeader = strLine.substr(0,6); strHeader = toUpperCase(strHeader); if (0 == strHeader.compare("MEDIA ")) // # of media has been read during first file reading continue; else if (0 == strHeader.compare("OBJECT")) { strSubLine = strLine.substr(7,3); strSubLine = removeSpace(strSubLine); iObjectIndex = atoi( strSubLine.c_str() ); strSubLine = strLine.substr(11,3); strSubLine = removeSpace(strSubLine); iObjectType = atoi( strSubLine.c_str() ); strSubLine = strLine.substr(15,3); strSubLine = removeSpace(strSubLine); iObjectMediaNum = atoi( strSubLine.c_str() ); strSubLine = strLine.substr(19,8); strSubLine = removeSpace(strSubLine); fInDielec = atof( strSubLine.c_str() ); // entries of vctfMediaEps have been initialized to be 1/epkt vctfMediaEps.push_back(fInDielec/fEPKT); if (0 != iObjectType) { bOnlyMolecule = false; // dataobject(iObjectIndex,1) and dataobject(iObjectIndex,2) vctstrObject.push_back(strLine); vctstrObject.push_back(string(" ")); } else { // dataobject(iObjectIndex,1) and dataobject(iObjectIndex,2) vctstrObject.push_back(string("is a molecule 0")); vctstrObject.push_back(string(" ")); prgiObjectMediaNum.push_back(iObjectMediaNum); } } else if (0 == strHeader.compare("CRGDST")) throw CUnsupportedCRGDST(strLine); else if (0 == strHeader.compare("ATOM ") || 0 == strHeader.compare("HETATM")) { tmpAtomObj.setAtInf(strLine.substr(11,15)); strX = strLine.substr(30,8); strX = removeSpace(strX); strY = strLine.substr(38,8); strY = removeSpace(strY); strZ = strLine.substr(46,8); strZ = removeSpace(strZ); tmpAtomObj.setPose( atof(strX.c_str()),atof(strY.c_str()),atof(strZ.c_str()) ); strSubLine = strLine.substr(54,6); strSubLine = removeSpace(strSubLine); tmpAtomObj.setRadius( (delphi_real)atof(strSubLine.c_str()) ); strSubLine = strLine.substr(60,7); strSubLine = removeSpace(strSubLine); tmpAtomObj.setCharge( (delphi_real)atof(strSubLine.c_str()) ); vctapAtomPdb.push_back(tmpAtomObj); vctiAtomMediaNum.push_back(iObjectMediaNum); iAtomIndex += 1; } else continue; } // ---------- end of while (!ifPdbFileStream.eof()) }
//-----------------------------------------------------------------------// // atom(a6),residue(a3),radius(f8.4) or charge(f8.4) // aaaaaarrrfff.ffff void CIO::readFileInNotPKFormat(ifstream& ifFileStream, const int& iFileType) { //getForceFileRecordNum(ifFileStream,iFileType); vector<CForce> * prgaf; // pointer to an array fo CForce if (SIZEFILE == iFileType) { prgaf = &prgas; } else if (CHARGEFILE == iFileType) { prgaf = &prgac; } string strLine, strSubLine; ifFileStream.clear(); ifFileStream.seekg(0); // rewind while (!ifFileStream.eof()) // skip comments and header { getline(ifFileStream,strLine); strSubLine = removeSpace(strLine); if (0 == strSubLine.compare(0,1,"")) continue; // ignore possible empty lines if ('!' != strLine[0]) break; // header } CForce tmpForceObj; while (!ifFileStream.eof()) { getline(ifFileStream, strLine); if ('!' == strLine[0]) continue; // skip commented line // to ignore possible empty lines strSubLine = removeSpace(strLine); if (0 == strSubLine.compare(0,1,"")) continue; strSubLine = strLine.substr(0,6); // atom name, 6 characters if (0 != strSubLine.compare(0,6," ")) { strSubLine = removeSpace(strSubLine); strSubLine = toUpperCase(strSubLine); } else strSubLine = " "; tmpForceObj.setAtom(strSubLine); strSubLine = strLine.substr(6,3); // residue name, 3 characters if (0 != strSubLine.compare(0,3," ")) { strSubLine = removeSpace(strSubLine); strSubLine = toUpperCase(strSubLine); } else strSubLine = " "; tmpForceObj.setResidue(strSubLine); tmpForceObj.setResidueNum(" "); // residue number tmpForceObj.setChain(" "); // subunit name strSubLine = strLine.substr(9,8); // radius or charge strSubLine = removeSpace(strSubLine); tmpForceObj.setValue( atof(strSubLine.c_str()) ); prgaf->push_back(tmpForceObj); } // ---------- end of while (!ifFileStream.eof()) }
void plainconf::parseLine(const char *fileName, int lineNumber, const char *sLine) { const int MAX_NAME_LENGTH = 4096; char name[MAX_NAME_LENGTH] = {0}; char value[MAX_NAME_LENGTH] = {0}; const char *attr = NULL; XmlNode *pNode = NULL; XmlNode *pCurNode = (XmlNode *)gModuleList.back(); const char *p = sLine; const char *pEnd = sLine + strlen(sLine); bool bNameSet = false; for (; p < pEnd; ++p) { //"{" is a beginning of a block only if it is the last char of a line if (*p == '{' && pEnd - p == 1) { if (strlen(name) > 0) { const char *pRealname = getRealName(name); if (pRealname) { pNode = new XmlNode; pNode->init(pRealname, &attr); //Remove space in the end of the value such as "module cache {", value will be "cache" removeSpace(value, 1); if (strlen(value) > 0) pNode->setValue(value, strlen(value)); pCurNode->addChild(pNode->getName(), pNode); gModuleList.push_back(pNode); pCurNode = pNode; clearNameAndValue(name, value); break; } else { logToMem(LOG_LEVEL_ERR, "parseline find block name [%s] is NOT keyword in %s:%d", name, fileName, lineNumber); break; } } else { logToMem(LOG_LEVEL_ERR, "parseline found '{' without a block name in %s:%d", fileName, lineNumber); break; } } else if (*p == '}' && p == sLine) { if (gModuleList.size() > 1) { gModuleList.pop_back(); clearNameAndValue(name, value); if (*(p + 1)) { ++p; trimWhiteSpace(&p); parseLine(fileName, lineNumber, p); break; } } else { logToMem(LOG_LEVEL_ERR, "parseline found more '}' in %s:%d", fileName, lineNumber); clearNameAndValue(name, value); break; } } else if ((*p == ' ' || *p == '\t') && value[0] == 0) { bNameSet = true; continue; } else { if (!bNameSet) strcatchr(name, *p, MAX_NAME_LENGTH); else strcatchr(value, *p, MAX_NAME_LENGTH); } } if (name[0] != 0) { const char *pRealname = getRealName(name); if (pRealname) { assert(pNode == NULL); pNode = new XmlNode; pNode->init(pRealname, &attr); if (strlen(value) > 0) pNode->setValue(value, strlen(value)); pCurNode->addChild(pNode->getName(), pNode); } else { //There is no special case in server level //if (memcmp(pCurNode->getName(), SERVER_ROOT_XML_NAME, sizeof(SERVER_ROOT_XML_NAME) - 1) != 0) saveUnknownItems(fileName, lineNumber, pCurNode, name, value); //else // logToMem(LOG_LEVEL_ERR, "%s Server level find unknown keyword [%s], ignored.", SERVER_ROOT_XML_NAME, name ); } } }
//This function may be recruse called void plainconf::loadConfFile(const char *path) { logToMem(LOG_LEVEL_INFO, "start parsing file %s", path); int type = checkFiletype(path); if (type == 0) return; else if (type == 2) loadDirectory(path, NULL); else if (type == 3) { AutoStr2 prefixPath = path; const char *p = strrchr(path, '/'); if (p) prefixPath.setStr(path, p - path); struct stat sb; //removed the wildchar filename, should be a directory if exist if (stat(prefixPath.c_str(), &sb) == -1) { logToMem(LOG_LEVEL_ERR, "LoadConfFile error 1, path:%s directory:%s", path, prefixPath.c_str()); return ; } if ((sb.st_mode & S_IFMT) != S_IFDIR) { logToMem(LOG_LEVEL_ERR, "LoadConfFile error 2, path:%s directory:%s", path, prefixPath.c_str()); return ; } loadDirectory(prefixPath.c_str(), p + 1); } else //existed file { //gModuleList.push_back(); //XmlNode *xmlNode = new XmlNode; FILE *fp = fopen(path, "r"); if (fp == NULL) { logToMem(LOG_LEVEL_ERR, "Cannot open configuration file: %s", path); return; } const int MAX_LINE_LENGTH = 8192; char sLine[MAX_LINE_LENGTH]; char *p; char sLines[MAX_LINE_LENGTH] = {0}; int lineNumber = 0; const int MAX_MULLINE_SIGN_LENGTH = 128; char sMultiLineModeSign[MAX_MULLINE_SIGN_LENGTH] = {0}; size_t nMultiLineModeSignLen = 0; //>0 is mulline mode while (fgets(sLine, MAX_LINE_LENGTH, fp), !feof(fp)) { ++lineNumber; p = sLine; if (nMultiLineModeSignLen) { //Check if reach the END of the milline mode size_t len = 0; const char *pLineStart = getStrNoSpace(p, len); if (len == nMultiLineModeSignLen && strncasecmp(pLineStart, sMultiLineModeSign, nMultiLineModeSignLen) == 0) { nMultiLineModeSignLen = 0; removeSpace(sLines, 1); //Remove the last \r\n so that if it is one line, it will still be one line parseLine(path, lineNumber, sLines); sLines[0] = 0x00; } else strcat(sLines, p); continue; } removeSpace(p, 0); removeSpace(p, 1); if (!isValidline(p)) continue; AutoStr2 pathInclude; if (isInclude(p, pathInclude)) { char achBuf[512] = {0}; getIncludeFile(pathInclude.c_str(), achBuf); loadConfFile(achBuf); } else { nMultiLineModeSignLen = checkMultiLineMode(p, sMultiLineModeSign, MAX_MULLINE_SIGN_LENGTH); if (nMultiLineModeSignLen > 0) strncat(sLines, p, strlen(p) - (3 + nMultiLineModeSignLen)); //need to continue else if (isChunkedLine(p)) { strncat(sLines, p, strlen(p) - 1); //strcatchr(sLines, ' ', MAX_LINE_LENGTH); //add a space at the end of the line which has a '\\' } else { strcat(sLines, p); parseLine(path, lineNumber, sLines); sLines[0] = 0x00; } } } fclose(fp); //Parsed, check in it checkInFile(path); } }
//-----------------------------------------------------------------------// void CIO::readForceFile(const string & strFile) { ifstream ifFileStream; // open the file with name strParamFile ifFileStream.open(strFile.c_str()); // if the file doesnt exists, exit if (!ifFileStream.is_open()) throw CUnknownIOFile(strFile); string strLine, strSubLine; while (!ifFileStream.eof()) // skip comments and empty lines till the header { getline(ifFileStream,strLine); strSubLine = removeSpace(strLine); if (0 == strSubLine.compare(0,1,"")) continue; // ignore possible empty lines if ('!' != strLine[0]) break; // header } if ( 0 == strLine.find("atom__res_radius") || 0 == strLine.find("atom__resnumbc_radius_") ) cout << "\n" << "atom radii read from file " << strFile << "\n"; else if ( 0 == strLine.find("atom__res_charge") || 0 == strLine.find("atom__resnumbc_charge_") ) cout << "\n" << "atomic charges read from file " << strFile << "\n"; else throw CUnknownForceFileHeader(strFile,strLine); ifFileStream.clear(); ifFileStream.seekg(0); // rewind while (!ifFileStream.eof()) // skip and print comments (start with !) till the header { getline(ifFileStream,strLine); strSubLine = removeSpace(strLine); if (0 == strSubLine.compare(0,1,"")) continue; // ignore possible empty lines if ('!' != strLine[0]) break; // header cout << strLine << endl; // print comments } // determine file format // isPK = false: // atom(a6),residue(a3),radius(f8.4): aaaaaarrrfff.ffff // isPK = true: // atom(a6),residue(a3),residue_number(a4),subunit(a1),radius(f8.4): // aaaaaarrrnnnncfff.ffff if (0 == strLine.find("atom__res_radius") || 0 == strLine.find("atom__resnumbc_radius_")) { if (0 == strLine.find("atom__res_radius")) { readFileInNotPKFormat(ifFileStream,SIZEFILE); #ifdef DEBUG_IO_SIZE printForce(SIZEFILE); #endif } else if (0 == strLine.find("atom__resnumbc_radius_")) { cout << "reading pK style radius file \n"; readFileInPKFormat(ifFileStream,SIZEFILE); #ifdef DEBUG_IO_SIZE printForce(SIZEFILE); #endif } iRadiusNum = prgas.size(); // # of entries in radius file cout << "# of radius parameter records: \t\t" << iRadiusNum << "\n"; } else // 0 == strLine.find("atom__res_charge") || // 0 == strLine.find("atom__resnumbc_charge_") { if (0 == strLine.find("atom__res_charge")) { readFileInNotPKFormat(ifFileStream,CHARGEFILE); #ifdef DEBUG_IO_CHARGE printForce(CHARGEFILE); #endif } else if (0 == strLine.find("atom__resnumbc_charge_")) { cout << "reading pK style charge file \n"; readFileInPKFormat(ifFileStream,CHARGEFILE); #ifdef DEBUG_IO_CHARGE printForce(CHARGEFILE); #endif } iCrgNum = prgac.size(); // # of entries in charge file cout << "# of charge parameter records: \t\t" << iCrgNum << "\n"; } ifFileStream.close(); }
void CIO::readPdbFile(const string& strPdbFile, const int& iPdbFormat, const bool& bPdbUnformatIn, const vector<string>& strCommPDB) { if (CommPDB == iPdbFormat) { bExistRadiiInfo = true; bool bPostProcess = true; vctfMediaEps.push_back(0.0); // medeps(0) commVecPDB(strCommPDB); iAtomNum = vctapAtomPdb.size(); if (bPostProcess) { if (0 == vctfMediaEps.size()) vctfMediaEps.push_back(0.0); // medeps(0) cout << "You are not reading from an object file! \n"; cout << "Assuming having only molecules, and one medium \n"; vctfMediaEps.push_back(fDielec/fEPKT); // medeps(1)=repsin/epkt // dataobject(1,1) and dataobject(1,2) vctstrObject.push_back(string("is a molecule 0")); vctstrObject.push_back(string(" ")); prgiObjectMediaNum.push_back(iObjectMediaNum); } iObjectNum = vctstrObject.size()/2; iMediaNum = vctfMediaEps.size()-1; // regardless of being a molecule or not, iatmmed has a field to say which is its medium if (0 != prgiObjectMediaNum.size()) { for (unsigned i=0; i < prgiObjectMediaNum.size(); i++) vctiAtomMediaNum.push_back(prgiObjectMediaNum[i]); prgiObjectMediaNum.clear(); } } else { bExistRadiiInfo = false; // iatrad, whether there is radius info ifstream ifPdbFileStream; ifPdbFileStream.open(strPdbFile.c_str()); if (!ifPdbFileStream.is_open()) throw CUnknownIOFile(strPdbFile); bool bPostProcess = true; int iFormatID = 0; // idfrm if(!bPdbUnformatIn) // ---------- formatted pdb file ---------- // { string strLine, strSubLine, strHeader; cout << "\nopening formatted file: " << strPdbFile << endl; // Now only delphi mod type pdb files have keyword "DELPHI PDB", other pdb files // such as standard, mod4 and pqr pdb files do not check the keyword any more if (MODPDB == iPdbFormat) // mod pdb file { getline(ifPdbFileStream,strLine); // read the 1st line string strHeadFirst = strLine.substr(0,6); strHeadFirst = removeSpace(strHeadFirst); strHeadFirst = toUpperCase(strHeadFirst); if (0 == strHeadFirst.compare(0,5,"MEDIA")) bPostProcess = false; if (string::npos != strLine.find("DELPHI")) // find keyword "DELPHI" { if (string::npos == strLine.find("PDB")) // no keyword "PDB" is found throw CUnknownDelphiPdb(strPdbFile); cout << "Reading a Delphi-style pdb file \n"; getline(ifPdbFileStream,strLine); // read the 2nd line size_t found = strLine.find_first_of('='); strSubLine = strLine.substr(found+1,strLine.size()-found-1); strSubLine = removeSpace(strSubLine); iFormatID = atoi(strSubLine.c_str()); cout << "Read Delphi Format Number = " << iFormatID << endl; if (1 != iFormatID && 4 != iFormatID) throw CUnknownModPdb(strPdbFile,iFormatID); } } else { ifPdbFileStream.clear(); ifPdbFileStream.seekg(0); // rewind cout << "No DELPHI keyword, assuming Delphi Format number = " << iFormatID << endl; } if (STDPDB == iPdbFormat) bExistRadiiInfo = false; // standard pdb else bExistRadiiInfo = true; // others // medeps(0:nmediamax) vctfMediaEps.push_back(0.0); // medeps(0) switch (iPdbFormat) { case STDPDB: // standard pdb readStdPdbFile(ifPdbFileStream); break; case MODPDB: // mod pdb if (1 == iFormatID) readModFile1(ifPdbFileStream); else readModFile4(ifPdbFileStream); // 4 == iFormatID break; case PQRPDB: // pqr pdb readPqrFile(ifPdbFileStream); break; case MOD4PDB: // mod4 pdb readMod4File(ifPdbFileStream); break; case PQR4PDB: // pqr4 pdb readPqr4File(ifPdbFileStream); break; } iAtomNum = vctapAtomPdb.size(); cout << "number of atoms read in = " << iAtomNum << " formatted \n"; } else // ---------- unformatted pdb file ---------- // { int iUnformatID = 0; // idfrm char cLine[80]; // line bExistRadiiInfo = true; ifPdbFileStream.read(cLine,80); // header string strHeader(cLine); // string to be converted from cLine for simpler manipulation if (string::npos != strHeader.find("DELPHI")) // find keyword "DELPHI" { if (string::npos == strHeader.find("PDB")) // no keyword "PDB" is found throw CUnknownDelphiPdb(strPdbFile); cout << "Reading a Delphi-style pdb file \n"; } ifPdbFileStream.read( reinterpret_cast<char*>(&iUnformatID), sizeof(int) ); // idfrm if (0 != iUnformatID && 1 != iUnformatID) throw CUnknownUnformattedPdb(strPdbFile); readUnformattedPdb(strPdbFile,ifPdbFileStream,bPostProcess); } #ifdef DEBUG_IO_PDB printPDB(); #endif // Some post-processing if (bPostProcess) { if (0 == vctfMediaEps.size()) vctfMediaEps.push_back(0.0); // medeps(0) cout << "You are not reading from an object file! \n"; cout << "Assuming having only molecules, and one medium \n"; vctfMediaEps.push_back(fDielec/fEPKT); // medeps(1)=repsin/epkt // dataobject(1,1) and dataobject(1,2) vctstrObject.push_back(string("is a molecule 0")); vctstrObject.push_back(string(" ")); prgiObjectMediaNum.push_back(iObjectMediaNum); } iObjectNum = vctstrObject.size()/2; iMediaNum = vctfMediaEps.size()-1; // regardless of being a molecule or not, iatmmed has a field to say which is its medium if (0 != prgiObjectMediaNum.size()) { for (unsigned i=0; i < prgiObjectMediaNum.size(); i++) vctiAtomMediaNum.push_back(prgiObjectMediaNum[i]); prgiObjectMediaNum.clear(); } ifPdbFileStream.close(); } }
void CSite::writeSite(const int& iisitsf) { //---------------------------------------------------------------------------------------------// bool isita = bAtomInSite, isiti = bSaltInSite, isitmd = bMDInSite, isitpot = bPotentialInSite, isitx = bAtomCoordInSite, isitq = bCrgInSite, isitf = bFieldInSite, isitp = bGridPotentialInSite, isitr = bReactPotentialInSite, isitc = bCoulombPotentialInSite, isitap = bAtomPotentialInSite, isitdeb = bDebyeFractionInSite, isitsf = bSurfCrgInSite, isittf = bTotalForceInSite, isitrf = bReactForceInSite, isitt = bTotalPotentialInSite, isitcf = bCoulombForceInSite, iself = bPDB2FRCInSite; //----- ifrm is true if ANY of the flags for special output have been set bool ifrm = isita || isitq || isitp || isitf || isitr || isitt || isitc || isitx || isiti || isitrf || isitcf || isitap || isittf || isitdeb; bool isitmp1 = ifrm; ifrm = ifrm || isitsf; bool ofrm = true; if (isitmd || isitpot) {iFrcFormatOut = -1; ofrm = false;} if (!ifrm && (0 == iFrcFormatOut || 3 == iFrcFormatOut)) { isitx = true; isitq = true; isitf = true; isitp = true; } switch (iFrcFormatOut) { case 1: isitx = true; isitq = true; isitr = true; isitc = true; break; case 2: isitx = true; isitq = true; isitr = true; break; case 3: ofrm = false; break; } string vrow(80,' '),datum(65,' '); int j = 0, k = 0; if (isita) { vrow.replace(j,15,"ATOM DESCRIPTOR"); datum.replace(k,5,"ATOM "); j += 20; k += 5; } if (isitx) { vrow.replace(j+4,24,"ATOM COORDINATES (X,Y,Z)"); datum.replace(k,12,"COORDINATES "); j += 30; k += 12; } if (isitq) { vrow.replace(j+3,6,"CHARGE"); datum.replace(k,7,"CHARGE "); j += 10; k += 7; } if (isitp) { vrow.replace(j+2,8,"GRID PT."); datum.replace(k,11,"POTENTIALS "); j += 10; k += 11; } if (isiti) { vrow.replace(j+1,8,"SALT CON"); datum.replace(k,5,"SALT "); j += 10; k += 5; } if (80 <= j) { isitr = false; isitc = false; isitap = false; isitdeb = false; isitf = false; isitsf = false; isittf = false; isitrf = false; isitcf = false; isitt = false; } if (isitr) { vrow.replace(j,10," REAC. PT."); datum.replace(k,9,"REACTION "); j += 10; k += 9; } if (80 <= j) { isitc = false; isitap = false; isitdeb = false; isitf = false; isitsf = false; isittf = false; isitrf = false; isitcf = false; isitt = false; } if (isitc) { vrow.replace(j,10," COUL. POT"); datum.replace(k,10,"COULOMBIC "); j += 10; k += 10; } if (80 <= j) { isitap = false; isitdeb = false; isitf = false; isitsf = false; isittf = false; isitrf = false; isitcf = false; isitt = false; } if (isitap) { vrow.replace(j+2,8,"ATOM PT."); datum.replace(k,11,"ATOMIC PT. "); j += 10; k += 11; } if (80 <= j) { isitdeb = false; isitf = false; isitsf = false; isittf = false; isitrf = false; isitcf = false; isitt = false; } if (isitdeb) { vrow.replace(j+3,11,"DEBFRACTION"); datum.replace(k,12,"DEBFRACTION "); j += 14; k += 12; } if (60 <= j) { isitf = false; isitsf = false; isittf = false; isitrf = false; isitcf = false; isitt = false; } if (isitf) { vrow.replace(j+4,25,"GRID FIELDS: (Ex, Ey, Ez)"); datum.replace(k,7,"FIELDS "); j += 30; } if (60 <= j) { isitsf = false; isittf = false; isitrf = false; isitcf = false; isitt = false; } if (isitrf) { vrow.replace(j+4,25,"REAC. FORCE: (Rx, Ry, Rz)"); datum.replace(k,7,"RFORCE "); j += 30; } if (60 <= j) { isitsf = false; isittf = false; isitcf = false; isitt = false; } if (isitcf) { vrow.replace(j+4,25,"COUL. FORCE: (Cx, Cy, Cz)"); datum.replace(k,7,"CFORCE "); j += 30; } if (60 <= j) { isitsf = false; isittf = false; isitt = false; } if (isittf) { vrow.replace(j+4,25,"TOTAL FORCE: (Tx, Ty, Tz)"); datum.replace(k,7,"TFORCE "); j += 30; } if (70 <= j) { isitt = false; } if (isitt) { vrow.replace(j+4,6," TOTAL"); datum.replace(k,6,"TOTAL "); j += 10; } if (50 <= j) isitsf = false; if (isitsf) { vrow.replace(j+4,65,"sCharge, x y z urf.E°n,surf. E[kT/(qA)]"); datum.replace(k,35,"SCh, x, y, z, surf En, surf. E"); j += 50; } //---------------------------------------------------------------------------------------------// /* * if site potentials required and unformatted read/write, skip during formatted frc file read/write can write unformatted frc.pdb */ bool ifrm2 = false, iqass = true; ifstream ifFileStream; vector<bool> residsf(iResidueNum,false); if (!(isitmd || isitpot)) cout << "\nwriting potentials at given sites...\n"; if (iself) { cout << "using the current pdb file\n"; ifrm2 = true; iqass = false; } else { if (!isitpot) { ifFileStream.open(strFrciFile.c_str()); // just inquire whether the file exists or not if (!ifFileStream.is_open()) { CUnknownInFrcFile warning(strFrciFile); ifFileStream.close(); return; } else { cout << "coordinates, etc for potential output read from file " << strFrciFile << endl; ifrm2 = checkFileFormat(strFrciFile); } ifFileStream.close(); } } //----- if unformatted may not contain all the info needed for all options, i.e atom info if (!ifrm2 && isita) { CNoAtomInfo warning(strFrciFile); isita = false; iqass = false; } if (!ifrm2) iqass = false; if (!iself && !isitpot) { if (ifrm2) ifFileStream.open(strFrciFile.c_str()); else ifFileStream.open(strFrciFile.c_str(),ios::binary); if (!ifFileStream.is_open()) CUnknownInFrcFile warning(strFrciFile); } if (isitsf) //----- isitsf assumes ifrm2=.true. { ifstream ifFileStream15; string strLine,strHead; int iresnum; ifFileStream15.open(strFrciFile.c_str()); // just inquire whether the file exists or not if (!ifFileStream15.is_open()) { CUnknownInFrcFile warning(strFrciFile); } else { cout << "coordinates, etc for potential output read from file " << strFrciFile << endl; while (!ifFileStream15.eof()) // loop D302 { getline(ifFileStream15,strLine); strHead = strLine.substr(0,6); if (0 != strHead.compare(" ")) strHead = toUpperCase(strHead); if (0 != strHead.compare("ATOM ") && 0 != strHead.compare("HETATM")) continue; iresnum = atoi(strLine.substr(23,4).c_str()); residsf[iresnum-1] = true; } } ifFileStream15.close(); } //---------------------------------------------------------------------------------------------// ofstream ofFileStream; if (ofrm) ofFileStream.open(strFrcFile.c_str()); if(!(ofrm || isitmd || isitpot)) ofFileStream.open(strFrcFile.c_str(),ios::binary); if (!isitmd && !isitpot) cout << "potentials written to file " << strFrcFile << endl << endl; if (ofrm) { ofFileStream << "DELPHI SITE POTENTIAL FILE\n"; ofFileStream << "grid size,percent fill: " << iGrid << " " << fPercentageFill << endl; ofFileStream << "outer diel. and first one assigned : " << fExDielec << " " << vctfMediaEps[1]*fEPKT << endl; ofFileStream << "ionic strength (M): " << fIonStrength << endl; ofFileStream << "ion excl., probe radii: " << fIonRadius << " " << rgfProbeRadius[0] << " " << rgfProbeRadius[1] << endl; ofFileStream << "linear, nolinear iterations: " << iLinIterateNum << " " << iNonIterateNum << endl; ofFileStream << "boundary condition: " << iBndyType << endl; ofFileStream << "Data Output: " << datum << endl; ofFileStream << "title: " << rgcFileMap << endl; ofFileStream << "\n\n"; ofFileStream << vrow << endl; } if (!ofrm && (!(isitmd || isitpot))) { ofFileStream << fixed << setprecision(4); string strLine; strLine = "DELPHI FRC FILE"; ofFileStream << strLine << endl; strLine = "FORMAT NUMBER=1"; ofFileStream << strLine << endl; strLine = "DATA="; strLine.append(datum); ofFileStream << strLine << endl; ofFileStream << setw(5) << right << iGrid << setw(10) << right << fPercentageFill << setw(10) << right << fExDielec << setw(10) << right << fIonStrength << endl; for (int i = 1; i <= iMediaNum; i++) ofFileStream << "dielectric in medium nr. " << i << ": " << vctfMediaEps[i]*fEPKT << endl; ofFileStream << setw(10) << right << fIonRadius << setw(10) << right << rgfProbeRadius[0] << setw(10) << right << rgfProbeRadius[1] << setw(5) << right << iLinIterateNum << setw(5) << right << iNonIterateNum << setw(5) << right << iBndyType << endl; ofFileStream.unsetf(ios_base::floatfield); } if (!iself && (isitrf || isitmd || isittf)) { CCalcReactForceError warning; isitrf = false; isittf = false; isitmd = false; } vector< SGrid<real> > rfield; if (isitrf || isitmd || isittf) { if (1 == iMediaNum && fZero > abs(vctfMediaEps[1]*fEPKT-1.0)) rfield = rforceeps1(); else rfield = rforce(); } //---------------------------------------------------------------------------------------------// integer nnatom,inum,ncrgs; SGrid<real> cxyz = {0.0,0.0,0.0},xo,xn,fu,fl,xo2,fxyz,vtemp,xu2,xu,rxyz; real chrgv,radu,goff,vphi,aphi,etot,phiv,temp,phii,debyefraction,phirt,phict,phir,phias,tcrgs,dist,phirtt,crgs,phiat,phic,phiac,eps,phiact,phit; real sdist,ff,fn; string atm,res,rnum,chn,crdstr,atnum,atdes(16,' '),strLine,strHead; bool isitmp; int iFound,iresnum,idist,ncrg,jtmp; vector<bool> atmsf(iAtomNum*iisitsf,false); vector<real> sold,scomp; char otemp[10]; string oline(80,' '); nnatom = 0; chrgv = 0.0; goff = ((real)iGrid+1.0)/2.0; etot = 0.0; phirt = 0.0; phict =0.0; if (isitpot) { CSitePhiError warning; } else { do // beginning of the big loop on natom { if(iself) { if (iAtomNum == nnatom) break; xo = prgfgAtomCoordA[nnatom]; chrgv = vctapAtomPdb[nnatom].getCharge(); radu = vctapAtomPdb[nnatom].getRadius()*fScale; atm = vctapAtomPdb[nnatom].getAtInf().substr(0,4); res = vctapAtomPdb[nnatom].getAtInf().substr(6,3); rnum = vctapAtomPdb[nnatom].getAtInf().substr(11,4); chn = vctapAtomPdb[nnatom].getAtInf().substr(10,1); } else { //if (!ifFileStream.is_open()) break; if(ifrm2) // formatted reading { getline(ifFileStream,strLine); if (ifFileStream.eof()) break; strHead = strLine.substr(0,6); strHead = toUpperCase(strHead); if (0 != strHead.compare("ATOM ") && 0 != strHead.compare("HETATM")) continue; crdstr = strLine.substr(30,24); atnum = strLine.substr(6,5); xo.nX = atof(crdstr.substr(0,8).c_str()); xo.nY = atof(crdstr.substr(8,8).c_str()); xo.nZ = atof(crdstr.substr(16,8).c_str()); inum = atoi(atnum.c_str()); } else // unformatted (binary) reading { ifFileStream.read( reinterpret_cast<char*>(&xo.nX),sizeof(real) ); ifFileStream.read( reinterpret_cast<char*>(&xo.nY),sizeof(real) ); ifFileStream.read( reinterpret_cast<char*>(&xo.nZ),sizeof(real) ); ifFileStream.read( reinterpret_cast<char*>(&radu), sizeof(real) ); ifFileStream.read( reinterpret_cast<char*>(&chrgv),sizeof(real) ); } } //----- end of atom reading nnatom++; isitmp = (isitq && iqass) || isitap || isitp; if((isita || isitmp) && !iself) { atm = strLine.substr(11,5); res = strLine.substr(17,3); rnum = strLine.substr(22,4); chn = strLine.substr(21,1); if (0 != atm.compare(" ")) {atm = removeSpace(atm); atm = toUpperCase(atm);} if (0 != res.compare(" ")) {res = removeSpace(res); res = toUpperCase(res);} if (0 != rnum.compare(" ")) {rnum = removeSpace(rnum); rnum = toUpperCase(rnum);} if (0 != chn.compare(" ")) {chn = removeSpace(chn); chn = toUpperCase(chn);} } xn = (xo-fgBoxCenter)*fScale+goff; // scale atoms to grid space if (isita) { atdes.assign(16,' '); atdes.replace( 0,atm.size(),atm); atdes.replace( 5,res.size(),res); atdes.replace( 9,chn.size(),chn); atdes.replace(11,rnum.size(),rnum); } /* * assign charge to atom, searching for decreasingly specific specification * note if no charge record found, is assumed to be 0.0 */ if(!iself && ifrm2 && isitmp) { chrgv = 0.0; iFound = FindRecord(atm,res,rnum,chn,CHARGEFILE,chrgv); if(isitap) iFound = FindRecord(atm,res,rnum,chn,SIZEFILE,radu); radu = radu*fScale; } if (isitsf) { iresnum = atoi(rnum.c_str()); atmsf[nnatom-1] = false; if (residsf[iresnum-1]) atmsf[nnatom-1] = true; } if(isitap && fZero < abs(chrgv)) { real rads = min(radu,fPotentialUpperBond*fScale); SGrid<real> xt; xt = xn; xt.nX += rads; vphi = interpl(iGrid,phimap,xt); aphi = vphi; xt = xn; xt.nX -= rads; vphi = interpl(iGrid,phimap,xt); aphi += vphi; xt = xn; xt.nY += rads; vphi = interpl(iGrid,phimap,xt); aphi += vphi; xt = xn; xt.nY -= rads; vphi = interpl(iGrid,phimap,xt); aphi += vphi; xt = xn; xt.nZ += rads; vphi = interpl(iGrid,phimap,xt); aphi += vphi; xt = xn; xt.nZ -= rads; vphi = interpl(iGrid,phimap,xt); aphi += vphi; aphi = aphi/6.0; } if (isitp || isiti || (isitap && fZero > abs(chrgv))) { vphi = interpl(iGrid,phimap,xn); if (isitap && fZero > abs(chrgv)) aphi = vphi; if (isitp) { etot += chrgv*vphi; phiv = vphi; } if (isiti) { CNoIDebMap warning; /* * we have changed the iconc action so that the phimap has NOT been converted to salt concentrations. therefore */ if (0 != iNonIterateNum) { temp = vphi*fTaylorCoeff5+fTaylorCoeff4; temp = vphi*temp+fTaylorCoeff3; temp = vphi*temp+fTaylorCoeff2; temp = vphi*temp+fTaylorCoeff1; phii = vphi*temp; } else phii = -fIonStrength*2.0*vphi; } } //----- end if isitp or isiti, salt and or potentials if (isitdeb) // it calculates the fraction of closest grid points that are in solution { cout << "Calculating Debye Fraction\n"; debyefraction = boolinterpl(iGrid,prgbDielecMap,xn); } if (isitf) { xn.nX += 1.0; fu.nX = interpl(iGrid,phimap,xn); xn.nX -= 2.0; fl.nX = interpl(iGrid,phimap,xn); xn.nX += 1.0; xn.nY += 1.0; fu.nY = interpl(iGrid,phimap,xn); xn.nY -= 2.0; fl.nY = interpl(iGrid,phimap,xn); xn.nY += 1.0; xn.nZ += 1.0; fu.nZ = interpl(iGrid,phimap,xn); xn.nZ -= 2.0; fl.nZ = interpl(iGrid,phimap,xn); xn.nZ += 1.0; fxyz = (fl-fu)*0.5*fScale; // the electric field is opposite the potential gradient so I change the sign } /* * check if this point is within the box. */ if (isitt) { SExtrema<real> bedge; bedge.nMin = fgBoxCenter-0.5*(iGrid-1)/fScale; bedge.nMax = fgBoxCenter+0.5*(iGrid-1)/fScale; int it = 0; if ( optORLT<real>(xo,bedge.nMin) || optORGT<real>(xo,bedge.nMax) ) it = 1; if (0 == it) { xo2 = (xo-fgBoxCenter)*fScale+goff; /* * first find reaction field from surface elements inside of the box.. */ phir=0.0; phias=0.0; ncrgs=0; tcrgs=0.0; sold.assign(30,0.0); for (integer i = 0; i < iDielecBndySum; i++) { vtemp = xo - prgfgSurfCrgA[i]; dist = sqrt(optDot(vtemp,vtemp)); //----- first find reaction field from surface elements inside of the box ncrgs++; tcrgs += prgfSurfCrgE[i]; phirtt = prgfSurfCrgE[i]/dist; //----- medeps either epsin contain the 561.0 factor.... phirtt = phirtt*fEPKT; phir += phirtt; xu2.nX = (real)prgigBndyGrid[i].nX; xu2.nY = (real)prgigBndyGrid[i].nY; xu2.nZ = (real)prgigBndyGrid[i].nZ; crgs = prgfSurfCrgE[i]; //----- took place of repsin because eps is no more included in schrg , surface charge phiat = tops(xu2,xo2,crgs,1.0,1); phiat = phiat*2.0; phias += phiat; idist = (int)dist; sold[idist] += phiat - phirtt; } temp = 0.0; cout << "Writing sold(1:30) and temp \n"; for (integer i = 0; i < 30; i++) { temp += sold[i]; cout << sold[i] << " " << temp; } cout << endl; /* * next find the colombic potential for that site from charges within the box */ phic = 0.0; phiac = 0.0; ncrg = 0; for (integer i = 0; i < iCrgGridNum; i++) { it = 0; if (optORLT<real>(prgfgCrgPoseA[i],bedge.nMin) || optORGT<real>(prgfgCrgPoseA[i],bedge.nMax)) it = 1; if (0 == it) { ncrg++; vtemp = xo - prgfgCrgPoseA[i]; dist = sqrt(optDot(vtemp,vtemp)); if (5.0 > dist) { if (fZero < dist) {temp = prggvAtomicCrg[i].nValue/dist; phic += temp/prgfAtomEps[i];} //----- find analytic potential from this real charge..=phiac xu = prgfgCrgPoseA[i]; crgs = prggvAtomicCrg[i].nValue; xu2 = (xu-fgBoxCenter)*fScale+goff; eps = prgfAtomEps[i]*fEPKT; phiact = tops(xu2,xo2,crgs,eps,1); phiac += phiact; } } } /* * medeps, either epsin contain the 561.0 factor.... */ phiac = phiac*2.0; /* * find the grid potentials.. */ phiv = interpl(iGrid,phimap,xn); string strFileName7 = "extra.dat"; ofstream ofFileSteam7; ofFileSteam7.open(strFileName7.c_str()); ofFileSteam7 << phic << " " << phir << " " << phiv << " " << phias << " " << phiac << " "<< ncrg << " " << ncrgs << " " << tcrgs << endl; ofFileSteam7.close(); phit = phic + phir + phiv - phias - phiac; } else phit = 0.0; /* * phit contains the total corrected potential */ } if (isitr) { scomp.assign(30,0.0); sold.assign(30,0.0); phir = 0.0; for (integer i = 0; i < iDielecBndySum; i++) { vtemp = xo - prgfgSurfCrgA[i]; dist = sqrt(optDot(vtemp,vtemp)); idist = (int)dist; if (30 > idist) sold[idist] += fEPKT*prgfSurfCrgE[i]/dist; phir += prgfSurfCrgE[i]/dist; } /* * medeps either epsin contains the 561.0 factor.... */ phir = phir*fEPKT; for (integer i = 0; i < 30; i++) { if (0 == i) scomp[i] = sold[i]; if (0 != i) scomp[i] = scomp[i-1]+sold[i]; } phirt += phir*chrgv; } /* * medeps either epsin contains the 561.0 factor.... */ if (isitrf || isitmd || isittf) rxyz = rfield[nnatom-1]*fEPKT; if(isitcf || isitmd || isittf) { cxyz.nX = 0.0; cxyz.nY = 0.0; cxyz.nZ = 0.0; if (fZero < abs(chrgv)) { for (integer i = 0; i < iCrgGridNum; i++) { vtemp = xo - prgfgCrgPoseA[i]; dist = optDot(vtemp,vtemp); if (fZero < dist) { sdist = sqrt(dist)*dist; temp = prggvAtomicCrg[i].nValue/(prgfAtomEps[i]*sdist); cxyz = cxyz + vtemp*temp; } } /* * atmeps and medeps and epsin contain the 561.0 factor.... */ cxyz = cxyz*chrgv; } } if (isitc) { phic = 0.0; for (integer i = 0; i < iCrgGridNum; i++) { vtemp = xo - prgfgCrgPoseA[i]; dist = optDot(vtemp,vtemp); if (fZero < dist) { sdist = sqrt(dist); temp = prggvAtomicCrg[i].nValue/sdist; phic += temp/prgfAtomEps[i]; } } /* * atmeps and medeps and epsin contain the 561.0 factor.... */ phict += phic*chrgv; } //---------------------------------------------------------------------------------------// /* * write out calculated/assigned charges * * need otemp cos can not write into a substring apparently * otemp needs to be at least 15 long to avoid an error!! */ oline.assign(80,' '); // reset oline j = 0; if (isita) { oline.replace(j,16,atdes.substr(0,16)); j += 20; } if (isitx) { sprintf(otemp,"%10.4f",xo.nX); oline.replace(j,10,otemp); j += 10; sprintf(otemp,"%10.4f",xo.nY); oline.replace(j,10,otemp); j += 10; sprintf(otemp,"%10.4f",xo.nZ); oline.replace(j,10,otemp); j += 10; } if (isitq) { sprintf(otemp,"%10.4f",chrgv); oline.replace(j,10,otemp); j += 10; } if (isitp) { sprintf(otemp,"%10.4f",phiv); oline.replace(j,10,otemp); j += 10; #ifdef MCCE mcce_phiv.push_back(phiv); #endif } if (isiti) { sprintf(otemp,"%10.4f",phii); oline.replace(j,10,otemp); j += 10; } if (isitr) { sprintf(otemp,"%10.4f",phir); oline.replace(j,10,otemp); j += 10; } if (isitc) { sprintf(otemp,"%10.4f",phic); oline.replace(j,10,otemp); j += 10; } if (isitap) { sprintf(otemp,"%10.4f",aphi); oline.replace(j,10,otemp); j += 10; } if (isitdeb) { sprintf(otemp,"%10.4f",debyefraction); oline.replace(j,10,otemp); j += 10; } if (isitf) { sprintf(otemp,"%10.4f",fxyz.nX); oline.replace(j,10,otemp); j += 10; sprintf(otemp,"%10.4f",fxyz.nY); oline.replace(j,10,otemp); j += 10; sprintf(otemp,"%10.4f",fxyz.nZ); oline.replace(j,10,otemp); j += 10; } if (isitrf) { sprintf(otemp,"%10.4f",rxyz.nX); oline.replace(j,10,otemp); j += 10; sprintf(otemp,"%10.4f",rxyz.nY); oline.replace(j,10,otemp); j += 10; sprintf(otemp,"%10.4f",rxyz.nZ); oline.replace(j,10,otemp); j += 10; } if (isitcf) { sprintf(otemp,"%10.4f",cxyz.nX); oline.replace(j,10,otemp); j += 10; sprintf(otemp,"%10.4f",cxyz.nY); oline.replace(j,10,otemp); j += 10; sprintf(otemp,"%10.4f",cxyz.nZ); oline.replace(j,10,otemp); j += 10; } if (isittf) { vtemp = rxyz + cxyz; sprintf(otemp,"%10.4f",vtemp.nX); oline.replace(j,10,otemp); j += 10; sprintf(otemp,"%10.4f",vtemp.nY); oline.replace(j,10,otemp); j += 10; sprintf(otemp,"%10.4f",vtemp.nZ); oline.replace(j,10,otemp); j += 10; } if (isitmd) { vtemp = rxyz + cxyz; cout << "atom: " << nnatom << " rx= " << rxyz.nX << " cx= " << cxyz.nX << " tx= " << vtemp.nX << endl; cout << "atom: " << nnatom << " ry= " << rxyz.nY << " cy= " << cxyz.nY << " ty= " << vtemp.nY << endl; cout << "atom: " << nnatom << " rz= " << rxyz.nZ << " cz= " << cxyz.nZ << " tz= " << vtemp.nZ << endl; } if (isitt) { sprintf(otemp,"%10.4f",phit); oline.replace(j,10,otemp); j += 10; } if (ofrm && isitmp1) ofFileStream << oline << endl; if (!ofrm && isitmp1) { if (isita) ofFileStream << atdes << endl; if (isitx) ofFileStream << xo << endl; if (isitq) ofFileStream << chrgv << endl; if (isitp) ofFileStream << phiv << endl; if (isiti) ofFileStream << phii << endl; if (isitr) ofFileStream << phir << endl; if (isitc) ofFileStream << phic << endl; if (isitap) ofFileStream << aphi << endl; if (isitf) ofFileStream << fxyz << endl; if (isitrf) ofFileStream << rxyz << endl; if (isitcf) ofFileStream << cxyz << endl; if (isittf) { vtemp = rxyz + cxyz; ofFileStream << vtemp << endl;} } } while(true); // end of the big loop on natom } if (isitsf) { for (integer jj = 0; jj < iBndyGridNum; jj++) { integer i = prgiAtSurf[jj]; if (atmsf[i-1] && (0 < prgiAtNdx[jj])) { /* * if the bgp belongs to the interesting site * attention: using always radprb(1), in some case might be inappropriate */ xo = prgfgSurfCrgA[jj]+rgfProbeRadius[0]*prgfgSurfCrgE[jj]; xn = (xo-fgBoxCenter)*fScale+goff; xn.nX += 1.0; fu.nX = interpl(iGrid,phimap,xn); xn.nX -= 2.0; fu.nX = interpl(iGrid,phimap,xn); xn.nX += 1.0; xn.nY += 1.0; fu.nY = interpl(iGrid,phimap,xn); xn.nY -= 2.0; fu.nY = interpl(iGrid,phimap,xn); xn.nY += 1.0; xn.nZ += 1.0; fu.nZ = interpl(iGrid,phimap,xn); xn.nZ -= 2.0; fu.nZ = interpl(iGrid,phimap,xn); xn.nZ += 1.0; fxyz = fl - fu; fn = 0.5*fScale*(optDot(fxyz,prgfgSurfCrgE[jj])); ff = 0.5*fScale*(optDot(fxyz,fxyz)); if (ofrm) { jtmp = j; sprintf(otemp,"%10.4f",prgfSurfCrgE[jj]); oline.replace(jtmp,10,otemp); jtmp += 10; sprintf(otemp,"%10.4f",xo.nX); oline.replace(jtmp,10,otemp); jtmp += 10; sprintf(otemp,"%10.4f",xo.nY); oline.replace(jtmp,10,otemp); jtmp += 10; sprintf(otemp,"%10.4f",xo.nZ); oline.replace(jtmp,10,otemp); jtmp += 10; sprintf(otemp,"%10.4f",fn); oline.replace(jtmp,10,otemp); jtmp += 10; sprintf(otemp,"%10.4f",ff); oline.replace(jtmp,10,otemp); jtmp += 10; ofFileStream << oline << endl; } if (!ofrm) ofFileStream << prgfSurfCrgE[jj] << " " << fn << endl; } } } if(!iself) ifFileStream.close(); #ifdef VERBOSE cout << "\n number of atom coordinates read : " << nnatom << endl << endl; #endif etot = etot/2.0; if (ofrm) { if (0 == iFrcFormatOut) { ofFileStream << "total energy = " << etot << " kt\n"; if (isitr) ofFileStream << "corrected reaction field energy= " << phirt/2.0 << " kt\n"; if (isitap) ofFileStream << "Atomic potential for charged atoms is averaged over a spherical surface of less than " << fPotentialUpperBond << " A\n"; } if (1 == iFrcFormatOut) { ofFileStream << "corrected reaction field energy= " << phirt/2.0 << " kt\n"; ofFileStream << "total coulombic energy = " << phict/2.0 << " kt\n"; if (isitap) ofFileStream << "Atomic potential for charged atoms is averaged over a spherical surface of less than " << fPotentialUpperBond << " A\n"; } if (2 == iFrcFormatOut) { ofFileStream << "corrected reaction field energy= " << phirt/2.0 << " kt\n"; if (isitap) ofFileStream << "Atomic potential for charged atoms is averaged over a spherical surface of less than " << fPotentialUpperBond << " A\n"; } } /* * end of formatted frc read/write and unformatted frc write * end of unformatted frc.pdb read and frc write */ if (ofFileStream.is_open()) ofFileStream.close(); #ifdef VERBOSE cout << "frc stuff now done at "; pTimer->showTime(); cout << endl; #endif }