Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Caffeinate #13

Merged
merged 25 commits into from
Aug 21, 2024
Merged
Changes from 2 commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
7a0d965
initial commit for caffeinate sub-module
ebanyas Aug 6, 2024
522e8bb
support for gamma-centered, M-P, and line-mode KPOINTS objects
ebanyas Aug 15, 2024
43aa519
resolved KPointsCard import and return blocks
ebanyas Aug 16, 2024
c2b6c89
Renamed module, added (some) error messages and warnings
ebanyas Aug 16, 2024
54eaabd
removed old module file
ebanyas Aug 16, 2024
d1228e4
minor updates; pushing latest version for debugging explicit grid
ebanyas Aug 16, 2024
a6f3ddf
Fixed explicit grid issue
ebanyas Aug 17, 2024
6c173f6
_caffeinate_kpoints is fully functional (famous last words)
ebanyas Aug 17, 2024
5a7c0b7
another module rename
ebanyas Aug 17, 2024
33e9713
fixed bug in gamma-point only explicit grids
ebanyas Aug 17, 2024
8556161
fixed tetrahedra warning error
ebanyas Aug 17, 2024
ca16483
added caffeination support for POSCAR files
ebanyas Aug 20, 2024
3c11dd2
cleaning up Poscar implementation
ebanyas Aug 20, 2024
8d4160c
reverting unintended pwin changes
ebanyas Aug 20, 2024
e45ffae
created sub-functions for k-point caffeination
ebanyas Aug 20, 2024
05bb85c
fixed poscar bug
ebanyas Aug 20, 2024
49fa739
Didn't really fix the ibrav check
ebanyas Aug 20, 2024
73dc5b7
updated ibrav kwarg handling
ebanyas Aug 20, 2024
5f6c996
removed superfluous ibrav type-checking
ebanyas Aug 20, 2024
2061996
added custom warning class for tpiba conversion (for later filtering …
ebanyas Aug 21, 2024
874ce94
changed return logic for k-point converters
ebanyas Aug 21, 2024
50fe91b
removed useless Angstrom comment
ebanyas Aug 21, 2024
5b5f529
fixed species bug
ebanyas Aug 21, 2024
f052358
updated line_mode conversion
ebanyas Aug 21, 2024
89f67f1
Final reformat and lint
oashour Aug 21, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
168 changes: 168 additions & 0 deletions pymatgen/io/espresso/caffeinate.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,168 @@
"""
Classes for converting VASP inputs to PWSCF inputs.

Supported VASP inputs:
KPOINTS*
POSCAR
Not (yet) supported:
INCAR
KPOINTS: generalized regular grids or
fully automatic (KSPACING) grids
"""

# TODO: imports need linting!
# TODO: Gamma vs. M-P conversion should be tested with an actual VASP/QE comp.

from __future__ import annotations

import contextlib
import warnings

import numpy as np

from pymatgen.core.structure import Structure

from pymatgen.io.vasp.inputs import Kpoints, Poscar
from pymatgen.io.espresso.inputs import pwin
oashour marked this conversation as resolved.
Show resolved Hide resolved

# TODO
# introduce class Caffeinator():
# TODO: define get_pwin method
# which reads in a full set of VASP inputs
# and returns a full pwin object

# Functions for converting a specified VASP input file
# to PWin format

def caffeinate(vasp_in):
if isinstance(vasp_in, Kpoints):
return _caffeinate_kpoints(vasp_in)
elif isinstance(vasp_in, Poscar):
return _caffeinate_poscar(vasp_in)
else:
# TODO: Define a warning
return vasp_in

def _caffeinate_kpoints(kpoints):
"""
Convert a Kpoints object to a KPointsCard object.

NOTE: Cartesian coordinates are preserved in their original form,
i.e. in units of 2*pi/a where a is defined in an accompanying Poscar object.
"""
k_style = kpoints.style
k_num = kpoints.num_kpts
k_pts = kpoints.kpts
k_shift = kpoints.kpts_shift
k_wts = kpoints.kpts_weights
k_coord = kpoints.coord_type
k_lab = kpoints.labels

if k_style.name.lower()[0] in "gm":
oashour marked this conversation as resolved.
Show resolved Hide resolved
if (
all(int(x) == 1 for x in k_pts[0]) and
all(x == 0.0 for x in k_shift)
):
opt_str = "gamma"
else:
opt_str = "automatic"

# TODO: option assignment from string should be fixed in next version
option = pwin.KPointsCard.opts.from_string(opt_str)
grid = [ int(x) for x in k_pts[0] ]
shift = [ bool(x) for x in k_shift ]

# TODO: needs checking
# convert gamma-centered grids to Monkhorst-Pack grids, if necessary
# (i.e. for even subdivisions)
if k_style.name.lower()[0] == "g":
for i, x in enumerate(grid):
if not x % 2:
shift[i] = not shift[i]

return pwin.KPointsCard(
oashour marked this conversation as resolved.
Show resolved Hide resolved
option = option,
grid = grid,
shift = shift,
k = [],
weights = [],
labels = [])

elif k_style.name.lower()[0] == "l":
if k_coord.lower()[0] == "r":
opt_str = "crystal_b"
else:
opt_str = "tpiba_b"

pw_k = [list(k_pts[0])]
pw_lbls = [k_lab[0]]
pw_wts = [k_num]
for i in range(1,len(k_lab)):
if k_lab[i] == k_lab[i - 1]:
pass
elif not i % 2:
pw_lbls.append(k_lab[i])
pw_wts[-1] = 1
pw_wts.append(k_num)
pw_k.append(list(k_pts[i]))
else:
pw_lbls.append(k_lab[i])
pw_wts.append(k_num)
pw_k.append(list(k_pts[i]))

pw_wts[-1] = 1
option = pwin.KPointsCard.opts.from_string(opt_str)

return pwin.KPointsCard(
option = option,
grid = [],
shift = [],
k = pw_k,
weights = pw_wts,
labels = pw_lbls)

elif k_style.name.lower()[0] in "rc" and k_num > 0:
if k_num == 1 and (
all(int(x) == 1 for x in k_pts[0]) and
all(x == 0.0 for x in k_shift)
):
opt_str = "gamma"
elif k_style.name.lower()[0] == "c":
opt_str = "tpiba"
else:
opt_str = "crystal"

option = pwin.KPointsCard.opts.from_string(opt_str)
# TODO: finish parsing k-points


else:
# In this case the style we have either a fully-automatic grid with a
# defined spacing (officially deprecated by VASP) or a generalized
# regular grid.
# Neither option has a direct PWSCF parallel and conversion has not
# been implemented yet.
# TODO: Define a warning
return kpoints

if "tpiba" in option:
# TODO: Define a warning.
# Without an accompanying POSCAR, VASP's cartesian coordinates
# cannot properly be converted to PWSCF's tpiba coordinates.
# This warning can be ignored in pwin if a Poscar object is
# provided.
pass

# DEBUGGING (TODO)
return option

# TODO:
def _caffeinate_poscar(poscar):
"""
Convert a Poscar object to the following three objects:
- AtomicPositionsCard
- AtomicSpeciesCard
- CellParametersCard
"""
pass

Loading