Skip to content

Commit

Permalink
#2273 When user selects and moves atom on Functional Group or Salt it…
Browse files Browse the repository at this point in the history
… doesn't replaces atom in the structure (#2568)

* #2273 - when using the select tool to drag and drop an atom, it replaces the functinal group or salt

* #2273 - select atom drop and merge action now checks for attachment atoms in case extra neighbours are presented

* #2273 - redundant extra neighbour check cut

* #2273 - fragment bonds explicit remove added

---------

Co-authored-by: Dmitrii Vasilev <dmitrii.vasilev@clarivate.com>
  • Loading branch information
VasilevDO and Dmitrii Vasilev committed May 3, 2023
1 parent 81ace02 commit dff3ffc
Showing 1 changed file with 14 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -91,32 +91,29 @@ function extractAttachmentAtom(mergeItems: MergeItems, editor: Editor) {
atoms: new Map(mergeItems.atoms),
bonds: new Map(mergeItems.bonds)
}
const removeNonAttachmentAtoms = new Action()
const removeSGroup = new Action()

const action = new Action()

mergeItems.atomToFunctionalGroup?.forEach((functionalGroupId, srcAtomId) => {
const sGroup = struct.sgroups.get(functionalGroupId)
const attachmentAtomId = sGroup?.getAttAtomId(struct)

if (attachmentAtomId) {
const attachmentAtom = struct.atoms.get(attachmentAtomId)
if (SGroup.isAtomInContractedSGroup(attachmentAtom, struct.sgroups)) {
return
}
newMergeItems.atoms.set(srcAtomId, attachmentAtomId)
const attachmentAtomId = sGroup?.getAttAtomId(struct)

removeNonAttachmentAtoms.mergeWith(
if (attachmentAtomId !== undefined) {
const atomsToDelete = [...SGroup.getAtoms(struct, sGroup)].filter(
(atomId) => atomId !== attachmentAtomId
)
const bondsToDelete = [...SGroup.getBonds(struct, sGroup)]
action.mergeWith(fromSgroupDeletion(reStruct, functionalGroupId))
action.mergeWith(
fromFragmentDeletion(reStruct, {
atoms: [...SGroup.getAtoms(struct, sGroup)].filter(
(atomId) => atomId !== attachmentAtomId
),
bonds: [...SGroup.getBonds(struct, sGroup)]
atoms: atomsToDelete,
bonds: bondsToDelete
})
)

removeSGroup.mergeWith(fromSgroupDeletion(reStruct, functionalGroupId))
newMergeItems.atoms.set(srcAtomId, attachmentAtomId)
}
})

return [newMergeItems, removeNonAttachmentAtoms] as const
return [newMergeItems, action] as const
}

0 comments on commit dff3ffc

Please sign in to comment.