Skip to content

Commit

Permalink
#1865 Extended SMILES saved from Ketcher might be invalid for RDKit (#…
Browse files Browse the repository at this point in the history
…2498)

* #1865 Extended SMILES saved from Ketcher might be invalid for RDKit

* #1865 fix conflicts

* #1865 remove IMPLICIT_V for molfile generation
  • Loading branch information
KonstantinEpam23 authored Apr 20, 2023
1 parent 382e2ea commit af188bb
Show file tree
Hide file tree
Showing 4 changed files with 143 additions and 83 deletions.
22 changes: 15 additions & 7 deletions packages/ketcher-core/src/application/editor/actions/atom.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ export function fromAtomsAttrs(restruct, ids, attrs, reset) {
const action = new Action()
const aids = Array.isArray(ids) ? ids : [ids]

aids.forEach((aid) => {
aids.forEach((atomId) => {
Object.keys(Atom.attrlist).forEach((key) => {
if (key === 'attpnt' && !(key in attrs)) return
if (!(key in attrs) && !reset) return
Expand All @@ -72,16 +72,16 @@ export function fromAtomsAttrs(restruct, ids, attrs, reset) {
switch (key) {
case 'stereoLabel':
if (key in attrs && value) {
action.addOp(new AtomAttr(aid, key, value).perform(restruct))
action.addOp(new AtomAttr(atomId, key, value).perform(restruct))
}
break
case 'stereoParity':
if (key in attrs && value) {
action.addOp(new AtomAttr(aid, key, value).perform(restruct))
action.addOp(new AtomAttr(atomId, key, value).perform(restruct))
}
break
default:
action.addOp(new AtomAttr(aid, key, value).perform(restruct))
action.addOp(new AtomAttr(atomId, key, value).perform(restruct))
break
}
})
Expand All @@ -93,16 +93,24 @@ export function fromAtomsAttrs(restruct, ids, attrs, reset) {
attrs.label !== 'L#' &&
!('atomList' in attrs)
) {
action.addOp(new AtomAttr(aid, 'atomList', null).perform(restruct))
action.addOp(new AtomAttr(atomId, 'atomList', null).perform(restruct))
}

action.addOp(new CalcImplicitH([aid]).perform(restruct))
action.addOp(new CalcImplicitH([atomId]).perform(restruct))

const atomNeighbors = restruct.molecule.atomGetNeighbors(aid)
const atomNeighbors = restruct.molecule.atomGetNeighbors(atomId)
const bond = restruct.molecule.bonds.get(atomNeighbors[0]?.bid)
if (bond) {
action.mergeWith(fromBondStereoUpdate(restruct, bond))
}
// when a heteroatom connects to an aromatic ring it's necessary to add a ImplicitHCount
// property to this atom to specify the number of hydrogens on it.
const atom = restruct.molecule.atoms.get(atomId)
if (Atom.isInAromatizedRing(restruct.molecule, atomId)) {
action.addOp(
new AtomAttr(atomId, 'implicitHCount', atom.implicitH).perform(restruct)
)
}
})

return action
Expand Down
Loading

0 comments on commit af188bb

Please sign in to comment.