Skip to content

Commit

Permalink
Backmerge: #3891 - Aromatize/Dearomatize of having abbreviation (Salt…
Browse files Browse the repository at this point in the history
…s and Solvents) on the canvas causes spontaneous random de-abbreviation (#4135)

- removed resetting sgroup id in restruct
- added setting sgroup id on deserialisation step
- added functional groups id mapping to link functional groups properly during struct merge

---------

Co-authored-by: Roman Rodionov <roman_rodionov@epam.com>
  • Loading branch information
rrodionov91 and rrodionov91 committed Feb 23, 2024
1 parent c872aa3 commit b20d718
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 9 deletions.
4 changes: 4 additions & 0 deletions packages/ketcher-core/src/application/render/renderStruct.ts
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,11 @@ export class RenderStruct {
return;
}

console.log('-----START-------');
console.log(struct.sgroups);
const preparedStruct = this.prepareStruct(struct);
console.log(preparedStruct.sgroups);
console.log('-----END-------');
preparedStruct.initHalfBonds();
preparedStruct.initNeighbors();
preparedStruct.setImplicitHydrogen();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ import {
Pile,
Pool,
RGroupAttachmentPoint,
SGroup,
Struct,
Vec2,
} from 'domain/entities';
Expand Down Expand Up @@ -154,9 +153,6 @@ class ReStruct {
this.sgroups.set(id, new ReSGroup(item));
if (item.type === 'DAT' && !item.data.attached) {
this.sgroupData.set(id, new ReDataSGroupData(item));
} // [MK] sort of a hack, we use the SGroup id for the data field id
if (FunctionalGroup.isFunctionalGroup(item) || SGroup.isSuperAtom(item)) {
this.molecule.functionalGroups.set(id, new FunctionalGroup(item));
}
});
}
Expand Down
10 changes: 8 additions & 2 deletions packages/ketcher-core/src/domain/entities/struct.ts
Original file line number Diff line number Diff line change
Expand Up @@ -281,7 +281,8 @@ export class Struct {
if (bondSet!.has(bid)) bidMap.set(bid, cp.bonds.add(bond.clone(aidMap!)));
});

this.sgroups.forEach((sg) => {
const sgroupIdMap = {};
this.sgroups.forEach((sg, sgroupId) => {
if (sg.atoms.some((aid) => !atomSet!.has(aid))) return;
const oldSgroup = sg;

Expand All @@ -293,6 +294,8 @@ export class Struct {
const id = cp.sgroups.add(sg);
sg.id = id;

sgroupIdMap[sgroupId] = id;

sg.atoms.forEach((aid) => {
const atom = cp.atoms.get(aid);
if (atom) {
Expand All @@ -306,7 +309,10 @@ export class Struct {

this.functionalGroups.forEach((fg) => {
if (fg.relatedSGroup.atoms.some((aid) => !atomSet!.has(aid))) return;
fg = FunctionalGroup.clone(fg);
const sgroup = cp.sgroups.get(sgroupIdMap[fg.relatedSGroupId]);
// It is possible that there is no sgroup in case of templates library rendering
// Sgroup is deleteing before render to show templates without brackets (see RenderStruct.prepareStruct method)
fg = sgroup ? new FunctionalGroup(sgroup) : FunctionalGroup.clone(fg);
cp.functionalGroups.add(fg);
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,9 +67,11 @@ export function moleculeToStruct(ketItem: any): Struct {
}

if (ketItem.sgroups) {
ketItem.sgroups.forEach((sgroup) =>
struct.sgroups.add(sgroupToStruct(sgroup)),
);
ketItem.sgroups.forEach((sgroupData) => {
const sgroup = sgroupToStruct(sgroupData);
const id = struct.sgroups.add(sgroup);
sgroup.id = id;
});
}

struct.initHalfBonds();
Expand Down

0 comments on commit b20d718

Please sign in to comment.