{"id":46061877,"url":"https://github.com/ajz34/libcint-rs","last_synced_at":"2026-04-16T15:01:29.858Z","repository":{"id":299388356,"uuid":"1002704546","full_name":"ajz34/libcint-rs","owner":"ajz34","description":"Rust FFI and wrapper of libcint, a GTO electronic integral engine (C language).","archived":false,"fork":false,"pushed_at":"2025-12-15T03:45:56.000Z","size":980,"stargazers_count":5,"open_issues_count":0,"forks_count":0,"subscribers_count":0,"default_branch":"main","last_synced_at":"2026-03-01T13:40:43.679Z","etag":null,"topics":["computational-chemistry","electronic-structure","rust"],"latest_commit_sha":null,"homepage":"https://docs.rs/libcint","language":"C","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/ajz34.png","metadata":{"files":{"readme":"readme.md","changelog":"CHANGELOG","contributing":null,"funding":null,"license":null,"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,"zenodo":null,"notice":null,"maintainers":null,"copyright":null,"agents":null,"dco":null,"cla":null}},"created_at":"2025-06-16T02:29:36.000Z","updated_at":"2026-02-26T06:40:15.000Z","dependencies_parsed_at":"2025-06-16T10:17:00.891Z","dependency_job_id":"663677ca-bd42-4c11-af88-e9021b82a917","html_url":"https://github.com/ajz34/libcint-rs","commit_stats":null,"previous_names":["ajz34/libcint-rs"],"tags_count":24,"template":false,"template_full_name":null,"purl":"pkg:github/ajz34/libcint-rs","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ajz34%2Flibcint-rs","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ajz34%2Flibcint-rs/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ajz34%2Flibcint-rs/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ajz34%2Flibcint-rs/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/ajz34","download_url":"https://codeload.github.com/ajz34/libcint-rs/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ajz34%2Flibcint-rs/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":31891038,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-04-16T11:36:10.202Z","status":"ssl_error","status_checked_at":"2026-04-16T11:36:09.652Z","response_time":69,"last_error":"SSL_connect returned=1 errno=0 peeraddr=140.82.121.5:443 state=error: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"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":["computational-chemistry","electronic-structure","rust"],"created_at":"2026-03-01T11:32:07.814Z","updated_at":"2026-04-16T15:01:29.785Z","avatar_url":"https://github.com/ajz34.png","language":"C","funding_links":[],"categories":[],"sub_categories":[],"readme":"# libcint FFI Bindings and Wrapper\n\nThis project contains libcint (C language) FFI bindings, wrapper and build-from-source.\n\n[libcint](https://github.com/sunqm/libcint) is a C library for GTO (gaussian-type orbital) electronic integral, can be applied in computational chemistry, and has already been applied extensively in [PySCF](https://github.com/pyscf/pyscf).\n\n| Resources | Badges |\n|--|--|\n| Crate | [![Crate](https://img.shields.io/crates/v/libcint.svg)](https://crates.io/crates/libcint) |\n| API Document | [![API Documentation](https://docs.rs/libcint/badge.svg)](https://docs.rs/libcint) |\n| FFI Binding (libcint) | [v6.1.2](https://github.com/sunqm/libcint/tree/v6.1.2) |\n| FFI Binding (qcint) | [v6.1.2](https://github.com/sunqm/qcint/tree/v6.1.2) |\n| ECP Source Code (PySCF) | [v2.9.0](https://github.com/pyscf/pyscf/tree/v2.9.0) |\n\nThis crate is not official bindgen project, neither [libcint](https://github.com/sunqm/libcint), [PySCF](https://github.com/pyscf/pyscf), nor [REST](https://gitee.com/RESTGroup/rest). It is originally intended to be some pioneer work for possible future development of [rest_libcint](https://gitee.com/RESTGroup/rest_libcint) wrapper.\n\n## Minimal Example\n\nThe most important function is [`CInt::integrate`](https://docs.rs/libcint/latest/libcint/cint/struct.CInt.html#method.integrate) and [`CInt::integrate_row_major`](https://docs.rs/libcint/latest/libcint/cint/struct.CInt.html#method.integrate_row_major). It is somehow similar to PySCF's `mol.intor(intor, aosym, shls_slice)`, but the user shall check output shape and strides. For more information on usage of crate `libcint`, we refer to [API Documentation](https://docs.rs/libcint).\n\n```rust\nuse libcint::prelude::*;\n\n// This is for testing and development purpose only.\n// For actual usage, you should initialize `CInt` with your own molecule data.\nlet cint_data: CInt = init_h2o_def2_tzvp();\n\n// int1e_ipkin: the integral of kinetic energy operator with derivative on the first orbital\n\n// [mu, nu, comp], column-major, same data memory layout to PySCF's 2/3-center intor\nlet (out, shape): (Vec\u003cf64\u003e, Vec\u003cusize\u003e) = cint_data.integrate(\"int1e_ipkin\", None, None).into();\nassert_eq!(shape, [43, 43, 3]);\n\n// [comp, mu, nu], row-major, same shape to PySCF intor\nlet (out, shape): (Vec\u003cf64\u003e, Vec\u003cusize\u003e) = cint_data.integrate_row_major(\"int1e_ipkin\", None, None).into();\nassert_eq!(shape, [3, 43, 43]);\n```\n\n## Installation and Cargo Features\n\n### Install with pre-compiled `libcint.so` (recommended)\n\nIf you have already compiled `libcint.so`, then put path of this shared library in `CINT_DIR` or `LD_LIBRARY_PATH` (or `REST_EXT_DIR`). Then you just use this library in your `Cargo.toml` file by\n\n```toml\n[dependencies]\nlibcint = { version = \"0.1\" }\n```\n\n### Install and also build-from-source\n\nIf you have not compiled `libcint.so` or `libcint.a`, then you are suggested to use this library by specifying some cargo features:\n\n```toml\n[dependencies]\nlibcint = { version = \"0.1\", features = [\"build_from_source\", \"static\"] }\n```\n\nThe source code will be automatically downloaded from github, and cargo will handle the building process.\n\nIf access to github is not available, you can use environment variable `CINT_SRC` to specify source mirror of [sunqm/libcint](https://github.com/sunqm/libcint) or [sunqm/qcint](https://github.com/sunqm/qcint).\n\n### Cargo features\n\n- Default features: None of any listed below (use library provided by system or user, using [sunqm/libcint](https://github.com/sunqm/libcint), dynamic linking, without F12 and 4c1e support).\n- `build_from_source`: Trigger of C language library libcint building. This performs by CMake; source code will be automatically downloaded from github (if environment variable `CINT_SRC` not specified).\n- `static`: Use static library for linking. This will require static link `libcint.a`, and dynamic link `libquadmath.so`.\n- `qcint`: Use [sunqm/qcint](https://github.com/sunqm/qcint) instead of [sunqm/libcint](https://github.com/sunqm/libcint). Some integrals will not be available if `qcint` does not supports that. This will also change URL source if cargo feature `build_from_source` specified.\n- `with_f12`: Whether F12 integrals (`int2e_stg`, `int2e_yp`, etc.) are supported.\n- `with_4c1e`: Whether 4c1e integrals (`int4c1e`, etc.) are supported.\n- `no_linkage`: Disable automatic linkage of `libcint` in `build.rs`. By default, this crate will not activate this feature and handle linkage properly. This feature is useful when you want to link `libcint` manually or use `libcint` in a different way (probably beneficial to conda, @jeanwsr). However, notice that ECP part will still be built anyway, which will require `libcint` to be linked properly by your self.\n\n### Shell environment variables\n\n- `CINT_DIR`, `LD_LIBRARY_PATH`, `REST_EXT_DIR`: Your compiled library path of `libcint.so` and `libcint.a`. This crate will try to find if this library is in directory root, or `directory_root/lib`. May override the library built by cargo feature `build_from_source`.\n- `CINT_SRC`: Source of libcint or qcint (must be a git repository). Only works with cargo feature `build_from_source`.\n- `CINT_VIR`: Version of libcint or qcint (e.g. `v6.1.2`, must starts with `v` prefix). Only works with cargo feature `build_from_source`.\n\n## 50 lines RHF with Rust\n\nThis is a full example code to compute the RHF/def2-TZVP energy of H2O molecule, using\n- This crate, `libcint`, as electronic integral library (corresponding to some parts of `pyscf.gto`);\n- [RSTSR](https://github.com/RESTGroup/rstsr) as tensor library (corresponding to NumPy and SciPy).\n\nYou will see that except for import and preparation, the **code with core algorithms is 27 lines** (see also directory [examples/h2o_rhf](examples/h2o_rhf)). For comparison, the **same code in Python is 23 lines** (see also [pyscf_h2o_rhf.py](libcint/scripts/pyscf_h2o_rhf.py)).\n\n```rust\nuse libcint::prelude::*;\nuse rstsr::prelude::*;\n\npub type Tsr = Tensor\u003cf64, DeviceBLAS\u003e;\npub type TsrView\u003c'a\u003e = TensorView\u003c'a, f64, DeviceBLAS\u003e;\n\n/// Obtain integrals (in row-major, same to PySCF but reverse of libcint)\npub fn intor_row_major(cint_data: \u0026CInt, intor: \u0026str) -\u003e Tsr {\n    // use up all rayon available threads for tensor operations\n    let device = DeviceBLAS::default();\n    // intor, \"s1\", full_shls_slice\n    let (out, shape) = cint_data.integrate(intor, None, None).into();\n    // row-major by transposition of col-major shape\n    rt::asarray((out, shape.f(), \u0026device)).into_reverse_axes()\n}\n\nfn main() {\n    let device = DeviceBLAS::default();\n    // Assuming H2O/def2-TZVP data for `CInt` has been prepared\n    let cint_data = init_h2o_def2_tzvp();\n\n    /* #region rhf total energy algorithms */\n    let atom_coords = {\n        let coords = cint_data.atom_coords();\n        let coords = coords.into_iter().flatten().collect::\u003cVec\u003cf64\u003e\u003e();\n        rt::asarray((coords, \u0026device)).into_shape((-1, 3))\n    };\n    let atom_charges = rt::asarray((cint_data.atom_charges(), \u0026device));\n    let mut dist = rt::sci::cdist((atom_coords.view(), atom_coords.view()));\n    dist.diagonal_mut(None).fill(f64::INFINITY);\n    let eng_nuc = 0.5 * (\u0026atom_charges * atom_charges.i((.., None)) / dist).sum();\n    println!(\"Nuclear repulsion energy: {eng_nuc}\");\n\n    let hcore = intor_row_major(\u0026cint_data, \"int1e_kin\") + intor_row_major(\u0026cint_data, \"int1e_nuc\");\n    let ovlp = intor_row_major(\u0026cint_data, \"int1e_ovlp\");\n    let int2e = intor_row_major(\u0026cint_data, \"int2e\");\n    let nocc = 5; // hardcoded for H2O, 5 occupied orbitals\n\n    let mut dm = ovlp.zeros_like();\n    for _ in 0..40 {\n        // hardcoded SCF iterations\n        let fock = \u0026hcore + ((1.0_f64 * \u0026int2e - 0.5_f64 * int2e.swapaxes(1, 2)) * \u0026dm).sum_axes([-1, -2]);\n        let (_, c) = rt::linalg::eigh((\u0026fock, \u0026ovlp)).into();\n        dm = 2.0_f64 * c.i((.., ..nocc)) % c.i((.., ..nocc)).t();\n    }\n    let eng_scratch = \u0026hcore + ((0.5_f64 * \u0026int2e - 0.25_f64 * int2e.swapaxes(1, 2)) * \u0026dm).sum_axes([-1, -2]);\n    let eng_elec = (dm * \u0026eng_scratch).sum();\n    println!(\"Total elec energy: {eng_elec}\");\n    println!(\"Total RHF energy: {}\", eng_nuc + eng_elec);\n    /* #endregion */\n}\n```\n\n## License\n\nThis repository is licensed under Apache-2.0, the same to PySCF and REST.\n\n- ECP part of code is directly copied and slightly modified from PySCF.\n- Code for filling shell blocks of integrals is modified from an early version of rest_libcint.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fajz34%2Flibcint-rs","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fajz34%2Flibcint-rs","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fajz34%2Flibcint-rs/lists"}