Skip to content

Commit b7c9950

Browse files
committed
Merge branch 'release/0.4.0'
2 parents d4ee83c + db036e2 commit b7c9950

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

52 files changed

+911
-201
lines changed

.github/dependabot.yml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
version: 2
2+
updates:
3+
- package-ecosystem: pip
4+
directory: "/"
5+
schedule:
6+
interval: daily
7+
open-pull-requests-limit: 10

.github/workflows/deploy.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ jobs:
1010
runs-on: ubuntu-latest
1111
steps:
1212
- uses: actions/checkout@v2
13-
- uses: actions/setup-python@v1
14-
- uses: dschep/install-poetry-action@v1.3
13+
- uses: actions/setup-python@v2
14+
- uses: snok/install-poetry@v1.1.2
1515
- run: poetry config pypi-token.pypi ${{ secrets.PYPI_TOKEN }}
1616
- run: poetry publish --build

.github/workflows/pre-commit.yml

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,5 @@ jobs:
66
runs-on: ubuntu-latest
77
steps:
88
- uses: actions/checkout@v2
9-
- uses: actions/setup-python@v1
10-
- name: set PY
11-
run: echo "::set-env name=PY::$(python --version --version | sha256sum | cut -d' ' -f1)"
12-
- uses: actions/cache@v1
13-
with:
14-
path: ~/.cache/pre-commit
15-
key: pre-commit|${{ env.PY }}|${{ hashFiles('.pre-commit-config.yaml') }}
16-
- uses: pre-commit/[email protected]
9+
- uses: actions/setup-python@v2
10+
- uses: pre-commit/[email protected]

.github/workflows/test.yml

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,30 @@
1-
name: tests
1+
name: Run Tests
22
on: [push, pull_request]
33

44
jobs:
55
pytest:
66
runs-on: ubuntu-latest
77
strategy:
88
matrix:
9-
python-version: [3.6, 3.7, 3.8, pypy3]
9+
python-version: [3.6, 3.7, 3.8, 3.9, pypy3]
1010

1111
steps:
1212
- uses: actions/checkout@v2
1313

14-
- name: Set up python
15-
uses: actions/setup-python@v1
14+
- name: Set up python ${{ matrix.python-version }}
15+
uses: actions/setup-python@v2
1616
with:
1717
python-version: ${{ matrix.python-version }}
1818
architecture: x64
1919

2020
- name: Install Poetry
21-
uses: dschep/install-poetry-action@v1.3
21+
uses: snok/install-poetry@v1.1.2
2222

23-
- name: Install Dependencies
23+
- name: Install dependencies
2424
run: poetry install -E yaml
2525

2626
- name: Run pytest
27-
run: poetry run pytest --cov-report xml --cov-report term-missing --cov-append --cov cp2k_output_tools tests/
27+
run: poetry run pytest --cov-report=xml --cov-report=term-missing --cov-append --cov=cp2k_output_tools tests/
2828

2929
- uses: codecov/codecov-action@v1
3030
with:

.pre-commit-config.yaml

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,24 @@
22
# # Install pre-commit hooks via
33
# pre-commit install
44

5-
default_language_version:
6-
python: python3
7-
85
repos:
6+
- repo: https://github.com/pycqa/isort
7+
rev: 5.9.1
8+
hooks:
9+
- id: isort
10+
name: isort (python)
11+
- id: isort
12+
name: isort (cython)
13+
types: [cython]
14+
- id: isort
15+
name: isort (pyi)
16+
types: [pyi]
917
- repo: https://github.com/ambv/black
10-
rev: stable
18+
rev: 21.6b0
1119
hooks:
1220
- id: black
1321
- repo: https://gitlab.com/pycqa/flake8
14-
rev: 3.7.0
22+
rev: 3.9.2
1523
hooks:
1624
- id: flake8
1725
additional_dependencies: ["flake8-bugbear"]

CHANGELOG.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,12 @@
1+
## [0.4.0] - 2021-07-19
2+
3+
* cp2kparse/api: can now parse forces
4+
* cp2kparse: gained a highlight mode to show what gets matched
5+
* cp2kparse: moved to click for providing the CLI to improve UX
6+
* cp2kparse/api: fix bug with parsing line continued kv
7+
* api: introduced BlockMatch to provide more info about the match (like the char span)
8+
* cp2k_bs2csv: generate files in CWD rather than in source dir
9+
110
## [0.3.1] - 2020-09-09
211

312
* cp2k_pdos: add support for list-of-atoms output

README.md

Lines changed: 56 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,21 @@
11
# cp2k-output-tools
22

3-
[![Build Status](https://github.com/cp2k/cp2k-output-tools/workflows/tests/badge.svg)](https://github.com/cp2k/cp2k-output-tools/actions) [![codecov](https://codecov.io/gh/cp2k/cp2k-output-tools/branch/develop/graph/badge.svg)](https://codecov.io/gh/cp2k/cp2k-output-tools) [![PyPI](https://img.shields.io/pypi/pyversions/cp2k-output-tools)](https://pypi.org/project/cp2k-output-tools/)
3+
[![Build Status](https://github.com/cp2k/cp2k-output-tools/actions/workflows/test.yml/badge.svg)](https://github.com/cp2k/cp2k-output-tools/actions) [![codecov](https://codecov.io/gh/cp2k/cp2k-output-tools/branch/develop/graph/badge.svg)](https://codecov.io/gh/cp2k/cp2k-output-tools) [![PyPI](https://img.shields.io/pypi/pyversions/cp2k-output-tools)](https://pypi.org/project/cp2k-output-tools/)
44

55
Modular CP2K output file parsers, mostly in the form of regular expressions plus other tools to mangle various CP2K output:
66

7-
* `cp2kparse` ... parse CP2K output files (for restart & input files look at the [cp2k-input-tools](https://github.com/cp2k/cp2k-input-tools) project)
8-
* `xyz_restart_parser` ... when restarts occur during an MD you may end up with duplicated frames in the trajectory, this tool filters them
7+
* `cp2kparse` ... parse CP2K output (for restart & input files look at the [cp2k-input-tools](https://github.com/cp2k/cp2k-input-tools) project) and allow easy selection of common values.
8+
* `xyz_restart_parser` ... when restarts occur during an MD you may end up with duplicated frames in the trajectory, this tool filters them (and can easily handle huge files)
99
* `cp2k_bs2csv` ... convert a CP2K band structure file to multiple (one-per-set) CSV files for easier plotting. There is also an API available if you need to import bandstructure data into your application.
10-
* `cp2k_pdos` ... bring CP2Ks PDOS dump into a more CSV-like form for easier plotting/parsing
10+
* `cp2k_pdos` ... apply a convolution with Gaussians on a regular grid on the CP2K PDOS output and generate a CSV file for further processing or plotting. The same grid is used for all input files with the min/max of the grid automatically determined, but no summation of the different projections is done.
1111

1212
## Requirements
1313

1414
* Python 3.6+
15-
* regex 2020+
15+
* regex 2021+
16+
* click 8+
17+
* numpy 1.19+
18+
* optional: ruamel.yaml
1619

1720
For development: https://poetry.eustace.io/ https://pytest.org/
1821

@@ -23,18 +26,21 @@ There is a simple command-line interface `cp2kparse`:
2326

2427
```console
2528
$ cp2kparse --help
26-
usage: cp2kparse [-h] [-y] [-k <path>] [<file>]
29+
Usage: cp2kparse [OPTIONS] [FILE|-]
2730

28-
Parse the CP2K output file and return a JSON
31+
Parse the CP2K output FILE and return a structured output
2932

30-
positional arguments:
31-
<file> CP2K output file, stdin if not specified
32-
33-
optional arguments:
34-
-h, --help show this help message and exit
35-
-y, --yaml output yaml instead of json
36-
-k <path>, --key <path>
37-
Path, ex.: 'energies/total force_eval'
33+
Options:
34+
-f, --format [json|yaml|highlight]
35+
Output format (json or yaml are structure
36+
formats, highlight shows which lines of the
37+
output have been matched)
38+
--color [auto|always] When to colorize output
39+
-s, --safe-keys generate 'safe' key names (e.g. without
40+
spaces, dashes, ..)
41+
-S, --statistics print some statistics to stderr
42+
-k, --key <PATH> Path, ex.: 'energies/total force_eval'
43+
--help Show this message and exit.
3844

3945
$ cp2kparse calc.out
4046
{
@@ -506,6 +512,41 @@ found restart point @1, dropping 1 frames, flushing 1
506512
flushing remaining 2 frames
507513
```
508514

515+
## Usage: cp2k_bs2csv
516+
517+
Given a `.bs` file as written by CP2K the script will generate CSV files with the same name and suffixes `.set-X.csv` in the same directory as the source file:
518+
519+
```console
520+
$ cp2k_bs2csv WO3.bs
521+
writing point set WO3.bs.set-1.csv (total number of k-points: 11)
522+
with the following special points:
523+
GAMMA: 0.00000000 / 0.00000000 / 0.00000000
524+
X: 0.00000000 / 0.50000000 / 0.00000000
525+
writing point set WO3.bs.set-2.csv (total number of k-points: 11)
526+
with the following special points:
527+
X: 0.00000000 / 0.50000000 / 0.00000000
528+
M: 0.50000000 / 0.50000000 / 0.00000000
529+
writing point set WO3.bsset-3.csv (total number of k-points: 11)
530+
with the following special points:
531+
M: 0.50000000 / 0.50000000 / 0.00000000
532+
GAMMA: 0.00000000 / 0.00000000 / 0.00000000
533+
writing point set WO3.bs.set-4.csv (total number of k-points: 11)
534+
with the following special points:
535+
GAMMA: 0.00000000 / 0.00000000 / 0.00000000
536+
R: 0.50000000 / 0.50000000 / 0.50000000
537+
writing point set WO3.bs.set-5.csv (total number of k-points: 11)
538+
with the following special points:
539+
R: 0.50000000 / 0.50000000 / 0.50000000
540+
X: 0.00000000 / 0.50000000 / 0.00000000
541+
writing point set WO3.bs.set-6.csv (total number of k-points: 11)
542+
with the following special points:
543+
R: 0.50000000 / 0.50000000 / 0.50000000
544+
M: 0.50000000 / 0.50000000 / 0.00000000
545+
$ ls
546+
WO3.cp2k-8.bs WO3.cp2k-8.bs.set-2.csv WO3.cp2k-8.bs.set-4.csv WO3.cp2k-8.bs.set-6.csv
547+
WO3.cp2k-8.bs.set-1.csv WO3.cp2k-8.bs.set-3.csv WO3.cp2k-8.bs.set-5.csv
548+
```
549+
509550
## Development
510551

511552
```console

cp2k_output_tools/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
__version__ = "0.3.1"
1+
__version__ = "0.4.0"
22

33
__all__ = ["builtin_matchers", "parse_iter"]
44

cp2k_output_tools/blocks/__init__.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
from .condition_number import match_overlap_matrix_condition_number
2+
from .energies import match_energies
3+
from .forces import match_forces
4+
from .kv_sections import match_kv_sections
25
from .mulliken import match_mulliken_population_analysis
36
from .program_info import match_program_info
4-
from .kv_sections import match_kv_sections
5-
from .energies import match_energies
67
from .warnings import match_warnings
78

89
builtin_matchers = [
@@ -11,5 +12,6 @@
1112
match_program_info,
1213
match_kv_sections,
1314
match_energies,
15+
match_forces,
1416
match_warnings,
1517
]

cp2k_output_tools/blocks/common.py

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
from dataclasses import dataclass
2+
from typing import Any, Dict, List, Tuple, Union
3+
14
# floating point regex
25
FLOAT = r"[\+\-]?(\d*[\.]\d+|\d+[\.]?\d*)([Ee][\+\-]?\d+)?"
36

@@ -18,3 +21,26 @@ def safe_string(string):
1821
.replace("{", "_")
1922
.replace("}", "_")
2023
)
24+
25+
26+
@dataclass
27+
class BlockMatch:
28+
data: Dict[str, Any] # the parsed/structured data
29+
spans: List[Union[int, Tuple[int, int]]] # start and end character indices of the matches
30+
31+
32+
def merged_spans(spans: List[Tuple[int, int]]):
33+
merged = [(-1, -1)]
34+
35+
for start, end in sorted(spans):
36+
if start > merged[-1][1]: # if the new start is after the latest end, add a new span
37+
merged.append((start, end))
38+
else: # if not, keep the current start and replace its end
39+
merged[-1] = (merged[-1][0], max(merged[-1][1], end))
40+
41+
del merged[0]
42+
return merged
43+
44+
45+
def span_char_count(spans: List[Tuple[int, int]]):
46+
return sum(end - start for start, end in spans)

0 commit comments

Comments
 (0)