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

dpdata label system read ase db file #115

Open
wants to merge 6 commits into
base: devel
Choose a base branch
from
Open
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
Empty file added dpdata/ase/__init__.py
Empty file.
42 changes: 42 additions & 0 deletions dpdata/ase/db.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
from ase import Atom
from ase.db import connect
import numpy as np


def get_frames(fname, begin=0, step=1):
asedb = connect(fname)
num = asedb.count()
at0 = asedb.get(1).toatoms()

numbers = at0.numbers
nat0 = at0[numbers.argsort()]
chemical_symbols = nat0.get_chemical_symbols()
unique_numbers = np.unique(numbers)
unique_numbers.sort()
atom_names = [Atom(u).symbol for u in unique_numbers]
atom_numbs = [chemical_symbols.count(i) for i in atom_names]
atom_types = np.array([atom_names.index(i) for i in chemical_symbols])

all_coords = []
all_cells = []
all_energies = []
all_forces = []
all_virials = None

for i in range(begin, num, step):
ati = asedb.get(i+1)
ats_ = ati.toatoms()
numbers = ats_.numbers
sorted_numbers = numbers.argsort()
ats = ats_[sorted_numbers]
data = ati.data
energy = data['energy']
cell = ats.get_cell().view()
coord = ats.positions
forces = data['forces'][sorted_numbers]
all_coords.append(coord)
all_cells.append(cell)
all_forces.append(forces)
all_energies.append(energy)

return atom_names, atom_numbs, atom_types, np.array(all_cells), np.array(all_coords), np.array(all_energies), np.array(all_forces), all_virials
Binary file added dpdata/cp2k/.___init__.py
Binary file not shown.
Binary file added dpdata/deepmd/.___init__.py
Binary file not shown.
Binary file added dpdata/fhi_aims/.___init__.py
Binary file not shown.
Binary file added dpdata/gaussian/.___init__.py
Binary file not shown.
Binary file added dpdata/gromacs/.___init__.py
Binary file not shown.
Binary file added dpdata/lammps/.___init__.py
Binary file not shown.
Binary file added dpdata/md/.___init__.py
Binary file not shown.
16 changes: 16 additions & 0 deletions dpdata/system.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import dpdata.vasp.poscar
import dpdata.vasp.xml
import dpdata.vasp.outcar
import dpdata.ase.db
import dpdata.deepmd.raw
import dpdata.deepmd.comp
import dpdata.qe.traj
Expand Down Expand Up @@ -1137,6 +1138,21 @@ def from_vasp_outcar(self, file_name, begin = 0, step = 1) :
# rotate the system to lammps convention
self.rot_lower_triangular()

@register_from_funcs.register_funcs('db')
@register_from_funcs.register_funcs('ase/db')
def from_ase_db(self, file_name, begin = 0, step = 1) :
self.data['atom_names'], \
self.data['atom_numbs'], \
self.data['atom_types'], \
self.data['cells'], \
self.data['coords'], \
self.data['energies'], \
self.data['forces'], \
tmp_virial, \
= dpdata.ase.db.get_frames(file_name, begin = begin, step = step)

# rotate the system to lammps convention
self.rot_lower_triangular()

def affine_map_fv(self, trans, f_idx) :
assert(np.linalg.det(trans) != 0)
Expand Down
Binary file added dpdata/vasp/.___init__.py
Binary file not shown.
4 changes: 3 additions & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,13 @@
'dpdata/siesta',
'dpdata/gaussian',
'dpdata/cp2k',
'dpdata/ase',
'dpdata/xyz',
'dpdata/pwmat',
'dpdata/amber',
'dpdata/fhi_aims',
'dpdata/gromacs'
'dpdata/gromacs',
'dpdata/ase'
Copy link
Member

@njzjz njzjz Oct 9, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You need to use another directory name instead of ase, otherwise it will be conflict with the ase package when you import ase package in this directory.

],
package_data={'dpdata':['*.json']},
classifiers=[
Expand Down
2,105 changes: 2,105 additions & 0 deletions tags

Large diffs are not rendered by default.

Binary file added tests/ase/CuO.db
Binary file not shown.
Empty file added tests/test_ase_db.py
Empty file.