Skip to content

Commit

Permalink
Molecule.fragmented: maintain atom numbers in fragments
Browse files Browse the repository at this point in the history
do not renumber atoms for fragments
  • Loading branch information
ybyygu committed Feb 9, 2024
1 parent e6df6af commit 4352b60
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions src/topology.rs
Original file line number Diff line number Diff line change
Expand Up @@ -89,9 +89,13 @@ impl Molecule {

/// Break molecule into multiple fragments based on its bonding
/// connectivity. Return molecules whole connected by bonds
/// without periodic lattice
/// without periodic lattice. The atom numbers in fragments will
/// be the same as in their parent.
pub fn fragmented(&self) -> impl Iterator<Item = Self> + '_ {
self.graph().connected_components().map(|g| Molecule::from_graph(g))
self.graph().connected_components().map(|g| {
let numbers: Vec<_> = g.node_indices().map(|n| self.atom_sn(n)).collect();
Molecule::from_graph_raw(g, numbers)
})
}

/// Return the number of fragments based on bonding connectivity.
Expand Down

0 comments on commit 4352b60

Please sign in to comment.