public AbstractMolecule merge ( AbstractMolecule firstContainer , IAtomBase firstRgroup , AbstractMolecule secondContainer , IAtomBase secondRgroup ) throws CTKException { if ( firstContainer . isSingleStereo ( firstRgroup ) && secondContainer . isSingleStereo ( secondRgroup ) ) { throw new CTKException ( "Both R atoms are connected to chiral centers" ) ; } if ( firstContainer == secondContainer ) { firstContainer . dearomatize ( ) ; secondContainer . dearomatize ( ) ; IAtomBase atom1 = getNeighborAtom ( firstRgroup ) ; IAtomBase atom2 = getNeighborAtom ( secondRgroup ) ; firstContainer . removeAttachment ( firstRgroup ) ; firstContainer . removeAttachment ( secondRgroup ) ; setStereoInformation ( firstContainer , firstRgroup , firstContainer , secondRgroup , atom1 , atom2 ) ; firstContainer . removeINode ( firstRgroup ) ; firstContainer . removeINode ( secondRgroup ) ; } else { firstContainer . dearomatize ( ) ; secondContainer . dearomatize ( ) ; IAtomBase atom1 = getNeighborAtom ( firstRgroup ) ; IAtomBase atom2 = getNeighborAtom ( secondRgroup ) ; firstContainer . removeAttachment ( firstRgroup ) ; secondContainer . removeAttachment ( secondRgroup ) ; setStereoInformation ( firstContainer , firstRgroup , secondContainer , secondRgroup , atom1 , atom2 ) ; firstContainer . removeINode ( firstRgroup ) ; secondContainer . removeINode ( secondRgroup ) ; AttachmentList mergedAttachments = mergeAttachments ( firstContainer , secondContainer ) ; firstContainer . addIBase ( secondContainer ) ; firstContainer . setAttachments ( mergedAttachments ) ; } return firstContainer ; }
merges second molecule to first using given rGroups