Skip to content

Commit

Permalink
feat: implement generic editor (#219)
Browse files Browse the repository at this point in the history
Closes: #136
Refs: Actelion/openchemlib#111
Co-authored-by: tpoisseau <[email protected]>
  • Loading branch information
targos and tpoisseau authored Jul 25, 2024
1 parent 88c9b40 commit 8a8185f
Show file tree
Hide file tree
Showing 118 changed files with 10,477 additions and 4,515 deletions.
1 change: 0 additions & 1 deletion .eslintignore

This file was deleted.

9 changes: 0 additions & 9 deletions .eslintrc.yml

This file was deleted.

4 changes: 2 additions & 2 deletions .github/workflows/nodejs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -49,9 +49,9 @@ jobs:
run: npm run build-debug-full
- name: Upload debug build and logs
if: failure()
uses: actions/upload-artifact@v3
uses: actions/upload-artifact@v4
with:
name: debug-build
name: debug-build-${{ matrix.node-version }}
path: |
dist/openchemlib-full.pretty.js
compile-full.log
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,9 @@ war/**
*.log
/gwt/
gwt.zip
/jdk/
jdk.tar.gz
/dist/
/distbuild/
/distold/
/distesm/
1 change: 1 addition & 0 deletions .node-version
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
22
9 changes: 9 additions & 0 deletions .prettierignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
/CHANGELOG.md
/dist
/distbuild
/distesm
/distold
/gwt
/lib/canvas_editor/cursors_24px.js
/openchemlib
/war
17 changes: 17 additions & 0 deletions .run/Build java.run.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<component name="ProjectRunConfigurationManager">
<configuration default="false" name="Build java" type="ShConfigurationType">
<option name="SCRIPT_TEXT" value="npm run build-full-pretty" />
<option name="INDEPENDENT_SCRIPT_PATH" value="true" />
<option name="SCRIPT_PATH" value="" />
<option name="SCRIPT_OPTIONS" value="" />
<option name="INDEPENDENT_SCRIPT_WORKING_DIRECTORY" value="true" />
<option name="SCRIPT_WORKING_DIRECTORY" value="$PROJECT_DIR$" />
<option name="INDEPENDENT_INTERPRETER_PATH" value="true" />
<option name="INTERPRETER_PATH" value="/bin/zsh" />
<option name="INTERPRETER_OPTIONS" value="" />
<option name="EXECUTE_IN_TERMINAL" value="true" />
<option name="EXECUTE_SCRIPT_FILE" value="false" />
<envs />
<method v="2" />
</configuration>
</component>
7 changes: 7 additions & 0 deletions .run/Run JS DEV.run.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<component name="ProjectRunConfigurationManager">
<configuration default="false" name="Run JS DEV" type="CompoundRunConfigurationType">
<toRun name="build-esm-bundle-watch" type="js.build_tools.npm" />
<toRun name="vite" type="js.build_tools.npm" />
<method v="2" />
</configuration>
</component>
12 changes: 12 additions & 0 deletions .run/build-esm-bundle-watch.run.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<component name="ProjectRunConfigurationManager">
<configuration default="false" name="build-esm-bundle-watch" type="js.build_tools.npm" nameIsGenerated="true">
<package-json value="$PROJECT_DIR$/package.json" />
<command value="run" />
<scripts>
<script value="build-esm-bundle-watch" />
</scripts>
<node-interpreter value="project" />
<envs />
<method v="2" />
</configuration>
</component>
12 changes: 12 additions & 0 deletions .run/vite.run.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<component name="ProjectRunConfigurationManager">
<configuration default="false" name="vite" type="js.build_tools.npm" nameIsGenerated="true">
<package-json value="$PROJECT_DIR$/package.json" />
<command value="run" />
<scripts>
<script value="vite" />
</scripts>
<node-interpreter value="project" />
<envs />
<method v="2" />
</configuration>
</component>
2 changes: 1 addition & 1 deletion __tests__/SmilesParser.js
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ it('should should optionally not invent coordinates', () => {

it('should should optionally not parse stereo features', () => {
const parser = new SmilesParser();
const vitaminA = 'C/C(=C\\CO)/C=C/C=C(/C)\\C=C\\C1=C(C)CCCC1(C)C';
const vitaminA = String.raw`C/C(=C\CO)/C=C/C=C(/C)\C=C\C1=C(C)CCCC1(C)C`;
const molecule = new Molecule(0, 0);
parser.parseMolecule(vitaminA, { molecule, noStereo: true });
const idCodeWithoutStereo = molecule.getIDCode();
Expand Down
8 changes: 8 additions & 0 deletions __tests__/__snapshots__/library.js.snap
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

exports[`prototype properties of CanonizerUtil 1`] = `[]`;

exports[`prototype properties of CanvasEditor 1`] = `[]`;

exports[`prototype properties of ConformerGenerator 1`] = `
[
"getConformerCount",
Expand Down Expand Up @@ -405,6 +407,8 @@ exports[`prototype properties of Transformer 1`] = `

exports[`prototype properties of Util 1`] = `[]`;

exports[`prototype properties of registerCustomElement 1`] = `[]`;

exports[`static properties of CanonizerUtil 1`] = `
[
"BACKBONE",
Expand All @@ -416,6 +420,8 @@ exports[`static properties of CanonizerUtil 1`] = `
]
`;

exports[`static properties of CanvasEditor 1`] = `[]`;

exports[`static properties of ConformerGenerator 1`] = `
[
"STRATEGY_ADAPTIVE_RANDOM",
Expand Down Expand Up @@ -776,3 +782,5 @@ exports[`static properties of Util 1`] = `
"getHoseCodesFromDiastereotopicID",
]
`;

exports[`static properties of registerCustomElement 1`] = `[]`;
3 changes: 2 additions & 1 deletion __tests__/__snapshots__/reaction.js.snap
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,8 @@ exports[`Reaction class should load and create RXN files 2`] = `
OCL_RXN_V1.0:gJX@@eKU@@ gGQHDHaInfh@!gJX@@eKU@@ fHdP@@##!ROvp@[C}c@FNZz@@ !R_\`CW?Hc|_\`BH_Ykh@@ !ROvp@[C}c@FNZz@@ !RGP@@##
VM V30 BEGIN REACTANT
M V30 COUNTS 2 2
M V30 BEGIN REACTANT
M V30 BEGIN CTAB
M V30 COUNTS 6 5 0 0 0
M V30 BEGIN ATOM
Expand Down
20 changes: 13 additions & 7 deletions __tests__/library.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,13 @@ const coreAPI = [
'Transformer',
];

const fullAPI = ['StructureView', 'StructureEditor', 'SVGRenderer'];
const fullAPI = [
'CanvasEditor',
'registerCustomElement',
'StructureView',
'StructureEditor',
'SVGRenderer',
];

const allAPI = [...minimalAPI, ...coreAPI, ...fullAPI];

Expand All @@ -47,12 +53,12 @@ test('core', () => {
});

test('full', () => {
[full, pretty].forEach((lib) => {
for (const lib of [full, pretty]) {
checkHas(lib, allAPI);
});
}
});

allAPI.forEach((key) => {
for (const key of allAPI) {
const api = full[key];
if (typeof api === 'function') {
test(`static properties of ${key}`, () => {
Expand All @@ -64,16 +70,16 @@ allAPI.forEach((key) => {
});
}
}
});
}

function checkHas(obj, properties) {
expect(Object.keys(obj).sort()).toStrictEqual(properties.sort());
}

function checkHasNot(obj, properties) {
properties.forEach((prop) => {
for (const prop of properties) {
expect(obj).not.toHaveProperty(prop);
});
}
}

function getFilteredKeys(obj) {
Expand Down
2 changes: 1 addition & 1 deletion __tests__/molecule.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
'use strict';

const fs = require('fs');
const fs = require('node:fs');

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

Expand Down
10 changes: 6 additions & 4 deletions __tests__/molfileAndAtomMapNo.test.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
'use strict';

const { readFileSync } = require('fs');
const { readFileSync } = require('node:fs');

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

Expand All @@ -11,9 +11,11 @@ test('molfile with atomMapNo', () => {
const newMolfile = molecule.toMolfile();
const atomMapNo = newMolfile
.split(/\r?\n/)
.filter((line) => line.match(/ [OCH] /))
// eslint-disable-next-line prefer-named-capture-group
.map((line) => line.replace(/.* ([OCH]) .*(.) {2}0 {2}0$/, '$1 $2'));
.filter((line) => line.match(/ [CHO] /))
.map((line) =>
line.replace(/.* (?<och>[CHO]) .*(?<n>.) {2}0 {2}0$/, '$<och> $<n>'),
);

expect(atomMapNo).toStrictEqual(['O 5', 'C 1', 'C 3', 'C 4', 'H 2']);

const svg = molecule.toSVG(300, 200);
Expand Down
3 changes: 1 addition & 2 deletions __tests__/sssearcher.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,7 @@ describe('SSSearcher', () => {
let benzeneFragment = Molecule.fromSmiles('c1ccccc1');
benzeneFragment.setFragment(true);
let ethylBenzene = Molecule.fromSmiles('CCc1ccccc1');
let allicin = Molecule.fromSmiles('O=S(SC\\C=C)C\\C=C');

let allicin = Molecule.fromSmiles(String.raw`O=S(SC\C=C)C\C=C`);
it('should find in itself', () => {
let searcher = new SSSearcher();
searcher.setMolecule(benzene);
Expand Down
2 changes: 1 addition & 1 deletion __tests__/sssearcher_with_index.js
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ function getTestData() {
const ethylBenzene = Molecule.fromSmiles('CCc1ccccc1');
const ethylBenzeneIndex = searcher.createIndex(ethylBenzene);

const allicin = Molecule.fromSmiles('O=S(SC\\C=C)C\\C=C');
const allicin = Molecule.fromSmiles(String.raw`O=S(SC\C=C)C\C=C`);
const allicinIndex = searcher.createIndex(allicin);
return {
benzene,
Expand Down
3 changes: 0 additions & 3 deletions benchmark/.eslintrc.yml

This file was deleted.

24 changes: 0 additions & 24 deletions benchmark/diastereoID.js

This file was deleted.

16 changes: 16 additions & 0 deletions benchmark/diastereoID.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import { getDiastereotopicAtomIDs } from 'openchemlib-utils';

import { Molecule, version } from '../full.js';

console.log('OCL version', version);
console.time('diastereoID');
const response = await fetch('https://wikipedia.cheminfo.org/data.json');
const { data } = await response.json();
let totalLength = 0;
for (const entry of data.molecules.slice(0, 700)) {
const molecule = Molecule.fromIDCode(entry.idCode);
const ids = getDiastereotopicAtomIDs(molecule);
totalLength += ids.length;
}
console.timeEnd('diastereoID');
console.log(totalLength);
8 changes: 3 additions & 5 deletions benchmark/molfile.js → benchmark/molfile.mjs
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
'use strict';
import Benchmark from 'benchmark';

const Benchmark = require('benchmark');

const OCLOld = require('../distold/openchemlib-full.pretty');
const OCLNew = require('../full.pretty');
import OCLOld from '../distold/openchemlib-full.pretty.js';
import OCLNew from '../full.pretty.js';

const idcode = 'enYXNH@MHDAELem`OCIILdhhdiheCDlieKDdefndZRVVjjfjjfjihJBbb@@@';
const mol = OCLNew.Molecule.fromIDCode(idcode);
Expand Down
8 changes: 3 additions & 5 deletions benchmark/sssearcher.js → benchmark/sssearcher.mjs
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
'use strict';
import Benchmark from 'benchmark';

const Benchmark = require('benchmark');

const OCLOld = require('../distold/openchemlib-full.pretty');
const OCLNew = require('../full.pretty');
import OCLOld from '../distold/openchemlib-full.pretty.js';
import OCLNew from '../full.pretty.js';

let benzeneFragmentNew = OCLNew.Molecule.fromSmiles('c1ccccc1');
benzeneFragmentNew.setFragment(true);
Expand Down
22 changes: 0 additions & 22 deletions benchmark/wikipedia.js

This file was deleted.

14 changes: 14 additions & 0 deletions benchmark/wikipedia.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import { Molecule, version } from '../full.js';

console.log('OCL version', version);
console.time('wikipedia');
const response = await fetch('https://wikipedia.cheminfo.org/data.json');
const { data } = await response.json();
const idCodes = [];
for (const entry of data.molecules.slice(0, 10000)) {
const molecule = Molecule.fromIDCode(entry.idCode);
const idCode = molecule.getIDCode();
idCodes.push(idCode);
}
console.timeEnd('wikipedia');
console.log(idCodes.join(',').length);
Loading

0 comments on commit 8a8185f

Please sign in to comment.