Changes in src/moleculelist.cpp [274d45:84c494]
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
src/moleculelist.cpp
r274d45 r84c494 12 12 #include "atom.hpp" 13 13 #include "bond.hpp" 14 #include "bondgraph.hpp" 14 15 #include "boundary.hpp" 15 16 #include "config.hpp" … … 23 24 #include "periodentafel.hpp" 24 25 #include "Helpers/Assert.hpp" 26 #include "Matrix.hpp" 27 #include "Box.hpp" 25 28 26 29 #include "Helpers/Assert.hpp" … … 379 382 * bonded to the same atom, then we add for this pair a correction term constructed from a Morse 380 383 * potential function fit to QM calculations with respecting to the interatomic hydrogen distance. 381 * \param *out output stream for debugging 382 * \param *path path to file 383 */ 384 bool MoleculeListClass::AddHydrogenCorrection(char *path) 384 * \param &path path to file 385 */ 386 bool MoleculeListClass::AddHydrogenCorrection(std::string &path) 385 387 { 386 388 bond *Binder = NULL; … … 400 402 // 0a. find dimension of matrices with constants 401 403 line = path; 402 line.append("/");403 line += FRAGMENTPREFIX;404 404 line += "1"; 405 405 line += FITCONSTANTSUFFIX; 406 406 input.open(line.c_str()); 407 if (input == NULL) {407 if (input.fail()) { 408 408 DoLog(1) && (Log() << Verbose(1) << endl << "Unable to open " << line << ", is the directory correct?" << endl); 409 409 return false; … … 569 569 570 570 /** Store force indices, i.e. the connection between the nuclear index in the total molecule config and the respective atom in fragment config. 571 * \param *out output stream for debugging 572 * \param *path path to file 571 * \param &path path to file 573 572 * \param *SortIndex Index to map from the BFS labeling to the sequence how of Ion_Type in the config 574 573 * \return true - file written successfully, false - writing failed 575 574 */ 576 bool MoleculeListClass::StoreForcesFile(char *path, 577 int *SortIndex) 575 bool MoleculeListClass::StoreForcesFile(std::string &path, int *SortIndex) 578 576 { 579 577 bool status = true; 580 ofstream ForcesFile; 581 stringstream line; 578 string filename(path); 579 filename += FORCESFILE; 580 ofstream ForcesFile(filename.c_str()); 582 581 periodentafel *periode=World::getInstance().getPeriode(); 583 582 584 583 // open file for the force factors 585 584 DoLog(1) && (Log() << Verbose(1) << "Saving force factors ... "); 586 line << path << "/" << FRAGMENTPREFIX << FORCESFILE; 587 ForcesFile.open(line.str().c_str(), ios::out); 588 if (ForcesFile != NULL) { 585 if (!ForcesFile.fail()) { 589 586 //Log() << Verbose(1) << "Final AtomicForcesList: "; 590 587 //output << prefix << "Forces" << endl; … … 611 608 } else { 612 609 status = false; 613 DoLog(1) && (Log() << Verbose(1) << "failed to open file " << line.str()<< "." << endl);610 DoLog(1) && (Log() << Verbose(1) << "failed to open file " << filename << "." << endl); 614 611 } 615 612 ForcesFile.close(); … … 620 617 /** Writes a config file for each molecule in the given \a **FragmentList. 621 618 * \param *out output stream for debugging 622 * \param *configuration standard configuration to attach atoms in fragment molecule to.619 * \param &prefix path and prefix to the fragment config files 623 620 * \param *SortIndex Index to map from the BFS labeling to the sequence how of Ion_Type in the config 624 621 * \return true - success (each file was written), false - something went wrong. 625 622 */ 626 bool MoleculeListClass::OutputConfigForListOfFragments( config *configuration, int *SortIndex)623 bool MoleculeListClass::OutputConfigForListOfFragments(std::string &prefix, int *SortIndex) 627 624 { 628 625 ofstream outputFragment; 629 char FragmentName[MAXSTRINGSIZE];626 std::string FragmentName; 630 627 char PathBackup[MAXSTRINGSIZE]; 631 628 bool result = true; … … 636 633 int FragmentCounter = 0; 637 634 ofstream output; 638 double cell_size_backup[6]; 639 double * const cell_size = World::getInstance().getDomain(); 640 641 // backup cell_size 642 for (int i=0;i<6;i++) 643 cell_size_backup[i] = cell_size[i]; 635 Matrix cell_size = World::getInstance().getDomain().getM(); 636 Matrix cell_size_backup = cell_size; 637 644 638 // store the fragments as config and as xyz 645 639 for (MoleculeList::iterator ListRunner = ListOfMolecules.begin(); ListRunner != ListOfMolecules.end(); ListRunner++) { 646 640 // save default path as it is changed for each fragment 647 path = configuration->GetDefaultPath();641 path = World::getInstance().getConfig()->GetDefaultPath(); 648 642 if (path != NULL) 649 643 strcpy(PathBackup, path); … … 658 652 // output xyz file 659 653 FragmentNumber = FixedDigitNumber(ListOfMolecules.size(), FragmentCounter++); 660 sprintf(FragmentName, "%s/%s%s.conf.xyz", configuration->configpath, FRAGMENTPREFIX, FragmentNumber);661 outputFragment.open(FragmentName , ios::out);654 FragmentName = prefix + FragmentNumber + ".conf.xyz"; 655 outputFragment.open(FragmentName.c_str(), ios::out); 662 656 DoLog(2) && (Log() << Verbose(2) << "Saving bond fragment No. " << FragmentNumber << "/" << FragmentCounter - 1 << " as XYZ ..."); 663 657 if ((intermediateResult = (*ListRunner)->OutputXYZ(&outputFragment))) … … 679 673 (*ListRunner)->CenterEdge(&BoxDimension); 680 674 (*ListRunner)->SetBoxDimension(&BoxDimension); // update Box of atoms by boundary 681 int j = -1;682 675 for (int k = 0; k < NDIM; k++) { 683 j += k + 1;684 BoxDimension[k] = 2.5 * (configuration->GetIsAngstroem() ? 1. : 1. / AtomicLengthToAngstroem);685 cell_size[j] = BoxDimension[k] * 2.;686 }676 BoxDimension[k] = 2.5 * (World::getInstance().getConfig()->GetIsAngstroem() ? 1. : 1. / AtomicLengthToAngstroem); 677 cell_size.at(k,k) = BoxDimension[k] * 2.; 678 } 679 World::getInstance().setDomain(cell_size); 687 680 (*ListRunner)->Translate(&BoxDimension); 688 681 689 682 // also calculate necessary orbitals 690 683 (*ListRunner)->CountElements(); // this is a bugfix, atoms should shoulds actually be added correctly to this fragment 691 (*ListRunner)->CalculateOrbitals(*configuration);684 //(*ListRunner)->CalculateOrbitals(*World::getInstance().getConfig); 692 685 693 686 // change path in config 694 //strcpy(PathBackup, configuration->configpath); 695 sprintf(FragmentName, "%s/%s%s/", PathBackup, FRAGMENTPREFIX, FragmentNumber); 696 configuration->SetDefaultPath(FragmentName); 687 FragmentName = PathBackup; 688 FragmentName += "/"; 689 FragmentName += FRAGMENTPREFIX; 690 FragmentName += FragmentNumber; 691 FragmentName += "/"; 692 World::getInstance().getConfig()->SetDefaultPath(FragmentName.c_str()); 697 693 698 694 // and save as config 699 sprintf(FragmentName, "%s/%s%s.conf", configuration->configpath, FRAGMENTPREFIX, FragmentNumber);695 FragmentName = prefix + FragmentNumber + ".conf"; 700 696 DoLog(2) && (Log() << Verbose(2) << "Saving bond fragment No. " << FragmentNumber << "/" << FragmentCounter - 1 << " as config ..."); 701 if ((intermediateResult = configuration->Save(FragmentName, (*ListRunner)->elemente, (*ListRunner))))697 if ((intermediateResult = World::getInstance().getConfig()->Save(FragmentName.c_str(), (*ListRunner)->elemente, (*ListRunner)))) 702 698 DoLog(0) && (Log() << Verbose(0) << " done." << endl); 703 699 else … … 706 702 707 703 // restore old config 708 configuration->SetDefaultPath(PathBackup);704 World::getInstance().getConfig()->SetDefaultPath(PathBackup); 709 705 710 706 // and save as mpqc input file 711 sprintf(FragmentName, "%s/%s%s.conf", configuration->configpath, FRAGMENTPREFIX, FragmentNumber);707 FragmentName = prefix + FragmentNumber + ".conf"; 712 708 DoLog(2) && (Log() << Verbose(2) << "Saving bond fragment No. " << FragmentNumber << "/" << FragmentCounter - 1 << " as mpqc input ..."); 713 if ((intermediateResult = configuration->SaveMPQC(FragmentName, (*ListRunner))))709 if ((intermediateResult = World::getInstance().getConfig()->SaveMPQC(FragmentName.c_str(), (*ListRunner)))) 714 710 DoLog(2) && (Log() << Verbose(2) << " done." << endl); 715 711 else … … 727 723 728 724 // restore cell_size 729 for (int i=0;i<6;i++) 730 cell_size[i] = cell_size_backup[i]; 725 World::getInstance().setDomain(cell_size_backup); 731 726 732 727 return result; … … 767 762 768 763 // 1. dissect the molecule into connected subgraphs 769 if (!configuration->BG->ConstructBondGraph(mol)) { 770 World::getInstance().destroyMolecule(mol); 771 DoeLog(1) && (eLog()<< Verbose(1) << "There are no bonds." << endl); 764 if (configuration->BG != NULL) { 765 if (!configuration->BG->ConstructBondGraph(mol)) { 766 World::getInstance().destroyMolecule(mol); 767 DoeLog(1) && (eLog()<< Verbose(1) << "There are no bonds." << endl); 768 return; 769 } 770 } else { 771 DoeLog(1) && (eLog()<< Verbose(1) << "There is no BondGraph class present to create bonds." << endl); 772 772 return; 773 773 } … … 884 884 // center at set box dimensions 885 885 mol->CenterEdge(¢er); 886 World::getInstance().getDomain()[0] = center[0]; 887 World::getInstance().getDomain()[1] = 0; 888 World::getInstance().getDomain()[2] = center[1]; 889 World::getInstance().getDomain()[3] = 0; 890 World::getInstance().getDomain()[4] = 0; 891 World::getInstance().getDomain()[5] = center[2]; 886 Matrix domain; 887 for(int i =0;i<NDIM;++i) 888 domain.at(i,i) = center[i]; 889 World::getInstance().setDomain(domain); 892 890 insert(mol); 893 891 }
Note:
See TracChangeset
for help on using the changeset viewer.