Exemplo n.º 1
0
def sync(group, db_sqlite, db_server):
    num_inserted = 0
    symm_checker = SymmetryEquivalenceCheck()
    atoms_on_server = [r.toatoms() for r in db_server.select(type='initial')]
    rows = []
    for r in db_sqlite.select(group=group):
        rows.append(r)

    for r in rows:
        if symm_checker.compare(r.toatoms(), atoms_on_server):
            exists = True
            print("Structures already exists in DB")
            return

    for row in rows:
        if row.get('struct_type', 'none') == 'initial':
            row.__dict__.update({'type': 'initial'})
            if 'type' not in row._keys:
                row._keys.append('type')
        try:
            row.__dict__.update({'project': 'cluster_expansion_almgsiX_fcc'})
            row._keys.append('project')
            db_server.write(row)
            num_inserted += 1
        except Exception as exc:
            print(exc)
    print("Inserted {} calculations".format(num_inserted))
Exemplo n.º 2
0
Arquivo: io.py Projeto: zadorlab/pynta
    def get_unique_prefixes(
            path_to_species: str) -> List[str]:
        ''' Compare each conformers for a given adsorbate and returns a list
        with prefixes of a symmetrty dictinct structures

        Parameters
        ----------
        path_to_species : str
            a path to species
            e.g. ``'Cu_111/minima/CO'``

        Returns
        -------
        unique_minima_prefixes : List[str]
            a list with prefixes of symmetry distinct structures for a given
            adsorbate

        '''
        good_minima = []
        result_dict = {}
        unique_minima_prefixes = []
        trajlist = sorted(Path(path_to_species).glob('*traj'), key=str)
        for traj in trajlist:
            minima = read(traj)
            comparator = SymmetryEquivalenceCheck(to_primitive=True)
            result = comparator.compare(minima, good_minima)
            result_dict[str(os.path.basename(traj).split('.')[0])] = result
            if result is False:
                good_minima.append(minima)
        for prefix, result in result_dict.items():
            if result is False:
                unique_minima_prefixes.append(prefix)
        return unique_minima_prefixes
Exemplo n.º 3
0
def sync():
    db_server = connect(MYSQL_DB)
    db_sqlite = connect(SQLITE_DB)

    num_inserted = 0
    symm_checker = SymmetryEquivalenceCheck()
    atoms_on_server = [r.toatoms() for r in db_server.select(type='initial')]
    groups = [row.get('group', -1) for row in db_sqlite.select()]
    for g in groups:
        rows = []
        for r in db_sqlite.select(group=g):
            rows.append(r)

        exists = False
        for r in rows:
            if symm_checker.compare(r.toatoms(), atoms_on_server):
                exists = True
                break

        if exists:
            continue

        for r in rows:
            try:
                row.__dict__.update(
                    {'project': 'cluster_expansion_almgsiX_fcc'})
                row._keys.append('project')
                #db_server.write(row)
                num_inserted += 1
            except Exception:
                pass
    print("Inserted {} calculations".format(num_inserted))
Exemplo n.º 4
0
def test_spglib_standardize():
    for i in [
            "../tests/MoS2_2H_1l.xyz",
            "../tests/WS2_2H_1l.xyz",
            "../tests/graphene.xyz",
    ]:
        atoms = ase.io.read(PROJECT_ROOT_DIR.joinpath(i))
        N = [[3, 1, 0], [-1, 2, 0], [0, 0, 1]]
        sc = make_supercell(atoms, N)
        cppatoms = ase_atoms_to_cpp_atoms(sc)
        cppatoms.standardize(1, 0, 1e-5, 5)

        cell = (sc.cell, sc.get_scaled_positions(), sc.numbers)
        spgcell = spglib.standardize_cell(cell,
                                          to_primitive=True,
                                          no_idealize=False,
                                          symprec=1e-5,
                                          angle_tolerance=5)
        atoms = Atoms(
            cell=spgcell[0],
            scaled_positions=spgcell[1],
            numbers=spgcell[2],
            pbc=[True, True, True],
        )
        cppatoms = cpp_atoms_to_ase_atoms(cppatoms)
        comp = SymmetryEquivalenceCheck()
        is_equal = comp.compare(atoms, cppatoms)
        assert (
            is_equal
        ), "Standardization in backend and from spglib do not yield same result."
Exemplo n.º 5
0
def exists_in_db(a):

    db = connect('FeCu.db')
    atoms = []

    for row in db.select(struct_type = 'initial'):

        atoms.append(row.toatoms())

    symcheck = SymmetryEquivalenceCheck()

    return symcheck.compare(a, atoms)
Exemplo n.º 6
0
def exists_in_db(a, db_name):

    db = connect(db_name)
    atoms = []
    print('Checking database ' + db_name)
    for row in db.select(struct_type='initial'):

        atoms.append(row.toatoms())

    symcheck = SymmetryEquivalenceCheck()

    return symcheck.compare(a, atoms)
Exemplo n.º 7
0
Arquivo: ts.py Projeto: zadorlab/pynta
    def check_symm(path: str,
                   return_unique: bool,
                   compare_traj: bool = True) -> List[int]:
        ''' Check for the symmetry equivalent structures in the given path

        Parameters
        ___________
        path : str
            a path to a directory where are files to be checked,
            e.g. ``'Cu_111/TS_estimate_unique'``
        return_unique : bool
            If True, the method will return a list of unique prefixes.
            If False, the method will return a list of non-unique prefixes.
        compare_traj : bool
            If True, the method will compare .traj files.
            If False, .xyz files will be compared

        Returns
        ________
        idx_list : list(str)
            a list with prefixes of all symmetrically distinct sites

        '''
        if compare_traj:
            keyphrase = '**/*.traj'
        else:
            keyphrase = '*.xyz'

        comparator = SymmetryEquivalenceCheck()
        list_of_geoms = sorted(Path(path).glob(keyphrase))

        good_adsorbates_atom_obj_list = []
        result = []

        for geom in list_of_geoms:
            adsorbate_atom_obj = read(geom)
            adsorbate_atom_obj.pbc = True
            comparision = comparator.compare(adsorbate_atom_obj,
                                             good_adsorbates_atom_obj_list)
            result.append(comparision)

            if comparision is False:
                good_adsorbates_atom_obj_list.append(adsorbate_atom_obj)

        list_of_prefixes = []
        for num, res in enumerate(result):
            if res is not return_unique:
                list_of_prefixes.append(str(num).zfill(3))
        return list_of_prefixes
Exemplo n.º 8
0
def test_one_vs_many():
    s1 = Atoms('H3', positions=[[0.5, 0.5, 0], [0.5, 1.5, 0], [1.5, 1.5, 0]],
               cell=[2, 2, 2], pbc=True)
    # Get the unit used for position comparison
    u = (s1.get_volume() / len(s1))**(1 / 3)
    comp = SymmetryEquivalenceCheck(stol=.095 / u, scale_volume=True)
    s2 = s1.copy()
    assert comp.compare(s1, s2)
    s2_list = []
    s3 = Atoms('H3', positions=[[0.5, 0.5, 0], [0.5, 1.5, 0], [1.5, 1.5, 0]],
               cell=[3, 3, 3], pbc=True)
    s2_list.append(s3)
    for d in np.linspace(0.1, 1.0, 5):
        s2 = s1.copy()
        s2.positions[0] += [d, 0, 0]
        s2_list.append(s2)
    assert not comp.compare(s1, s2_list[:-1])
    assert comp.compare(s1, s2_list)
Exemplo n.º 9
0
def test_original_paper_structures():
    # Structures from the original paper:
    # Comput. Phys. Commun. 183, 690-697 (2012)
    # They should evaluate equal (within a certain tolerance)
    syms = ['O', 'O', 'Mg', 'F']
    cell1 = [(3.16, 0.00, 0.00), (-0.95, 4.14, 0.00), (-0.95, -0.22, 4.13)]
    p1 = [(0.44, 0.40, 0.30), (0.94, 0.40, 0.79), (0.45, 0.90, 0.79),
          (0.94, 0.40, 0.29)]
    s1 = Atoms(syms, cell=cell1, scaled_positions=p1, pbc=True)

    cell2 = [(6.00, 0.00, 0.00), (1.00, 3.00, 0.00), (2.00, -3.00, 3.00)]
    p2 = [(0.00, 0.00, 0.00), (0.00, 0.00, 0.50), (0.50, 0.00, 0.00),
          (0.00, 0.50, 0.00)]
    s2 = Atoms(syms, cell=cell2, scaled_positions=p2, pbc=True)

    comp = SymmetryEquivalenceCheck()

    assert comp.compare(s1, s2)
    assert comp.compare(s2, s1) == comp.compare(s1, s2)
Exemplo n.º 10
0
def test_backend_supercell():
    for i in [
            "../tests/MoS2_2H_1l.xyz",
            "../tests/WS2_2H_1l.xyz",
            "../tests/graphene.xyz",
    ]:
        atoms = ase.io.read(PROJECT_ROOT_DIR.joinpath(i))
        cppatoms = ase_atoms_to_cpp_atoms(atoms)
        N = [[3, 1, 0], [-1, 2, 0], [0, 0, 1]]
        atoms = make_supercell(atoms, N)

        N = int2dVector([int1dVector(k) for k in N])
        cppatoms = cpp_make_supercell(cppatoms, N)
        cppatoms = cpp_atoms_to_ase_atoms(cppatoms)
        comp = SymmetryEquivalenceCheck()
        is_equal = comp.compare(atoms, cppatoms)
        assert (
            is_equal
        ), "Supercell generation in backend and from ASE do not yield same result."
Exemplo n.º 11
0
Arquivo: io.py Projeto: zadorlab/pynta
    def get_unique_final_ts_prefixes(
            path_to_ts: str) -> List[str]:
        ''' Compare each conformers for a given adsorbate and returns a list
        with prefixes of a symmetrty dictinct structures

        Parameters
        ----------
        path_to_species : str
            a path to species
            e.g. ``'Cu_111/minima/CO'``

        Returns
        -------
        unique_minima_prefixes : List[str]
            a list with prefixes of symmetry distinct structures for a given
            adsorbate

        '''
        unique_ts = []
        result_dict = {}
        unique_ts_prefixes = []
        trajlist = sorted(Path(path_to_ts).glob('**/*traj'), key=str)
        for traj in trajlist:
            try:
                ts = read(traj)
                comparator = SymmetryEquivalenceCheck(to_primitive=True)
                result = comparator.compare(ts, unique_ts)
                result_dict[str(os.path.basename(traj)[:2])] = result
                if result is False:
                    unique_ts.append(ts)
            # error handling while calculations are still running/unfinished
            except UnknownFileTypeError:
                pass
        for prefix, result in result_dict.items():
            if result is False:
                unique_ts_prefixes.append(prefix)
        return unique_ts_prefixes
Exemplo n.º 12
0
    del a5[5]

    assert comparator.compare(a0, a5)
    assert comparator.compare(a5, a0) == comparator.compare(a0, a5)


def run_all_tests(comparator):
    test_compare(comparator)
    test_fcc_bcc(comparator)
    test_single_impurity(comparator)
    test_translations(comparator)
    test_rot_60_deg(comparator)
    test_rot_120_deg(comparator)
    test_rotations_to_standard(comparator)
    test_point_inversion(comparator)
    test_mirror_plane(comparator)
    test_hcp_symmetry_ops(comparator)
    test_fcc_symmetry_ops(comparator)
    test_bcc_symmetry_ops(comparator)
    test_bcc_translation(comparator)
    test_one_atom_out_of_pos(comparator)
    test_reduce_to_primitive(comparator)
    test_order_of_candidates(comparator)
    test_one_vs_many()
    test_original_paper_structures()
    test_supercell_w_periodic_atom_removed(comparator)


comparator = SymmetryEquivalenceCheck()
run_all_tests(comparator)
Exemplo n.º 13
0
def comparator():
    return SymmetryEquivalenceCheck()