Skip to main content

A flexible .mwfn format handler

Project description

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 make and Eigen3 for C++
  • setuptools and pybind11 for Python

C++

  • Obtain the source code via git cloneing the repository or wgeting the latest release.
  • Specify the C++ compiler and the Eigen3 directory in makefile.
  • Build the library with make -j[N] and you will find the newly created directories include/ and lib/.
  • Tryout. (Reading in an existent file test.mwfn and exporting its information to another test_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.mwfn and exporting its information to another test_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 libmwfn module.
// C++
#include <libmwfn.h>
# Python
import libmwfn as lm
  • Reading and exporting wavefunction information from job.mwfn to job_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 Mwfn instance.
// 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.h for 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 mwfn file format. Upon I/O of mwfn file, a matrix transformation is applied to accommodate this difference.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distributions

No source distribution files available for this release.See tutorial on generating distribution archives.

Built Distributions

If you're not sure about the file name format, learn more about wheel file names.

libmwfn-0.0.3-cp313-cp313-musllinux_1_2_x86_64.whl (1.5 MB view details)

Uploaded CPython 3.13musllinux: musl 1.2+ x86-64

libmwfn-0.0.3-cp313-cp313-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl (440.4 kB view details)

Uploaded CPython 3.13manylinux: glibc 2.27+ x86-64manylinux: glibc 2.28+ x86-64

libmwfn-0.0.3-cp312-cp312-musllinux_1_2_x86_64.whl (1.5 MB view details)

Uploaded CPython 3.12musllinux: musl 1.2+ x86-64

libmwfn-0.0.3-cp312-cp312-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl (440.0 kB view details)

Uploaded CPython 3.12manylinux: glibc 2.27+ x86-64manylinux: glibc 2.28+ x86-64

libmwfn-0.0.3-cp311-cp311-musllinux_1_2_x86_64.whl (1.5 MB view details)

Uploaded CPython 3.11musllinux: musl 1.2+ x86-64

libmwfn-0.0.3-cp311-cp311-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl (435.8 kB view details)

Uploaded CPython 3.11manylinux: glibc 2.27+ x86-64manylinux: glibc 2.28+ x86-64

libmwfn-0.0.3-cp310-cp310-musllinux_1_2_x86_64.whl (1.5 MB view details)

Uploaded CPython 3.10musllinux: musl 1.2+ x86-64

libmwfn-0.0.3-cp310-cp310-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl (433.9 kB view details)

Uploaded CPython 3.10manylinux: glibc 2.27+ x86-64manylinux: glibc 2.28+ x86-64

libmwfn-0.0.3-cp39-cp39-musllinux_1_2_x86_64.whl (1.5 MB view details)

Uploaded CPython 3.9musllinux: musl 1.2+ x86-64

libmwfn-0.0.3-cp39-cp39-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl (432.3 kB view details)

Uploaded CPython 3.9manylinux: glibc 2.27+ x86-64manylinux: glibc 2.28+ x86-64

File details

Details for the file libmwfn-0.0.3-cp313-cp313-musllinux_1_2_x86_64.whl.

File metadata

File hashes

Hashes for libmwfn-0.0.3-cp313-cp313-musllinux_1_2_x86_64.whl
Algorithm Hash digest
SHA256 d860ad0438572297636edf84fcc9f8612c1f1ae749f0d3f7069adf8b209fdde6
MD5 2807923228db61eb01c6a3e3dbd53cdd
BLAKE2b-256 621acd14c36542be335d3812351f141e6718f7359a6e7813ae4a89481a073775

See more details on using hashes here.

File details

Details for the file libmwfn-0.0.3-cp313-cp313-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl.

File metadata

File hashes

Hashes for libmwfn-0.0.3-cp313-cp313-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 a4e63c879665ac26eabdcda639cc4b814b8d0048a81bd527095b71e5cec65b3e
MD5 4173dcd3fb8d2b74566cc9d7e8be5dbb
BLAKE2b-256 add7602c6e78222c51bf108808a82d97851dbdfa06a7f25ffc4d09b9d06f4f04

See more details on using hashes here.

File details

Details for the file libmwfn-0.0.3-cp312-cp312-musllinux_1_2_x86_64.whl.

File metadata

File hashes

Hashes for libmwfn-0.0.3-cp312-cp312-musllinux_1_2_x86_64.whl
Algorithm Hash digest
SHA256 114129b1b526931a8871536ac8b7653fff2112cb7be358744b1e8c1648fa7733
MD5 3fa5aceecc96c4b7c1d04bd429c19c98
BLAKE2b-256 7fd4d4f74f1dad19b36e288efec940cfb389135b7f22eee3b84f8cdb11afa56e

See more details on using hashes here.

File details

Details for the file libmwfn-0.0.3-cp312-cp312-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl.

File metadata

File hashes

Hashes for libmwfn-0.0.3-cp312-cp312-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 ead688bc8b6c02a19b6afb22d9ac23d8d22d320507cc3a84bbcbd0ce82aada2f
MD5 47362dd0d4bbbfa36cb48b3ca38d9455
BLAKE2b-256 689e8645725af65cc3daa17e0df8eab68f38f8262b54e05ef702f67a92b098b4

See more details on using hashes here.

File details

Details for the file libmwfn-0.0.3-cp311-cp311-musllinux_1_2_x86_64.whl.

File metadata

File hashes

Hashes for libmwfn-0.0.3-cp311-cp311-musllinux_1_2_x86_64.whl
Algorithm Hash digest
SHA256 8dfd0d83b73765cf5988056a1f87b1a8b06e558f73e81f76428f38588e7c02f4
MD5 e1d59917f04b96bba5ce5d8a0211d7d9
BLAKE2b-256 8f194160e42febe41a70c4377fe922090acc32f96cc62cd510414318b84f042a

See more details on using hashes here.

File details

Details for the file libmwfn-0.0.3-cp311-cp311-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl.

File metadata

File hashes

Hashes for libmwfn-0.0.3-cp311-cp311-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 12911ce9dc773a9fc83c00a4dc484f138e6108075546b3b310eb996326d16e86
MD5 732766bb554f3dea6fcd80b328c3cdb7
BLAKE2b-256 edac1816429b788dab6fb2f68b3871c5c5bf71920c9e0812692241c08a8b1614

See more details on using hashes here.

File details

Details for the file libmwfn-0.0.3-cp310-cp310-musllinux_1_2_x86_64.whl.

File metadata

File hashes

Hashes for libmwfn-0.0.3-cp310-cp310-musllinux_1_2_x86_64.whl
Algorithm Hash digest
SHA256 935a328afd0abc670507f5a8483d7a7d3ab872e81c6aa517ace82b4602bc0d4a
MD5 ce57f188c563839c40535bfe80ef2bed
BLAKE2b-256 6d23c5bfd7b9b2dd350b0f7e880a208c00b52afcac6c7077b2110599dfb6549f

See more details on using hashes here.

File details

Details for the file libmwfn-0.0.3-cp310-cp310-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl.

File metadata

File hashes

Hashes for libmwfn-0.0.3-cp310-cp310-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 d9ae13ff6ea2bec35514dd56c948b74d4fe7e27ab7a5dd1f075c931a09cc5e80
MD5 ebfb47ecdc7ab0bc27ca7bc58e722cec
BLAKE2b-256 3b9af95a9d47daaa3dbb11ed043f24f2a9705ce544bd8ea2896efe6bc3b55fcc

See more details on using hashes here.

File details

Details for the file libmwfn-0.0.3-cp39-cp39-musllinux_1_2_x86_64.whl.

File metadata

File hashes

Hashes for libmwfn-0.0.3-cp39-cp39-musllinux_1_2_x86_64.whl
Algorithm Hash digest
SHA256 53dce97f611d8cd9ef22a21ba6027ac630fe72af180a837d198b6525b2d1807a
MD5 6a217dd517d09a275c1127967d2db92d
BLAKE2b-256 bdd5e5ca4ea3b7b534580385077119adf6da83e486f0d1e7e7ad2e2130b3571d

See more details on using hashes here.

File details

Details for the file libmwfn-0.0.3-cp39-cp39-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl.

File metadata

File hashes

Hashes for libmwfn-0.0.3-cp39-cp39-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 1661b58ad891a3009cc43154c5daaae989a9012370c5370a2b263f2351ba92e6
MD5 0002bf0e084d175bacc238f88fcdfe2f
BLAKE2b-256 30f50e0f2bb23218cd2dfebf44a714369297a714ef911d7ffaaeb6632ad21e3e

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page