Skip to content

Commit

Permalink
#1810 – fixed name for standalone S-Groups (#1866)
Browse files Browse the repository at this point in the history
  • Loading branch information
Nitvex authored Nov 25, 2022
1 parent 8fd5503 commit 7cfb1e2
Showing 1 changed file with 19 additions and 0 deletions.
19 changes: 19 additions & 0 deletions packages/ketcher-core/src/domain/entities/functionalGroup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,20 @@ export class FunctionalGroup {
return new FunctionalGroup(functionalGroup.#sgroup)
}

// Checks, if S-Group is standalone or attached to some other structure
static isAttachedSGroup(sgroup, molecule) {
const { bonds } = molecule
const isAttachmentBond = ({ begin, end }) =>
(sgroup.atoms.includes(begin) && !sgroup.atoms.includes(end)) ||
(sgroup.atoms.includes(end) && !sgroup.atoms.includes(begin))
for (const bond of bonds.values()) {
if (isAttachmentBond(bond)) {
return true
}
}
return false
}

/**
* This function determines, if an atom is used for attachment to other structure.
* For example, having sgroup CF3, which looks like
Expand Down Expand Up @@ -134,6 +148,11 @@ export class FunctionalGroup {
return true
}
}
// if atom in S-Group, which is not attached to any structure, then
// atoms[0] is considered as attachment point
if (!this.isAttachedSGroup(sgroup, molecule)) {
return sgroup.atoms[0] === atomId
}
}
return false
}
Expand Down

0 comments on commit 7cfb1e2

Please sign in to comment.