Skip to content

Commit

Permalink
#5640 – Multiple monomers expansion in micromolecules mode
Browse files Browse the repository at this point in the history
  • Loading branch information
svvald committed Nov 1, 2024
1 parent d851892 commit 6d067d9
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,10 @@ export function setExpandMonomerSGroup(
atom.a.neighbors.forEach((halfBondId) => {
const neighborAtomId =
restruct.molecule?.halfBonds?.get(halfBondId)?.end;
if (!neighborAtomId || sGroupAtoms.includes(neighborAtomId)) {
if (
neighborAtomId === undefined ||
sGroupAtoms.includes(neighborAtomId)
) {
return;
}

Expand Down
14 changes: 12 additions & 2 deletions packages/ketcher-core/src/domain/entities/sgroup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,12 @@ import { Struct } from './struct';
import { SaltsAndSolventsProvider } from '../helpers';
import { Vec2 } from './vec2';
import { ReStruct } from '../../application/render';
import { FunctionalGroup, Pool, SGroupAttachmentPoint } from 'domain/entities';
import {
FunctionalGroup,
MonomerMicromolecule,
Pool,
SGroupAttachmentPoint,
} from 'domain/entities';
import { ReSGroup } from 'application/render';
import { SgContexts } from 'application/editor/shared/constants';
import assert from 'assert';
Expand Down Expand Up @@ -504,7 +509,12 @@ export class SGroup {
const crossBonds = crossBondsPerAtom
? Object.values(crossBondsPerAtom).flat()
: null;
if (!crossBonds || crossBonds.length !== 2) {
// TODO: Overall cross bonds logic seems unclear and not-correct for s groups in general leading to tilted hover plate
if (
sGroup instanceof MonomerMicromolecule ||
!crossBonds ||
crossBonds.length !== 2
) {
sGroup.bracketDirection = new Vec2(1, 0);
} else {
const p1 = mol.bonds.get(crossBonds[0]).getCenter(mol);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,21 +10,32 @@ const MacromoleculeMenuItems = (
) => {
const [action, hidden] = useMonomerExpansionHandlers();

const multipleMonomersSelected =
props?.propsFromTrigger?.functionalGroups &&
props.propsFromTrigger.functionalGroups.length > 1;

const expandText = multipleMonomersSelected
? 'Expand monomers'
: 'Expand monomer';
const collapseText = multipleMonomersSelected
? 'Collapse monomers'
: 'Collapse monomer';

return (
<>
<Item
{...props}
hidden={(params) => hidden(params, true)}
onClick={(params) => action(params, true)}
>
Expand monomer
{expandText}
</Item>
<Item
{...props}
hidden={(params) => hidden(params, false)}
onClick={(params) => action(params, false)}
>
Collapse monomer
{collapseText}
</Item>
</>
);
Expand Down

0 comments on commit 6d067d9

Please sign in to comment.