Skip to content

Commit

Permalink
MAINT: Read the pressure from the cp2k .out file (#227)
Browse files Browse the repository at this point in the history
Read it from the `.out` file when calculating the bulk modulus, rather than calculating it from scratch.
  • Loading branch information
BvB93 committed Mar 4, 2021
1 parent 8e5b1ca commit 92993d8
Show file tree
Hide file tree
Showing 3 changed files with 1,740 additions and 226,737 deletions.
11 changes: 7 additions & 4 deletions FOX/properties/bulk_modulus.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
from qmflows.packages.cp2k_package import CP2K_Result
from qmflows.warnings_qmflows import QMFlows_Warning

from . import FromResult, get_pressure
from . import FromResult

__all__ = ['get_bulk_modulus', 'GetBulkMod']

Expand Down Expand Up @@ -75,8 +75,8 @@ def __call__(self): # noqa: D205,D400
:class:`qmflows.CP2K_Result <qmflows.packages.cp2k_package.CP2K_Result>`
to have access to the following files for each argument:
* **pressure**: ``cp2k-frc-1.xyz``, ``cp2k-pos-1.xyz``, ``cp2k-1.cell`` & ``cp2k-1.ener``
* **volume**: ``cp2k-1.cell``
* **pressure**: ``*.out`` (expected unit: bar)
* **volume**: ``cp2k-1.cell`` (expected unit: angstrom**3)
Furthermore, in order to get sensible results both the pressure and
cell volume must be variable.
Expand Down Expand Up @@ -118,13 +118,16 @@ def from_result(self, result, reduce=None, axis=None, *, return_unit='ha/bohr^3'
return self._reduce(ret1, reduce, axis)

a_to_au = Units.conversion_ratio('angstrom', 'bohr')
bar_to_au = Units.conversion_ratio('bar', 'ha/bohr^3')
with warnings.catch_warnings():
warnings.simplefilter('error', QMFlows_Warning)

volume = self._pop(
kwargs, 'volume', callback=lambda: getattr(result, 'volume') * a_to_au**3
)
pressure = get_pressure.from_result(result, reduce=None, volume=volume)
pressure = self._pop(
kwargs, 'pressure', callback=lambda: getattr(result, 'pressure') * bar_to_au
)

ret2 = self(pressure, volume, return_unit=return_unit, **kwargs)
self._cache[result] = (ret2, return_unit)
Expand Down
Binary file modified tests/test_files/bulk_modulus.npy
Binary file not shown.

0 comments on commit 92993d8

Please sign in to comment.