Skip to content

Commit

Permalink
#5634 - ketcher.getMolfile() stopped working for macro canvas with pe…
Browse files Browse the repository at this point in the history
…ptides
  • Loading branch information
rrodionov91 committed Oct 13, 2024
1 parent 5d7f256 commit 49f5b8a
Show file tree
Hide file tree
Showing 7 changed files with 49 additions and 23 deletions.
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
17 changes: 10 additions & 7 deletions packages/ketcher-core/src/application/ketcher.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import { saveAs } from 'file-saver';
import { FormatterFactory, SupportedFormat } from './formatters';
import { GenerateImageOptions, StructService } from 'domain/services';

import { CoreEditor, Editor, defaultBondThickness } from './editor';
import { CoreEditor, Editor } from './editor';
import { Indigo } from 'application/indigo';
import { KetSerializer, MolfileFormat } from 'domain/serializers';
import { SGroup, Struct } from 'domain/entities';
Expand Down 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 @@ -465,7 +468,6 @@ export class Ketcher {
data: string,
options: GenerateImageOptions = {
outputFormat: 'png',
bondThickness: defaultBondThickness,
},
): Promise<Blob> {
let meta = '';
Expand All @@ -480,11 +482,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
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 49f5b8a

Please sign in to comment.