Skip to content

Commit

Permalink
#3475 - corrected logic for all types of monomers
Browse files Browse the repository at this point in the history
  • Loading branch information
chgayane authored and chgayane committed Nov 8, 2023
1 parent ab84cf9 commit 0a42c9f
Show file tree
Hide file tree
Showing 6 changed files with 33 additions and 31 deletions.
4 changes: 4 additions & 0 deletions packages/ketcher-core/src/domain/entities/BaseMonomer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
35 changes: 21 additions & 14 deletions packages/ketcher-core/src/domain/entities/Peptide.ts
Original file line number Diff line number Diff line change
@@ -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;
}
}
2 changes: 1 addition & 1 deletion packages/ketcher-core/src/domain/entities/Phosphate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ export class Phosphate extends BaseMonomer {
this.hasAttachmentPoint('R2') &&
!this.isAttachmentPointUsed('R2')
) {
return 'R1';
return 'R2';
}
return this.firstFreeAttachmentPoint;
}
Expand Down
6 changes: 1 addition & 5 deletions packages/ketcher-core/src/domain/entities/RNABase.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,11 @@
import { BaseMonomer } from 'domain/entities/BaseMonomer';
import { Sugar } from './Sugar';

export class RNABase extends BaseMonomer {
public getValidSourcePoint(monomer: BaseMonomer) {
return monomer.firstFreeAttachmentPoint;
}

public getValidTargetPoint(monomer: BaseMonomer) {
if (monomer instanceof Sugar) {
return 'R3';
}
return this.firstFreeAttachmentPoint;
return monomer.firstFreeAttachmentPoint;
}
}
4 changes: 2 additions & 2 deletions packages/ketcher-core/src/domain/entities/Sugar.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down

0 comments on commit 0a42c9f

Please sign in to comment.