sub find_symmetry { my $compound = shift @_; $$compound{Symmetries} = []; my $M_matrix = $$compound{Mapping}; my $A_matrix = $$compound{Adjacency}; my @isomorphs; my $row = 0; my $dimension = $#$A_matrix; my @indices = (0..$dimension); my @reverse = reverse @indices; my @used = map {0;} (@indices); my @mapping = map {-1;} (@indices); my (@sm_rows, @same_rows); foreach my $row (@$A_matrix) { push @sm_rows, $row; } foreach my $row (@$M_matrix) { push @same_rows, $row;} my $equate_sub = sub { for (reverse(0..$row)) { my (@smrow, @omrow); alias @smrow = @{$sm_rows[$_]}; alias @omrow = @{$sm_rows[$mapping[$_]]}; for (0..$row) { if ($smrow[$_] != $omrow[$mapping[$_]]) { return 0; } } } return 1; }; LOOP: while(1) { do { $mapping[$row] ++ } while ( $mapping[$row] <= $dimension and ($used[$mapping[$row]] == 1 || $same_rows[$row][$mapping[$row]] == 0 )); next if ($mapping[$row] > $dimension); if ( $row == $dimension ) { OUTER: { for (@indices) { my (@smrow2, @omrow2); alias @smrow2 = @{$sm_rows[$_]}; alias @omrow2 = @{$sm_rows[$mapping[$_]]}; for (@reverse) { if ( $smrow2[$_] != $omrow2[$mapping[$_]] ) { last OUTER; } } } push @{$$compound{Symmetries}}, [@mapping]; # print join(",",@mapping), "\n"; } } elsif ( $row == 0 or &$equate_sub == 1 ) { $used[$mapping[$row]] = 1; $row++; } } continue { while ( $row >= 0 and $mapping[$row] >= $dimension ) { last LOOP if ($row == 0); $mapping[$row] = -1; $row --; $used[$mapping[$row]] = 0; } } $$compound{Mapping} = undef; $$compound{Adjacency} = undef; # return \@isomorphs; }