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

feat: add possitility to generate smarts and kekule isomeric smiles #204

Merged
merged 8 commits into from
May 13, 2024
Merged
Show file tree
Hide file tree
Changes from 2 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
4 changes: 4 additions & 0 deletions __tests__/__snapshots__/library.js.snap
Original file line number Diff line number Diff line change
Expand Up @@ -296,6 +296,7 @@ exports[`prototype properties of Molecule 1`] = `
"toMolfile",
"toMolfileV3",
"toSVG",
"toSmarts",
lpatiny marked this conversation as resolved.
Show resolved Hide resolved
"toSmiles",
"translateCoords",
"validate",
Expand Down Expand Up @@ -458,6 +459,9 @@ exports[`static properties of Molecule 1`] = `
"CANONIZER_TIE_BREAK_FREE_VALENCE_ATOMS",
"FISCHER_PROJECTION_LIMIT",
"FISCHER_PROJECTION_RING_LIMIT",
"MODE_CREATE_SMARTS",
"MODE_INCLUDE_MAPPING",
"MODE_KEKULIZED_OUTPUT",
"STEREO_ANGLE_LIMIT",
"VALIDATION_ERRORS_STEREO",
"VALIDATION_ERROR_AMBIGUOUS_CONFIGURATION",
Expand Down
17 changes: 16 additions & 1 deletion __tests__/molecule.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

const fs = require('fs');

const Molecule = require('../minimal').Molecule;
const { Molecule } = require('../minimal');

describe('from and to SMILES', () => {
it.each(['C', 'COCOC', 'c1cc2cccc3c4cccc5cccc(c(c1)c23)c54'])(
Expand Down Expand Up @@ -34,6 +34,21 @@ describe('from and to SMILES', () => {
const mol = Molecule.fromSmiles(input);
expect(mol.toIsomericSmiles()).toBe(output);
});

it('smiles options', () => {
const mol = Molecule.fromSmiles('C1=CC=CC=C1');
expect(mol.toSmiles()).toBe('C1(=CC=CC=C1)');
expect(mol.toIsomericSmiles()).toBe('c1ccccc1');
expect(mol.toIsomericSmiles(Molecule.MODE_KEKULIZED_OUTPUT)).toBe('C1=CC=CC=C1');
expect(mol.toIsomericSmiles(Molecule.MODE_CREATE_SMARTS)).toBe('c1ccccc1');
mol.setAtomMapNo(0, 1);
expect(mol.toIsomericSmiles(Molecule.MODE_INCLUDE_MAPPING)).toBe('c1cc[cH:1]cc1');

const fragment = Molecule.fromSmiles('C1=CC=CC=C1C');
fragment.setFragment(true);
fragment.setAtomicNo(6, 1)
expect(fragment.toIsomericSmiles(Molecule.MODE_CREATE_SMARTS)).toBe('c1cc[c;!H0]cc1');
})
});

describe('Molecule', () => {
Expand Down
11 changes: 11 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@
},
"homepage": "https://github.com/cheminfo/openchemlib-js",
"devDependencies": {
"@types/jest": "^29.5.12",
"benchmark": "^2.1.4",
"eslint": "^8.56.0",
"eslint-config-cheminfo": "^9.1.1",
Expand Down
19 changes: 16 additions & 3 deletions src/com/actelion/research/gwt/minimal/JSMolecule.java
Original file line number Diff line number Diff line change
Expand Up @@ -82,11 +82,17 @@ public native Object getOCL()
}-*/;

public String toSmiles() {
// we still allow to old code that do not care about stereo features and provide another SMILES
return new SmilesCreator().generateSmiles(oclMolecule);
}

public String toIsomericSmiles(boolean includeAtomMapping) {
return new IsomericSmilesCreator(oclMolecule, includeAtomMapping).getSmiles();
public String toIsomericSmiles(int mode) {
return new IsomericSmilesCreator(oclMolecule, mode).getSmiles();
}

public String toSmarts() {
return new IsomericSmilesCreator(oclMolecule, IsomericSmilesCreator.MODE_CREATE_SMARTS)
.getSmiles();
}

public String toMolfile() {
Expand Down Expand Up @@ -293,7 +299,14 @@ public StereoMolecule getStereoMolecule() {
return oclMolecule;
}

// coming form Canonizer.java
// coming from IsomericSmilesCreator.java
public static final int MODE_CREATE_SMARTS = 1;
public static final int MODE_INCLUDE_MAPPING = 2;
public static final int MODE_KEKULIZED_OUTPUT = 4; // no lower case atom labels and single/double
// bonds to represent aromaticity


// coming from Canonizer.java
public static final int CANONIZER_CREATE_SYMMETRY_RANK = 1;
public static final int CANONIZER_CONSIDER_DIASTEREOTOPICITY = 2;
public static final int CANONIZER_CONSIDER_ENANTIOTOPICITY = 4;
Expand Down
9 changes: 7 additions & 2 deletions types.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,11 @@ export declare class Molecule {

// based on JSMolecule.java you can do a regexp ".*static.* (int|long|double)(.*) = .*;" and replace with "$2: number;"

static MODE_CREATE_SMARTS = 1;
static MODE_INCLUDE_MAPPING = 2;
static MODE_KEKULIZED_OUTPUT = 4; // no lower case atom labels and single/double
// bonds to represent aromaticity

static CANONIZER_CREATE_SYMMETRY_RANK: number;
static CANONIZER_CONSIDER_DIASTEREOTOPICITY: number;
static CANONIZER_CONSIDER_ENANTIOTOPICITY: number;
Expand Down Expand Up @@ -435,7 +440,7 @@ export declare class Molecule {
*/
getOCL(): any;

toSmiles(): string;
toSmiles(mode?: number): string;
lpatiny marked this conversation as resolved.
Show resolved Hide resolved

toIsomericSmiles(): string;

Expand Down Expand Up @@ -1302,7 +1307,7 @@ export declare class Molecule {
* @param mapNo
* @param autoMapped
*/
setAtomMapNo(atom: number, mapNo: number, autoMapped: boolean): void;
setAtomMapNo(atom: number, mapNo: number, autoMapped?: boolean): void;

/**
* Set atom to specific isotop or to have a natural isotop distribution
Expand Down
Loading