Changeset 9c793c for src/FunctionApproximation
- Timestamp:
- Nov 11, 2016, 2:25:36 PM (8 years ago)
- Branches:
- Action_Thermostats, Add_AtomRandomPerturbation, Add_RotateAroundBondAction, Add_SelectAtomByNameAction, Adding_Graph_to_ChangeBondActions, Adding_MD_integration_tests, Adding_StructOpt_integration_tests, Automaking_mpqc_open, AutomationFragmentation_failures, Candidate_v1.6.0, Candidate_v1.6.1, ChangeBugEmailaddress, ChangingTestPorts, ChemicalSpaceEvaluator, 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_ChronosMutex, Fix_StatusMsg, Fix_StepWorldTime_single_argument, Fix_Verbose_Codepatterns, ForceAnnealing_goodresults, ForceAnnealing_oldresults, ForceAnnealing_tocheck, ForceAnnealing_with_BondGraph, ForceAnnealing_with_BondGraph_continued, ForceAnnealing_with_BondGraph_continued_betteresults, ForceAnnealing_with_BondGraph_contraction-expansion, GeometryObjects, Gui_displays_atomic_force_velocity, IndependentFragmentGrids_IntegrationTest, JobMarket_RobustOnKillsSegFaults, JobMarket_StableWorkerPool, JobMarket_unresolvable_hostname_fix, ODR_violation_mpqc_open, PartialCharges_OrthogonalSummation, PythonUI_with_named_parameters, QtGui_reactivate_TimeChanged_changes, Recreated_GuiChecks, RotateToPrincipalAxisSystem_UndoRedo, StoppableMakroAction, Subpackage_CodePatterns, Subpackage_JobMarket, Subpackage_LinearAlgebra, Subpackage_levmar, Subpackage_mpqc_open, Subpackage_vmg, ThirdParty_MPQC_rebuilt_buildsystem, TremoloParser_IncreasedPrecision, TremoloParser_MultipleTimesteps, Ubuntu_1604_changes, stable
- Children:
- f5dbea
- Parents:
- bc069f
- git-author:
- Frederik Heber <heber@…> (10/05/16 21:33:40)
- git-committer:
- Frederik Heber <heber@…> (11/11/16 14:25:36)
- Location:
- src/FunctionApproximation
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
src/FunctionApproximation/Extractors.cpp
rbc069f r9c793c 61 61 #include "LinearAlgebra/Vector.hpp" 62 62 63 #include "Fragmentation/Homology/HomologyGraph.hpp" 63 64 #include "FunctionApproximation/Extractors.hpp" 64 65 #include "FunctionApproximation/FunctionArgument.hpp" 65 66 #include "Fragmentation/Homology/HomologyGraph.hpp" 66 #include "Potentials/BindingModel.hpp" 67 67 68 68 using namespace boost::assign; … … 535 535 const HomologyGraph &_graph, 536 536 const ParticleTypes_t &_types, 537 const HomologyGraph&_bindingmodel537 const BindingModel &_bindingmodel 538 538 ) 539 539 { … … 545 545 // deal with the case when there are no distances (ConstantPotential) 546 546 if (_bindingmodel.getNodes().size() < 2) { 547 LOG(3, "DEBUG: Potential requires only zeroor no particle types, needs no distances.");547 LOG(3, "DEBUG: Potential requires only one or no particle types, needs no distances."); 548 548 continue; 549 549 } 550 if (_bindingmodel.get Edges().empty()) {550 if (_bindingmodel.getGraph().getEdges().empty()) { 551 551 LOG(3, "DEBUG: Potential represents non-bonded interactions, gets all distances."); 552 // TODO: Here we need to constrain to all distances matching the types? 552 553 returnargs.push_back(args); 553 554 continue; … … 604 605 605 606 /// 2. grab first node of the binding model (gives a type) 606 const FragmentNode &firstnode = _bindingmodel.getNodes().begin()->first;607 const size_t &firsttimes = _bindingmodel.getNodes().begin()->second;608 const size_t &firsttype = firstnode.getAtomicNumber(); // TODO: convert to ParticleNumber_t ?607 const BindingModel::vector_nodes_t::const_iterator firstiter = _bindingmodel.getNodes().begin(); 608 const FragmentNode &firstnode = *firstiter; 609 const Extractors::ParticleType_t &firsttype = firstnode.getAtomicNumber(); 609 610 610 611 /// 3. grab all candidate nodes contained in arguments_t … … 612 613 type_index_lookup_t::right_const_iterator, 613 614 type_index_lookup_t::right_const_iterator> range = type_index_lookup.right.equal_range(firsttype); 614 #ifndef NDEBUG615 const size_t checktimes = std::distance(range.first, range.second);616 ASSERT( firsttimes == checktimes,617 "Extractors::reorderArgumentsByParticleTypes() - unequal amounts of same first type "618 +toString(firsttype)+" in HomologyGraph and in type lookup "+toString(checktimes));619 #endif620 615 621 616 /// 4. go over all candidate nodes (gives index) 617 const size_t nodes_in_bindingmodel = _bindingmodel.getNodes().size(); 618 LOG(2, "DEBUG: There are " << nodes_in_bindingmodel << " nodes in the binding model."); 622 619 set_of_nodes_t set_of_nodes; 623 620 for (type_index_lookup_t::right_const_iterator rangeiter = range.first; … … 648 645 649 646 generateAllInducedConnectedSubgraphs( 650 N-1, level, nodes, set_of_nodes, nodes_per_level, fragmentgraph, distances, index_map);647 nodes_in_bindingmodel-1, level, nodes, set_of_nodes, nodes_per_level, fragmentgraph, distances, index_map); 651 648 LOG(2, "DEBUG: We have found " << set_of_nodes.size() << " unique induced, connected subgraphs."); 652 649 } … … 661 658 662 659 /// 10. compare each converted HomologyGraph with _bindingmodel: Accept or Reject 663 if (nodes_graph == _bindingmodel ) {664 LOG(2, "ACCEPT: " << nodes_graph << " is identical to " << _bindingmodel );660 if (nodes_graph == _bindingmodel.getGraph()) { 661 LOG(2, "ACCEPT: " << nodes_graph << " is identical to " << _bindingmodel.getGraph()); 665 662 /// 11. for each accepted keyset, pick _all_ symmetric distances from arguments_t 666 663 FunctionModel::arguments_t argumentbunch; … … 687 684 */ 688 685 689 /// So, we need to store for each node its type and the number of connected690 /// edges, which we extract from the argumentbunch.686 /// So, we need to extract from the argumentbunch the information contained in each 687 /// FragmentNode, namely its type and the number of connected edges 691 688 node_FragmentNode_map_t node_FragmentNode_map = fillNodeFragmentMap(argumentbunch); 692 689 693 /// Then, we step through the nodes of the bindingmodel 694 const HomologyGraph::nodes_t bindingmodel_nodes = _bindingmodel.getNodes(); 690 /// Then, we step through the nodes of the bindingmodel ... 691 /// ... and find a suitable mapping from indices in the arguments to 692 /// the index in the order of the HomologyGraph's nodes 693 const BindingModel::vector_nodes_t bindingmodel_nodes = _bindingmodel.getNodes(); 695 694 argindex_to_nodeindex_t argindex_to_nodeindex; 696 695 size_t nodeindex = 0; 697 for ( HomologyGraph::nodes_t::const_iterator nodeiter = bindingmodel_nodes.begin();696 for (BindingModel::vector_nodes_t::const_iterator nodeiter = bindingmodel_nodes.begin(); 698 697 nodeiter != bindingmodel_nodes.end(); ++nodeiter) { 699 const FragmentNode &node = nodeiter->first;698 const FragmentNode &node = *nodeiter; 700 699 LOG(3, "DEBUG: Binding model's node #" << node << "."); 701 // might have to pick several 702 for (size_t pick_no = 0; pick_no < nodeiter->second; ++pick_no) { 703 /// ... and pick for each the first (and unique) from these stored nodes. 704 node_FragmentNode_map_t::iterator mapiter = node_FragmentNode_map.begin(); 705 for (;mapiter != node_FragmentNode_map.end(); ++mapiter) { 706 if ((mapiter->second.first == node.getAtomicNumber()) 707 && (mapiter->second.second == node.getConnectedEdges())) { 708 LOG(3, "DEBUG: #" << mapiter->first << " with type " << mapiter->second.first 709 << " and " << mapiter->second.second << " connected edges matches as choice #" 710 << pick_no << "."); 711 break; 712 } 700 /// ... and pick for each the first (and unique) from these stored nodes. 701 node_FragmentNode_map_t::iterator mapiter = node_FragmentNode_map.begin(); 702 for (;mapiter != node_FragmentNode_map.end(); ++mapiter) { 703 if ((mapiter->second.first == node.getAtomicNumber()) 704 && (mapiter->second.second == node.getConnectedEdges())) { 705 LOG(3, "DEBUG: #" << mapiter->first << " with type " << mapiter->second.first 706 << " and " << mapiter->second.second << " connected edges matches."); 707 break; 713 708 } 714 ASSERT( mapiter != node_FragmentNode_map.end(),715 "Extractors::reorderArgumentsByParticleTypes() - could not find a suitable node for #"+716 toString(mapiter->first)+" with type "+toString(mapiter->second.first)+" and "+717 toString(mapiter->second.second)+" connected edges");718 std::pair<argindex_to_nodeindex_t::iterator, bool> inserter =719 argindex_to_nodeindex.insert( std::make_pair(mapiter->first, nodeindex++) );720 ASSERT( inserter.second,721 "Extractors::reorderArgumentsByParticleTypes() - node #"+toString(mapiter->first)+722 " is already present?");723 // remove to ensure uniqueness of choice724 node_FragmentNode_map.erase(mapiter);725 709 } 710 ASSERT( mapiter != node_FragmentNode_map.end(), 711 "Extractors::reorderArgumentsByParticleTypes() - could not find a suitable node for #"+ 712 toString(mapiter->first)+" with type "+toString(mapiter->second.first)+" and "+ 713 toString(mapiter->second.second)+" connected edges"); 714 std::pair<argindex_to_nodeindex_t::iterator, bool> inserter = 715 argindex_to_nodeindex.insert( std::make_pair(mapiter->first, nodeindex++) ); 716 ASSERT( inserter.second, 717 "Extractors::reorderArgumentsByParticleTypes() - node #"+toString(mapiter->first)+ 718 " is already present?"); 719 // remove to ensure uniqueness of choice 720 node_FragmentNode_map.erase(mapiter); 726 721 } 727 /// This gives then the desired mapping from indices in the arguments to 728 /// the index in the order of the HomologyGraph's nodes 722 LOG(4, "DEBUG: argument's indices to node index map is " << argindex_to_nodeindex); 723 // i.e. this is not the arg's index in argumentbunch, but the index of the position 724 // contained in the argument_t 729 725 730 726 /// Finally, we only need to bring the arguments in the typical order: 731 727 /// 01 02 03 04 ... 0n, 12 13 14 ... 1n, 23 24 25 ... 2n, ..., (n-1)n 728 /// These ordering we store in a map for each argument's indices 732 729 const size_t num_args = argindex_to_nodeindex.size(); 733 730 argument_placement_map_t argument_placement_map = fillArgumentsPlacementMap(num_args); … … 737 734 toString(argument_placement_map.size())+" and we expected "+toString(argumentbunch.size())); 738 735 739 // and finally resort the arguments with the knownplacement map740 FunctionModel::arguments_t sortedargs(argumentbunch );736 // and finally resort the arguments with the constructed placement map 737 FunctionModel::arguments_t sortedargs(argumentbunch.size()); 741 738 for (FunctionModel::arguments_t::const_iterator argiter = argumentbunch.begin(); 742 739 argiter != argumentbunch.end(); ++argiter) { 743 740 const argument_t &arg = *argiter; 741 const argument_t::indices_t translatedIndices = 742 translateIndices(argindex_to_nodeindex, arg.indices); 744 743 const argument_placement_map_t::const_iterator indexiter = 745 argument_placement_map.find( translate Indices(argindex_to_nodeindex, arg.indices));744 argument_placement_map.find( translatedIndices ); 746 745 ASSERT( indexiter != argument_placement_map.end(), 747 746 "Extractors::reorderArgumentsByParticleTypes() - could not find place for edge "+ … … 749 748 sortedargs[indexiter->second] = arg; 750 749 LOG(3, "DEBUG: Placed argument " << arg << " at #" << indexiter->second 751 << " as translated indices are " << translate Indices(argindex_to_nodeindex, arg.indices));750 << " as translated indices are " << translatedIndices); 752 751 } 753 752 LOG(2, "DEBUG: Sorted arguments are " << sortedargs << "."); … … 755 754 returnargs.push_back(sortedargs); 756 755 } else { 757 LOG(2, "REJECT: " << nodes_graph << " is not identical to " << _bindingmodel );756 LOG(2, "REJECT: " << nodes_graph << " is not identical to " << _bindingmodel.getGraph()); 758 757 } 759 758 } … … 767 766 const HomologyGraph &_graph, 768 767 const ParticleTypes_t &_types, 769 const HomologyGraph&_bindingmodel768 const BindingModel &_bindingmodel 770 769 ) 771 770 { -
src/FunctionApproximation/Extractors.hpp
rbc069f r9c793c 20 20 #include "FunctionApproximation/FunctionModel.hpp" 21 21 22 class BindingModel; 22 23 class Fragment; 23 24 class HomologyGraph; … … 118 119 const HomologyGraph &_graph, 119 120 const ParticleTypes_t &_types, 120 const HomologyGraph&_bindingmodel121 const BindingModel &_bindingmodel 121 122 ); 122 123 … … 135 136 const HomologyGraph &_graph, 136 137 const ParticleTypes_t &_types, 137 const HomologyGraph&_bindingmodel138 const BindingModel &_bindingmodel 138 139 ); 139 140
Note:
See TracChangeset
for help on using the changeset viewer.