diff --git a/packages/ketcher-core/src/application/render/renderers/BondRenderer.ts b/packages/ketcher-core/src/application/render/renderers/BondRenderer.ts index 81062fc21c..4dc73fae56 100644 --- a/packages/ketcher-core/src/application/render/renderers/BondRenderer.ts +++ b/packages/ketcher-core/src/application/render/renderers/BondRenderer.ts @@ -198,7 +198,7 @@ export class BondRenderer extends BaseRenderer { private appendRootElement() { return this.canvas - .append('g') + .insert('g', ':first-child') .data([this]) .attr( 'transform', diff --git a/packages/ketcher-core/src/domain/entities/Phosphate.ts b/packages/ketcher-core/src/domain/entities/Phosphate.ts index 35c7841faf..6935d17ca2 100644 --- a/packages/ketcher-core/src/domain/entities/Phosphate.ts +++ b/packages/ketcher-core/src/domain/entities/Phosphate.ts @@ -12,6 +12,10 @@ export class Phosphate extends BaseMonomer { } public getValidSourcePoint(secondMonomer: BaseMonomer) { + if (!secondMonomer) { + return this.firstFreeAttachmentPoint; + } + return this.getValidPoint( secondMonomer, secondMonomer.potentialSecondAttachmentPointForBond, @@ -19,6 +23,10 @@ export class Phosphate extends BaseMonomer { } public getValidTargetPoint(firstMonomer: BaseMonomer) { + if (!firstMonomer) { + return this.firstFreeAttachmentPoint; + } + // same implementation for both source and target attachment points return this.getValidPoint( firstMonomer, diff --git a/packages/ketcher-core/src/domain/entities/Sugar.ts b/packages/ketcher-core/src/domain/entities/Sugar.ts index 32b0fd5fd5..87fe401916 100644 --- a/packages/ketcher-core/src/domain/entities/Sugar.ts +++ b/packages/ketcher-core/src/domain/entities/Sugar.ts @@ -9,7 +9,11 @@ import { isRnaBaseOrAmbiguousRnaBase } from 'domain/helpers/monomers'; import { IVariantMonomer } from 'domain/entities/types'; export class Sugar extends BaseMonomer { - public getValidSourcePoint(secondMonomer: BaseMonomer & IVariantMonomer) { + public getValidSourcePoint(secondMonomer?: BaseMonomer & IVariantMonomer) { + if (!secondMonomer) { + return this.firstFreeAttachmentPoint; + } + return this.getValidPoint( secondMonomer, secondMonomer.potentialSecondAttachmentPointForBond, @@ -17,6 +21,10 @@ export class Sugar extends BaseMonomer { } public getValidTargetPoint(firstMonomer: BaseMonomer & IVariantMonomer) { + if (!firstMonomer) { + return this.firstFreeAttachmentPoint; + } + // same implementation for both source and target attachment points return this.getValidPoint( firstMonomer, diff --git a/packages/ketcher-core/src/domain/entities/UnresolvedMonomer.ts b/packages/ketcher-core/src/domain/entities/UnresolvedMonomer.ts index c3314fc02f..f5df3fd2d3 100644 --- a/packages/ketcher-core/src/domain/entities/UnresolvedMonomer.ts +++ b/packages/ketcher-core/src/domain/entities/UnresolvedMonomer.ts @@ -5,12 +5,20 @@ import { SubChainNode } from 'domain/entities/monomer-chains/types'; import { Peptide } from 'domain/entities/Peptide'; export class UnresolvedMonomer extends BaseMonomer { - public getValidSourcePoint(monomer?: BaseMonomer) { - return Peptide.prototype.getValidSourcePoint.call(this, monomer); + public getValidSourcePoint(secondMonomer?: BaseMonomer) { + if (!secondMonomer) { + return this.firstFreeAttachmentPoint; + } + + return Peptide.prototype.getValidSourcePoint.call(this, secondMonomer); } - public getValidTargetPoint(monomer: BaseMonomer) { - return Peptide.prototype.getValidTargetPoint.call(this, monomer); + public getValidTargetPoint(firstMonomer: BaseMonomer) { + if (!firstMonomer) { + return this.firstFreeAttachmentPoint; + } + + return Peptide.prototype.getValidTargetPoint.call(this, firstMonomer); } public get SubChainConstructor() {