htesp.cif_to_gsinput

Module to write QE/VASP input files from .cif files.

FIX(19) – DUPLICATED FUNCTION. pos_to_kpt below is a diverged copy of htesp.htepc.pos_to_kpt. They are NOT interchangeable:

  • this copy takes a third argument evenkpt; when true it rounds every odd mesh division up to the next even number,

  • this copy writes a KPOINTS file in the current directory as a side effect and returns the mesh, whereas htepc.pos_to_kpt only returns it,

  • htepc.pos_to_kpt computes kratio/klat/kmesh twice (a copy-paste leftover; the second computation is identical to the first).

The numerical core is otherwise the same. They are deliberately left unmerged in this pass; htesp/htepc.py is maintained separately. Callers that need KPOINTS on disk or an even mesh must use this one.

Functions

ciftoscf(calc_type, mpid[, cif2cell, keven])

Function to convert a CIF file to a Quantum ESPRESSO (QE) input file 'scf.in'.

find_mpid(mpid[, path])

1-based index of mpid in the tracking file, or None (FIX(18)).

main([calc_type, argv])

The main function of the script.

pos_to_kpt(structure_filename, kpoint_density)

Function to obtain a k-point mesh from a structure file.

pymatgen_cif(infile)

Function to convert (ICSD) CIF files to pymatgen format.

read_mpid_entries([path])

Return [(mpid, compound), ...] from a v<N> <mpid> <compound> file.

register_mpid(mpid, compound[, path])

Record mpid in the v<N> <mpid> <compound> tracking file.

htesp.cif_to_gsinput.pos_to_kpt(structure_filename, kpoint_density, evenkpt=False)[source]

Function to obtain a k-point mesh from a structure file.

Note

FIX(19) – diverged duplicate of htesp.htepc.pos_to_kpt(); that one has no evenkpt argument and does not write KPOINTS.

Parameters:

  • structure_filename (str): Path to the structure file (QE scf.in or VASP POSCAR).

  • kpoint_density (float): Desired k-point density.

  • evenkpt (bool): Flag indicating whether to enforce an even number of k-points along each axis. Default is False.

Returns:

  • kmesh (list): K-point mesh according to the k-point density.

Example

>>> # Generating a k-point mesh for a VASP POSCAR with a k-point density of 0.05
>>> pos_to_kpt("POSCAR", 0.05, evenkpt=True)
htesp.cif_to_gsinput.read_mpid_entries(path='mpid.in')[source]

Return [(mpid, compound), ...] from a v<N> <mpid> <compound> file.

A missing or unreadable file is an empty list (FIX(18)).

htesp.cif_to_gsinput.find_mpid(mpid, path='mpid.in')[source]

1-based index of mpid in the tracking file, or None (FIX(18)).

htesp.cif_to_gsinput.register_mpid(mpid, compound, path='mpid.in')[source]

Record mpid in the v<N> <mpid> <compound> tracking file.

FIX(18): the original read-then-append pattern (repeated verbatim in qe_input.py, vasp_input.py, oqmd_extract.py and aflow_extract.py) numbered the new entry v<len(lines)+1>, so a file that had ever been hand-edited, or two processes appending at once, produced duplicate or skipped v<N> numbers – and every consumer looks an entry up with grep "v$ii ". This helper

  • is idempotent – an mpid already present is left alone and its existing index returned,

  • renumbers v<N> densely from 1 on every write, and

  • is atomic – the whole file is written to a temporary file in the same directory and moved into place with os.replace.

Returns the 1-based index of mpid in the file.

htesp.cif_to_gsinput.pymatgen_cif(infile)[source]

Function to convert (ICSD) CIF files to pymatgen format.

Parameters: - infile (str): Path to the input CIF file.

Returns: - structure (Structure): Pymatgen Structure object representing the CIF structure. .. rubric:: Example

>>> # Convert a CIF file named 'example.cif' to pymatgen format
>>> pymatgen_cif("example.cif")
htesp.cif_to_gsinput.ciftoscf(calc_type, mpid, cif2cell=True, keven=False)[source]

Function to convert a CIF file to a Quantum ESPRESSO (QE) input file ‘scf.in’.

Parameters: - calc_type (str): The type of calculation, either ‘VASP’ or ‘QE’. - mpid (str): The Material ID. - cif2cell (bool): If True, uses cif2cell to process the CIF file. Default is True. - keven (bool): If True, even k-mesh is used. Default is False.

Returns: - compound (str): The compound name.

Writes the ‘scf-mpid.in’ file. .. rubric:: Example

>>> # Convert a CIF file to a Quantum ESPRESSO input file
>>> ciftoscf("QE", "mp-1234", cif2cell=False, keven=False)
htesp.cif_to_gsinput.main(calc_type=None, argv=None)[source]

The main function of the script.

This function performs the following operations: - Retrieves a list of CIF files in the current directory. - Sets the calculation type. - Sets the flag for using cif2cell. - Iterates over CIF files, converts them to QE input files, and writes data to ‘mpid.in’.

Parameters:

  • calc_type (str): Calculation type (‘VASP’ or ‘QE’). FIX(20): this is now a real argument; it used to be read from sys.argv[1] in the middle of the function, so the module could not be driven from Python. When it is omitted the value still comes from the command line, keeping the cif_to_gsinput.py <calc> contract.

  • argv (list): command line used when calc_type is omitted.

Returns: None