Git Product home page Git Product logo

lammps-sys's Introduction

lammps-sys

License Documentation Crates.io Version

Builds and generates Rust bindings for the C interface of LAMMPS, the Large-scale Atomic/Molecular Massively Parallel Simulator.

Usage

lammps-sys is available on crates.io! (actually seriously this time).

[dependencies]
lammps-sys = "0.6.0"

Docs

See LAMMPS' library.cpp. This is the file that bindings will be generated to.

If you just want to see the rust signatures for the bindings, you can also generate those yourself:

git clone https://github.com/ExpHP/lammps-sys
cd lammps-sys
git submodule update --init
cargo doc --open

Modes of operation

lammps-sys will first probe for a system liblammps using pkg-config, and, failing that, will build it from source. This behavior may also be configured through the RUST_LAMMPS_SOURCE environment variable.

See the following documents for additional information:

Linking a system library

See Linking a system LAMMPS library.

Building from source

See Automatically building LAMMPS from source.

Configuration

Environment variables

The following environment variables are used by lammps-sys to control the build:

  • RUST_LAMMPS_SOURCE
    • RUST_LAMMPS_SOURCE=auto: Try to link a system library, else build from source. (default)
    • RUST_LAMMPS_SOURCE=system: Always link the system lammps library (else report an error explaining why this failed)
    • RUST_LAMMPS_SOURCE=build: Always build from source

Cargo features

exceptions

Enables the following API functions by ensuring that LAMMPS_EXCEPTIONS is defined:

lammps_has_error
lammps_get_last_error_message

The system library will be skipped if it was not built with the definition.

Optional packages

There are a number of cargo features named with the prefix package-. These are in one-to-one correspondence with LAMMPS' optional features documented here. Activating the feature "package-user-misc" corresponds to supplying the cmake file with -DPKG_USER-MISC=yes, which in turn has a similar effect to running make yes-user-misc if you were to use Lammps' classic make-based build system.

You should activate features for all of the packages used directly by your crate. Unfortunately, these currently only have an effect when building LAMMPS from source (see the cautionary discussion about packages in Linking a system LAMMPS library).

Be aware that these flags are almost entirely untested, and it's possible that some of them are unusable or even produce invalid cmake flags. Please file bug reports!

Some packages such as POEMS or REAX have additional library components that must be built. lammps-sys currently does not have any special handling for these, assuming that the cmake flags take care of this. If they work for you, that's great! If not, please file an issue.

Does it work?

For an easier time diagnosing building/linking issues, you can clone this repo and try running the link-test example.

$ git clone https://github.com/ExpHP/lammps-sys
$ cd lammps-sys
$ # note: submodule update is only needed when building lammps from source
$ git submodule update --init
$ cargo run --example=link-test
LAMMPS (31 Mar 2017)
Total wall time: 0:00:00

Be sure to try this using the environment variables and --features that you plan to enable in your own project.

License

Like Lammps, lammps-sys is licensed under the (full) GNU GPL v3.0. Please see the file COPYING for more details.

Release notes

See Release notes.

Citations

S. Plimpton, Fast Parallel Algorithms for Short-Range Molecular Dynamics, J Comp Phys, 117, 1-19 (1995)

lammps-sys's People

Contributors

colin-daniels avatar exphp avatar joelgallant avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

lammps-sys's Issues

Features for gzip, png, jpeg, ffmpeg

Features could be added to require these.

They should somehow use these C API functions to validate that the functionality is present in system libraries:

int lammps_config_has_gzip_support();
int lammps_config_has_png_support();
int lammps_config_has_jpeg_support();
int lammps_config_has_ffmpeg_support();

When activated in an automatic build, they should set the corresponding cmake flags to yes.

I don't think these features should be enabled by default, for the same reasons that exceptions is not on by default. However, unlike for mpi, I believe it is okay that cmake should be allowed to enable these libraries if they are found, even without the feature. (so without the feature, we should do nothing, rather than defining WITH_JPEG=no). This is because they do not require additional effort from us to link them, given that cmake could find them. (whereas linking MPI requires querying mpicxx)

...I think. I could be wrong.


I have no need for any of this myself, so I'll leave the effort to somebody who does. ;)

v0.4.x should have the ability to use dynamic builds

This is a big reason why my own code still uses v0.3.x. I need dynamic linking for the occasional time I need to modify the LAMMPS source.

Back when I was writing 0.4.x, I briefly considered having static and dynamic flags, but chickened out. Kornelski gives some good best practices here: https://kornel.ski/rust-sys-crate

In Cargo.toml you can have [features] section with static and dynamic options.

[features]
static = []
dynamic = []

Don't put any of them as Cargo's default feature, because it's too hard to unset defaults in Cargo.

and this gives the toplevel binary crate the power to choose which to use by depending on lammps-sys and activating the appropriate feature.

Can't build from source on WSL

Trying to build using Windows Subsystem for Linux. This is odd:

image

This is even more odd:

[ exp @ 22:03:36 ] (master) /mnt/f/asd/clone/rsp2/target/debug/build/lammps-sys-e860d6dc26d88121/out/lammps
$ ls
LICENSE  README  cmake  doc  lib

Where's... where's the src directory!?


I went and tried using the cmake build system to manually build lammps, and it worked just fine, so... yeah. Uhm... something's up.

publish v0.5.0 to crates.io

v0.5.0 will be far from perfect, but I feel that, now that we have the option to choose between system libs and automatic builds, it is finally usable enough to be ready for crates.io.

use travis to test both shared linking and automatic builds

Issue #10 was able to slip by unnoticed because I had a system install of lammps when I packaged the crate. This is the kind of stuff travis is for.

The travis test for automatic builds should specifically include a call to cargo package, to make sure nothing essential from the lammps submodule is accidentally excluded.

automatic building doesn't work on packaged crate

The ./lammps/potentials/* exclude rule in Cargo.toml not only excludes the contents of the potentials directory, but it even gets rid of the directory itself!

Also, we need to keep the manpage under doc which it tries to install.

Detecting if a system installation has package enabled

Wonderful things were added to library.h in recent versions:

int lammps_config_has_package(char * package_name);
int lammps_config_package_count();
int lammps_config_package_name(int index, char * buffer, int max_size);

It would be awesome to use these somehow to validate that certain features have been enabled in a system installation of lammps. Like the exceptions feature, we could reject a system library missing these features and fall back to a source build.

lammps apparently has cmake configs

The code for building from source in the 0.4.x branch is pretty nasty, and even does stuff like editing a Makefile. I'd love to get rid of it.

It turns out that Lammps has some (tragically underadvertised!) cmake configuration files, which appear to aim to solve a great deal of the problems that lammps-sys needs to solve, and quite probably in a better manner than how lammps-sys does it. It'd be nice to be able to use those.

Incompatible with crates using newer versions of bindgen/clang-sys

There is a known issue that the current version of lammps-sys is incompatible with crates that use recent versions of bindgen or clang-sys.

This is due to problems upstream. Basically, we're waiting for a number of upstream crates to update their dependencies:

  • You cannot have multiple versions of clang-sys due to it declaring the links property.
  • libffi-sys uses an old bindgen that uses an old clang-sys
  • mpi-sys uses libffi-sys and therefore must also use an old bindgen
  • lammps-sys uses mpi-sys and therefore must also use an old bindgen

v0.4.x missing packages (yes-manybody, etc.)

Currently I can't even build 0.4.x for the potentials that I use!

At bare minimum I personally need a feature for

make yes-manybody

...but really, what I should do is find a complete listing of these packages somewhere in the LAMMPS documentation.

update to next lammps release

Currently lammps-sys depends on an unreleased master commit of LAMMPS for some bugfixes. Once LAMMPS gets another release, v0.5.0 can be released.

(for future reference, at the time of writing, the latest release is patch_5Sep2018)

detection of libs without pkg-config

I consider it suboptimal that lammps-sys only cares about pkg-config when searching for system libraries. The trouble is that a liblammps.pc file will almost never exist in PKG_CONFIG_PATH for any typical installation of LAMMPS, because this is not something people normally need to worry about (entries in LD_LIBRARY_PATH and C_INCLUDE_PATH are usually all you need!).

However, the reason that it only cares about pkg-config at the moment is because there needs to be a clear way for the build script to determine when the libraries are NOT present, so that it knows when to fall back to performing an automatic build. And I'm not sure what the right way is to do that. (is there something we can do at build-script time to determine whether an -l library would be found by the linker when invoked by rustc?)

Issues with newer LAMMPS

While trying to update the building from source guide, I tried building my own copy of LAMMPS and ran into a number of issues:

  • The use of the ptr argument to lammps_open is deprecated; the function now returns a pointer.
    • Unfortunately this makes it unclear how to fix lammps_open, which we need to define ourselves to avoid incompatibilities with how rsmpi defines MPI_Comm.
      • Thankfully, the current signature void(*) (int, **char, MPI_Comm, **void) is loosely ABI-compatible with the old signature void (int, **char, MPI_Comm, **void) in most modern calling conventions.
      • ...unfortunately I'm getting a segfault when I try to test with this.
      • There is still no update to mpi-sys
  • -DBUILD_LIB=on is no longer required`
  • Many packages were renamed or split up.
    • Here's the documented list as of 2022-03-07:
      ADIOS ASPHERE ATC AWPMD BOCS BODY BROWNIAN CG-DNA CG-SDK CLASS2 COLLOID COLVARS COMPRESS CORESHELL DIELECTRIC DIFFRACTION DIPOLE DPD-BASIC DPD-MESO DPD-REACT DPD-SMOOTH DRUDE EFF EXTRA-COMPUTE EXTRA-DUMP EXTRA-FIX EXTRA-MOLECULE EXTRA-PAIR FEP GPU GRANULAR H5MD INTEL INTERLAYER KIM KOKKOS KSPACE LATBOLTZ LATTE MACHDYN MANIFOLD MANYBODY MC MDI MEAM MESONT MESSAGE MGPT MISC ML-HDNNP ML-IAP ML-PACE ML-QUIP ML-RANN ML-SNAP MOFFF MOLECULE MOLFILE MPIIO MSCG NETCDF OPENMP OPT ORIENT PERI PHONON PLUGIN PLUMED POEMS PTM PYTHON QEQ QMMM QTB REACTION REAXFF REPLICA RIGID SCAFACOS SHOCK SMTBQ SPH SPIN SRD TALLY UEF VORONOI VTK YAFF
  • Virtually any update related to any of this is going to require adding CI Testing on a matrix of MPI/no-MPI, system/build, and a small number of "tested" lammps versions, because it's beyond the point where I have the bandwidth to test all of this.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.