npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

@peterspackman/mlip.js

v0.1.0

Published

JavaScript/WebAssembly bindings for mlipcpp - Machine Learning Interatomic Potentials

Readme

mlip.js

JavaScript/WebAssembly bindings for mlipcpp - Machine Learning Interatomic Potentials.

Run ML potentials (PET, MACE, etc.) directly in the browser or Node.js with no native dependencies.

Installation

npm install @mlipcpp/mlip.js

Usage

Browser (ES6 Modules)

<!DOCTYPE html>
<html>
<head>
    <script type="module">
        import createMlip from '@mlipcpp/mlip.js';

        async function main() {
            const Module = await createMlip();

            // Load a model (must be fetched and provided as ArrayBuffer)
            const response = await fetch('pet-mad.gguf');
            const modelBuffer = await response.arrayBuffer();
            const model = Module.Model.loadFromBuffer(modelBuffer);

            console.log('Model type:', model.modelType());
            console.log('Cutoff:', model.cutoff(), 'Å');

            // Create a water molecule
            const positions = new Float64Array([
                0.0, 0.0, 0.117,   // O
                0.0, 0.757, -0.469, // H
                0.0, -0.757, -0.469 // H
            ]);
            const atomicNumbers = new Int32Array([8, 1, 1]);

            const water = Module.AtomicSystem.create(
                positions,
                atomicNumbers,
                null,  // no cell
                false  // not periodic
            );

            // Predict energy and forces
            const result = model.predict(water);
            console.log('Energy:', result.energy, 'eV');
            console.log('Forces:', result.forces);
        }

        main();
    </script>
</head>
<body>
    <h1>mlip.js Demo</h1>
</body>
</html>

Node.js

import createMlip from '@mlipcpp/mlip.js';
import fs from 'fs';

async function main() {
    const Module = await createMlip();

    // Load model from file
    const modelBuffer = fs.readFileSync('pet-mad.gguf');
    const model = Module.Model.loadFromBuffer(modelBuffer.buffer);

    console.log('Model loaded:', model.modelType());

    // Create system from XYZ string
    const xyzString = `3
Water molecule
O  0.0  0.0  0.117
H  0.0  0.757  -0.469
H  0.0  -0.757  -0.469
`;

    const system = Module.AtomicSystem.fromXyzString(xyzString);
    console.log('Atoms:', system.numAtoms());

    // Get energy only (faster)
    const energy = model.predictEnergy(system);
    console.log('Energy:', energy, 'eV');

    // Get energy and forces
    const result = model.predict(system);
    console.log('Forces (eV/Å):');
    for (let i = 0; i < system.numAtoms(); i++) {
        console.log(`  Atom ${i}: [${result.forces[i*3]}, ${result.forces[i*3+1]}, ${result.forces[i*3+2]}]`);
    }
}

main();

Periodic Systems

// Silicon crystal
const positions = new Float64Array([
    0.0, 0.0, 0.0,
    1.3575, 1.3575, 1.3575
]);
const atomicNumbers = new Int32Array([14, 14]);

// Cell vectors (row-major, Å)
const cell = new Float64Array([
    5.43, 0.0, 0.0,
    0.0, 5.43, 0.0,
    0.0, 0.0, 5.43
]);

const silicon = Module.AtomicSystem.create(
    positions,
    atomicNumbers,
    cell,
    true  // periodic
);

const result = model.predict(silicon);
console.log('Energy:', result.energy, 'eV');
console.log('Stress (Voigt):', result.stress); // [xx, yy, zz, yz, xz, xy]

API Reference

Module Functions

  • getVersion() - Returns mlipcpp version string

AtomicSystem

Represents an atomic configuration.

Static Methods

  • AtomicSystem.create(positions, atomicNumbers, cell, periodic) - Create from arrays

    • positions: Float64Array - Flattened [x0,y0,z0, x1,y1,z1, ...] in Ångstroms
    • atomicNumbers: Int32Array - Atomic numbers [Z0, Z1, ...]
    • cell: Float64Array or null - 3x3 cell matrix (row-major) or null for non-periodic
    • periodic: boolean - Whether the system is periodic
  • AtomicSystem.fromXyzString(xyzContent) - Parse XYZ format string

Instance Methods

  • numAtoms() - Number of atoms
  • isPeriodic() - Whether system is periodic
  • getPositions() - Get positions as Float64Array
  • getAtomicNumbers() - Get atomic numbers as Int32Array
  • getCell() - Get cell as Float64Array or null

Model

Machine learning potential model.

Static Methods

  • Model.load(path) - Load from file path (Emscripten VFS)
  • Model.loadFromBuffer(arrayBuffer) - Load from ArrayBuffer

Instance Methods

  • modelType() - Model architecture name (e.g., "PET")
  • cutoff() - Interaction cutoff radius in Ångstroms
  • isLoaded() - Whether model is loaded
  • predictEnergy(system) - Predict energy only (faster)
  • predict(system) - Predict energy, forces, and stress (if periodic)

Returns object with:

  • energy: Total energy in eV
  • forces: Float64Array of forces in eV/Å
  • stress: Float64Array of stress in Voigt notation (periodic only)

Supported Models

  • PET (Pretrained Equivariant Transformer)
  • More coming soon (MACE, etc.)

Models must be in GGUF format. See mlipcpp documentation for model conversion.

Performance

WebAssembly runs ~2-3x slower than native code. For large systems or many evaluations, consider using the native mlipcpp library.

Building from Source

# Install Emscripten SDK
git clone https://github.com/emscripten-core/emsdk.git
cd emsdk && ./emsdk install latest && ./emsdk activate latest
source emsdk_env.sh

# Build WASM
cd mlipcpp
./scripts/build_wasm.sh

# Build npm package
cd packages/mlip.js
npm install
npm run build

License

BSD-3-Clause - see LICENSE