Created
November 26, 2023 09:18
-
-
Save Ionizing/4edb3dcde6126c819506f3bbbfd22738 to your computer and use it in GitHub Desktop.
make NEB initial POSCAR with specified atom not affected by PBC.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python3 | |
import copy | |
from pathlib import Path | |
import shutil | |
from sys import argv | |
import numpy as np | |
from ase.io import read as poscar_reader | |
from ase import Atoms | |
def lerp(IS: Atoms, FS: Atoms, nimages: int, *, inopbc=None): | |
ispos = IS.get_scaled_positions() | |
fspos = FS.get_scaled_positions() | |
dist = (fspos - ispos + 0.5) % 1 - 0.5 | |
lerped_pos = np.linspace(ispos, | |
ispos + dist, | |
nimages + 2) | |
if inopbc is not None: | |
lerped_pos[:, inopbc - 1, :] = np.linspace(ispos[inopbc-1, :], | |
fspos[inopbc-1, :], | |
nimages + 2) | |
lerped_cell = np.linspace(IS.get_cell(), | |
FS.get_cell(), | |
nimages + 2) | |
ret = [] | |
for i in range(nimages + 2): | |
TS = copy.deepcopy(IS) | |
TS.set_scaled_positions(lerped_pos[i]) | |
TS.set_cell(lerped_cell[i]) | |
ret.append(TS) | |
return ret | |
def gen_neb(isname: str, fsname: str, nimages: int, inopbc): | |
IS = poscar_reader(isname, index = 0) | |
FS = poscar_reader(fsname, index = 0) | |
TSS = lerp(Atoms(IS), Atoms(FS), nimages, inopbc=inopbc) | |
for ii in range(nimages + 2): | |
dirname = "{:02d}".format(ii) | |
print(dirname) | |
Path(dirname).mkdir(parents=True, exist_ok=True) | |
if 0 == ii: | |
shutil.copy2(argv[1], dirname+'/POSCAR') | |
elif nimages + 1 == ii: | |
shutil.copy2(argv[2], dirname+'/POSCAR') | |
else: | |
TSS[ii].write(dirname+'/POSCAR', vasp5=True) | |
pass | |
shutil.copy2('KPOINTS', dirname) | |
shutil.copy2('INCAR', dirname) | |
if '__main__' == __name__: | |
assert (len(argv) >= 4), "Usage: nebmake.py POSCAR_init POSCAR_fin NIMAGES [inopbc]" | |
isfname = argv[1] | |
fsfname = argv[2] | |
nimages = int(argv[3]) | |
if len(argv) == 5: | |
inopbc = int(argv[4]) | |
else: | |
inopbc = None | |
gen_neb(isfname, fsfname, nimages, inopbc) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment