The connectivity checker can be use to split a molecule by breaking bonds. We should document and test this use case more, one corner case not currently handled is the Sgroups. We need to check if a split molecule can inherit and Sgroup correctly.
Also an optimisation is to avoid the copy if there is only a single component. This is now super simple as the SDG seems to depend on some invariant that the molecule but not the atoms/bonds got copied so that needs to be investigated.
public static IAtomContainerSet partitionIntoMolecules(IAtomContainer container) {
ConnectedComponents cc = new ConnectedComponents(GraphUtil.toAdjList(container));
if (cc.nComponents() == 1) {
IAtomContainerSet acset = container.getBuilder().newInstance(IAtomContainerSet.class);
acset.addAtomContainer(container);
return acset;
}
return partitionIntoMolecules(container, cc.components());
}
The connectivity checker can be use to split a molecule by breaking bonds. We should document and test this use case more, one corner case not currently handled is the Sgroups. We need to check if a split molecule can inherit and Sgroup correctly.
Also an optimisation is to avoid the copy if there is only a single component. This is now super simple as the SDG seems to depend on some invariant that the molecule but not the atoms/bonds got copied so that needs to be investigated.