Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

#5678 - Introduce creating antisense chains #6032

Open
wants to merge 16 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -147,9 +147,6 @@ describe('Select Rectangle Tool', () => {
jest
.spyOn(BaseMonomerRenderer.prototype, 'redrawEnumeration')
.mockImplementation(() => {});
jest
.spyOn(BaseMonomerRenderer.prototype, 'reDrawChainBeginning')
.mockImplementation(() => {});
const fn = jest
.spyOn(window, 'requestAnimationFrame')
.mockImplementation((func) => {
Expand Down
45 changes: 45 additions & 0 deletions packages/ketcher-core/src/application/editor/Editor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ import { ViewModel } from 'application/render/view-model/ViewModel';
import { HandTool } from 'application/editor/tools/Hand';
import { HydrogenBond } from 'domain/entities/HydrogenBond';
import { ToolName } from 'application/editor/tools/types';
import { BaseMonomerRenderer } from 'application/render';

interface ICoreEditorConstructorParams {
theme;
Expand Down Expand Up @@ -230,6 +231,16 @@ export class CoreEditor {
!(eventData.polymerBond instanceof HydrogenBond))
) {
this.events.rightClickPolymerBond.dispatch(event, eventData);
} else if (
eventData instanceof BaseMonomerRenderer &&
eventData.monomer.selected
) {
this.events.rightClickSelectedMonomers.dispatch(
event,
this.drawingEntitiesManager.selectedEntities
.filter(([, drawingEntity]) => drawingEntity instanceof BaseMonomer)
.map(([, drawingEntity]) => drawingEntity as BaseMonomer),
);
} else if (isClickOnCanvas) {
this.events.rightClickCanvas.dispatch(event);
}
Expand Down Expand Up @@ -271,6 +282,20 @@ export class CoreEditor {
this.events.changeSequenceTypeEnterMode.add((mode: SequenceType) =>
this.onChangeSequenceTypeEnterMode(mode),
);
this.events.createAntisenseChain.add(() => {
this.onCreateAntisenseChain();
});
this.events.copySelectedStructure.add(() => {
this.mode.onCopy();
});
this.events.deleteSelectedStructure.add(() => {
const command = new Command();
const history = new EditorHistory(this);

command.merge(this.drawingEntitiesManager.deleteSelectedEntities());
history.update(command);
this.renderersContainer.update(command);
});
}

private onEditSequence(sequenceItemRenderer: BaseSequenceItemRenderer) {
Expand Down Expand Up @@ -301,6 +326,14 @@ export class CoreEditor {
this.sequenceTypeEnterMode = mode;
}

private onCreateAntisenseChain() {
const modelChanges = this.drawingEntitiesManager.createAntisenseChain();
const history = new EditorHistory(this);

this.renderersContainer.update(modelChanges);
history.update(modelChanges);
}

private onSelectMonomer(monomer: MonomerItemType) {
if (this.mode instanceof SequenceMode) {
this.mode.insertMonomerFromLibrary(monomer);
Expand Down Expand Up @@ -626,6 +659,18 @@ export class CoreEditor {
struct,
this.drawingEntitiesManager,
);

if (this.mode instanceof SnakeMode) {
modelChanges.merge(
this.drawingEntitiesManager.applySnakeLayout(
this.canvas.width.baseVal.value,
true,
true,
false,
),
);
}

this.renderersContainer.update(modelChanges);
ketcher?.editor.clear();
this._type = EditorType.Macromolecules;
Expand Down
5 changes: 5 additions & 0 deletions packages/ketcher-core/src/application/editor/editorEvents.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ export function resetEditorEvents() {
rightClickSequence: new Subscription(),
rightClickCanvas: new Subscription(),
rightClickPolymerBond: new Subscription(),
rightClickSelectedMonomers: new Subscription(),
editSequence: new Subscription(),
startNewSequence: new Subscription(),
turnOnSequenceEditInRNABuilderMode: new Subscription(),
Expand All @@ -53,6 +54,9 @@ export function resetEditorEvents() {
doubleClickOnSequenceItem: new Subscription(),
openConfirmationDialog: new Subscription(),
mouseUpAtom: new Subscription(),
createAntisenseChain: new Subscription(),
copySelectedStructure: new Subscription(),
deleteSelectedStructure: new Subscription(),
};
}
resetEditorEvents();
Expand All @@ -73,6 +77,7 @@ export const renderersEvents: ToolEventHandlerName[] = [
'rightClickSequence',
'rightClickCanvas',
'rightClickPolymerBond',
'rightClickSelectedMonomers',
'editSequence',
'startNewSequence',
'turnOnSequenceEditInRNABuilderMode',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -105,8 +105,8 @@ export abstract class BaseMode {

abstract scrollForView(): void;

onCopy(event: ClipboardEvent) {
if (this.checkIfTargetIsInput(event)) {
onCopy(event?: ClipboardEvent) {
if (event && this.checkIfTargetIsInput(event)) {
return;
}
const editor = CoreEditor.provideEditorInstance();
Expand Down Expand Up @@ -162,7 +162,7 @@ export abstract class BaseMode {
);
if (isClipboardAPIAvailable()) {
navigator.clipboard.writeText(serializedKet);
} else {
} else if (event) {
legacyCopy(event.clipboardData, {
'text/plain': serializedKet,
});
Expand Down
19 changes: 15 additions & 4 deletions packages/ketcher-core/src/application/editor/modes/SequenceMode.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,13 @@ import assert from 'assert';
import {
getPeptideLibraryItem,
getRnaPartLibraryItem,
getSugarBySequenceType,
} from 'domain/helpers/rna';
import {
peptideNaturalAnalogues,
RNA_DNA_NON_MODIFIED_PART,
rnaDnaNaturalAnalogues,
RnaDnaNaturalAnaloguesEnum,
} from 'domain/constants/monomers';
import { SubChainNode } from 'domain/entities/monomer-chains/types';
import { isNumber, uniq } from 'lodash';
Expand Down Expand Up @@ -106,7 +108,7 @@ export class SequenceMode extends BaseMode {
// Prevent rearranging chains (and recalculating the layout) when switching to sequence mode,
// only recalculate after changes in the sequence
const modelChanges = needReArrangeChains
? editor.drawingEntitiesManager.reArrangeChains(
? editor.drawingEntitiesManager.applySnakeLayout(
editor.canvas.width.baseVal.value,
true,
false,
Expand Down Expand Up @@ -494,19 +496,28 @@ export class SequenceMode extends BaseMode {
}

private handleRnaDnaNodeAddition(
enteredSymbol: string,
enteredSymbol: RnaDnaNaturalAnaloguesEnum | string,
currentNode: SubChainNode,
newNodePosition: Vec2,
) {
if (!rnaDnaNaturalAnalogues.includes(enteredSymbol)) {
return undefined;
}

const editor = CoreEditor.provideEditorInstance();
const modelChanges = new Command();
const { modelChanges: addedNodeModelChanges, node: nodeToAdd } =
currentNode instanceof Nucleotide || currentNode instanceof Nucleoside
? Nucleotide.createOnCanvas(enteredSymbol, newNodePosition)
: Nucleoside.createOnCanvas(enteredSymbol, newNodePosition);
? Nucleotide.createOnCanvas(
enteredSymbol,
newNodePosition,
getSugarBySequenceType(editor.sequenceTypeEnterMode),
)
: Nucleoside.createOnCanvas(
enteredSymbol,
newNodePosition,
getSugarBySequenceType(editor.sequenceTypeEnterMode),
);

modelChanges.merge(addedNodeModelChanges);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ export class SnakeMode extends BaseMode {
// we need just redraw canvas to apply new bond view style (straight instead of curved)
const modelChanges = _isUndo
? new Command()
: editor.drawingEntitiesManager.reArrangeChains(
: editor.drawingEntitiesManager.applySnakeLayout(
editor.canvas.width.baseVal.value,
true,
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { Operation } from 'domain/entities/Operation';
import { RenderersManager } from 'application/render/renderers/RenderersManager';

export class RecalculateCanvasMatrixOperation implements Operation {
public priority = 1;
constructor(
private recalculateCanvasMatrixModelChange: () => void,
private invertRecalculateCanvasMatrixModelChange: () => void,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,7 @@ export class MonomerItemModifyOperation implements Operation {
public revertMonomerItem: () => BaseMonomer,
) {
this.monomer = monomer;
this.execute();
}

public execute() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,15 @@ import { PolymerBond } from 'domain/entities/PolymerBond';
import { RenderersManager } from 'application/render/renderers/RenderersManager';
import { Operation } from 'domain/entities/Operation';
import { BaseMonomer } from 'domain/entities/BaseMonomer';
import { HydrogenBond } from 'domain/entities';

export class PolymerBondAddOperation implements Operation {
public polymerBond;
public priority = 1;
constructor(
private addPolymerBondChangeModel: (
polymerBond?: PolymerBond,
) => PolymerBond,
polymerBond?: PolymerBond | HydrogenBond,
) => PolymerBond | HydrogenBond,
private deletePolymerBondChangeModel: (polymerBond) => void,
) {
this.polymerBond = this.addPolymerBondChangeModel();
Expand All @@ -45,11 +46,11 @@ export class PolymerBondAddOperation implements Operation {
export class PolymerBondDeleteOperation implements Operation {
public priority = -1;
constructor(
public polymerBond: PolymerBond,
public polymerBond: PolymerBond | HydrogenBond,
private deletePolymerBondChangeModel: () => void,
private finishPolymerBondCreationModelChange: (
polymerBond?: PolymerBond,
) => PolymerBond,
polymerBond?: PolymerBond | HydrogenBond,
) => PolymerBond | HydrogenBond,
) {
this.deletePolymerBondChangeModel();
}
Expand Down
12 changes: 0 additions & 12 deletions packages/ketcher-core/src/application/editor/tools/Bond.ts
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,6 @@ class PolymerBond implements BaseTool {
this.editor.drawingEntitiesManager.hidePolymerBondInformation(
renderer.polymerBond,
);
this.editor.renderersContainer.markForRecalculateBegin();
this.editor.renderersContainer.update(modelChanges);
}

Expand All @@ -157,7 +156,6 @@ class PolymerBond implements BaseTool {
this.editor.drawingEntitiesManager.showPolymerBondInformation(
renderer.polymerBond,
);
this.editor.renderersContainer.markForRecalculateBegin();
this.editor.renderersContainer.update(modelChanges);
}

Expand Down Expand Up @@ -188,7 +186,6 @@ class PolymerBond implements BaseTool {
);
}

this.editor.renderersContainer.markForRecalculateBegin();
this.editor.renderersContainer.update(modelChanges);
}

Expand Down Expand Up @@ -229,7 +226,6 @@ class PolymerBond implements BaseTool {
);
}

this.editor.renderersContainer.markForRecalculateBegin();
this.editor.renderersContainer.update(modelChanges);
}

Expand Down Expand Up @@ -257,7 +253,6 @@ class PolymerBond implements BaseTool {
this.bondRenderer?.polymerBond,
);

this.editor.renderersContainer.markForRecalculateBegin();
this.editor.renderersContainer.update(modelChanges);
}
}
Expand All @@ -276,7 +271,6 @@ class PolymerBond implements BaseTool {
attachmentPointRenderer.monomer,
this.bondRenderer?.polymerBond,
);
this.editor.renderersContainer.markForRecalculateBegin();
this.editor.renderersContainer.update(modelChanges);
}
}
Expand Down Expand Up @@ -329,8 +323,6 @@ class PolymerBond implements BaseTool {
this.editor.renderersContainer.update(modelChanges);
this.editor.renderersContainer.deletePolymerBond(
this.bondRenderer.polymerBond,
false,
false,
);
this.bondRenderer = undefined;
event.stopPropagation();
Expand Down Expand Up @@ -448,8 +440,6 @@ class PolymerBond implements BaseTool {
this.editor.renderersContainer.update(modelChanges);
this.editor.renderersContainer.deletePolymerBond(
this.bondRenderer.polymerBond,
false,
false,
);
this.bondRenderer = undefined;
this.history.update(modelChanges);
Expand Down Expand Up @@ -520,8 +510,6 @@ class PolymerBond implements BaseTool {
this.isBondConnectionModalOpen = false;
this.editor.renderersContainer.deletePolymerBond(
this.bondRenderer.polymerBond,
false,
false,
);
this.bondRenderer = undefined;
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -278,7 +278,6 @@ class SelectRectangle implements BaseTool {
this.editor.drawingEntitiesManager.showPolymerBondInformation(
renderer.polymerBond,
);
this.editor.renderersContainer.markForRecalculateBegin();
this.editor.renderersContainer.update(modelChanges);
}

Expand All @@ -293,7 +292,6 @@ class SelectRectangle implements BaseTool {
this.editor.drawingEntitiesManager.hidePolymerBondInformation(
renderer.polymerBond,
);
this.editor.renderersContainer.markForRecalculateBegin();
this.editor.renderersContainer.update(modelChanges);
}

Expand Down
2 changes: 2 additions & 0 deletions packages/ketcher-core/src/application/editor/tools/Tool.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,8 @@ interface ToolEventHandler {

rightClickPolymerBond?(event: Event): void;

rightClickSelectedMonomers?(event: Event): void;

editSequence?(): void;

startNewSequence?(): void;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,8 @@ export class AmbiguousMonomerRenderer extends BaseMonomerRenderer {

this.monomerRenderer = new MonomerRenderer(new EmptyMonomer());
this.monomerSymbolElementsIds = monomerSymbolElementsIds;
this.CHAIN_BEGINNING = this.monomerRenderer.CHAIN_BEGINNING;
this.CHAIN_START_TERMINAL_INDICATOR_TEXT =
this.monomerRenderer.CHAIN_START_TERMINAL_INDICATOR_TEXT;
}

protected appendBody(
Expand Down Expand Up @@ -122,9 +123,6 @@ export class AmbiguousMonomerRenderer extends BaseMonomerRenderer {
if (this.enumerationElementPosition) {
this.appendEnumeration();
}
if (this.CHAIN_BEGINNING) {
this.appendChainBeginning();
}
}

private appendPreviewAttachmentPoint(
Expand Down
Loading
Loading