File: db.py

package info (click to toggle)
python-ase 3.12.0-2
  • links: PTS, VCS
  • area: main
  • in suites: stretch
  • size: 14,192 kB
  • ctags: 8,112
  • sloc: python: 93,375; sh: 99; makefile: 94
file content (26 lines) | stat: -rw-r--r-- 677 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
import ase.db


def read_db(filename, index, **kwargs):
    con = ase.db.connect(filename, serial=True, **kwargs)
    if index == slice(-1, None):
        yield con.get().toatoms()
    else:
        if index == slice(None, None, None):
            index = None
        elif isinstance(index, str) and index.isdigit():
            index = int(index)
        for row in con.select(index):
            yield row.toatoms()


def write_db(filename, images, **kwargs):
    con = ase.db.connect(filename, serial=True, **kwargs)
    for atoms in images:
        con.write(atoms)

        
read_json = read_db
write_json = write_db
read_postgresql = read_db
write_postgresql = write_db