Skip to content

Commit

Permalink
#3846 - macro class field is absent after serialisation to ket
Browse files Browse the repository at this point in the history
Co-authored-by: Konstantin Zharich <kostantin_zharich@epam.com>
  • Loading branch information
Konstantin1996 and Konstantin Zharich authored Jan 18, 2024
1 parent 8a138a9 commit 116430c
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -347,6 +347,7 @@
]
}
],
"class": "Base",
"classHELM": "RNA",
"id": "baA___N-benzyl-adenine",
"fullName": "N-benzyl-adenine",
Expand Down Expand Up @@ -532,6 +533,7 @@
]
}
],
"class": "Sugar",
"classHELM": "RNA",
"id": "12ddR___1',2'-Di-Deoxy-Ribose",
"fullName": "2'-Di-Deoxy-Ribose",
Expand Down Expand Up @@ -638,6 +640,7 @@
]
}
],
"class": "Phosphate",
"classHELM": "RNA",
"id": "P___Phosphate",
"fullName": "Phosphate",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<T> = new (...args: unknown[]) => T;
export const MONOMER_CONST = {
Expand Down Expand Up @@ -41,11 +41,11 @@ export const monomerFactory = (
): [
Monomer: Monomer,
MonomerRenderer: DerivedClass<BaseMonomerRenderer>,
monomerClass: monomerClass,
ketMonomerClass: ketMonomerClass,
] => {
let Monomer;
let MonomerRenderer;
let monomerClass: monomerClass;
let ketMonomerClass: ketMonomerClass;

if (
monomer.props.MonomerType === MONOMER_CONST.CHEM ||
Expand All @@ -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];
};
10 changes: 10 additions & 0 deletions packages/ketcher-core/src/application/formatters/types/ket.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -470,15 +473,15 @@ export class KetSerializer implements Serializer<Struct> {
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,
Expand Down

0 comments on commit 116430c

Please sign in to comment.