-
Notifications
You must be signed in to change notification settings - Fork 187
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Backmerge: #5335 - The application crashes when selecting Enhanced St…
…ereochemistry from the right-click menu (#5349) - added set stereo labels to atoms to setMolecule
- Loading branch information
1 parent
ceed0ac
commit 06bf272
Showing
6 changed files
with
117 additions
and
116 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
91 changes: 91 additions & 0 deletions
91
packages/ketcher-core/src/application/editor/actions/helpers.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,91 @@ | ||
import { Atom, Bond, Neighbor, StereoLabel, Struct } from 'domain/entities'; | ||
import { StereoValidator } from 'domain/helpers'; | ||
|
||
export function getStereoAtomsMap( | ||
struct: Struct, | ||
bonds: Array<Bond>, | ||
bond?: Bond, | ||
) { | ||
const stereoAtomsMap = new Map(); | ||
const correctAtomIds: Array<number> = []; | ||
|
||
bonds.forEach((bond: Bond | undefined) => { | ||
if (bond) { | ||
const beginNeighs: Array<Neighbor> | undefined = struct.atomGetNeighbors( | ||
bond.begin, | ||
); | ||
const endNeighs: Array<Neighbor> | undefined = struct.atomGetNeighbors( | ||
bond.end, | ||
); | ||
|
||
if ( | ||
StereoValidator.isCorrectStereoCenter( | ||
bond, | ||
beginNeighs, | ||
endNeighs, | ||
struct, | ||
) | ||
) { | ||
const stereoLabel = struct.atoms.get(bond.begin)?.stereoLabel; | ||
if ( | ||
stereoLabel == null || | ||
stereoAtomsMap.get(bond.begin)?.stereoLabel == null | ||
) { | ||
stereoAtomsMap.set(bond.begin, { | ||
stereoParity: getStereoParity(bond.stereo), | ||
stereoLabel: stereoLabel || `${StereoLabel.Abs}`, | ||
}); | ||
} | ||
correctAtomIds.push(bond.begin); | ||
} else { | ||
if (!correctAtomIds.includes(bond.begin)) { | ||
stereoAtomsMap.set(bond.begin, { | ||
stereoParity: Atom.PATTERN.STEREO_PARITY.NONE, | ||
stereoLabel: null, | ||
}); | ||
} | ||
if (!correctAtomIds.includes(bond.end)) { | ||
stereoAtomsMap.set(bond.end, { | ||
stereoParity: Atom.PATTERN.STEREO_PARITY.NONE, | ||
stereoLabel: null, | ||
}); | ||
} | ||
} | ||
} | ||
}); | ||
|
||
// in case the stereo band is flipped, changed or removed | ||
// TODO the duplication of the code below should be fixed, mayby by function | ||
if (bond) { | ||
if (!correctAtomIds.includes(bond.begin)) { | ||
stereoAtomsMap.set(bond.begin, { | ||
stereoParity: Atom.PATTERN.STEREO_PARITY.NONE, | ||
stereoLabel: null, | ||
}); | ||
} | ||
if (!correctAtomIds.includes(bond.end)) { | ||
stereoAtomsMap.set(bond.end, { | ||
stereoParity: Atom.PATTERN.STEREO_PARITY.NONE, | ||
stereoLabel: null, | ||
}); | ||
} | ||
} | ||
|
||
return stereoAtomsMap; | ||
} | ||
|
||
function getStereoParity(stereo: number): number | null { | ||
let newAtomParity: number | null = null; | ||
switch (stereo) { | ||
case Bond.PATTERN.STEREO.UP: | ||
newAtomParity = Atom.PATTERN.STEREO_PARITY.ODD; | ||
break; | ||
case Bond.PATTERN.STEREO.EITHER: | ||
newAtomParity = Atom.PATTERN.STEREO_PARITY.EITHER; | ||
break; | ||
case Bond.PATTERN.STEREO.DOWN: | ||
newAtomParity = Atom.PATTERN.STEREO_PARITY.EVEN; | ||
break; | ||
} | ||
return newAtomParity; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters