Skip to content

Commit

Permalink
6021 connection between molecule and monomer does not affect an amoun…
Browse files Browse the repository at this point in the history
…t of implicit hydrogens (#6229)

* 6021-connection-between-molecule-and-monomer-does-not-affect-an-amount-of-implicit-hydrogens

* add type check

* update test

---------

Co-authored-by: Andrey Menshikov <[email protected]>
  • Loading branch information
Drimodaren and Andrey Menshikov authored Dec 30, 2024
1 parent 76dd6d2 commit 06b5dc5
Show file tree
Hide file tree
Showing 9 changed files with 42 additions and 27 deletions.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
Expand Up @@ -345,6 +345,7 @@ export class RenderersManager {

public addMonomerToAtomBond(bond: MonomerToAtomBond) {
const bondRenderer = new MonomerToAtomBondRenderer(bond);
this.redrawDrawingEntity(bond.atom);

bondRenderer.show();
bond.monomer.renderer?.redrawAttachmentPoints();
Expand All @@ -353,6 +354,7 @@ export class RenderersManager {

public deleteMonomerToAtomBond(bond: MonomerToAtomBond) {
bond.renderer?.remove();
this.redrawDrawingEntity(bond.atom);
}

public runPostRenderMethods() {
Expand Down
56 changes: 34 additions & 22 deletions packages/ketcher-core/src/domain/entities/CoreAtom.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import { BaseRenderer } from 'application/render';
import { AtomLabel, Elements } from 'domain/constants';
import { AtomRenderer } from 'application/render/renderers/AtomRenderer';
import { isNumber } from 'lodash';
import { MonomerToAtomBond } from './MonomerToAtomBond';

export interface AtomProperties {
charge?: number | null;
Expand All @@ -15,7 +16,7 @@ export interface AtomProperties {
alias?: string | null;
}
export class Atom extends DrawingEntity {
public bonds: Bond[] = [];
public bonds: Array<Bond | MonomerToAtomBond> = [];
public renderer: AtomRenderer | undefined = undefined;
constructor(
position: Vec2,
Expand All @@ -31,8 +32,14 @@ export class Atom extends DrawingEntity {
return this.position;
}

public addBond(bond: Bond) {
this.bonds.push(bond);
public addBond(bond: Bond | MonomerToAtomBond) {
if (!this.bonds.includes(bond)) {
this.bonds.push(bond);
}
}

public deleteBond(bondId: number) {
this.bonds = this.bonds.filter((bond) => bond.id !== bondId);
}

public setRenderer(renderer: AtomRenderer) {
Expand All @@ -48,26 +55,31 @@ export class Atom extends DrawingEntity {
let connectionsAmount = 0;

for (let i = 0; i < this.bonds.length; i++) {
switch (this.bonds[i].type) {
case BondType.Single:
connectionsAmount += 1;
break;
case BondType.Double:
connectionsAmount += 2;
break;
case BondType.Triple:
connectionsAmount += 3;
break;
case BondType.Dative:
case BondType.Hydrogen:
break;
case BondType.Aromatic:
if (this.bonds.length === 1) {
const bond = this.bonds[i];
if (bond instanceof MonomerToAtomBond) {
connectionsAmount += 1;
} else {
switch (bond.type) {
case BondType.Single:
connectionsAmount += 1;
break;
case BondType.Double:
connectionsAmount += 2;
break;
case BondType.Triple:
connectionsAmount += 3;
break;
case BondType.Dative:
case BondType.Hydrogen:
break;
case BondType.Aromatic:
if (this.bonds.length === 1) {
return -1;
}
return this.bonds.length;
default:
return -1;
}
return this.bonds.length;
default:
return -1;
}
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2447,8 +2447,9 @@ export class DrawingEntitiesManager {
if (bond.selected) {
return;
}

command.merge(this.deleteBond(bond));
if (bond instanceof Bond) {
command.merge(this.deleteBond(bond));
}
});

this.monomerToAtomBonds.forEach((monomerToAtomBond) => {
Expand Down Expand Up @@ -2553,12 +2554,12 @@ export class DrawingEntitiesManager {
if (_monomerToAtomBond) {
this.monomerToAtomBonds.set(_monomerToAtomBond.id, _monomerToAtomBond);
monomer.setBond(attachmentPoint, _monomerToAtomBond);

atom.addBond(_monomerToAtomBond);
return _monomerToAtomBond;
}

const monomerToAtomBond = new MonomerToAtomBond(monomer, atom);

atom.addBond(monomerToAtomBond);
this.monomerToAtomBonds.set(monomerToAtomBond.id, monomerToAtomBond);

monomerToAtomBond.moveToLinkedEntities();
Expand All @@ -2579,7 +2580,7 @@ export class DrawingEntitiesManager {
monomerAtomBond.monomer.unsetBond(attachmentPointName);
}
this.monomerToAtomBonds.delete(monomerAtomBond.id);

monomerAtomBond.atom.deleteBond(monomerAtomBond.id);
return monomerAtomBond;
}

Expand Down

0 comments on commit 06b5dc5

Please sign in to comment.