Skip to content
Open
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
35 changes: 29 additions & 6 deletions packages/ketcher-core/src/domain/entities/AmbiguousMonomer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -135,15 +135,38 @@ export class AmbiguousMonomer extends BaseMonomer implements IVariantMonomer {
}

public getValidSourcePoint(_secondMonomer?: BaseMonomer) {
return MONOMER_CLASS_TO_CONSTRUCTOR[
this.monomerClass
].prototype.getValidSourcePoint.call(this, _secondMonomer);
const proto = MONOMER_CLASS_TO_CONSTRUCTOR[this.monomerClass].prototype;
return proto.getValidSourcePoint.call(
this._createContextProxy(proto),
_secondMonomer,
);
}

public getValidTargetPoint(_firstMonomer: BaseMonomer) {
return MONOMER_CLASS_TO_CONSTRUCTOR[
this.monomerClass
].prototype.getValidTargetPoint.call(this, _firstMonomer);
const proto = MONOMER_CLASS_TO_CONSTRUCTOR[this.monomerClass].prototype;
return proto.getValidTargetPoint.call(
this._createContextProxy(proto),
_firstMonomer,
);
}

private _createContextProxy(proto: Record<string, unknown>) {
return new Proxy(this, {
get(target, prop, receiver) {
if (
typeof prop === 'string' &&
!(prop in AmbiguousMonomer.prototype) &&
prop in proto
) {
const value = proto[prop];
if (typeof value === 'function') {
return (...args: unknown[]) => value.call(receiver, ...args);
}
return value;
}
return Reflect.get(target, prop, receiver);
},
});
}

public get SubChainConstructor() {
Expand Down
4 changes: 2 additions & 2 deletions packages/ketcher-core/src/domain/entities/Phosphate.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import { BaseMonomer } from './BaseMonomer';
import { AttachmentPointName, MonomerItemType } from 'domain/types';
import { Vec2 } from './vec2';
import { Sugar } from './Sugar';
import { PhosphateSubChain } from 'domain/entities/monomer-chains/PhosphateSubChain';
import { SubChainNode } from 'domain/entities/monomer-chains/types';
import { RnaSubChain } from 'domain/entities/monomer-chains/RnaSubChain';
import { isSugarOrAmbiguousSugar } from 'domain/helpers/monomers';

export class Phosphate extends BaseMonomer {
constructor(monomerItem: MonomerItemType, _position?: Vec2) {
Expand Down Expand Up @@ -54,7 +54,7 @@ export class Phosphate extends BaseMonomer {
}

// If other monomer is not a Sugar, we want to open modal
if (!(otherMonomer instanceof Sugar)) {
if (!isSugarOrAmbiguousSugar(otherMonomer)) {
return;
}
// If we chose a specific AP on other monomer, we want to determine the correct AP on this one
Expand Down
8 changes: 5 additions & 3 deletions packages/ketcher-core/src/domain/entities/Sugar.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
import { BaseMonomer } from './BaseMonomer';
import { RNABase } from './RNABase';
import { Phosphate } from './Phosphate';
import { AttachmentPointName } from 'domain/types';
import { RnaSubChain } from 'domain/entities/monomer-chains/RnaSubChain';
import { SubChainNode } from 'domain/entities/monomer-chains/types';
import { PhosphateSubChain } from 'domain/entities/monomer-chains/PhosphateSubChain';
import { isRnaBaseOrAmbiguousRnaBase } from 'domain/helpers/monomers';
import {
isPhosphateOrAmbiguousPhosphate,
isRnaBaseOrAmbiguousRnaBase,
} from 'domain/helpers/monomers';
import { IVariantMonomer } from 'domain/entities/types';
import { PolymerBond } from 'domain/entities/PolymerBond';

Expand Down Expand Up @@ -52,7 +54,7 @@ export class Sugar extends BaseMonomer {

// If other monomer is neither a Phosphate nor RNABase, open modal
if (
!(otherMonomer instanceof Phosphate) &&
!isPhosphateOrAmbiguousPhosphate(otherMonomer) &&
!isRnaBaseOrAmbiguousRnaBase(otherMonomer)
) {
return;
Expand Down
20 changes: 20 additions & 0 deletions packages/ketcher-core/src/domain/helpers/monomers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -322,6 +322,26 @@ export function isRnaBaseOrAmbiguousRnaBase(
);
}

export function isPhosphateOrAmbiguousPhosphate(
monomer?: BaseMonomer,
): monomer is Phosphate | AmbiguousMonomer {
return (
monomer instanceof Phosphate ||
(monomer instanceof AmbiguousMonomer &&
monomer.monomerClass === KetMonomerClass.Phosphate)
);
}

export function isSugarOrAmbiguousSugar(
monomer?: BaseMonomer,
): monomer is Sugar | AmbiguousMonomer {
return (
monomer instanceof Sugar ||
(monomer instanceof AmbiguousMonomer &&
monomer.monomerClass === KetMonomerClass.Sugar)
);
}

export function isRnaBaseApplicableForAntisense(monomer?: BaseMonomer) {
return (
monomer instanceof UnsplitNucleotide ||
Expand Down
Loading