hecss 0.5.0.1__tar.gz → 0.7.0__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.
- hecss-0.7.0/PKG-INFO +118 -0
- hecss-0.7.0/README.md +73 -0
- hecss-0.7.0/hecss/__init__.py +4 -0
- hecss-0.7.0/hecss/cli.py +404 -0
- hecss-0.7.0/hecss/core.py +1139 -0
- {hecss-0.5.0.1 → hecss-0.7.0}/hecss/monitor.py +268 -158
- hecss-0.7.0/hecss/optimize.py +192 -0
- hecss-0.7.0/hecss/parallel.py +111 -0
- hecss-0.7.0/hecss/planner.py +60 -0
- hecss-0.7.0/hecss/util.py +169 -0
- hecss-0.7.0/hecss/xscale.py +23 -0
- hecss-0.7.0/hecss.egg-info/PKG-INFO +118 -0
- hecss-0.7.0/hecss.egg-info/SOURCES.txt +26 -0
- {hecss-0.5.0.1 → hecss-0.7.0}/hecss.egg-info/entry_points.txt +1 -0
- hecss-0.7.0/hecss.egg-info/requires.txt +25 -0
- hecss-0.7.0/pyproject.toml +67 -0
- hecss-0.7.0/tests/test_asap.py +105 -0
- hecss-0.7.0/tests/test_cli.py +286 -0
- hecss-0.7.0/tests/test_core.py +124 -0
- hecss-0.7.0/tests/test_monitor.py +96 -0
- hecss-0.7.0/tests/test_optimize.py +52 -0
- hecss-0.7.0/tests/test_util.py +73 -0
- hecss-0.7.0/tests/test_vasp.py +76 -0
- hecss-0.5.0.1/CONTRIBUTING.md +0 -26
- hecss-0.5.0.1/MANIFEST.in +0 -5
- hecss-0.5.0.1/PKG-INFO +0 -116
- hecss-0.5.0.1/README.md +0 -95
- hecss-0.5.0.1/hecss/__init__.py +0 -1
- hecss-0.5.0.1/hecss/_nbdev.py +0 -44
- hecss-0.5.0.1/hecss/cli.py +0 -211
- hecss-0.5.0.1/hecss/core.py +0 -560
- hecss-0.5.0.1/hecss.egg-info/PKG-INFO +0 -116
- hecss-0.5.0.1/hecss.egg-info/SOURCES.txt +0 -19
- hecss-0.5.0.1/hecss.egg-info/not-zip-safe +0 -1
- hecss-0.5.0.1/hecss.egg-info/requires.txt +0 -8
- hecss-0.5.0.1/settings.ini +0 -30
- hecss-0.5.0.1/setup.py +0 -47
- {hecss-0.5.0.1 → hecss-0.7.0}/COPYING +0 -0
- {hecss-0.5.0.1 → hecss-0.7.0}/LICENSE +0 -0
- {hecss-0.5.0.1 → hecss-0.7.0}/hecss.egg-info/dependency_links.txt +0 -0
- {hecss-0.5.0.1 → hecss-0.7.0}/hecss.egg-info/top_level.txt +0 -0
- {hecss-0.5.0.1 → hecss-0.7.0}/setup.cfg +0 -0
hecss-0.7.0/PKG-INFO
ADDED
|
@@ -0,0 +1,118 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: hecss
|
|
3
|
+
Version: 0.7.0
|
|
4
|
+
Summary: High Efficiency Configuration Space Sampler
|
|
5
|
+
Author-email: "Paweł T. Jochym" <pawel.jochym@ifj.edu.pl>
|
|
6
|
+
License: GPL-3.0-or-later
|
|
7
|
+
Project-URL: Repository, https://github.com/jochym/hecss/
|
|
8
|
+
Project-URL: Documentation, https://jochym.github.io/hecss/
|
|
9
|
+
Keywords: physics
|
|
10
|
+
Classifier: Development Status :: 3 - Alpha
|
|
11
|
+
Classifier: Intended Audience :: Science/Research
|
|
12
|
+
Classifier: Natural Language :: English
|
|
13
|
+
Classifier: Programming Language :: Python :: 3.9
|
|
14
|
+
Classifier: Programming Language :: Python :: 3.10
|
|
15
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
16
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
17
|
+
Classifier: License :: OSI Approved :: GNU General Public License v3 (GPLv3)
|
|
18
|
+
Requires-Python: >=3.9
|
|
19
|
+
Description-Content-Type: text/markdown
|
|
20
|
+
License-File: LICENSE
|
|
21
|
+
License-File: COPYING
|
|
22
|
+
Requires-Dist: fastcore>=1.5
|
|
23
|
+
Requires-Dist: numpy
|
|
24
|
+
Requires-Dist: scipy
|
|
25
|
+
Requires-Dist: ase
|
|
26
|
+
Requires-Dist: spglib
|
|
27
|
+
Requires-Dist: tqdm
|
|
28
|
+
Requires-Dist: click
|
|
29
|
+
Requires-Dist: matplotlib
|
|
30
|
+
Requires-Dist: ipython
|
|
31
|
+
Provides-Extra: test
|
|
32
|
+
Requires-Dist: pytest>=7; extra == "test"
|
|
33
|
+
Requires-Dist: asap3; extra == "test"
|
|
34
|
+
Provides-Extra: docs
|
|
35
|
+
Requires-Dist: mkdocs-material>=9; extra == "docs"
|
|
36
|
+
Requires-Dist: mkdocstrings[python]>=0.24; extra == "docs"
|
|
37
|
+
Provides-Extra: dev
|
|
38
|
+
Requires-Dist: pytest>=7; extra == "dev"
|
|
39
|
+
Requires-Dist: asap3; extra == "dev"
|
|
40
|
+
Requires-Dist: build; extra == "dev"
|
|
41
|
+
Requires-Dist: twine; extra == "dev"
|
|
42
|
+
Requires-Dist: mkdocs-material>=9; extra == "dev"
|
|
43
|
+
Requires-Dist: mkdocstrings[python]>=0.24; extra == "dev"
|
|
44
|
+
Dynamic: license-file
|
|
45
|
+
|
|
46
|
+
# HECSS
|
|
47
|
+
|
|
48
|
+
[](https://pypi.org/project/hecss/)
|
|
49
|
+
[](https://github.com/jochym/hecss/actions/workflows/test.yaml)
|
|
50
|
+
[](COPYING)
|
|
51
|
+
|
|
52
|
+
HECSS is a Monte-Carlo configuration space sampler using a sample weighting
|
|
53
|
+
algorithm for probability distribution sampling. It provides an alternative
|
|
54
|
+
way to create representations of systems at thermal equilibrium without
|
|
55
|
+
running an expensive molecular dynamics simulation. The theoretical
|
|
56
|
+
foundation is described in [SciPost Phys. 10, 129 (2021)](https://scipost.org/SciPostPhys.10.6.129)
|
|
57
|
+
and summarised in the [Background](https://jochym.github.io/hecss/background/) page
|
|
58
|
+
of the [documentation](https://jochym.github.io/hecss/).
|
|
59
|
+
|
|
60
|
+
## Quick start
|
|
61
|
+
|
|
62
|
+
```python
|
|
63
|
+
from hecss import HECSS
|
|
64
|
+
from hecss.util import select_asap_model, create_asap_calculator
|
|
65
|
+
from ase.build import bulk
|
|
66
|
+
|
|
67
|
+
model = select_asap_model('SiC')
|
|
68
|
+
cryst = bulk('SiC', crystalstructure='zincblende',
|
|
69
|
+
a=4.38120844, cubic=True).repeat((3, 3, 3))
|
|
70
|
+
cryst.calc = create_asap_calculator(model)
|
|
71
|
+
sampler = HECSS(cryst, lambda: create_asap_calculator(model))
|
|
72
|
+
samples = sampler.sample(300, 100)
|
|
73
|
+
distribution = sampler.generate(samples, 300)
|
|
74
|
+
```
|
|
75
|
+
|
|
76
|
+
The [documentation](https://jochym.github.io/hecss/) has the full worked example,
|
|
77
|
+
including plotting the resulting energy distribution.
|
|
78
|
+
|
|
79
|
+
## Installation
|
|
80
|
+
|
|
81
|
+
```bash
|
|
82
|
+
pip install hecss
|
|
83
|
+
```
|
|
84
|
+
|
|
85
|
+
or, with conda:
|
|
86
|
+
|
|
87
|
+
```bash
|
|
88
|
+
conda install -c conda-forge hecss
|
|
89
|
+
```
|
|
90
|
+
|
|
91
|
+
## Development
|
|
92
|
+
|
|
93
|
+
The project uses a local `uv` environment:
|
|
94
|
+
|
|
95
|
+
```bash
|
|
96
|
+
uv venv
|
|
97
|
+
uv pip install -e '.[dev]'
|
|
98
|
+
.venv/bin/python -m pytest # fast tests
|
|
99
|
+
.venv/bin/python -m pytest -m asap # ASAP3/OpenKIM integration tests
|
|
100
|
+
.venv/bin/python -m pytest -m vasp # VASP tests, dedicated environment only
|
|
101
|
+
.venv/bin/mkdocs build --strict # documentation
|
|
102
|
+
```
|
|
103
|
+
|
|
104
|
+
VASP tests require a VASP executable and a working setup in the dedicated
|
|
105
|
+
environment; set `HECSS_VASP_COMMAND` if VASP is invoked through a wrapper.
|
|
106
|
+
|
|
107
|
+
## Documentation and source
|
|
108
|
+
|
|
109
|
+
Full documentation: <https://jochym.github.io/hecss/>
|
|
110
|
+
Source code: <https://github.com/jochym/hecss>
|
|
111
|
+
|
|
112
|
+
## Citation
|
|
113
|
+
|
|
114
|
+
Please cite SciPost Phys. 10, 129 (2021) in any work using this code.
|
|
115
|
+
|
|
116
|
+
## License
|
|
117
|
+
|
|
118
|
+
GPL-3.0-or-later. See [COPYING](COPYING).
|
hecss-0.7.0/README.md
ADDED
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
# HECSS
|
|
2
|
+
|
|
3
|
+
[](https://pypi.org/project/hecss/)
|
|
4
|
+
[](https://github.com/jochym/hecss/actions/workflows/test.yaml)
|
|
5
|
+
[](COPYING)
|
|
6
|
+
|
|
7
|
+
HECSS is a Monte-Carlo configuration space sampler using a sample weighting
|
|
8
|
+
algorithm for probability distribution sampling. It provides an alternative
|
|
9
|
+
way to create representations of systems at thermal equilibrium without
|
|
10
|
+
running an expensive molecular dynamics simulation. The theoretical
|
|
11
|
+
foundation is described in [SciPost Phys. 10, 129 (2021)](https://scipost.org/SciPostPhys.10.6.129)
|
|
12
|
+
and summarised in the [Background](https://jochym.github.io/hecss/background/) page
|
|
13
|
+
of the [documentation](https://jochym.github.io/hecss/).
|
|
14
|
+
|
|
15
|
+
## Quick start
|
|
16
|
+
|
|
17
|
+
```python
|
|
18
|
+
from hecss import HECSS
|
|
19
|
+
from hecss.util import select_asap_model, create_asap_calculator
|
|
20
|
+
from ase.build import bulk
|
|
21
|
+
|
|
22
|
+
model = select_asap_model('SiC')
|
|
23
|
+
cryst = bulk('SiC', crystalstructure='zincblende',
|
|
24
|
+
a=4.38120844, cubic=True).repeat((3, 3, 3))
|
|
25
|
+
cryst.calc = create_asap_calculator(model)
|
|
26
|
+
sampler = HECSS(cryst, lambda: create_asap_calculator(model))
|
|
27
|
+
samples = sampler.sample(300, 100)
|
|
28
|
+
distribution = sampler.generate(samples, 300)
|
|
29
|
+
```
|
|
30
|
+
|
|
31
|
+
The [documentation](https://jochym.github.io/hecss/) has the full worked example,
|
|
32
|
+
including plotting the resulting energy distribution.
|
|
33
|
+
|
|
34
|
+
## Installation
|
|
35
|
+
|
|
36
|
+
```bash
|
|
37
|
+
pip install hecss
|
|
38
|
+
```
|
|
39
|
+
|
|
40
|
+
or, with conda:
|
|
41
|
+
|
|
42
|
+
```bash
|
|
43
|
+
conda install -c conda-forge hecss
|
|
44
|
+
```
|
|
45
|
+
|
|
46
|
+
## Development
|
|
47
|
+
|
|
48
|
+
The project uses a local `uv` environment:
|
|
49
|
+
|
|
50
|
+
```bash
|
|
51
|
+
uv venv
|
|
52
|
+
uv pip install -e '.[dev]'
|
|
53
|
+
.venv/bin/python -m pytest # fast tests
|
|
54
|
+
.venv/bin/python -m pytest -m asap # ASAP3/OpenKIM integration tests
|
|
55
|
+
.venv/bin/python -m pytest -m vasp # VASP tests, dedicated environment only
|
|
56
|
+
.venv/bin/mkdocs build --strict # documentation
|
|
57
|
+
```
|
|
58
|
+
|
|
59
|
+
VASP tests require a VASP executable and a working setup in the dedicated
|
|
60
|
+
environment; set `HECSS_VASP_COMMAND` if VASP is invoked through a wrapper.
|
|
61
|
+
|
|
62
|
+
## Documentation and source
|
|
63
|
+
|
|
64
|
+
Full documentation: <https://jochym.github.io/hecss/>
|
|
65
|
+
Source code: <https://github.com/jochym/hecss>
|
|
66
|
+
|
|
67
|
+
## Citation
|
|
68
|
+
|
|
69
|
+
Please cite SciPost Phys. 10, 129 (2021) in any work using this code.
|
|
70
|
+
|
|
71
|
+
## License
|
|
72
|
+
|
|
73
|
+
GPL-3.0-or-later. See [COPYING](COPYING).
|
hecss-0.7.0/hecss/cli.py
ADDED
|
@@ -0,0 +1,404 @@
|
|
|
1
|
+
"""The command line interface for the HECSS sampler"""
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
__all__ = ['hecss_sampler', 'plot_stats', 'plot_bands', 'calculate_xscale',
|
|
5
|
+
'reshape_sample', 'dfset_writer', 'xsl_writer']
|
|
6
|
+
|
|
7
|
+
import ast
|
|
8
|
+
import math
|
|
9
|
+
import os
|
|
10
|
+
import shlex
|
|
11
|
+
from pathlib import Path
|
|
12
|
+
|
|
13
|
+
import ase
|
|
14
|
+
import click
|
|
15
|
+
from ase import units as un
|
|
16
|
+
from ase.calculators.vasp import Vasp
|
|
17
|
+
from numpy import array, loadtxt, savetxt, sqrt
|
|
18
|
+
|
|
19
|
+
import hecss
|
|
20
|
+
from hecss import *
|
|
21
|
+
from hecss.optimize import make_sampling
|
|
22
|
+
from hecss.util import calc_init_xscale, write_dfset
|
|
23
|
+
|
|
24
|
+
_version_message=("HECSS, version %(version)s\n"
|
|
25
|
+
'High Efficiency Configuration Space Sampler\n'
|
|
26
|
+
'(C) 2021-2024 by Paweł T. Jochym\n'
|
|
27
|
+
' License: GPL v3 or later')
|
|
28
|
+
|
|
29
|
+
def _save_xsl(workdir, scale, xsl, sl):
|
|
30
|
+
if scale and xsl:
|
|
31
|
+
with open(Path(workdir).joinpath(scale), 'at') as sf:
|
|
32
|
+
for xs in xsl:
|
|
33
|
+
savetxt(sf, xs, fmt='%8.5f',
|
|
34
|
+
header=f'{xs.shape}, {len(sl)}, {len(xsl)}')
|
|
35
|
+
xsl.clear()
|
|
36
|
+
|
|
37
|
+
|
|
38
|
+
def xsl_writer(s, sl, workdir='', dfset='', scale='', xsl=None):
|
|
39
|
+
"""Append amplitude corrections to the scale file without writing DFSET data.
|
|
40
|
+
|
|
41
|
+
Used as the sampler sentinel when ``--nodfset`` is combined with
|
|
42
|
+
``--scale``. `s`, `sl` and `dfset` are unused; they match the sentinel
|
|
43
|
+
callback signature. Always returns `False` to keep sampling going.
|
|
44
|
+
"""
|
|
45
|
+
_save_xsl(workdir, scale, xsl, sl)
|
|
46
|
+
return False
|
|
47
|
+
|
|
48
|
+
|
|
49
|
+
def dfset_writer(s, sl, workdir='', dfset='', scale='', xsl=None):
|
|
50
|
+
'''
|
|
51
|
+
Write one sample to the DFSET file in `workdir`.
|
|
52
|
+
|
|
53
|
+
`s` is a sample tuple; `sl` is unused and exists only to match the
|
|
54
|
+
sentinel callback signature. If `scale` and `xsl` are both set, the
|
|
55
|
+
accumulated amplitude corrections are appended to the scale file and
|
|
56
|
+
`xsl` is cleared. Always
|
|
57
|
+
returns `False`, so it can be used as a sampler sentinel.
|
|
58
|
+
'''
|
|
59
|
+
wd = Path(workdir)
|
|
60
|
+
write_dfset(f'{wd.joinpath(dfset)}.raw', s)
|
|
61
|
+
_save_xsl(workdir, scale, xsl, sl)
|
|
62
|
+
# Important! Return False to keep iteration going
|
|
63
|
+
return False
|
|
64
|
+
|
|
65
|
+
@click.command()
|
|
66
|
+
@click.argument('fname', type=click.Path(exists=True))
|
|
67
|
+
@click.option('-W', '--workdir', default="WORK", type=click.Path(exists=True), help="Work directory")
|
|
68
|
+
@click.option('-l', '--label', default="hecss", help="Label for the calculations.")
|
|
69
|
+
@click.option('-T', '--temp', default=300, type=float, help="Target temperature in Kelvin.")
|
|
70
|
+
@click.option('-w', '--width', default=None, type=float, help="Initial scale of the prior distribution")
|
|
71
|
+
@click.option('-a', '--ampl', default='', type=click.Path(), help='Initialise amplitude correction from the file.')
|
|
72
|
+
@click.option('-s', '--scale', default='', type=click.Path(), help='Save amplitude correction history')
|
|
73
|
+
@click.option('-m', '--symprec', default=1e-5, type=float, help='Symmetry search tolerance.')
|
|
74
|
+
@click.option('-C', '--calc', default="VASP", type=str,
|
|
75
|
+
help="ASE calculator to be used for the job. "
|
|
76
|
+
"Supported calculators: VASP (default)")
|
|
77
|
+
@click.option('-S', '--setups', default="guess", type=str,
|
|
78
|
+
help="setups parameter of the calculator to force use of the "
|
|
79
|
+
"particular variants of pseudopotentials in the calculations. "
|
|
80
|
+
"By default pseudopotentials are guessed from the POTCAR in "
|
|
81
|
+
"the supercell directory.")
|
|
82
|
+
@click.option('-n', '--nodfset', is_flag=True, default=False, help='Do not write DFSET file for ALAMODE')
|
|
83
|
+
@click.option('-d', '--dfset', default='DFSET.dat', help='Name of the DFSET file')
|
|
84
|
+
@click.option('-N', '--nsamples', default=10, type=int, help="Number of samples to be generated")
|
|
85
|
+
@click.option('-e', '--neta', default=2, type=int,
|
|
86
|
+
help="Number of samples for width scale estimation (ignored when -w is given)")
|
|
87
|
+
@click.option('-c', '--command', default='./run-calc', help="Command to run calculator")
|
|
88
|
+
@click.option('-k', '--nwork', default=None, type=int, help="Parallel workers for width estimation only (0=unlimited); sampling runs serially")
|
|
89
|
+
@click.option('-p', '--pbar/--no-pbar', default=True,
|
|
90
|
+
help="Show or hide the progress bar (shown by default)")
|
|
91
|
+
@click.version_option(hecss.__version__, '-V', '--version', message=_version_message)
|
|
92
|
+
@click.help_option('-h', '--help')
|
|
93
|
+
def hecss_sampler(fname, workdir, label, temp, width, ampl, scale, symprec, calc, setups, nodfset, dfset, nsamples, neta, command, nwork, pbar):
|
|
94
|
+
'''
|
|
95
|
+
Run HECSS sampler on the structure in the provided file (FNAME).\b
|
|
96
|
+
Read the docs at: https://jochym.github.io/hecss/
|
|
97
|
+
|
|
98
|
+
\b
|
|
99
|
+
FNAME - Supercell structure file. The containing
|
|
100
|
+
directory must be readable by Vasp(restart).
|
|
101
|
+
Usually this is a CONTCAR file for a supercell.
|
|
102
|
+
'''
|
|
103
|
+
|
|
104
|
+
if not math.isfinite(temp) or temp <= 0:
|
|
105
|
+
print(f'Invalid temperature {temp}. Use a finite value above 0 K.')
|
|
106
|
+
return
|
|
107
|
+
|
|
108
|
+
print(f'HECSS ({hecss.__version__})\n'
|
|
109
|
+
f'Supercell: {fname}\n'
|
|
110
|
+
f'Temperature: {temp}K\n'
|
|
111
|
+
f'Work directory: {workdir}\n'
|
|
112
|
+
f'Calculator: {calc}')
|
|
113
|
+
|
|
114
|
+
src_path = Path(fname)
|
|
115
|
+
workdir = Path(workdir)
|
|
116
|
+
Ep0 = None
|
|
117
|
+
if calc=="VASP":
|
|
118
|
+
calculator = Vasp(label=label, directory=src_path.parent, restart=True)
|
|
119
|
+
Ep0 = calculator.get_potential_energy()
|
|
120
|
+
cryst = ase.Atoms(calculator.atoms)
|
|
121
|
+
cryst.calc = calculator
|
|
122
|
+
calculator.set(directory=workdir)
|
|
123
|
+
command = Path(command)
|
|
124
|
+
calculator.set(command=f'{shlex.quote(str(command.absolute()))} {shlex.quote(str(label))}')
|
|
125
|
+
calculator.set(nsw=0)
|
|
126
|
+
if setups :
|
|
127
|
+
if setups=='guess':
|
|
128
|
+
setups = {}
|
|
129
|
+
with open(src_path.parent / Path("POTCAR"), "r") as pf:
|
|
130
|
+
for l in pf.readlines():
|
|
131
|
+
if "TITEL" in l:
|
|
132
|
+
l = l.strip().split()[3].split("_")
|
|
133
|
+
el = l[0]
|
|
134
|
+
st = ""
|
|
135
|
+
if len(l)>1:
|
|
136
|
+
st = f"_{l[1]}"
|
|
137
|
+
setups[el] = st
|
|
138
|
+
print(f"Setups guessed from {src_path.parent / Path('POTCAR')}: {setups}")
|
|
139
|
+
else :
|
|
140
|
+
if setups in {'recommended', 'minimal', 'gw'}:
|
|
141
|
+
# We do not need to parse these. Just use as is
|
|
142
|
+
pass
|
|
143
|
+
else :
|
|
144
|
+
# Parse into dict
|
|
145
|
+
setups = ast.literal_eval(setups)
|
|
146
|
+
print(f"Setups forced: {setups}")
|
|
147
|
+
calculator.set(setups=setups)
|
|
148
|
+
else:
|
|
149
|
+
print(f'The {calc} calculator is not supported.')
|
|
150
|
+
return
|
|
151
|
+
|
|
152
|
+
if nodfset:
|
|
153
|
+
# Scale history is still written when -s is requested.
|
|
154
|
+
sentinel = xsl_writer if scale else None
|
|
155
|
+
else:
|
|
156
|
+
sentinel = dfset_writer
|
|
157
|
+
|
|
158
|
+
xsl = None
|
|
159
|
+
if scale:
|
|
160
|
+
xsl = []
|
|
161
|
+
|
|
162
|
+
wl = []
|
|
163
|
+
|
|
164
|
+
sampler = HECSS(cryst, calculator, directory=workdir, width=width, pbar=pbar)
|
|
165
|
+
sampler.Ep0 = Ep0
|
|
166
|
+
|
|
167
|
+
if ampl:
|
|
168
|
+
sampler.xscale_init = loadtxt(ampl)
|
|
169
|
+
|
|
170
|
+
if width is not None:
|
|
171
|
+
# Explicit width supersedes the default (or requested) estimation.
|
|
172
|
+
neta = 0
|
|
173
|
+
|
|
174
|
+
if nsamples < 2 and scale:
|
|
175
|
+
print('Need at least 2 samples (-N 2) to calculate amplitudes (-s).')
|
|
176
|
+
print('Refusing the job.')
|
|
177
|
+
return
|
|
178
|
+
|
|
179
|
+
if nsamples < 1:
|
|
180
|
+
print('WARNING: No samples will be generated (N=0)')
|
|
181
|
+
print('Continue with the job')
|
|
182
|
+
|
|
183
|
+
if width is None and neta > 0:
|
|
184
|
+
if (workdir/'w_est').exists() :
|
|
185
|
+
print(f'Directory {workdir/"w_est"} exists.')
|
|
186
|
+
print('Make sure you specified correct working directory.')
|
|
187
|
+
print('I refuse to overwrite existing calculations.')
|
|
188
|
+
print(f'Either specify w on the command line, \n'
|
|
189
|
+
f'or remove w_est directory from {workdir}.')
|
|
190
|
+
if (workdir/'w_est/w_est.dat').exists():
|
|
191
|
+
wm = loadtxt(workdir/'w_est/w_est.dat').T
|
|
192
|
+
y = sqrt((3*wm[1]*un.kB)/(2*wm[2]))
|
|
193
|
+
print(f'Width scale from {workdir/"w_est/w_est.dat"} data: {y.mean():.3g}+/-{y.std():.3g}')
|
|
194
|
+
return
|
|
195
|
+
print('Estimating width scale.')
|
|
196
|
+
eta, sigma, xscale = sampler.estimate_width_scale(neta, Tmin=temp/2, Tmax=temp, pbar=sampler._pbar, nwork=nwork)
|
|
197
|
+
if nsamples < 2:
|
|
198
|
+
print(f'Width scale from {neta} pts.: {eta:.3g}+/-{sigma:.3g}')
|
|
199
|
+
print('Width scale estimation run (N<2). Not running sampling.')
|
|
200
|
+
return
|
|
201
|
+
|
|
202
|
+
if (workdir/f"T_{temp:.1f}K").exists():
|
|
203
|
+
print(f'Directory {workdir/f"T_{temp:.1f}K"} exists.')
|
|
204
|
+
print('Make sure you specified correct working directory.')
|
|
205
|
+
print('I refuse to overwrite existing calculations.')
|
|
206
|
+
print(f'Correct your workdir or move {workdir/f"T_{temp:.1f}K"} to a different location.')
|
|
207
|
+
return
|
|
208
|
+
|
|
209
|
+
if not nodfset:
|
|
210
|
+
df_path = workdir / dfset
|
|
211
|
+
if df_path.exists():
|
|
212
|
+
old_t = None
|
|
213
|
+
with df_path.open() as df:
|
|
214
|
+
for line in df:
|
|
215
|
+
if line.startswith('## T='):
|
|
216
|
+
try:
|
|
217
|
+
old_t = float(line[5:])
|
|
218
|
+
except ValueError:
|
|
219
|
+
pass
|
|
220
|
+
if old_t is not None and not math.isclose(old_t, temp, abs_tol=1e-6):
|
|
221
|
+
print(f'WARNING: {df_path} already contains data for T={old_t:.1f} K; '
|
|
222
|
+
f'appending data for T={temp:.1f} K.')
|
|
223
|
+
|
|
224
|
+
print('Sampling configurations')
|
|
225
|
+
samples = sampler.sample(temp, nsamples,
|
|
226
|
+
width_list=wl,
|
|
227
|
+
sentinel=sentinel,
|
|
228
|
+
sentinel_args={'workdir': f'{workdir}/T_{temp:.1f}K/',
|
|
229
|
+
'dfset': dfset,
|
|
230
|
+
'scale': scale,
|
|
231
|
+
'xsl': xsl
|
|
232
|
+
},
|
|
233
|
+
xscale_list=xsl,
|
|
234
|
+
symprec=symprec)
|
|
235
|
+
if not samples:
|
|
236
|
+
print('No samples generated (N<1).')
|
|
237
|
+
return
|
|
238
|
+
# generate distribution centered at mean energy
|
|
239
|
+
T_m = 2*array([s[-1] for s in samples]).mean()/3/un.kB
|
|
240
|
+
print(f'Generating distribution centered at: {T_m:.3f} K')
|
|
241
|
+
distr = sampler.generate(samples, T_m)
|
|
242
|
+
if len(wl)>1 :
|
|
243
|
+
wl = array(wl).T
|
|
244
|
+
# print(wl.shape)
|
|
245
|
+
print(f'Average width scale ({len(wl[0])} pnts): {wl[0].mean():.3g}+/-{wl[0].std():.3g}')
|
|
246
|
+
|
|
247
|
+
if not nodfset:
|
|
248
|
+
wd = Path(workdir)
|
|
249
|
+
for i, s in enumerate(distr):
|
|
250
|
+
write_dfset(f'{wd.joinpath(dfset)}', s,
|
|
251
|
+
comment=f'T={temp:.1f}' if i == 0 else '')
|
|
252
|
+
|
|
253
|
+
return
|
|
254
|
+
|
|
255
|
+
@click.command()
|
|
256
|
+
@click.argument('supercell', type=click.Path(exists=True))
|
|
257
|
+
@click.argument('scale', type=click.Path(exists=True))
|
|
258
|
+
@click.option('-o', '--output', type=click.Path(), required=True, help='Write output to the file.')
|
|
259
|
+
@click.option('-s', '--skip', default=0, type=int, help='Skip this number of samples at the beginning')
|
|
260
|
+
@click.version_option(hecss.__version__, '-V', '--version', message=_version_message)
|
|
261
|
+
@click.help_option('-h', '--help')
|
|
262
|
+
def calculate_xscale(supercell, scale, output, skip):
|
|
263
|
+
'''
|
|
264
|
+
Calculate initial values for amplitude correction coefficients
|
|
265
|
+
from the scale file data for the specified supercell.
|
|
266
|
+
'''
|
|
267
|
+
sc = ase.io.read(supercell)
|
|
268
|
+
xsl = loadtxt(scale).reshape((-1, len(sc), 3))
|
|
269
|
+
xsi = calc_init_xscale(sc, xsl, skip=skip if skip else None)
|
|
270
|
+
savetxt(output, xsi, fmt='%9.4f')
|
|
271
|
+
print(f'Done. The initial scale saved to: {output}')
|
|
272
|
+
|
|
273
|
+
@click.command()
|
|
274
|
+
@click.argument('dfset', type=click.Path(exists=True))
|
|
275
|
+
@click.argument('T', default=-1, type=float)
|
|
276
|
+
@click.option('-N', '--nmul', default=4, type=int, help="Sample length multiplier (default: 4)")
|
|
277
|
+
@click.option('-p', '--prob', type=float, default=0.25, help='Probability treshold (default: 0.25)')
|
|
278
|
+
@click.option('-w', is_flag=True, default=True, help='Force non-zero weights for samples above probability treshold. (default: True)')
|
|
279
|
+
@click.option('-b', is_flag=True, default=False, help='Border samples account for the rest of domain')
|
|
280
|
+
@click.option('-c', '--check', type=click.Path(), default="", help='Check and skip unconverged samples in calc directory.')
|
|
281
|
+
@click.option('-o', '--output', type=click.Path(), required=True, help='Write output to the file.')
|
|
282
|
+
@click.option('-d', is_flag=True, default=False, help='Plot debug plots')
|
|
283
|
+
@click.version_option(hecss.__version__, '-V', '--version', message=_version_message)
|
|
284
|
+
def reshape_sample(dfset, t, nmul, prob, w, check, b, output, d):
|
|
285
|
+
'''
|
|
286
|
+
Reshape the sample to the normal distribution centered around mean energy (temperature),
|
|
287
|
+
or around provided temperature T (Kelvin). The reshaping is done by adjusting weighting
|
|
288
|
+
of the samples by repeating the ones which should be up-weighted.
|
|
289
|
+
The parameters are the variants of the weighting algorithm (see the docs).\b
|
|
290
|
+
|
|
291
|
+
The procedure reads and produces a file with in the DFSET format.
|
|
292
|
+
For the 'check' function to work the parameter must point to the root directory
|
|
293
|
+
of the calculated samples. The checked directories will be in the form: '{root}/nnnn'.
|
|
294
|
+
|
|
295
|
+
In check mode the raw file is *not* reshaped, just filtered.
|
|
296
|
+
'''
|
|
297
|
+
from hecss.util import load_dfset
|
|
298
|
+
p = Path(dfset)
|
|
299
|
+
smpl = load_dfset(p)
|
|
300
|
+
|
|
301
|
+
if check :
|
|
302
|
+
from tqdm.auto import tqdm
|
|
303
|
+
print(f"Checking convergence in {check}/nnnn")
|
|
304
|
+
configs = {i for n, i, x, f, e in smpl}
|
|
305
|
+
converged = {i for i in tqdm(configs)
|
|
306
|
+
if Vasp(restart=True, directory=f'{check}/{i:04d}').converged}
|
|
307
|
+
print(f"Number of converged calculations: {len(converged)}/{len(configs)}")
|
|
308
|
+
dist = [s for s in smpl if s[1] in converged]
|
|
309
|
+
print(f"Rewriting the raw dfset (skipping reshape).")
|
|
310
|
+
else :
|
|
311
|
+
if t < 0:
|
|
312
|
+
t = 2*array([s[-1] for s in smpl]).mean()/3/un.kB
|
|
313
|
+
dist = make_sampling(smpl, t, border=b, probTH=prob, Nmul=nmul, nonzero_w=w, debug=d)
|
|
314
|
+
print(f'Done. Distribution reshaped to {t:.2f} K.')
|
|
315
|
+
|
|
316
|
+
print(f'Done. Saving to: {output}')
|
|
317
|
+
for s in dist:
|
|
318
|
+
write_dfset(output, s)
|
|
319
|
+
|
|
320
|
+
|
|
321
|
+
@click.command()
|
|
322
|
+
@click.argument('dfset', type=click.Path(exists=True))
|
|
323
|
+
@click.argument('T', default=-1, type=float)
|
|
324
|
+
@click.option('-n', '--sqrn', is_flag=True, help='Show sqrt(N) bars on the histogram.')
|
|
325
|
+
@click.option('-s', '--sixel', is_flag=True, help='Use SixEl driver for terminal graphics.')
|
|
326
|
+
@click.option('-w', '--width', type=float, default=6, help='Width of the figure.')
|
|
327
|
+
@click.option('-h', '--height', type=float, default=4, help='Height of the figure.')
|
|
328
|
+
@click.option('-o', '--output', type=click.Path(), default="", help='Write output to the file.')
|
|
329
|
+
@click.option('-x', is_flag=True, default=False, help='Make plot in an interactive window')
|
|
330
|
+
@click.version_option(hecss.__version__, '-V', '--version', message=_version_message)
|
|
331
|
+
def plot_stats( dfset, t, output, x, sixel, sqrn, width, height):
|
|
332
|
+
"""
|
|
333
|
+
Plot the statistics of the samples from the DFSET file.
|
|
334
|
+
Use T(K) as a reference target temperature. Optionally
|
|
335
|
+
write out the plot to the output graphics file.
|
|
336
|
+
"""
|
|
337
|
+
import matplotlib.pylab as plt
|
|
338
|
+
|
|
339
|
+
from hecss.monitor import plot_stats
|
|
340
|
+
from hecss.util import load_dfset
|
|
341
|
+
|
|
342
|
+
p = Path(dfset)
|
|
343
|
+
smpl = load_dfset(p)
|
|
344
|
+
plt.figure(figsize=(float(width), float(height)))
|
|
345
|
+
plot_stats(smpl, T=t if t >0 else None, sqrN=sqrn, show=x)
|
|
346
|
+
if output:
|
|
347
|
+
plt.savefig(output)
|
|
348
|
+
if sixel:
|
|
349
|
+
try :
|
|
350
|
+
import sixelplot
|
|
351
|
+
except ImportError:
|
|
352
|
+
print('SixEl graphics support not installed. Install sixelplot package.')
|
|
353
|
+
return
|
|
354
|
+
sixelplot.show()
|
|
355
|
+
|
|
356
|
+
@click.command()
|
|
357
|
+
@click.argument('bands', type=click.Path(exists=True), nargs=-1)
|
|
358
|
+
@click.option('-s', '--sixel', is_flag=True, help='Use SixEl driver for terminal graphics.')
|
|
359
|
+
@click.option('-n', '--nodecor', is_flag=True, help='Decorate the plot.')
|
|
360
|
+
@click.option('-w', '--width', type=float, default=6, help='Width of the figure.')
|
|
361
|
+
@click.option('-h', '--height', type=float, default=4, help='Height of the figure.')
|
|
362
|
+
@click.option('-o', '--output', type=click.Path(), default="",
|
|
363
|
+
help='Write output to the file.')
|
|
364
|
+
@click.option('-l', '--label', type=str, default="",
|
|
365
|
+
help='Label(s) for the plot. Comma-separated list')
|
|
366
|
+
@click.option('-x', is_flag=True, default=False,
|
|
367
|
+
help='Make plot in an interactive window')
|
|
368
|
+
@click.version_option(hecss.__version__, '-V', '--version', message=_version_message)
|
|
369
|
+
def plot_bands( bands, output, x, sixel, width, height, label, nodecor):
|
|
370
|
+
"""
|
|
371
|
+
Plot the phonon dispersion from the file generated by ALAMODE.
|
|
372
|
+
Optionally write out the plot to the output graphics file.
|
|
373
|
+
"""
|
|
374
|
+
import matplotlib.pylab as plt
|
|
375
|
+
|
|
376
|
+
import hecss.monitor as hm
|
|
377
|
+
|
|
378
|
+
|
|
379
|
+
plt.figure(figsize=(float(width), float(height)))
|
|
380
|
+
|
|
381
|
+
ll = label.split(',')
|
|
382
|
+
if len(ll) < len(bands):
|
|
383
|
+
cp = os.path.commonpath(bands)
|
|
384
|
+
rpl = [p[len(cp):][::-1] for p in bands]
|
|
385
|
+
cs = os.path.commonpath(rpl)
|
|
386
|
+
ll = [p[len(cp):-len(cs)] for p in bands]
|
|
387
|
+
|
|
388
|
+
for b, l in zip(bands, ll):
|
|
389
|
+
p = Path(b)
|
|
390
|
+
|
|
391
|
+
hm.plot_bands_file(p, lbl=l, decorate=not nodecor)
|
|
392
|
+
|
|
393
|
+
if label or len(bands)>1:
|
|
394
|
+
plt.legend()
|
|
395
|
+
|
|
396
|
+
if output:
|
|
397
|
+
plt.savefig(output)
|
|
398
|
+
if sixel:
|
|
399
|
+
try :
|
|
400
|
+
import sixelplot
|
|
401
|
+
except ImportError:
|
|
402
|
+
print('SixEl graphics support not installed. Install sixelplot package.')
|
|
403
|
+
return
|
|
404
|
+
sixelplot.show()
|