Skip to content

Commit

Permalink
#3326 - Add text field for query SMARTS advanced features
Browse files Browse the repository at this point in the history
- Fix PR comments
  • Loading branch information
AKZhuk committed Sep 21, 2023
1 parent 6d235be commit 410b310
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 30 deletions.
32 changes: 16 additions & 16 deletions packages/ketcher-core/src/application/render/restruct/reatom.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1079,19 +1079,27 @@ 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;
}

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;
}

Expand Down Expand Up @@ -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();
Expand Down
28 changes: 14 additions & 14 deletions packages/ketcher-react/src/script/ui/data/convert/structconv.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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,
Expand Down Expand Up @@ -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,
Expand Down

0 comments on commit 410b310

Please sign in to comment.