Changeset 9a5bcd


Ignore:
Timestamp:
Oct 17, 2008, 1:20:42 PM (16 years ago)
Author:
Frederik Heber <heber@…>
Branches:
Action_Thermostats, Add_AtomRandomPerturbation, Add_FitFragmentPartialChargesAction, Add_RotateAroundBondAction, Add_SelectAtomByNameAction, Added_ParseSaveFragmentResults, AddingActions_SaveParseParticleParameters, Adding_Graph_to_ChangeBondActions, Adding_MD_integration_tests, Adding_ParticleName_to_Atom, Adding_StructOpt_integration_tests, AtomFragments, Automaking_mpqc_open, AutomationFragmentation_failures, Candidate_v1.5.4, Candidate_v1.6.0, Candidate_v1.6.1, ChangeBugEmailaddress, ChangingTestPorts, ChemicalSpaceEvaluator, CombiningParticlePotentialParsing, Combining_Subpackages, Debian_Package_split, Debian_package_split_molecuildergui_only, Disabling_MemDebug, Docu_Python_wait, EmpiricalPotential_contain_HomologyGraph, EmpiricalPotential_contain_HomologyGraph_documentation, Enable_parallel_make_install, Enhance_userguide, Enhanced_StructuralOptimization, Enhanced_StructuralOptimization_continued, Example_ManyWaysToTranslateAtom, Exclude_Hydrogens_annealWithBondGraph, FitPartialCharges_GlobalError, Fix_BoundInBox_CenterInBox_MoleculeActions, Fix_ChargeSampling_PBC, Fix_ChronosMutex, Fix_FitPartialCharges, Fix_FitPotential_needs_atomicnumbers, Fix_ForceAnnealing, Fix_IndependentFragmentGrids, Fix_ParseParticles, Fix_ParseParticles_split_forward_backward_Actions, Fix_PopActions, Fix_QtFragmentList_sorted_selection, Fix_Restrictedkeyset_FragmentMolecule, Fix_StatusMsg, Fix_StepWorldTime_single_argument, Fix_Verbose_Codepatterns, Fix_fitting_potentials, Fixes, ForceAnnealing_goodresults, ForceAnnealing_oldresults, ForceAnnealing_tocheck, ForceAnnealing_with_BondGraph, ForceAnnealing_with_BondGraph_continued, ForceAnnealing_with_BondGraph_continued_betteresults, ForceAnnealing_with_BondGraph_contraction-expansion, FragmentAction_writes_AtomFragments, FragmentMolecule_checks_bonddegrees, GeometryObjects, Gui_Fixes, Gui_displays_atomic_force_velocity, ImplicitCharges, IndependentFragmentGrids, IndependentFragmentGrids_IndividualZeroInstances, IndependentFragmentGrids_IntegrationTest, IndependentFragmentGrids_Sole_NN_Calculation, JobMarket_RobustOnKillsSegFaults, JobMarket_StableWorkerPool, JobMarket_unresolvable_hostname_fix, MoreRobust_FragmentAutomation, ODR_violation_mpqc_open, PartialCharges_OrthogonalSummation, PdbParser_setsAtomName, PythonUI_with_named_parameters, QtGui_reactivate_TimeChanged_changes, Recreated_GuiChecks, Rewrite_FitPartialCharges, RotateToPrincipalAxisSystem_UndoRedo, SaturateAtoms_findBestMatching, SaturateAtoms_singleDegree, StoppableMakroAction, Subpackage_CodePatterns, Subpackage_JobMarket, Subpackage_LinearAlgebra, Subpackage_levmar, Subpackage_mpqc_open, Subpackage_vmg, Switchable_LogView, ThirdParty_MPQC_rebuilt_buildsystem, TrajectoryDependenant_MaxOrder, TremoloParser_IncreasedPrecision, TremoloParser_MultipleTimesteps, TremoloParser_setsAtomName, Ubuntu_1604_changes, stable
Children:
4ee3df
Parents:
f00693
Message:

config::Save() and config::SaveMPQC() now take string for filename, instead of opened ofstream.

This was necessary, as config::SaveMPQC() now writes to files: One with hessian calc enabled, the other not. As it is a pendant of config::Save(), this file was changed accordingly. Both are called from builder.cpp (ParseFromParamters() and main()) and moleculelist.cpp (MoleculeListClass::OutputConfigForListOfFragments()), hence these were changed,too.

Location:
src
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • src/builder.cpp

    rf00693 r9a5bcd  
    699699  mol->CalculateOrbitals(*configuration);
    700700  configuration->InitMaxMinStopStep = configuration->MaxMinStopStep = configuration->MaxPsiDouble;
    701   if (ConfigFileName != NULL) {
     701  strcpy(filename, ConfigFileName);
     702  if (ConfigFileName != NULL) { // test the file name
    702703    output.open(ConfigFileName, ios::trunc);
    703704  } else if (strlen(configuration->configname) != 0) {
     705    strcpy(filename, configuration->configname);
    704706    output.open(configuration->configname, ios::trunc);
    705707    } else {
     708      strcpy(filename, DEFAULTCONFIG);
    706709      output.open(DEFAULTCONFIG, ios::trunc);
    707710    }
     711  output.close();
     712  output.clear();
    708713  cout << Verbose(0) << "Saving of config file ";
    709   if (configuration->Save(&output, periode, mol))
     714  if (configuration->Save(filename, periode, mol))
    710715    cout << "successful." << endl;
    711716  else
    712717    cout << "failed." << endl;
    713   output.close();
    714   output.clear();
    715718 
    716719  // and save to xyz file
     
    741744 
    742745  // and save as MPQC configuration
    743   if (ConfigFileName != NULL) {
     746  if (ConfigFileName != NULL)
    744747    strcpy(filename, ConfigFileName);
    745     strcat(filename, ".in");
    746     output.open(filename, ios::trunc);
    747   }
    748   if (output == NULL) {
     748  if (output == NULL)
    749749    strcpy(filename,"main_pcp_linux");
    750     strcat(filename, ".in");
    751     output.open(filename, ios::trunc);
    752   }
    753750  cout << Verbose(0) << "Saving as mpqc input ";
    754   if (configuration->SaveMPQC(&output, mol))
     751  if (configuration->SaveMPQC(filename, mol))
    755752    cout << "done." << endl;
    756753  else
    757754    cout << "failed." << endl;
    758   output.close();
    759   output.clear();
    760755 
    761756  if (!strcmp(configuration->configpath, configuration->GetDefaultPath())) {
     
    919914              ExitFlag = 1;
    920915              if ((argptr >= argc) || (argv[argptr][0] == '-')) {
     916                ExitFlag = 255;
    921917                cerr << "Not enough arguments for parsing: -p <xyz file>" << endl;
    922918              } else {
     
    934930              ExitFlag = 1;
    935931              if ((argptr >= argc) || (argv[argptr][0] == '-') || (!IsValidNumber(argv[argptr+1]))) {
     932                ExitFlag = 255;
    936933                cerr << "Not enough or invalid arguments for adding atom: -a <element> <x> <y> <z>" << endl;
    937934              } else {
     
    995992              ExitFlag = 1;
    996993              if ((argptr+1 >= argc) || (!IsValidNumber(argv[argptr])) || (argv[argptr+1][0] == '-')) {
     994                ExitFlag = 255;
    997995                cerr << "Not enough or invalid arguments given for changing element: -E <atom nr.> <element>" << endl;
    998996              } else {
     
    10071005              ExitFlag = 1;
    10081006              if ((argptr >= argc) || (argv[argptr][0] == '-')) {
     1007                ExitFlag = 255;
    10091008                cerr << "Not enough or invalid arguments given for storing tempature: -T <temperature file>" << endl;
    10101009              } else {
     
    10231022              ExitFlag = 1;
    10241023              if ((argptr >= argc) || (argv[argptr][0] == '-')) {
     1024                ExitFlag = 255;
    10251025                cerr << "Not enough or invalid arguments given for parsing and integrating forces: -P <forces file>" << endl;
    10261026              } else {
     
    10371037              ExitFlag = 1;
    10381038              if ((argptr+2 >= argc) || (!IsValidNumber(argv[argptr])) || (!IsValidNumber(argv[argptr+1])) || (!IsValidNumber(argv[argptr+2])) ) {
     1039                ExitFlag = 255;
    10391040                cerr << "Not enough or invalid arguments given for translation: -t <x> <y> <z>" << endl;
    10401041              } else {
     
    10511052              ExitFlag = 1;
    10521053              if ((argptr >= argc) || (!IsValidNumber(argv[argptr])) ) {
     1054                ExitFlag = 255;
    10531055                cerr << "Not enough or invalid arguments given for scaling: -s <factor/[factor_x]> [factor_y] [factor_z]" << endl;
    10541056              } else {
     
    10771079              ExitFlag = 1;
    10781080              if ((argptr+2 >= argc) || (!IsValidNumber(argv[argptr])) || (!IsValidNumber(argv[argptr+1])) || (!IsValidNumber(argv[argptr+2])) ) {
     1081                ExitFlag = 255;
    10791082                cerr << "Not enough or invalid arguments given for centering in box: -b <length_x> <length_y> <length_z>" << endl;
    10801083              } else {
     
    10971100              ExitFlag = 1;
    10981101              if ((argptr+2 >= argc) || (!IsValidNumber(argv[argptr])) || (!IsValidNumber(argv[argptr+1])) || (!IsValidNumber(argv[argptr+2])) ) {
     1102                ExitFlag = 255;
    10991103                cerr << "Not enough or invalid arguments given for centering with boundary: -c <boundary_x> <boundary_y> <boundary_z>" << endl;
    11001104              } else {
     
    11321136              ExitFlag = 1;
    11331137              if ((argptr+1 >= argc) || (!IsValidNumber(argv[argptr])) || (!IsValidNumber(argv[argptr+1]))) {
     1138                ExitFlag = 255;
    11341139                cerr << "Not enough or invalid arguments for fragmentation: -f <max. bond distance> <bond order>" << endl;
    11351140              } else {
     
    11701175              ExitFlag = 1;
    11711176              if ((argptr+1 >= argc) || (!IsValidNumber(argv[argptr])) || (!IsValidNumber(argv[argptr+1])) ) {
     1177                ExitFlag = 255;
    11721178                cerr << "Not enough or invalid arguments given for suspension with specified volume: -U <volume> <density>" << endl;
    11731179                volume = -1; // for case 'u': don't print error again
     
    11801186              if ((argptr >= argc) || (!IsValidNumber(argv[argptr])) ) {
    11811187                if (volume != -1)
     1188                  ExitFlag = 255;
    11821189                  cerr << "Not enough arguments given for suspension: -u <density>" << endl;
    11831190              } else {
     
    12021209              ExitFlag = 1;
    12031210              if ((argptr+2 >= argc) || (!IsValidNumber(argv[argptr])) || (!IsValidNumber(argv[argptr+1])) || (!IsValidNumber(argv[argptr+2])) ) {
     1211                ExitFlag = 255;
    12041212                cerr << "Not enough or invalid arguments given for repeating cells: -d <repeat_x> <repeat_y> <repeat_z>" << endl;
    12051213              } else {
  • src/config.cpp

    rf00693 r9a5bcd  
    971971
    972972/** Stores all elements of config structure from which they can be re-read.
    973  * \param output open output *file stream to write to
     973 * \param *filename name of file
    974974 * \param *periode pointer to a periodentafel class with all elements
    975975 * \param *mol pointer to molecule containing all atoms of the molecule
    976976 */
    977 bool config::Save(ofstream *output, periodentafel *periode, molecule *mol) const
     977bool config::Save(const char *filename, periodentafel *periode, molecule *mol) const
    978978{
    979979  bool result = true;
    980980        // bring MaxTypes up to date
    981981        mol->CountElements();
     982  ofstream *output = NULL;
     983  output = new ofstream(filename, ios::out);
    982984  if (output != NULL) {
    983985    *output << "# ParallelCarParinello - main configuration file - created with molecuilder" << endl;
     
    10671069    else
    10681070      result = result && mol->OutputTrajectories(output);
     1071    output->close();
     1072    output->clear();
     1073    delete(output);
    10691074    return result;
    10701075  } else
     
    10741079/** Stores all elements in a MPQC input file.
    10751080 * Note that this format cannot be parsed again.
    1076  * \param output open output *file stream to write to
     1081 * \param *filename name of file (without ".in" suffix!)
    10771082 * \param *mol pointer to molecule containing all atoms of the molecule
    10781083 */
    1079 bool config::SaveMPQC(ofstream *output, molecule *mol) const
     1084bool config::SaveMPQC(const char *filename, molecule *mol) const
    10801085{
    10811086  int ElementNo = 0;
    10821087  int AtomNo;
    10831088  atom *Walker = NULL;
    1084   element *runner = mol->elemente->start;
     1089  element *runner = NULL;
    10851090  Vector *center = NULL;
    1086 
     1091  ofstream *output = NULL;
     1092  stringstream *fname = NULL;
     1093 
     1094  // first without hessian
     1095  fname = new stringstream;
     1096  *fname << filename << ".in";
     1097  output = new ofstream(fname->str().c_str(), ios::out);
    10871098  *output << "% Created by MoleCuilder" << endl;
    10881099  *output << "mpqc: (" << endl;
     
    11001111  center = mol->DetermineCenterOfAll(output);
    11011112  // output of atoms
     1113  runner = mol->elemente->start;
    11021114  while (runner->next != mol->elemente->end) { // go through every element
    11031115    runner = runner->next;
     
    11221134  *output << "\tmolecule = $:molecule" << endl;
    11231135  *output << ")" << endl;
     1136  output->close();
     1137  delete(output);
     1138  delete(fname);
     1139
     1140  // second with hessian
     1141  fname = new stringstream;
     1142  *fname << filename << ".hess.in";
     1143  output = new ofstream(fname->str().c_str(), ios::out);
     1144  *output << "% Created by MoleCuilder" << endl;
     1145  *output << "mpqc: (" << endl;
     1146  *output << "\tsavestate = no" << endl;
     1147  *output << "\tdo_gradient = yes" << endl;
     1148  *output << "\tmole<CLHF>: (" << endl;
     1149  *output << "\t\tmaxiter = 200" << endl;
     1150  *output << "\t\tbasis = $:basis" << endl;
     1151  *output << "\t\tmolecule = $:molecule" << endl;
     1152  *output << "\t)" << endl;
     1153  *output << "\tfreq<MolecularFrequencies>: (" << endl;
     1154  *output << "\t\tmolecule=$:molecule" << endl;
     1155  *output << "\t)" << endl;
     1156  *output << ")" << endl;
     1157  *output << "molecule<Molecule>: (" << endl;
     1158  *output << "\tunit = " << (IsAngstroem ? "angstrom" : "bohr" ) << endl;
     1159  *output << "\t{ atoms geometry } = {" << endl;
     1160  center = mol->DetermineCenterOfAll(output);
     1161  // output of atoms
     1162  runner = mol->elemente->start;
     1163  while (runner->next != mol->elemente->end) { // go through every element
     1164    runner = runner->next;
     1165    if (mol->ElementsInMolecule[runner->Z]) { // if this element got atoms
     1166      ElementNo++;
     1167      AtomNo = 0;
     1168      Walker = mol->start;
     1169      while (Walker->next != mol->end) { // go through every atom of this element
     1170        Walker = Walker->next;
     1171        if (Walker->type == runner) { // if this atom fits to element
     1172          AtomNo++;
     1173          *output << "\t\t" << Walker->type->symbol << " [ " << Walker->x.x[0]-center->x[0] << "\t" << Walker->x.x[1]-center->x[1] << "\t" << Walker->x.x[2]-center->x[2] << " ]" << endl;
     1174        }
     1175      }
     1176    }
     1177  }
     1178  delete(center);
     1179  *output << "\t}" << endl;
     1180  *output << ")" << endl;
     1181  *output << "basis<GaussianBasisSet>: (" << endl;
     1182  *output << "\tname = \"3-21G\"" << endl;
     1183  *output << "\tmolecule = $:molecule" << endl;
     1184  *output << ")" << endl;
     1185  output->close();
     1186  delete(output);
     1187  delete(fname);
     1188 
    11241189  return true;
    11251190};
  • src/moleculelist.cpp

    rf00693 r9a5bcd  
    450450    // and save as config
    451451    sprintf(FragmentName, "%s/%s%s.conf", configuration->configpath, FRAGMENTPREFIX, FragmentNumber);
    452     outputFragment.open(FragmentName, ios::out);
    453452    *out << Verbose(2) << "Saving bond fragment No. " << FragmentNumber << "/" << FragmentCounter-1 << " as config ...";
    454     if ((intermediateResult = configuration->Save(&outputFragment, ListOfMolecules[i]->elemente, ListOfMolecules[i])))
     453    if ((intermediateResult = configuration->Save(FragmentName, ListOfMolecules[i]->elemente, ListOfMolecules[i])))
    455454      *out << " done." << endl;
    456455    else
    457456      *out << " failed." << endl;
     457    result = result && intermediateResult;
    458458
    459459    // restore old config
    460460    configuration->SetDefaultPath(PathBackup);
    461461
    462     result = result && intermediateResult;
    463     outputFragment.close();
    464     outputFragment.clear();
    465462
    466463    // and save as mpqc input file
    467     sprintf(FragmentName, "%s/%s%s.in", configuration->configpath, FRAGMENTPREFIX, FragmentNumber);
    468     outputFragment.open(FragmentName, ios::out);
     464    sprintf(FragmentName, "%s/%s%s.conf", configuration->configpath, FRAGMENTPREFIX, FragmentNumber);
    469465    *out << Verbose(2) << "Saving bond fragment No. " << FragmentNumber << "/" << FragmentCounter-1 << " as mpqc input ...";
    470     if ((intermediateResult = configuration->SaveMPQC(&outputFragment, ListOfMolecules[i])))
     466    if ((intermediateResult = configuration->SaveMPQC(FragmentName, ListOfMolecules[i])))
    471467      *out << " done." << endl;
    472468    else
     
    474470       
    475471    result = result && intermediateResult;
    476     outputFragment.close();
    477     outputFragment.clear();
     472    //outputFragment.close();
     473    //outputFragment.clear();
    478474    delete(FragmentNumber);
    479475    //Free((void **)&FragmentNumber, "MoleculeListClass::OutputConfigForListOfFragments: *FragmentNumber");
  • src/molecules.hpp

    rf00693 r9a5bcd  
    452452  void LoadOld(char *filename, periodentafel *periode, molecule *mol);
    453453  void RetrieveConfigPathAndName(string filename);
    454   bool Save(ofstream *file, periodentafel *periode, molecule *mol) const;
    455   bool SaveMPQC(ofstream *file, molecule *mol) const;
     454  bool Save(const char *filename, periodentafel *periode, molecule *mol) const;
     455  bool SaveMPQC(const char *filename, molecule *mol) const;
    456456  void Edit(molecule *mol);
    457457  bool GetIsAngstroem() const;
Note: See TracChangeset for help on using the changeset viewer.