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

Select frames which are convergent in SC-calculatio of VASP #7

Merged
merged 2 commits into from
Jul 1, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
41 changes: 25 additions & 16 deletions dpdata/vasp/outcar.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,21 @@
def system_info (lines, type_idx_zero = False) :
atom_names = []
atom_numbs = None
nelm = None
for ii in lines:
if 'TITEL =' in ii :
# get atom names from POTCAR info, tested only for PAW_PBE ...
atom_names.append(ii.split()[3])
elif 'NELM' in ii :
nelm = int(ii.split()[2][:-1])
break;
elif 'ions per type' in ii :
atom_numbs_ = [int(s) for s in ii.split()[4:]]
if atom_numbs is None :
atom_numbs = atom_numbs_
else :
assert (atom_numbs == atom_numbs_), "in consistent numb atoms in OUTCAR"
break
assert(nelm is not None), "cannot find maximum steps for each SC iteration"
assert(atom_numbs is not None), "cannot find ion type info in OUTCAR"
atom_names = atom_names[:len(atom_numbs)]
atom_types = []
Expand All @@ -23,7 +27,7 @@ def system_info (lines, type_idx_zero = False) :
atom_types.append(idx)
else :
atom_types.append(idx+1)
return atom_names, atom_numbs, np.array(atom_types, dtype = int)
return atom_names, atom_numbs, np.array(atom_types, dtype = int), nelm


def get_outcar_block(fp) :
Expand All @@ -41,7 +45,7 @@ def get_frames (fname, begin = 0, step = 1) :
fp = open(fname)
blk = get_outcar_block(fp)

atom_names, atom_numbs, atom_types = system_info(blk, type_idx_zero = True)
atom_names, atom_numbs, atom_types, nelm = system_info(blk, type_idx_zero = True)
ntot = sum(atom_numbs)

all_coords = []
Expand All @@ -53,31 +57,36 @@ def get_frames (fname, begin = 0, step = 1) :
cc = 0
while len(blk) > 0 :
if cc >= begin and (cc - begin) % step == 0 :
coord, cell, energy, force, virial = analyze_block(blk, ntot)
if len(coord) == 0:
break
all_coords.append(coord)
all_cells.append(cell)
all_energies.append(energy)
all_forces.append(force)
if virial is not None :
all_virials.append(virial)
coord, cell, energy, force, virial, is_converge = analyze_block(blk, ntot, nelm)
if is_converge :
if len(coord) == 0:
break
all_coords.append(coord)
all_cells.append(cell)
all_energies.append(energy)
all_forces.append(force)
if virial is not None :
all_virials.append(virial)
blk = get_outcar_block(fp)
cc += 1

fp.close()
return atom_names, atom_numbs, atom_types, np.array(all_cells), np.array(all_coords), np.array(all_energies), np.array(all_forces), np.array(all_virials)


def analyze_block(lines, ntot) :
def analyze_block(lines, ntot, nelm) :
coord = []
cell = []
energy = None
force = []
virial = None
is_converge = True
sc_index = 0
for idx,ii in enumerate(lines) :
if 'Iteration' in ii:
pass
sc_index = int(ii.split()[3][:-1])
if sc_index >= nelm:
is_converge = False
elif 'free energy TOTEN' in ii:
energy = float(ii.split()[4])
assert((force is not None) and len(coord) > 0 and len(cell) > 0)
Expand All @@ -87,7 +96,7 @@ def analyze_block(lines, ntot) :
# all_forces.append(force)
# if virial is not None :
# all_virials.append(virial)
return coord, cell, energy, force, virial
return coord, cell, energy, force, virial, is_converge
elif 'VOLUME and BASIS' in ii:
for dd in range(3) :
tmp_l = lines[idx+5+dd]
Expand All @@ -111,4 +120,4 @@ def analyze_block(lines, ntot) :
info = [float(ss) for ss in tmp_l.split()]
coord.append(info[:3])
force.append(info[3:])
return coord, cell, energy, force, virial
return coord, cell, energy, force, virial, is_converge
Loading