- Timestamp:
- Apr 15, 2013, 10:30:31 AM (12 years ago)
- 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:
- 7b0494
- Parents:
- 503acc1
- git-author:
- Frederik Heber <heber@…> (03/07/13 20:53:50)
- git-committer:
- Frederik Heber <heber@…> (04/15/13 10:30:31)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
src/Actions/FragmentationAction/FragmentationAutomationAction.cpp
r503acc1 r0cd8cf 58 58 #include "Fragmentation/Automation/FragmentationChargeDensity.hpp" 59 59 #include "Fragmentation/Automation/FragmentJobQueue.hpp" 60 #include "Fragmentation/Automation/FragmentationResults.hpp" 60 #include "Fragmentation/Automation/FragmentationLongRangeResults.hpp" 61 #include "Fragmentation/Automation/FragmentationShortRangeResults.hpp" 61 62 #include "Fragmentation/Automation/MPQCFragmentController.hpp" 62 63 #include "Fragmentation/Automation/VMGDebugGridFragmentController.hpp" … … 112 113 } 113 114 114 /** Helper function to get number of atoms somehow.115 *116 * Here, we just parse the number of lines in the adjacency file as117 * it should correspond to the number of atoms, except when some atoms118 * are not bonded, but then fragmentation makes no sense.119 *120 * @param path path to the adjacency file121 */122 size_t getNoAtomsFromAdjacencyFile(const std::string &path)123 {124 size_t NoAtoms = 0;125 126 // parse in special file to get atom count (from line count)127 std::string filename(path);128 filename += FRAGMENTPREFIX;129 filename += ADJACENCYFILE;130 std::ifstream adjacency(filename.c_str());131 if (adjacency.fail()) {132 LOG(0, endl << "getNoAtomsFromAdjacencyFile() - Unable to open " << filename << ", is the directory correct?");133 return false;134 }135 std::string buffer;136 while (getline(adjacency, buffer))137 NoAtoms++;138 LOG(1, "INFO: There are " << NoAtoms << " atoms.");139 140 return NoAtoms;141 }142 143 144 145 /** Place results from FragmentResult into EnergyMatrix and ForceMatrix.146 *147 * @param fragmentData MPQCData resulting from the jobs148 * @param MatrixNrLookup Lookup up-map from job id to fragment number149 * @param FragmentCounter total number of fragments150 * @param NoAtoms total number of atoms151 * @param Energy energy matrix to be filled on return152 * @param Force force matrix to be filled on return153 * @return true - everything ok, false - else154 */155 bool putResultsintoMatrices(156 const std::map<JobId_t, MPQCData> &fragmentData,157 const std::map< JobId_t, size_t > &MatrixNrLookup,158 const size_t FragmentCounter,159 const size_t NoAtoms,160 EnergyMatrix &Energy,161 ForceMatrix &Force)162 {163 for (std::map<JobId_t, MPQCData>::const_iterator dataiter = fragmentData.begin();164 dataiter != fragmentData.end(); ++dataiter) {165 const MPQCData &extractedData = dataiter->second;166 const JobId_t &jobid = dataiter->first;167 std::map< JobId_t, size_t >::const_iterator nriter = MatrixNrLookup.find(jobid);168 ASSERT( nriter != MatrixNrLookup.end(),169 "putResultsintoMatrices() - MatrixNrLookup does not contain id "170 +toString(jobid)+".");171 // place results into EnergyMatrix ...172 {173 MatrixContainer::MatrixArray matrix;174 matrix.resize(1);175 matrix[0].resize(1, extractedData.energies.total);176 if (!Energy.AddMatrix(177 std::string("MPQCJob ")+toString(jobid),178 matrix,179 nriter->second)) {180 ELOG(1, "Adding energy matrix failed.");181 return false;182 }183 }184 // ... and ForceMatrix (with two empty columns in front)185 {186 MatrixContainer::MatrixArray matrix;187 const size_t rows = extractedData.forces.size();188 matrix.resize(rows);189 for (size_t i=0;i<rows;++i) {190 const size_t columns = 2+extractedData.forces[i].size();191 matrix[i].resize(columns, 0.);192 // for (size_t j=0;j<2;++j)193 // matrix[i][j] = 0.;194 for (size_t j=2;j<columns;++j)195 matrix[i][j] = extractedData.forces[i][j-2];196 }197 if (!Force.AddMatrix(198 std::string("MPQCJob ")+toString(jobid),199 matrix,200 nriter->second)) {201 ELOG(1, "Adding force matrix failed.");202 return false;203 }204 }205 }206 // add one more matrix (not required for energy)207 MatrixContainer::MatrixArray matrix;208 matrix.resize(1);209 matrix[0].resize(1, 0.);210 if (!Energy.AddMatrix(std::string("MPQCJob total"), matrix, FragmentCounter))211 return false;212 // but for energy because we need to know total number of atoms213 matrix.resize(NoAtoms);214 for (size_t i = 0; i< NoAtoms; ++i)215 matrix[i].resize(2+NDIM, 0.);216 if (!Force.AddMatrix(std::string("MPQCJob total"), matrix, FragmentCounter))217 return false;218 219 return true;220 }221 222 /** Print MPQCData from received results.223 *224 * @param fragmentData MPQCData resulting from the jobs, associated to job id225 * @param MatrixNrLookup map with enumerated jobids226 * @param KeySet KeySets of all (non-hydrogen) atoms227 * @param ForceKeySet KeySets of all atoms except those added by saturation228 * @param NoAtoms total number of atoms229 */230 bool printReceivedMPQCResults(231 const std::map<JobId_t, MPQCData> &fragmentData,232 const std::map< JobId_t, size_t > MatrixNrLookup,233 KeySetsContainer KeySet,234 const KeySetsContainer &ForceKeySet,235 size_t NoAtoms)236 {237 size_t FragmentCounter = MatrixNrLookup.size();238 239 // place results into maps240 EnergyMatrix Energy;241 ForceMatrix Force;242 if (!putResultsintoMatrices(fragmentData, MatrixNrLookup, FragmentCounter, NoAtoms, Energy, Force))243 return false;244 245 if (!Energy.InitialiseIndices()) return false;246 247 if (!Force.ParseIndices(ForceKeySet)) return false;248 249 // combine all found data250 if (!KeySet.ParseManyBodyTerms()) return false;251 252 EnergyMatrix EnergyFragments;253 ForceMatrix ForceFragments;254 if (!EnergyFragments.AllocateMatrix(Energy.Header, Energy.MatrixCounter, Energy.RowCounter, Energy.ColumnCounter)) return false;255 if (!ForceFragments.AllocateMatrix(Force.Header, Force.MatrixCounter, Force.RowCounter, Force.ColumnCounter)) return false;256 257 if(!Energy.SetLastMatrix(0., 0)) return false;258 if(!Force.SetLastMatrix(0., 2)) return false;259 260 for (int BondOrder=0;BondOrder<KeySet.Order;BondOrder++) {261 // --------- sum up energy --------------------262 LOG(1, "INFO: Summing energy of order " << BondOrder+1 << " ...");263 if (!EnergyFragments.SumSubManyBodyTerms(Energy, KeySet, BondOrder)) return false;264 if (!Energy.SumSubEnergy(EnergyFragments, NULL, KeySet, BondOrder, 1.)) return false;265 266 // --------- sum up Forces --------------------267 LOG(1, "INFO: Summing forces of order " << BondOrder+1 << " ...");268 if (!ForceFragments.SumSubManyBodyTerms(Force, KeySet, BondOrder)) return false;269 if (!Force.SumSubForces(ForceFragments, KeySet, BondOrder, 1.)) return false;270 }271 272 // for debugging print resulting energy and forces273 LOG(1, "INFO: Resulting energy is " << Energy.Matrix[ FragmentCounter ][0][0]);274 std::stringstream output;275 for (int i=0; i< Force.RowCounter[FragmentCounter]; ++i) {276 for (int j=0; j< Force.ColumnCounter[FragmentCounter]; ++j)277 output << Force.Matrix[ FragmentCounter ][i][j] << " ";278 output << "\n";279 }280 LOG(1, "INFO: Resulting forces are " << std::endl << output.str());281 282 return true;283 }284 285 /** Print MPQCData from received results.286 *287 * @param fragmentData MPQCData resulting from the jobs, associated to job id288 * @param KeySetFilename filename with keysets to associate forces correctly289 * @param NoAtoms total number of atoms290 */291 bool printReceivedMPQCResults(292 const std::map<JobId_t, MPQCData> &fragmentData,293 const std::string &KeySetFilename,294 size_t NoAtoms)295 {296 // create a vector of all job ids297 std::vector<JobId_t> jobids;298 std::transform(fragmentData.begin(),fragmentData.end(),299 std::back_inserter(jobids),300 boost::bind( &std::map<JobId_t,MPQCData>::value_type::first, boost::lambda::_1 )301 );302 303 // create lookup from job nr to fragment number304 size_t FragmentCounter = 0;305 const std::map< JobId_t, size_t > MatrixNrLookup =306 createMatrixNrLookup(jobids, FragmentCounter);307 308 // initialise keysets309 KeySetsContainer KeySet;310 parseKeySetFile(KeySet, KeySetFilename, FragmentCounter, NonHydrogenKeySets);311 KeySetsContainer ForceKeySet;312 parseKeySetFile(ForceKeySet, KeySetFilename, FragmentCounter, HydrogenKeySets);313 314 return printReceivedMPQCResults(315 fragmentData,316 MatrixNrLookup,317 KeySet,318 ForceKeySet,319 NoAtoms);320 }321 322 /** Print MPQCData from received results.323 *324 * @param fragmentData MPQCData resulting from the jobs, associated to job id325 * @param KeySet KeySets of all (non-hydrogen) atoms326 * @param ForceKeySet KeySets of all atoms except those added by saturation327 * @param NoAtoms total number of atoms328 */329 bool printReceivedMPQCResults(330 const std::map<JobId_t, MPQCData> &fragmentData,331 const KeySetsContainer &KeySet,332 const KeySetsContainer &ForceKeySet,333 size_t NoAtoms)334 {335 // create a vector of all job ids336 std::vector<JobId_t> jobids;337 std::transform(fragmentData.begin(),fragmentData.end(),338 std::back_inserter(jobids),339 boost::bind( &std::map<JobId_t,MPQCData>::value_type::first, boost::lambda::_1 )340 );341 342 // create lookup from job nr to fragment number343 size_t FragmentCounter = 0;344 const std::map< JobId_t, size_t > MatrixNrLookup =345 createMatrixNrLookup(jobids, FragmentCounter);346 347 return printReceivedMPQCResults(348 fragmentData,349 MatrixNrLookup,350 KeySet,351 ForceKeySet,352 NoAtoms);353 }354 355 115 void writeToFile(const std::string &filename, const std::string contents) 356 116 { … … 360 120 } 361 121 362 /** Print MPQCDatafrom received results.122 /** Print (short range) energy, forces, and timings from received results. 363 123 * 364 124 * @param results summed up results container 365 125 */ 366 void printReceived FullResults(367 const Fragmentation Results &results)126 void printReceivedShortResults( 127 const FragmentationShortRangeResults &results) 368 128 { 369 129 // print tables (without eigenvalues, they go extra) … … 378 138 filename += FRAGMENTPREFIX + std::string("_Energy.dat"); 379 139 writeToFile(filename, energyresult); 380 }381 382 if (results.Result_LongRange_fused.size() >= (results.getMaxLevel()-2))383 {384 const std::string gridresult =385 writeTable<VMGDataMap_t, VMGDataVector_t >()(386 results.Result_LongRange_fused, results.getMaxLevel(), 2);387 LOG(0, "VMG table is \n" << gridresult);388 std::string filename;389 filename += FRAGMENTPREFIX + std::string("_VMGEnergy.dat");390 writeToFile(filename, gridresult);391 }392 393 if (results.Result_LongRangeIntegrated_fused.size() >= (results.getMaxLevel()-2))394 {395 const std::string gridresult =396 writeTable<VMGDataLongRangeMap_t, VMGDataLongRangeVector_t >()(397 results.Result_LongRangeIntegrated_fused, results.getMaxLevel(), 2);398 LOG(0, "LongRange table is \n" << gridresult);399 std::string filename;400 filename += FRAGMENTPREFIX + std::string("_LongRangeEnergy.dat");401 writeToFile(filename, gridresult);402 140 } 403 141 … … 436 174 } 437 175 176 177 /** Print long range energy from received results. 178 * 179 * @param results summed up results container 180 */ 181 void printReceivedFullResults( 182 const FragmentationLongRangeResults &results) 183 { 184 // print tables (without eigenvalues, they go extra) 185 186 if (results.Result_LongRange_fused.size() >= (results.getMaxLevel()-2)) 187 { 188 const std::string gridresult = 189 writeTable<VMGDataMap_t, VMGDataVector_t >()( 190 results.Result_LongRange_fused, results.getMaxLevel(), 2); 191 LOG(0, "VMG table is \n" << gridresult); 192 std::string filename; 193 filename += FRAGMENTPREFIX + std::string("_VMGEnergy.dat"); 194 writeToFile(filename, gridresult); 195 } 196 197 if (results.Result_LongRangeIntegrated_fused.size() >= (results.getMaxLevel()-2)) 198 { 199 const std::string gridresult = 200 writeTable<VMGDataLongRangeMap_t, VMGDataLongRangeVector_t >()( 201 results.Result_LongRangeIntegrated_fused, results.getMaxLevel(), 2); 202 LOG(0, "LongRange table is \n" << gridresult); 203 std::string filename; 204 filename += FRAGMENTPREFIX + std::string("_LongRangeEnergy.dat"); 205 writeToFile(filename, gridresult); 206 } 207 } 208 438 209 bool appendToHomologyFile( 439 210 const boost::filesystem::path &homology_file, 440 const FragmentationResults &results) 211 const FragmentationShortRangeResults &shortrangeresults, 212 const FragmentationLongRangeResults &longrangeresults 213 ) 441 214 { 442 215 /// read homology container (if present) … … 458 231 /// append all fragments to a HomologyContainer 459 232 HomologyContainer::container_t values; 460 const size_t FragmentCounter = results.Result_perIndexSet_Energy.size();233 const size_t FragmentCounter = shortrangeresults.Result_perIndexSet_Energy.size(); 461 234 462 235 // convert KeySetContainer to IndexSetContainer 463 IndexSetContainer::ptr ForceContainer(new IndexSetContainer( results.getForceKeySet()));464 const IndexSetContainer::Container_t &Indices = results.getContainer();236 IndexSetContainer::ptr ForceContainer(new IndexSetContainer(shortrangeresults.getForceKeySet())); 237 const IndexSetContainer::Container_t &Indices = shortrangeresults.getContainer(); 465 238 const IndexSetContainer::Container_t &ForceIndices = ForceContainer->getContainer(); 466 239 IndexSetContainer::Container_t::const_iterator iter = Indices.begin(); … … 478 251 // obtain fragment as key 479 252 std::map<IndexSet::ptr, std::pair< MPQCDataFragmentMap_t, MPQCDataFragmentMap_t> >::const_iterator fragmentiter 480 = results.Result_perIndexSet_Fragment.find(index);481 ASSERT( fragmentiter != results.Result_perIndexSet_Fragment.end(),253 = longrangeresults.Result_perIndexSet_Fragment.find(index); 254 ASSERT( fragmentiter != longrangeresults.Result_perIndexSet_Fragment.end(), 482 255 "appendToHomologyFile() - cannot find index "+toString(*index) 483 256 +" in FragmentResults."); … … 486 259 // obtain energy as value 487 260 std::map<IndexSet::ptr, std::pair< MPQCDataEnergyMap_t, MPQCDataEnergyMap_t> >::const_iterator energyiter 488 = results.Result_perIndexSet_Energy.find(index);489 ASSERT( energyiter != results.Result_perIndexSet_Energy.end(),261 = shortrangeresults.Result_perIndexSet_Energy.find(index); 262 ASSERT( energyiter != shortrangeresults.Result_perIndexSet_Energy.end(), 490 263 "appendToHomologyFile() - cannot find index "+toString(*index) 491 264 +" in FragmentResults."); … … 557 330 } 558 331 332 FragmentationShortRangeResults shortrangeresults( 333 fragmentData, 334 FragmentJobQueue::getInstance().getKeySets(), 335 FragmentJobQueue::getInstance().getFullKeySets()); 336 shortrangeresults(fragmentData); 337 printReceivedShortResults(shortrangeresults); 338 559 339 #ifdef HAVE_VMG 560 340 if (params.DoLongrange.get()) { … … 613 393 614 394 // Final phase: sum up and print result 615 Fragmentation Resultsresults(395 FragmentationLongRangeResults longrangeresults( 616 396 fragmentData, 617 397 longrangeData, 618 398 FragmentJobQueue::getInstance().getKeySets(), 619 399 FragmentJobQueue::getInstance().getFullKeySets()); 620 results(400 longrangeresults( 621 401 fragmentData, 622 402 longrangeData, 623 403 fullsolutionData, 624 404 full_sample); 625 printReceivedFullResults( results);405 printReceivedFullResults(longrangeresults); 626 406 627 407 // append all keysets to homology file … … 630 410 if (homology_file.string() != "") { 631 411 LOG(1, "INFO: Appending HomologyGraphs to file " << homology_file.string() << "."); 632 if (!appendToHomologyFile(homology_file, results))412 if (!appendToHomologyFile(homology_file, shortrangeresults, longrangeresults)) 633 413 Exitflag = 1; 634 414 } … … 651 431 } 652 432 } 653 #else654 // Final phase: print result655 {656 LOG(1, "INFO: Parsing fragment files from " << params.path.get() << ".");657 printReceivedMPQCResults(658 fragmentData,659 FragmentJobQueue::getInstance().getKeySets(),660 FragmentJobQueue::getInstance().getFullKeySets(),661 World::getInstance().getAllAtoms().size()));662 }663 433 #endif 664 434
Note:
See TracChangeset
for help on using the changeset viewer.