{"id":15384661,"url":"https://github.com/amphiluke/potprox","last_synced_at":"2026-02-16T17:02:24.596Z","repository":{"id":20624444,"uuid":"90457834","full_name":"Amphiluke/potprox","owner":"Amphiluke","description":"Approximation of computed data with empirical pair potentials","archived":false,"fork":false,"pushed_at":"2025-03-01T16:32:43.000Z","size":933,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-04-09T23:09:33.886Z","etag":null,"topics":["approximation","buckingham","lennard-jones","morse","potential","rydberg"],"latest_commit_sha":null,"homepage":"https://amphiluke.github.io/potprox/","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/Amphiluke.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2017-05-06T11:20:16.000Z","updated_at":"2024-09-27T07:50:59.000Z","dependencies_parsed_at":"2024-09-30T08:40:27.282Z","dependency_job_id":null,"html_url":"https://github.com/Amphiluke/potprox","commit_stats":{"total_commits":62,"total_committers":2,"mean_commits":31.0,"dds":"0.016129032258064502","last_synced_commit":"767a9358bfbb8e8599c674dbdba0124b0c8b386d"},"previous_names":[],"tags_count":13,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Amphiluke%2Fpotprox","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Amphiluke%2Fpotprox/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Amphiluke%2Fpotprox/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Amphiluke%2Fpotprox/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Amphiluke","download_url":"https://codeload.github.com/Amphiluke/potprox/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":249140869,"owners_count":21219379,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["approximation","buckingham","lennard-jones","morse","potential","rydberg"],"created_at":"2024-10-01T14:43:00.985Z","updated_at":"2026-02-16T17:02:24.565Z","avatar_url":"https://github.com/Amphiluke.png","language":"JavaScript","readme":"[![Build and test](https://github.com/Amphiluke/potprox/actions/workflows/build-and-test.yml/badge.svg?branch=master)](https://github.com/Amphiluke/potprox/actions/workflows/build-and-test.yml)\n\n# potprox\n\nApproximation of computed data with empirical pair potentials.\n\n## Synopsis\n\nIt is a quite common case when there is a need to describe computed numerical *ab initio* data with some analytical form of pair potential (e.g. the [Lennard-Jones function](https://en.wikipedia.org/wiki/Lennard-Jones_potential) or the [Morse function](https://en.wikipedia.org/wiki/Morse_potential)).\n\nPotprox uses the [method of least squares](https://en.wikipedia.org/wiki/Least_squares) to approximate computed data with empirical pair potentials. The list of currently available potentials includes\n\n* [The Lennard-Jones potential](#the-potproxlennardjones-class)\n* [The modified Buckingham potential](#the-potproxbuckingham-class) (the exp-6 potential)\n* [The Morse potential](#the-potproxmorse-class)\n* [The Rydberg potential](#the-potproxrydberg-class)\n* [The Varshni potential (III)](#the-potproxvarshni3-class)\n\n## Install and load potprox\n\n### As a Node.js module\n\nInstalling the package:\n\n```shell\nnpm install potprox\n```\n\nImporting the module:\n\n```javascript\nimport * as potprox from \"potprox\";\n```\n\nor (for CommonJS modules)\n\n```javascript\nlet potprox = require(\"potprox\");\n```\n\nIf you need only a few potential classes, using named import will allow module bundlers to perform “tree shaking” and exclude the rest unused code.\n\n```javascript\nimport {Morse, Rydberg} from \"potprox\";\n```\n\n### In browsers\n\nThe module can be loaded from the popular CDNs like unpkg or jsDelivr.\n\n```html\n\u003cscript src=\"https://cdn.jsdelivr.net/npm/potprox/dist/potprox.min.js\"\u003e\u003c/script\u003e\n```\n\nIf you use ES modules, you may import the potprox module from the [potprox.min.mjs](dist/potprox.min.mjs) file:\n\n```javascript\nimport * as potprox from \"https://cdn.jsdelivr.net/npm/potprox/dist/potprox.min.mjs\";\n```\n\n### In web workers\n\n```javascript\nimportScripts(\"https://www.unpkg.com/potprox\");\n```\n\n## Usage\n\nHere is an example of approximation of some external computational data using the potprox module.\n\n```javascript\nimport * as potprox from \"potprox\";\n\n// Computed numerical data on energy of interatomic binding\n// r - interatomic distance\n// e - binding energy\nlet data = [\n    {r: 10.0, e: 0},\n    {r: 9.5, e: -0.00065673},\n    {r: 9.0, e: -0.00173718},\n    {r: 8.5, e: -0.00346348},\n    {r: 8.0, e: -0.00612669},\n    {r: 7.5, e: -0.01005967},\n    {r: 7.0, e: -0.01554171},\n    {r: 6.5, e: -0.02256036},\n    {r: 6.0, e: -0.03028974},\n    {r: 5.5, e: -0.03598181},\n    {r: 5.0, e: -0.03234259},\n    {r: 4.5, e: 0.00189849},\n];\n\n// Approximate with the Lennard-Jones potential\nlet lennardjones = potprox.LennardJones.from(data);\nconsole.log(\"Lennard-Jones potential info:\", lennardjones.toJSON());\n\n// Approximate with the exp-6 potential\nlet buckingham = potprox.Buckingham.from(data);\nconsole.log(\"Buckingham potential info:\", buckingham.toJSON());\n\n// Approximate with the Morse potential\nlet morse = potprox.Morse.from(data);\nconsole.log(\"Morse potential info:\", morse.toJSON());\n\n// Approximate with the Rydberg potential\nlet rydberg = potprox.Rydberg.from(data);\nconsole.log(\"Rydberg potential info:\", rydberg.toJSON());\n\n// Approximate with the Varshni potential (III)\nlet varshni = potprox.Varshni3.from(data);\nconsole.log(\"Varshni potential (III) info:\", varshni.toJSON());\n```\n\n## API\n\n### The `potprox` object\n\nThe potprox module exports an object with potential names as keys and potential classes as values.\n\n```javascript\nconsole.log(potprox); // =\u003e Object {LennardJones: \u003cclass\u003e, Buckingham: \u003cclass\u003e, ...}\n```\n\n### The `potprox.LennardJones` class\n\nAn instance of the `LennardJones` class represents the Lennard-Jones potential with the given parameters `epsilon` and `sigma`.\n\n$$V\\left(r\\right)=4\\varepsilon\\left[\\left(\\frac{\\sigma}{r}\\right)^{12}-\\left(\\frac{\\sigma}{r}\\right)^6\\right]$$\n\nYou may instantiate the `LennardJones` class as follows:\n\n```javascript\nlet lennardjones = new potprox.LennardJones({epsilon: 0.041, sigma: 4.5});\n```\n\n### The `potprox.Buckingham` class\n\nAn instance of the `Buckingham` class represents the modified Buckingham potential (the exp-6 potential) with the given parameters `d0`, `r0`, and `a` (which are often referenced to as *ε*, *r\u003csub\u003em\u003c/sub\u003e*, and *α* respectively).\n\n$$V\\left(r\\right)=\\frac{D_0}{1-6/a}\\left(\\frac{6}{a}\\exp\\left[a\\left(1-\\frac{r}{r_0}\\right)\\right]-\\left(\\frac{r_0}{r}\\right)^6\\right)$$\n\nYou may instantiate the `Buckingham` class as follows:\n\n```javascript\nlet buckingham = new potprox.Buckingham({d0: 0.0360, r0: 5.298, a: 4.332});\n```\n\n### The `potprox.Morse` class\n\nAn instance of the `Morse` class represents the Morse potential with the given parameters `d0`, `r0`, and `a` (which are often referenced to as *D\u003csub\u003ee\u003c/sub\u003e*, *r\u003csub\u003ee\u003c/sub\u003e*, and *α* respectively).\n\n$$V\\left(r\\right)=-D_0+D_0\\left[1-\\exp\\left(-a\\left(r-r_0\\right)\\right)\\right]^2$$\n\nYou may instantiate the `Morse` class as follows:\n\n```javascript\nlet morse = new potprox.Morse({d0: 0.0368, r0: 5.316, a: 0.867});\n```\n\n### The `potprox.Rydberg` class\n\nAn instance of the `Rydberg` class represents the Rydberg potential with the given parameters `d0`, `r0`, and `b`.\n\n$$V\\left(r\\right)=-D_0\\left[1+\\frac{b}{r_0}\\left(r-r_0\\right)\\right]\\exp\\left[-\\frac{b}{r_0}\\left(r-r_0\\right)\\right]$$\n\nYou may instantiate the `Rydberg` class as follows:\n\n```javascript\nlet rydberg = new potprox.Rydberg({d0: 0.0368, r0: 5.350, b: 6.415});\n```\n\n### The `potprox.Varshni3` class\n\nAn instance of the `Varshni3` class represents the Varshni potential (III) with the given parameters `d0`, `r0`, and `b`.\n\n$$V\\left(r\\right)=-D_0+D_0\\left[1-\\frac{r_0}{r}\\exp\\left(-b\\left(r^2-r_0^2\\right)\\right)\\right]^2$$\n\nYou may instantiate the `Varshni3` class as follows:\n\n```javascript\nlet varshni = new potprox.Varshni3({d0: 0.0368, r0: 5.389, b: 0.0597});\n```\n\n### Potential class members\n\nAll the classes in the `potprox` object have a few members listed below.\n\n#### `type`\n\nThe *static* read-only property containing the name of the potential class (e.g. `\"LennardJones\"`, `\"Morse\"`, `\"Buckingham\"` etc.).\n\n```javascript\nconsole.log(potprox.LennardJones.type); // =\u003e \"LennardJones\"\n```\n\n#### `from(data [, settings])`\n\nThe *static* method `from` creates an instance of the specific class with potential parameters obtained via the least squares approximation procedure.\n\nThe first (required) argument is input approximated data, an array of objects `{r: Number, e: Number}`, where `r` is an interatomic distance, and `e` is the corresponding binding energy. Refer the [Usage](#usage) section for an example.\n\nThe second (optional) argument can be specified to override approximation settings. Thus in order to get better approximation results you may decrease convergence limits by specifying custom convergence factors for all or some potential parameters.\n\n```javascript\nlet morse = potprox.Morse.from(data, {d0Conv: 0.0001, r0Conv: 0.0001, aConv: 0.0001});\nlet rydberg = potprox.Rydberg.from(data, {b0Conv: 0.0001});\n```\n\nBe careful though when using too small convergence factors as this may end up with performance issues. Consider using web workers if you need high-accuracy approximation but things appear to get slow.\n\n#### `at(r)`\n\nCalculates the value of the potential for the given interatomic distance.\n\n```javascript\nlet lennardjones = new potprox.LennardJones({epsilon: 0.041, sigma: 4.5});\nconsole.log(lennardjones.at(6.0)); // =\u003e -0.02399355483055115\n\nlet buckingham = new potprox.Buckingham({d0: 0.0360, r0: 5.298, a: 4.332});\nconsole.log(buckingham.at(6.0)); // =\u003e -0.028625141782941267\n\nlet morse = new potprox.Morse({d0: 0.0368, r0: 5.316, a: 0.867});\nconsole.log(morse.at(6.0)); // =\u003e -0.029435553046279185\n\nlet rydberg = new potprox.Rydberg({d0: 0.0368, r0: 5.350, b: 6.415});\nconsole.log(rydberg.at(6.0)); // =\u003e -0.030035419908893232\n\nlet varshni = new potprox.Varshni3({d0: 0.0368, r0: 5.389, b: 0.0597});\nconsole.log(varshni.at(6.0)); // =\u003e -0.03069928686072358\n```\n\n#### `points([options])`\n\nThe method `points` can be used to generate points of a potential function in the given distance range. The method takes one optional argument and returns a [Generator object](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Generator) which you may iterate over. The optional parameter of the method is the configuration object. The following configuration options are available (each of them is optional):\n\n* `start` — starting interatomic distance to generate points from (by default it’s set to a half of the equilibrium distance);\n* `end` — end interatomic distance where to stop (by default it’s double of the equilibrium distance);\n* `step` — step for point generation (default step is configured to generate 50 points).\n\n```javascript\nlet morse = new potprox.Morse({d0: 0.0368, r0: 5.316, a: 0.867});\n\n// Generate 50 points starting from r = r0/2 and finishing at r = 2*r0\nfor (let {r, e, index} of morse.points()) {\n    console.log(`${index + 1}. r = ${r.toFixed(4)} nm; E = ${e.toFixed(3)} eV`);\n}\n\n// Generate 30 points in the user-defined distance range\nlet start = 5.0;\nlet end = 8.5;\nlet pointCount = 30;\nlet step = (end - start) / (pointCount - 1);\nfor (let {r, e, index} of morse.points({start, end, step})) {\n    console.log(`${index + 1}. r = ${r.toFixed(4)} nm; E = ${e.toFixed(3)} eV`);\n}\n\n// Generate points infinitely until the given energy threshold is reached\nfor (let {r, e, index} of morse.points({start: 5.0, end: Infinity, step: 0.1})) {\n    console.log(`${index + 1}. r = ${r.toFixed(4)} nm; E = ${e.toFixed(5)} eV`);\n    if (e \u003e -0.001) {\n        break;\n    }\n}\n```\n\n#### `rSqr(data)`\n\nUse the method `rSqr` to calculate the [coefficient of determination](https://en.wikipedia.org/wiki/Coefficient_of_determination) _R²_, a measure of goodness of fit. The method takes the initial data array as an argument (same as that passed to the [`from` method](#fromdata--settings)).\n\n```javascript\nlet morse = potprox.Morse.from(data);\nlet rSqr = morse.rSqr(data);\nconsole.log(`Coefficient of determination = ${rSqr}`);\n```\n\n#### `toJSON()`\n\nReturns an object containing information on the potential. This information is enough to restore the potential instance form a serializable JSON object (see the [Tips](#tips) section for details).\n\n```javascript\nlet lennardjones = new potprox.LennardJones({epsilon: 0.041, sigma: 4.5});\nconsole.log(lennardjones.toJSON()); // =\u003e {type: \"LennardJones\", epsilon: 0.041, sigma: 4.5}\n\nlet buckingham = new potprox.Buckingham({d0: 0.0360, r0: 5.298, a: 4.332});\nconsole.log(buckingham.toJSON()); // =\u003e {type: \"Buckingham\", d0: 0.036, r0: 5.298, a: 4.332}\n\nlet morse = new potprox.Morse({d0: 0.0368, r0: 5.316, a: 0.867});\nconsole.log(morse.toJSON()); // =\u003e {type: \"Morse\", d0: 0.0368, r0: 5.316, a: 0.867}\n\nlet rydberg = new potprox.Rydberg({d0: 0.0368, r0: 5.350, b: 6.415});\nconsole.log(rydberg.toJSON()); // =\u003e {type: \"Rydberg\", d0: 0.0368, r0: 5.350, b: 6.415}\n\nlet varshni = new potprox.Varshni3({d0: 0.0368, r0: 5.389, b: 0.0597});\nconsole.log(varshni.toJSON()); // =\u003e {type: \"Varshni3\", d0: 0.0368, r0: 5.389, b: 0.0597}\n```\n\nNote that the potential parameters are also available as direct instance properties, and you may change them at any time.\n\n## Tips\n\nThe overridden method `toJSON()` allows the instances of the potprox potential classes to be easily serialized to a JSON string, and restored from the JSON string later on.\n\n```javascript\n// Create and serialize\nlet morse = new potprox.Morse({d0: 0.0368, r0: 5.316, a: 0.867});\nlet json = JSON.stringify(morse);\n\n// Unserialize and restore\nlet potentialData = JSON.parse(json);\nlet morseCopy = new potprox[potentialData.type](potentialData);\n```\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Famphiluke%2Fpotprox","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Famphiluke%2Fpotprox","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Famphiluke%2Fpotprox/lists"}