Chemistry-Mol

 view release on metacpan or  search on metacpan

lib/Chemistry/Mol.pm  view on Meta::CPAN

        }
        for my $bond ($mol2->bonds) {
            $mol->add_bond($bond);
        }
    }
    $mol;
}

=item my @mols = $mol->separate

Separates a molecule into "connected fragments". The original object is not
modified; the fragments are clones of the original ones. Example: if you have
ethane (H3CCH3) and you delete the C-C bond, you have two CH3 radicals within
one molecule object ($mol). When you call $mol->separate you get two molecules,
each one with a CH3.

=cut

# splits a molecule into connected fragments
# returns a list of molecules. Does not touch the original copy.
sub separate {
    my ($self) = @_;
    $self = $self->clone;
    my $unseen = set($self->atoms);
    my $open = set;
    my %colors;
    my $color = 0;
    while (!$unseen->is_null) {
        my ($first) = $unseen->members;



( run in 0.946 second using v1.01-cache-2.11-cpan-364913b4093 )