From 0a42c9f849740ea373ca246795e8d4dfb8f3d814 Mon Sep 17 00:00:00 2001 From: chgayane Date: Wed, 8 Nov 2023 16:10:52 +0400 Subject: [PATCH] #3475 - corrected logic for all types of monomers --- .../src/domain/entities/BaseMonomer.ts | 4 +++ .../domain/entities/DrawingEntitiesManager.ts | 13 +++---- .../src/domain/entities/Peptide.ts | 35 +++++++++++-------- .../src/domain/entities/Phosphate.ts | 2 +- .../src/domain/entities/RNABase.ts | 6 +--- .../ketcher-core/src/domain/entities/Sugar.ts | 4 +-- 6 files changed, 33 insertions(+), 31 deletions(-) diff --git a/packages/ketcher-core/src/domain/entities/BaseMonomer.ts b/packages/ketcher-core/src/domain/entities/BaseMonomer.ts index 0e4a85237a..2d63885291 100644 --- a/packages/ketcher-core/src/domain/entities/BaseMonomer.ts +++ b/packages/ketcher-core/src/domain/entities/BaseMonomer.ts @@ -138,6 +138,10 @@ export abstract class BaseMonomer extends DrawingEntity { return Boolean(this.firstFreeAttachmentPoint); } + public isAttachmentPointExistAndFree(attachmentPoint: AttachmentPointName){ + return this.hasAttachmentPoint(attachmentPoint) && !this.isAttachmentPointUsed(attachmentPoint) + } + public setRenderer(renderer: BaseMonomerRenderer) { super.setBaseRenderer(renderer as BaseRenderer); this.renderer = renderer; diff --git a/packages/ketcher-core/src/domain/entities/DrawingEntitiesManager.ts b/packages/ketcher-core/src/domain/entities/DrawingEntitiesManager.ts index e45ada1b00..eb9fde92ed 100644 --- a/packages/ketcher-core/src/domain/entities/DrawingEntitiesManager.ts +++ b/packages/ketcher-core/src/domain/entities/DrawingEntitiesManager.ts @@ -349,17 +349,12 @@ export class DrawingEntitiesManager { const command = new Command(); monomer.turnOnHover(); monomer.turnOnAttachmentPointsVisibility(); - const availableAttachmentPointForBondEnd = - monomer.availableAttachmentPointForBondEnd; - if (availableAttachmentPointForBondEnd) { - monomer.setPotentialBond(availableAttachmentPointForBondEnd, bond); - } bond.firstMonomer.removePotentialBonds(); monomer.removePotentialBonds(); - const firstValidAttPoint = monomer.getValidSourcePoint(bond.firstMonomer); - const secondValidAttPonint = monomer.getValidTargetPoint(bond.firstMonomer); - bond.firstMonomer.setPotentialBond(secondValidAttPonint, bond); - monomer.setPotentialBond(firstValidAttPoint, bond); + const firstMonomerValidSourcePoint = bond.firstMonomer.getValidSourcePoint(monomer); + const secondMonomerValidTargetPoint = monomer.getValidTargetPoint(bond.firstMonomer); + bond.firstMonomer.setPotentialBond(firstMonomerValidSourcePoint, bond); + monomer.setPotentialBond(secondMonomerValidTargetPoint, bond); const connectFirstMonomerOperation = new MonomerHoverOperation( bond.firstMonomer, true, diff --git a/packages/ketcher-core/src/domain/entities/Peptide.ts b/packages/ketcher-core/src/domain/entities/Peptide.ts index c3553468c6..28b689169d 100644 --- a/packages/ketcher-core/src/domain/entities/Peptide.ts +++ b/packages/ketcher-core/src/domain/entities/Peptide.ts @@ -1,23 +1,30 @@ import { BaseMonomer } from './BaseMonomer'; export class Peptide extends BaseMonomer { + public getValidSourcePoint(monomer: BaseMonomer) { - if ( - monomer.hasAttachmentPoint('R1') && - !monomer.isAttachmentPointUsed('R1') - ) { - return this.R1AttachmentPoint; - } - return this.R2AttachmentPoint; + + if (monomer.isAttachmentPointExistAndFree('R1') && this.isAttachmentPointExistAndFree('R2')) { + + return 'R2'; + + } + if (this.isAttachmentPointExistAndFree('R1') && monomer.isAttachmentPointExistAndFree('R2') ) { + return 'R1'; + } + + return this.firstFreeAttachmentPoint; } public getValidTargetPoint(monomer: BaseMonomer) { - if ( - monomer.hasAttachmentPoint('R2') && - !monomer.isAttachmentPointUsed('R2') - ) { - return this.R2AttachmentPoint; - } - return this.R1AttachmentPoint; + + if (this.isAttachmentPointExistAndFree('R1') && monomer.isAttachmentPointExistAndFree('R2') ) { + return 'R1'; + } + if (monomer.isAttachmentPointExistAndFree('R1') && this.isAttachmentPointExistAndFree('R2')) { + return 'R2'; + } + + return this.firstFreeAttachmentPoint; } } diff --git a/packages/ketcher-core/src/domain/entities/Phosphate.ts b/packages/ketcher-core/src/domain/entities/Phosphate.ts index 759207c1b0..5bf9c78cca 100644 --- a/packages/ketcher-core/src/domain/entities/Phosphate.ts +++ b/packages/ketcher-core/src/domain/entities/Phosphate.ts @@ -25,7 +25,7 @@ export class Phosphate extends BaseMonomer { this.hasAttachmentPoint('R2') && !this.isAttachmentPointUsed('R2') ) { - return 'R1'; + return 'R2'; } return this.firstFreeAttachmentPoint; } diff --git a/packages/ketcher-core/src/domain/entities/RNABase.ts b/packages/ketcher-core/src/domain/entities/RNABase.ts index 19fdd56681..8c8c99815b 100644 --- a/packages/ketcher-core/src/domain/entities/RNABase.ts +++ b/packages/ketcher-core/src/domain/entities/RNABase.ts @@ -1,5 +1,4 @@ import { BaseMonomer } from 'domain/entities/BaseMonomer'; -import { Sugar } from './Sugar'; export class RNABase extends BaseMonomer { public getValidSourcePoint(monomer: BaseMonomer) { @@ -7,9 +6,6 @@ export class RNABase extends BaseMonomer { } public getValidTargetPoint(monomer: BaseMonomer) { - if (monomer instanceof Sugar) { - return 'R3'; - } - return this.firstFreeAttachmentPoint; + return monomer.firstFreeAttachmentPoint; } } diff --git a/packages/ketcher-core/src/domain/entities/Sugar.ts b/packages/ketcher-core/src/domain/entities/Sugar.ts index 5a83598e8a..f4dd35c6aa 100644 --- a/packages/ketcher-core/src/domain/entities/Sugar.ts +++ b/packages/ketcher-core/src/domain/entities/Sugar.ts @@ -27,14 +27,14 @@ export class Sugar extends BaseMonomer { this.hasAttachmentPoint('R3') && !this.isAttachmentPointUsed('R3') ) { - return 'R1'; + return 'R3'; } if ( monomer instanceof Phosphate && this.hasAttachmentPoint('R1') && !this.isAttachmentPointUsed('R1') ) { - return 'R2'; + return 'R1'; } return this.firstFreeAttachmentPoint; }