diff --git a/packages/ketcher-core/src/application/render/restruct/reatom.ts b/packages/ketcher-core/src/application/render/restruct/reatom.ts index 718d34b260..e0bd6a7c58 100644 --- a/packages/ketcher-core/src/application/render/restruct/reatom.ts +++ b/packages/ketcher-core/src/application/render/restruct/reatom.ts @@ -1079,9 +1079,13 @@ function getRingBondCountAttrText(value: number) { let attrText: string; if (value > 0) { attrText = 'rb' + value.toString(); - } else if (value === -1) attrText = 'rb0'; - else if (value === -2) attrText = 'rb*'; - else throw new Error('Ring bond count invalid'); + } else if (value === -1) { + attrText = 'rb0'; + } else if (value === -2) { + attrText = 'rb*'; + } else { + throw new Error('Ring bond count invalid'); + } return attrText; } @@ -1089,9 +1093,13 @@ function getSubstitutionCountAttrText(value: number) { let attrText: string; if (value > 0) { attrText = 's' + value.toString(); - } else if (value === -1) attrText = 's0'; - else if (value === -2) attrText = 's*'; - else throw new Error('Substitution count invalid'); + } else if (value === -1) { + attrText = 's0'; + } else if (value === -2) { + attrText = 's*'; + } else { + throw new Error('Substitution count invalid'); + } return attrText; } @@ -1178,19 +1186,11 @@ function getQueryAttrsText(atom, isAromatized: boolean) { return customQuery; } if (ringBondCount !== 0) { - if (ringBondCount > 0) { - queryAttrsText += 'rb' + ringBondCount.toString(); - } else if (ringBondCount === -1) queryAttrsText += 'rb0'; - else if (ringBondCount === -2) queryAttrsText += 'rb*'; - else throw new Error('Ring bond count invalid'); + queryAttrsText += getRingBondCountAttrText(ringBondCount); } if (substitutionCount !== 0) { addSemicolon(); - if (substitutionCount > 0) { - queryAttrsText += 's' + substitutionCount.toString(); - } else if (substitutionCount === -1) queryAttrsText += 's0'; - else if (substitutionCount === -2) queryAttrsText += 's*'; - else throw new Error('Substitution count invalid'); + queryAttrsText += getSubstitutionCountAttrText(substitutionCount); } if (unsaturatedAtom > 0) { addSemicolon(); diff --git a/packages/ketcher-react/src/script/ui/data/convert/structconv.js b/packages/ketcher-react/src/script/ui/data/convert/structconv.js index 082efdb8f5..62ec43f2f6 100644 --- a/packages/ketcher-react/src/script/ui/data/convert/structconv.js +++ b/packages/ketcher-react/src/script/ui/data/convert/structconv.js @@ -110,7 +110,7 @@ export function fromAtom(satom) { }; } -export function toAtom(satom) { +export function toAtom(atom) { // TODO merge this to Atom.attrlist? // see ratomtool const { @@ -123,11 +123,11 @@ export function toAtom(satom) { chirality, atomicMass, customQuery, - ...atom - } = satom; + ...restAtom + } = atom; if (customQuery) { - return Object.assign({}, atom, { - label: capitalize(atom.label), + return Object.assign({}, restAtom, { + label: capitalize(restAtom.label), alias: null, charge: 0, isotope: 0, @@ -155,18 +155,18 @@ export function toAtom(satom) { }); } const chargeRegexp = new RegExp(atomSchema.properties.charge.pattern); - const pch = chargeRegexp.exec(atom.charge); - const charge = pch ? parseInt(pch[1] + pch[3] + pch[2]) : atom.charge; - - const conv = Object.assign({}, atom, { - label: capitalize(atom.label), - alias: atom.alias || null, - exactChangeFlag: +(atom.exactChangeFlag ?? false), - unsaturatedAtom: +(atom.unsaturatedAtom ?? false), + const pch = chargeRegexp.exec(restAtom.charge); + const charge = pch ? parseInt(pch[1] + pch[3] + pch[2]) : restAtom.charge; + + const conv = Object.assign({}, restAtom, { + label: capitalize(restAtom.label), + alias: restAtom.alias || null, + exactChangeFlag: +(restAtom.exactChangeFlag ?? false), + unsaturatedAtom: +(restAtom.unsaturatedAtom ?? false), queryProperties: { aromaticity, degree, - implicitHCount: atom.implicitHCount, + implicitHCount: restAtom.implicitHCount, ringMembership, ringSize, connectivity,