Skip to content

Commit 58c1753

Browse files
authored
add option to ignore convergence check for vasp/contcar (#355)
it is the realization for discussion #350. Signed-off-by: Pan Xiang <[email protected]>
1 parent 652bb22 commit 58c1753

File tree

7 files changed

+86
-22
lines changed

7 files changed

+86
-22
lines changed

dpdata/fhi_aims/output.py

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import numpy as np
22
import re
3+
import warnings
34

45
latt_patt="\|\s+([0-9]{1,}[.][0-9]*)\s+([0-9]{1,}[.][0-9]*)\s+([0-9]{1,}[.][0-9]*)"
56
pos_patt_first="\|\s+[0-9]{1,}[:]\s\w+\s(\w+)(\s.*[-]?[0-9]{1,}[.][0-9]*)(\s+[-]?[0-9]{1,}[.][0-9]*)(\s+[-]?[0-9]{1,}[.][0-9]*)"
@@ -63,7 +64,7 @@ def get_fhi_aims_block(fp) :
6364
return blk
6465
return blk
6566

66-
def get_frames (fname, md=True, begin = 0, step = 1) :
67+
def get_frames (fname, md=True, begin = 0, step = 1, convergence_check=True) :
6768
fp = open(fname)
6869
blk = get_fhi_aims_block(fp)
6970
ret = get_info(blk, type_idx_zero = True)
@@ -78,6 +79,7 @@ def get_frames (fname, md=True, begin = 0, step = 1) :
7879
all_virials = []
7980

8081
cc = 0
82+
rec_failed = []
8183
while len(blk) > 0 :
8284
if debug:
8385
with open(str(cc),'w') as f:
@@ -87,9 +89,9 @@ def get_frames (fname, md=True, begin = 0, step = 1) :
8789
coord, _cell, energy, force, virial, is_converge = analyze_block(blk, first_blk=True, md=md)
8890
else:
8991
coord, _cell, energy, force, virial, is_converge = analyze_block(blk, first_blk=False)
90-
if is_converge :
91-
if len(coord) == 0:
92-
break
92+
if len(coord) == 0:
93+
break
94+
if is_converge or not convergence_check:
9395
all_coords.append(coord)
9496

9597
if _cell:
@@ -101,9 +103,16 @@ def get_frames (fname, md=True, begin = 0, step = 1) :
101103
all_forces.append(force)
102104
if virial is not None :
103105
all_virials.append(virial)
106+
if not is_converge:
107+
rec_failed.append(cc+1)
108+
104109
blk = get_fhi_aims_block(fp)
105110
cc += 1
106111

112+
if len(rec_failed) > 0 :
113+
prt = "so they are not collected." if convergence_check else "but they are still collected due to the requirement for ignoring convergence checks."
114+
warnings.warn(f"The following structures were unconverged: {rec_failed}; "+prt)
115+
107116
if len(all_virials) == 0 :
108117
all_virials = None
109118
else :

dpdata/plugins/fhi_aims.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
@Format.register("fhi_aims/md")
55
@Format.register("fhi_aims/output")
66
class FhiMDFormat(Format):
7-
def from_labeled_system(self, file_name, md=True, begin = 0, step = 1, **kwargs):
7+
def from_labeled_system(self, file_name, md=True, begin = 0, step = 1, convergence_check=True, **kwargs):
88
data = {}
99
data['atom_names'], \
1010
data['atom_numbs'], \
@@ -14,7 +14,7 @@ def from_labeled_system(self, file_name, md=True, begin = 0, step = 1, **kwargs)
1414
data['energies'], \
1515
data['forces'], \
1616
tmp_virial, \
17-
= dpdata.fhi_aims.output.get_frames(file_name, md = md, begin = begin, step = step)
17+
= dpdata.fhi_aims.output.get_frames(file_name, md = md, begin = begin, step = step, convergence_check=convergence_check)
1818
if tmp_virial is not None :
1919
data['virials'] = tmp_virial
2020
return data

dpdata/plugins/pwmat.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
@Format.register("pwmat/output")
1212
class PwmatOutputFormat(Format):
1313
@Format.post("rot_lower_triangular")
14-
def from_labeled_system(self, file_name, begin=0, step=1, **kwargs):
14+
def from_labeled_system(self, file_name, begin=0, step=1, convergence_check=True, **kwargs):
1515
data = {}
1616
data['atom_names'], \
1717
data['atom_numbs'], \
@@ -21,7 +21,7 @@ def from_labeled_system(self, file_name, begin=0, step=1, **kwargs):
2121
data['energies'], \
2222
data['forces'], \
2323
tmp_virial \
24-
= dpdata.pwmat.movement.get_frames(file_name, begin=begin, step=step)
24+
= dpdata.pwmat.movement.get_frames(file_name, begin=begin, step=step, convergence_check=convergence_check)
2525
if tmp_virial is not None:
2626
data['virials'] = tmp_virial
2727
# scale virial to the unit of eV

dpdata/plugins/vasp.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ def to_system(self, data, frame_idx=0, **kwargs):
5454
@Format.register("vasp/outcar")
5555
class VASPOutcarFormat(Format):
5656
@Format.post("rot_lower_triangular")
57-
def from_labeled_system(self, file_name, begin=0, step=1, **kwargs):
57+
def from_labeled_system(self, file_name, begin=0, step=1, convergence_check=True, **kwargs):
5858
data = {}
5959
ml = kwargs.get("ml", False)
6060
data['atom_names'], \
@@ -65,7 +65,7 @@ def from_labeled_system(self, file_name, begin=0, step=1, **kwargs):
6565
data['energies'], \
6666
data['forces'], \
6767
tmp_virial, \
68-
= dpdata.vasp.outcar.get_frames(file_name, begin=begin, step=step, ml=ml)
68+
= dpdata.vasp.outcar.get_frames(file_name, begin=begin, step=step, ml=ml, convergence_check=convergence_check)
6969
if tmp_virial is not None:
7070
data['virials'] = tmp_virial
7171
# scale virial to the unit of eV

dpdata/pwmat/movement.py

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import numpy as np
22
from ..periodic_table import ELEMENTS
3+
import warnings
34

45
def system_info (lines, type_idx_zero = False) :
56
atom_names = []
@@ -49,7 +50,7 @@ def get_movement_block(fp) :
4950
return blk
5051

5152
# we assume that the force is printed ...
52-
def get_frames (fname, begin = 0, step = 1) :
53+
def get_frames (fname, begin = 0, step = 1, convergence_check=True) :
5354
fp = open(fname)
5455
blk = get_movement_block(fp)
5556

@@ -64,20 +65,28 @@ def get_frames (fname, begin = 0, step = 1) :
6465
all_virials = []
6566

6667
cc = 0
68+
rec_failed = []
6769
while len(blk) > 0 :
6870
if cc >= begin and (cc - begin) % step == 0 :
6971
coord, cell, energy, force, virial, is_converge = analyze_block(blk, ntot, nelm)
70-
if is_converge :
71-
if len(coord) == 0:
72-
break
72+
if len(coord) == 0:
73+
break
74+
if is_converge or not convergence_check:
7375
all_coords.append(coord)
7476
all_cells.append(cell)
7577
all_energies.append(energy)
7678
all_forces.append(force)
7779
if virial is not None :
7880
all_virials.append(virial)
81+
if not is_converge:
82+
rec_failed.append(cc+1)
83+
7984
blk = get_movement_block(fp)
8085
cc += 1
86+
87+
if len(rec_failed) > 0 :
88+
prt = "so they are not collected." if convergence_check else "but they are still collected due to the requirement for ignoring convergence checks."
89+
warnings.warn(f"The following structures were unconverged: {rec_failed}; "+prt)
8190

8291
if len(all_virials) == 0 :
8392
all_virials = None

dpdata/system.py

Lines changed: 41 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -176,6 +176,7 @@ def __init__ (self,
176176
begin = 0,
177177
step = 1,
178178
data = None,
179+
convergence_check = True,
179180
**kwargs) :
180181
"""
181182
Constructor
@@ -192,14 +193,49 @@ def __init__ (self,
192193
- ``deepmd/raw``: deepmd-kit raw
193194
- ``deepmd/npy``: deepmd-kit compressed format (numpy binary)
194195
- ``vasp/poscar``: vasp POSCAR
196+
- ``vasp/contcar``: vasp contcar
197+
- ``vasp/string``: vasp string
198+
- ``vasp/outcar``: vasp outcar
199+
- ``vasp/xml``: vasp xml
195200
- ``qe/cp/traj``: Quantum Espresso CP trajectory files. should have: file_name+'.in' and file_name+'.pos'
196201
- ``qe/pw/scf``: Quantum Espresso PW single point calculations. Both input and output files are required. If file_name is a string, it denotes the output file name. Input file name is obtained by replacing 'out' by 'in' from file_name. Or file_name is a list, with the first element being the input file name and the second element being the output filename.
197202
- ``abacus/scf``: ABACUS pw/lcao scf. The directory containing INPUT file is required.
198203
- ``abacus/md``: ABACUS pw/lcao MD. The directory containing INPUT file is required.
199-
- ``abacus/relax``: ABACUS pw/lcao relax or cell-relax. The directory containing INPUT file is required.
204+
- ``abacus/relax``: ABACUS pw/lcao relax or cell-relax. The directory containing INPUT file is required.
205+
- ``abacus/stru``: abacus stru
206+
- ``abacus/lcao/scf``: abacus lcao scf
207+
- ``abacus/pw/scf``: abacus pw scf
208+
- ``abacus/lcao/md``: abacus lcao md
209+
- ``abacus/pw/md``: abacus pw md
210+
- ``abacus/lcao/relax``: abacus lcao relax
211+
- ``abacus/pw/relax``: abacus pw relax
200212
- ``siesta/output``: siesta SCF output file
201213
- ``siesta/aimd_output``: siesta aimd output file
202214
- ``pwmat/atom.config``: pwmat atom.config
215+
- ``pwmat/movement``: pwmat movement
216+
- ``pwmat/output``: pwmat output
217+
- ``pwmat/mlmd``: pwmat mlmd
218+
- ``pwmat/final.config``: pwmat final.config
219+
- ``quip/gap/xyz_file``: quip gap xyz_file
220+
- ``quip/gap/xyz``: quip gap xyz
221+
- ``fhi_aims/output``: fhi_aims output
222+
- ``fhi_aims/md``: fhi_aims md
223+
- ``fhi_aims/scf``: fhi_aims scf
224+
- ``pymatgen/structure``: pymatgen structure
225+
- ``pymatgen/molecule``: pymatgen molecule
226+
- ``pymatgen/computedstructureentry``: pymatgen computedstructureentry
227+
- ``amber/md``: amber md
228+
- ``sqm/out``: sqm out
229+
- ``sqm/in``: sqm in
230+
- ``ase/structure``: ase structure
231+
- ``gaussian/log``: gaussian log
232+
- ``gaussian/md``: gaussian md
233+
- ``gaussian/gjf``: gaussian gjf
234+
- ``deepmd/comp``: deepmd comp
235+
- ``deepmd/hdf5``: deepmd hdf5
236+
- ``gromacs/gro``: gromacs gro
237+
- ``cp2k/aimd_output``: cp2k aimd_output
238+
- ``cp2k/output``: cp2k output
203239
type_map : list of str
204240
Needed by formats lammps/lmp and lammps/dump. Maps atom type to name. The atom with type `ii` is mapped to `type_map[ii]`.
205241
If not provided the atom names are assigned to `'Type_1'`, `'Type_2'`, `'Type_3'`...
@@ -208,7 +244,9 @@ def __init__ (self,
208244
step : int
209245
The number of skipped frames when loading MD trajectory.
210246
data : dict
211-
The raw data of System class.
247+
The raw data of System class.
248+
convergence_check : boolean
249+
Whether to request a convergence check.
212250
"""
213251
self.data = {}
214252
self.data['atom_numbs'] = []
@@ -224,7 +262,7 @@ def __init__ (self,
224262
return
225263
if file_name is None :
226264
return
227-
self.from_fmt(file_name, fmt, type_map=type_map, begin= begin, step=step, **kwargs)
265+
self.from_fmt(file_name, fmt, type_map=type_map, begin= begin, step=step, convergence_check=convergence_check, **kwargs)
228266

229267
if type_map is not None:
230268
self.apply_type_map(type_map)

dpdata/vasp/outcar.py

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import numpy as np
22
import re
3+
import warnings
34

45
def system_info(lines, type_idx_zero = False):
56
atom_names = []
@@ -52,7 +53,7 @@ def get_outcar_block(fp, ml = False):
5253
return blk
5354

5455
# we assume that the force is printed ...
55-
def get_frames(fname, begin = 0, step = 1, ml = False):
56+
def get_frames(fname, begin = 0, step = 1, ml = False, convergence_check=True):
5657
fp = open(fname)
5758
blk = get_outcar_block(fp)
5859

@@ -66,22 +67,29 @@ def get_frames(fname, begin = 0, step = 1, ml = False):
6667
all_virials = []
6768

6869
cc = 0
70+
rec_failed = []
6971
while len(blk) > 0 :
7072
if cc >= begin and (cc - begin) % step == 0 :
7173
coord, cell, energy, force, virial, is_converge = analyze_block(blk, ntot, nelm, ml)
72-
if is_converge :
73-
if len(coord) == 0:
74-
break
74+
if len(coord) == 0:
75+
break
76+
if is_converge or not convergence_check:
7577
all_coords.append(coord)
7678
all_cells.append(cell)
7779
all_energies.append(energy)
7880
all_forces.append(force)
7981
if virial is not None :
8082
all_virials.append(virial)
83+
if not is_converge:
84+
rec_failed.append(cc+1)
8185

8286
blk = get_outcar_block(fp, ml)
8387
cc += 1
84-
88+
89+
if len(rec_failed) > 0 :
90+
prt = "so they are not collected." if convergence_check else "but they are still collected due to the requirement for ignoring convergence checks."
91+
warnings.warn(f"The following structures were unconverged: {rec_failed}; "+prt)
92+
8593
if len(all_virials) == 0 :
8694
all_virials = None
8795
else :

0 commit comments

Comments
 (0)