Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

#5640 – Multiple monomers expansion in micromolecules mode #5894

Merged
merged 3 commits into from
Nov 1, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,10 @@ export class MonomerMicromolecule extends SGroup {
this.data.attached = false;
}

public get isMonomer() {
return true;
}

public override getContractedPosition(struct: Struct) {
assert(this.pp);
const sgroupContractedPosition = super.getContractedPosition(struct);
Expand Down
7 changes: 6 additions & 1 deletion packages/ketcher-core/src/domain/entities/sgroup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -368,6 +368,10 @@ export class SGroup {
return this.type === SGroup.TYPES.SUP && !this.data.name;
}

public get isMonomer() {
return false;
}

static getOffset(sgroup: SGroup): null | Vec2 {
if (!sgroup?.pp || !sgroup.bracketBox) return null;
return Vec2.diff(sgroup.pp, sgroup.bracketBox.p1);
Expand Down Expand Up @@ -504,7 +508,8 @@ 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.isMonomer || !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
Loading