From ce018cbd9c62b02f9468506061b9bd339f16248a Mon Sep 17 00:00:00 2001 From: Roman Rodionov Date: Wed, 3 Jul 2024 14:46:29 +0200 Subject: [PATCH] #4973 - Connection between molecule and monomer lost after opening and saving to ket - fixed monomer atoms ids mapping during struct clone --- .../src/domain/entities/monomerMicromolecule.ts | 9 +++++++-- packages/ketcher-core/src/domain/entities/struct.ts | 2 +- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/packages/ketcher-core/src/domain/entities/monomerMicromolecule.ts b/packages/ketcher-core/src/domain/entities/monomerMicromolecule.ts index bf402bc12f..81bd9be656 100644 --- a/packages/ketcher-core/src/domain/entities/monomerMicromolecule.ts +++ b/packages/ketcher-core/src/domain/entities/monomerMicromolecule.ts @@ -30,13 +30,18 @@ export class MonomerMicromolecule extends SGroup { return { position: this.pp, atomId: sgroupContractedPosition.atomId }; } - public static clone(monomerMicromolecule: MonomerMicromolecule) { + public static clone( + monomerMicromolecule: MonomerMicromolecule, + atomIdMap?: Map, + ) { const monomerMicromoleculeClone = new MonomerMicromolecule( monomerMicromolecule.type, monomerMicromolecule.monomer, ); monomerMicromoleculeClone.pp = monomerMicromolecule.pp; - monomerMicromoleculeClone.atoms = monomerMicromolecule.atoms; + monomerMicromoleculeClone.atoms = atomIdMap + ? monomerMicromolecule.atoms.map((elem) => atomIdMap.get(elem)) + : monomerMicromolecule.atoms; return monomerMicromoleculeClone; } diff --git a/packages/ketcher-core/src/domain/entities/struct.ts b/packages/ketcher-core/src/domain/entities/struct.ts index b173ce5593..0b12554407 100644 --- a/packages/ketcher-core/src/domain/entities/struct.ts +++ b/packages/ketcher-core/src/domain/entities/struct.ts @@ -293,7 +293,7 @@ export class Struct { sg = oldSgroup instanceof MonomerMicromolecule - ? MonomerMicromolecule.clone(oldSgroup) + ? MonomerMicromolecule.clone(oldSgroup, aidMap!) : SGroup.clone(sg, aidMap!); const id = cp.sgroups.add(sg);