Skip to content

Commit

Permalink
Backmerge: #4935 - Preview: Enumeration is missing for cycled unsplit…
Browse files Browse the repository at this point in the history
… nucleotides after load from file (KET/MOL doesn't matter) (#5251)

- added check for cyclic chain beginning
  • Loading branch information
rrodionov91 authored and Guch1g0v committed Oct 17, 2024
1 parent 2c4e134 commit 474bd23
Show file tree
Hide file tree
Showing 3 changed files with 52 additions and 12 deletions.
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 @@ -19,6 +19,9 @@ import {
MonomerHoverOperation,
} from 'application/editor/operations/monomer';
import { RenderersManager } from 'application/render/renderers/RenderersManager';
import { createPolymerEditorCanvas } from '../../helpers/dom';
import { CoreEditor } from 'application/editor';
import { FlexMode } from 'application/editor/modes/FlexMode';

describe('Drawing Entities Manager', () => {
it('should create monomer', () => {
Expand Down Expand Up @@ -86,7 +89,12 @@ describe('Drawing Entities Manager', () => {
});

it('should delete peptide', () => {
const drawingEntitiesManager = new DrawingEntitiesManager();
const editor = new CoreEditor({
canvas: createPolymerEditorCanvas(),
theme: {},
mode: new FlexMode(),
});
const drawingEntitiesManager = editor.drawingEntitiesManager;
const renderersManager = new RenderersManager({ theme: {} });
drawingEntitiesManager.addMonomer(peptideMonomerItem, new Vec2(0, 0));
const peptide = Array.from(drawingEntitiesManager.monomers)[0][1];
Expand All @@ -99,7 +107,12 @@ describe('Drawing Entities Manager', () => {
});

it('should delete polymer bond', () => {
const drawingEntitiesManager = new DrawingEntitiesManager();
const editor = new CoreEditor({
canvas: createPolymerEditorCanvas(),
theme: {},
mode: new FlexMode(),
});
const drawingEntitiesManager = editor.drawingEntitiesManager;
const renderersManager = new RenderersManager({ theme: {} });
const { polymerBond } = drawingEntitiesManager.startPolymerBondCreation(
new Peptide(peptideMonomerItem),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ import {
isMonomerBeginningOfChain,
} from 'domain/helpers/monomers';
import { CoreEditor } from 'application/editor';
import { ChainsCollection } from 'domain/entities/monomer-chains/ChainsCollection';

export class RenderersManager {
private theme;
Expand Down Expand Up @@ -164,7 +165,10 @@ export class RenderersManager {

const nextMonomer = getNextMonomerInChain(monomerRenderer.monomer);

if (!(nextMonomer instanceof Peptide)) {
if (
!(nextMonomer instanceof Peptide) ||
nextMonomer === peptideRenderer.monomer
) {
return;
}

Expand Down Expand Up @@ -216,9 +220,10 @@ export class RenderersManager {
const nextMonomer = getNextMonomerInChain(monomerRenderer.monomer);

if (
!(nextMonomer instanceof Sugar) &&
!(nextMonomer instanceof Phosphate) &&
!(nextMonomer instanceof UnsplitNucleotide)
(!(nextMonomer instanceof Sugar) &&
!(nextMonomer instanceof Phosphate) &&
!(nextMonomer instanceof UnsplitNucleotide)) ||
nextMonomer === rnaComponentRenderer.monomer
) {
return;
}
Expand All @@ -241,26 +246,36 @@ export class RenderersManager {
}
}

private recalculatePeptideEnumeration(peptideRenderer: PeptideRenderer) {
private recalculatePeptideEnumeration(
peptideRenderer: PeptideRenderer,
firstMonomers: BaseMonomer[],
) {
if (!peptideRenderer.monomer.hasBonds) {
peptideRenderer.setEnumeration(null);
peptideRenderer.redrawEnumeration();
}

if (!isMonomerBeginningOfChain(peptideRenderer.monomer, [Peptide])) {
if (
!isMonomerBeginningOfChain(peptideRenderer.monomer, [Peptide]) &&
!firstMonomers.includes(peptideRenderer.monomer)
) {
return;
}

this.recalculatePeptideChainEnumeration(peptideRenderer);
}

private recalculateRnaEnumeration(rnaComponentRenderer: BaseMonomerRenderer) {
private recalculateRnaEnumeration(
rnaComponentRenderer: BaseMonomerRenderer,
firstMonomers: BaseMonomer[],
) {
if (
!isMonomerBeginningOfChain(rnaComponentRenderer.monomer, [
Phosphate,
Sugar,
UnsplitNucleotide,
])
]) &&
!firstMonomers.includes(rnaComponentRenderer.monomer)
) {
return;
}
Expand All @@ -269,17 +284,29 @@ export class RenderersManager {
}

private recalculateMonomersEnumeration() {
const editor = CoreEditor.provideEditorInstance();
const [, firstMonomersInCyclicChains] =
ChainsCollection.getFirstMonomersInChains([
...editor.drawingEntitiesManager.monomers.values(),
]);

this.monomers.forEach((monomerRenderer) => {
if (monomerRenderer instanceof PeptideRenderer) {
this.recalculatePeptideEnumeration(monomerRenderer as PeptideRenderer);
this.recalculatePeptideEnumeration(
monomerRenderer as PeptideRenderer,
firstMonomersInCyclicChains,
);
}

if (
monomerRenderer instanceof UnsplitNucleotideRenderer ||
monomerRenderer instanceof PhosphateRenderer ||
monomerRenderer instanceof SugarRenderer
) {
this.recalculateRnaEnumeration(monomerRenderer as BaseMonomerRenderer);
this.recalculateRnaEnumeration(
monomerRenderer as BaseMonomerRenderer,
firstMonomersInCyclicChains,
);
}

if (
Expand Down

0 comments on commit 474bd23

Please sign in to comment.