From d90ba288a622ab41e99e706633b80ebe1894e541 Mon Sep 17 00:00:00 2001 From: Amphiluke Date: Sat, 27 Jan 2024 20:23:50 +0700 Subject: [PATCH 1/2] Better ESM support for Node.js --- .eslintrc.json | 10 +- .github/workflows/build-and-test.yml | 4 +- .npmrc | 1 + README.md | 46 +- dist/potprox.cjs | 914 +++++++++++++++++++++++++++ dist/potprox.js | 2 +- dist/potprox.min.js | 2 +- dist/potprox.min.mjs | 2 +- dist/potprox.mjs | 2 +- package-lock.json | 410 +++++++++--- package.json | 22 +- rollup.config.mjs | 61 +- src/potentials/abstract-proto.mjs | 2 +- src/potentials/buckingham.mjs | 2 +- src/potentials/lennard-jones.mjs | 2 +- src/potentials/morse.mjs | 2 +- src/potentials/rydberg.mjs | 2 +- src/potentials/varshni3.mjs | 2 +- test/.eslintrc | 5 - test/browser/datasets.js | 10 +- test/browser/ui.js | 2 +- test/browser/worker.js | 4 +- test/helpers/potential-data.mjs | 20 +- test/helpers/utils.mjs | 4 +- 24 files changed, 1341 insertions(+), 192 deletions(-) create mode 100644 .npmrc create mode 100644 dist/potprox.cjs delete mode 100644 test/.eslintrc diff --git a/.eslintrc.json b/.eslintrc.json index a429b94..d764a19 100644 --- a/.eslintrc.json +++ b/.eslintrc.json @@ -6,7 +6,8 @@ "node": true }, "parserOptions": { - "sourceType": "module" + "sourceType": "module", + "ecmaVersion": 2018 }, "extends": "eslint:recommended", "rules": { @@ -27,6 +28,10 @@ "error", "1tbs" ], + "comma-dangle": [ + "error", + {"arrays": "always-multiline", "objects": "always-multiline"} + ], "comma-spacing": [ "error" ], @@ -54,7 +59,8 @@ ], "indent": [ "error", - 4 + 4, + {"SwitchCase": 1} ], "key-spacing": [ "error" diff --git a/.github/workflows/build-and-test.yml b/.github/workflows/build-and-test.yml index 1d54f3f..b033e49 100644 --- a/.github/workflows/build-and-test.yml +++ b/.github/workflows/build-and-test.yml @@ -15,10 +15,10 @@ jobs: steps: - uses: actions/checkout@v3 - - name: Use Node.js v18 + - name: Use Node.js v20 uses: actions/setup-node@v3 with: - node-version: 18 + node-version: 20 - run: npm ci - run: npm run lint - run: npm run build diff --git a/.npmrc b/.npmrc new file mode 100644 index 0000000..32fd3a7 --- /dev/null +++ b/.npmrc @@ -0,0 +1 @@ +git-tag-version=false diff --git a/README.md b/README.md index 8fdcd01..5439fe3 100644 --- a/README.md +++ b/README.md @@ -16,46 +16,52 @@ Potprox uses the [method of least squares](https://en.wikipedia.org/wiki/Least_s * [The Rydberg potential](#the-potproxrydberg-class) * [The Varshni potential (III)](#the-potproxvarshni3-class) -## Requirements - -Use the module in [environments with ES6 support](https://kangax.github.io/compat-table/es6/). - ## Install and load potprox -**As a NodeJS module:** +### As a Node.js module -``` +Installing the package: + +```shell npm install potprox ``` +Importing the module: + ```javascript -let potprox = require("potprox"); +import * as potprox from "potprox"; ``` -The version for browsers (and web workers) is also available: check out the [dist directory](dist). - -**Browsers:** +or (for CommonJS modules) -```html - +```javascript +let potprox = require("potprox"); ``` -If you use ES modules, you may import the potprox module from the [potprox.min.mjs](dist/potprox.min.mjs) file: +If you need only a few potential classes, using named import will allow module bundlers to perform “tree shaking” and exclude the rest unused code. ```javascript -import * as potprox from "./dist/potprox.min.mjs"; +import {Morse, Rydberg} from "potprox"; ``` -Importing only those potential classes you really need will allow module bundlers to perform “tree shaking” and exclude the rest unused code. +### In browsers + +The module can be loaded from the popular CDNs like unpkg or jsDelivr. + +```html + +``` + +If you use ES modules, you may import the potprox module from the [potprox.min.mjs](dist/potprox.min.mjs) file: ```javascript -import {Morse, Rydberg} from "./dist/potprox.min.mjs"; +import * as potprox from "https://cdn.jsdelivr.net/npm/potprox/dist/potprox.min.mjs"; ``` -**Web workers:** +### In web workers ```javascript -importScripts("dist/potprox.min.js"); +importScripts("https://www.unpkg.com/potprox"); ``` ## Usage @@ -63,7 +69,7 @@ importScripts("dist/potprox.min.js"); Here is an example of approximation of some external computational data using the potprox module. ```javascript -let potprox = require("potprox"); +import * as potprox from "potprox"; // Computed numerical data on energy of interatomic binding // r - interatomic distance @@ -80,7 +86,7 @@ let data = [ {r: 6.0, e: -0.03028974}, {r: 5.5, e: -0.03598181}, {r: 5.0, e: -0.03234259}, - {r: 4.5, e: 0.00189849} + {r: 4.5, e: 0.00189849}, ]; // Approximate with the Lennard-Jones potential diff --git a/dist/potprox.cjs b/dist/potprox.cjs new file mode 100644 index 0000000..7460d1a --- /dev/null +++ b/dist/potprox.cjs @@ -0,0 +1,914 @@ +/*! +potprox v0.8.0 +https://amphiluke.github.io/potprox/ +*/ +'use strict'; + +class AbstractProto { + /** + * Calculate the coefficient of determination to measure the goodness of fit + * @param {Array.<{r: Number, e: Number}>} data - Experimental/ab initio data + * @returns {Number} + * @see https://en.wikipedia.org/wiki/Coefficient_of_determination + */ + rSqr(data) { + let avg = 0; // the mean of the experimental/ab initio data + let ssRes = 0; // the residual sum of squares (RSS) + for (let {r, e} of data) { + avg += e; + let residual = e - this.at(r); + ssRes += residual * residual; + } + avg /= data.length; + let ssTot = 0; // the total sum of squares + for (let {e} of data) { + let diff = e - avg; + ssTot += diff * diff; + } + return 1 - ssRes / ssTot; + } + + /** + * Generate points of the potential curve + * @param {Object} [options] - Configuration options + * @param {Number} [options.start=this.r0/2] - Starting interatomic distance + * @param {Number} [options.end=this.r0*2] - End interatomic distance + * @param {Number} [options.step=(end-start)/49] - Step for point generation (defaults make 50 points) + * @returns {Generator<{r: Number, e: Number}>} + */ + * points({start = this.r0 / 2, end = this.r0 * 2, step = (end - start) / 49} = {}) { + let i = 0; + let r = start; + let direction = Math.sign(end - start); // when end < start, iteration is backward + step = Math.abs(step) * direction; // the user may specify step as signed or not + while ((end - r) * direction >= 0) { + yield {r, e: this.at(r), index: i}; + r = start + step * ++i; + } + return {r: end, e: this.at(end)}; + } +} + +const lackOfData = "Too little points. Approximation is impossible"; + +const arrExpected = "Approximated data must be an array of points"; + +const numExpected = (param) => `The “${param}” parameter must be a finite number`; + +const greaterThan = (param, min = 0) => `The “${param}” parameter must be greater than ${min}`; + +const distType = "Distance must be a number"; + +const distRange = "Distance mustn’t be less than 0"; + +let instanceData$4 = new WeakMap(); + +class LennardJones extends AbstractProto { + constructor({epsilon = 1, sigma = 1} = {}) { + super(); + instanceData$4.set(this, {}); + this.epsilon = epsilon; + this.sigma = sigma; + } + + /** + * The name of the potential class. To be used instead of + * `instance.constructor.name` (since in the minified version names are mangled) + * @type {String} + * @readonly + * @static + */ + static get type() { + return "LennardJones"; + } + + /** + * Create an instance of the Lennard-Jones potential via approximation of input data + * @param {Array.<{r: Number, e: Number}>} data - Coordinates for approximation + * @returns {LennardJones} + * @static + */ + static from(data) { + if (!Array.isArray(data)) { + throw new TypeError(arrExpected); + } + if (data.length < 3) { + throw new Error(lackOfData); + } + let c1 = 0, c2 = 0, c3 = 0, c4 = 0, c5 = 0; + for (let {r, e} of data) { + c1 += Math.pow(r, -24); + c2 += Math.pow(r, -18); + c3 += e * Math.pow(r, -12); + c4 += Math.pow(r, -12); + c5 += e * Math.pow(r, -6); + } + let b = (c5 - c2 * c3 / c1) / (c4 - c2 * c2 / c1); + let a = (c3 - c2 * b) / c1; + let sigma = Math.pow(-a / b, 1 / 6); + let epsilon = a / (4 * Math.pow(sigma, 12)); + return new LennardJones({epsilon, sigma}); + } + + get epsilon() { + return instanceData$4.get(this).epsilon; + } + set epsilon(value) { + if (!Number.isFinite(value)) { + throw new TypeError(numExpected("epsilon")); + } + if (value <= 0) { + throw new RangeError(greaterThan("epsilon")); + } + instanceData$4.get(this).epsilon = value; + } + + get sigma() { + return instanceData$4.get(this).sigma; + } + set sigma(value) { + if (!Number.isFinite(value)) { + throw new TypeError(numExpected("sigma")); + } + if (value <= 0) { + throw new RangeError(greaterThan("sigma")); + } + instanceData$4.get(this).sigma = value; + } + + get r0() { + return 1.122462048309373 * this.sigma; + } + set r0(value) { + this.sigma = value / 1.122462048309373; + } + + /** + * Calculate the energy for the given interatomic distance + * @param {Number} r + * @returns {Number} + */ + at(r) { + if (typeof r !== "number") { + throw new TypeError(distType); + } + if (r < 0) { + throw new RangeError(distRange); + } + let {epsilon, sigma} = this; + return 4 * epsilon * (Math.pow(sigma / r, 12) - Math.pow(sigma / r, 6)); + } + + toJSON() { + return {type: LennardJones.type, epsilon: this.epsilon, sigma: this.sigma}; + } +} + +let instanceData$3 = new WeakMap(); + +class Buckingham extends AbstractProto { + constructor({d0 = 1, r0 = 1, a = 2} = {}) { + super(); + instanceData$3.set(this, {}); + this.d0 = d0; + this.r0 = r0; + this.a = a; + } + + /** + * The name of the potential class. To be used instead of + * `instance.constructor.name` (since in the minified version names are mangled) + * @type {String} + * @readonly + * @static + */ + static get type() { + return "Buckingham"; + } + + /** + * Create an instance of the Buckingham potential via approximation of input data. + * This method performs fast initial approximation and is not very accurate. + * @param {Array.<{r: Number, e: Number}>} data - Coordinates for approximation + * @returns {Buckingham} + * @static + */ + static fastFrom(data) { + if (!Array.isArray(data)) { + throw new TypeError(arrExpected); + } + if (data.length < 3) { + throw new Error(lackOfData); + } + data = data.slice().sort((pt1, pt2) => pt1.r - pt2.r); + let d0 = Number.POSITIVE_INFINITY; + let r0 = 1; + for (let {r, e} of data) { + if (e < d0) { + d0 = e; + r0 = r; + } + } + d0 = Math.abs(d0); + let pt1, pt2; + for (let i = 1; i < data.length; i++) { + pt1 = data[i - 1]; + pt2 = data[i]; + if (pt2.r >= r0 || pt1.e < 0 || pt2.e < 0) { + break; + } + } + let a; + if (pt1 && pt2 && pt1.r < r0 && pt2.r <= r0) { + let sigma = pt1.e * (pt1.r - pt2.r) / (pt2.e - pt1.e) + pt1.r; + if (sigma > 0) { + let A = 1 - sigma / r0; + let B = Math.pow(r0 / sigma, 6) / 6; + a = (B - A - Math.sqrt(B * B - 2 * A * B - A * A)) / (A * A); + if (!Number.isFinite(a)) { + a = undefined; + } + } + } + return new Buckingham({d0, r0, a}); + } + + /** + * Create an instance of the Buckingham potential via approximation of input data. + * This method gives more accurate approximation results than the `fastFrom` method. + * @param {Array.<{r: Number, e: Number}>} data - Coordinates for approximation + * @param {Object} [settings] - Approximation settings + * @param {Number} [settings.d0Conv=0.001] - `d0` convergence factor + * @param {Number} [settings.r0Conv=0.001] - `r0` convergence factor + * @param {Number} [settings.aConv=0.001] - `a` convergence factor + * @returns {Buckingham} + * @static + */ + static from(data, {d0Conv = 0.001, r0Conv = 0.001, aConv = 0.001} = {}) { + let buckingham = this.fastFrom(data); + let {d0, r0, a} = buckingham; // initial approximation + + // Convergence limits + const d0Lim = d0 * d0Conv; + const r0Lim = r0 * r0Conv; + const aLim = a * aConv; + + // Deltas + let dd0, dr0, da; + + do { + let c1 = 0, c2 = 0, c3 = 0, c4 = 0, c5 = 0, c6 = 0, c7 = 0, c8 = 0, c9 = 0; + for (let {r, e} of data) { + let factor = a * Math.pow(r0 / r, 6); + let exp = Math.exp(a * (1 - r / r0)); + let k = d0 / (a - 6) * (6 * exp - factor); + let l = k / d0; + let m = d0 / (a - 6) * (6 * exp * a * r / (r0 * r0) - 6 * factor / r0); + let n = -d0 / ((a - 6) * (a - 6)) * (6 * exp - factor) + + d0 / (a - 6) * (6 * (1 - r / r0) * exp - factor / a); + + c1 += l * l; + c2 += m * l; + c3 += n * l; + c4 += (k - e) * l; + c5 += m * m; + c6 += n * m; + c7 += (k - e) * m; + c8 += n * n; + c9 += (k - e) * n; + } + + da = -((c4 - c1 * c7 / c2) - (c4 - c1 * c9 / c3) * ((c2 - c1 * c5 / c2) / (c2 - c1 * c6 / c3))) / + ((c3 - c1 * c6 / c2) - (c3 - c1 * c8 / c3) * (c2 - c1 * c5 / c2) / (c2 - c1 * c6 / c3)); + dr0 = ((c3 - c1 * c6 / c2) * da + (c4 - c1 * c7 / c2)) / (c1 * c5 / c2 - c2); + dd0 = (-c2 * dr0 - c3 * da - c4) / c1; + + d0 += dd0; + r0 += dr0; + a += da; + } while ((Math.abs(dd0) > d0Lim) && (Math.abs(dr0) > r0Lim) && (Math.abs(da) > aLim)); + + buckingham.d0 = d0; + buckingham.r0 = r0; + buckingham.a = a; + return buckingham; + } + + get d0() { + return instanceData$3.get(this).d0; + } + set d0(value) { + if (!Number.isFinite(value)) { + throw new TypeError(numExpected("d0")); + } + if (value <= 0) { + throw new RangeError(greaterThan("d0")); + } + instanceData$3.get(this).d0 = value; + } + + get r0() { + return instanceData$3.get(this).r0; + } + set r0(value) { + if (!Number.isFinite(value)) { + throw new TypeError(numExpected("r0")); + } + if (value <= 0) { + throw new RangeError(greaterThan("r0")); + } + instanceData$3.get(this).r0 = value; + } + + get a() { + return instanceData$3.get(this).a; + } + set a(value) { + if (!Number.isFinite(value)) { + throw new TypeError(numExpected("a")); + } + if (value <= 0) { + throw new RangeError(greaterThan("a")); + } + instanceData$3.get(this).a = value; + } + + /** + * Calculate energy for the given interatomic distance + * @param {Number} r + * @returns {Number} + */ + at(r) { + if (typeof r !== "number") { + throw new TypeError(distType); + } + if (r < 0) { + throw new RangeError(distRange); + } + let {d0, r0, a} = this; + return d0 / (a - 6) * (6 * Math.exp(a * (1 - r / r0)) - a * Math.pow(r0 / r, 6)); + } + + toJSON() { + return {type: Buckingham.type, d0: this.d0, r0: this.r0, a: this.a}; + } +} + +let instanceData$2 = new WeakMap(); + +class Morse extends AbstractProto { + constructor({d0 = 1, r0 = 1, a = 1} = {}) { + super(); + instanceData$2.set(this, {}); + this.d0 = d0; + this.r0 = r0; + this.a = a; + } + + /** + * The name of the potential class. To be used instead of + * `instance.constructor.name` (since in the minified version names are mangled) + * @type {String} + * @readonly + * @static + */ + static get type() { + return "Morse"; + } + + /** + * Create an instance of the Morse potential via approximation of input data. + * This method performs fast initial approximation and is not very accurate. + * @param {Array.<{r: Number, e: Number}>} data - Coordinates for approximation + * @returns {Morse} + * @static + */ + static fastFrom(data) { + if (!Array.isArray(data)) { + throw new TypeError(arrExpected); + } + if (data.length < 3) { + throw new Error(lackOfData); + } + let d0 = Number.POSITIVE_INFINITY; + let r0 = 1; + for (let {r, e} of data) { + if (e < d0) { + d0 = e; + r0 = r; + } + } + d0 = Math.abs(d0); + let a = 0; + let counter = 0; + for (let {r, e} of data) { + let eFactor = Math.sqrt(1 + e / d0); + let aTemp = Number.NaN; + if (r > r0) { + aTemp = Math.log(1 - eFactor) / (r0 - r); + } else if (r < r0) { + aTemp = Math.log(1 + eFactor) / (r0 - r); + } + if (Number.isFinite(aTemp)) { + a += aTemp; + counter++; + } + } + a /= counter; + return new Morse({d0, r0, a}); + } + + /** + * Create an instance of the Morse potential via approximation of input data. + * This method gives more accurate approximation results than the `fastFrom` method. + * @param {Array.<{r: Number, e: Number}>} data - Coordinates for approximation + * @param {Object} [settings] - Approximation settings + * @param {Number} [settings.d0Conv=0.001] - `d0` convergence factor + * @param {Number} [settings.r0Conv=0.001] - `r0` convergence factor + * @param {Number} [settings.aConv=0.001] - `a` convergence factor + * @returns {Morse} + * @static + */ + static from(data, {d0Conv = 0.001, r0Conv = 0.001, aConv = 0.001} = {}) { + let morse = this.fastFrom(data); + let {d0, r0, a} = morse; // initial approximation + + // Convergence limits + const d0Lim = d0 * d0Conv; + const r0Lim = r0 * r0Conv; + const aLim = a * aConv; + + // Deltas + let dd0, dr0, da; + + do { + let c1 = 0, c2 = 0, c3 = 0, c4 = 0, c5 = 0, c6 = 0, c7 = 0, c8 = 0, c9 = 0; + for (let {r, e} of data) { + let exp = Math.exp(a * (r0 - r)); + let k = -d0 + d0 * (1 - exp) * (1 - exp); + let l = k / d0; + let m = -2 * d0 * (1 - exp) * a * exp; + let n = 2 * d0 * (1 - exp) * (r - r0) * exp; + + c1 += l * l; + c2 += m * l; + c3 += n * l; + c4 += (k - e) * l; + c5 += m * m; + c6 += n * m; + c7 += (k - e) * m; + c8 += n * n; + c9 += (k - e) * n; + } + + da = -((c4 - c1 * c7 / c2) - (c4 - c1 * c9 / c3) * ((c2 - c1 * c5 / c2) / (c2 - c1 * c6 / c3))) / + ((c3 - c1 * c6 / c2) - (c3 - c1 * c8 / c3) * (c2 - c1 * c5 / c2) / (c2 - c1 * c6 / c3)); + dr0 = ((c3 - c1 * c6 / c2) * da + (c4 - c1 * c7 / c2)) / (c1 * c5 / c2 - c2); + dd0 = (-c2 * dr0 - c3 * da - c4) / c1; + + d0 += dd0; + r0 += dr0; + a += da; + } while ((Math.abs(dd0) > d0Lim) && (Math.abs(dr0) > r0Lim) && (Math.abs(da) > aLim)); + + morse.d0 = d0; + morse.r0 = r0; + morse.a = a; + return morse; + } + + get d0() { + return instanceData$2.get(this).d0; + } + set d0(value) { + if (!Number.isFinite(value)) { + throw new TypeError(numExpected("d0")); + } + if (value <= 0) { + throw new RangeError(greaterThan("d0")); + } + instanceData$2.get(this).d0 = value; + } + + get r0() { + return instanceData$2.get(this).r0; + } + set r0(value) { + if (!Number.isFinite(value)) { + throw new TypeError(numExpected("r0")); + } + if (value <= 0) { + throw new RangeError(greaterThan("r0")); + } + instanceData$2.get(this).r0 = value; + } + + get a() { + return instanceData$2.get(this).a; + } + set a(value) { + if (!Number.isFinite(value)) { + throw new TypeError(numExpected("a")); + } + if (value <= 0) { + throw new RangeError(greaterThan("a")); + } + instanceData$2.get(this).a = value; + } + + /** + * Calculate energy for the given interatomic distance + * @param {Number} r + * @returns {Number} + */ + at(r) { + if (typeof r !== "number") { + throw new TypeError(distType); + } + if (r < 0) { + throw new RangeError(distRange); + } + let {d0, r0, a} = this; + let factor = 1 - Math.exp(a * (r0 - r)); + return d0 * factor * factor - d0; + } + + toJSON() { + return {type: Morse.type, d0: this.d0, r0: this.r0, a: this.a}; + } +} + +let instanceData$1 = new WeakMap(); + +class Rydberg extends AbstractProto { + constructor({d0 = 1, r0 = 1, b = 2} = {}) { + super(); + instanceData$1.set(this, {}); + this.d0 = d0; + this.r0 = r0; + this.b = b; + } + + /** + * The name of the potential class. To be used instead of + * `instance.constructor.name` (since in the minified version names are mangled) + * @type {String} + * @readonly + * @static + */ + static get type() { + return "Rydberg"; + } + + /** + * Create an instance of the Rydberg potential via approximation of input data. + * This method performs fast initial approximation and is not very accurate. + * @param {Array.<{r: Number, e: Number}>} data - Coordinates for approximation + * @returns {Rydberg} + * @static + */ + static fastFrom(data) { + if (!Array.isArray(data)) { + throw new TypeError(arrExpected); + } + if (data.length < 3) { + throw new Error(lackOfData); + } + data = data.slice().sort((pt1, pt2) => pt1.r - pt2.r); + let d0 = Number.POSITIVE_INFINITY; + let r0 = 1; + for (let {r, e} of data) { + if (e < d0) { + d0 = e; + r0 = r; + } + } + d0 = Math.abs(d0); + let pt1, pt2; + for (let i = 1; i < data.length; i++) { + pt1 = data[i - 1]; + pt2 = data[i]; + if (pt2.r >= r0 || pt1.e < 0 || pt2.e < 0) { + break; + } + } + let b; + if (pt1 && pt2 && pt1.r < r0 && pt2.r <= r0) { + let sigma = pt1.e * (pt1.r - pt2.r) / (pt2.e - pt1.e) + pt1.r; + if (sigma > 0) { + b = r0 / (r0 - sigma); + } + } + return new Rydberg({d0, r0, b}); + } + + /** + * Create an instance of the Rydberg potential via approximation of input data. + * This method gives more accurate approximation results than the `fastFrom` method. + * @param {Array.<{r: Number, e: Number}>} data - Coordinates for approximation + * @param {Object} [settings] - Approximation settings + * @param {Number} [settings.d0Conv=0.001] - `d0` convergence factor + * @param {Number} [settings.r0Conv=0.001] - `r0` convergence factor + * @param {Number} [settings.bConv=0.001] - `b` convergence factor + * @returns {Rydberg} + * @static + */ + static from(data, {d0Conv = 0.001, r0Conv = 0.001, bConv = 0.001} = {}) { + let rydberg = this.fastFrom(data); + let {d0, r0, b} = rydberg; // initial approximation + + // Convergence limits + const d0Lim = d0 * d0Conv; + const r0Lim = r0 * r0Conv; + const bLim = b * bConv; + + // Deltas + let dd0, dr0, db; + + do { + let c1 = 0, c2 = 0, c3 = 0, c4 = 0, c5 = 0, c6 = 0, c7 = 0, c8 = 0, c9 = 0; + for (let {r, e} of data) { + let factor = b * (r / r0 - 1); + let exp = Math.exp(-factor); + let k = -d0 * (1 + factor) * exp; + let l = k / d0; + let m = -d0 * b * r / (r0 * r0) * exp * factor; + let n = d0 * factor / b * exp * factor; + + c1 += l * l; + c2 += m * l; + c3 += n * l; + c4 += (k - e) * l; + c5 += m * m; + c6 += n * m; + c7 += (k - e) * m; + c8 += n * n; + c9 += (k - e) * n; + } + + db = -((c4 - c1 * c7 / c2) - (c4 - c1 * c9 / c3) * ((c2 - c1 * c5 / c2) / (c2 - c1 * c6 / c3))) / + ((c3 - c1 * c6 / c2) - (c3 - c1 * c8 / c3) * (c2 - c1 * c5 / c2) / (c2 - c1 * c6 / c3)); + dr0 = ((c3 - c1 * c6 / c2) * db + (c4 - c1 * c7 / c2)) / (c1 * c5 / c2 - c2); + dd0 = (-c2 * dr0 - c3 * db - c4) / c1; + + d0 += dd0; + r0 += dr0; + b += db; + } while ((Math.abs(dd0) > d0Lim) && (Math.abs(dr0) > r0Lim) && (Math.abs(db) > bLim)); + + rydberg.d0 = d0; + rydberg.r0 = r0; + rydberg.b = b; + return rydberg; + } + + get d0() { + return instanceData$1.get(this).d0; + } + set d0(value) { + if (!Number.isFinite(value)) { + throw new TypeError(numExpected("d0")); + } + if (value <= 0) { + throw new RangeError(greaterThan("d0")); + } + instanceData$1.get(this).d0 = value; + } + + get r0() { + return instanceData$1.get(this).r0; + } + set r0(value) { + if (!Number.isFinite(value)) { + throw new TypeError(numExpected("r0")); + } + if (value <= 0) { + throw new RangeError(greaterThan("r0")); + } + instanceData$1.get(this).r0 = value; + } + + get b() { + return instanceData$1.get(this).b; + } + set b(value) { + if (!Number.isFinite(value)) { + throw new TypeError(numExpected("b")); + } + if (value <= 1) { + throw new RangeError(greaterThan("b", 1)); + } + instanceData$1.get(this).b = value; + } + + /** + * Calculate energy for the given interatomic distance + * @param {Number} r + * @returns {Number} + */ + at(r) { + if (typeof r !== "number") { + throw new TypeError(distType); + } + if (r < 0) { + throw new RangeError(distRange); + } + let {d0, r0, b} = this; + let factor = b * (r - r0) / r0; + return -d0 * (1 + factor) * Math.exp(-factor); + } + + toJSON() { + return {type: Rydberg.type, d0: this.d0, r0: this.r0, b: this.b}; + } +} + +let instanceData = new WeakMap(); + +class Varshni3 extends AbstractProto { + constructor({d0 = 1, r0 = 1, b = 1} = {}) { + super(); + instanceData.set(this, {}); + this.d0 = d0; + this.r0 = r0; + this.b = b; + } + + /** + * The name of the potential class. To be used instead of + * `instance.constructor.name` (since in the minified version names are mangled) + * @type {String} + * @readonly + * @static + */ + static get type() { + return "Varshni3"; + } + + /** + * Create an instance of the Varshni potential (III) via approximation of input data. + * This method performs fast initial approximation and is not very accurate. + * @param {Array.<{r: Number, e: Number}>} data - Coordinates for approximation + * @returns {Varshni3} + * @static + */ + static fastFrom(data) { + if (!Array.isArray(data)) { + throw new TypeError(arrExpected); + } + if (data.length < 3) { + throw new Error(lackOfData); + } + let d0 = Number.POSITIVE_INFINITY; + let r0 = 1; + for (let {r, e} of data) { + if (e < d0) { + d0 = e; + r0 = r; + } + } + d0 = Math.abs(d0); + let b = 0; + let counter = 0; + for (let {r, e} of data) { + let eFactor = Math.sqrt(1 + e / d0); + let bTemp = Number.NaN; + if (r > r0) { + bTemp = Math.log(r / r0 * (1 - eFactor)) / (r0 * r0 - r * r); + } else if (r < r0) { + bTemp = Math.log(r / r0 * (1 + eFactor)) / (r0 * r0 - r * r); + } + if (Number.isFinite(bTemp)) { + b += bTemp; + counter++; + } + } + b /= counter; + return new Varshni3({d0, r0, b}); + } + + /** + * Create an instance of the Varshni potential (III) via approximation of input data. + * This method gives more accurate approximation results than the `fastFrom` method. + * @param {Array.<{r: Number, e: Number}>} data - Coordinates for approximation + * @param {Object} [settings] - Approximation settings + * @param {Number} [settings.d0Conv=0.001] - `d0` convergence factor + * @param {Number} [settings.r0Conv=0.001] - `r0` convergence factor + * @param {Number} [settings.bConv=0.001] - `b` convergence factor + * @returns {Varshni3} + * @static + */ + static from(data, {d0Conv = 0.001, r0Conv = 0.001, bConv = 0.001} = {}) { + let varshni = this.fastFrom(data); + let {d0, r0, b} = varshni; // initial approximation + + // Convergence limits + const d0Lim = d0 * d0Conv; + const r0Lim = r0 * r0Conv; + const bLim = b * bConv; + + // Deltas + let dd0, dr0, db; + + do { + let c1 = 0, c2 = 0, c3 = 0, c4 = 0, c5 = 0, c6 = 0, c7 = 0, c8 = 0, c9 = 0; + for (let {r, e} of data) { + let exp = r0 / r * Math.exp(b * (r0 * r0 - r * r)); + let k = -d0 + d0 * (1 - exp) * (1 - exp); + let l = k / d0; + let m = 2 * d0 * (1 - exp) * (-exp / r0 - exp * 2 * b * r0); + let n = 2 * d0 * (1 - exp) * exp * (r * r - r0 * r0); + + c1 += l * l; + c2 += m * l; + c3 += n * l; + c4 += (k - e) * l; + c5 += m * m; + c6 += n * m; + c7 += (k - e) * m; + c8 += n * n; + c9 += (k - e) * n; + } + + db = -((c4 - c1 * c7 / c2) - (c4 - c1 * c9 / c3) * ((c2 - c1 * c5 / c2) / (c2 - c1 * c6 / c3))) / + ((c3 - c1 * c6 / c2) - (c3 - c1 * c8 / c3) * (c2 - c1 * c5 / c2) / (c2 - c1 * c6 / c3)); + dr0 = ((c3 - c1 * c6 / c2) * db + (c4 - c1 * c7 / c2)) / (c1 * c5 / c2 - c2); + dd0 = (-c2 * dr0 - c3 * db - c4) / c1; + + d0 += dd0; + r0 += dr0; + b += db; + } while ((Math.abs(dd0) > d0Lim) && (Math.abs(dr0) > r0Lim) && (Math.abs(db) > bLim)); + + varshni.d0 = d0; + varshni.r0 = r0; + varshni.b = b; + return varshni; + } + + get d0() { + return instanceData.get(this).d0; + } + set d0(value) { + if (!Number.isFinite(value)) { + throw new TypeError(numExpected("d0")); + } + if (value <= 0) { + throw new RangeError(greaterThan("d0")); + } + instanceData.get(this).d0 = value; + } + + get r0() { + return instanceData.get(this).r0; + } + set r0(value) { + if (!Number.isFinite(value)) { + throw new TypeError(numExpected("r0")); + } + if (value <= 0) { + throw new RangeError(greaterThan("r0")); + } + instanceData.get(this).r0 = value; + } + + get b() { + return instanceData.get(this).b; + } + set b(value) { + if (!Number.isFinite(value)) { + throw new TypeError(numExpected("b")); + } + if (value <= 0) { + throw new RangeError(greaterThan("b")); + } + instanceData.get(this).b = value; + } + + /** + * Calculate energy for the given interatomic distance + * @param {Number} r + * @returns {Number} + */ + at(r) { + if (typeof r !== "number") { + throw new TypeError(distType); + } + if (r < 0) { + throw new RangeError(distRange); + } + let {d0, r0, b} = this; + let factor = 1 - r0 / r * Math.exp(b * (r0 * r0 - r * r)); + return d0 * factor * factor - d0; + } + + toJSON() { + return {type: Varshni3.type, d0: this.d0, r0: this.r0, b: this.b}; + } +} + +exports.Buckingham = Buckingham; +exports.LennardJones = LennardJones; +exports.Morse = Morse; +exports.Rydberg = Rydberg; +exports.Varshni3 = Varshni3; diff --git a/dist/potprox.js b/dist/potprox.js index 299cf4f..78e7ef7 100644 --- a/dist/potprox.js +++ b/dist/potprox.js @@ -1,5 +1,5 @@ /*! -potprox v0.7.2 +potprox v0.8.0 https://amphiluke.github.io/potprox/ */ (function (global, factory) { diff --git a/dist/potprox.min.js b/dist/potprox.min.js index 1b3ba64..e1ff6a8 100644 --- a/dist/potprox.min.js +++ b/dist/potprox.min.js @@ -1,5 +1,5 @@ /*! -potprox v0.7.2 +potprox v0.8.0 https://amphiluke.github.io/potprox/ */ !function(t,r){"object"==typeof exports&&"undefined"!=typeof module?r(exports):"function"==typeof define&&define.amd?define(["exports"],r):r((t="undefined"!=typeof globalThis?globalThis:t||self).potprox={})}(this,(function(t){"use strict";class r{rSqr(t){let r=0,e=0;for(let{r:i,e:s}of t){r+=s;let t=s-this.at(i);e+=t*t}r/=t.length;let i=0;for(let{e:e}of t){let t=e-r;i+=t*t}return 1-e/i}*points({start:t=this.r0/2,end:r=2*this.r0,step:e=(r-t)/49}={}){let i=0,s=t,o=Math.sign(r-t);for(e=Math.abs(e)*o;(r-s)*o>=0;)yield{r:s,e:this.at(s),index:i},s=t+e*++i;return{r:r,e:this.at(r)}}}const e="Too little points. Approximation is impossible",i="Approximated data must be an array of points",s=t=>`The “${t}” parameter must be a finite number`,o=(t,r=0)=>`The “${t}” parameter must be greater than ${r}`,n="Distance must be a number",a="Distance mustn’t be less than 0";let h=new WeakMap;class w extends r{constructor({epsilon:t=1,sigma:r=1}={}){super(),h.set(this,{}),this.epsilon=t,this.sigma=r}static get type(){return"LennardJones"}static from(t){if(!Array.isArray(t))throw new TypeError(i);if(t.length<3)throw new Error(e);let r=0,s=0,o=0,n=0,a=0;for(let{r:e,e:i}of t)r+=Math.pow(e,-24),s+=Math.pow(e,-18),o+=i*Math.pow(e,-12),n+=Math.pow(e,-12),a+=i*Math.pow(e,-6);let h=(a-s*o/r)/(n-s*s/r),f=(o-s*h)/r,l=Math.pow(-f/h,1/6),p=f/(4*Math.pow(l,12));return new w({epsilon:p,sigma:l})}get epsilon(){return h.get(this).epsilon}set epsilon(t){if(!Number.isFinite(t))throw new TypeError(s("epsilon"));if(t<=0)throw new RangeError(o("epsilon"));h.get(this).epsilon=t}get sigma(){return h.get(this).sigma}set sigma(t){if(!Number.isFinite(t))throw new TypeError(s("sigma"));if(t<=0)throw new RangeError(o("sigma"));h.get(this).sigma=t}get r0(){return 1.122462048309373*this.sigma}set r0(t){this.sigma=t/1.122462048309373}at(t){if("number"!=typeof t)throw new TypeError(n);if(t<0)throw new RangeError(a);let{epsilon:r,sigma:e}=this;return 4*r*(Math.pow(e/t,12)-Math.pow(e/t,6))}toJSON(){return{type:w.type,epsilon:this.epsilon,sigma:this.sigma}}}let f=new WeakMap;class l extends r{constructor({d0:t=1,r0:r=1,a:e=2}={}){super(),f.set(this,{}),this.d0=t,this.r0=r,this.a=e}static get type(){return"Buckingham"}static fastFrom(t){if(!Array.isArray(t))throw new TypeError(i);if(t.length<3)throw new Error(e);t=t.slice().sort(((t,r)=>t.r-r.r));let r,s,o,n=Number.POSITIVE_INFINITY,a=1;for(let{r:r,e:e}of t)e=a||r.e<0||s.e<0));e++);if(r&&s&&r.r0){let r=1-t/a,e=Math.pow(a/t,6)/6;o=(e-r-Math.sqrt(e*e-2*r*e-r*r))/(r*r),Number.isFinite(o)||(o=void 0)}}return new l({d0:n,r0:a,a:o})}static from(t,{d0Conv:r=.001,r0Conv:e=.001,aConv:i=.001}={}){let s=this.fastFrom(t),{d0:o,r0:n,a:a}=s;const h=o*r,w=n*e,f=a*i;let l,p,g;do{let r=0,e=0,i=0,s=0,h=0,w=0,f=0,u=0,b=0;for(let{r:l,e:p}of t){let t=a*Math.pow(n/l,6),g=Math.exp(a*(1-l/n)),d=o/(a-6)*(6*g-t),m=d/o,y=o/(a-6)*(6*g*a*l/(n*n)-6*t/n),E=-o/((a-6)*(a-6))*(6*g-t)+o/(a-6)*(6*(1-l/n)*g-t/a);r+=m*m,e+=y*m,i+=E*m,s+=(d-p)*m,h+=y*y,w+=E*y,f+=(d-p)*y,u+=E*E,b+=(d-p)*E}g=-(s-r*f/e-(e-r*h/e)/(e-r*w/i)*(s-r*b/i))/(i-r*w/e-(i-r*u/i)*(e-r*h/e)/(e-r*w/i)),p=((i-r*w/e)*g+(s-r*f/e))/(r*h/e-e),l=(-e*p-i*g-s)/r,o+=l,n+=p,a+=g}while(Math.abs(l)>h&&Math.abs(p)>w&&Math.abs(g)>f);return s.d0=o,s.r0=n,s.a=a,s}get d0(){return f.get(this).d0}set d0(t){if(!Number.isFinite(t))throw new TypeError(s("d0"));if(t<=0)throw new RangeError(o("d0"));f.get(this).d0=t}get r0(){return f.get(this).r0}set r0(t){if(!Number.isFinite(t))throw new TypeError(s("r0"));if(t<=0)throw new RangeError(o("r0"));f.get(this).r0=t}get a(){return f.get(this).a}set a(t){if(!Number.isFinite(t))throw new TypeError(s("a"));if(t<=0)throw new RangeError(o("a"));f.get(this).a=t}at(t){if("number"!=typeof t)throw new TypeError(n);if(t<0)throw new RangeError(a);let{d0:r,r0:e,a:i}=this;return r/(i-6)*(6*Math.exp(i*(1-t/e))-i*Math.pow(e/t,6))}toJSON(){return{type:l.type,d0:this.d0,r0:this.r0,a:this.a}}}let p=new WeakMap;class g extends r{constructor({d0:t=1,r0:r=1,a:e=1}={}){super(),p.set(this,{}),this.d0=t,this.r0=r,this.a=e}static get type(){return"Morse"}static fastFrom(t){if(!Array.isArray(t))throw new TypeError(i);if(t.length<3)throw new Error(e);let r=Number.POSITIVE_INFINITY,s=1;for(let{r:e,e:i}of t)is?a=Math.log(1-t)/(s-e):eh&&Math.abs(p)>w&&Math.abs(g)>f);return s.d0=o,s.r0=n,s.a=a,s}get d0(){return p.get(this).d0}set d0(t){if(!Number.isFinite(t))throw new TypeError(s("d0"));if(t<=0)throw new RangeError(o("d0"));p.get(this).d0=t}get r0(){return p.get(this).r0}set r0(t){if(!Number.isFinite(t))throw new TypeError(s("r0"));if(t<=0)throw new RangeError(o("r0"));p.get(this).r0=t}get a(){return p.get(this).a}set a(t){if(!Number.isFinite(t))throw new TypeError(s("a"));if(t<=0)throw new RangeError(o("a"));p.get(this).a=t}at(t){if("number"!=typeof t)throw new TypeError(n);if(t<0)throw new RangeError(a);let{d0:r,r0:e,a:i}=this,s=1-Math.exp(i*(e-t));return r*s*s-r}toJSON(){return{type:g.type,d0:this.d0,r0:this.r0,a:this.a}}}let u=new WeakMap;class b extends r{constructor({d0:t=1,r0:r=1,b:e=2}={}){super(),u.set(this,{}),this.d0=t,this.r0=r,this.b=e}static get type(){return"Rydberg"}static fastFrom(t){if(!Array.isArray(t))throw new TypeError(i);if(t.length<3)throw new Error(e);t=t.slice().sort(((t,r)=>t.r-r.r));let r,s,o,n=Number.POSITIVE_INFINITY,a=1;for(let{r:r,e:e}of t)e=a||r.e<0||s.e<0));e++);if(r&&s&&r.r0&&(o=a/(a-t))}return new b({d0:n,r0:a,b:o})}static from(t,{d0Conv:r=.001,r0Conv:e=.001,bConv:i=.001}={}){let s=this.fastFrom(t),{d0:o,r0:n,b:a}=s;const h=o*r,w=n*e,f=a*i;let l,p,g;do{let r=0,e=0,i=0,s=0,h=0,w=0,f=0,u=0,b=0;for(let{r:l,e:p}of t){let t=a*(l/n-1),g=Math.exp(-t),d=-o*(1+t)*g,m=d/o,y=-o*a*l/(n*n)*g*t,E=o*t/a*g*t;r+=m*m,e+=y*m,i+=E*m,s+=(d-p)*m,h+=y*y,w+=E*y,f+=(d-p)*y,u+=E*E,b+=(d-p)*E}g=-(s-r*f/e-(e-r*h/e)/(e-r*w/i)*(s-r*b/i))/(i-r*w/e-(i-r*u/i)*(e-r*h/e)/(e-r*w/i)),p=((i-r*w/e)*g+(s-r*f/e))/(r*h/e-e),l=(-e*p-i*g-s)/r,o+=l,n+=p,a+=g}while(Math.abs(l)>h&&Math.abs(p)>w&&Math.abs(g)>f);return s.d0=o,s.r0=n,s.b=a,s}get d0(){return u.get(this).d0}set d0(t){if(!Number.isFinite(t))throw new TypeError(s("d0"));if(t<=0)throw new RangeError(o("d0"));u.get(this).d0=t}get r0(){return u.get(this).r0}set r0(t){if(!Number.isFinite(t))throw new TypeError(s("r0"));if(t<=0)throw new RangeError(o("r0"));u.get(this).r0=t}get b(){return u.get(this).b}set b(t){if(!Number.isFinite(t))throw new TypeError(s("b"));if(t<=1)throw new RangeError(o("b",1));u.get(this).b=t}at(t){if("number"!=typeof t)throw new TypeError(n);if(t<0)throw new RangeError(a);let{d0:r,r0:e,b:i}=this,s=i*(t-e)/e;return-r*(1+s)*Math.exp(-s)}toJSON(){return{type:b.type,d0:this.d0,r0:this.r0,b:this.b}}}let d=new WeakMap;class m extends r{constructor({d0:t=1,r0:r=1,b:e=1}={}){super(),d.set(this,{}),this.d0=t,this.r0=r,this.b=e}static get type(){return"Varshni3"}static fastFrom(t){if(!Array.isArray(t))throw new TypeError(i);if(t.length<3)throw new Error(e);let r=Number.POSITIVE_INFINITY,s=1;for(let{r:e,e:i}of t)is?a=Math.log(e/s*(1-t))/(s*s-e*e):eh&&Math.abs(p)>w&&Math.abs(g)>f);return s.d0=o,s.r0=n,s.b=a,s}get d0(){return d.get(this).d0}set d0(t){if(!Number.isFinite(t))throw new TypeError(s("d0"));if(t<=0)throw new RangeError(o("d0"));d.get(this).d0=t}get r0(){return d.get(this).r0}set r0(t){if(!Number.isFinite(t))throw new TypeError(s("r0"));if(t<=0)throw new RangeError(o("r0"));d.get(this).r0=t}get b(){return d.get(this).b}set b(t){if(!Number.isFinite(t))throw new TypeError(s("b"));if(t<=0)throw new RangeError(o("b"));d.get(this).b=t}at(t){if("number"!=typeof t)throw new TypeError(n);if(t<0)throw new RangeError(a);let{d0:r,r0:e,b:i}=this,s=1-e/t*Math.exp(i*(e*e-t*t));return r*s*s-r}toJSON(){return{type:m.type,d0:this.d0,r0:this.r0,b:this.b}}}t.Buckingham=l,t.LennardJones=w,t.Morse=g,t.Rydberg=b,t.Varshni3=m})); diff --git a/dist/potprox.min.mjs b/dist/potprox.min.mjs index 217afb8..2c8c157 100644 --- a/dist/potprox.min.mjs +++ b/dist/potprox.min.mjs @@ -1,5 +1,5 @@ /*! -potprox v0.7.2 +potprox v0.8.0 https://amphiluke.github.io/potprox/ */ class r{rSqr(r){let t=0,e=0;for(let{r:i,e:s}of r){t+=s;let r=s-this.at(i);e+=r*r}t/=r.length;let i=0;for(let{e:e}of r){let r=e-t;i+=r*r}return 1-e/i}*points({start:r=this.r0/2,end:t=2*this.r0,step:e=(t-r)/49}={}){let i=0,s=r,o=Math.sign(t-r);for(e=Math.abs(e)*o;(t-s)*o>=0;)yield{r:s,e:this.at(s),index:i},s=r+e*++i;return{r:t,e:this.at(t)}}}const t="Too little points. Approximation is impossible",e="Approximated data must be an array of points",i=r=>`The “${r}” parameter must be a finite number`,s=(r,t=0)=>`The “${r}” parameter must be greater than ${t}`,o="Distance must be a number",n="Distance mustn’t be less than 0";let a=new WeakMap;class h extends r{constructor({epsilon:r=1,sigma:t=1}={}){super(),a.set(this,{}),this.epsilon=r,this.sigma=t}static get type(){return"LennardJones"}static from(r){if(!Array.isArray(r))throw new TypeError(e);if(r.length<3)throw new Error(t);let i=0,s=0,o=0,n=0,a=0;for(let{r:t,e:e}of r)i+=Math.pow(t,-24),s+=Math.pow(t,-18),o+=e*Math.pow(t,-12),n+=Math.pow(t,-12),a+=e*Math.pow(t,-6);let w=(a-s*o/i)/(n-s*s/i),f=(o-s*w)/i,l=Math.pow(-f/w,1/6),p=f/(4*Math.pow(l,12));return new h({epsilon:p,sigma:l})}get epsilon(){return a.get(this).epsilon}set epsilon(r){if(!Number.isFinite(r))throw new TypeError(i("epsilon"));if(r<=0)throw new RangeError(s("epsilon"));a.get(this).epsilon=r}get sigma(){return a.get(this).sigma}set sigma(r){if(!Number.isFinite(r))throw new TypeError(i("sigma"));if(r<=0)throw new RangeError(s("sigma"));a.get(this).sigma=r}get r0(){return 1.122462048309373*this.sigma}set r0(r){this.sigma=r/1.122462048309373}at(r){if("number"!=typeof r)throw new TypeError(o);if(r<0)throw new RangeError(n);let{epsilon:t,sigma:e}=this;return 4*t*(Math.pow(e/r,12)-Math.pow(e/r,6))}toJSON(){return{type:h.type,epsilon:this.epsilon,sigma:this.sigma}}}let w=new WeakMap;class f extends r{constructor({d0:r=1,r0:t=1,a:e=2}={}){super(),w.set(this,{}),this.d0=r,this.r0=t,this.a=e}static get type(){return"Buckingham"}static fastFrom(r){if(!Array.isArray(r))throw new TypeError(e);if(r.length<3)throw new Error(t);r=r.slice().sort(((r,t)=>r.r-t.r));let i,s,o,n=Number.POSITIVE_INFINITY,a=1;for(let{r:t,e:e}of r)e=a||i.e<0||s.e<0));t++);if(i&&s&&i.r0){let t=1-r/a,e=Math.pow(a/r,6)/6;o=(e-t-Math.sqrt(e*e-2*t*e-t*t))/(t*t),Number.isFinite(o)||(o=void 0)}}return new f({d0:n,r0:a,a:o})}static from(r,{d0Conv:t=.001,r0Conv:e=.001,aConv:i=.001}={}){let s=this.fastFrom(r),{d0:o,r0:n,a:a}=s;const h=o*t,w=n*e,f=a*i;let l,p,g;do{let t=0,e=0,i=0,s=0,h=0,w=0,f=0,u=0,b=0;for(let{r:l,e:p}of r){let r=a*Math.pow(n/l,6),g=Math.exp(a*(1-l/n)),d=o/(a-6)*(6*g-r),m=d/o,y=o/(a-6)*(6*g*a*l/(n*n)-6*r/n),E=-o/((a-6)*(a-6))*(6*g-r)+o/(a-6)*(6*(1-l/n)*g-r/a);t+=m*m,e+=y*m,i+=E*m,s+=(d-p)*m,h+=y*y,w+=E*y,f+=(d-p)*y,u+=E*E,b+=(d-p)*E}g=-(s-t*f/e-(e-t*h/e)/(e-t*w/i)*(s-t*b/i))/(i-t*w/e-(i-t*u/i)*(e-t*h/e)/(e-t*w/i)),p=((i-t*w/e)*g+(s-t*f/e))/(t*h/e-e),l=(-e*p-i*g-s)/t,o+=l,n+=p,a+=g}while(Math.abs(l)>h&&Math.abs(p)>w&&Math.abs(g)>f);return s.d0=o,s.r0=n,s.a=a,s}get d0(){return w.get(this).d0}set d0(r){if(!Number.isFinite(r))throw new TypeError(i("d0"));if(r<=0)throw new RangeError(s("d0"));w.get(this).d0=r}get r0(){return w.get(this).r0}set r0(r){if(!Number.isFinite(r))throw new TypeError(i("r0"));if(r<=0)throw new RangeError(s("r0"));w.get(this).r0=r}get a(){return w.get(this).a}set a(r){if(!Number.isFinite(r))throw new TypeError(i("a"));if(r<=0)throw new RangeError(s("a"));w.get(this).a=r}at(r){if("number"!=typeof r)throw new TypeError(o);if(r<0)throw new RangeError(n);let{d0:t,r0:e,a:i}=this;return t/(i-6)*(6*Math.exp(i*(1-r/e))-i*Math.pow(e/r,6))}toJSON(){return{type:f.type,d0:this.d0,r0:this.r0,a:this.a}}}let l=new WeakMap;class p extends r{constructor({d0:r=1,r0:t=1,a:e=1}={}){super(),l.set(this,{}),this.d0=r,this.r0=t,this.a=e}static get type(){return"Morse"}static fastFrom(r){if(!Array.isArray(r))throw new TypeError(e);if(r.length<3)throw new Error(t);let i=Number.POSITIVE_INFINITY,s=1;for(let{r:t,e:e}of r)es?a=Math.log(1-r)/(s-t):th&&Math.abs(p)>w&&Math.abs(g)>f);return s.d0=o,s.r0=n,s.a=a,s}get d0(){return l.get(this).d0}set d0(r){if(!Number.isFinite(r))throw new TypeError(i("d0"));if(r<=0)throw new RangeError(s("d0"));l.get(this).d0=r}get r0(){return l.get(this).r0}set r0(r){if(!Number.isFinite(r))throw new TypeError(i("r0"));if(r<=0)throw new RangeError(s("r0"));l.get(this).r0=r}get a(){return l.get(this).a}set a(r){if(!Number.isFinite(r))throw new TypeError(i("a"));if(r<=0)throw new RangeError(s("a"));l.get(this).a=r}at(r){if("number"!=typeof r)throw new TypeError(o);if(r<0)throw new RangeError(n);let{d0:t,r0:e,a:i}=this,s=1-Math.exp(i*(e-r));return t*s*s-t}toJSON(){return{type:p.type,d0:this.d0,r0:this.r0,a:this.a}}}let g=new WeakMap;class u extends r{constructor({d0:r=1,r0:t=1,b:e=2}={}){super(),g.set(this,{}),this.d0=r,this.r0=t,this.b=e}static get type(){return"Rydberg"}static fastFrom(r){if(!Array.isArray(r))throw new TypeError(e);if(r.length<3)throw new Error(t);r=r.slice().sort(((r,t)=>r.r-t.r));let i,s,o,n=Number.POSITIVE_INFINITY,a=1;for(let{r:t,e:e}of r)e=a||i.e<0||s.e<0));t++);if(i&&s&&i.r0&&(o=a/(a-r))}return new u({d0:n,r0:a,b:o})}static from(r,{d0Conv:t=.001,r0Conv:e=.001,bConv:i=.001}={}){let s=this.fastFrom(r),{d0:o,r0:n,b:a}=s;const h=o*t,w=n*e,f=a*i;let l,p,g;do{let t=0,e=0,i=0,s=0,h=0,w=0,f=0,u=0,b=0;for(let{r:l,e:p}of r){let r=a*(l/n-1),g=Math.exp(-r),d=-o*(1+r)*g,m=d/o,y=-o*a*l/(n*n)*g*r,E=o*r/a*g*r;t+=m*m,e+=y*m,i+=E*m,s+=(d-p)*m,h+=y*y,w+=E*y,f+=(d-p)*y,u+=E*E,b+=(d-p)*E}g=-(s-t*f/e-(e-t*h/e)/(e-t*w/i)*(s-t*b/i))/(i-t*w/e-(i-t*u/i)*(e-t*h/e)/(e-t*w/i)),p=((i-t*w/e)*g+(s-t*f/e))/(t*h/e-e),l=(-e*p-i*g-s)/t,o+=l,n+=p,a+=g}while(Math.abs(l)>h&&Math.abs(p)>w&&Math.abs(g)>f);return s.d0=o,s.r0=n,s.b=a,s}get d0(){return g.get(this).d0}set d0(r){if(!Number.isFinite(r))throw new TypeError(i("d0"));if(r<=0)throw new RangeError(s("d0"));g.get(this).d0=r}get r0(){return g.get(this).r0}set r0(r){if(!Number.isFinite(r))throw new TypeError(i("r0"));if(r<=0)throw new RangeError(s("r0"));g.get(this).r0=r}get b(){return g.get(this).b}set b(r){if(!Number.isFinite(r))throw new TypeError(i("b"));if(r<=1)throw new RangeError(s("b",1));g.get(this).b=r}at(r){if("number"!=typeof r)throw new TypeError(o);if(r<0)throw new RangeError(n);let{d0:t,r0:e,b:i}=this,s=i*(r-e)/e;return-t*(1+s)*Math.exp(-s)}toJSON(){return{type:u.type,d0:this.d0,r0:this.r0,b:this.b}}}let b=new WeakMap;class d extends r{constructor({d0:r=1,r0:t=1,b:e=1}={}){super(),b.set(this,{}),this.d0=r,this.r0=t,this.b=e}static get type(){return"Varshni3"}static fastFrom(r){if(!Array.isArray(r))throw new TypeError(e);if(r.length<3)throw new Error(t);let i=Number.POSITIVE_INFINITY,s=1;for(let{r:t,e:e}of r)es?a=Math.log(t/s*(1-r))/(s*s-t*t):th&&Math.abs(p)>w&&Math.abs(g)>f);return s.d0=o,s.r0=n,s.b=a,s}get d0(){return b.get(this).d0}set d0(r){if(!Number.isFinite(r))throw new TypeError(i("d0"));if(r<=0)throw new RangeError(s("d0"));b.get(this).d0=r}get r0(){return b.get(this).r0}set r0(r){if(!Number.isFinite(r))throw new TypeError(i("r0"));if(r<=0)throw new RangeError(s("r0"));b.get(this).r0=r}get b(){return b.get(this).b}set b(r){if(!Number.isFinite(r))throw new TypeError(i("b"));if(r<=0)throw new RangeError(s("b"));b.get(this).b=r}at(r){if("number"!=typeof r)throw new TypeError(o);if(r<0)throw new RangeError(n);let{d0:t,r0:e,b:i}=this,s=1-e/r*Math.exp(i*(e*e-r*r));return t*s*s-t}toJSON(){return{type:d.type,d0:this.d0,r0:this.r0,b:this.b}}}export{f as Buckingham,h as LennardJones,p as Morse,u as Rydberg,d as Varshni3}; diff --git a/dist/potprox.mjs b/dist/potprox.mjs index e086efa..21ee396 100644 --- a/dist/potprox.mjs +++ b/dist/potprox.mjs @@ -1,5 +1,5 @@ /*! -potprox v0.7.2 +potprox v0.8.0 https://amphiluke.github.io/potprox/ */ class AbstractProto { diff --git a/package-lock.json b/package-lock.json index d4e02bd..054b90c 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,18 +1,18 @@ { "name": "potprox", - "version": "0.7.2", + "version": "0.8.0", "lockfileVersion": 3, "requires": true, "packages": { "": { "name": "potprox", - "version": "0.7.2", + "version": "0.8.0", "license": "MIT", "devDependencies": { - "@rollup/plugin-terser": "^0.4.3", - "eslint": "^8.45.0", - "husky": "^8.0.3", - "rollup": "^3.26.3" + "@rollup/plugin-terser": "^0.4.4", + "eslint": "^8.56.0", + "husky": "^9.0.6", + "rollup": "^4.9.6" } }, "node_modules/@aashutoshrathi/word-wrap": { @@ -40,18 +40,18 @@ } }, "node_modules/@eslint-community/regexpp": { - "version": "4.6.0", - "resolved": "https://registry.npmjs.org/@eslint-community/regexpp/-/regexpp-4.6.0.tgz", - "integrity": "sha512-uiPeRISaglZnaZk8vwrjQZ1CxogZeY/4IYft6gBOTqu1WhVXWmCmZMWxUv2Q/pxSvPdp1JPaO62kLOcOkMqWrw==", + "version": "4.10.0", + "resolved": "https://registry.npmjs.org/@eslint-community/regexpp/-/regexpp-4.10.0.tgz", + "integrity": "sha512-Cu96Sd2By9mCNTx2iyKOmq10v22jUVQv0lQnlGNy16oE9589yE+QADPbrMGCkA51cKZSg3Pu/aTJVTGfL/qjUA==", "dev": true, "engines": { "node": "^12.0.0 || ^14.0.0 || >=16.0.0" } }, "node_modules/@eslint/eslintrc": { - "version": "2.1.0", - "resolved": "https://registry.npmjs.org/@eslint/eslintrc/-/eslintrc-2.1.0.tgz", - "integrity": "sha512-Lj7DECXqIVCqnqjjHMPna4vn6GJcMgul/wuS0je9OZ9gsL0zzDpKPVtcG1HaDVc+9y+qgXneTeUMbCqXJNpH1A==", + "version": "2.1.4", + "resolved": "https://registry.npmjs.org/@eslint/eslintrc/-/eslintrc-2.1.4.tgz", + "integrity": "sha512-269Z39MS6wVJtsoUl10L60WdkhJVdPG24Q4eZTH3nnF6lpvSShEK3wQjDX9JRWAUPvPh7COouPpU9IrqaZFvtQ==", "dev": true, "dependencies": { "ajv": "^6.12.4", @@ -72,22 +72,22 @@ } }, "node_modules/@eslint/js": { - "version": "8.44.0", - "resolved": "https://registry.npmjs.org/@eslint/js/-/js-8.44.0.tgz", - "integrity": "sha512-Ag+9YM4ocKQx9AarydN0KY2j0ErMHNIocPDrVo8zAE44xLTjEtz81OdR68/cydGtk6m6jDb5Za3r2useMzYmSw==", + "version": "8.56.0", + "resolved": "https://registry.npmjs.org/@eslint/js/-/js-8.56.0.tgz", + "integrity": "sha512-gMsVel9D7f2HLkBma9VbtzZRehRogVRfbr++f06nL2vnCGCNlzOD+/MUov/F4p8myyAHspEhVobgjpX64q5m6A==", "dev": true, "engines": { "node": "^12.22.0 || ^14.17.0 || >=16.0.0" } }, "node_modules/@humanwhocodes/config-array": { - "version": "0.11.10", - "resolved": "https://registry.npmjs.org/@humanwhocodes/config-array/-/config-array-0.11.10.tgz", - "integrity": "sha512-KVVjQmNUepDVGXNuoRRdmmEjruj0KfiGSbS8LVc12LMsWDQzRXJ0qdhN8L8uUigKpfEHRhlaQFY0ib1tnUbNeQ==", + "version": "0.11.14", + "resolved": "https://registry.npmjs.org/@humanwhocodes/config-array/-/config-array-0.11.14.tgz", + "integrity": "sha512-3T8LkOmg45BV5FICb15QQMsyUSWrQ8AygVfC7ZG32zOalnqrilm018ZVCw0eapXux8FtA33q8PSRSstjee3jSg==", "dev": true, "dependencies": { - "@humanwhocodes/object-schema": "^1.2.1", - "debug": "^4.1.1", + "@humanwhocodes/object-schema": "^2.0.2", + "debug": "^4.3.1", "minimatch": "^3.0.5" }, "engines": { @@ -108,9 +108,9 @@ } }, "node_modules/@humanwhocodes/object-schema": { - "version": "1.2.1", - "resolved": "https://registry.npmjs.org/@humanwhocodes/object-schema/-/object-schema-1.2.1.tgz", - "integrity": "sha512-ZnQMnLV4e7hDlUvw8H+U8ASL02SS2Gn6+9Ac3wGGLIe7+je2AeAOxPY+izIPJDfFDb7eDjev0Us8MO1iFRN8hA==", + "version": "2.0.2", + "resolved": "https://registry.npmjs.org/@humanwhocodes/object-schema/-/object-schema-2.0.2.tgz", + "integrity": "sha512-6EwiSjwWYP7pTckG6I5eyFANjPhmPjUX9JRLUSfNPC7FX7zK9gyZAfUEaECL6ALTpGX5AjnBq3C9XmVWPitNpw==", "dev": true }, "node_modules/@jridgewell/gen-mapping": { @@ -128,9 +128,9 @@ } }, "node_modules/@jridgewell/resolve-uri": { - "version": "3.1.0", - "resolved": "https://registry.npmjs.org/@jridgewell/resolve-uri/-/resolve-uri-3.1.0.tgz", - "integrity": "sha512-F2msla3tad+Mfht5cJq7LSXcdudKTWCVYUgw6pLFOOHSTtZlj6SWNYAp+AhuqLmWdBO2X5hPrLcu8cVP8fy28w==", + "version": "3.1.1", + "resolved": "https://registry.npmjs.org/@jridgewell/resolve-uri/-/resolve-uri-3.1.1.tgz", + "integrity": "sha512-dSYZh7HhCDtCKm4QakX0xFpsRDqjjtZf/kjI/v3T3Nwt5r8/qz/M19F9ySyOqU94SXBmeG9ttTul+YnR4LOxFA==", "dev": true, "engines": { "node": ">=6.0.0" @@ -162,21 +162,15 @@ "dev": true }, "node_modules/@jridgewell/trace-mapping": { - "version": "0.3.18", - "resolved": "https://registry.npmjs.org/@jridgewell/trace-mapping/-/trace-mapping-0.3.18.tgz", - "integrity": "sha512-w+niJYzMHdd7USdiH2U6869nqhD2nbfZXND5Yp93qIbEmnDNk7PD48o+YchRVpzMU7M6jVCbenTR7PA1FLQ9pA==", + "version": "0.3.22", + "resolved": "https://registry.npmjs.org/@jridgewell/trace-mapping/-/trace-mapping-0.3.22.tgz", + "integrity": "sha512-Wf963MzWtA2sjrNt+g18IAln9lKnlRp+K2eH4jjIoF1wYeq3aMREpG09xhlhdzS0EjwU7qmUJYangWa+151vZw==", "dev": true, "dependencies": { - "@jridgewell/resolve-uri": "3.1.0", - "@jridgewell/sourcemap-codec": "1.4.14" + "@jridgewell/resolve-uri": "^3.1.0", + "@jridgewell/sourcemap-codec": "^1.4.14" } }, - "node_modules/@jridgewell/trace-mapping/node_modules/@jridgewell/sourcemap-codec": { - "version": "1.4.14", - "resolved": "https://registry.npmjs.org/@jridgewell/sourcemap-codec/-/sourcemap-codec-1.4.14.tgz", - "integrity": "sha512-XPSJHWmi394fuUuzDnGz1wiKqWfo1yXecHQMRf2l6hztTO+nPru658AyDngaBe7isIxEkRsPR3FZh+s7iVa4Uw==", - "dev": true - }, "node_modules/@nodelib/fs.scandir": { "version": "2.1.5", "resolved": "https://registry.npmjs.org/@nodelib/fs.scandir/-/fs.scandir-2.1.5.tgz", @@ -213,9 +207,9 @@ } }, "node_modules/@rollup/plugin-terser": { - "version": "0.4.3", - "resolved": "https://registry.npmjs.org/@rollup/plugin-terser/-/plugin-terser-0.4.3.tgz", - "integrity": "sha512-EF0oejTMtkyhrkwCdg0HJ0IpkcaVg1MMSf2olHb2Jp+1mnLM04OhjpJWGma4HobiDTF0WCyViWuvadyE9ch2XA==", + "version": "0.4.4", + "resolved": "https://registry.npmjs.org/@rollup/plugin-terser/-/plugin-terser-0.4.4.tgz", + "integrity": "sha512-XHeJC5Bgvs8LfukDwWZp7yeqin6ns8RTl2B9avbejt6tZqsqvVoWI7ZTQrcNsfKEDWBTnTxM8nMDkO2IFFbd0A==", "dev": true, "dependencies": { "serialize-javascript": "^6.0.1", @@ -226,7 +220,7 @@ "node": ">=14.0.0" }, "peerDependencies": { - "rollup": "^2.x || ^3.x" + "rollup": "^2.0.0||^3.0.0||^4.0.0" }, "peerDependenciesMeta": { "rollup": { @@ -234,10 +228,191 @@ } } }, + "node_modules/@rollup/rollup-android-arm-eabi": { + "version": "4.9.6", + "resolved": "https://registry.npmjs.org/@rollup/rollup-android-arm-eabi/-/rollup-android-arm-eabi-4.9.6.tgz", + "integrity": "sha512-MVNXSSYN6QXOulbHpLMKYi60ppyO13W9my1qogeiAqtjb2yR4LSmfU2+POvDkLzhjYLXz9Rf9+9a3zFHW1Lecg==", + "cpu": [ + "arm" + ], + "dev": true, + "optional": true, + "os": [ + "android" + ] + }, + "node_modules/@rollup/rollup-android-arm64": { + "version": "4.9.6", + "resolved": "https://registry.npmjs.org/@rollup/rollup-android-arm64/-/rollup-android-arm64-4.9.6.tgz", + "integrity": "sha512-T14aNLpqJ5wzKNf5jEDpv5zgyIqcpn1MlwCrUXLrwoADr2RkWA0vOWP4XxbO9aiO3dvMCQICZdKeDrFl7UMClw==", + "cpu": [ + "arm64" + ], + "dev": true, + "optional": true, + "os": [ + "android" + ] + }, + "node_modules/@rollup/rollup-darwin-arm64": { + "version": "4.9.6", + "resolved": "https://registry.npmjs.org/@rollup/rollup-darwin-arm64/-/rollup-darwin-arm64-4.9.6.tgz", + "integrity": "sha512-CqNNAyhRkTbo8VVZ5R85X73H3R5NX9ONnKbXuHisGWC0qRbTTxnF1U4V9NafzJbgGM0sHZpdO83pLPzq8uOZFw==", + "cpu": [ + "arm64" + ], + "dev": true, + "optional": true, + "os": [ + "darwin" + ] + }, + "node_modules/@rollup/rollup-darwin-x64": { + "version": "4.9.6", + "resolved": "https://registry.npmjs.org/@rollup/rollup-darwin-x64/-/rollup-darwin-x64-4.9.6.tgz", + "integrity": "sha512-zRDtdJuRvA1dc9Mp6BWYqAsU5oeLixdfUvkTHuiYOHwqYuQ4YgSmi6+/lPvSsqc/I0Omw3DdICx4Tfacdzmhog==", + "cpu": [ + "x64" + ], + "dev": true, + "optional": true, + "os": [ + "darwin" + ] + }, + "node_modules/@rollup/rollup-linux-arm-gnueabihf": { + "version": "4.9.6", + "resolved": "https://registry.npmjs.org/@rollup/rollup-linux-arm-gnueabihf/-/rollup-linux-arm-gnueabihf-4.9.6.tgz", + "integrity": "sha512-oNk8YXDDnNyG4qlNb6is1ojTOGL/tRhbbKeE/YuccItzerEZT68Z9gHrY3ROh7axDc974+zYAPxK5SH0j/G+QQ==", + "cpu": [ + "arm" + ], + "dev": true, + "optional": true, + "os": [ + "linux" + ] + }, + "node_modules/@rollup/rollup-linux-arm64-gnu": { + "version": "4.9.6", + "resolved": "https://registry.npmjs.org/@rollup/rollup-linux-arm64-gnu/-/rollup-linux-arm64-gnu-4.9.6.tgz", + "integrity": "sha512-Z3O60yxPtuCYobrtzjo0wlmvDdx2qZfeAWTyfOjEDqd08kthDKexLpV97KfAeUXPosENKd8uyJMRDfFMxcYkDQ==", + "cpu": [ + "arm64" + ], + "dev": true, + "optional": true, + "os": [ + "linux" + ] + }, + "node_modules/@rollup/rollup-linux-arm64-musl": { + "version": "4.9.6", + "resolved": "https://registry.npmjs.org/@rollup/rollup-linux-arm64-musl/-/rollup-linux-arm64-musl-4.9.6.tgz", + "integrity": "sha512-gpiG0qQJNdYEVad+1iAsGAbgAnZ8j07FapmnIAQgODKcOTjLEWM9sRb+MbQyVsYCnA0Im6M6QIq6ax7liws6eQ==", + "cpu": [ + "arm64" + ], + "dev": true, + "optional": true, + "os": [ + "linux" + ] + }, + "node_modules/@rollup/rollup-linux-riscv64-gnu": { + "version": "4.9.6", + "resolved": "https://registry.npmjs.org/@rollup/rollup-linux-riscv64-gnu/-/rollup-linux-riscv64-gnu-4.9.6.tgz", + "integrity": "sha512-+uCOcvVmFUYvVDr27aiyun9WgZk0tXe7ThuzoUTAukZJOwS5MrGbmSlNOhx1j80GdpqbOty05XqSl5w4dQvcOA==", + "cpu": [ + "riscv64" + ], + "dev": true, + "optional": true, + "os": [ + "linux" + ] + }, + "node_modules/@rollup/rollup-linux-x64-gnu": { + "version": "4.9.6", + "resolved": "https://registry.npmjs.org/@rollup/rollup-linux-x64-gnu/-/rollup-linux-x64-gnu-4.9.6.tgz", + "integrity": "sha512-HUNqM32dGzfBKuaDUBqFB7tP6VMN74eLZ33Q9Y1TBqRDn+qDonkAUyKWwF9BR9unV7QUzffLnz9GrnKvMqC/fw==", + "cpu": [ + "x64" + ], + "dev": true, + "optional": true, + "os": [ + "linux" + ] + }, + "node_modules/@rollup/rollup-linux-x64-musl": { + "version": "4.9.6", + "resolved": "https://registry.npmjs.org/@rollup/rollup-linux-x64-musl/-/rollup-linux-x64-musl-4.9.6.tgz", + "integrity": "sha512-ch7M+9Tr5R4FK40FHQk8VnML0Szi2KRujUgHXd/HjuH9ifH72GUmw6lStZBo3c3GB82vHa0ZoUfjfcM7JiiMrQ==", + "cpu": [ + "x64" + ], + "dev": true, + "optional": true, + "os": [ + "linux" + ] + }, + "node_modules/@rollup/rollup-win32-arm64-msvc": { + "version": "4.9.6", + "resolved": "https://registry.npmjs.org/@rollup/rollup-win32-arm64-msvc/-/rollup-win32-arm64-msvc-4.9.6.tgz", + "integrity": "sha512-VD6qnR99dhmTQ1mJhIzXsRcTBvTjbfbGGwKAHcu+52cVl15AC/kplkhxzW/uT0Xl62Y/meBKDZvoJSJN+vTeGA==", + "cpu": [ + "arm64" + ], + "dev": true, + "optional": true, + "os": [ + "win32" + ] + }, + "node_modules/@rollup/rollup-win32-ia32-msvc": { + "version": "4.9.6", + "resolved": "https://registry.npmjs.org/@rollup/rollup-win32-ia32-msvc/-/rollup-win32-ia32-msvc-4.9.6.tgz", + "integrity": "sha512-J9AFDq/xiRI58eR2NIDfyVmTYGyIZmRcvcAoJ48oDld/NTR8wyiPUu2X/v1navJ+N/FGg68LEbX3Ejd6l8B7MQ==", + "cpu": [ + "ia32" + ], + "dev": true, + "optional": true, + "os": [ + "win32" + ] + }, + "node_modules/@rollup/rollup-win32-x64-msvc": { + "version": "4.9.6", + "resolved": "https://registry.npmjs.org/@rollup/rollup-win32-x64-msvc/-/rollup-win32-x64-msvc-4.9.6.tgz", + "integrity": "sha512-jqzNLhNDvIZOrt69Ce4UjGRpXJBzhUBzawMwnaDAwyHriki3XollsewxWzOzz+4yOFDkuJHtTsZFwMxhYJWmLQ==", + "cpu": [ + "x64" + ], + "dev": true, + "optional": true, + "os": [ + "win32" + ] + }, + "node_modules/@types/estree": { + "version": "1.0.5", + "resolved": "https://registry.npmjs.org/@types/estree/-/estree-1.0.5.tgz", + "integrity": "sha512-/kYRxGDLWzHOB7q+wtSUQlFrtcdUccpfy+X+9iMBpHK8QLLhx2wIPYuS5DYtR9Wa/YlZAbIovy7qVdB1Aq6Lyw==", + "dev": true + }, + "node_modules/@ungap/structured-clone": { + "version": "1.2.0", + "resolved": "https://registry.npmjs.org/@ungap/structured-clone/-/structured-clone-1.2.0.tgz", + "integrity": "sha512-zuVdFrMJiuCDQUMCzQaD6KL28MjnqqN8XnAqiEq9PNm/hCPTSGfrXCOfwj1ow4LFb/tNymJPwsNbVePc1xFqrQ==", + "dev": true + }, "node_modules/acorn": { - "version": "8.10.0", - "resolved": "https://registry.npmjs.org/acorn/-/acorn-8.10.0.tgz", - "integrity": "sha512-F0SAmZ8iUtS//m8DmCTA0jlh6TDKkHQyK6xc6V4KDTyZKA9dnvX9/3sRTVQrWm79glUAZbnmmNcdYwUIHWVybw==", + "version": "8.11.3", + "resolved": "https://registry.npmjs.org/acorn/-/acorn-8.11.3.tgz", + "integrity": "sha512-Y9rRfJG5jcKOE0CLisYbojUjIrIEE7AGMzA/Sm4BslANhbS+cDMpgBdcPT91oJ7OuJ9hYJBx59RjbhxVnrF8Xg==", "dev": true, "bin": { "acorn": "bin/acorn" @@ -440,27 +615,28 @@ } }, "node_modules/eslint": { - "version": "8.45.0", - "resolved": "https://registry.npmjs.org/eslint/-/eslint-8.45.0.tgz", - "integrity": "sha512-pd8KSxiQpdYRfYa9Wufvdoct3ZPQQuVuU5O6scNgMuOMYuxvH0IGaYK0wUFjo4UYYQQCUndlXiMbnxopwvvTiw==", + "version": "8.56.0", + "resolved": "https://registry.npmjs.org/eslint/-/eslint-8.56.0.tgz", + "integrity": "sha512-Go19xM6T9puCOWntie1/P997aXxFsOi37JIHRWI514Hc6ZnaHGKY9xFhrU65RT6CcBEzZoGG1e6Nq+DT04ZtZQ==", "dev": true, "dependencies": { "@eslint-community/eslint-utils": "^4.2.0", - "@eslint-community/regexpp": "^4.4.0", - "@eslint/eslintrc": "^2.1.0", - "@eslint/js": "8.44.0", - "@humanwhocodes/config-array": "^0.11.10", + "@eslint-community/regexpp": "^4.6.1", + "@eslint/eslintrc": "^2.1.4", + "@eslint/js": "8.56.0", + "@humanwhocodes/config-array": "^0.11.13", "@humanwhocodes/module-importer": "^1.0.1", "@nodelib/fs.walk": "^1.2.8", - "ajv": "^6.10.0", + "@ungap/structured-clone": "^1.2.0", + "ajv": "^6.12.4", "chalk": "^4.0.0", "cross-spawn": "^7.0.2", "debug": "^4.3.2", "doctrine": "^3.0.0", "escape-string-regexp": "^4.0.0", - "eslint-scope": "^7.2.0", - "eslint-visitor-keys": "^3.4.1", - "espree": "^9.6.0", + "eslint-scope": "^7.2.2", + "eslint-visitor-keys": "^3.4.3", + "espree": "^9.6.1", "esquery": "^1.4.2", "esutils": "^2.0.2", "fast-deep-equal": "^3.1.3", @@ -494,9 +670,9 @@ } }, "node_modules/eslint-scope": { - "version": "7.2.1", - "resolved": "https://registry.npmjs.org/eslint-scope/-/eslint-scope-7.2.1.tgz", - "integrity": "sha512-CvefSOsDdaYYvxChovdrPo/ZGt8d5lrJWleAc1diXRKhHGiTYEI26cvo8Kle/wGnsizoCJjK73FMg1/IkIwiNA==", + "version": "7.2.2", + "resolved": "https://registry.npmjs.org/eslint-scope/-/eslint-scope-7.2.2.tgz", + "integrity": "sha512-dOt21O7lTMhDM+X9mB4GX+DZrZtCUJPL/wlcTqxyrx5IvO0IYtILdtrQGQp+8n5S0gwSVmOf9NQrjMOgfQZlIg==", "dev": true, "dependencies": { "esrecurse": "^4.3.0", @@ -510,9 +686,9 @@ } }, "node_modules/eslint-visitor-keys": { - "version": "3.4.1", - "resolved": "https://registry.npmjs.org/eslint-visitor-keys/-/eslint-visitor-keys-3.4.1.tgz", - "integrity": "sha512-pZnmmLwYzf+kWaM/Qgrvpen51upAktaaiI01nsJD/Yr3lMOdNtq0cxkrrg16w64VtisN6okbs7Q8AfGqj4c9fA==", + "version": "3.4.3", + "resolved": "https://registry.npmjs.org/eslint-visitor-keys/-/eslint-visitor-keys-3.4.3.tgz", + "integrity": "sha512-wpc+LXeiyiisxPlEkUzU6svyS1frIO3Mgxj1fdy7Pm8Ygzguax2N3Fa/D/ag1WqbOprdI+uY6wMUl8/a2G+iag==", "dev": true, "engines": { "node": "^12.22.0 || ^14.17.0 || >=16.0.0" @@ -599,9 +775,9 @@ "dev": true }, "node_modules/fastq": { - "version": "1.15.0", - "resolved": "https://registry.npmjs.org/fastq/-/fastq-1.15.0.tgz", - "integrity": "sha512-wBrocU2LCXXa+lWBt8RoIRD89Fi8OdABODa/kEnyeyjS5aZO5/GNvI5sEINADqP/h8M29UHTHUb53sUu5Ihqdw==", + "version": "1.17.0", + "resolved": "https://registry.npmjs.org/fastq/-/fastq-1.17.0.tgz", + "integrity": "sha512-zGygtijUMT7jnk3h26kUms3BkSDp4IfIKjmnqI2tvx6nuBfiF1UqOxbnLfzdv+apBy+53oaImsKtMw/xYbW+1w==", "dev": true, "dependencies": { "reusify": "^1.0.4" @@ -636,12 +812,13 @@ } }, "node_modules/flat-cache": { - "version": "3.0.4", - "resolved": "https://registry.npmjs.org/flat-cache/-/flat-cache-3.0.4.tgz", - "integrity": "sha512-dm9s5Pw7Jc0GvMYbshN6zchCA9RgQlzzEZX3vylR9IqFfS8XciblUXOKfW6SiuJ0e13eDYZoZV5wdrev7P3Nwg==", + "version": "3.2.0", + "resolved": "https://registry.npmjs.org/flat-cache/-/flat-cache-3.2.0.tgz", + "integrity": "sha512-CYcENa+FtcUKLmhhqyctpclsq7QF38pKjZHsGNiSQF5r4FtoKDWabFDl3hzaEQMvT1LHEysw5twgLvpYYb4vbw==", "dev": true, "dependencies": { - "flatted": "^3.1.0", + "flatted": "^3.2.9", + "keyv": "^4.5.3", "rimraf": "^3.0.2" }, "engines": { @@ -649,9 +826,9 @@ } }, "node_modules/flatted": { - "version": "3.2.7", - "resolved": "https://registry.npmjs.org/flatted/-/flatted-3.2.7.tgz", - "integrity": "sha512-5nqDSxl8nn5BSNxyR3n4I6eDmbolI6WT+QqR547RwxQapgjQBmtktdP+HTBb/a/zLsbzERTONyUB5pefh5TtjQ==", + "version": "3.2.9", + "resolved": "https://registry.npmjs.org/flatted/-/flatted-3.2.9.tgz", + "integrity": "sha512-36yxDn5H7OFZQla0/jFJmbIKTdZAQHngCedGxiMmpNfEZM0sdEeT+WczLQrjK6D7o2aiyLYDnkw0R3JK0Qv1RQ==", "dev": true }, "node_modules/fs.realpath": { @@ -661,9 +838,9 @@ "dev": true }, "node_modules/fsevents": { - "version": "2.3.2", - "resolved": "https://registry.npmjs.org/fsevents/-/fsevents-2.3.2.tgz", - "integrity": "sha512-xiqMQR4xAeHTuB9uWm+fFRcIOgKBMiOBP+eXiyT7jsgVCq1bkVygt00oASowB7EdtpOHaaPgKt812P9ab+DDKA==", + "version": "2.3.3", + "resolved": "https://registry.npmjs.org/fsevents/-/fsevents-2.3.3.tgz", + "integrity": "sha512-5xoDfX+fL7faATnagmWPpbFtwh/R77WmMMqqHGS65C3vvB0YHrgF+B1YmZ3441tMj5n63k0212XNoJwzlhffQw==", "dev": true, "hasInstallScript": true, "optional": true, @@ -707,9 +884,9 @@ } }, "node_modules/globals": { - "version": "13.20.0", - "resolved": "https://registry.npmjs.org/globals/-/globals-13.20.0.tgz", - "integrity": "sha512-Qg5QtVkCy/kv3FUSlu4ukeZDVf9ee0iXLAUYX13gbR17bnejFTzr4iS9bY7kwCf1NztRNm1t91fjOiyx4CSwPQ==", + "version": "13.24.0", + "resolved": "https://registry.npmjs.org/globals/-/globals-13.24.0.tgz", + "integrity": "sha512-AhO5QUcj8llrbG09iWhPU2B204J1xnPeL8kQmVorSsy+Sjj1sk8gIyh6cUocGmH4L0UuhAJy+hJMRA4mgA4mFQ==", "dev": true, "dependencies": { "type-fest": "^0.20.2" @@ -737,24 +914,24 @@ } }, "node_modules/husky": { - "version": "8.0.3", - "resolved": "https://registry.npmjs.org/husky/-/husky-8.0.3.tgz", - "integrity": "sha512-+dQSyqPh4x1hlO1swXBiNb2HzTDN1I2IGLQx1GrBuiqFJfoMrnZWwVmatvSiO+Iz8fBUnf+lekwNo4c2LlXItg==", + "version": "9.0.6", + "resolved": "https://registry.npmjs.org/husky/-/husky-9.0.6.tgz", + "integrity": "sha512-EEuw/rfTiMjOfuL7pGO/i9otg1u36TXxqjIA6D9qxVjd/UXoDOsLor/BSFf5hTK50shwzCU3aVVwdXDp/lp7RA==", "dev": true, "bin": { - "husky": "lib/bin.js" + "husky": "bin.js" }, "engines": { - "node": ">=14" + "node": ">=18" }, "funding": { "url": "https://github.com/sponsors/typicode" } }, "node_modules/ignore": { - "version": "5.2.4", - "resolved": "https://registry.npmjs.org/ignore/-/ignore-5.2.4.tgz", - "integrity": "sha512-MAb38BcSbH0eHNBxn7ql2NH/kX33OkB3lZ1BNdh7ENeRChHTYsTvWrMubiIAMNS2llXEEgZ1MUOBtXChP3kaFQ==", + "version": "5.3.0", + "resolved": "https://registry.npmjs.org/ignore/-/ignore-5.3.0.tgz", + "integrity": "sha512-g7dmpshy+gD7mh88OC9NwSGTKoc3kyLAZQRU1mt53Aw/vnvfXnbC+F/7F7QoYVKbV+KNvJx8wArewKy1vXMtlg==", "dev": true, "engines": { "node": ">= 4" @@ -849,6 +1026,12 @@ "js-yaml": "bin/js-yaml.js" } }, + "node_modules/json-buffer": { + "version": "3.0.1", + "resolved": "https://registry.npmjs.org/json-buffer/-/json-buffer-3.0.1.tgz", + "integrity": "sha512-4bV5BfR2mqfQTJm+V5tPPdf+ZpuhiIvTuAB5g8kcrXOZpTT/QwwVRWBywX1ozr6lEuPdbHxwaJlm9G6mI2sfSQ==", + "dev": true + }, "node_modules/json-schema-traverse": { "version": "0.4.1", "resolved": "https://registry.npmjs.org/json-schema-traverse/-/json-schema-traverse-0.4.1.tgz", @@ -861,6 +1044,15 @@ "integrity": "sha512-Bdboy+l7tA3OGW6FjyFHWkP5LuByj1Tk33Ljyq0axyzdk9//JSi2u3fP1QSmd1KNwq6VOKYGlAu87CisVir6Pw==", "dev": true }, + "node_modules/keyv": { + "version": "4.5.4", + "resolved": "https://registry.npmjs.org/keyv/-/keyv-4.5.4.tgz", + "integrity": "sha512-oxVHkHR/EJf2CNXnWxRLW6mg7JyCCUcG0DtEGmL2ctUo1PNTin1PUil+r/+4r5MpVgC/fn1kjsx7mjSujKqIpw==", + "dev": true, + "dependencies": { + "json-buffer": "3.0.1" + } + }, "node_modules/levn": { "version": "0.4.1", "resolved": "https://registry.npmjs.org/levn/-/levn-0.4.1.tgz", @@ -1024,9 +1216,9 @@ } }, "node_modules/punycode": { - "version": "2.3.0", - "resolved": "https://registry.npmjs.org/punycode/-/punycode-2.3.0.tgz", - "integrity": "sha512-rRV+zQD8tVFys26lAGR9WUuS4iUAngJScM+ZRSKtvl5tKeZ2t5bvdNFdNHBW9FWR4guGHlgmsZ1G7BSm2wTbuA==", + "version": "2.3.1", + "resolved": "https://registry.npmjs.org/punycode/-/punycode-2.3.1.tgz", + "integrity": "sha512-vYt7UD1U9Wg6138shLtLOvdAu+8DsC/ilFtEVHcH+wydcSpNE20AfSOduf6MkRFahL5FY7X1oU7nKVZFtfq8Fg==", "dev": true, "engines": { "node": ">=6" @@ -1096,18 +1288,34 @@ } }, "node_modules/rollup": { - "version": "3.26.3", - "resolved": "https://registry.npmjs.org/rollup/-/rollup-3.26.3.tgz", - "integrity": "sha512-7Tin0C8l86TkpcMtXvQu6saWH93nhG3dGQ1/+l5V2TDMceTxO7kDiK6GzbfLWNNxqJXm591PcEZUozZm51ogwQ==", + "version": "4.9.6", + "resolved": "https://registry.npmjs.org/rollup/-/rollup-4.9.6.tgz", + "integrity": "sha512-05lzkCS2uASX0CiLFybYfVkwNbKZG5NFQ6Go0VWyogFTXXbR039UVsegViTntkk4OglHBdF54ccApXRRuXRbsg==", "dev": true, + "dependencies": { + "@types/estree": "1.0.5" + }, "bin": { "rollup": "dist/bin/rollup" }, "engines": { - "node": ">=14.18.0", + "node": ">=18.0.0", "npm": ">=8.0.0" }, "optionalDependencies": { + "@rollup/rollup-android-arm-eabi": "4.9.6", + "@rollup/rollup-android-arm64": "4.9.6", + "@rollup/rollup-darwin-arm64": "4.9.6", + "@rollup/rollup-darwin-x64": "4.9.6", + "@rollup/rollup-linux-arm-gnueabihf": "4.9.6", + "@rollup/rollup-linux-arm64-gnu": "4.9.6", + "@rollup/rollup-linux-arm64-musl": "4.9.6", + "@rollup/rollup-linux-riscv64-gnu": "4.9.6", + "@rollup/rollup-linux-x64-gnu": "4.9.6", + "@rollup/rollup-linux-x64-musl": "4.9.6", + "@rollup/rollup-win32-arm64-msvc": "4.9.6", + "@rollup/rollup-win32-ia32-msvc": "4.9.6", + "@rollup/rollup-win32-x64-msvc": "4.9.6", "fsevents": "~2.3.2" } }, @@ -1155,9 +1363,9 @@ ] }, "node_modules/serialize-javascript": { - "version": "6.0.1", - "resolved": "https://registry.npmjs.org/serialize-javascript/-/serialize-javascript-6.0.1.tgz", - "integrity": "sha512-owoXEFjWRllis8/M1Q+Cw5k8ZH40e3zhp/ovX+Xr/vi1qj6QesbyXXViFbpNvWvPNAD62SutwEXavefrLJWj7w==", + "version": "6.0.2", + "resolved": "https://registry.npmjs.org/serialize-javascript/-/serialize-javascript-6.0.2.tgz", + "integrity": "sha512-Saa1xPByTTq2gdeFZYLLo+RFE35NHZkAbqZeWNd3BpzppeVisAqpDjcp8dyf6uIvEqJRd46jemmyA4iFIeVk8g==", "dev": true, "dependencies": { "randombytes": "^2.1.0" @@ -1185,9 +1393,9 @@ } }, "node_modules/smob": { - "version": "1.4.0", - "resolved": "https://registry.npmjs.org/smob/-/smob-1.4.0.tgz", - "integrity": "sha512-MqR3fVulhjWuRNSMydnTlweu38UhQ0HXM4buStD/S3mc/BzX3CuM9OmhyQpmtYCvoYdl5ris6TI0ZqH355Ymqg==", + "version": "1.4.1", + "resolved": "https://registry.npmjs.org/smob/-/smob-1.4.1.tgz", + "integrity": "sha512-9LK+E7Hv5R9u4g4C3p+jjLstaLe11MDsL21UpYaCNmapvMkYhqCV4A/f/3gyH8QjMyh6l68q9xC85vihY9ahMQ==", "dev": true }, "node_modules/source-map": { @@ -1246,9 +1454,9 @@ } }, "node_modules/terser": { - "version": "5.19.2", - "resolved": "https://registry.npmjs.org/terser/-/terser-5.19.2.tgz", - "integrity": "sha512-qC5+dmecKJA4cpYxRa5aVkKehYsQKc+AHeKl0Oe62aYjBL8ZA33tTljktDHJSaxxMnbI5ZYw+o/S2DxxLu8OfA==", + "version": "5.27.0", + "resolved": "https://registry.npmjs.org/terser/-/terser-5.27.0.tgz", + "integrity": "sha512-bi1HRwVRskAjheeYl291n3JC4GgO/Ty4z1nVs5AAsmonJulGxpSektecnNedrwK9C7vpvVtcX3cw00VSLt7U2A==", "dev": true, "dependencies": { "@jridgewell/source-map": "^0.3.3", diff --git a/package.json b/package.json index fc480bc..7a130db 100644 --- a/package.json +++ b/package.json @@ -1,9 +1,17 @@ { "name": "potprox", - "version": "0.7.2", + "version": "0.8.0", "description": "Approximation of computed data with empirical pair potentials", - "main": "dist/potprox.js", - "module": "dist/potprox.mjs", + "main": "./dist/potprox.js", + "module": "./dist/potprox.mjs", + "unpkg": "./dist/potprox.min.js", + "exports": { + ".": { + "import": "./dist/potprox.mjs", + "require": "./dist/potprox.cjs" + } + }, + "type": "module", "scripts": { "prepare": "husky install", "lint": "eslint src/**/*.mjs test/**/*.mjs", @@ -33,9 +41,9 @@ }, "homepage": "https://amphiluke.github.io/potprox/", "devDependencies": { - "@rollup/plugin-terser": "^0.4.3", - "eslint": "^8.45.0", - "husky": "^8.0.3", - "rollup": "^3.26.3" + "@rollup/plugin-terser": "^0.4.4", + "eslint": "^8.56.0", + "husky": "^9.0.6", + "rollup": "^4.9.6" } } diff --git a/rollup.config.mjs b/rollup.config.mjs index d34009c..5d5295f 100644 --- a/rollup.config.mjs +++ b/rollup.config.mjs @@ -1,29 +1,40 @@ +import pkg from "./package.json" with {type: "json"}; import terser from "@rollup/plugin-terser"; -import pkg from "./package.json" assert {type: "json"}; -function getConfig({format = "umd", minify = false} = {}) { - let config = { - input: "src/potprox.mjs", - output: { - file: `dist/potprox${minify ? ".min" : ""}${format === "es" ? ".mjs" : ".js"}`, - format, - name: "potprox", - banner: `/*!\n${pkg.name} v${pkg.version}\n${pkg.homepage}\n*/` - } - }; - if (minify) { - config.plugins = [ - terser({ - output: {comments: /^!/}, - }) - ]; - } - return config; -} +let config = { + input: "src/potprox.mjs", + output: { + name: "potprox", + banner: `/*!\n${pkg.name} v${pkg.version}\n${pkg.homepage}\n*/`, + }, + plugins: [ + terser({ + output: {comments: /^!/}, + }), + ], +}; export default [ - getConfig(), - getConfig({minify: true}), - getConfig({format: "es"}), - getConfig({format: "es", minify: true}) -]; \ No newline at end of file + { + input: config.input, + output: {file: "dist/potprox.mjs", format: "esm", ...config.output}, + }, + { + input: config.input, + output: {file: "dist/potprox.min.mjs", format: "esm", ...config.output}, + plugins: config.plugins, + }, + { + input: config.input, + output: {file: "dist/potprox.js", format: "umd", ...config.output}, + }, + { + input: config.input, + output: {file: "dist/potprox.min.js", format: "umd", ...config.output}, + plugins: config.plugins, + }, + { + input: config.input, + output: {file: "dist/potprox.cjs", format: "cjs", ...config.output}, + }, +]; diff --git a/src/potentials/abstract-proto.mjs b/src/potentials/abstract-proto.mjs index 8916e52..7326e73 100644 --- a/src/potentials/abstract-proto.mjs +++ b/src/potentials/abstract-proto.mjs @@ -43,4 +43,4 @@ class AbstractProto { } } -export default AbstractProto; \ No newline at end of file +export default AbstractProto; diff --git a/src/potentials/buckingham.mjs b/src/potentials/buckingham.mjs index 0f01673..b304aad 100644 --- a/src/potentials/buckingham.mjs +++ b/src/potentials/buckingham.mjs @@ -191,4 +191,4 @@ class Buckingham extends AbstractProto { } } -export default Buckingham; \ No newline at end of file +export default Buckingham; diff --git a/src/potentials/lennard-jones.mjs b/src/potentials/lennard-jones.mjs index bc6c836..85d9894 100644 --- a/src/potentials/lennard-jones.mjs +++ b/src/potentials/lennard-jones.mjs @@ -104,4 +104,4 @@ class LennardJones extends AbstractProto { } } -export default LennardJones; \ No newline at end of file +export default LennardJones; diff --git a/src/potentials/morse.mjs b/src/potentials/morse.mjs index 75f9d9a..c4b7191 100644 --- a/src/potentials/morse.mjs +++ b/src/potentials/morse.mjs @@ -185,4 +185,4 @@ class Morse extends AbstractProto { } } -export default Morse; \ No newline at end of file +export default Morse; diff --git a/src/potentials/rydberg.mjs b/src/potentials/rydberg.mjs index aa338d1..72757ac 100644 --- a/src/potentials/rydberg.mjs +++ b/src/potentials/rydberg.mjs @@ -186,4 +186,4 @@ class Rydberg extends AbstractProto { } } -export default Rydberg; \ No newline at end of file +export default Rydberg; diff --git a/src/potentials/varshni3.mjs b/src/potentials/varshni3.mjs index ac32a8b..40f1b68 100644 --- a/src/potentials/varshni3.mjs +++ b/src/potentials/varshni3.mjs @@ -185,4 +185,4 @@ class Varshni3 extends AbstractProto { } } -export default Varshni3; \ No newline at end of file +export default Varshni3; diff --git a/test/.eslintrc b/test/.eslintrc deleted file mode 100644 index 36eb708..0000000 --- a/test/.eslintrc +++ /dev/null @@ -1,5 +0,0 @@ -{ - "parserOptions": { - "ecmaVersion": 2016 - } -} \ No newline at end of file diff --git a/test/browser/datasets.js b/test/browser/datasets.js index 972cf89..954666d 100644 --- a/test/browser/datasets.js +++ b/test/browser/datasets.js @@ -12,7 +12,7 @@ self.datasets = { {r: 6.0, e: -0.03028974}, {r: 5.5, e: -0.03598181}, {r: 5.0, e: -0.03234259}, - {r: 4.5, e: 0.00189849} + {r: 4.5, e: 0.00189849}, ], morse: [ @@ -52,7 +52,7 @@ self.datasets = { {r: 4.8, e: -0.034606}, {r: 4.7, e: -0.024064}, {r: 4.6, e: -0.010401}, - {r: 4.5, e: 0.0070517} + {r: 4.5, e: 0.0070517}, ], dft1: [ @@ -75,7 +75,7 @@ self.datasets = { {r: 8.0, e: -0.0001106484301089950}, {r: 10.0, e: -0.0000510502900397114}, {r: 12.0, e: -0.0000181051000254229}, - {r: 14.0, e: 0.0000000000000000000} + {r: 14.0, e: 0.0000000000000000000}, ], dft2: [ @@ -96,6 +96,6 @@ self.datasets = { {r: 8, e: 0.000010500670214242}, {r: 10, e: 0.000003441470198595}, {r: 12, e: 0.000001319030161540}, - {r: 14, e: 0.000000000000000000} - ] + {r: 14, e: 0.000000000000000000}, + ], }; diff --git a/test/browser/ui.js b/test/browser/ui.js index 2a6e618..9ea3f69 100644 --- a/test/browser/ui.js +++ b/test/browser/ui.js @@ -27,4 +27,4 @@ }); document.getElementById("result").textContent = output; }); -})(); \ No newline at end of file +})(); diff --git a/test/browser/worker.js b/test/browser/worker.js index aa7e681..6ba9d2b 100644 --- a/test/browser/worker.js +++ b/test/browser/worker.js @@ -12,8 +12,8 @@ self.addEventListener("message", ({data = {}}) => { result[name] = { potential: potential.toJSON(), rSqr: potential.rSqr(dataset), - points: [...potential.points({start: 5, end: 10, step: (10 - 5) / 9})] + points: [...potential.points({start: 5, end: 10, step: (10 - 5) / 9})], }; }); self.postMessage({type: "recalcDone", result}); -}); \ No newline at end of file +}); diff --git a/test/helpers/potential-data.mjs b/test/helpers/potential-data.mjs index ffd3ee2..d332115 100644 --- a/test/helpers/potential-data.mjs +++ b/test/helpers/potential-data.mjs @@ -40,43 +40,43 @@ potentialData.set("ab initio", { {r: 7.7, e: -0.010867186}, {r: 7.8, e: -0.010091833}, {r: 7.9, e: -0.009378217}, - {r: 8.0, e: -0.008721082} - ] + {r: 8.0, e: -0.008721082}, + ], }); let potentialParams = { LennardJones: { epsilon: 0.06830448257027043, - sigma: 4.572601751994529 + sigma: 4.572601751994529, }, Buckingham: { d0: 0.06716628791443133, r0: 5.252617286323438, - a: 4.938464977302329 + a: 4.938464977302329, }, Morse: { d0: 0.06845835040507252, r0: 5.20478344215002, - a: 1.095112794871565 + a: 1.095112794871565, }, Rydberg: { d0: 0.06849683974115128, r0: 5.2282343210681, - b: 7.9514048075009836 + b: 7.9514048075009836, }, Varshni3: { d0: 0.06858192442230913, r0: 5.250064314946983, - b: 0.08289544848817255 - } + b: 0.08289544848817255, + }, }; Object.entries(potentialParams).forEach(([type, params]) => { let potential = new potprox[type](params); potentialData.set(type, { data: potentialData.get("ab initio").data.map(({r}) => ({r, e: potential.at(r)})), - params: potential.toJSON() + params: potential.toJSON(), }); }); -export default potentialData; \ No newline at end of file +export default potentialData; diff --git a/test/helpers/utils.mjs b/test/helpers/utils.mjs index aeb8a29..1a82812 100644 --- a/test/helpers/utils.mjs +++ b/test/helpers/utils.mjs @@ -3,7 +3,7 @@ const LIM_ERR = 10 ** Math.ceil(Math.log10(Number.EPSILON)); let utils = { equal(num1, num2) { return Math.abs(num1 - num2) < LIM_ERR; - } + }, }; -export default utils; \ No newline at end of file +export default utils; From 867c49a3f43e3ac3d1313bf5e1b8483ad43fef23 Mon Sep 17 00:00:00 2001 From: Amphiluke Date: Sat, 27 Jan 2024 20:55:33 +0700 Subject: [PATCH 2/2] Add install tests --- .husky/.gitignore | 1 - .husky/pre-commit | 3 --- package.json | 4 ++-- test/install-test/node-cjs-test.cjs | 3 +++ test/install-test/node-esm-test.mjs | 3 +++ test/install-test/package-lock.json | 22 ++++++++++++++++++++++ test/install-test/package.json | 14 ++++++++++++++ 7 files changed, 44 insertions(+), 6 deletions(-) delete mode 100644 .husky/.gitignore mode change 100755 => 100644 .husky/pre-commit create mode 100644 test/install-test/node-cjs-test.cjs create mode 100644 test/install-test/node-esm-test.mjs create mode 100644 test/install-test/package-lock.json create mode 100644 test/install-test/package.json diff --git a/.husky/.gitignore b/.husky/.gitignore deleted file mode 100644 index 31354ec..0000000 --- a/.husky/.gitignore +++ /dev/null @@ -1 +0,0 @@ -_ diff --git a/.husky/pre-commit b/.husky/pre-commit old mode 100755 new mode 100644 index 20d0d06..3867a0f --- a/.husky/pre-commit +++ b/.husky/pre-commit @@ -1,4 +1 @@ -#!/bin/sh -. "$(dirname "$0")/_/husky.sh" - npm run lint diff --git a/package.json b/package.json index 7a130db..44723cf 100644 --- a/package.json +++ b/package.json @@ -13,10 +13,10 @@ }, "type": "module", "scripts": { - "prepare": "husky install", "lint": "eslint src/**/*.mjs test/**/*.mjs", "test": "node --test test/potprox.test.mjs test/potentials/", - "build": "rollup -c" + "build": "rollup -c", + "prepare": "husky" }, "files": [ "dist", diff --git a/test/install-test/node-cjs-test.cjs b/test/install-test/node-cjs-test.cjs new file mode 100644 index 0000000..9d3132f --- /dev/null +++ b/test/install-test/node-cjs-test.cjs @@ -0,0 +1,3 @@ +let potprox = require("potprox"); + +console.dir(potprox); diff --git a/test/install-test/node-esm-test.mjs b/test/install-test/node-esm-test.mjs new file mode 100644 index 0000000..5095ecc --- /dev/null +++ b/test/install-test/node-esm-test.mjs @@ -0,0 +1,3 @@ +import * as potprox from "potprox"; + +console.dir(potprox); diff --git a/test/install-test/package-lock.json b/test/install-test/package-lock.json new file mode 100644 index 0000000..810d9dd --- /dev/null +++ b/test/install-test/package-lock.json @@ -0,0 +1,22 @@ +{ + "name": "potprox-install-test", + "version": "1.0.0", + "lockfileVersion": 3, + "requires": true, + "packages": { + "": { + "name": "potprox-install-test", + "version": "1.0.0", + "license": "MIT", + "dependencies": { + "potprox": "file:../../potprox-0.8.0.tgz" + } + }, + "node_modules/potprox": { + "version": "0.8.0", + "resolved": "file:../../potprox-0.8.0.tgz", + "integrity": "sha512-/OJE8XcSwEGmqdlkIANFt/FuYCIRc+4NuDAX1J4uI0NtkcHGvlviuYx0o3SH3b26eYDjuJ3tBQ5DPBSL/hLbfw==", + "license": "MIT" + } + } +} diff --git a/test/install-test/package.json b/test/install-test/package.json new file mode 100644 index 0000000..ab741d7 --- /dev/null +++ b/test/install-test/package.json @@ -0,0 +1,14 @@ +{ + "name": "potprox-install-test", + "version": "1.0.0", + "description": "", + "main": "index.js", + "scripts": { + "test": "echo \"Error: no test specified\" && exit 1" + }, + "author": "Amphiluke", + "license": "MIT", + "dependencies": { + "potprox": "file:../../potprox-0.8.0.tgz" + } +}