Skip to content

Commit

Permalink
#3531 – updated documentation for Ketcher API
Browse files Browse the repository at this point in the history
  • Loading branch information
Nitvex committed Dec 1, 2023
1 parent df7205c commit da42b41
Show file tree
Hide file tree
Showing 3 changed files with 63 additions and 2 deletions.
60 changes: 60 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,66 @@ Ketcher uses Miew-React for viewing and editing data in 3D.
You can find the latest version of Miew-React [here](https://github.com/epam/miew/tree/master/packages/miew-react).
The last checked version - [1.0.0](https://www.npmjs.com/package/miew-react).

## Ketcher API
Ketcher can return drawn structures using the following methods:

`getSmiles(isExtended = false): Promise<string>` – returns `string` representation of drawn structure in SMILES format.
Parameters: `isExtended: boolean`. By default, `false`. Indicates, whether extended SMILES format needs to be used.

`getMolfile(molfileFormat): Promise<string>` – returns `string` representation of drawn structure in MOL-format.
Parameters: `molfileFormat: 'v2000' | 'v3000'`. Optional, by default, 'auto'. Indicates, in which format result will be returned. If no desired format is provided, then it is chosen automatically, depending on drawn structure.

`getRxn(molfileFormat): Promise<string>` – returns `string` representation of drawn structure in RXN-format.
Parameters: `molfileFormat: 'v2000' | 'v3000'`. Optional, by default, 'v2000'. Indicates, in which format result will be returned.

`getKet(): Promise<string>` – returns `string` representation of drawn structure is internal Ket-format.

`getSmarts(): Promise<string>` – returns `string` representation of drawn structure in Smarts-format.

`getCml(): Promise<string>` – returns `string` representation of drawn structure in Cml-format.

`getSdf(molfileFormat): Promise<string>` – returns `string` representation of drawn structure in Sdf-format.
Parameters: `molfileFormat: 'v2000' | 'v3000'`. Optional, by default, 'v2000'. Indicates, in which format result will be returned.

`getCDXml(): Promise<string>` – returns `string` representation of drawn structure in CDXml-format.

`getCDX(): Promise<string>` – returns `string` representation of drawn structure in CDX-format.

`getInchi(withAuxInfo = false): Promise<string>` – returns `string` representation of drawn structure in Inchi-format.
Parameters: `withAuxInfo: boolean`. Optional, by default, `false`.

`getInchiKey(): Promise<string>` – returns `string` representation of drawn structure in InChiKey-format.

`containsReaction(): boolean` – returns `true`, in case drawn structure contains reaction; `false` otherwise.

`isQueryStructureSelected(): boolean` – returns `true`, in case selected structure has query.

`setMolecule(structure: string): Promise<void>` – draws passed structure on the canvas. Before drawing passed structure, current structure is removed.
Parameters: `structure: string`. Structure is a string in any supported format.

`setMolecule(structure: string): Promise<void>` – adds passed structure on the canvas. Current structure is not changed.
Parameters: `structure: string`. Structure is a string in any supported format.

`layout(): Promise<void>` – performs layout algorithm for drawn structure.

`recognize(image: Blob, version?: string): Promise<Struct>` – recognizes a structure from image.
Parameters: `image: Blob` – image to recognize. Returns `Struct` – object, which represents recognized structure.

```
generateImage(data: string, options: {
outputFormat: 'png' | 'svg';
backgroundColor: string;
bondThickness: number;
}): Promise<Blob>
```
Generates image from passed structure.
Parameters:
`data``string` representation of structure in any supported format.
`options` – object with the following properties:
* `outputFormat` – can be 'png' or 'svg'
* `backgroundColor` – image background color
* `bondThickness` – thickness of bonds in output structure

## Settings

You can add extra configuration in editor.setSetting
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -823,7 +823,6 @@ test.describe('RNA Library', () => {
/*
Test case: Open&save files
Description: File saved with three Monomers as .ket file
Test working as not expected. API getKet returns an incorrect ket.
*/
await openFileAndAddToCanvas('KET/monomers-connected-with-bonds.ket', page);
const expectedFile = await getKet(page);
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 @@ -6,7 +6,7 @@ import {
} from './formatters';
import { Ketcher } from './ketcher';
import { ChemicalMimeType, StructService } from 'domain/services';
import { CoreEditor } from './editor';
import { CoreEditor, EditorHistory } from './editor';
import { KetSerializer } from 'domain/serializers';
import assert from 'assert';

Expand Down Expand Up @@ -99,5 +99,7 @@ export async function parseAndAddMacromoleculesOnCanvas(
deserialisedKet.drawingEntitiesManager.mergeInto(
editor.drawingEntitiesManager,
);

new EditorHistory(editor).update(deserialisedKet.modelChanges);
editor.renderersContainer.update(deserialisedKet.modelChanges);
}

0 comments on commit da42b41

Please sign in to comment.