@@ -32,7 +32,7 @@ along with LeMonADE-Viewer. If not, see <http://www.gnu.org/licenses/>.
3232
3333#include < string>
3434#include < sstream>
35- #include < algorithm> // std::find_if
35+ #include < algorithm> // std::find_if std::max
3636#include < cstddef> // NULL
3737#include < cstdlib> // std::strtod
3838#include < iostream>
@@ -403,66 +403,145 @@ class CommandSetColorTopology : public LineCommandBase<IngredientsType, Molecule
403403 float redEnd, greenEnd, blueEnd;
404404 readColor ( vex[2 ], &redEnd, &greenEnd, &blueEnd, " !setColorTopology (end)" );
405405
406- // color all monomers
407- /* for(uint32_t i = 0; i < ingredients.modifyMolecules().size(); i++)
408- {
409- if(ingredients.modifyMolecules().getNumLinks(i) == numLinks)
410- ingredients.modifyMolecules()[i].setColor( red ,green , blue);
411- }*/
412406
413- Graph treeGraph;
414407
408+ /* ################################################################ */
415409
416- Nodelist degreeNode; // Degree of node
410+ // if the coloring should be calculated using the systems larges topological distance, replace MonomerGroupsVector molecules_type by ingredients and the true index by the monomer index
411+ // do the coloring groupwise
412+ for (uint32_t groupIdx=0 ; groupIdx<molecules_type.size (); groupIdx++ ){
417413
418- for (int k= 0 ; k < ingredients.getMolecules ().size (); k++)
414+ // typedef std::map<NodeIdx, Nodelist> Graph;
415+ Graph treeGraph;
416+ // typedef std::map<NodeIdx, int> Nodelist;
417+ Nodelist degreeNode; // Degree of node
418+ for ( uint32_t k=0 ; k<molecules_type[groupIdx].size (); k++){
419+ // get the index from the group
420+ int32_t monoIdx (molecules_type[groupIdx].trueIndex (k));
421+ for ( uint32_t link=0 ; link< ingredients.getMolecules ().getNumLinks (monoIdx); link++){
422+ // connect from idxAA to idxBB with value ZZ
423+ // all (symmetric) connections
424+ treeGraph[monoIdx][ingredients.getMolecules ().getNeighborIdx (monoIdx, link)]=1 ;
425+ }
426+ // fill with degree of nodes
427+ degreeNode[monoIdx]=ingredients.getMolecules ().getNumLinks (monoIdx);
428+ }
429+
430+ // calculate eccentricity of graph for all nodes
431+ std::cout << " Calculate eccentricity can take time..." << std::endl;
432+ std::map<NodeIdx, int > eccentricity;
433+ // std::map<NodeIdx, Nodelist> distance;
434+
435+ for ( uint32_t k=0 ; k<molecules_type[groupIdx].size (); k++)
419436 {
420- for (int l = 0 ; l < ingredients.getMolecules ().getNumLinks (k); l++)
437+ NodeIdx startNode = molecules_type[groupIdx].trueIndex (k);
438+ Nodelist topo_distance;
439+ dijkstra (treeGraph, startNode, topo_distance);
440+
441+ int maxTopologicalDistance = 0 ;
442+
443+ for (Nodelist::iterator it=topo_distance.begin (); it!=topo_distance.end (); ++it)
421444 {
422- // connect from idxAA to idxBB with value ZZ
423- // all (symmetric) connections
424- treeGraph[k][ingredients.getMolecules ().getNeighborIdx (k, l)]=1 ;
445+ // std::cout<< startNode << " -> " << it->first << " => "<<it->second<<std::endl;
446+ // distance[startNode][it->first] = it->second;
425447
448+ if (maxTopologicalDistance < it->second )
449+ maxTopologicalDistance=it->second ;
426450 }
427- // fill with degree of nodes
428- degreeNode[k]=ingredients.getMolecules ().getNumLinks (k);
451+
452+ eccentricity[startNode]=maxTopologicalDistance;
453+ std::cout<< startNode << " -> eccentricity: " << eccentricity[startNode] <<std::endl;
429454 }
430455
456+ // calculate the radius of the graph = min eccentricity
457+ int radiusGraph = std::numeric_limits<int >::max ();
431458
432- // finding the center of the tree (either one or two)
433- NodeVector centerNodes;
434- findCentersOfTree (treeGraph, degreeNode, centerNodes);
459+ for (std::map<NodeIdx, int >::iterator it_ecc=eccentricity.begin (); it_ecc!=eccentricity.end (); ++it_ecc)
460+ {
461+ if (it_ecc->second < radiusGraph)
462+ radiusGraph = it_ecc->second ;
463+ }
464+ std::cout << " Radius Graph = " << radiusGraph <<std::endl;
435465
436- // calculate the topological distance of center to all nodes and fill histogram
437- NodeVector::iterator itv;
438- for (itv=centerNodes.begin (); itv!=centerNodes.end (); ++itv){
466+ // calculate center nodes: eccentricity[center] == radiusGraph
467+ NodeVector centerGraph;
468+ for (std::map<NodeIdx, int >::iterator it_ecc=eccentricity.begin (); it_ecc!=eccentricity.end (); ++it_ecc)
469+ {
470+ if (it_ecc->second == radiusGraph)
471+ centerGraph.push_back (it_ecc->first );
472+ }
439473
474+ std::cout << " Center Graph = ( " ;
475+ for (NodeVector::iterator it_center=centerGraph.begin (); it_center!=centerGraph.end (); ++it_center){
476+ std::cout << *it_center << " : " ;
477+ }
478+ std::cout << " )" << std::endl;
440479
480+ // calculate the diameter of the graph = max eccentricity
481+ int diameterGraph = std::numeric_limits<int >::min ();
441482
442- NodeIdx startNode = (*itv);
443- std::cout << std::endl << " startNode: " << startNode << std::endl;
483+ for (std::map<NodeIdx, int >::iterator it_ecc=eccentricity.begin (); it_ecc!=eccentricity.end (); ++it_ecc)
484+ {
485+ if (diameterGraph < it_ecc->second )
486+ diameterGraph = it_ecc->second ;
487+ }
488+ std::cout << " Diameter Graph = " << diameterGraph <<std::endl;
444489
445- // idx -> distance from center
446- Nodelist topo_distance;
447- dijkstra (treeGraph, startNode, topo_distance);
448490
449- std::cout << " startNode -> node => distance" <<std::endl;
491+ // pick an arbitrary center node
492+ {
493+ NodeIdx startNode = centerGraph.at (0 );
494+ Nodelist topo_distance;
495+ dijkstra (treeGraph, startNode, topo_distance);
450496
451- int maxTopologicalDistance = 0 ;
497+ int maxTopologicalDistance = 0 ;
452498
453- Nodelist::iterator it;
454- for (it=topo_distance.begin (); it!=topo_distance.end (); ++it){
499+ for (Nodelist::iterator it=topo_distance.begin (); it!=topo_distance.end (); ++it)
500+ {
501+ // find the maximum topological distance from the tree center
502+ if (maxTopologicalDistance < it->second )
503+ maxTopologicalDistance=it->second ;
504+ }
505+
506+ std::cout<< startNode << " -> max center distance " << maxTopologicalDistance <<std::endl;
507+
508+
509+ /*
510+
511+ //finding the center of the tree (either one or two)
512+ //typedef std::vector<NodeIdx> NodeVector;
513+ NodeVector centerNodes;
514+ findCentersOfTree(treeGraph, degreeNode, centerNodes);
515+
516+ //calculate the topological distance of center to all nodes and fill histogram
517+ NodeVector::iterator itv;
518+
519+ for(itv=centerNodes.begin(); itv!=centerNodes.end(); ++itv){
520+ NodeIdx startNode = (*itv);
521+
522+
523+ // idx -> distance from center
524+ Nodelist topo_distance;
525+ dijkstra(treeGraph, startNode, topo_distance);
526+
527+ int maxTopologicalDistance = 0;
528+
529+
530+ Nodelist::iterator it;
531+ for(it=topo_distance.begin(); it!=topo_distance.end(); ++it){
532+ //find the maximum topological distance from the tree center
533+ if(maxTopologicalDistance < it->second)
534+ maxTopologicalDistance=it->second;
535+ }
536+
537+
538+ std::cout << "startNode -> node => distance" <<std::endl;
539+ */
455540
456- // std::cout<< startNode << " -> " << it->first << " => "<<it->second<<std::endl;
457541
458- // find the maximum topological distance from the tree center
459- if (maxTopologicalDistance < it->second )
460- maxTopologicalDistance=it->second ;
461- }
462- std::cout<< startNode << " -> max topological distance " << maxTopologicalDistance <<std::endl;
463542
464543 // color the structure
465- for (it=topo_distance.begin (); it!=topo_distance.end (); ++it){
544+ for (Nodelist::iterator it=topo_distance.begin (); it!=topo_distance.end (); ++it){
466545
467546 // std::cout<< startNode << " -> " << it->first << " => "<<it->second<<std::endl;
468547
@@ -480,7 +559,11 @@ class CommandSetColorTopology : public LineCommandBase<IngredientsType, Molecule
480559 }
481560
482561
483- }
562+
563+
564+
565+ }
566+ } // end loop monomerGroups
484567
485568
486569 return std::string (" apply color to all monomers with numTopology" );
@@ -1297,6 +1380,7 @@ class CommandGetHelp : public LineCommandBase<IngredientsType, MoleculesType>
12971380 " !setRadius:all=radius\n "
12981381 " !setRadiusAttributes:att=radius\n "
12991382 " !setRadiusLinks:numLinks=radius\n "
1300- " !setRadiusGroups:idxGroup=radius\n " );
1383+ " !setRadiusGroups:idxGroup=radius\n "
1384+ " !exit\n " );
13011385 }
13021386};
0 commit comments