Skip to content

Commit

Permalink
Add setups guessing code to hecss_sampler
Browse files Browse the repository at this point in the history
  • Loading branch information
jochym committed Oct 22, 2024
1 parent 2cd54f5 commit 2f3b21f
Show file tree
Hide file tree
Showing 5 changed files with 99 additions and 35 deletions.
99 changes: 67 additions & 32 deletions 02_CLI.ipynb

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions environment.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ channels:
- conda-forge
- fastai
dependencies:
- setuptools
- python=3.10
- fastcore
- nbdev
Expand Down
2 changes: 1 addition & 1 deletion hecss/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
__version__ = "0.5.26"
__version__ = "0.5.27"

from .core import *

30 changes: 29 additions & 1 deletion hecss/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
from hecss.optimize import make_sampling
import traceback
from tempfile import TemporaryDirectory
import ast

# %% ../02_CLI.ipynb 5
_version_message=("HECSS, version %(version)s\n"
Expand Down Expand Up @@ -66,6 +67,11 @@ def dfset_writer(s, sl, workdir='', dfset='', scale='', xsl=None):
@click.option('-C', '--calc', default="VASP", type=str,
help="ASE calculator to be used for the job. "
"Supported calculators: VASP (default)")
@click.option('-S', '--setups', default="guess", type=str,
help="setups parameter of the calculator to force use of the "
"particular variants of pseudopotentials in the calculations. "
"By default pseudopotentials are guessed from the POTCAR in "
"the supercell directory.")
@click.option('-n', '--nodfset', is_flag=True, default=False, help='Do not write DFSET file for ALAMODE')
@click.option('-d', '--dfset', default='DFSET.dat', help='Name of the DFSET file')
@click.option('-N', '--nsamples', default=10, type=int, help="Number of samples to be generated")
Expand All @@ -75,7 +81,7 @@ def dfset_writer(s, sl, workdir='', dfset='', scale='', xsl=None):
@click.option('-p', '--pbar', is_flag=True, default=True, help="Do not show progress bar")
@click.version_option(hecss.__version__, '-V', '--version', message=_version_message)
@click.help_option('-h', '--help')
def hecss_sampler(fname, workdir, label, temp, width, ampl, scale, symprec, calc, nodfset, dfset, nsamples, neta, command, nwork, pbar):
def hecss_sampler(fname, workdir, label, temp, width, ampl, scale, symprec, calc, setups, nodfset, dfset, nsamples, neta, command, nwork, pbar):
'''
Run HECSS sampler on the structure in the provided file (FNAME).\b
Read the docs at: https://jochym.github.io/hecss/
Expand Down Expand Up @@ -103,6 +109,28 @@ def hecss_sampler(fname, workdir, label, temp, width, ampl, scale, symprec, calc
command = Path(command)
calculator.set(command=f'{command.absolute()} {label}')
calculator.set(nsw=0)
if setups :
if setups=='guess':
setups = {}
with open(src_path.parent / Path("POTCAR"), "r") as pf:
for l in pf.readlines():
if "TITEL" in l:
l = l.strip().split()[3].split("_")
el = l[0]
st = ""
if len(l)>1:
st = f"_{l[1]}"
setups[el] = st
print(f"Setups guessed from {src_path.parent / Path('POTCAR')}: {setups}")
else :
if setups in {'recommended', 'minimal', 'gw'}:
# We do not need to parse these. Just use as is
pass
else :
# Parse into dict
setups = ast.literal_eval(setups)
print(f"Setups forced: {setups}")
calculator.set(setups=setups)
else:
print(f'The {calc} calculator is not supported.')
return
Expand Down
2 changes: 1 addition & 1 deletion settings.ini
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ author = Paweł T. Jochym
author_email = pawel.jochym@ifj.edu.pl
copyright = Paweł T. Jochym
branch = devel
version = 0.5.26
version = 0.5.27
min_python = 3.7
audience = Science/Research
language = English
Expand Down

0 comments on commit 2f3b21f

Please sign in to comment.