Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Backmerge: #5335 - The application crashes when selecting Enhanced Stereochemistry from the right-click menu #5349

Merged
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading