Hi Uli,

The code you have is the correct (almost) way to do it...  I'm not sure
a utility method is needed since it's simple/easy enough and clear what is
happening.

The more correct code should not create AtomContainer with new since the
main class ATM is actually AtomContainer2. So things will possibly break if
you do it with "new AtomContainer" - we can't hide the constructor as it
will break down stream code. If we're going to break APIs I would rather
delete AtomContainerSet :-) (it is not even a set!).





*IAtomContainer mergedAtomContainer =
atomContainerSet.getBuilder().newAtomContainer();for (IAtomContainer
atomContainer: atomContainerSet.atomContainers()) {
mergedAtomContainer.add(atomContainer);}*

Since you can do it in two (one if you don't count the new container
construction)



*IAtomContainer combined =
molset.getBuilder().newAtomContainer();molset.atomContainers().spliterator().forEachRemaining(combined::add);*

I presume you're dealing with reactions in which case please look at the
*ReactionManipulator.toMolecule()* function. This collapses the reaction
into a single flat molecule, but sets the ReactionRole and ReactionGroup
properties so you can reverse it or pick things/subset easier. In your
function hear if you come from a reaction you will remove any component
grouping - e.g. *[Na+].[Cl-].c1ccccc1>>* would be 2 AtomContainers in an
AtomContainerSet, if you convert this with your method then split again you
get 3 AtomContainers.

*More info on AtomContainer2*

AtomContainer2 will become AtomContainer shortly (example of errors you get
- https://github.com/cdk/cdk/issues/607, explanation -
https://github.com/cdk/cdk/wiki/AtomContainer2). Basically it's a backwards
compatible way of making the containers performant, but we needed a
staggered introduction.

Best,
John

On Thu, 1 Sept 2022 at 06:08, Uli Fechner <u...@pending.ai> wrote:

> Hi,
>
> I require the functionality to merge all IAtomContainers in an
> AtomContainerSet into a single IAtomContainer then having several
> disconnected components / graphs and couldn't find a suitable method in
> AtomContainerManipulator and AtomContainerSetManipulator.
>
> IAtomContainer mergedAtomContainer = new AtomContainer();
> for (IAtomContainer atomContainer: atomContainerSet.atomContainers()) {
>     mergedAtomContainer.add(atomContainer);
> }
>
> If this isn't in CDK (and it is not just me not being able to find it) I
> am happy to make a PR by adding a method, probably to
> AtomContainerSetManipulator.
>
> Best
> Uli
> _______________________________________________
> Cdk-user mailing list
> Cdk-user@lists.sourceforge.net
> https://lists.sourceforge.net/lists/listinfo/cdk-user
>
_______________________________________________
Cdk-user mailing list
Cdk-user@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/cdk-user

Reply via email to