From cbb822cf05e913d615bb8880cec09950f5d6bd53 Mon Sep 17 00:00:00 2001 From: Andrei Mazol <72735611+AndreiMazol@users.noreply.github.com> Date: Mon, 7 Jun 2021 19:56:57 +0300 Subject: [PATCH] #554 Stereocenter should disappear after replacing the stereobond with the dative bond or the double cis/trans bond (#575) * update priority of operations * fix flipping of dative bonds * recalculate stereo flag is cis/trans bond is used * set AtomAttr priority equals 1 --- .../src/script/editor/actions/bond.ts | 26 ++++++++++--------- .../script/editor/operations/atom/AtomAttr.ts | 6 ++--- .../script/editor/operations/atom/index.ts | 2 +- .../src/script/editor/operations/base.ts | 10 ++++--- 4 files changed, 25 insertions(+), 19 deletions(-) diff --git a/packages/ketcher-react/src/script/editor/actions/bond.ts b/packages/ketcher-react/src/script/editor/actions/bond.ts index 6b0a129116..f535b3480d 100644 --- a/packages/ketcher-react/src/script/editor/actions/bond.ts +++ b/packages/ketcher-react/src/script/editor/actions/bond.ts @@ -15,26 +15,25 @@ ***************************************************************************/ import { Atom, Bond, StereoLabel, Struct, Vec2 } from 'ketcher-core' - import { - FragmentAdd, AtomAdd, AtomAttr, BondAdd, BondAttr, - BondDelete + BondDelete, + FragmentAdd } from '../operations' -import utils from '../shared/utils' -import Action from '../shared/action' - -import { atomGetAttr, atomForNewBond, atomGetNeighbors } from './utils' +import { atomForNewBond, atomGetAttr, atomGetNeighbors } from './utils' import { fromAtomMerge, fromStereoAtomAttrs, mergeFragmentsIfNeeded, mergeSgroups } from './atom' + +import Action from '../shared/action' import ReStruct from '../../render/restruct' +import utils from '../shared/utils' export function fromBondAddition( restruct: ReStruct, @@ -172,7 +171,11 @@ export function fromBondStereoUpdate( let bond = struct.bonds.get(bid) const action = new Action() - if (bond?.stereo === Bond.PATTERN.STEREO.NONE) { + if ( + bond && + (bond.stereo === Bond.PATTERN.STEREO.NONE || + bond.type === Bond.PATTERN.TYPE.DOUBLE) + ) { const neigs = atomGetNeighbors(restruct, bond.begin) const stereoNeig = neigs.find(item => { const bond = struct.bonds.get(item.bid) @@ -232,8 +235,9 @@ export function bondChangingAction( bondProps: any ): Action { if ( - bondProps.stereo !== Bond.PATTERN.STEREO.NONE && // - bondProps.type === Bond.PATTERN.TYPE.SINGLE && + ((bondProps.stereo !== Bond.PATTERN.STEREO.NONE && // + bondProps.type === Bond.PATTERN.TYPE.SINGLE) || + bond.type === Bond.PATTERN.TYPE.DATIVE) && bond.type === bondProps.type && bond.stereo === bondProps.stereo ) @@ -262,8 +266,6 @@ function bondFlipRequired(struct: Struct, bond: Bond, attrs: any): boolean { if (!bondBegin || !bondBegin.neighbors || !bondEnd || !bondEnd.neighbors) return false - if (attrs.type === Bond.PATTERN.TYPE.DATIVE) return true - return ( attrs.type === Bond.PATTERN.TYPE.SINGLE && bond.stereo === Bond.PATTERN.STEREO.NONE && diff --git a/packages/ketcher-react/src/script/editor/operations/atom/AtomAttr.ts b/packages/ketcher-react/src/script/editor/operations/atom/AtomAttr.ts index a0c7287276..d48e3355d2 100644 --- a/packages/ketcher-react/src/script/editor/operations/atom/AtomAttr.ts +++ b/packages/ketcher-react/src/script/editor/operations/atom/AtomAttr.ts @@ -1,3 +1,5 @@ +import { BaseOperation } from '../base' +import { OperationType } from '../OperationType' /**************************************************************************** * Copyright 2021 EPAM Systems * @@ -14,8 +16,6 @@ * limitations under the License. ***************************************************************************/ import Restruct from '../../../render/restruct' -import { BaseOperation } from '../base' -import { OperationType } from '../OperationType' type Data = { aid?: any @@ -28,7 +28,7 @@ export class AtomAttr extends BaseOperation { data2: Data | null constructor(atomId?: any, attribute?: any, value?: any) { - super(OperationType.ATOM_ATTR, 2) + super(OperationType.ATOM_ATTR, 1) this.data = { aid: atomId, attribute, value } this.data2 = null } diff --git a/packages/ketcher-react/src/script/editor/operations/atom/index.ts b/packages/ketcher-react/src/script/editor/operations/atom/index.ts index 4749d72516..21f658aca1 100644 --- a/packages/ketcher-react/src/script/editor/operations/atom/index.ts +++ b/packages/ketcher-react/src/script/editor/operations/atom/index.ts @@ -31,7 +31,7 @@ class AtomAdd extends BaseOperation { data: Data constructor(atom?: any, pos?: any) { - super(OperationType.ATOM_ADD, 1) + super(OperationType.ATOM_ADD) this.data = { atom, pos, aid: null } } diff --git a/packages/ketcher-react/src/script/editor/operations/base.ts b/packages/ketcher-react/src/script/editor/operations/base.ts index 8118b48170..db2f4ed0b9 100644 --- a/packages/ketcher-react/src/script/editor/operations/base.ts +++ b/packages/ketcher-react/src/script/editor/operations/base.ts @@ -14,10 +14,9 @@ * limitations under the License. ***************************************************************************/ +import { OperationType } from './OperationType' // todo: rename file in another PR import Restruct from '../../render/restruct' -import { OperationType } from './OperationType' - import { StereLabelStyleType } from '../../render/restruct/GeneralEnumTypes' type ValueOf = Readonly @@ -126,7 +125,12 @@ class BaseOperation { BaseOperation.invalidateAtom(restruct, bond.b.end, 0) } - protected static invalidateItem(restruct: Restruct, map, id: number, level?) { + protected static invalidateItem( + restruct: Restruct, + map, + id: number, + level?: any + ) { if (map === 'atoms') { BaseOperation.invalidateAtom(restruct, id, level) return