Giter Club home page Giter Club logo

qha's Introduction

qha: A Powerful Python toolkit for quasi-harmonic approximation

[TOC]

Stable docs Build Status

category percent downloads
with_mirrors 100.00% 2,801
without_mirrors 20.67% 579
Total 2,801

Date range: 2023-04-20 - 2023-10-17

Contributors

This repository is now maintained by Qi Zhang. Thanks to the contribution from Chenxing Luo.

How to cite

The associated paper is published on Computer Physics Communications.

Please cite this article as: T. Qin, Q. Zhang, R.M. Wentzcovitch et al., qha: A Python package for quasiharmonic free energy calculation for multi-configuration systems, Computer Physics Communications (2018), https://doi.org/10.1016/j.cpc.2018.11.003.

Quick start: installation

Python environment

qha is written in Python, and can be installed from Python package index (PyPI) or local source files.

Python 3 can be downloaded from its official website for systems including Windows, macOS, and Linux, please check more details on Python 3 documentation.

To install qha, currently, Python 3.6.x distributions are recommended.

Where to get it

Binary installers for the latest released version are available at the PyPI.

# use PyPI
$ pip install qha

Dependencies

Installation from sources

The source code is currently hosted on GitHub. Please go to the “releases” page to download the tagged releases. Unzip the downloaded sources, go to the top-level directory (e.g., /path/to/repo/qha), run

$ pip install .

Notice that you have to use Python version > 3.6.x to install. If you want to install qha in development mode, instead run

$ pip install -e .

Checking the examples

To run the examples, go to examples/ice VII/ or examples/silicon/ directories and type in terminal:

$ qha run /path/to/settings.yaml

If you want to plot your results, in the same folder, run

$ qha plot /path/to/settings.yaml

Structure of the qha package

The qha source code consists of three major parts.

  1. ./qha directory contains all the source code.

  2. ./examples directory contains two examples, ./examples/silicon is the example for single-configuration calculation, ./examples/ice VII is the example for multi-configuration calculation.

The brief of the organization of these directories follows as below:

The main folder ./

This main folder contains three folders, license file, readme file, and setup file.

LICENSE.txt: The license file attached with the qha code;

README.md: Readme file of the code, it would be better to view it in a Markdown editor, e.g., Typora;

setup.py: setup file needed for installation of the qha Python package.

The ./qha/ folder

qha/__init__.py: Tells Python interpreter that this is a Python package;

qha/calculator.py: Perform single-, multi-configuration calculations, one of the most crucial modules in this code;

qha/fitting.py: Perform the Birch—Murnaghan (BM) equation-of-state (EOS) fitting;

qha/grid_interpolation.py: Find the most suitable volume grid to perform the BM EOS fitting;

qha/plotting.py: A simple module to plot the calculated physical properties;

qha/settings.py: Define some computational settings for the calculation;

qha/single_configuration.py: Calculate the Helmholtz free energy for a single-configuration system;

qha/statmech.py: Define some useful statistical mechanics functions;

qha/thermodynamics.py: Derive the internal energy($U$), enthalpy($H$), and Gibbs free energy ($G$) from the calculated Helmholtz free energy ($F$) via basic thermodynamics relationship;

qha/tools.py: Define some miscellaneous functions used in the code, e.g., function used to perform Lagrange interpolation;

qha/type_aliases.py: Define some types for annotation in the code;

qha/unit_conversion.py: A module to convert units used in the calculation;

qha/v2p.py: Contain the function v2p used to convert calculated properties on $(T, V)$ grid to $(T, P)$ grid;

qha/input_maker.py: Generate the input file for qha from results obtained from ab initio calculation;

qha/out.py: Functions used to write calculated properties into files.

The ./qha/readers folder

qha/readers/__init__.py

qha/readers/read_input.py: This module is used to read the input file.

The ./qha/cli folder

This folder contains files used for the command-line interface.

qha/cli/__init__.py

qha/cli/converter.py

qha/cli/handler.py

qha/cli/parser.py

qha/cli/plotter.py

qha/cli/runner.py

The ./qha/multi_configurations folder

This folder contains files to calculate Helmholtz free energy for the multi-configuration system.

qha/multi_configurations/__init__.py

qha/multi_configurations/different_phonon_dos.py: Work with qha/calculator.py to calculate Helmholtz free energy for the multi-configuration system with different phonon density of states (VDOS) for each configuration;

qha/multi_configurations/same_phonon_dos.py: Work with qha/calculator.py to calculate Helmholtz free energy for multi-configuration system with the same VDOS for all configurations.

The ./qha/tests folder

this folder contains unit test files

qha/tests/__init__.py

qha/tests/test_overall_run.py

qha/tests/test_read_input.py

qha/tests/test_samevdos_overall.py

qha/tests/test_single_configuration.py

qha/tests/test_unit_conversion.py

The ./examples/ folder

This folder contains two examples for demonstration purpose.

The ./examples/silicon folder

This folder conations an example to perform the single-configuration calculation. Also, an example to generate the input file for the qha code is included, check examples/silicon/make_input/README for details;

examples/silicon/input: The input file for qha;

examples/silicon/settings.yaml: This file is the computational settings file.

The ./examples/ice VII folder

examples/ice VII/input_01 : input_01 through input_52 are the input files of 52 distinguish configurations; examples/ice VII/input_02 examples/ice VII/input_03 examples/ice VII/input_52

examples/ice VII/settings.yaml: This file is the computational settings file, see our online tutorial for more details.

License

GNU General Public License v3

Documentation

The official documentation is hosted on our GitHub page.

Stargazers over time

Stargazers over time

qha's People

Contributors

chazeon avatar restyled-commits avatar singularitti avatar tianqin91 avatar underhill1886 avatar zhenzhang305 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

qha's Issues

Dependency on `bigfloat` package

The package bigfloat is the high precision arithmetic used by the Helmholtz free energy part of the calculator to do exponential and logarithm calculation. It is not actively maintained and supports Python 3.5 and 3.6 to date. This outdated package could limit the possibility for our code to be port to Python 3.7 or later versions. As Python 3.7 has its official release, as is mentioned in #46, this could be an issue. So I'm thinking of finding alternatives.

Another package gmpy is more actively developed and maintained, and is marked as a superseder in the Unofficial Windows Binaries for Python Extension Packages page, could be the option.

Yet do we actually need the precision, as is indicated in the code, 500 for our calculator? Just for log and exp? Maybe numpy's float64 is just good enough for the job. Even our unit conversion code could not maintain such high a precision as that.

We should test the outcome of using more convenient ways; and we could maybe give options for drivers and list them as “extra” dependencies for the package, like the Beautiful Soup 4 package does?

Split numbers when reading QE's `matdyn` output

Sometimes the QE outputs of phonon frequencies have a lot of imaginary frequencies. If they are too large, it will merge with the previous number.

            0.300000  0.291188  0.276701
-2471.6424-2400.9590-1460.5687-1267.3818  157.7216  181.1466

The current parser separates with spaces, therefore it will fails to read the frequencies. It should separate by numbers.

['0' '300'] not in index

Expected Behavior

qha-plot produce a bunch of plots

Actual Behavior

Error raised:

Traceback (most recent call last):
  File "C:\ProgramData\Anaconda3\Scripts\mc-qha-script.py", line 11, in <module>
    load_entry_point('qha==1.0.10', 'console_scripts', 'mc-qha')()
  File "C:\ProgramData\Anaconda3\lib\site-packages\qha\cli\__init__.py", line 18, in main
    namespace = parser.parse_args()
  File "C:\ProgramData\Anaconda3\lib\site-packages\qha\cli\parser.py", line 27, in parse_args
    program.run(namespace)
  File "C:\ProgramData\Anaconda3\lib\site-packages\qha\cli\plotter.py", line 67, in run
    plotter.fv_pv()
  File "C:\ProgramData\Anaconda3\lib\site-packages\qha\plotting.py", line 163, in fv_pv
    volume_t = volume[temperature_sample]
  File "C:\ProgramData\Anaconda3\lib\site-packages\pandas\core\frame.py", line 2056, in __getitem__
    return self._getitem_array(key)
  File "C:\ProgramData\Anaconda3\lib\site-packages\pandas\core\frame.py", line 2100, in _getitem_array
    indexer = self.loc._convert_to_indexer(key, axis=1)
  File "C:\ProgramData\Anaconda3\lib\site-packages\pandas\core\indexing.py", line 1231, in _convert_to_indexer
    raise KeyError('%s not in index' % objarr[mask])
KeyError: "['0' '300'] not in index"

Steps to Reproduce the Problem

Run qha-plot.

Specifications

  • Version: 1.0.10
  • Platform: Windows 10, Python 3.6.1
  • Subsystem: None

Fix `pyyaml` error

In this commit, I change

yaml.load(f)

to

yaml.load(f, Loader=yaml.CLoader)

which breaks qha for who do not have libyaml installed (thus no yaml.CLoader).

Population of each configuration in multi-configuration calculation

The population of each configuration multi-configuration could be calculated according to the partition function of each phase:

$$
n_j(V, T) = Z_j(V, T) / \sum_j Z_j(V, T)
$$
where the partition function $Z_j$ could be calculated through free energy.

We could write this distribution to output as a function of (P, T) and (V, T).

Test out the lower bounds of each package

As reported in issue #37, some Anaconda users are reporting that their packages are outdated and seem to be experiencing dependency hell. We need to figure out the lowest versions of each package we depend on and add them to setup.py and README.md or somewhere else. I recommend users to install the latest packages currently before we finish doing that.

`test_ho_free_energy` fails because of numerical error

Expected Behavior

self.assertEqual(ho_free_energy(0, 1000), 0.004556299262079407)
self.assertEqual(ho_free_energy(100, 1000), 0.0045562989049199466)

pass through.

Actual Behavior

Traceback (most recent call last):
  File "/Applications/PyCharm.app/Contents/helpers/pycharm/teamcity/diff_tools.py", line 32, in _patched_equals
    old(self, first, second, msg)
  File "/Users/qz/.pyenv/versions/3.6.8/lib/python3.6/unittest/case.py", line 829, in assertEqual
    assertion_func(first, second, msg=msg)
  File "/Users/qz/.pyenv/versions/3.6.8/lib/python3.6/unittest/case.py", line 822, in _baseAssertEqual
    raise self.failureException(msg)
AssertionError: 0.004556335252869987 != 0.004556299262079407

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/Users/qz/.pyenv/versions/3.6.8/lib/python3.6/unittest/case.py", line 59, in testPartExecutor
    yield
  File "/Users/qz/.pyenv/versions/3.6.8/lib/python3.6/unittest/case.py", line 605, in run
    testMethod()
  File "/Users/qz/.ghq/github.com/MineralsCloud/qha/qha/tests/test_single_configuration.py", line 13, in test_ho_free_energy
    self.assertEqual(ho_free_energy(0, 1000), 0.004556299262079407)

and

Traceback (most recent call last):
  File "/Applications/PyCharm.app/Contents/helpers/pycharm/teamcity/diff_tools.py", line 32, in _patched_equals
    old(self, first, second, msg)
  File "/Users/qz/.pyenv/versions/3.6.8/lib/python3.6/unittest/case.py", line 829, in assertEqual
    assertion_func(first, second, msg=msg)
  File "/Users/qz/.pyenv/versions/3.6.8/lib/python3.6/unittest/case.py", line 822, in _baseAssertEqual
    raise self.failureException(msg)
AssertionError: 0.004556334895497172 != 0.0045562989049199466

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/Users/qz/.pyenv/versions/3.6.8/lib/python3.6/unittest/case.py", line 59, in testPartExecutor
    yield
  File "/Users/qz/.pyenv/versions/3.6.8/lib/python3.6/unittest/case.py", line 605, in run
    testMethod()
  File "/Users/qz/.ghq/github.com/MineralsCloud/qha/qha/tests/test_single_configuration.py", line 14, in test_ho_free_energy
    self.assertEqual(ho_free_energy(100, 1000), 0.0045562989049199466)

Steps to Reproduce the Problem

  1. Install numba 0.44.0

Specifications

  • Version: qha 1.0.16, numba 0.44.0
  • Platform: All
  • Subsystem: All

`test_read_ice_input` fails because test data have been reanmed

Expected Behavior

test_read_ice_input runs through without error

Actual Behavior

test_read_ice_input runs with error

Error
Traceback (most recent call last):
  File "/Users/qz/.pyenv/versions/3.6.8/lib/python3.6/unittest/case.py", line 59, in testPartExecutor
    yield
  File "/Users/qz/.pyenv/versions/3.6.8/lib/python3.6/unittest/case.py", line 605, in run
    testMethod()
  File "/Users/qz/.ghq/github.com/MineralsCloud/qha/qha/tests/test_read_input.py", line 27, in test_read_ice_input
    nm, volumes, static_energies, frequencies, q_weights = read_input(file_path)
  File "/Users/qz/.ghq/github.com/MineralsCloud/qha/qha/basic_io/read_input.py", line 37, in read_input
    text_stream = TextStream(pathlib.Path(inp))
  File "/Users/qz/.virtualenvs/qha-Z2YbyQSM/lib/python3.6/site-packages/text_stream/__init__.py", line 58, in __init__
    "The *inp* argument '{0}' is not a valid file!".format(inp))
FileNotFoundError: The *inp* argument '../../examples/ice VII/input_conf01' is not a valid file!

Reason

examples/ice VII/input_conf01, etc., have been renamed to examples/ice VII/input_01, etc.

Specifications

  • Version: qha 1.0.16
  • Platform: All
  • Subsystem: All

Adaptive `volume_ratio` setting

As a reference, for $P(V)$ data, it is generally not advisable to let $\frac{ V }{ V_0 } &lt; 0.8$, which corresponds to have volume_ratio should not be larger than 1.25 in qha. My opinion is that when fitting, if we find the volume_ratio tends to be larger than 1.25 in the first step, we could let qha use 5th order Birch--Murnghan eos automatically, and print a warnging.

Make scripts to be invoked more conveniently under multiple platform

Something to consider: we could follow Python's official packages' organization in order that they can be more easily invoked. Good examples are http.server and pip, they could both be invoked with python -m, like:

python -m http.server

or

python -m pip

and pip could also be invoked as scripts under Unix based system. To allow python -m, we could move the main part of scripts/qha to qha/__main__.py, and scripts/qha-convert to qha/convert.py, thus they would be runnable use

python -m qha

or

python -m qha.convert

and create the scripts at the old places to invoke those two scripts.

We could refer to distributions of the official packages as examples.

Ice example unable to finish, with error in v2p

Expected Behavior

qha-run generates a bunch of outputs in ICE VII example

Actual Behavior

qha-run generates the following error:

Traceback (most recent call last):
  File "C:\ProgramData\Anaconda3\Scripts\qha-run-script.py", line 11, in <module>
    load_entry_point('qha==1.0.10', 'console_scripts', 'qha-run')()
  File "C:\ProgramData\Anaconda3\lib\site-packages\qha\run.py", line 124, in main
    save_x_tp(getattr(calc, attr_name), temperature_array, desired_pressures_gpa, p_sample_gpa, file_dir)
  File "C:\ProgramData\Anaconda3\lib\site-packages\lazy_property\__init__.py", line 27, in __get__
    result = self.method(instance)
  File "C:\ProgramData\Anaconda3\lib\site-packages\qha\calculator.py", line 247, in f_tp_ry
    return v2p(self.f_tv_ry, self.p_tv_au, self.desired_pressures)
  File "C:\ProgramData\Anaconda3\lib\site-packages\qha\v2p.py", line 68, in v2p
    x1, x2, x3, x4 = extended_p[i, k - 1:k + 3]
ValueError: not enough values to unpack (expected 4, got 0)

Specifications

  • Version: 1.0.10
  • Platform: Windows 10, Python 3.6.1
  • Subsystem: None

Numba does not support option "parallel"

Expected Behavior

qha-run should produce a bunch of output and plots.

Actual Behavior

The following error was raised:

PS C:\Users\chenx\Documents\Projects\qha\examples\silicon> mc-qha run
You have single-configuration calculation assumed.
Caution: If negative frequencies found, they are currently treated as 0!
Traceback (most recent call last):
  File "C:\ProgramData\Anaconda3\lib\site-packages\numba\targets\options.py", line 18, in from_dict
    ctor = self.OPTIONS[k]
KeyError: 'parallel'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "C:\ProgramData\Anaconda3\Scripts\mc-qha-script.py", line 11, in <module>
    load_entry_point('qha==1.0.10', 'console_scripts', 'mc-qha')()
  File "C:\ProgramData\Anaconda3\lib\site-packages\qha\cli\__init__.py", line 18, in main
    namespace = parser.parse_args()
  File "C:\ProgramData\Anaconda3\lib\site-packages\qha\cli\parser.py", line 27, in parse_args
    program.run(namespace)
  File "C:\ProgramData\Anaconda3\lib\site-packages\qha\cli\runner.py", line 130, in run
    save_x_tp(getattr(calc, attr_name), temperature_array, desired_pressures_gpa, p_sample_gpa, file_dir)
  File "C:\ProgramData\Anaconda3\lib\site-packages\lazy_property\__init__.py", line 27, in __get__
    result = self.method(instance)
  File "C:\ProgramData\Anaconda3\lib\site-packages\qha\calculator.py", line 247, in f_tp_ry
    return v2p(self.f_tv_ry, self.p_tv_au, self.desired_pressures)
  File "C:\ProgramData\Anaconda3\lib\site-packages\qha\v2p.py", line 68, in v2p
    result[i, j] = _lagrange4(desired_pressures[j], x1, x2, x3, x4, f1, f2, f3, f4)
  File "C:\ProgramData\Anaconda3\lib\site-packages\numba\dispatcher.py", line 307, in _compile_for_args
    return self.compile(tuple(argtypes))
  File "C:\ProgramData\Anaconda3\lib\site-packages\numba\dispatcher.py", line 579, in compile
    cres = self._compiler.compile(args, return_type)
  File "C:\ProgramData\Anaconda3\lib\site-packages\numba\dispatcher.py", line 72, in compile
    self.targetdescr.options.parse_as_flags(flags, self.targetoptions)
  File "C:\ProgramData\Anaconda3\lib\site-packages\numba\targets\options.py", line 28, in parse_as_flags
    opt.from_dict(options)
  File "C:\ProgramData\Anaconda3\lib\site-packages\numba\targets\options.py", line 21, in from_dict
    raise KeyError(fmt % (self.__class__, k))
KeyError: "<class 'numba.targets.cpu.CPUTargetOptions'> does not support option: 'parallel'"

Steps to Reproduce the Problem

Run qha-run on the silicon example.

Specifications

  • Version: 1.0.10
  • Platform: Windows 10, Python 3.6.1
  • Subsystem: None

`mpmath.workprec` and `bigfloat.precision`

I just found that what we used before, i.e., bigfloat.precision(self.precision), equivalent to bigfloat.Context(precision=self.precision), is

Precision of the floating-point format, given in bits.

To keep the modified code functioning as the old code, I also use mpmath.workprec(self.precision), also in bits. However, mpmath does provide mpmath.workdps, using decimal precision.

In general, the number of bits can be converted to decimal digits by multiplying it by ln(2)/ln(10) ~= 0.3. I think we should notice the users in doc, to let them know what precision we are using.

anisotropic crystal & fixed volume energies with castep

Hello QHA developers,

I would like to use QHA to get thermodynamic properties for the mineral tourmaline (trigonal). I am a complete novice to the subject to i apologies if these are very basic questions. I use the software CASTEP for my geometry optimizations and VDOS calculations. I have a question regarding the 'static' input file that was generated using quantum expresso (a software i do not have any experience with).

  1. the examples given of silicon and ice VII are both cubic systems, however i saw that the code was used for orthorhomic systems (fosterite) as well. What do i have to change in the input files for anisotropic crystal systems? (my system is trigonal however there are disordered endmembers in the tourmaline system which need supercells to describe them which have P1 symmetry)

  2. In castep i can do fixed volume and fixed cell optimizations. which of these two do i have to use to get an static energy at fixed volume? So far i tried

  • initial geometry optimisation of the endmember cell
  • expand and contract the lattice parameter manually and use a fixed volume geometric optimisation to get new static energies at those fixed volumes
    However the fixed volume optimisation generates an internall stress in the cell which is anisotropic:
    image
  1. what does the pressure mean in the 'static' input file. Is this the internal pressure the cell, eg in the image above the -11.0495 GPa?

Greetings Stan Roozen

`partition_functions_for_each_configuration` is actually the partition function for all configurations

Expected Behavior

multi_configurations.different_phonon_dos.partition_functions_for_each_configuration outputs the partition function for each configuration for each volume.

Actual Behavior

multi_configurations.different_phonon_dos.partition_functions_for_each_configuration outputs the partition function for all configurations for each volume.

Specifications

  • Version: qha 1.0.16
  • Platform: All
  • Subsystem: All

`YAMLLoadWarning: calling yaml.load() without Loader=... is deprecated`

The latest version of PyYAML package (version 5.1.1) has deprecated loading YAML file without a loader specified.
When running qha, it will complain like below

~/MineralsCloud/qha/qha/settings.py:83: YAMLLoadWarning: calling yaml.load() without Loader=... is deprecated, as the default Loader is unsafe. Please read https://msg.pyyaml.org/load for full details.
  return Settings(yaml.load(f))

The code being affected is here.

Collect 3 separate commands under 1 namespace

Expected Behavior

Should we consider move all commands under qha namespace?
For example, rename qha-run to qha run, qha-plot to qha plot, qha-convert to qha convert? That is, combine 3 separate commands into only 1 command with 3 different options.

Actual Behavior

Current behavior:

  1. qha-run
  2. qha-plot
  3. qha-convert

Seperate plotter and converter

Now since the plugin system is almost online as in #51, we could consider move the plotter and the converter to separate packages, and they could have their own CLI command in order to be runnable on supercomputers, and also list qha as an optional dependency, to work as a plugin for QHA.

Supporting 3 styles of CLI command is trival, only ~10 lines of modification as is shown in this commit.


Update: Now #51 is moved to #53.

Should we make a docker image of `qha`?

As mentioned in #52,

Some of the components, such as the plotter or the converter, should be a part of QHA, doesn't have to depend on QHA. Depending on QHA limits their use cases since QHA is not available to be installed everywhere (such as on Habanero or other places where bigfloat could not be installed or Python is not of version 3.6).

Will it be easier for people who use qha on supercomputers because they are the target users of qha?

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.