Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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
17 changes: 0 additions & 17 deletions .eslintrc.yml

This file was deleted.

16 changes: 16 additions & 0 deletions .github/workflows/nodejs.yml
Original file line number Diff line number Diff line change
@@ -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
6 changes: 6 additions & 0 deletions .prettierignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
tiles/font-awesome
util/aesjs.js
util/cloneDeepLimitArray.js
util/md5.js
util/yamlParser.js,
spectra-data/conrec.js
3 changes: 0 additions & 3 deletions .travis.yml

This file was deleted.

211 changes: 178 additions & 33 deletions ChemEquilibrium/AcidModel.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,153 @@

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 (_) {

Check failure on line 150 in ChemEquilibrium/AcidModel.js

View workflow job for this annotation

GitHub Actions / nodejs / lint-eslint

Unexpected unnamed function
class AcidBase {
constructor(customPkas) {
this.pkas = customPkas || pkas;
Expand All @@ -9,35 +155,33 @@
}

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);
}
return Array.from(species);
}

addAcidBase(label, total) {
var titrProtonCount;
var titrSpecie = pkas.find(function (pka) {
let titrProtonCount;
let titrSpecie = pkas.find(function (pka) {

Check failure on line 168 in ChemEquilibrium/AcidModel.js

View workflow job for this annotation

GitHub Actions / nodejs / lint-eslint

Unexpected unnamed function
return pka.ha === label;
});
if (titrSpecie) {
titrProtonCount = titrSpecie.specie.number;
titrSpecie = titrSpecie.specie.label;
} else {
titrSpecie = pkas.find(function (pka) {

Check failure on line 175 in ChemEquilibrium/AcidModel.js

View workflow job for this annotation

GitHub Actions / nodejs / lint-eslint

Unexpected unnamed function
return pka.a === label;
});
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;
}
Expand All @@ -52,81 +196,82 @@
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) {

Check failure on line 225 in ChemEquilibrium/AcidModel.js

View workflow job for this annotation

GitHub Actions / nodejs / lint-eslint

Unexpected unnamed function
return String(c.label) === String(pka.specie.label);
});
});

// group pkas by component
var grouped = _.groupBy(pkas, function (pka) {
let grouped = _.groupBy(pkas, function (pka) {

Check failure on line 231 in ChemEquilibrium/AcidModel.js

View workflow job for this annotation

GitHub Actions / nodejs / lint-eslint

Unexpected unnamed function
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++) {

Check failure on line 244 in ChemEquilibrium/AcidModel.js

View workflow job for this annotation

GitHub Actions / nodejs / lint-eslint

'i' declared on line 259 column 16 is used outside of binding context

Check failure on line 244 in ChemEquilibrium/AcidModel.js

View workflow job for this annotation

GitHub Actions / nodejs / lint-eslint

'i' declared on line 259 column 16 is used outside of binding context

Check failure on line 244 in ChemEquilibrium/AcidModel.js

View workflow job for this annotation

GitHub Actions / nodejs / lint-eslint

'i' declared on line 259 column 16 is used outside of binding context
model.components[i] = Object.assign({}, this.components[i]);
model.components[i] = { ...this.components[i] };

Check failure on line 245 in ChemEquilibrium/AcidModel.js

View workflow job for this annotation

GitHub Actions / nodejs / lint-eslint

'i' declared on line 259 column 16 is used outside of binding context

Check failure on line 245 in ChemEquilibrium/AcidModel.js

View workflow job for this annotation

GitHub Actions / nodejs / lint-eslint

'i' declared on line 259 column 16 is used outside of binding context
}

// 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);
}
}

Expand Down
20 changes: 10 additions & 10 deletions ChemEquilibrium/chart.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) => {
Expand All @@ -37,10 +37,10 @@ define(['src/util/color'], function (Color) {
data.yAxis = 1;
data.defaultStyle = {
lineColor: colors[i],
lineWidth: 1
lineWidth: 1,
};
}
return chart;
}
},
};
});
Loading
Loading