Skip to content

Commit

Permalink
#554 Stereocenter should disappear after replacing the stereobond wit…
Browse files Browse the repository at this point in the history
…h 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
  • Loading branch information
AndreiMazol authored Jun 7, 2021
1 parent dcccda8 commit cbb822c
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 19 deletions.
26 changes: 14 additions & 12 deletions packages/ketcher-react/src/script/editor/actions/bond.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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
)
Expand Down Expand Up @@ -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 &&
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import { BaseOperation } from '../base'
import { OperationType } from '../OperationType'
/****************************************************************************
* Copyright 2021 EPAM Systems
*
Expand All @@ -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
Expand All @@ -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
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 }
}

Expand Down
10 changes: 7 additions & 3 deletions packages/ketcher-react/src/script/editor/operations/base.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<TObject extends object> = Readonly<TObject[keyof TObject]>
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit cbb822c

Please sign in to comment.