MTK++ Latest version: 0.2.0

DivConInterface.h
Go to the documentation of this file.
00001 
00036 #ifndef DIVCONINTERFACE_H
00037 #define DIVCONINTERFACE_H
00038 
00039 #include <iostream>
00040 #include <fstream>
00041 #include <sstream>
00042 #include <vector>
00043 #include <algorithm>
00044 #include <iomanip>
00045 
00046 namespace MTKpp
00047 {
00048 
00049 // ============================================================
00050 // Class : DivConInterface()
00051 // ------------------------------------------------------------
00060 // ============================================================
00061 class DivConInterface
00062 {
00063 public:
00064 
00068     inline DivConInterface() {};
00069 
00073     inline int runDivCon(std::string divConInput) {
00074       std::string DivCon = getenv("DIVCON");
00075 
00076       int iDivCon = -1;
00077       std::string runDivCon = DivCon + " -i " + divConInput;
00078       iDivCon = system(runDivCon.c_str());
00079       if (iDivCon != 0 ) {
00080         std::cout << " DivConInterface:Error executing DivCon for " << divConInput << std::endl;
00081         return 1;
00082       }
00083       else {
00084         std::cout << " DivConInterface:Divcon Successful: " <<  divConInput << std::endl;
00085       }
00086       return 0;
00087     }
00088 
00092     inline int Minimize(std::string hamiltonian, std::string chargeModel,
00093                  std::string optScheme, int maxOpt, collection* pCollection) {
00094       molecule* pMolecule = 0;
00095       dcParser* pDcParser = new dcParser();
00096       pDcParser->setHamiltonian(hamiltonian);
00097       pDcParser->setChargeModel(chargeModel);
00098       pDcParser->setOptimizer(optScheme);
00099       pDcParser->setMaxOpt(maxOpt);
00100       pDcParser->setDirect(1);
00101 
00102       std::vector<molecule*> molList = pCollection->getMoleculeList();
00103       std::string dcFileName = "";
00104       std::string dcOutFileName = "";
00105 
00106       for (unsigned int i = 0; i < molList.size(); i++) {
00107         pMolecule = molList[i];
00108 
00109         if (molList.size() > 1) {
00110           std::stringstream ss1;
00111           ss1 << i+1;
00112           std::string num = ss1.str().c_str(); 
00113           dcFileName = "dcMin_" + num + ".in";
00114           dcOutFileName = "dcMin_" + num + ".out";
00115         }
00116         else {
00117           dcFileName = "dcMin_1.in";
00118         }
00119 
00120         int nAtoms = pMolecule->getNumAtoms();
00121         if (nAtoms == 1) {
00122           pDcParser->setOptimizer("");
00123           pDcParser->setMaxOpt(0);
00124         }
00125         else {
00126           pDcParser->setOptimizer(optScheme);
00127           pDcParser->setMaxOpt(maxOpt);
00128         }
00129 
00130         pMolecule->setTotalCharge(pMolecule->getFormalCharge()); // pMolecule->setTotalCharge(0);
00131         bool success = true;
00132         pDcParser->Write(dcFileName, pMolecule, success);
00133         if (!success) return 1;
00134 
00135         int failure = runDivCon(dcFileName);
00136         if (failure) {
00137           delete pDcParser;
00138           return 1;
00139         }
00140       }
00141 
00142       // - Clean up - //
00143       delete pDcParser;
00144       return 0;
00145     }
00146 
00150     inline int Minimize(std::string hamiltonian, std::string chargeModel,
00151                  std::string optScheme, int maxOpt, molecule* pMolecule, int num = 1) {
00152       dcParser* pDcParser = new dcParser();
00153       pDcParser->setHamiltonian(hamiltonian);
00154       pDcParser->setChargeModel(chargeModel);
00155       pDcParser->setOptimizer(optScheme);
00156       pDcParser->setMaxOpt(maxOpt);
00157       pDcParser->setDirect(1);
00158 
00159       std::string dcFileName = "";
00160       std::string dcOutFileName = "";
00161 
00162       std::stringstream ss1;
00163       ss1 << num;
00164       std::string numStr = ss1.str().c_str(); 
00165       dcFileName = "dcMin_" + numStr + ".in";
00166       dcOutFileName = "dcMin_" + numStr + ".out";
00167 
00168       int nAtoms = pMolecule->getNumAtoms();
00169       if (nAtoms == 1) {
00170         pDcParser->setOptimizer("");
00171         pDcParser->setMaxOpt(0);
00172       }
00173       else {
00174         pDcParser->setOptimizer(optScheme);
00175         pDcParser->setMaxOpt(maxOpt);
00176       }
00177 
00178       pMolecule->setTotalCharge(pMolecule->getFormalCharge()); // pMolecule->setTotalCharge(0);
00179 
00180       bool success = true;
00181       pDcParser->Write(dcFileName, pMolecule, success);
00182       if (!success) return 1;
00183 
00184       int failure = runDivCon(dcFileName);
00185       if (failure) {
00186         delete pDcParser;
00187         return 1;
00188       }
00189 
00190       // - Clean up - //
00191       delete pDcParser;
00192       return 0;
00193     }
00194 
00198     inline int runNMR(std::string hamiltonian, int nuclei, collection* pCollection) {
00199       molecule* pMolecule = 0;
00200       dcParser* pDcParser = new dcParser();
00201       pDcParser->setHamiltonian(hamiltonian);
00202       pDcParser->setDirect(1);
00203       pDcParser->setCalNuc(nuclei);
00204 
00205       std::string dcFileName = "";
00206 
00207       std::vector<molecule*> molList = pCollection->getMoleculeList();
00208 
00209       for (unsigned int i = 0; i < molList.size(); i++) {
00210         pMolecule = molList[i];
00211         std::stringstream ss1;
00212         ss1 << i+1;
00213         std::string i_str = ss1.str().c_str(); 
00214         dcFileName = "dcMin_" + i_str + ".out";
00215 
00216         // test if file is there
00217         std::ifstream inputStream;
00218         inputStream.open(dcFileName.c_str());
00219         if (!inputStream) {
00220           std::cerr << "Error opening DivCon output file, please run minimization first" << std::endl;
00221           return 1;
00222         }
00223 
00224         pDcParser->Read(dcFileName, pMolecule);
00225         std::string dcFileName2 = "dcNmr_" + i_str + ".in";
00226         std::string dcOutFileName = "dcNmr_" + i_str + ".out";
00227 
00228         bool success = true;
00229         pDcParser->Write(dcFileName2, pMolecule, success);
00230         if (!success) return 1;
00231 
00232         int failure = runDivCon(dcFileName2);
00233         if (failure) {
00234           delete pDcParser;
00235           return 1;
00236         }
00237         pDcParser->Read(dcOutFileName, pMolecule);
00238       }
00239 
00240       // - Clean up - //
00241       delete pDcParser;
00242       return 0;
00243     }
00247     inline int runNMR(dcParser* pDcParser, collection* pCollection) {
00248       molecule* pMolecule = 0;
00249       std::string dcFileName = "";
00250 
00251       std::vector<molecule*> molList = pCollection->getMoleculeList();
00252 
00253       for (unsigned int i = 0; i < molList.size(); i++) {
00254         pMolecule = molList[i];
00255         std::stringstream ss1;
00256         ss1 << i+1;
00257         std::string i_str = ss1.str().c_str(); 
00258         dcFileName = "dcMin_" + i_str + ".out";
00259 
00260         // test if file is there
00261         std::ifstream inputStream;
00262         inputStream.open(dcFileName.c_str());
00263         if (!inputStream) {
00264           std::cerr << "Error opening DivCon output file, please run minimization first" << std::endl;
00265           return 1;
00266         }
00267 
00268         pDcParser->Read(dcFileName, pMolecule);
00269         std::string dcFileName2 = "dcNmr_" + i_str + ".in";
00270         std::string dcOutFileName = "dcNmr_" + i_str + ".out";
00271 
00272         bool success = true;
00273         pDcParser->Write(dcFileName2, pMolecule, success);
00274         if (!success) return 1;
00275 
00276         int failure = runDivCon(dcFileName2);
00277         if (failure) {
00278           delete pDcParser;
00279           return 1;
00280         }
00281         pDcParser->Read(dcOutFileName, pMolecule);
00282       }
00283       return 0;
00284     }
00285 
00289     inline int runNMR(std::string hamiltonian, int nuclei, molecule* pMolecule, int n) {
00290       dcParser* pDcParser = new dcParser();
00291       pDcParser->setHamiltonian(hamiltonian);
00292       pDcParser->setDirect(1);
00293       pDcParser->setCalNuc(nuclei);
00294 
00295       std::string dcFileName = "";
00296 
00297       std::stringstream ss1;
00298       ss1 << n;
00299       std::string i_str = ss1.str().c_str(); 
00300       dcFileName = "dcMin_" + i_str + ".out";
00301 
00302       // test if file is there
00303       std::ifstream inputStream;
00304       inputStream.open(dcFileName.c_str());
00305       if (!inputStream) {
00306         std::cerr << "Error opening DivCon output file, please run minimization first" << std::endl;
00307         return 1;
00308       }
00309 
00310       pDcParser->Read(dcFileName, pMolecule);
00311       std::string dcFileName2 = "dcNmr_" + i_str + ".in";
00312       std::string dcOutFileName = "dcNmr_" + i_str + ".out";
00313 
00314       bool success = true;
00315       pDcParser->Write(dcFileName2, pMolecule, success);
00316       if (!success) return 1;
00317 
00318       int failure = runDivCon(dcFileName2);
00319       if (failure) {
00320         delete pDcParser;
00321         return 1;
00322       }
00323       pDcParser->Read(dcOutFileName, pMolecule);
00324 
00325       // - Clean up - //
00326       delete pDcParser;
00327       return 0;
00328     }
00329 
00330 protected:
00331 
00333 };
00334 
00335 } // MTKpp namespace
00336 
00337 #endif // DIVCONINTERFACE_H
00338 

Generated on Fri Dec 23 2011 09:28:49 for MTK++ by Doxygen 1.7.5.1