Cif to vasp

From pdl-openair/OpenAIR · View interactive version

Cif to vasp is an AI agent skill from the GitHub repository pdl-openair/OpenAIR. Generate VASP input files (POSCAR, INCAR, KPOINTS, POTCAR) from CIF crystal structure files. Use this skill whenever the user needs to prepare VASP calculations from crystal structure data, convert CIF to POSCAR, set up relaxation or static calculations, or generate VASP input sets. Also trigger whe

How to use this skill

Skill file

CIF to VASP Input Generator

Generate correct, validated VASP input files from CIF crystal structures.

The most common VASP failures (ZHEGV failed, Cannot allocate memory) trace back to two root causes this skill prevents:

  1. Wrong POSCAR coordinates — placing conventional-cell atomic positions into a reduced/primitive cell (atoms overlap, overlap matrix becomes singular)
  2. Aggressive INCAR settings — PREC=Accurate + dense KPOINTS + high ENCUT overwhelms HPC memory

Workflow

Step 1: Read and validate the CIF

Read the CIF file. Check:

If the CIF looks malformed or has missing symmetry info, ask the user before proceeding.

Step 2: Generate POSCAR from CIF

Always use pymatgen to convert CIF → POSCAR. This ensures symmetry operations are applied correctly and coordinates match the lattice vectors.

from pymatgen.core import Structure

struct = Structure.from_file("input.cif")
struct.to(fmt="poscar", filename="POSCAR")

After writing, clean the POSCAR by removing species charge labels from coordinate lines (e.g., Al3+ → just the three fractional coordinates). VASP does not expect text after coordinate values.

Critical: validate the POSCAR before proceeding. Run this check every time:

from pymatgen.core import Structure

s = Structure.from_file("POSCAR")
min_dist = float('inf')
for i in range(len(s)):
    for j in range(i+1, len(s)):
        d = s.get_distance(i, j)
        if d < min_dist:
            min_dist = d

print(f"Atoms: {len(s)}, Min distance: {min_dist:.4f} A")

Validation rules:

Step 3: Determine the POTCAR element order

Read the POSCAR species order (the line like Al In Se in POSCAR). The POTCAR must concatenate pseudopotentials in exactly this order.

POTCAR generation options:

  1. VASPKit (if installed): run vaspkit → task 103 (generate POTCAR automatically from POSCAR)
  2. pymatgen (if PMG_VASP_PSP_DIR is set): use MPRelaxSet(struct).potcar
  3. Manual: concatenate PAW_PBE pseudopotential files in the POSCAR species order

If no POTCAR source is available, write a potcar_generator.sh helper script that documents the required order.

Step 4: Generate KPOINTS

The k-point mesh density must match the cell size. Larger cells need fewer k-points because the Brillouin zone is smaller.

Rule of thumb for Gamma-centered meshes:

| Cell dimension (A) | K-points along that axis |

|--------------------|--------------------------|

| < 5 | 6-8 |

| 5-8 | 4-6 |

| 8-12 | 3-4 |

| 12-20 | 2-3 |

| > 20 | 1-2 |

For the c-axis specifically: if c > 15 A with layered/van der Waals structure, use 1-2 k-points along c.

For initial relaxation, always use Gamma-centered (not Monkhorst-Pack) to avoid Gamma-point duplication issues.

Example KPOINTS for a hexagonal cell with a=7.07, c=18.84:

Kpoints for relaxation
0
Gamma
3 3 1
0 0 0

Step 5: Generate INCAR

Use conservative, memory-safe defaults for initial relaxation. The user can tighten parameters for production runs later.

Default INCAR template for relaxation:

System = [FORMULA]

# Electronic Optimization
ENCUT   = [ENCUT]
PREC    = Normal
ALGO    = Normal
EDIFF   = 1E-5
NELM    = 200
ISMEAR  = 0
SIGMA   = 0.05
LREAL   = A

# Ionic Optimization
IBRION  = 2
ISIF    = 3
NSW     = 100
EDIFFG  = -0.01

# Output
LCHARG  = .TRUE.
LWAVE   = .FALSE.

ENCUT determination:

Why these defaults:

When to adjust:

Step 6: Final validation

Before delivering the four files, verify:

  1. POSCAR: minimum interatomic distance > 1.5 A, atom count matches CIF expectation
  2. INCAR: ENCUT ≥ 1.3 × max(ENMAX from POTCAR)
  3. KPOINTS: mesh density appropriate for cell dimensions
  4. POTCAR: element order matches POSCAR species line exactly
  5. Cross-check: number of ions in POSCAR (line 6 species counts) matches total atoms

Print a summary for the user showing:

Common pitfalls

Cell mismatch (the #1 cause of ZHEGV errors)

Never mix lattice vectors from one cell setting with coordinates from another. For example, if the CIF uses the conventional hexagonal cell (a=7.07 A) but you use a reduced primitive cell (a=4.08 A), the coordinates will place atoms on top of each other. Always let pymatgen handle the full conversion from CIF — it correctly pairs lattice vectors with symmetry-generated positions.

Memory errors on HPC

The combination of PREC=Accurate + dense KPOINTS + high ENCUT can easily exceed node memory. For initial relaxation:

POTCAR element order mismatch

VASP silently accepts a POTCAR whose species order differs from POSCAR — but the results will be wrong. Always verify the order matches.

File structure

output_directory/
├── POSCAR    ← from CIF via pymatgen
├── INCAR     ← template with system-specific parameters
├── KPOINTS   ← Gamma mesh scaled to cell dimensions
└── POTCAR    ← concatenated pseudopotentials matching POSCAR order
Use this skill with your AI agent: Open on Skill Issue to copy, download, or add to your library. Works with Claude, ChatGPT, Gemini, Cursor, Windsurf and more.