diff --git a/.eslintrc.yml b/.eslintrc.yml deleted file mode 100644 index 5c90981e..00000000 --- a/.eslintrc.yml +++ /dev/null @@ -1,17 +0,0 @@ -extends: cheminfo -env: - amd: true - browser: true - jest: true -parserOptions: - sourceType: module - ecmaVersion: '2018' - -rules: - import/no-amd: 0 - import/unambiguous: 0 - import/no-unresolved: 0 - import/no-extraneous-dependencies: 0 - import/default: 0 - import/no-named-as-default: 0 - import/no-named-as-default-member: 0 diff --git a/.github/workflows/nodejs.yml b/.github/workflows/nodejs.yml new file mode 100644 index 00000000..fee873d7 --- /dev/null +++ b/.github/workflows/nodejs.yml @@ -0,0 +1,16 @@ +name: Node.js CI + +on: + push: + branches: + - main + pull_request: + +jobs: + nodejs: + uses: zakodium/workflows/.github/workflows/nodejs.yml@nodejs-v1 + with: + node-version: '24.x' + node-version-matrix: '[24]' + disable-test-package: true + upload-coverage: false diff --git a/.prettierignore b/.prettierignore new file mode 100644 index 00000000..5f11b1c1 --- /dev/null +++ b/.prettierignore @@ -0,0 +1,6 @@ +tiles/font-awesome +util/aesjs.js +util/cloneDeepLimitArray.js +util/md5.js +util/yamlParser.js, +spectra-data/conrec.js diff --git a/.travis.yml b/.travis.yml deleted file mode 100644 index d6b81871..00000000 --- a/.travis.yml +++ /dev/null @@ -1,3 +0,0 @@ -language: node_js -node_js: - - node diff --git a/ChemEquilibrium/AcidModel.js b/ChemEquilibrium/AcidModel.js index c0ec6cbd..ad7d48c9 100644 --- a/ChemEquilibrium/AcidModel.js +++ b/ChemEquilibrium/AcidModel.js @@ -1,5 +1,151 @@ - -var pkas = [{ ha: 'HIO3', a: 'IO3-', pka: 0.8, specie: { label: 'IO3-', number: 1, pka: 0.8 } }, { ha: 'H3PO4', a: 'H2PO4-', pka: 2.16, specie: { label: 'PO4---', number: 3, pka: 21.69 } }, { ha: 'H2PO4-', a: 'HPO4--', pka: 7.21, specie: { label: 'PO4---', number: 2, pka: 19.53 } }, { ha: 'HPO4--', a: 'PO4---', pka: 12.32, specie: { label: 'PO4---', number: 1, pka: 12.32 } }, { ha: 'HF', a: 'F-', pka: 3.2, specie: { label: 'F-', number: 1, pka: 3.2 } }, { ha: 'HNO2', a: 'NO2-', pka: 3.25, specie: { label: 'NO2-', number: 1, pka: 3.25 } }, { ha: 'HOCN', a: 'OCN-', pka: 3.48, specie: { label: 'OCN-', number: 1, pka: 3.48 } }, { ha: 'H2CO3', a: 'HCO3-', pka: 6.35, specie: { label: 'CO3--', number: 2, pka: 16.68 } }, { ha: 'HCO3-', a: 'CO3--', pka: 10.33, specie: { label: 'CO3--', number: 1, pka: 10.33 } }, { ha: 'H2S', a: 'HS-', pka: 7.05, specie: { label: 'S--', number: 2, pka: 19.14 } }, { ha: 'HS-', a: 'S--', pka: 12.09, specie: { label: 'S--', number: 1, pka: 12.09 } }, { ha: 'HClO', a: 'ClO-', pka: 7.4, specie: { label: 'ClO-', number: 1, pka: 7.4 } }, { ha: 'HBrO', a: 'BrO-', pka: 8.6, specie: { label: 'BrO-', number: 1, pka: 8.6 } }, { ha: 'HCN', a: 'CN-', pka: 9.21, specie: { label: 'CN-', number: 1, pka: 9.21 } }, { ha: 'NH4+', a: 'NH3', pka: 9.25, specie: { label: 'NH3', number: 1, pka: 9.25 } }, { ha: 'CH2ClCOOH', a: 'CH2ClCOO-', pka: 2.89, specie: { label: 'CH2ClCOO-', number: 1, pka: 2.89 } }, { ha: 'HCOOH', a: 'HCOO-', pka: 3.75, specie: { label: 'HCOO-', number: 1, pka: 3.75 } }, { ha: 'C6H5COOH', a: 'C6H5COO-', pka: 4.2, specie: { label: 'C6H5COO-', number: 1, pka: 4.2 } }, { ha: 'C66H5NH3+', a: 'C66H5NH2', pka: 4.6, specie: { label: 'C66H5NH2', number: 1, pka: 4.6 } }, { ha: 'CH3COOH', a: 'CH3COO-', pka: 4.75, specie: { label: 'CH3COO-', number: 1, pka: 4.75 } }, { ha: 'C2H5COOH', a: 'C2H5COO-', pka: 4.87, specie: { label: 'C2H5COO-', number: 1, pka: 4.87 } }, { ha: 'C5H5NH+', a: 'C5H5N', pka: 5.25, specie: { label: 'C5H5N', number: 1, pka: 5.25 } }, { ha: 'CH3NH3+', a: 'CH3NH2', pka: 10.66, specie: { label: 'CH3NH2', number: 1, pka: 10.66 } }, { ha: '(C2H5)3NH+', a: '(C2H5)3N', pka: 10.75, specie: { label: '(C2H5)3N', number: 1, pka: 10.75 } }, { ha: 'C2H5NH3+', a: 'C2H5NH2', pka: 10.8, specie: { label: 'C2H5NH2', number: 1, pka: 10.8 } }, { ha: 'HCl', a: 'Cl-', pka: 1, specie: { label: 'Cl-', number: 1, pka: 1 } }]; +let pkas = [ + { + ha: 'HIO3', + a: 'IO3-', + pka: 0.8, + specie: { label: 'IO3-', number: 1, pka: 0.8 }, + }, + { + ha: 'H3PO4', + a: 'H2PO4-', + pka: 2.16, + specie: { label: 'PO4---', number: 3, pka: 21.69 }, + }, + { + ha: 'H2PO4-', + a: 'HPO4--', + pka: 7.21, + specie: { label: 'PO4---', number: 2, pka: 19.53 }, + }, + { + ha: 'HPO4--', + a: 'PO4---', + pka: 12.32, + specie: { label: 'PO4---', number: 1, pka: 12.32 }, + }, + { ha: 'HF', a: 'F-', pka: 3.2, specie: { label: 'F-', number: 1, pka: 3.2 } }, + { + ha: 'HNO2', + a: 'NO2-', + pka: 3.25, + specie: { label: 'NO2-', number: 1, pka: 3.25 }, + }, + { + ha: 'HOCN', + a: 'OCN-', + pka: 3.48, + specie: { label: 'OCN-', number: 1, pka: 3.48 }, + }, + { + ha: 'H2CO3', + a: 'HCO3-', + pka: 6.35, + specie: { label: 'CO3--', number: 2, pka: 16.68 }, + }, + { + ha: 'HCO3-', + a: 'CO3--', + pka: 10.33, + specie: { label: 'CO3--', number: 1, pka: 10.33 }, + }, + { + ha: 'H2S', + a: 'HS-', + pka: 7.05, + specie: { label: 'S--', number: 2, pka: 19.14 }, + }, + { + ha: 'HS-', + a: 'S--', + pka: 12.09, + specie: { label: 'S--', number: 1, pka: 12.09 }, + }, + { + ha: 'HClO', + a: 'ClO-', + pka: 7.4, + specie: { label: 'ClO-', number: 1, pka: 7.4 }, + }, + { + ha: 'HBrO', + a: 'BrO-', + pka: 8.6, + specie: { label: 'BrO-', number: 1, pka: 8.6 }, + }, + { + ha: 'HCN', + a: 'CN-', + pka: 9.21, + specie: { label: 'CN-', number: 1, pka: 9.21 }, + }, + { + ha: 'NH4+', + a: 'NH3', + pka: 9.25, + specie: { label: 'NH3', number: 1, pka: 9.25 }, + }, + { + ha: 'CH2ClCOOH', + a: 'CH2ClCOO-', + pka: 2.89, + specie: { label: 'CH2ClCOO-', number: 1, pka: 2.89 }, + }, + { + ha: 'HCOOH', + a: 'HCOO-', + pka: 3.75, + specie: { label: 'HCOO-', number: 1, pka: 3.75 }, + }, + { + ha: 'C6H5COOH', + a: 'C6H5COO-', + pka: 4.2, + specie: { label: 'C6H5COO-', number: 1, pka: 4.2 }, + }, + { + ha: 'C66H5NH3+', + a: 'C66H5NH2', + pka: 4.6, + specie: { label: 'C66H5NH2', number: 1, pka: 4.6 }, + }, + { + ha: 'CH3COOH', + a: 'CH3COO-', + pka: 4.75, + specie: { label: 'CH3COO-', number: 1, pka: 4.75 }, + }, + { + ha: 'C2H5COOH', + a: 'C2H5COO-', + pka: 4.87, + specie: { label: 'C2H5COO-', number: 1, pka: 4.87 }, + }, + { + ha: 'C5H5NH+', + a: 'C5H5N', + pka: 5.25, + specie: { label: 'C5H5N', number: 1, pka: 5.25 }, + }, + { + ha: 'CH3NH3+', + a: 'CH3NH2', + pka: 10.66, + specie: { label: 'CH3NH2', number: 1, pka: 10.66 }, + }, + { + ha: '(C2H5)3NH+', + a: '(C2H5)3N', + pka: 10.75, + specie: { label: '(C2H5)3N', number: 1, pka: 10.75 }, + }, + { + ha: 'C2H5NH3+', + a: 'C2H5NH2', + pka: 10.8, + specie: { label: 'C2H5NH2', number: 1, pka: 10.8 }, + }, + { ha: 'HCl', a: 'Cl-', pka: 1, specie: { label: 'Cl-', number: 1, pka: 1 } }, +]; define(['lodash'], function (_) { class AcidBase { @@ -9,8 +155,8 @@ define(['lodash'], function (_) { } static getAllAcidBaseLabels() { - var species = new Set(); - for (var i = 0; i < pkas.length; i++) { + let species = new Set(); + for (let i = 0; i < pkas.length; i++) { species.add(pkas[i].ha); species.add(pkas[i].a); } @@ -18,8 +164,8 @@ define(['lodash'], function (_) { } addAcidBase(label, total) { - var titrProtonCount; - var titrSpecie = pkas.find(function (pka) { + let titrProtonCount; + let titrSpecie = pkas.find(function (pka) { return pka.ha === label; }); if (titrSpecie) { @@ -31,13 +177,11 @@ define(['lodash'], function (_) { }); if (titrSpecie) { titrProtonCount = 0; + } else if (label === 'OH-') { + this.addComponent('OH-', total); + return; } else { - if (label === 'OH-') { - this.addComponent('OH-', total); - return; - } else { - throw new Error('Could not find acid/base'); - } + throw new Error('Could not find acid/base'); } titrSpecie = titrSpecie.specie.label; } @@ -52,81 +196,82 @@ define(['lodash'], function (_) { total = -total; } if (!total) total = 0; - var comp = this.components.find((c) => c.label === label); + let comp = this.components.find((c) => c.label === label); if (comp) { comp.total += total; } else { this.components.push({ - label, total + label, + total, }); } } setTotal(componentLabel, total) { - var c = this.components.find((c) => c.label === componentLabel); + let c = this.components.find((c) => c.label === componentLabel); c.total = total; c.atEquilibrium = undefined; } setAtEquilibrium(componentLabel, atEquilibrium) { - var c = this.components.find((c) => c.label === componentLabel); + let c = this.components.find((c) => c.label === componentLabel); c.atEquilibrium = atEquilibrium; c.total = undefined; } getModel() { // Get all involved pkas - var pkas = this.pkas.filter((pka) => { + let pkas = this.pkas.filter((pka) => { return this.components.find(function (c) { return String(c.label) === String(pka.specie.label); }); }); // group pkas by component - var grouped = _.groupBy(pkas, function (pka) { + let grouped = _.groupBy(pkas, function (pka) { return String(pka.specie.label); }); + let nbComponents = this.components.length; - var nbComponents = this.components.length; - - var protonIndex = this.components.findIndex((c) => c.label === 'H+'); + let protonIndex = this.components.findIndex((c) => c.label === 'H+'); if (protonIndex === -1) throw new Error('Acid-base model has no proton'); - var model = {}; + let model = {}; // Model components model.components = new Array(nbComponents); for (i = 0; i < this.components.length; i++) { - model.components[i] = Object.assign({}, this.components[i]); + model.components[i] = { ...this.components[i] }; } // Model formed species model.formedSpecies = [ { label: 'OH-', - beta: Math.pow(10, -14), - components: new Array(nbComponents).fill(0) - } + beta: 10 ** -14, + components: new Array(nbComponents).fill(0), + }, ]; model.formedSpecies[0].components[protonIndex] = -1; - for (var i = 0; i < this.components.length; i++) { if (i === protonIndex) continue; - var group = grouped[this.components[i].label]; + let group = grouped[this.components[i].label]; if (!group) throw new Error('Should be unreachable'); - for (var j = 0; j < group.length; j++) { - var el = group[j]; + for (let j = 0; j < group.length; j++) { + let el = group[j]; model.formedSpecies.push({ label: String(el.ha), - beta: Math.pow(10, Number(el.specie.pka)), - components: new Array(nbComponents).fill(0) + beta: 10 ** Number(el.specie.pka), + components: new Array(nbComponents).fill(0), }); model.formedSpecies[model.formedSpecies.length - 1].components[i] = 1; - model.formedSpecies[model.formedSpecies.length - 1].components[protonIndex] = Number(el.specie.number); + model.formedSpecies[model.formedSpecies.length - 1].components[ + protonIndex + ] = Number(el.specie.number); } } diff --git a/ChemEquilibrium/chart.js b/ChemEquilibrium/chart.js index 8dfbe69b..816251c3 100644 --- a/ChemEquilibrium/chart.js +++ b/ChemEquilibrium/chart.js @@ -5,23 +5,23 @@ define(['src/util/color'], function (Color) { if (x.length !== y.length || y.length === 0) { throw new Error('Invalid data length'); } - var chart = { + let chart = { data: [], axis: [ { - label: options.xLabel || '' + label: options.xLabel || '', }, { - label: options.yLabel || '' - } - ] + label: options.yLabel || '', + }, + ], }; - var species = Object.keys(y[0]); - var colors = Color.getDistinctColors(species.length); + let species = Object.keys(y[0]); + let colors = Color.getDistinctColors(species.length); for (var i = 0; i < species.length; i++) { - var data = {}; + let data = {}; chart.data.push(data); // eslint-disable-next-line no-loop-func data.y = y.map((y) => { @@ -37,10 +37,10 @@ define(['src/util/color'], function (Color) { data.yAxis = 1; data.defaultStyle = { lineColor: colors[i], - lineWidth: 1 + lineWidth: 1, }; } return chart; - } + }, }; }); diff --git a/ChemEquilibrium/table.js b/ChemEquilibrium/table.js index c1593374..039785b0 100644 --- a/ChemEquilibrium/table.js +++ b/ChemEquilibrium/table.js @@ -1,11 +1,10 @@ - module.exports = function getTable(sol) { - var result = []; + let result = []; result.push(`x\t${sol.species.join('\t')}`); - for (var i = 0; i < sol.x.length; i++) { - var line = []; + for (let i = 0; i < sol.x.length; i++) { + let line = []; line.push(sol.x[i]); - for (var specie of sol.species) { + for (let specie of sol.species) { line.push(sol.solutions[i][specie]); } result.push(line.join('\t')); diff --git a/README.md b/README.md index 1ae572c9..cffe91c9 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,6 @@ # visualizer-helper -Small pieces of code useful in the visualizer +Small pieces of code useful in the visualizer ## Build diff --git a/biology/needleman/data.js b/biology/needleman/data.js index 8b33ddeb..11880c9e 100644 --- a/biology/needleman/data.js +++ b/biology/needleman/data.js @@ -1096,9 +1096,9 @@ function createTable(v, w) { let n = v.length; let m = w.length; let rows = []; - for (var i = 0; i < n + 1; i++) { + for (let i = 0; i < n + 1; i++) { rows[i] = []; - for (var j = 0; j < m + 1; j++) { + for (let j = 0; j < m + 1; j++) { rows[i].push(0); } } @@ -1117,9 +1117,9 @@ function identityMatrix(n, match, penalization) { penalization = penalization || 0; let matrix = []; - for (var i = 0; i < n; i++) { + for (let i = 0; i < n; i++) { matrix[i] = []; - for (var j = 0; j < n; j++) { + for (let j = 0; j < n; j++) { matrix[i][j] = i === j ? match : penalization; } } @@ -1140,9 +1140,9 @@ function similarityMatrix(v, w, scores) { let vocab = vocabulary(v + w); let matrix = {}; - for (var i in vocab) { + for (let i in vocab) { matrix[vocab[i]] = {}; - for (var j in vocab) { + for (let j in vocab) { matrix[vocab[i]][vocab[j]] = i === j ? match : mismatch; } } diff --git a/chemistry/PubChem.js b/chemistry/PubChem.js index d251d064..203bfc00 100644 --- a/chemistry/PubChem.js +++ b/chemistry/PubChem.js @@ -8,14 +8,14 @@ async function getMolecules(mf) { searchParams.set('fields', 'data.iupac,data.ocl'); searchParams.set('limit', '50000'); - let response = await fetch(`${pubchemURL}` + searchParams.toString()); + let response = await fetch(`${pubchemURL}${searchParams.toString()}`); let results = await response.json(); console.log(results.data); return results.data; } module.exports = { - choose: function (mf) { + choose(mf) { let promise = getMolecules(mf); return ui .choose([{ promise }], { diff --git a/chemistry/__tests__/sequenceSplitter.js b/chemistry/__tests__/sequenceSplitter.js deleted file mode 100644 index 5db3dfee..00000000 --- a/chemistry/__tests__/sequenceSplitter.js +++ /dev/null @@ -1,22 +0,0 @@ - -const sequenceSplitter = require('../sequenceSplitter'); - -test('AAA', () => { - expect(sequenceSplitter('AAA')).toHaveLength(3); -}); - -test('HAlaAlaAlaOH', () => { - expect(sequenceSplitter('HAlaAlaAlaOH')).toHaveLength(3); -}); - -test('HAlaAla(H-1OH)AlaOH', () => { - expect(sequenceSplitter('HAlaAla(H-1OH)AlaOH')).toHaveLength(3); -}); - -test('H(+)AlaAla(H-1OH)AlaOH', () => { - expect(sequenceSplitter('H(+)AlaAla(H-1OH)AlaOH')).toHaveLength(3); -}); - -test('ForAlaAla(H-1OH)AlaOH', () => { - expect(sequenceSplitter('ForAlaAla(H-1OH)AlaOH')).toHaveLength(3); -}); diff --git a/chemistry/__tests__/sequenceSplitter.test.js b/chemistry/__tests__/sequenceSplitter.test.js new file mode 100644 index 00000000..9c251962 --- /dev/null +++ b/chemistry/__tests__/sequenceSplitter.test.js @@ -0,0 +1,21 @@ +const sequenceSplitterTest = require('../sequenceSplitter'); + +test('AAA', () => { + expect(sequenceSplitterTest('AAA')).toHaveLength(3); +}); + +test('HAlaAlaAlaOH', () => { + expect(sequenceSplitterTest('HAlaAlaAlaOH')).toHaveLength(3); +}); + +test('HAlaAla(H-1OH)AlaOH', () => { + expect(sequenceSplitterTest('HAlaAla(H-1OH)AlaOH')).toHaveLength(3); +}); + +test('H(+)AlaAla(H-1OH)AlaOH', () => { + expect(sequenceSplitterTest('H(+)AlaAla(H-1OH)AlaOH')).toHaveLength(3); +}); + +test('ForAlaAla(H-1OH)AlaOH', () => { + expect(sequenceSplitterTest('ForAlaAla(H-1OH)AlaOH')).toHaveLength(3); +}); diff --git a/chemistry/chemcalcSequenceSVG.js b/chemistry/chemcalcSequenceSVG.js index 39b23691..16d33692 100644 --- a/chemistry/chemcalcSequenceSVG.js +++ b/chemistry/chemcalcSequenceSVG.js @@ -1,6 +1,6 @@ define([ 'https://www.lactame.com/github/adobe-webplatform/Snap.svg/84fbff7d512c8145c522b71fc9c872cb0bcae49a/dist/snap.svg-min.js', - './sequenceSplitter' + './sequenceSplitter', ], function (Snap, sequenceSplitter) { function getSVG(sequence, analysisResult, options) { const { @@ -12,28 +12,28 @@ define([ labelFontFamily = 'Verdana', labelSize = 8, verticalShiftForTerminalAnnotations = 20, - showLabels = true + showLabels = true, } = options; - var residues = []; - var mfParts = sequenceSplitter(sequence); - var results = JSON.parse(JSON.stringify(analysisResult)); + let residues = []; + let mfParts = sequenceSplitter(sequence); + let results = JSON.parse(JSON.stringify(analysisResult)); - var xPos = leftRightBorders; - var xOld = xPos; + let xPos = leftRightBorders; + let xOld = xPos; - var line = 0; + let line = 0; // we create a temporary paper in order to get the width of the text blocs - var tempPaper = Snap(1000, 40); - for (var i = 0; i < mfParts.length; i++) { - var part = mfParts[i]; - var text = tempPaper.text(xPos, 20, part); + let tempPaper = Snap(1000, 40); + for (let i = 0; i < mfParts.length; i++) { + let part = mfParts[i]; + let text = tempPaper.text(xPos, 20, part); text.attr({ 'font-family': labelFontFamily, 'font-weight': 'bold', - 'font-size': 12 + 'font-size': 12, }); - var textWidth = text.node.getBoundingClientRect().width; + let textWidth = text.node.getBoundingClientRect().width; xPos += textWidth; if (xPos > width - leftRightBorders) { xOld = leftRightBorders; @@ -49,7 +49,7 @@ define([ line, usedSlots: [], topPosition: 0, - bottomPosition: 0 + bottomPosition: 0, }); xPos += spaceBetweenResidues; xOld = xPos; @@ -59,9 +59,9 @@ define([ // we calculate all the lines based on the results for (let result of results) { // internal fragment ? - var parts = result.type.split(/(?=[a-z])/); - var firstPart = parts[0]; - var secondPart = parts[1]; + let parts = result.type.split(/(?=[a-z])/); + let firstPart = parts[0]; + let secondPart = parts[1]; if ('abc'.indexOf(firstPart.charAt(0)) > -1) { // n-terminal fragment @@ -115,40 +115,40 @@ define([ // for each line (internal fragment) we calculate the vertical position // where it should be drawn as well and the maximal number of lines - var maxNumberLines = 0; - for (var result of results) { + let maxNumberLines = 0; + for (let result of results) { if (result.internal) { result.slot = assignSlot(result.from, result.to); if (result.slot > maxNumberLines) maxNumberLines = result.slot; } } - var rowHeight = + let rowHeight = verticalShiftForTerminalAnnotations + spaceBetweenInteralLines * (maxNumberLines + 6); - var height = + let height = rowHeight * (line + 1) + 50 + verticalShiftForTerminalAnnotations; // We start to create the SVG and create the paper - var paper = Snap(width, height); + let paper = Snap(width, height); addScript(paper); residues.forEach(function (residue) { residue.y = (residue.line + 1) * rowHeight; - var text = paper.text(residue.xFrom, residue.y, residue.label); + let text = paper.text(residue.xFrom, residue.y, residue.label); text.attr({ id: `residue-${residue.nTer}` }); text.attr({ 'font-family': labelFontFamily, 'font-weight': 'bold', - 'font-size': 12 + 'font-size': 12, }); }); drawInternals(); drawTerminals(); - var svg = paper + let svg = paper .toString() .replace(/>/g, '>\r') .replace(/&/g, '&') @@ -160,14 +160,14 @@ define([ // we need to define the height of the line. // we need to find a height that is not yet used. function assignSlot(from, to) { - var used = {}; - for (var i = from; i < to; i++) { - var residue = residues[i]; + let used = {}; + for (let i = from; i < to; i++) { + let residue = residues[i]; residue.usedSlots.forEach(function (usedSlot, index) { used[index] = true; }); } - var counter = 0; + let counter = 0; while (true) { if (!used[counter]) { break; @@ -181,9 +181,9 @@ define([ } function drawTerminals() { - for (var result of results) { + for (let result of results) { var residue; - var nTerminal = false; + let nTerminal = false; if (result.fromNTerm) { residue = residues[result.to]; nTerminal = true; @@ -196,7 +196,7 @@ define([ residue.xTo + spaceBetweenResidues / 2, residue.y, residue.xTo + spaceBetweenResidues / 2, - residue.y - 8 + residue.y - 8, ); line.attr({ stroke: result.color, 'stroke-width': strokeWidth }); if (nTerminal) { @@ -204,13 +204,13 @@ define([ residue.xTo + spaceBetweenResidues / 2, residue.y, residue.xTo + spaceBetweenResidues / 2 - 5, - residue.y + 5 + residue.y + 5, ); line.attr({ stroke: result.color, 'stroke-width': strokeWidth }); drawLabel( result, residue.xTo + spaceBetweenResidues / 2 - 15, - residue.y + 12 + residue.bottomPosition * labelSize + residue.y + 12 + residue.bottomPosition * labelSize, ); residue.bottomPosition++; } else { @@ -218,13 +218,13 @@ define([ residue.xTo + spaceBetweenResidues / 2, residue.y - 8, residue.xTo + spaceBetweenResidues / 2 + 5, - residue.y - 13 + residue.y - 13, ); line.attr({ stroke: result.color, 'stroke-width': strokeWidth }); drawLabel( result, residue.xTo + spaceBetweenResidues / 2, - residue.y - 15 - residue.topPosition * labelSize + residue.y - 15 - residue.topPosition * labelSize, ); residue.topPosition++; } @@ -234,41 +234,41 @@ define([ function drawLabel(result, x, y) { if (!showLabels) return; - var label = result.type; - var similarity = Math.round(result.similarity); - var charge = result.charge > 0 ? `+${result.charge}` : result.charge; - var text = paper.text(x, y, label); + let label = result.type; + let similarity = Math.round(result.similarity); + let charge = result.charge > 0 ? `+${result.charge}` : result.charge; + let text = paper.text(x, y, label); text.attr({ fill: result.textColor, 'font-family': labelFontFamily, 'font-weight': 'bold', - 'font-size': labelSize + 'font-size': labelSize, }); - var textWidth = text.node.getBoundingClientRect().width + 3; + let textWidth = text.node.getBoundingClientRect().width + 3; text = paper.text(x + textWidth, y - labelSize / 2, charge); text.attr({ fill: result.textColor, 'font-family': labelFontFamily, - 'font-size': labelSize / 2 + 'font-size': labelSize / 2, }); text = paper.text(x + textWidth, y, similarity); text.attr({ fill: result.textColor, 'font-family': labelFontFamily, - 'font-size': labelSize / 2 + 'font-size': labelSize / 2, }); } function drawInternals() { - for (var result of results) { + for (let result of results) { if (result.internal) { - var fromResidue = residues[result.from + 1]; - var toResidue = residues[result.to]; + let fromResidue = residues[result.from + 1]; + let toResidue = residues[result.to]; // var charge = result.charge > 0 ? '+' + result.charge : result.charge; // var label = result.type + ' (' + charge + ', ' + Math.round(result.similarity) + '%)'; // we need to check on how many lines we are var fromX, toX, y; - for (var line = fromResidue.line; line <= toResidue.line; line++) { + for (let line = fromResidue.line; line <= toResidue.line; line++) { y = -10 - result.slot * spaceBetweenInteralLines + @@ -284,15 +284,15 @@ define([ } else { toX = width - 1; } - var drawLine = paper.line(fromX, y, toX, y); + let drawLine = paper.line(fromX, y, toX, y); drawLine.attr({ onmouseover: 'mouseOver(evt)', onmouseout: 'mouseOut(evt)', - id: `line${fromResidue.nTer}-${toResidue.nTer}` + id: `line${fromResidue.nTer}-${toResidue.nTer}`, }); drawLine.attr({ stroke: result.color, - 'stroke-width': strokeWidth + 'stroke-width': strokeWidth, }); drawLabel(result, (fromX + toX) / 2 - 10, y - 2); @@ -304,7 +304,7 @@ define([ } function addScript(paper) { - var script = ` // `; - var scriptElement = paper.el('script', { - type: 'application/ecmascript' + let scriptElement = paper.el('script', { + type: 'application/ecmascript', }); scriptElement.node.textContent = script; } diff --git a/chemistry/orbitals.js b/chemistry/orbitals.js index 73385575..375def68 100644 --- a/chemistry/orbitals.js +++ b/chemistry/orbitals.js @@ -1,8 +1,9 @@ +define([ + 'https://www.lactame.com/github/adobe-webplatform/Snap.svg/84fbff7d512c8145c522b71fc9c872cb0bcae49a/dist/snap.svg-min.js', +], function (Snap) { + let exports = {}; -define(['https://www.lactame.com/github/adobe-webplatform/Snap.svg/84fbff7d512c8145c522b71fc9c872cb0bcae49a/dist/snap.svg-min.js'], function (Snap) { - var exports = {}; - - var defaultOptions = { + let defaultOptions = { width: 1000, height: 600, leftRightMargin: 4, @@ -13,93 +14,113 @@ define(['https://www.lactame.com/github/adobe-webplatform/Snap.svg/84fbff7d512c8 rectMargin: 10, spinOuterMarginRatio: 1 / 4, arrowStrokeWidth: 3, - arrowHeadSize: 3 + arrowHeadSize: 3, }; - - var paper, svg, svgModifier; - + let paper, svg, svgModifier; // Create svg function createSvg(electronicConfiguration, opts) { - opts = Object.assign({}, defaultOptions, opts); + opts = { ...defaultOptions, ...opts }; // User defined - var width = opts.width; - var height = opts.height; - var leftRightMargin = opts.leftRightMargin; - var topBottomMargin = opts.topBottomMargin; - var fontSize = opts.fontSize; - var rectWidth = opts.rectWidth; - var rectHeight = opts.rectHeight; - var rectMargin = opts.rectMargin; - var spinOuterMarginRatio = opts.spinOuterMarginRatio; - var arrowStrokeWidth = opts.arrowStrokeWidth; - var arrowHeadSize = opts.arrowHeadSize; + let width = opts.width; + let height = opts.height; + let leftRightMargin = opts.leftRightMargin; + let topBottomMargin = opts.topBottomMargin; + let fontSize = opts.fontSize; + let rectWidth = opts.rectWidth; + let rectHeight = opts.rectHeight; + let rectMargin = opts.rectMargin; + let spinOuterMarginRatio = opts.spinOuterMarginRatio; + let arrowStrokeWidth = opts.arrowStrokeWidth; + let arrowHeadSize = opts.arrowHeadSize; // Calculated - var drawWidth = width - 2 * leftRightMargin; - var drawHeight = height - 2 * topBottomMargin; - var levelHeight = fontSize + rectHeight; - var sSpace = (drawHeight - levelHeight) / 6; - var labelOffset = rectHeight + fontSize + 5; - var columnOffset = (drawWidth - 16 * rectWidth - 12 * rectMargin) / 3; - var pOffset = [sSpace / 4, null, sSpace * 5 - sSpace / 3, rectWidth + columnOffset]; - var dOffset = [2 * sSpace / 4, null, sSpace * 3 - sSpace / 3, 4 * rectWidth + 2 * rectMargin + 2 * columnOffset]; - var fOffset = [-1 / 4 * sSpace, null, 3 / 4 * sSpace, 9 * rectWidth + 6 * rectMargin + 3 * columnOffset]; - var spinOuterMargin = rectWidth * spinOuterMarginRatio; - var spinInnerMargin = rectWidth * (1 - 2 * spinOuterMarginRatio); + let drawWidth = width - 2 * leftRightMargin; + let drawHeight = height - 2 * topBottomMargin; + let levelHeight = fontSize + rectHeight; + let sSpace = (drawHeight - levelHeight) / 6; + let labelOffset = rectHeight + fontSize + 5; + let columnOffset = (drawWidth - 16 * rectWidth - 12 * rectMargin) / 3; + let pOffset = [ + sSpace / 4, + null, + sSpace * 5 - sSpace / 3, + rectWidth + columnOffset, + ]; + let dOffset = [ + (2 * sSpace) / 4, + null, + sSpace * 3 - sSpace / 3, + 4 * rectWidth + 2 * rectMargin + 2 * columnOffset, + ]; + let fOffset = [ + (-1 / 4) * sSpace, + null, + (3 / 4) * sSpace, + 9 * rectWidth + 6 * rectMargin + 3 * columnOffset, + ]; + let spinOuterMargin = rectWidth * spinOuterMarginRatio; + let spinInnerMargin = rectWidth * (1 - 2 * spinOuterMarginRatio); function drawElectrons(elConfig) { elConfig = parseelConfig(elConfig); - for (var i = 0; i < elConfig.length; i++) { - var layer = elConfig[i].layer; - var electrons = elConfig[i].electrons; - for (var j = 0; j < electrons; j++) { + for (let i = 0; i < elConfig.length; i++) { + let layer = elConfig[i].layer; + let electrons = elConfig[i].electrons; + for (let j = 0; j < electrons; j++) { drawElectron(layer, j); } } } function drawElectron(layer, electron) { - var group = getElectronGroup(layer, electron); - var spin = getElectronSpin(layer, electron); - var p; + let group = getElectronGroup(layer, electron); + let spin = getElectronSpin(layer, electron); + let p; if (spin > 0) { p = `M${spinOuterMargin},${rectHeight - 1} ${spinOuterMargin},${2 * arrowHeadSize + 1}`; } else { - var margin = spinOuterMargin + spinInnerMargin; + let margin = spinOuterMargin + spinInnerMargin; p = `M${margin},2 ${margin},${rectHeight - (2 * arrowHeadSize + 1)}`; } if (group) { - paper.path(p).attr({ - style: 'marker-end: url(#svgarrow);', - strokeWidth: arrowStrokeWidth, - stroke: '#000000', - dataClass: 'spin' - }).appendTo(group); + paper + .path(p) + .attr({ + style: 'marker-end: url(#svgarrow);', + strokeWidth: arrowStrokeWidth, + stroke: '#000000', + dataClass: 'spin', + }) + .appendTo(group); } } function drawRect(posx, posy, id) { - var rectId = getRectId(id); - paper.g().attr({ - transform: `translate(${posx},${posy})`, - id: `g${rectId}` - }).rect(0, 0, rectWidth, rectHeight).attr({ - fill: 'white', - stroke: 'grey', - strokeWidth: 1, - id: rectId, - class: 'elecRect' - }); + let rectId = getRectId(id); + paper + .g() + .attr({ + transform: `translate(${posx},${posy})`, + id: `g${rectId}`, + }) + .rect(0, 0, rectWidth, rectHeight) + .attr({ + fill: 'white', + stroke: 'grey', + strokeWidth: 1, + id: rectId, + class: 'elecRect', + }); svgModifier.push({ selector: `#${rectId}`, info: { - quanticNumbers: getQuanticNumbers(id) - } + quanticNumbers: getQuanticNumbers(id), + }, }); } @@ -107,34 +128,42 @@ define(['https://www.lactame.com/github/adobe-webplatform/Snap.svg/84fbff7d512c8 paper.text(posx, posy, text).attr({ fontSize, textAnchor: 'middle', - dataTest: 'abc' + dataTest: 'abc', }); } svgModifier = []; paper = Snap(width, height); - paper.path('M 0 0 L 10 4 L 0 8 z').marker(0, 0, arrowHeadSize, arrowHeadSize, 1, 4).attr({ - id: 'svgarrow', - viewBox: '0 0 10 8' - }); - - var i, j, x, y, label; + paper + .path('M 0 0 L 10 4 L 0 8 z') + .marker(0, 0, arrowHeadSize, arrowHeadSize, 1, 4) + .attr({ + id: 'svgarrow', + viewBox: '0 0 10 8', + }); + let i, j, x, y, label; // s for (i = 0; i < 7; i++) { label = `${7 - i}s`; - var w = drawHeight - levelHeight; - drawRect(leftRightMargin, i * w / 6 + topBottomMargin, `${label}1`); - drawText(leftRightMargin + rectWidth / 2, i * w / 6 + labelOffset, label); + let w = drawHeight - levelHeight; + drawRect(leftRightMargin, (i * w) / 6 + topBottomMargin, `${label}1`); + drawText( + leftRightMargin + rectWidth / 2, + (i * w) / 6 + labelOffset, + label, + ); } - // p for (i = 0; i < 6; i++) { label = `${7 - i}p`; - y = topBottomMargin + pOffset[0] + (i - 1) * (drawHeight - pOffset[0] - (drawHeight - pOffset[2])) / 4; + y = + topBottomMargin + + pOffset[0] + + ((i - 1) * (drawHeight - pOffset[0] - (drawHeight - pOffset[2]))) / 4; for (j = 0; j < 3; j++) { x = leftRightMargin + pOffset[3] + j * (rectWidth + rectMargin); drawRect(x, y, label + (j + 1)); @@ -146,7 +175,10 @@ define(['https://www.lactame.com/github/adobe-webplatform/Snap.svg/84fbff7d512c8 // d for (i = 0; i < 4; i++) { label = `${6 - i}d`; - y = topBottomMargin + dOffset[0] + (i - 1) * (drawHeight - dOffset[0] - (drawHeight - dOffset[2])) / 2; + y = + topBottomMargin + + dOffset[0] + + ((i - 1) * (drawHeight - dOffset[0] - (drawHeight - dOffset[2]))) / 2; for (j = 0; j < 5; j++) { x = leftRightMargin + dOffset[3] + j * (rectWidth + rectMargin); drawRect(x, y, label + (j + 1)); @@ -158,7 +190,10 @@ define(['https://www.lactame.com/github/adobe-webplatform/Snap.svg/84fbff7d512c8 // f for (i = 0; i < 2; i++) { label = `${5 - i}f`; - y = topBottomMargin + fOffset[0] + i * (drawHeight - fOffset[0] - (drawHeight - fOffset[2])); + y = + topBottomMargin + + fOffset[0] + + i * (drawHeight - fOffset[0] - (drawHeight - fOffset[2])); for (j = 0; j < 7; j++) { x = leftRightMargin + fOffset[3] + j * (rectWidth + rectMargin); drawRect(x, y, label + (j + 1)); @@ -173,33 +208,31 @@ define(['https://www.lactame.com/github/adobe-webplatform/Snap.svg/84fbff7d512c8 paper.remove(); } - // utils function getRectId(elConfig) { - var q = getQuanticNumbers(elConfig); + let q = getQuanticNumbers(elConfig); return `l${q.l}_m${q.m}_n${q.n}`; } function parseelConfig(elConfig) { elConfig = elConfig.split(' '); elConfig = elConfig.map(function (o) { - var m = o.match(/^(\d\w)(\d+)/); + let m = o.match(/^(\d\w)(\d+)/); return { layer: m[1], - electrons: +m[2] + electrons: +m[2], }; }); return elConfig; } - function getQuanticNumbers(elConfig) { elConfig = elConfig.split(' '); elConfig = elConfig[elConfig.length - 1]; - var ma = elConfig.match(/^(\d)(\w)(\d+)/); - var n = +ma[1]; - var l = ma[2]; - var m = +ma[3]; + let ma = elConfig.match(/^(\d)(\w)(\d+)/); + let n = +ma[1]; + let l = ma[2]; + let m = +ma[3]; switch (l) { case 's': @@ -218,13 +251,13 @@ define(['https://www.lactame.com/github/adobe-webplatform/Snap.svg/84fbff7d512c8 throw new Error(`Unexpected l: ${l}`); } - var num = l * 2 + 1; - m = (m - 1) % num - l; + let num = l * 2 + 1; + m = ((m - 1) % num) - l; return { l, m, n }; } function getLayerNum(layer) { - var l = layer[layer.length - 1].toLowerCase(); + let l = layer[layer.length - 1].toLowerCase(); switch (l) { case 's': return 1; @@ -240,16 +273,15 @@ define(['https://www.lactame.com/github/adobe-webplatform/Snap.svg/84fbff7d512c8 } function getElectronGroup(layer, electron) { - var id = getRectId(layer + (electron + 1)); + let id = getRectId(layer + (electron + 1)); return paper.select(`#g${id}`); } function getElectronSpin(layer, electron) { - var num = getLayerNum(layer); + let num = getLayerNum(layer); return Math.floor(electron / num) === 0 ? 1 : -1; } - exports.getSvg = function (...args) { createSvg(args); return svg; @@ -263,4 +295,3 @@ define(['https://www.lactame.com/github/adobe-webplatform/Snap.svg/84fbff7d512c8 return exports; }); - diff --git a/chemistry/sequenceSplitter.js b/chemistry/sequenceSplitter.js index f24047f0..1ccd81f8 100644 --- a/chemistry/sequenceSplitter.js +++ b/chemistry/sequenceSplitter.js @@ -2,27 +2,30 @@ Code that allows to split a sequence of aminoacids natural or non natural */ - module.exports = function sequenceSplitter(sequence) { - var parts = ['']; + let parts = ['']; if (sequence.match(/^[A-Z ]+$/)) { parts = sequence.replace(/ /g, '').split(/(?=[A-Z])/); } else { // we need to deal with upper and lowercases sequence = sequence.replace(/ /g, ''); - var parenthesisLevel = 0; - var begin = true; + let parenthesisLevel = 0; + let begin = true; for (let i = 0; i < sequence.length; i++) { let currentChar = sequence.charAt(i); parts[parts.length - 1] += currentChar; - let nextChar = (i < (sequence.length - 1)) ? sequence.charAt(i + 1) : ''; - let nextNextChar = (i < (sequence.length - 2)) ? sequence.charAt(i + 2) : ''; + let nextChar = i < sequence.length - 1 ? sequence.charAt(i + 1) : ''; + let nextNextChar = i < sequence.length - 2 ? sequence.charAt(i + 2) : ''; if (currentChar === '(') { parenthesisLevel++; } else if (currentChar === ')') { parenthesisLevel--; } - if (nextChar.match(/[A-Z]/) && nextNextChar.match(/[a-z]/) && parenthesisLevel === 0) { + if ( + nextChar.match(/[A-Z]/) && + nextNextChar.match(/[a-z]/) && + parenthesisLevel === 0 + ) { if (begin) { begin = false; } else { diff --git a/chemistry/showMfGroupsList.js b/chemistry/showMfGroupsList.js index 85681afc..4dcd3e06 100644 --- a/chemistry/showMfGroupsList.js +++ b/chemistry/showMfGroupsList.js @@ -2,8 +2,8 @@ We retrieve some exercises for structural analysis */ -import UI from 'src/util/ui'; import OCL from 'openchemlib'; +import UI from 'src/util/ui'; import MolecularFormula from '../eln/libs/MolecularFormula'; @@ -100,16 +100,15 @@ function getHtml(CustomMolecularFormula = MolecularFormula) {