pos2pkl.py

2023 July 23 update

Script to convert structre data into init_struc_data.pkl. The default input format is init_POSCARS. Single structure data such as POSCAR and cif files can be optionally converted. Output is init_struc_data.pkl. Structure data can be added to an already existing init_struc_data.pkl. The structure ID is not taken into account and is newly assigned. If the number of atoms is different, an error is generated.

init_struc_data.pkl can be loaded at the start of the simulation in CrySPY.

You can remove and sort species with -f option. Note that without this option, pymatgen will sort the species in electronegativity order!

Usage

usage: pos2pkl.py [-h] [-s [SINGLE ...]] [-f [FILTER ...]] [-p] [infile ...]

positional arguments:
  infile                input file: init_POSCARS

options:
  -h, --help            show this help message and exit
  -s [SINGLE ...], --single [SINGLE ...]
                        input file: single structure file (POSCAR, cif)
  -f [FILTER ...], --filter [FILTER ...]
                        filter (sort): remove species and sort
  -p, --permit_diff_comp
                        flag for permitting different composition

Examples

init_POSCARS –> init_struc_data.pkl

It can be used to convert init_POSCARS generated by CrySPY to init_struc_data.pkl in another machine such as a supercomputer. Multiple input files can be converted.

python3 pos2pkl.py init_POSCARS

If you put the pos2pkl.py in your PATH, you can omit python3.

pos2pkl.py init_POSCARS
Composition: Na8 Cl8

Converted. The number of structures: 4
Save init_struc_data.pkl

Multiple inputs:

python3 pos2pkl.py init_POSCARS init_POSCARS2 init_POSCARS3
Composition: Na8 Cl8

Converted. The number of structures: 12
Save init_struc_data.pkl

If init_struc_data.pkl already exists in the current directory and you want to append to it:

python3 pos2pkl.py init_POSCARS
init_struc_data.pkl already exists.
Append to init_struc_data.pkl? [y/n]: y

Load init_struc_data
Composition: Na8 Cl8
The number of structures: 12

Converted. The number of structures: 16
Save init_struc_data.pkl

POSCAR or cif –> init_struc_data.pkl

Single structure data such as POSCAR and cif files can also be converted. -s/--single option is required.

python3 pos2pkl.py -s POSCAR test.cif
Composition: Na8 Cl8

Converted. The number of structures: 2
Save init_struc_data.pkl

init_POSCARS, POSCAR –> init_struc_data.pkl

python3 pos2pkl.py init_POSCARS -s POSCAR
Composition: Na8 Cl8

Converted. The number of structures: 5
Save init_struc_data.pkl
Warning

The following is wrong. The init_POSCARS is also treated as a single structure.

python3 pos2pkl.py -s POSCAR init_POSCARS

Filter (remove and sort)

Here we consider a cif file with the composition of Sr8 Co8 O20 X4, including 4 dummy atoms (X4). -f/--filter option can be used to remove and sort species. Specify the same as atype in cryspy.in.

python3 pos2pkl.py -s Sr8Co8O20X4.cif -f Sr Co O
Removed species: {'X0+'}
Composition: Sr8 Co8 O20

Converted. The number of structures: 1
Save init_struc_data.pkl

With extract_struc.py you can see how it was registered in init_struc_data.pkl.

python3 extract_struc.py init_struc_data.pkl -pa
ID 0
Full Formula (Sr8 Co8 O20)
Reduced Formula: Sr2Co2O5
...

-f option can allow you to sort.

python3 pos2pkl.py -s Sr8Co8O20X4.cif -f O Co 
Removed species: {'Sr', 'X0+'}
Composition: O20 Co8

Converted. The number of structures: 1
Save init_struc_data.pkl