Skip to content

Commit

Permalink
#4608 - Bugfix (PolymerBond): Correct isSideChainConnection getter
Browse files Browse the repository at this point in the history
  • Loading branch information
DmitriiP-EPAM committed Jun 25, 2024
1 parent 1d4c2fa commit 1410b4a
Showing 1 changed file with 52 additions and 26 deletions.
78 changes: 52 additions & 26 deletions packages/ketcher-core/src/domain/entities/PolymerBond.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
import { DrawingEntity } from 'domain/entities/DrawingEntity';
import { PolymerBondRenderer } from 'application/render/renderers/PolymerBondRenderer';
import { Vec2 } from 'domain/entities/vec2';
import { BaseMonomer } from './BaseMonomer';
import { BaseRenderer } from 'application/render/renderers/BaseRenderer';
import { AttachmentPointName } from 'domain/types';
import { PolymerBondRenderer } from 'application/render/renderers/PolymerBondRenderer';
import { BackBoneBondSequenceRenderer } from 'application/render/renderers/sequence/BackBoneBondSequenceRenderer';
import { PolymerBondSequenceRenderer } from 'application/render/renderers/sequence/PolymerBondSequenceRenderer';
import { BaseMonomer } from 'domain/entities/BaseMonomer';
import { DrawingEntity } from 'domain/entities/DrawingEntity';
import { Phosphate } from 'domain/entities/Phosphate';
import { RNABase } from 'domain/entities/RNABase';
import { Sugar } from 'domain/entities/Sugar';
import { Vec2 } from 'domain/entities/vec2';
import { AttachmentPointName } from 'domain/types';

export class PolymerBond extends DrawingEntity {
public secondMonomer?: BaseMonomer;
Expand Down Expand Up @@ -75,33 +78,56 @@ export class PolymerBond extends DrawingEntity {
: this.firstMonomer;
}

public static get backBoneChainAttachmentPoints() {
return [AttachmentPointName.R1, AttachmentPointName.R2];
}
public get isBackboneChainConnection(): boolean {
// Variants:
// • Sugar [R2] — [R1] Phosphate
// • Sugar [R1] — [R2] Phosphate
// • Phosphate [R2] — [R1] Sugar
// • Phosphate [R1] — [R2] Sugar
// • Sugar [R3] — [R1] RNA base
// • RNA base [R1] — [R3] Sugar
if (!this.secondMonomer) {
return true;
}

public get isBackBoneChainConnection() {
return !this.isSideChainConnection;
}
let sugarMonomer: Sugar;
let anotherMonomer: BaseMonomer;
if (this.firstMonomer instanceof Sugar) {
sugarMonomer = this.firstMonomer;
anotherMonomer = this.secondMonomer;
} else if (this.secondMonomer instanceof Sugar) {
sugarMonomer = this.secondMonomer;
anotherMonomer = this.firstMonomer;
} else {
return false;
}

public get isSideChainConnection() {
const firstMonomerAttachmentPoint =
this.firstMonomer.getAttachmentPointByBond(this);
const secondMonomerAttachmentPoint =
this.secondMonomer?.getAttachmentPointByBond(this);
const sugarMonomerAttachmentPoint =
sugarMonomer.getAttachmentPointByBond(this);
const anotherMonomerAttachmentPoint =
anotherMonomer.getAttachmentPointByBond(this);
if (!sugarMonomerAttachmentPoint || !anotherMonomerAttachmentPoint) {
return true;
}

if (!firstMonomerAttachmentPoint || !secondMonomerAttachmentPoint) {
return false;
const thereArePhosphateAndSugar = anotherMonomer instanceof Phosphate;
const thereAreR1AndR2 =
(sugarMonomerAttachmentPoint === AttachmentPointName.R2 &&
anotherMonomerAttachmentPoint === AttachmentPointName.R1) ||
(sugarMonomerAttachmentPoint === AttachmentPointName.R1 &&
anotherMonomerAttachmentPoint === AttachmentPointName.R2);
if (thereArePhosphateAndSugar && thereAreR1AndR2) {
return true;
}

return (
!(
PolymerBond.backBoneChainAttachmentPoints.includes(
firstMonomerAttachmentPoint,
) &&
PolymerBond.backBoneChainAttachmentPoints.includes(
secondMonomerAttachmentPoint,
)
) || firstMonomerAttachmentPoint === secondMonomerAttachmentPoint
sugarMonomerAttachmentPoint === AttachmentPointName.R3 &&
anotherMonomer instanceof RNABase &&
anotherMonomerAttachmentPoint === AttachmentPointName.R1
);
}

public get isSideChainConnection(): boolean {
return !this.isBackboneChainConnection;
}
}

0 comments on commit 1410b4a

Please sign in to comment.