Skip to content

Commit

Permalink
Backmerge: #5634 - ketcher.getMolfile() stopped working for macro can…
Browse files Browse the repository at this point in the history
…vas with peptides (#5750)
  • Loading branch information
rrodionov91 authored and Guch1g0v committed Oct 17, 2024
1 parent 75416b5 commit f51d1af
Show file tree
Hide file tree
Showing 22 changed files with 122 additions and 104 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -109,34 +109,31 @@ test.describe('CML files', () => {
expect(cmlFile).toEqual(cmlFileExpected);
});

test.fail(
'Open and Save file - CML - CML for R-group and other features',
async ({ page }) => {
/**
* Test case: EPMLSOPKET-1948
* Description: Saved cml file with structure is compering with paste R-group from a mol file
* It needs to be investigated why the test is failing.
* We have bug https://github.com/epam/Indigo/issues/2497
*/

await openFileAddToCanvasTakeScreenshot(
page,
'Molfiles-V2000/cml-1948-R-group.mol',
);
// check that structure opened from file is displayed correctly
test('Open and Save file - CML - CML for R-group and other features', async ({
page,
}) => {
/**
* Test case: EPMLSOPKET-1948
* Description: Saved cml file with structure is compering with paste R-group from a mol file
*/

const expectedFile = await getCml(page);
await saveToFile('CML/cml-1948-r-group-expected.cml', expectedFile);
const { file: cmlFile, fileExpected: cmlFileExpected } =
await receiveFileComparisonData({
page,
expectedFileName: 'tests/test-data/CML/cml-1948-r-group-expected.cml',
});
// comparing cml file with golden cml file
await openFileAddToCanvasTakeScreenshot(
page,
'Molfiles-V2000/cml-1948-R-group.mol',
);
// check that structure opened from file is displayed correctly

expect(cmlFile).toEqual(cmlFileExpected);
},
);
const expectedFile = await getCml(page);
await saveToFile('CML/cml-1948-r-group-expected.cml', expectedFile);
const { file: cmlFile, fileExpected: cmlFileExpected } =
await receiveFileComparisonData({
page,
expectedFileName: 'tests/test-data/CML/cml-1948-r-group-expected.cml',
});
// comparing cml file with golden cml file

expect(cmlFile).toEqual(cmlFileExpected);
});

test('Validate that unsplit nucleotides connected with peptides could be saved to CML file and loaded back', async ({
page,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -178,35 +178,33 @@ test.describe('Save files', () => {
},
);

test.fail(
'Automatic selection of MDL Molfile v3000 encoding is work if the number of atoms (or bonds) exceeds 999',
async ({ page }) => {
/**
* IMPORTANT: Test fails because we have bug https://github.com/epam/Indigo/issues/2494
* Test case: EPMLSOPKET-5260
* Description: Structure is saved according to automated selected format MDL Molfile v3000
*/

await openFileAndAddToCanvas(
'Molfiles-V3000/structure-where-atoms-exceeds999.mol',
test('Automatic selection of MDL Molfile v3000 encoding is work if the number of atoms (or bonds) exceeds 999', async ({
page,
}) => {
/**
* Test case: EPMLSOPKET-5260
* Description: Structure is saved according to automated selected format MDL Molfile v3000
*/

await openFileAndAddToCanvas(
'Molfiles-V3000/structure-where-atoms-exceeds999.mol',
page,
);
const expectedFile = await getMolfile(page);
await saveToFile(
'Molfiles-V3000/structure-where-atoms-exceeds999-expected.mol',
expectedFile,
);
const METADATA_STRING_INDEX = [1];
const { fileExpected: molFileExpected, file: molFile } =
await receiveFileComparisonData({
page,
);
const expectedFile = await getMolfile(page);
await saveToFile(
'Molfiles-V3000/structure-where-atoms-exceeds999-expected.mol',
expectedFile,
);
const METADATA_STRING_INDEX = [1];
const { fileExpected: molFileExpected, file: molFile } =
await receiveFileComparisonData({
page,
expectedFileName:
'tests/test-data/Molfiles-V3000/structure-where-atoms-exceeds999-expected.mol',
metaDataIndexes: METADATA_STRING_INDEX,
});
expect(molFile).toEqual(molFileExpected);
},
);
expectedFileName:
'tests/test-data/Molfiles-V3000/structure-where-atoms-exceeds999-expected.mol',
metaDataIndexes: METADATA_STRING_INDEX,
});
expect(molFile).toEqual(molFileExpected);
});

test('The file formats in the Save Structure window match the mockup', async ({
page,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -380,40 +380,36 @@ test.describe('Import-Saving .mol Files', () => {
await turnOnMacromoleculesEditor(page);
});

test.fail(
'Check that you can save snake viewed chain of peptides in a Mol v3000 file',
{ tag: ['@IncorrectResultBecauseOfBug'] },
async () => {
/*
test('Check that you can save snake viewed chain of peptides in a Mol v3000 file', async () => {
/*
Test case: Import/Saving files
Description: Snake viewed chain of peptides saved in a Mol v3000 file
Test fails because we have bug https://github.com/epam/ketcher/issues/5634
*/
await openFileAndAddToCanvasMacro(
'Molfiles-V3000/snake-mode-peptides.mol',
page,
);
await selectSnakeLayoutModeTool(page);
const expectedFile = await getMolfile(page);
await saveToFile(
'Molfiles-V3000/snake-mode-peptides-expected.mol',
expectedFile,
);
await openFileAndAddToCanvasMacro(
'Molfiles-V3000/snake-mode-peptides.mol',
page,
);
await selectSnakeLayoutModeTool(page);
const expectedFile = await getMolfile(page);
await saveToFile(
'Molfiles-V3000/snake-mode-peptides-expected.mol',
expectedFile,
);

const METADATA_STRING_INDEX = [1];
const METADATA_STRING_INDEX = [1];

const { fileExpected: molFileExpected, file: molFile } =
await receiveFileComparisonData({
page,
expectedFileName:
'tests/test-data/Molfiles-V3000/snake-mode-peptides-expected.mol',
metaDataIndexes: METADATA_STRING_INDEX,
});
const { fileExpected: molFileExpected, file: molFile } =
await receiveFileComparisonData({
page,
expectedFileName:
'tests/test-data/Molfiles-V3000/snake-mode-peptides-expected.mol',
metaDataIndexes: METADATA_STRING_INDEX,
});

expect(molFile).toEqual(molFileExpected);
},
);
expect(molFile).toEqual(molFileExpected);
});

test('Check that .mol file with macro structures is imported correctly in macro mode when saving it in micro mode', async () => {
/*
Expand Down
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.
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 @@ -82,4 +82,5 @@ export interface Editor {
macromoleculeConvertionError: string | null | undefined;
setMacromoleculeConvertionError: (errorMessage: string) => void;
clearMacromoleculeConvertionError: () => void;
serverSettings: object;
}
13 changes: 8 additions & 5 deletions packages/ketcher-core/src/application/indigo.ts
Original file line number Diff line number Diff line change
Expand Up @@ -113,12 +113,15 @@ export class Indigo {
});
}

layout(struct: StructOrString): Promise<Struct> {
layout(struct: StructOrString, options): Promise<Struct> {
return this.#structService
.layout({
struct: convertStructToString(struct, this.#ketSerializer),
output_format: ChemicalMimeType.KET,
})
.layout(
{
struct: convertStructToString(struct, this.#ketSerializer),
output_format: ChemicalMimeType.KET,
},
options,
)
.then((data) => this.#ketSerializer.deserialize(data.struct));
}

Expand Down
14 changes: 9 additions & 5 deletions packages/ketcher-core/src/application/ketcher.ts
Original file line number Diff line number Diff line change
Expand Up @@ -413,7 +413,10 @@ export class Ketcher {
}

runAsyncAction<void>(async () => {
const struct = await this._indigo.layout(this.#editor.struct());
const struct = await this._indigo.layout(
this.#editor.struct(),
this.editor.serverSettings,
);
const ketSerializer = new KetSerializer();
this.setMolecule(ketSerializer.serialize(struct));
}, this.eventBus);
Expand Down Expand Up @@ -480,11 +483,12 @@ export class Ketcher {
meta = 'image/png';
options.outputFormat = 'png';
}
const serverSettings = this.editor.serverSettings;

const base64 = await this.structService.generateImageAsBase64(
data,
options,
);
const base64 = await this.structService.generateImageAsBase64(data, {
...serverSettings,
...options,
});
const byteCharacters = atob(base64);
const byteNumbers = new Array(byteCharacters.length);
for (let i = 0; i < byteCharacters.length; i++) {
Expand Down
4 changes: 3 additions & 1 deletion packages/ketcher-core/src/application/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,9 @@ export function getStructure(
drawingEntitiesManager?: DrawingEntitiesManager,
selection?: EditorSelection,
): Promise<string> {
const formatter = formatterFactory.create(structureFormat);
const serverSettings = ketcherProvider.getKetcher().editor.serverSettings;
const formatter = formatterFactory.create(structureFormat, serverSettings);

return formatter.getStructureFromStructAsync(
struct,
drawingEntitiesManager,
Expand Down
9 changes: 8 additions & 1 deletion packages/ketcher-react/src/script/editor/Editor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -162,10 +162,12 @@ class Editor implements KetcherEditor {
updateFloatingTools: Subscription<FloatingToolsParams>;
};

public serverSettings = {};

lastEvent: any;
macromoleculeConvertionError: string | null | undefined;

constructor(clientArea, options) {
constructor(clientArea, options, serverSettings) {
this.render = new Render(
clientArea,
Object.assign(
Expand All @@ -186,6 +188,7 @@ class Editor implements KetcherEditor {
this.renderAndRecoordinateStruct =
this.renderAndRecoordinateStruct.bind(this);
this.setOptions = this.setOptions.bind(this);
this.setServerSettings(serverSettings);

this.lastCursorPosition = {
x: 0,
Expand Down Expand Up @@ -339,6 +342,10 @@ class Editor implements KetcherEditor {
return this.render.options;
}

public setServerSettings(serverSettings) {
this.serverSettings = serverSettings;
}

private updateToolAfterOptionsChange(wasViewOnlyEnabled: boolean) {
const isViewOnlyEnabled = this.render.options.viewOnlyMode;
if (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ describe('Rotate controller', () => {
* 2. click Rotate Tool
*/
it('hides when active tool is not SelectTool', () => {
const editor = new Editor(document, {});
const editor = new Editor(document, {}, {});
const NonSelectTool = new RotateTool(editor, undefined);
const paper = jest.fn();
const visibleAtoms = [0, 1];
Expand Down Expand Up @@ -89,7 +89,7 @@ describe('Rotate controller', () => {
* Click `zoom in` or press `Ctrl+=`
*/
it('rerenders while zooming', () => {
const editor = new Editor(document, {});
const editor = new Editor(document, {}, {});
editor.rotateController.rerender = jest.fn();

editor.zoom(2);
Expand Down Expand Up @@ -203,7 +203,7 @@ describe('Rotate controller', () => {
* 2. Undo
*/
it(`cancels rotation without modifying history stack`, () => {
const editor = new Editor(document, {});
const editor = new Editor(document, {}, {});
editor.render.ctab.molecule.getSelectedVisibleAtoms = () => [];
// @ts-ignore
editor.rotateController.rotateTool.dragCtx = {
Expand Down
12 changes: 7 additions & 5 deletions packages/ketcher-react/src/script/ui/views/Editor.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -35,12 +35,14 @@ const mapDispatchToProps = (dispatch) => {
};
};

const Editor = connect(
(state) => ({
const Editor = connect((state) => {
const serverSettings = state.options.getServerSettings();

return {
options: state.options.settings,
serverSettings,
indigoVerification: state.requestsStatuses.indigoVerification,
}),
mapDispatchToProps,
)(StructEditor);
};
}, mapDispatchToProps)(StructEditor);

export default Editor;
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,10 @@ function setupEditor(editor, props, oldProps = {}) {
}
}

if (oldProps.options && options !== oldProps.options) editor.options(options);
if (oldProps.options && options !== oldProps.options) {
editor.options(options);
editor.setServerSettings(props.serverSettings);
}

Object.keys(editor.event).forEach((name) => {
const eventName = `on${upperFirst(name)}`;
Expand Down Expand Up @@ -147,9 +150,13 @@ class StructEditor extends Component {
}

componentDidMount() {
this.editor = new Editor(this.editorRef.current, {
...this.props.options,
});
this.editor = new Editor(
this.editorRef.current,
{
...this.props.options,
},
{ ...this.props.serverSettings },
);
const ketcher = ketcherProvider.getKetcher();
if (ketcher?.editor.macromoleculeConvertionError) {
this.props.onShowMacromoleculesErrorMessage(
Expand Down Expand Up @@ -287,6 +294,7 @@ class StructEditor extends Component {
showAttachmentPoints = true,
onUpdateFloatingTools,
onShowMacromoleculesErrorMessage,
serverSettings,
/* eslint-enable @typescript-eslint/no-unused-vars */
...props
} = this.props;
Expand Down

0 comments on commit f51d1af

Please sign in to comment.