libmwfn
A flexible .mwfn format handler
Overview
mwfn is a text file format for gaussian-based wavefunctions of molecules and solids (described here).
This library, libmwfn, is a flexible handler of the mwfn format.
With libmwfn, the users are able to manipulate gaussian-based wavefunctions on their demand.
libmwfn is written in C++ and provides Python interface by pybind11.
The motive of this library is my need for a tool to deal with wavefunction files in my other two projects, Chinium and Orbaplaw, written in C++ and Python, respectively.
Installation
Prerequisites
- A C++ compiler that supports C++20 standard
- GNU
makeandEigen3for C++ setuptoolsandpybind11for Python
C++
- Obtain the source code via
git cloneing the repository orwgeting the latest release. - Specify the C++ compiler and the
Eigen3directory inmakefile. - Build the library with
make -j[N]and you will find the newly created directoriesinclude/andlib/. - Tryout. (Reading in an existent file
test.mwfnand exporting its information to anothertest_new.mwfn)
// test.cpp
#include <libmwfn.h>
int main(){
Mwfn mwfn("test.mwfn");
mwfn.Export("test_new.mwfn");
return 0;
}
// end of test.cpp
$ gcc test.cpp -I$(LIBMWFN)/include/ -L$(LIBMWFN)/lib/ -lmwfn # or -l:libmwfn.a
Python
- Install via pip.
$ pip install libmwfn
- Tryout. (Reading in an existent file
test.mwfnand exporting its information to anothertest_new.mwfn)
$ python
>>> import libmwfn as lm
>>> mwfn = lm.Mwfn("test.mwfn")
>>> mwfn.Export("test_new.mwfn")
Usage
Here is a typical procedure to deal with wavefunctions in libmwfn.
Ab initio quantum chemistry computation
A wavefunction file given by an ab initio calculation is needed.
This can be done by a variety of computational chemistry packages.
Here we use Gaussian 16 as an example.
! Gaussian input file
%nprocshared=40
%mem=60GB
%chk=job.chk
# b3lyp 6-31g(d) 5d 7f
Title Card Required
0 1
[Geometry]
Converting wavefunction file
The resultant wavefunction is stored in job.chk, an chk format file which is not supported by libmwfn.
We need to transform job.chk to fchk with formchk and then to mwfn format with Multiwfn.
$ # Shell
$ formchk job.chk # Now we have job.fchk
$ Multiwfn job.fchk
100 # Other functions (Part 1)
2 # Export various files (mwfn/pdb/xyz/wfn/wfx/molden/fch/47/mkl...) or generate input file of quantum chemistry programs
32 # Output current wavefunction as .mwfn file
# Default name: job.mwfn
2 # Export wavefunction, density matrix and overlap matrix
0 # Return
q # Exit Multiwfn.
Now we have job.mwfn.
Wavefunction processing
- Loading the
libmwfnmodule.
// C++
#include <libmwfn.h>
# Python
import libmwfn as lm
- Reading and exporting wavefunction information from
job.mwfntojob_new.mwfn.
// C++
Mwfn job_mwfn("job.mwfn");
job_mwfn.Export("job_new.mwfn");
# Python
job_mwfn = lm.Mwfn("job.mwfn")
job_mwfn.Export("job_new.mwfn")
- Getting the numbers of electrons.
// C++
int spin = 0; // 0 - default spin (depending on wavefunction types and functions); 1 - alpha; 2 - beta.
double n = job_mwfn.getNumElec(spin); // spin is optional. Default is 0, the total number of electrons of two spin types.
double n_alpha = job_mwfn.getNumElec(1); // The number of alpha electrons.
double n_beta = job_mwfn.getNumElec(2); // The number of beta electrons.
double charge = job_mwfn.getCharge(); // Total nuclear charges minus the number of electrons.
# Python
n = job_mwfn.getNumElec() # or job_mwfn.getNumElec(0)
n_alpha = job_mwfn.getNumElec(1)
n_beta = job_mwfn.getNumElec(2)
charge = job_mwfn.getCharge()
Note that the returned values are all floating-point numbers for the general case of fractional occupation.
- Getting and setting the occupation numbers.
// C++
int homo = std::round(job_mwfn.getNumElec(0) / 2) - 1; // The indices of the HOMO and LUMO.
int lumo = std::round(job_mwfn.getNumElec(0) / 2);
Eigen::VectorXd N = job_mwfn.getOccupation(0); // 0 for spin-restricted, 1 and 2 for alpha and beta in spin-unrestricted.
N(homo) = 0;
N(lumo) = 2; // Swapping the occupation numbers of the HOMO and LUMO.
job_mwfn.setOccupation(N, 0);
- Getting and setting the orbital energies.
// C++
Eigen::VectorXd E = job_mwfn.getEnergy(0);
E.setZero();
job_mwfn.setEnergy(E, 0); // Setting the orbital energies to zeros.
- Getting and setting the coefficient matrix.
// C++
Eigen::MatrixXd C = job_mwfn.getCoefficientMatrix(0);
Eigen::VectorXd C_0 = C.col(0); // The coefficient vector of the first orbital.
Eigen::VectorXd C_1 = C.col(1); // The coefficient vector of the second orbital.
C.col(0) = (C_0 + C_1) / 1.414213562; // Mixing the first two orbitals.
C.col(1) = (C_0 - C_1) / 1.414213562;
job_mwfn.setCoefficientMatrix(C, 0);
- Make a (deep) copy of a
Mwfninstance.
// C++
std::unique_ptr<Mwfn> another_mwfn = job_mwfn.Clone();
std::cout << another_mwfn->getNumElec() << std::endl; // The copy is a pointer.
# Python
another_mwfn = job_mwfn.Clone()
print(another_mwfn.getNumElec()) # No need to worry about the pointer thing.
- Check the header
libmwfn.hfor more functions.
Caution
- Ordering of basis functions.
The ordering of basis functions of $l \ge 2$ in libmwfn is [d-2, d-1, d0, d+1, d+2] and [f-3, f-2, f-1, f0, f+1, f+2, f+3], etc., different from [d0, d+1, d-1, d+2, d-2] and [f0, f+1, f-1, f+2, f-2, f+3, f-3, f+4, f-4], etc., in the
mwfnfile format. Upon I/O ofmwfnfile, a matrix transformation is applied to accommodate this difference.
Metadata
Release files for libmwfn 0.0.3
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Built distributions (wheels)
Total release size: 9.6 MB
Release files / libmwfn-0.0.3-cp313-cp313-musllinux_1_2_x86_64.whl
| Download URL | libmwfn-0.0.3-cp313-cp313-musllinux_1_2_x86_64.whl |
|---|---|
| Size | 1.5 MB |
| Tags | CPython 3.13 Linux musl 1.2+ x86-64 |
|
SHA-256 checksum How to use checksums |
d860ad0438572297636edf84fcc9f8612c1f1ae749f0d3f7069adf8b209fdde6
|
|
BLAKE2b-256 checksum How to use checksums |
621acd14c36542be335d3812351f141e6718f7359a6e7813ae4a89481a073775
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.1.0 CPython/3.13.7
|
Release files / libmwfn-0.0.3-cp313-cp313-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl
| Download URL | libmwfn-0.0.3-cp313-cp313-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl |
|---|---|
| Size | 440.4 kB |
| Tags | CPython 3.13 Linux glibc 2.27+ x86-64 Linux glibc 2.28+ x86-64 |
|
SHA-256 checksum How to use checksums |
a4e63c879665ac26eabdcda639cc4b814b8d0048a81bd527095b71e5cec65b3e
|
|
BLAKE2b-256 checksum How to use checksums |
add7602c6e78222c51bf108808a82d97851dbdfa06a7f25ffc4d09b9d06f4f04
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.1.0 CPython/3.13.7
|
Release files / libmwfn-0.0.3-cp312-cp312-musllinux_1_2_x86_64.whl
| Download URL | libmwfn-0.0.3-cp312-cp312-musllinux_1_2_x86_64.whl |
|---|---|
| Size | 1.5 MB |
| Tags | CPython 3.12 Linux musl 1.2+ x86-64 |
|
SHA-256 checksum How to use checksums |
114129b1b526931a8871536ac8b7653fff2112cb7be358744b1e8c1648fa7733
|
|
BLAKE2b-256 checksum How to use checksums |
7fd4d4f74f1dad19b36e288efec940cfb389135b7f22eee3b84f8cdb11afa56e
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.1.0 CPython/3.13.7
|
Release files / libmwfn-0.0.3-cp312-cp312-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl
| Download URL | libmwfn-0.0.3-cp312-cp312-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl |
|---|---|
| Size | 440.0 kB |
| Tags | CPython 3.12 Linux glibc 2.27+ x86-64 Linux glibc 2.28+ x86-64 |
|
SHA-256 checksum How to use checksums |
ead688bc8b6c02a19b6afb22d9ac23d8d22d320507cc3a84bbcbd0ce82aada2f
|
|
BLAKE2b-256 checksum How to use checksums |
689e8645725af65cc3daa17e0df8eab68f38f8262b54e05ef702f67a92b098b4
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.1.0 CPython/3.13.7
|
Release files / libmwfn-0.0.3-cp311-cp311-musllinux_1_2_x86_64.whl
| Download URL | libmwfn-0.0.3-cp311-cp311-musllinux_1_2_x86_64.whl |
|---|---|
| Size | 1.5 MB |
| Tags | CPython 3.11 Linux musl 1.2+ x86-64 |
|
SHA-256 checksum How to use checksums |
8dfd0d83b73765cf5988056a1f87b1a8b06e558f73e81f76428f38588e7c02f4
|
|
BLAKE2b-256 checksum How to use checksums |
8f194160e42febe41a70c4377fe922090acc32f96cc62cd510414318b84f042a
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.1.0 CPython/3.13.7
|
Release files / libmwfn-0.0.3-cp311-cp311-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl
| Download URL | libmwfn-0.0.3-cp311-cp311-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl |
|---|---|
| Size | 435.8 kB |
| Tags | CPython 3.11 Linux glibc 2.27+ x86-64 Linux glibc 2.28+ x86-64 |
|
SHA-256 checksum How to use checksums |
12911ce9dc773a9fc83c00a4dc484f138e6108075546b3b310eb996326d16e86
|
|
BLAKE2b-256 checksum How to use checksums |
edac1816429b788dab6fb2f68b3871c5c5bf71920c9e0812692241c08a8b1614
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.1.0 CPython/3.13.7
|
Release files / libmwfn-0.0.3-cp310-cp310-musllinux_1_2_x86_64.whl
| Download URL | libmwfn-0.0.3-cp310-cp310-musllinux_1_2_x86_64.whl |
|---|---|
| Size | 1.5 MB |
| Tags | CPython 3.10 Linux musl 1.2+ x86-64 |
|
SHA-256 checksum How to use checksums |
935a328afd0abc670507f5a8483d7a7d3ab872e81c6aa517ace82b4602bc0d4a
|
|
BLAKE2b-256 checksum How to use checksums |
6d23c5bfd7b9b2dd350b0f7e880a208c00b52afcac6c7077b2110599dfb6549f
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.1.0 CPython/3.13.7
|
Release files / libmwfn-0.0.3-cp310-cp310-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl
| Download URL | libmwfn-0.0.3-cp310-cp310-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl |
|---|---|
| Size | 433.9 kB |
| Tags | CPython 3.10 Linux glibc 2.27+ x86-64 Linux glibc 2.28+ x86-64 |
|
SHA-256 checksum How to use checksums |
d9ae13ff6ea2bec35514dd56c948b74d4fe7e27ab7a5dd1f075c931a09cc5e80
|
|
BLAKE2b-256 checksum How to use checksums |
3b9af95a9d47daaa3dbb11ed043f24f2a9705ce544bd8ea2896efe6bc3b55fcc
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.1.0 CPython/3.13.7
|
Release files / libmwfn-0.0.3-cp39-cp39-musllinux_1_2_x86_64.whl
| Download URL | libmwfn-0.0.3-cp39-cp39-musllinux_1_2_x86_64.whl |
|---|---|
| Size | 1.5 MB |
| Tags | CPython 3.9 Linux musl 1.2+ x86-64 |
|
SHA-256 checksum How to use checksums |
53dce97f611d8cd9ef22a21ba6027ac630fe72af180a837d198b6525b2d1807a
|
|
BLAKE2b-256 checksum How to use checksums |
bdd5e5ca4ea3b7b534580385077119adf6da83e486f0d1e7e7ad2e2130b3571d
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.1.0 CPython/3.13.7
|
Release files / libmwfn-0.0.3-cp39-cp39-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl
| Download URL | libmwfn-0.0.3-cp39-cp39-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl |
|---|---|
| Size | 432.3 kB |
| Tags | CPython 3.9 Linux glibc 2.27+ x86-64 Linux glibc 2.28+ x86-64 |
|
SHA-256 checksum How to use checksums |
1661b58ad891a3009cc43154c5daaae989a9012370c5370a2b263f2351ba92e6
|
|
BLAKE2b-256 checksum How to use checksums |
30f50e0f2bb23218cd2dfebf44a714369297a714ef911d7ffaaeb6632ad21e3e
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.1.0 CPython/3.13.7
|
Security for libmwfn 0.0.3
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.