From 116430c5f13714cc41fb39a308cb5aea52b65a7f Mon Sep 17 00:00:00 2001 From: konstantinzharich Date: Thu, 18 Jan 2024 16:34:00 +0100 Subject: [PATCH] #3846 - macro class field is absent after serialisation to ket Co-authored-by: Konstantin Zharich --- .../monomers-connected-with-bonds-expected.ket | 3 +++ .../operations/monomer/monomerFactory.ts | 18 +++++++++--------- .../src/application/formatters/types/ket.ts | 10 ++++++++++ .../domain/serializers/ket/ketSerializer.ts | 9 ++++++--- 4 files changed, 28 insertions(+), 12 deletions(-) diff --git a/ketcher-autotests/tests/test-data/KET/monomers-connected-with-bonds-expected.ket b/ketcher-autotests/tests/test-data/KET/monomers-connected-with-bonds-expected.ket index fbcb54d4de..22844c143a 100644 --- a/ketcher-autotests/tests/test-data/KET/monomers-connected-with-bonds-expected.ket +++ b/ketcher-autotests/tests/test-data/KET/monomers-connected-with-bonds-expected.ket @@ -347,6 +347,7 @@ ] } ], + "class": "Base", "classHELM": "RNA", "id": "baA___N-benzyl-adenine", "fullName": "N-benzyl-adenine", @@ -532,6 +533,7 @@ ] } ], + "class": "Sugar", "classHELM": "RNA", "id": "12ddR___1',2'-Di-Deoxy-Ribose", "fullName": "2'-Di-Deoxy-Ribose", @@ -638,6 +640,7 @@ ] } ], + "class": "Phosphate", "classHELM": "RNA", "id": "P___Phosphate", "fullName": "Phosphate", diff --git a/packages/ketcher-core/src/application/editor/operations/monomer/monomerFactory.ts b/packages/ketcher-core/src/application/editor/operations/monomer/monomerFactory.ts index 74d9e0ea33..0403969087 100644 --- a/packages/ketcher-core/src/application/editor/operations/monomer/monomerFactory.ts +++ b/packages/ketcher-core/src/application/editor/operations/monomer/monomerFactory.ts @@ -12,7 +12,7 @@ import { Chem } from 'domain/entities/Chem'; import { Sugar } from 'domain/entities/Sugar'; import { Phosphate } from 'domain/entities/Phosphate'; import { RNABase } from 'domain/entities/RNABase'; -import { monomerClass } from 'application/formatters/types/ket'; +import { ketMonomerClass } from 'application/formatters/types/ket'; type DerivedClass = new (...args: unknown[]) => T; export const MONOMER_CONST = { @@ -41,11 +41,11 @@ export const monomerFactory = ( ): [ Monomer: Monomer, MonomerRenderer: DerivedClass, - monomerClass: monomerClass, + ketMonomerClass: ketMonomerClass, ] => { let Monomer; let MonomerRenderer; - let monomerClass: monomerClass; + let ketMonomerClass: ketMonomerClass; if ( monomer.props.MonomerType === MONOMER_CONST.CHEM || @@ -55,26 +55,26 @@ export const monomerFactory = ( ) { Monomer = Chem; MonomerRenderer = ChemRenderer; - monomerClass = 'CHEM'; + ketMonomerClass = 'CHEM'; } else if (monomer.props.MonomerType === MONOMER_CONST.PEPTIDE) { Monomer = Peptide; MonomerRenderer = PeptideRenderer; - monomerClass = 'PEPTIDE'; + ketMonomerClass = 'AminoAcid'; } else { if (monomer.props.MonomerNaturalAnalogCode === MONOMER_CONST.R) { Monomer = Sugar; MonomerRenderer = SugarRenderer; - monomerClass = 'RNA'; + ketMonomerClass = 'Sugar'; } else if (monomer.props.MonomerNaturalAnalogCode === MONOMER_CONST.P) { Monomer = Phosphate; MonomerRenderer = PhosphateRenderer; - monomerClass = 'RNA'; + ketMonomerClass = 'Phosphate'; } else { Monomer = RNABase; MonomerRenderer = RNABaseRenderer; - monomerClass = 'RNA'; + ketMonomerClass = 'Base'; } } - return [Monomer, MonomerRenderer, monomerClass]; + return [Monomer, MonomerRenderer, ketMonomerClass]; }; diff --git a/packages/ketcher-core/src/application/formatters/types/ket.ts b/packages/ketcher-core/src/application/formatters/types/ket.ts index 69379db434..33672e38ad 100644 --- a/packages/ketcher-core/src/application/formatters/types/ket.ts +++ b/packages/ketcher-core/src/application/formatters/types/ket.ts @@ -38,6 +38,16 @@ export type monomerClass = | 'DNA' | 'MODDNA'; +export type ketMonomerClass = + | 'AminoAcid' + | 'Sugar' + | 'Phosphate' + | 'Base' + | 'Terminator' + | 'Linker' + | 'Unknown' + | 'CHEM'; + export type IKetAttachmentPointType = 'left' | 'right' | 'side'; export interface IKetAttachmentPoint { diff --git a/packages/ketcher-core/src/domain/serializers/ket/ketSerializer.ts b/packages/ketcher-core/src/domain/serializers/ket/ketSerializer.ts index 497b17796b..1aa56c5031 100644 --- a/packages/ketcher-core/src/domain/serializers/ket/ketSerializer.ts +++ b/packages/ketcher-core/src/domain/serializers/ket/ketSerializer.ts @@ -42,7 +42,10 @@ import { monomerToDrawingEntity } from 'domain/serializers/ket/fromKet/monomerTo import assert from 'assert'; import { polymerBondToDrawingEntity } from 'domain/serializers/ket/fromKet/polymerBondToDrawingEntity'; import { getMonomerUniqueKey } from 'domain/helpers/monomers'; -import { MONOMER_CONST } from 'application/editor/operations/monomer/monomerFactory'; +import { + MONOMER_CONST, + monomerFactory, +} from 'application/editor/operations/monomer/monomerFactory'; import { KetcherLogger } from 'utilities'; import { Chem } from 'domain/entities/Chem'; import { DrawingEntitiesManager } from 'domain/entities/DrawingEntitiesManager'; @@ -470,15 +473,15 @@ export class KetSerializer implements Serializer { seqid: monomer.monomerItem.seqId, }; fileContent.root.nodes.push(getKetRef(monomerName)); + const [, , monomerClass] = monomerFactory(monomer.monomerItem); const templateNameWithPrefix = setMonomerTemplatePrefix(templateId); - if (!fileContent[templateNameWithPrefix]) { fileContent[templateNameWithPrefix] = { ...JSON.parse( this.serializeMicromolecules(monomer.monomerItem.struct, monomer), ).mol0, type: 'monomerTemplate', - class: monomer.monomerItem.props.MonomerClass, + class: monomer.monomerItem.props.MonomerClass || monomerClass, classHELM: monomer.monomerItem.props.MonomerType, id: templateId, fullName: monomer.monomerItem.props.Name,