cp2k-spm-tools 1.4.4__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- cp2k_spm_tools-1.4.4/LICENSE +21 -0
- cp2k_spm_tools-1.4.4/PKG-INFO +118 -0
- cp2k_spm_tools-1.4.4/README.md +74 -0
- cp2k_spm_tools-1.4.4/cp2k_spm_tools/__init__.py +1 -0
- cp2k_spm_tools-1.4.4/cp2k_spm_tools/bader_wrapper.py +32 -0
- cp2k_spm_tools-1.4.4/cp2k_spm_tools/cli/__init__.py +0 -0
- cp2k_spm_tools-1.4.4/cp2k_spm_tools/cli/bader_bond_order.py +79 -0
- cp2k_spm_tools-1.4.4/cp2k_spm_tools/cli/crop_orbs_wfn.py +42 -0
- cp2k_spm_tools-1.4.4/cp2k_spm_tools/cli/cube_from_wfn.py +178 -0
- cp2k_spm_tools-1.4.4/cp2k_spm_tools/cli/cube_operations.py +114 -0
- cp2k_spm_tools-1.4.4/cp2k_spm_tools/cli/cube_single_column.py +68 -0
- cp2k_spm_tools-1.4.4/cp2k_spm_tools/cli/cube_split.py +247 -0
- cp2k_spm_tools-1.4.4/cp2k_spm_tools/cli/hrstm_from_wfn.py +337 -0
- cp2k_spm_tools-1.4.4/cp2k_spm_tools/cli/overlap_from_wfns.py +210 -0
- cp2k_spm_tools-1.4.4/cp2k_spm_tools/cli/stm_sts_from_wfn.py +303 -0
- cp2k_spm_tools-1.4.4/cp2k_spm_tools/cli/stm_sts_plotter.py +238 -0
- cp2k_spm_tools-1.4.4/cp2k_spm_tools/common.py +97 -0
- cp2k_spm_tools-1.4.4/cp2k_spm_tools/cp2k_ftsts.py +156 -0
- cp2k_spm_tools-1.4.4/cp2k_spm_tools/cp2k_grid_orbitals.py +869 -0
- cp2k_spm_tools-1.4.4/cp2k_spm_tools/cp2k_overlap_matrix.py +30 -0
- cp2k_spm_tools-1.4.4/cp2k_spm_tools/cp2k_stm_sts.py +703 -0
- cp2k_spm_tools-1.4.4/cp2k_spm_tools/cp2k_utils.py +223 -0
- cp2k_spm_tools-1.4.4/cp2k_spm_tools/cp2k_wfn_file.py +489 -0
- cp2k_spm_tools-1.4.4/cp2k_spm_tools/cube.py +215 -0
- cp2k_spm_tools-1.4.4/cp2k_spm_tools/cube_utils.py +78 -0
- cp2k_spm_tools-1.4.4/cp2k_spm_tools/cycles.py +108 -0
- cp2k_spm_tools-1.4.4/cp2k_spm_tools/hrstm_tools/__init__.py +0 -0
- cp2k_spm_tools-1.4.4/cp2k_spm_tools/hrstm_tools/cp2k_grid_matrix.py +224 -0
- cp2k_spm_tools-1.4.4/cp2k_spm_tools/hrstm_tools/hrstm.py +224 -0
- cp2k_spm_tools-1.4.4/cp2k_spm_tools/hrstm_tools/hrstm_utils.py +142 -0
- cp2k_spm_tools-1.4.4/cp2k_spm_tools/hrstm_tools/interpolator.py +113 -0
- cp2k_spm_tools-1.4.4/cp2k_spm_tools/hrstm_tools/ppstm_grid_orbitals.py +267 -0
- cp2k_spm_tools-1.4.4/cp2k_spm_tools/hrstm_tools/tip_coeffs.py +310 -0
- cp2k_spm_tools-1.4.4/cp2k_spm_tools/igor.py +348 -0
- cp2k_spm_tools-1.4.4/cp2k_spm_tools/qe_utils.py +334 -0
- cp2k_spm_tools-1.4.4/cp2k_spm_tools.egg-info/PKG-INFO +118 -0
- cp2k_spm_tools-1.4.4/cp2k_spm_tools.egg-info/SOURCES.txt +41 -0
- cp2k_spm_tools-1.4.4/cp2k_spm_tools.egg-info/dependency_links.txt +1 -0
- cp2k_spm_tools-1.4.4/cp2k_spm_tools.egg-info/entry_points.txt +11 -0
- cp2k_spm_tools-1.4.4/cp2k_spm_tools.egg-info/requires.txt +9 -0
- cp2k_spm_tools-1.4.4/cp2k_spm_tools.egg-info/top_level.txt +1 -0
- cp2k_spm_tools-1.4.4/pyproject.toml +63 -0
- cp2k_spm_tools-1.4.4/setup.cfg +4 -0
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2019 Kristjan Eimre
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
|
@@ -0,0 +1,118 @@
|
|
|
1
|
+
Metadata-Version: 2.2
|
|
2
|
+
Name: cp2k-spm-tools
|
|
3
|
+
Version: 1.4.4
|
|
4
|
+
Summary: CP2K Scanning Probe Microscopy tools.
|
|
5
|
+
Author-email: Kristjan Eimre <kristjaneimre@gmail.com>, Edoardo Baldi <edoardo.baldi@empa.ch>
|
|
6
|
+
License: MIT License
|
|
7
|
+
|
|
8
|
+
Copyright (c) 2019 Kristjan Eimre
|
|
9
|
+
|
|
10
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
11
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
12
|
+
in the Software without restriction, including without limitation the rights
|
|
13
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
14
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
15
|
+
furnished to do so, subject to the following conditions:
|
|
16
|
+
|
|
17
|
+
The above copyright notice and this permission notice shall be included in all
|
|
18
|
+
copies or substantial portions of the Software.
|
|
19
|
+
|
|
20
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
21
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
22
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
23
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
24
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
25
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
26
|
+
SOFTWARE.
|
|
27
|
+
|
|
28
|
+
Project-URL: Homepage, https://github.com/nanotech-empa/cp2k-spm-tools
|
|
29
|
+
Project-URL: Bug Tracker, https://github.com/nanotech-empa/cp2k-spm-tools/issues
|
|
30
|
+
Classifier: Programming Language :: Python :: 3
|
|
31
|
+
Classifier: License :: OSI Approved :: MIT License
|
|
32
|
+
Classifier: Operating System :: OS Independent
|
|
33
|
+
Requires-Python: >=3.8
|
|
34
|
+
Description-Content-Type: text/markdown
|
|
35
|
+
License-File: LICENSE
|
|
36
|
+
Requires-Dist: numpy<2,>=1.22
|
|
37
|
+
Requires-Dist: scipy<2,>=1.10
|
|
38
|
+
Requires-Dist: ase<4,>=3.15
|
|
39
|
+
Requires-Dist: matplotlib<4,>=3.0
|
|
40
|
+
Requires-Dist: mpi4py>3.1
|
|
41
|
+
Provides-Extra: dev
|
|
42
|
+
Requires-Dist: ruff; extra == "dev"
|
|
43
|
+
Requires-Dist: pre-commit; extra == "dev"
|
|
44
|
+
|
|
45
|
+
[](https://zenodo.org/badge/latestdoi/133041124)
|
|
46
|
+
|
|
47
|
+
## CP2K Scanning Probe Microscopy tools
|
|
48
|
+
|
|
49
|
+
Library and scripts to perform scanning probe microscopy simulations based on a [CP2K](https://www.cp2k.org/) calculation.
|
|
50
|
+
|
|
51
|
+
Features include:
|
|
52
|
+
|
|
53
|
+
- Processing the various output files of [CP2K](https://www.cp2k.org/), including the `.wfn` file
|
|
54
|
+
- Scanning Tunnelling Microscopy and Spectroscopy (STM/STS) analysis
|
|
55
|
+
- Fourier-Transformed STS analysis for finite cutouts of periodic systems
|
|
56
|
+
- Orbital hybridization analysis for adsorbed systems
|
|
57
|
+
- High-resolution STM (HRSTM) simulations
|
|
58
|
+
|
|
59
|
+
### Installation
|
|
60
|
+
|
|
61
|
+
The package requires an MPI implementation to be available on your system for `mpi4py`. You can install it:
|
|
62
|
+
|
|
63
|
+
- On Linux: through your package manager (e.g., `apt install mpich` or `yum install mpich`)
|
|
64
|
+
- On macOS: through Homebrew (`brew install mpich`)
|
|
65
|
+
- On Windows: through conda (`conda install -c conda-forge mpich`)
|
|
66
|
+
|
|
67
|
+
Then install the package with pip:
|
|
68
|
+
```bash
|
|
69
|
+
pip install cp2k-spm-tools
|
|
70
|
+
```
|
|
71
|
+
|
|
72
|
+
Or, for development:
|
|
73
|
+
```bash
|
|
74
|
+
git clone https://github.com/nanotech-empa/cp2k-spm-tools.git
|
|
75
|
+
cd cp2k-spm-tools
|
|
76
|
+
pip install -e .[dev]
|
|
77
|
+
```
|
|
78
|
+
|
|
79
|
+
### Command Line Tools
|
|
80
|
+
|
|
81
|
+
The package provides several command-line tools, including:
|
|
82
|
+
|
|
83
|
+
- `cp2k-stm-sts-wfn`: STM/STS analysis from wavefunction files
|
|
84
|
+
- `cp2k-cube-from-wfn`: Create cube files from wavefunction files
|
|
85
|
+
- `cp2k-bader-bond-order`: Bond order analysis based on Bader basins
|
|
86
|
+
|
|
87
|
+
Use `--help` with each command to see its options.
|
|
88
|
+
|
|
89
|
+
### Example Usage
|
|
90
|
+
|
|
91
|
+
When everything is set up correctly, the bash scripts in `examples/` folder can be executed without any further input and illustrate the usage of the various scripts. For example `example/benzene_stm/run_stm_sts_from_wfn.sh` evaluates the STM/STS signatures of isolated benzene at each orbital energy (`out/orb/`) as well as in an arbitrary energy range (`out/stm/`). The corresponding CP2K calculation is included in the repository.
|
|
92
|
+
|
|
93
|
+
**NB: In all cases, the underlying DFT calculation has to be performed with the diagonalization algorithm rather than orbital transformation (OT).**
|
|
94
|
+
|
|
95
|
+
### Python API Example
|
|
96
|
+
|
|
97
|
+
Most of the functionality of this library is built on top of the possibility to evaluate the Kohn-Sham orbitals encoded in the `.wfn` file on an arbitrarily defined grid. This is illustrated by the following script applied for a nanographene adsorbed on a Au(111) slab (total of 1252 atoms and 10512 electrons):
|
|
98
|
+
|
|
99
|
+
```python
|
|
100
|
+
from cp2k_spm_tools.cp2k_grid_orbitals import Cp2kGridOrbitals
|
|
101
|
+
|
|
102
|
+
### Create the gridding object and load the cp2k data ###
|
|
103
|
+
cgo = Cp2kGridOrbitals()
|
|
104
|
+
cgo.read_cp2k_input("./cp2k.inp")
|
|
105
|
+
cgo.read_xyz("./geom.xyz")
|
|
106
|
+
cgo.read_basis_functions("./BASIS_MOLOPT")
|
|
107
|
+
cgo.load_restart_wfn_file("./PROJ-RESTART.wfn", n_occ=2, n_virt=2)
|
|
108
|
+
|
|
109
|
+
### Evaluate the orbitals in the specific region ###
|
|
110
|
+
cgo.calc_morbs_in_region(
|
|
111
|
+
dr_guess = 0.15, # grid spacing
|
|
112
|
+
x_eval_region = None, # take whole cell in x
|
|
113
|
+
y_eval_region = [0.0, cgo.cell_ang[1]/2], # half cell in y
|
|
114
|
+
z_eval_region = [19.0, 24.0], # around the molecule in z
|
|
115
|
+
)
|
|
116
|
+
|
|
117
|
+
cgo.write_cube("./homo.cube", orbital_nr=0)
|
|
118
|
+
```
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
[](https://zenodo.org/badge/latestdoi/133041124)
|
|
2
|
+
|
|
3
|
+
## CP2K Scanning Probe Microscopy tools
|
|
4
|
+
|
|
5
|
+
Library and scripts to perform scanning probe microscopy simulations based on a [CP2K](https://www.cp2k.org/) calculation.
|
|
6
|
+
|
|
7
|
+
Features include:
|
|
8
|
+
|
|
9
|
+
- Processing the various output files of [CP2K](https://www.cp2k.org/), including the `.wfn` file
|
|
10
|
+
- Scanning Tunnelling Microscopy and Spectroscopy (STM/STS) analysis
|
|
11
|
+
- Fourier-Transformed STS analysis for finite cutouts of periodic systems
|
|
12
|
+
- Orbital hybridization analysis for adsorbed systems
|
|
13
|
+
- High-resolution STM (HRSTM) simulations
|
|
14
|
+
|
|
15
|
+
### Installation
|
|
16
|
+
|
|
17
|
+
The package requires an MPI implementation to be available on your system for `mpi4py`. You can install it:
|
|
18
|
+
|
|
19
|
+
- On Linux: through your package manager (e.g., `apt install mpich` or `yum install mpich`)
|
|
20
|
+
- On macOS: through Homebrew (`brew install mpich`)
|
|
21
|
+
- On Windows: through conda (`conda install -c conda-forge mpich`)
|
|
22
|
+
|
|
23
|
+
Then install the package with pip:
|
|
24
|
+
```bash
|
|
25
|
+
pip install cp2k-spm-tools
|
|
26
|
+
```
|
|
27
|
+
|
|
28
|
+
Or, for development:
|
|
29
|
+
```bash
|
|
30
|
+
git clone https://github.com/nanotech-empa/cp2k-spm-tools.git
|
|
31
|
+
cd cp2k-spm-tools
|
|
32
|
+
pip install -e .[dev]
|
|
33
|
+
```
|
|
34
|
+
|
|
35
|
+
### Command Line Tools
|
|
36
|
+
|
|
37
|
+
The package provides several command-line tools, including:
|
|
38
|
+
|
|
39
|
+
- `cp2k-stm-sts-wfn`: STM/STS analysis from wavefunction files
|
|
40
|
+
- `cp2k-cube-from-wfn`: Create cube files from wavefunction files
|
|
41
|
+
- `cp2k-bader-bond-order`: Bond order analysis based on Bader basins
|
|
42
|
+
|
|
43
|
+
Use `--help` with each command to see its options.
|
|
44
|
+
|
|
45
|
+
### Example Usage
|
|
46
|
+
|
|
47
|
+
When everything is set up correctly, the bash scripts in `examples/` folder can be executed without any further input and illustrate the usage of the various scripts. For example `example/benzene_stm/run_stm_sts_from_wfn.sh` evaluates the STM/STS signatures of isolated benzene at each orbital energy (`out/orb/`) as well as in an arbitrary energy range (`out/stm/`). The corresponding CP2K calculation is included in the repository.
|
|
48
|
+
|
|
49
|
+
**NB: In all cases, the underlying DFT calculation has to be performed with the diagonalization algorithm rather than orbital transformation (OT).**
|
|
50
|
+
|
|
51
|
+
### Python API Example
|
|
52
|
+
|
|
53
|
+
Most of the functionality of this library is built on top of the possibility to evaluate the Kohn-Sham orbitals encoded in the `.wfn` file on an arbitrarily defined grid. This is illustrated by the following script applied for a nanographene adsorbed on a Au(111) slab (total of 1252 atoms and 10512 electrons):
|
|
54
|
+
|
|
55
|
+
```python
|
|
56
|
+
from cp2k_spm_tools.cp2k_grid_orbitals import Cp2kGridOrbitals
|
|
57
|
+
|
|
58
|
+
### Create the gridding object and load the cp2k data ###
|
|
59
|
+
cgo = Cp2kGridOrbitals()
|
|
60
|
+
cgo.read_cp2k_input("./cp2k.inp")
|
|
61
|
+
cgo.read_xyz("./geom.xyz")
|
|
62
|
+
cgo.read_basis_functions("./BASIS_MOLOPT")
|
|
63
|
+
cgo.load_restart_wfn_file("./PROJ-RESTART.wfn", n_occ=2, n_virt=2)
|
|
64
|
+
|
|
65
|
+
### Evaluate the orbitals in the specific region ###
|
|
66
|
+
cgo.calc_morbs_in_region(
|
|
67
|
+
dr_guess = 0.15, # grid spacing
|
|
68
|
+
x_eval_region = None, # take whole cell in x
|
|
69
|
+
y_eval_region = [0.0, cgo.cell_ang[1]/2], # half cell in y
|
|
70
|
+
z_eval_region = [19.0, 24.0], # around the molecule in z
|
|
71
|
+
)
|
|
72
|
+
|
|
73
|
+
cgo.write_cube("./homo.cube", orbital_nr=0)
|
|
74
|
+
```
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"""CP2K Scanning Probe Microscopy tools"""
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
"""
|
|
2
|
+
Routines to call the Henkelmann Bader program
|
|
3
|
+
"""
|
|
4
|
+
|
|
5
|
+
import os
|
|
6
|
+
import subprocess
|
|
7
|
+
|
|
8
|
+
ang_2_bohr = 1.0 / 0.52917721067
|
|
9
|
+
hart_2_ev = 27.21138602
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
def call_bader(folder, cube_file, method="neargrid", basin_atoms=[], ref_cube=None):
|
|
13
|
+
cur_dir = os.getcwd()
|
|
14
|
+
|
|
15
|
+
command = "bader -b %s" % method
|
|
16
|
+
if len(basin_atoms) > 0:
|
|
17
|
+
command += " -p sel_atom " + " ".join([str(e + 1) for e in basin_atoms])
|
|
18
|
+
|
|
19
|
+
if ref_cube is not None:
|
|
20
|
+
command += " -ref %s" % ref_cube
|
|
21
|
+
|
|
22
|
+
command += " %s > bader.log" % cube_file
|
|
23
|
+
|
|
24
|
+
print(command)
|
|
25
|
+
|
|
26
|
+
try:
|
|
27
|
+
os.chdir(folder)
|
|
28
|
+
subprocess.call(command, shell=True)
|
|
29
|
+
except:
|
|
30
|
+
print("Warning: Couldn't run Bader.")
|
|
31
|
+
|
|
32
|
+
os.chdir(cur_dir)
|
|
File without changes
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
#!/usr/bin/env python
|
|
2
|
+
import argparse
|
|
3
|
+
import time
|
|
4
|
+
|
|
5
|
+
from mpi4py import MPI
|
|
6
|
+
|
|
7
|
+
from cp2k_spm_tools import common
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
def main():
|
|
11
|
+
comm = MPI.COMM_WORLD
|
|
12
|
+
mpi_rank = comm.Get_rank()
|
|
13
|
+
mpi_size = comm.Get_size()
|
|
14
|
+
|
|
15
|
+
parser = argparse.ArgumentParser(description="Runs bond order analysis based on Bader basins.")
|
|
16
|
+
|
|
17
|
+
parser.add_argument(
|
|
18
|
+
"--cp2k_input_file", metavar="FILENAME", required=True, help="CP2K input of the SCF calculation."
|
|
19
|
+
)
|
|
20
|
+
parser.add_argument(
|
|
21
|
+
"--basis_set_file", metavar="FILENAME", required=True, help="File containing the used basis sets."
|
|
22
|
+
)
|
|
23
|
+
parser.add_argument("--xyz_file", metavar="FILENAME", required=True, help=".xyz file containing the geometry.")
|
|
24
|
+
parser.add_argument(
|
|
25
|
+
"--wfn_file", metavar="FILENAME", required=True, help="cp2k restart file containing the wavefunction."
|
|
26
|
+
)
|
|
27
|
+
parser.add_argument(
|
|
28
|
+
"--output_file", metavar="FILENAME", required=True, help="Output file containing the bond orders."
|
|
29
|
+
)
|
|
30
|
+
parser.add_argument(
|
|
31
|
+
"--bader_basins_dir", metavar="DIR", required=True, help="directory containing the Bader basin .cube files."
|
|
32
|
+
)
|
|
33
|
+
parser.add_argument("--dx", type=float, metavar="DX", default=0.2, help="Spatial step for the grid (angstroms).")
|
|
34
|
+
parser.add_argument(
|
|
35
|
+
"--eval_cutoff",
|
|
36
|
+
type=float,
|
|
37
|
+
metavar="D",
|
|
38
|
+
default=14.0,
|
|
39
|
+
help=("Size of the region around the atom where each orbital is evaluated (only used for 'G' region)."),
|
|
40
|
+
)
|
|
41
|
+
parser.add_argument(
|
|
42
|
+
"--eval_region",
|
|
43
|
+
type=str,
|
|
44
|
+
nargs=6,
|
|
45
|
+
metavar="X",
|
|
46
|
+
required=False,
|
|
47
|
+
default=["G", "G", "G", "G", "G", "G"],
|
|
48
|
+
help=common.eval_region_description,
|
|
49
|
+
)
|
|
50
|
+
|
|
51
|
+
# Rest of your existing code, unchanged
|
|
52
|
+
time0 = time.time()
|
|
53
|
+
|
|
54
|
+
### ------------------------------------------------------
|
|
55
|
+
### Parse args for only one rank to suppress duplicate stdio
|
|
56
|
+
### ------------------------------------------------------
|
|
57
|
+
|
|
58
|
+
args = None
|
|
59
|
+
args_success = False
|
|
60
|
+
try:
|
|
61
|
+
if mpi_rank == 0:
|
|
62
|
+
args = parser.parse_args()
|
|
63
|
+
args_success = True
|
|
64
|
+
finally:
|
|
65
|
+
args_success = comm.bcast(args_success, root=0)
|
|
66
|
+
|
|
67
|
+
if not args_success:
|
|
68
|
+
print(mpi_rank, "exiting")
|
|
69
|
+
exit(0)
|
|
70
|
+
|
|
71
|
+
args = comm.bcast(args, root=0)
|
|
72
|
+
|
|
73
|
+
# ... rest of your existing code ...
|
|
74
|
+
|
|
75
|
+
print("R%d/%d finished, total time: %.2fs" % (mpi_rank, mpi_size, (time.time() - time0)))
|
|
76
|
+
|
|
77
|
+
|
|
78
|
+
if __name__ == "__main__":
|
|
79
|
+
main()
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
#!/usr/bin/env python
|
|
2
|
+
import argparse
|
|
3
|
+
import time
|
|
4
|
+
|
|
5
|
+
import cp2k_spm_tools.cp2k_wfn_file as cwf
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
def main():
|
|
9
|
+
parser = argparse.ArgumentParser(description="Crops CP2K RESTART.wfn file.")
|
|
10
|
+
|
|
11
|
+
parser.add_argument(
|
|
12
|
+
"--wfn_file", metavar="FILENAME", required=True, help="cp2k restart file containing the wavefunction."
|
|
13
|
+
)
|
|
14
|
+
parser.add_argument("--output_file", metavar="FILENAME", required=True, help="File where to save the output")
|
|
15
|
+
parser.add_argument(
|
|
16
|
+
"--emin", type=float, metavar="E", default=0.0, help="Lowest energy value for selecting orbitals (eV)."
|
|
17
|
+
)
|
|
18
|
+
parser.add_argument(
|
|
19
|
+
"--emax", type=float, metavar="E", default=0.0, help="Highest energy value for selecting orbitals (eV)."
|
|
20
|
+
)
|
|
21
|
+
parser.add_argument("--n_homo", type=int, metavar="N", default=0, help="Number of HOMO orbitals to export.")
|
|
22
|
+
parser.add_argument("--n_lumo", type=int, metavar="N", default=0, help="Number of LUMO orbitals to export.")
|
|
23
|
+
|
|
24
|
+
time0 = time.time()
|
|
25
|
+
|
|
26
|
+
args = parser.parse_args()
|
|
27
|
+
|
|
28
|
+
cp2k_wfn_f = cwf.Cp2kWfnFile()
|
|
29
|
+
|
|
30
|
+
if args.n_homo > 0 or args.n_lumo > 0:
|
|
31
|
+
print("Number of orbitals specified, energy limits ignored.")
|
|
32
|
+
cp2k_wfn_f.load_restart_wfn_file(args.wfn_file, n_homo=args.n_homo, n_lumo=args.n_lumo)
|
|
33
|
+
else:
|
|
34
|
+
cp2k_wfn_f.load_restart_wfn_file(args.wfn_file, emin=args.emin, emax=args.emax)
|
|
35
|
+
|
|
36
|
+
print("Loaded wfn, %.2fs" % (time.time() - time0))
|
|
37
|
+
|
|
38
|
+
cp2k_wfn_f.write_fortran(args.output_file)
|
|
39
|
+
|
|
40
|
+
|
|
41
|
+
if __name__ == "__main__":
|
|
42
|
+
main()
|
|
@@ -0,0 +1,178 @@
|
|
|
1
|
+
#!/usr/bin/env python
|
|
2
|
+
import argparse
|
|
3
|
+
import time
|
|
4
|
+
|
|
5
|
+
import numpy as np
|
|
6
|
+
from mpi4py import MPI
|
|
7
|
+
|
|
8
|
+
import cp2k_spm_tools.cp2k_grid_orbitals as cgo
|
|
9
|
+
from cp2k_spm_tools import common
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
def main():
|
|
13
|
+
comm = MPI.COMM_WORLD
|
|
14
|
+
mpi_rank = comm.Get_rank()
|
|
15
|
+
mpi_size = comm.Get_size()
|
|
16
|
+
|
|
17
|
+
parser = argparse.ArgumentParser(description="Creates Gaussian cube files from cp2k .wfn file.")
|
|
18
|
+
|
|
19
|
+
parser.add_argument(
|
|
20
|
+
"--cp2k_input_file", metavar="FILENAME", required=True, help="CP2K input of the SCF calculation."
|
|
21
|
+
)
|
|
22
|
+
parser.add_argument(
|
|
23
|
+
"--basis_set_file", metavar="FILENAME", required=True, help="File containing the used basis sets."
|
|
24
|
+
)
|
|
25
|
+
parser.add_argument("--xyz_file", metavar="FILENAME", required=True, help=".xyz file containing the geometry.")
|
|
26
|
+
parser.add_argument(
|
|
27
|
+
"--wfn_file", metavar="FILENAME", required=True, help="cp2k restart file containing the wavefunction."
|
|
28
|
+
)
|
|
29
|
+
|
|
30
|
+
parser.add_argument("--output_dir", metavar="DIR", required=True, help="directory where to output the cubes.")
|
|
31
|
+
### -----------------------------------------------------------
|
|
32
|
+
parser.add_argument("--dx", type=float, metavar="DX", default=0.2, help="Spatial step for the grid (angstroms).")
|
|
33
|
+
parser.add_argument(
|
|
34
|
+
"--eval_cutoff",
|
|
35
|
+
type=float,
|
|
36
|
+
metavar="D",
|
|
37
|
+
default=14.0,
|
|
38
|
+
help=("Size of the region around the atom where each orbital is evaluated (only used for 'G' region)."),
|
|
39
|
+
)
|
|
40
|
+
parser.add_argument(
|
|
41
|
+
"--eval_region",
|
|
42
|
+
type=str,
|
|
43
|
+
nargs=6,
|
|
44
|
+
metavar="X",
|
|
45
|
+
required=False,
|
|
46
|
+
default=["G", "G", "G", "G", "G", "G"],
|
|
47
|
+
help=common.eval_region_description,
|
|
48
|
+
)
|
|
49
|
+
parser.add_argument(
|
|
50
|
+
"--pbc",
|
|
51
|
+
type=int,
|
|
52
|
+
nargs=3,
|
|
53
|
+
metavar="X",
|
|
54
|
+
required=False,
|
|
55
|
+
default=[1, 1, 1],
|
|
56
|
+
help="periodic boundary conditions in directions [x,y,z]. (1=on, 0=off)",
|
|
57
|
+
)
|
|
58
|
+
### -----------------------------------------------------------
|
|
59
|
+
parser.add_argument("--n_homo", type=int, metavar="N", default=0, help="Number of HOMO orbitals to export.")
|
|
60
|
+
parser.add_argument("--n_lumo", type=int, metavar="N", default=0, help="Number of LUMO orbitals to export.")
|
|
61
|
+
parser.add_argument(
|
|
62
|
+
"--orb_square", action="store_true", help=("Additionally generate the square (RHO) for each MO.")
|
|
63
|
+
)
|
|
64
|
+
### -----------------------------------------------------------
|
|
65
|
+
parser.add_argument(
|
|
66
|
+
"--charge_dens", action="store_true", help=("Calculate charge density (all occupied orbitals are evaluated).")
|
|
67
|
+
)
|
|
68
|
+
parser.add_argument(
|
|
69
|
+
"--charge_dens_artif_core",
|
|
70
|
+
action="store_true",
|
|
71
|
+
help=("Calculate charge density with 'fake' artificial core (all occ orbitals are evaluated)."),
|
|
72
|
+
)
|
|
73
|
+
parser.add_argument(
|
|
74
|
+
"--spin_dens", action="store_true", help=("Calculate spin density (all occupied orbitals are evaluated).")
|
|
75
|
+
)
|
|
76
|
+
### -----------------------------------------------------------
|
|
77
|
+
parser.add_argument("--do_not_center_atoms", action="store_true", help=("Center atoms to cell."))
|
|
78
|
+
### -----------------------------------------------------------
|
|
79
|
+
|
|
80
|
+
time0 = time.time()
|
|
81
|
+
|
|
82
|
+
### ------------------------------------------------------
|
|
83
|
+
### Parse args for only one rank to suppress duplicate stdio
|
|
84
|
+
### ------------------------------------------------------
|
|
85
|
+
|
|
86
|
+
args = None
|
|
87
|
+
args_success = False
|
|
88
|
+
try:
|
|
89
|
+
if mpi_rank == 0:
|
|
90
|
+
args = parser.parse_args()
|
|
91
|
+
args_success = True
|
|
92
|
+
finally:
|
|
93
|
+
args_success = comm.bcast(args_success, root=0)
|
|
94
|
+
|
|
95
|
+
if not args_success:
|
|
96
|
+
print(mpi_rank, "exiting")
|
|
97
|
+
exit(0)
|
|
98
|
+
|
|
99
|
+
args = comm.bcast(args, root=0)
|
|
100
|
+
|
|
101
|
+
output_dir = args.output_dir if args.output_dir[-1] == "/" else args.output_dir + "/"
|
|
102
|
+
|
|
103
|
+
### ------------------------------------------------------
|
|
104
|
+
### Evaluate orbitals on the real-space grid
|
|
105
|
+
### ------------------------------------------------------
|
|
106
|
+
|
|
107
|
+
n_homo = args.n_homo
|
|
108
|
+
n_lumo = args.n_lumo
|
|
109
|
+
|
|
110
|
+
n_homo_range = n_homo
|
|
111
|
+
if args.charge_dens or args.spin_dens:
|
|
112
|
+
n_homo_range = None
|
|
113
|
+
|
|
114
|
+
mol_grid_orb = cgo.Cp2kGridOrbitals(mpi_rank, mpi_size, comm, single_precision=False)
|
|
115
|
+
mol_grid_orb.read_cp2k_input(args.cp2k_input_file)
|
|
116
|
+
mol_grid_orb.read_xyz(args.xyz_file)
|
|
117
|
+
if not args.do_not_center_atoms:
|
|
118
|
+
mol_grid_orb.center_atoms_to_cell()
|
|
119
|
+
mol_grid_orb.read_basis_functions(args.basis_set_file)
|
|
120
|
+
mol_grid_orb.load_restart_wfn_file(args.wfn_file, n_occ=n_homo_range, n_virt=n_lumo)
|
|
121
|
+
|
|
122
|
+
eval_reg = common.parse_eval_region_input(args.eval_region, mol_grid_orb.ase_atoms, mol_grid_orb.cell)
|
|
123
|
+
|
|
124
|
+
mol_grid_orb.calc_morbs_in_region(
|
|
125
|
+
args.dx,
|
|
126
|
+
x_eval_region=eval_reg[0],
|
|
127
|
+
y_eval_region=eval_reg[1],
|
|
128
|
+
z_eval_region=eval_reg[2],
|
|
129
|
+
pbc=np.array(args.pbc, dtype=bool),
|
|
130
|
+
reserve_extrap=0.0,
|
|
131
|
+
eval_cutoff=args.eval_cutoff,
|
|
132
|
+
)
|
|
133
|
+
|
|
134
|
+
### ------------------------------------------------------
|
|
135
|
+
### Export the data
|
|
136
|
+
### ------------------------------------------------------
|
|
137
|
+
|
|
138
|
+
ase_atoms = mol_grid_orb.ase_atoms
|
|
139
|
+
origin = mol_grid_orb.origin
|
|
140
|
+
cell = mol_grid_orb.eval_cell * np.eye(3)
|
|
141
|
+
vol_elem = np.prod(mol_grid_orb.dv)
|
|
142
|
+
|
|
143
|
+
for imo in np.arange(n_homo + n_lumo):
|
|
144
|
+
i_rel_homo = imo - n_homo + 1
|
|
145
|
+
for ispin in range(mol_grid_orb.nspin):
|
|
146
|
+
if imo >= len(mol_grid_orb.cwf.global_morb_indexes[ispin]):
|
|
147
|
+
continue
|
|
148
|
+
|
|
149
|
+
global_index = mol_grid_orb.cwf.global_morb_indexes[ispin][imo]
|
|
150
|
+
|
|
151
|
+
if i_rel_homo < 0:
|
|
152
|
+
hl_label = "HOMO%+d" % i_rel_homo
|
|
153
|
+
elif i_rel_homo == 0:
|
|
154
|
+
hl_label = "HOMO"
|
|
155
|
+
elif i_rel_homo == 1:
|
|
156
|
+
hl_label = "LUMO"
|
|
157
|
+
else:
|
|
158
|
+
hl_label = "LUMO%+d" % (i_rel_homo - 1)
|
|
159
|
+
|
|
160
|
+
name = "S%d_%d_%s" % (ispin, global_index, hl_label)
|
|
161
|
+
mol_grid_orb.write_cube(output_dir + name + ".cube", i_rel_homo, spin=ispin)
|
|
162
|
+
|
|
163
|
+
if args.orb_square:
|
|
164
|
+
mol_grid_orb.write_cube(output_dir + name + "_sq.cube", i_rel_homo, spin=ispin, square=True)
|
|
165
|
+
|
|
166
|
+
if args.charge_dens:
|
|
167
|
+
mol_grid_orb.calculate_and_save_charge_density(output_dir + "charge_density.cube")
|
|
168
|
+
if args.charge_dens_artif_core:
|
|
169
|
+
mol_grid_orb.calculate_and_save_charge_density(output_dir + "charge_density_artif.cube", artif_core=True)
|
|
170
|
+
|
|
171
|
+
if args.spin_dens:
|
|
172
|
+
mol_grid_orb.calculate_and_save_spin_density(output_dir + "spin_density.cube")
|
|
173
|
+
|
|
174
|
+
print("R%d/%d: finished, total time: %.2fs" % (mpi_rank, mpi_size, (time.time() - time0)))
|
|
175
|
+
|
|
176
|
+
|
|
177
|
+
if __name__ == "__main__":
|
|
178
|
+
main()
|
|
@@ -0,0 +1,114 @@
|
|
|
1
|
+
#!/usr/bin/env python
|
|
2
|
+
import argparse
|
|
3
|
+
import copy
|
|
4
|
+
import time
|
|
5
|
+
|
|
6
|
+
import numpy as np
|
|
7
|
+
|
|
8
|
+
from cp2k_spm_tools import cube, cube_utils
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
def main():
|
|
12
|
+
ang_2_bohr = 1.0 / 0.52917721067
|
|
13
|
+
|
|
14
|
+
parser = argparse.ArgumentParser(description="Operations on gaussian cube files.")
|
|
15
|
+
|
|
16
|
+
parser.add_argument("cubes", metavar="FILENAME", nargs="+", help="Gaussian cube files.")
|
|
17
|
+
|
|
18
|
+
parser.add_argument(
|
|
19
|
+
"operations", metavar="OP", type=str, help="Operations to apply to each cube. Enclose in quotation marks."
|
|
20
|
+
)
|
|
21
|
+
|
|
22
|
+
parser.add_argument(
|
|
23
|
+
"--proj_1d",
|
|
24
|
+
metavar="IDs",
|
|
25
|
+
type=str,
|
|
26
|
+
default="no",
|
|
27
|
+
help=("Projects to 'x', 'y' or 'z' dim, possibly averaging (e.g. 'z avg')."),
|
|
28
|
+
)
|
|
29
|
+
parser.add_argument("--skip_result_cube", action="store_true", help=("Don't write the result cube."))
|
|
30
|
+
parser.add_argument(
|
|
31
|
+
"--add_artif_core",
|
|
32
|
+
action="store_true",
|
|
33
|
+
help=("Adds artifical core charge to result cube (mainly for Bader analysis)."),
|
|
34
|
+
)
|
|
35
|
+
|
|
36
|
+
time0 = time.time()
|
|
37
|
+
|
|
38
|
+
args = parser.parse_args()
|
|
39
|
+
|
|
40
|
+
result = None
|
|
41
|
+
|
|
42
|
+
operations = args.operations.split()
|
|
43
|
+
|
|
44
|
+
if len(operations) != len(args.cubes):
|
|
45
|
+
print("Error: didn't find match between cubes and operations.")
|
|
46
|
+
print("Did you forget to enclose operations in quotation marks?")
|
|
47
|
+
exit(1)
|
|
48
|
+
|
|
49
|
+
for i_c, cube_file in enumerate(args.cubes):
|
|
50
|
+
time1 = time.time()
|
|
51
|
+
c = cube.Cube()
|
|
52
|
+
print("Reading %s..." % cube_file)
|
|
53
|
+
c.read_cube_file(cube_file)
|
|
54
|
+
|
|
55
|
+
if result is None:
|
|
56
|
+
result = copy.deepcopy(c)
|
|
57
|
+
result.data.fill(0)
|
|
58
|
+
|
|
59
|
+
if np.any(np.abs(c.cell - result.cell) > 1e-4):
|
|
60
|
+
print("Error: cube cell doesn't match: ", cube_file)
|
|
61
|
+
exit(1)
|
|
62
|
+
if np.any(c.data.shape != result.data.shape):
|
|
63
|
+
print("Error: cube shape doesn't match: ", cube_file)
|
|
64
|
+
exit(1)
|
|
65
|
+
|
|
66
|
+
op = operations[i_c]
|
|
67
|
+
|
|
68
|
+
if op == "+":
|
|
69
|
+
result.data += c.data
|
|
70
|
+
elif op == "-":
|
|
71
|
+
result.data -= c.data
|
|
72
|
+
elif op == "*":
|
|
73
|
+
result.data *= c.data
|
|
74
|
+
elif op == "/":
|
|
75
|
+
result.data /= c.data
|
|
76
|
+
|
|
77
|
+
print("%s done, time: %.2fs" % (cube_file, (time.time() - time1)))
|
|
78
|
+
|
|
79
|
+
if args.add_artif_core:
|
|
80
|
+
cube_utils.add_artif_core_charge(result)
|
|
81
|
+
|
|
82
|
+
if not args.skip_result_cube:
|
|
83
|
+
print("Writing result...")
|
|
84
|
+
result.write_cube_file("./result.cube")
|
|
85
|
+
|
|
86
|
+
proj_1d_ids = args.proj_1d.split()
|
|
87
|
+
|
|
88
|
+
if "no" not in proj_1d_ids:
|
|
89
|
+
avg = "avg" in proj_1d_ids
|
|
90
|
+
proj_dims = []
|
|
91
|
+
if "x" in proj_1d_ids:
|
|
92
|
+
proj_dims.append(0)
|
|
93
|
+
if "y" in proj_1d_ids:
|
|
94
|
+
proj_dims.append(1)
|
|
95
|
+
if "z" in proj_1d_ids:
|
|
96
|
+
proj_dims.append(2)
|
|
97
|
+
|
|
98
|
+
for pd in proj_dims:
|
|
99
|
+
if avg:
|
|
100
|
+
data_1d = np.mean(result.data, axis=tuple({0, 1, 2} - {pd}))
|
|
101
|
+
else:
|
|
102
|
+
data_1d = np.sum(result.data, axis=tuple({0, 1, 2} - {pd}))
|
|
103
|
+
x_arr = result.origin[pd] + np.linspace(0.0, result.cell[pd, pd], result.data.shape[pd])
|
|
104
|
+
x_arr /= ang_2_bohr
|
|
105
|
+
save_arr = np.column_stack((x_arr, data_1d))
|
|
106
|
+
avg_str = "_avg" if avg else ""
|
|
107
|
+
fname = "./proj_1d_%d" % pd + avg_str + ".txt"
|
|
108
|
+
np.savetxt(fname, save_arr)
|
|
109
|
+
|
|
110
|
+
print("Finished, total time: %.2fs" % (time.time() - time0))
|
|
111
|
+
|
|
112
|
+
|
|
113
|
+
if __name__ == "__main__":
|
|
114
|
+
main()
|