File: test_create_database.py

package info (click to toggle)
python-ase 3.21.1-2
  • links: PTS, VCS
  • area: main
  • in suites: bullseye
  • size: 13,936 kB
  • sloc: python: 122,428; xml: 946; makefile: 111; javascript: 47
file content (33 lines) | stat: -rw-r--r-- 851 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
27
28
29
30
31
32
33
def test_create_database():
    from ase.ga.data import PrepareDB
    from ase.ga.data import DataConnection
    import os
    import numpy as np

    db_file = 'gadb.db'
    if os.path.isfile(db_file):
        os.remove(db_file)


    from ase.build import fcc111

    atom_numbers = np.array([78, 78, 79, 79])
    slab = fcc111('Ag', size=(4, 4, 2), vacuum=10.)

    PrepareDB(db_file_name=db_file,
              simulation_cell=slab,
              stoichiometry=atom_numbers)

    assert os.path.isfile(db_file)

    dc = DataConnection(db_file)

    slab_get = dc.get_slab()
    an_get = dc.get_atom_numbers_to_optimize()

    assert len(slab) == len(slab_get)
    assert np.all(slab.numbers == slab_get.numbers)
    assert np.all(slab.get_positions() == slab_get.get_positions())
    assert np.all(an_get == atom_numbers)

    os.remove(db_file)