Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
31 commits
Select commit Hold shift + click to select a range
207ffde
fix bug in lammps/dump, fractional coord should not shift origin
Apr 16, 2020
a9e726a
fix bug in lammps/dump
Apr 16, 2020
8fc3909
Merge pull request #96 from amcadmus/devel
amcadmus Apr 16, 2020
a8c34fd
add a unittest to lammps dump shift origin
felix5572 Apr 16, 2020
2310a54
fix bug #74
felix5572 Apr 16, 2020
5086a51
Merge pull request #97 from felix5572/devel
amcadmus Apr 16, 2020
7aea226
fix bug of to_ase_structure in #98
njzjz May 3, 2020
f09886e
Merge pull request #99 from njzjz/ase
amcadmus May 4, 2020
1281cd8
fix fhi-amis multi-elements bug
haidi-ustc May 9, 2020
63b3d20
update gitignore
haidi-ustc May 9, 2020
276f8b1
update README
haidi-ustc May 9, 2020
e5f4650
update fhi-amis test & README
haidi-ustc May 23, 2020
37b2b3c
Merge pull request #100 from haidi-ustc/devel
amcadmus May 23, 2020
a9e8aa6
fix bug in deepmd/npy: error when size of energy is 1
Jun 3, 2020
b82f3b4
Merge pull request #101 from amcadmus/devel
amcadmus Jun 3, 2020
63b6f26
Method MultiSystem.from_dir support type_map && sorted glob.glob
felix5572 Jun 5, 2020
20f810b
Merge pull request #102 from felix5572/devel
amcadmus Jun 5, 2020
4a0d7ee
convert LabeledSystem to ComputedStructureEntry
haidi-ustc Jun 28, 2020
3bbd2f8
Merge pull request #104 from haidi-ustc/devel
amcadmus Jun 30, 2020
bce16bf
from deepmd for MultiSystems
njzjz Jun 30, 2020
2d681a6
Merge pull request #105 from njzjz/devel
amcadmus Jul 18, 2020
8fdb102
predict MultiSystems
njzjz Jul 25, 2020
961301a
Merge pull request #106 from njzjz/predict
amcadmus Jul 26, 2020
f65f2fe
fix double count bug
robinzyb Aug 1, 2020
572c004
Merge pull request #107 from robinzyb/devel
amcadmus Aug 2, 2020
13bd118
Merge pull request #2 from deepmodeling/devel
zezhong-zhang Aug 10, 2020
6c83ca8
sort atom according to the type_map of user input instead of alphabet…
zezhong-zhang Aug 10, 2020
ae7ff40
bug fix && modify set subtraction
felix5572 Aug 11, 2020
eb37843
Merge pull request #3 from felix5572/zezhong-devel
zezhong-zhang Aug 11, 2020
73e9cf9
Merge pull request #109 from zezhong-zhang/devel
amcadmus Aug 11, 2020
47c29d2
merge devel into master
Aug 12, 2020
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
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -20,3 +20,4 @@ dist
dpdata.egg-info
_version.py
!tests/cp2k/aimd/cp2k.log
__pycache__
23 changes: 23 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,8 @@ The `System` or `LabeledSystem` can be constructed from the following file forma
| QE | log | False | True | LabeledSystem | 'qe/pw/scf' |
| QE | log | True | False | System | 'qe/cp/traj' |
| QE | log | True | True | LabeledSystem | 'qe/cp/traj' |
| Fhi-aims| output | True | True | LabeledSystem | 'fhi_aims/md' |
| Fhi-aims| output | False | True | LabeledSystem | 'fhi_aims/scf' |
|quip/gap|xyz|True|True|MultiSystems|'quip/gap/xyz'|
| PWmat | atom.config | False | False | System | 'pwmat/atom.config' |
| PWmat | movement | True | True | LabeledSystem | 'pwmat/movement' |
Expand Down Expand Up @@ -112,6 +114,27 @@ xyz_multi_systems.systems['B1C9'].to_deepmd_raw('./my_work_dir/B1C9_raw')
xyz_multi_systems.to_deepmd_raw('./my_deepmd_data/')
```

You may also use the following code to parse muti-system:
```
from dpdata import LabeledSystem,MultiSystems
from glob import glob
"""
process multi systems
"""
fs=glob('./*/OUTCAR') # remeber to change here !!!
ms=MultiSystems()
for f in fs:
try:
ls=LabeledSystem(f)
except:
print(f)
if len(ls)>0:
ms.append(ls)

ms.to_deepmd_raw('deepmd')
ms.to_deepmd_npy('deepmd')
```

## Access data
These properties stored in `System` and `LabeledSystem` can be accessed by operator `[]` with the key of the property supplied, for example
```python
Expand Down
25 changes: 13 additions & 12 deletions dpdata/cp2k/output.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@

class Cp2kSystems(object):
"""
deal with cp2k outputfile
deal with cp2k outputfile
"""
def __init__(self, log_file_name, xyz_file_name):
self.log_file_object = open(log_file_name, 'r')
Expand Down Expand Up @@ -69,7 +69,7 @@ def get_log_block_generator(self):
break
if delimiter_flag is True:
raise RuntimeError('This file lacks some content, please check')

def get_xyz_block_generator(self):
p3 = re.compile(r'^\s*(\d+)\s*')
while True:
Expand Down Expand Up @@ -116,7 +116,7 @@ def handle_single_log_frame(self, lines):
if cell_length_pattern.match(line):
cell_A = float(cell_length_pattern.match(line).groupdict()['A']) * AU_TO_ANG
cell_B = float(cell_length_pattern.match(line).groupdict()['B']) * AU_TO_ANG
cell_C = float(cell_length_pattern.match(line).groupdict()['C']) * AU_TO_ANG
cell_C = float(cell_length_pattern.match(line).groupdict()['C']) * AU_TO_ANG
cell_flag+=1
if cell_angle_pattern.match(line):
cell_alpha = np.deg2rad(float(cell_angle_pattern.match(line).groupdict()['alpha']))
Expand Down Expand Up @@ -148,10 +148,10 @@ def handle_single_log_frame(self, lines):
element_index +=1
element_dict[line_list[2]]=[element_index,1]
atom_types_list.append(element_dict[line_list[2]][0])
forces_list.append([float(line_list[3])*AU_TO_EV_EVERY_ANG,
float(line_list[4])*AU_TO_EV_EVERY_ANG,
forces_list.append([float(line_list[3])*AU_TO_EV_EVERY_ANG,
float(line_list[4])*AU_TO_EV_EVERY_ANG,
float(line_list[5])*AU_TO_EV_EVERY_ANG])

atom_names=list(element_dict.keys())
atom_numbs=[]
for ii in atom_names:
Expand Down Expand Up @@ -190,8 +190,8 @@ def handle_single_xyz_frame(self, lines):
element_index +=1
element_dict[line_list[0]]=[element_index,1]
atom_types_list.append(element_dict[line_list[0]][0])
coords_list.append([float(line_list[1])*AU_TO_ANG,
float(line_list[2])*AU_TO_ANG,
coords_list.append([float(line_list[1])*AU_TO_ANG,
float(line_list[2])*AU_TO_ANG,
float(line_list[3])*AU_TO_ANG])
atom_names=list(element_dict.keys())
atom_numbs=[]
Expand All @@ -203,29 +203,30 @@ def handle_single_xyz_frame(self, lines):
info_dict['coords'] = np.asarray([coords_list]).astype('float32')
info_dict['energies'] = np.array([energy]).astype('float32')
info_dict['orig']=[0,0,0]
return info_dict
return info_dict

#%%

def get_frames (fname) :
coord_flag = False
force_flag = False
eV = 2.72113838565563E+01 # hatree to eV
angstrom = 5.29177208590000E-01 # Bohrto Angstrom
angstrom = 5.29177208590000E-01 # Bohrto Angstrom
fp = open(fname)
atom_symbol_list = []
cell = []
coord = []
force = []

coord_count = 0
for idx, ii in enumerate(fp) :
if 'CELL| Vector' in ii :
cell.append(ii.split()[4:7])
if 'Atom Kind Element' in ii :
coord_flag = True
coord_idx = idx
coord_count += 1
# get the coord block info
if coord_flag :
if coord_flag and (coord_count == 1):
if (idx > coord_idx + 1) :
if (ii == '\n') :
coord_flag = False
Expand Down
10 changes: 5 additions & 5 deletions dpdata/deepmd/comp.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ def to_system_data(folder,
# data is empty
data = load_type(folder, type_map = type_map)
data['orig'] = np.zeros([3])
sets = glob.glob(os.path.join(folder, 'set.*'))
sets = sorted(glob.glob(os.path.join(folder, 'set.*')))
all_cells = []
all_coords = []
all_eners = []
Expand All @@ -36,11 +36,11 @@ def to_system_data(folder,
if eners is not None:
eners = np.reshape(eners, [nframes])
if labels:
if eners is not None and len(eners) > 0:
if eners is not None and eners.size > 0:
all_eners.append(np.reshape(eners, [nframes]))
if forces is not None and len(forces) > 0:
if forces is not None and forces.size > 0:
all_forces.append(np.reshape(forces, [nframes,-1,3]))
if virs is not None and len(virs) > 0:
if virs is not None and virs.size > 0:
all_virs.append(np.reshape(virs, [nframes,3,3]))
data['cells'] = np.concatenate(all_cells, axis = 0)
data['coords'] = np.concatenate(all_coords, axis = 0)
Expand All @@ -61,7 +61,7 @@ def dump(folder,
comp_prec = np.float32,
remove_sets = True) :
os.makedirs(folder, exist_ok = True)
sets = glob.glob(os.path.join(folder, 'set.*'))
sets = sorted(glob.glob(os.path.join(folder, 'set.*')))
if len(sets) > 0:
if remove_sets :
for ii in sets :
Expand Down
25 changes: 12 additions & 13 deletions dpdata/fhi_aims/output.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
eng_patt="Total energy uncorrected.*([-]?[0-9]{1,}[.][0-9]*[E][+-][0-9]{1,})\s+eV"
#atom_numb_patt="Number of atoms.*([0-9]{1,})"

debug = False
def get_info (lines, type_idx_zero = False) :

atom_types = []
Expand All @@ -31,26 +32,23 @@ def get_info (lines, type_idx_zero = False) :
v_str=ii.split('|')[1].split()
vect=[float(kk) for kk in v_str]
cell.append(vect)
# print(cell)
#atom name

_tmp=re.findall(pos_patt_first,contents)
for ii in _tmp:
_atom_names.append(ii[0])
atom_names=[]
for ii in _atom_names:
if not ii in atom_names:
atom_names.append(ii)
#atom number
#_atom_numb_patt=re.compile(atom_numb_patt)

atom_numbs =[_atom_names.count(ii) for ii in atom_names]
if type_idx_zero :
type_map=dict(zip(atom_names,range(len(atom_names))))
else:
type_map=dict(zip(atom_names,range(1,len(atom_names)+1)))
atom_types=list(map(lambda k: type_map[k], _atom_names))
assert(atom_numbs is not None), "cannot find ion type info in aims output"

for idx,ii in enumerate(atom_numbs) :
for jj in range(ii) :
if type_idx_zero :
atom_types.append(idx)
else :
atom_types.append(idx+1)


return [cell, atom_numbs, atom_names, atom_types ]

Expand Down Expand Up @@ -81,8 +79,9 @@ def get_frames (fname, md=True, begin = 0, step = 1) :

cc = 0
while len(blk) > 0 :
# with open(str(cc),'w') as f:
# f.write('\n'.join(blk))
if debug:
with open(str(cc),'w') as f:
f.write('\n'.join(blk))
if cc >= begin and (cc - begin) % step == 0 :
if cc==0:
coord, _cell, energy, force, virial, is_converge = analyze_block(blk, first_blk=True, md=md)
Expand Down
8 changes: 4 additions & 4 deletions dpdata/lammps/dump.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,9 +83,9 @@ def get_posi_frac(lines) :
posis = np.array(posis)
return posis[:,1:4]

def safe_get_posi(lines, cell):
def safe_get_posi(lines, cell, orig = np.zeros(3)):
try:
posis = get_posi(lines)
posis = get_posi(lines) - orig
except ValueError:
fposis = get_posi_frac(lines)
posis = fposis @ cell
Expand Down Expand Up @@ -173,12 +173,12 @@ def system_data(lines, type_map = None, type_idx_zero = True) :
system['cells'] = [np.array(cell)]
natoms = sum(system['atom_numbs'])
system['atom_types'] = get_atype(lines, type_idx_zero = type_idx_zero)
system['coords'] = [safe_get_posi(lines, cell) - np.array(orig)]
system['coords'] = [safe_get_posi(lines, cell, np.array(orig))]
for ii in range(1, len(array_lines)) :
bounds, tilt = get_dumpbox(array_lines[ii])
orig, cell = dumpbox2box(bounds, tilt)
system['cells'].append(cell)
system['coords'].append(safe_get_posi(array_lines[ii], cell) - np.array(orig))
system['coords'].append(safe_get_posi(array_lines[ii], cell, np.array(orig)))
system['cells'] = np.array(system['cells'])
system['coords'] = np.array(system['coords'])
return system
Expand Down
Loading