File: test_particle_mutations.py

package info (click to toggle)
python-ase 3.26.0-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 15,484 kB
  • sloc: python: 148,112; xml: 2,728; makefile: 110; javascript: 47
file content (26 lines) | stat: -rw-r--r-- 848 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
# fmt: off
import numpy as np

from ase.build import fcc111
from ase.ga.particle_mutations import Poor2richPermutation, Rich2poorPermutation


def test_rich2poor_permutations():
    rng = np.random.RandomState(seed=1234)

    slab = fcc111("Pd", size=(10, 10, 1), vacuum=10.0)
    for i in range(0, len(slab), 2):
        slab.symbols[i] = "Ag"
    slab.info["confid"] = ""
    elements = ["Pd", "Ag"]

    parents = [slab]
    creator = Rich2poorPermutation(elements=elements, rng=rng, num_muts=1)
    offspring, _ = creator.get_new_individual(parents)
    assert offspring.symbols[17] == "Ag"
    assert offspring.symbols[92] == "Pd"

    creator = Poor2richPermutation(elements=elements, rng=rng, num_muts=1)
    offspring, _ = creator.get_new_individual(parents)
    assert offspring.symbols[7] == "Ag"
    assert offspring.symbols[38] == "Pd"