Skip to content

Commit

Permalink
#5335 - The application crashes when selecting Enhanced Stereochemist…
Browse files Browse the repository at this point in the history
…ry from the right-click menu (#5342) (#5348)

- added set stereo labels to atoms to setMolecule
  • Loading branch information
rrodionov91 authored Aug 23, 2024
1 parent db13a9c commit b5a9b01
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 23 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@
* limitations under the License.
***************************************************************************/

import { Box2Abs, Vec2 } from 'domain/entities';

import { Box2Abs } from 'domain/entities/box2Abs';
import { Vec2 } from 'domain/entities/vec2';
import { LayerMap } from './generalEnumTypes';
import ReObject from './reobject';
import { Scale } from 'domain/helpers';
Expand Down
1 change: 1 addition & 0 deletions packages/ketcher-core/src/application/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ export async function prepareStructToRender(
struct.initHalfBonds();
struct.initNeighbors();
struct.setImplicitHydrogen();
struct.setStereoLabelsToAtoms();
struct.markFragments();

return struct;
Expand Down
22 changes: 21 additions & 1 deletion packages/ketcher-core/src/domain/entities/struct.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@

import assert from 'assert';
import { Atom, radicalElectrons } from './atom';
import { EditorSelection } from 'application/editor';
import { EditorSelection, getStereoAtomsMap } from 'application/editor';
import { Bond } from './bond';
import { Box2Abs } from './box2Abs';
import { Elements } from 'domain/constants';
Expand Down Expand Up @@ -1073,6 +1073,26 @@ export class Struct {
}
}

public setStereoLabelsToAtoms() {
const stereAtomsMap = getStereoAtomsMap(
this,
Array.from(this.bonds.values()),
);

this.atoms.forEach((atom, id) => {
if (this?.atomGetNeighbors(id)?.length === 0) {
atom.stereoLabel = null;
atom.stereoParity = 0;
} else {
const stereoProp = stereAtomsMap.get(id);
if (stereoProp) {
atom.stereoLabel = stereoProp.stereoLabel;
atom.stereoParity = stereoProp.stereoParity;
}
}
});
}

atomGetNeighbors(aid: number): Array<Neighbor> | undefined {
return this.atoms.get(aid)?.neighbors.map((nei) => {
const hb = this.halfBonds.get(nei)!;
Expand Down
21 changes: 1 addition & 20 deletions packages/ketcher-react/src/script/ui/state/shared.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ import {
FormatterFactory,
Pile,
SGroup,
getStereoAtomsMap,
identifyStructFormat,
Struct,
SupportedFormat,
Expand Down Expand Up @@ -186,25 +185,7 @@ export function load(struct: Struct, options?) {

parsedStruct.findConnectedComponents();
parsedStruct.setImplicitHydrogen();

const stereAtomsMap = getStereoAtomsMap(
parsedStruct,
Array.from(parsedStruct.bonds.values()),
);

parsedStruct.atoms.forEach((atom, id) => {
if (parsedStruct?.atomGetNeighbors(id)?.length === 0) {
atom.stereoLabel = null;
atom.stereoParity = 0;
} else {
const stereoProp = stereAtomsMap.get(id);
if (stereoProp) {
atom.stereoLabel = stereoProp.stereoLabel;
atom.stereoParity = stereoProp.stereoParity;
}
}
});

parsedStruct.setStereoLabelsToAtoms();
parsedStruct.markFragments();

if (fragment) {
Expand Down

0 comments on commit b5a9b01

Please sign in to comment.