コード例 #1
0
    def __init__(self, *args, **kwargs):
        super(TestStructureContainer, self).__init__(*args, **kwargs)
        prim = bulk('Ag', a=4.09)
        chemical_symbols = ['Ag', 'Au']
        self.cs = ClusterSpace(structure=prim,
                               cutoffs=[4.0, 4.0, 4.0],
                               chemical_symbols=chemical_symbols)
        self.structure_list = []
        self.user_tags = []
        for k in range(4):
            structure = prim.repeat(2)
            symbols = [chemical_symbols[0]] * len(structure)
            symbols[:k] = [chemical_symbols[1]] * k
            structure.set_chemical_symbols(symbols)
            self.structure_list.append(structure)
            self.user_tags.append('Structure {}'.format(k))

        self.properties_list = []
        self.add_properties_list = []
        for k, structure in enumerate(self.structure_list):
            structure.set_calculator(EMT())
            properties = {'energy': structure.get_potential_energy(),
                          'volume': structure.get_volume(),
                          'Au atoms': structure.get_chemical_symbols().count('Au')}
            self.properties_list.append(properties)
            add_properties = {'total_energy': structure.get_total_energy()}
            self.add_properties_list.append(add_properties)
コード例 #2
0
 def __init__(self, *args, **kwargs):
     super(TestGroundStateFinderTwoActiveSublattices,
           self).__init__(*args, **kwargs)
     a = 4.0
     self.chemical_symbols = [['Au', 'Pd'], ['Li', 'Na']]
     self.cutoffs = [3.0]
     structure_prim = bulk(self.chemical_symbols[0][0], a=a)
     structure_prim.append(
         Atom(self.chemical_symbols[1][0], position=(a / 2, a / 2, a / 2)))
     structure_prim.wrap()
     self.structure_prim = structure_prim
     self.cs = ClusterSpace(self.structure_prim, self.cutoffs,
                            self.chemical_symbols)
     parameters = [0.1, -0.45, 0.333, 2, -1.42, 0.98]
     self.ce = ClusterExpansion(self.cs, parameters)
     self.all_possible_structures = []
     self.supercell = self.structure_prim.repeat(2)
     self.sl1_indices = [
         s for s, sym in enumerate(self.supercell.get_chemical_symbols())
         if sym == self.chemical_symbols[0][0]
     ]
     self.sl2_indices = [
         s for s, sym in enumerate(self.supercell.get_chemical_symbols())
         if sym == self.chemical_symbols[1][0]
     ]
     for i in self.sl1_indices:
         for j in self.sl2_indices:
             structure = self.supercell.copy()
             structure.symbols[i] = self.chemical_symbols[0][1]
             structure.symbols[j] = self.chemical_symbols[1][1]
             self.all_possible_structures.append(structure)
    def test_init_with_sublattices(self):
        """Tests the init of sublattices for different cases."""
        # First a binary with inactice sublattice (should work)
        subelements = [['Au', 'Pd'], ['H']]*(len(self.structure)//2)
        cutoffs = [3]
        cluster_space = ClusterSpace(self.structure, cutoffs, subelements)
        BinaryShortRangeOrderObserver(
            cluster_space=cluster_space, structure=self.structure,
            interval=self.interval, radius=self.radius)

        # First a binary with several inactice sublattice (should work)
        subelements = [['Au'], ['O'], ['Ge', 'Pd'], ['H']]*(len(self.structure)//4)
        cutoffs = [3]
        cluster_space = ClusterSpace(self.structure, cutoffs, subelements)
        BinaryShortRangeOrderObserver(
            cluster_space=cluster_space, structure=self.structure,
            interval=self.interval, radius=self.radius)

        # Two binary sublattices (should fail)
        subelements = [['Au', 'H'], ['Be', 'Ge']]*(len(self.structure)//2)
        cluster_space = ClusterSpace(self.structure, cutoffs, subelements)
        with self.assertRaises(ValueError) as msg:
            BinaryShortRangeOrderObserver(
                cluster_space=cluster_space, structure=self.structure,
                interval=self.interval, radius=self.radius)
        self.assertIn('Number of binary sublattices must equal one, not 2',
                      str(msg.exception))
コード例 #4
0
 def __init__(self, *args, **kwargs):
     super(TestConfigurationManager, self).__init__(*args, **kwargs)
     self.structure = bulk('Al').repeat([2, 1, 1])
     self.structure[1].symbol = 'Ag'
     self.structure = self.structure.repeat(3)
     cs = ClusterSpace(self.structure, cutoffs=[0], chemical_symbols=['Ag', 'Al'])
     self.sublattices = cs.get_sublattices(self.structure)
コード例 #5
0
    def test_is_swap_possible(self):
        """Tests is_swap_possible function."""

        # swaps are possible
        for i, sl in enumerate(self.cm.sublattices):
            self.assertTrue(self.cm.is_swap_possible(i))

        # setup system with inactive sublattice
        prim = bulk('Al').repeat([2, 1, 1])
        chemical_symbols = [['Al'], ['Ag', 'Al', 'Au']]
        cs = ClusterSpace(prim, cutoffs=[0], chemical_symbols=chemical_symbols)

        supercell = prim.repeat(2)
        supercell[1].symbol = 'Ag'
        supercell[3].symbol = 'Au'
        sublattices = cs.get_sublattices(supercell)
        cm = ConfigurationManager(supercell, sublattices)

        # check both sublattices
        self.assertTrue(cm.is_swap_possible(0))
        self.assertFalse(cm.is_swap_possible(1))

        # check both sublattices when specifying allowed species
        allowed_species = [13, 47]
        self.assertTrue(cm.is_swap_possible(0,
                                            allowed_species=allowed_species))
        self.assertFalse(cm.is_swap_possible(1,
                                             allowed_species=allowed_species))
コード例 #6
0
    def __init__(self,
                 cluster_space,
                 structure: Atoms,
                 radius: float,
                 interval: int = None) -> None:
        super().__init__(interval=interval,
                         return_type=dict,
                         tag='BinaryShortRangeOrderObserver')

        self._structure = structure

        self._cluster_space = ClusterSpace(
            structure=cluster_space.primitive_structure,
            cutoffs=[radius],
            chemical_symbols=cluster_space.chemical_symbols)
        self._cluster_count_observer = ClusterCountObserver(
            cluster_space=self._cluster_space,
            structure=structure,
            interval=interval)

        self._sublattices = self._cluster_space.get_sublattices(structure)
        binary_sublattice_counts = 0
        for symbols in self._sublattices.allowed_species:
            if len(symbols) == 2:
                binary_sublattice_counts += 1
                self._symbols = sorted(symbols)
            elif len(symbols) > 2:
                raise ValueError('Cluster space has more than two allowed'
                                 ' species on a sublattice. '
                                 'Allowed species: {}'.format(symbols))
        if binary_sublattice_counts != 1:
            raise ValueError('Number of binary sublattices must equal one,'
                             ' not {}'.format(binary_sublattice_counts))
コード例 #7
0
 def __init__(self, *args, **kwargs):
     super(TestGroundStateFinderInactiveSublatticeSameSpecies,
           self).__init__(*args, **kwargs)
     self.chemical_symbols = [['Ag', 'Au'], ['Ag']]
     self.cutoffs = [4.3]
     a = 4.0
     structure_prim = bulk(self.chemical_symbols[0][1], a=a)
     structure_prim.append(
         Atom(self.chemical_symbols[1][0], position=(a / 2, a / 2, a / 2)))
     self.structure_prim = structure_prim
     self.cs = ClusterSpace(self.structure_prim, self.cutoffs,
                            self.chemical_symbols)
     self.ce = ClusterExpansion(self.cs, [0, 0, 0.1, -0.02])
     self.all_possible_structures = []
     self.supercell = self.structure_prim.repeat(2)
     sublattices = self.cs.get_sublattices(self.supercell)
     self.n_active_sites = [
         len(subl.indices) for subl in sublattices.active_sublattices
     ]
     for i, sym in enumerate(self.supercell.get_chemical_symbols()):
         if sym not in self.chemical_symbols[0]:
             continue
         structure = self.supercell.copy()
         structure.symbols[i] = self.chemical_symbols[0][0]
         self.all_possible_structures.append(structure)
コード例 #8
0
 def __init__(self, *args, **kwargs):
     super(TestStructureGenerationSublatticesFCC,
           self).__init__(*args, **kwargs)
     self.prim = bulk('Au', a=4.0)
     self.prim.append(Atom('H', position=(2.0, 2.0, 2.0)))
     self.supercell = self.prim.repeat(3)
     self.cs = ClusterSpace(self.prim, [5.0, 4.0],
                            [['Au', 'Pd', 'Cu'], ['H', 'V']])
コード例 #9
0
    def test_get_swapped_state(self):
        """Tests the getting swap indices method."""

        for _ in range(1000):
            indices, elements = self.cm.get_swapped_state(0)
            index1 = indices[0]
            index2 = indices[1]
            self.assertNotEqual(
                self.cm.occupations[index1], self.cm.occupations[index2])
            self.assertNotEqual(
                elements[0], elements[1])
            self.assertEqual(self.cm.occupations[index1], elements[1])
            self.assertEqual(self.cm.occupations[index2], elements[0])

        # set everything to Al and see that swap is not possible
        indices = [i for i in range(len(self.structure))]
        elements = [13] * len(self.structure)
        self.cm.update_occupations(indices, elements)

        with self.assertRaises(SwapNotPossibleError) as context:
            indices, elements = self.cm.get_swapped_state(0)
        self.assertTrue("Cannot swap on sublattice" in str(context.exception))
        self.assertTrue("since it is full of" in str(context.exception))

        # setup a ternary system
        prim = bulk('Al').repeat([3, 1, 1])
        chemical_symbols = ['Ag', 'Al', 'Au']
        cs = ClusterSpace(prim, cutoffs=[0], chemical_symbols=chemical_symbols)

        for i, symbol in enumerate(chemical_symbols):
            prim[i].symbol = symbol
        supercell = prim.repeat(2)
        sublattices = cs.get_sublattices(supercell)
        cm = ConfigurationManager(supercell, sublattices)

        allowed_species = [13, 47]
        for _ in range(1000):
            indices, elements = cm.get_swapped_state(
                0, allowed_species=allowed_species)
            index1 = indices[0]
            index2 = indices[1]
            self.assertNotEqual(
                cm.occupations[index1], cm.occupations[index2])
            self.assertNotEqual(
                elements[0], elements[1])
            self.assertEqual(cm.occupations[index1], elements[1])
            self.assertEqual(cm.occupations[index2], elements[0])

        # set everything to Al and see that swap is not possible
        indices = [i for i in range(len(supercell))]
        elements = [13] * len(supercell)
        cm.update_occupations(indices, elements)

        with self.assertRaises(SwapNotPossibleError) as context:
            indices, elements = cm.get_swapped_state(
                0, allowed_species=allowed_species)
        self.assertTrue("Cannot swap on sublattice" in str(context.exception))
        self.assertTrue("since it is full of" in str(context.exception))
コード例 #10
0
 def __init__(self, *args, **kwargs):
     super(TestStructureGenerationInactiveSublatticeSameSpeciesFCC,
           self).__init__(*args, **kwargs)
     self.prim = bulk('Au', a=4.0)
     self.cs_with_only_active_sl = ClusterSpace(self.prim, [6.0, 5.0],
                                                ['Au', 'Pd'])
     self.prim.append(Atom('Au', position=(2.0, 2.0, 2.0)))
     self.supercell = self.prim.repeat(3)
     self.cs = ClusterSpace(self.prim, [6.0, 5.0], [['Au', 'Pd'], ['Au']])
コード例 #11
0
    def __init__(self, *args, **kwargs):
        super(TestFitStructure, self).__init__(*args, **kwargs)
        self.prim = bulk('Ag', a=4.09)
        self.cs = ClusterSpace(structure=self.prim, cutoffs=[4.0, 4.0, 4.0],
                               chemical_symbols=['Ag', 'Au'])

        self.structure = self.prim.repeat(2)
        self.prop = {'energy': 0.0126746}
        self.cv = self.cs.get_cluster_vector(self.structure)
        self.tag = 'struct1'
コード例 #12
0
    def test_sublattice_uniqueness(self):
        """Tests that the number of sublattices are correct
        in the case of the allowed species have duplicates in them.
        """
        structure = bulk("Al").repeat(2)

        chemical_symbols = [['H']] + [['Al', 'Ge']] * (len(structure) - 1)
        cs = ClusterSpace(structure=structure,
                          chemical_symbols=chemical_symbols,
                          cutoffs=[5])
        sublattices = cs.get_sublattices(structure)

        self.assertEqual(len(sublattices), 2)
        self.assertEqual(sublattices.allowed_species, [('Al', 'Ge'), ('H', )])
コード例 #13
0
    def test_restart_with_inactive_sites(self):
        """ Tests restart works with inactive sites """

        chemical_symbols = [['C', 'Be'], ['W']]
        prim = bulk(
            'W',
            'bcc',
            cubic=True,
        )
        cs = ClusterSpace(structure=prim,
                          chemical_symbols=chemical_symbols,
                          cutoffs=[5])
        parameters = [1] * len(cs)
        ce = ClusterExpansion(cs, parameters)

        size = 4
        structure = ce._cluster_space.primitive_structure.repeat(size)
        calculator = ClusterExpansionCalculator(structure, ce)

        # Carry out Monte Carlo simulations
        dc_file = tempfile.NamedTemporaryFile()
        mc = ConcreteEnsemble(structure=structure, calculator=calculator)
        mc.write_data_container(dc_file.name)
        mc.run(10)

        # and now restart
        mc = ConcreteEnsemble(structure=structure,
                              calculator=calculator,
                              dc_filename=dc_file.name)
        mc.run(10)
コード例 #14
0
 def __init__(self, *args, **kwargs):
     super(TestGroundStateFinderZeroParameter,
           self).__init__(*args, **kwargs)
     self.chemical_symbols = ['Ag', 'Au']
     self.cutoffs = [4.3]
     self.structure_prim = bulk(self.chemical_symbols[1], a=4.0)
     self.cs = ClusterSpace(self.structure_prim, self.cutoffs,
                            self.chemical_symbols)
     nonzero_ce = ClusterExpansion(self.cs, [0, 0, 0.1, -0.02])
     lolg = LocalOrbitListGenerator(
         self.cs.orbit_list, Structure.from_atoms(self.structure_prim),
         self.cs.fractional_position_tolerance)
     full_orbit_list = lolg.generate_full_orbit_list()
     binary_parameters_zero = transform_parameters(self.structure_prim,
                                                   full_orbit_list,
                                                   nonzero_ce.parameters)
     binary_parameters_zero[1] = 0
     A = get_transformation_matrix(self.structure_prim, full_orbit_list)
     Ainv = np.linalg.inv(A)
     zero_parameters = np.dot(Ainv, binary_parameters_zero)
     self.ce = ClusterExpansion(self.cs, zero_parameters)
     self.all_possible_structures = []
     self.supercell = self.structure_prim.repeat(2)
     for i in range(len(self.supercell)):
         structure = self.supercell.copy()
         structure.symbols[i] = self.chemical_symbols[0]
         self.all_possible_structures.append(structure)
コード例 #15
0
    def __init__(self, cluster_space: ClusterSpace, parameters: np.array,
                 metadata: dict = None) -> None:
        """
        Initializes a ClusterExpansion object.

        Parameters
        ----------
        cluster_space
            cluster space to be used for constructing the cluster expansion
        parameters
            parameter vector
        metadata : dict
            metadata dictionary, user-defined metadata to be stored together
            with cluster expansion. Will be pickled when CE is written to file.
            By default contains icet version, username, hostname and date.

        Raises
        ------
        ValueError
            if cluster space and parameters differ in length
        """
        if len(cluster_space) != len(parameters):
            raise ValueError('cluster_space ({}) and parameters ({}) must have'
                             ' the same length'.format(len(cluster_space), len(parameters)))
        self._cluster_space = cluster_space.copy()
        if isinstance(parameters, list):
            parameters = np.array(parameters)
        self._parameters = parameters

        # add metadata
        if metadata is None:
            metadata = dict()
        self._metadata = metadata
        self._add_default_metadata()
コード例 #16
0
    def __init__(self, *args, **kwargs):
        super(TestEnsembleSpectatorSublattice, self).__init__(*args, **kwargs)

        lattice_parameter = 4.0
        prim = bulk('Pd', a=lattice_parameter, crystalstructure='fcc')
        prim.append(Atom('H', position=(lattice_parameter / 2,)*3))
        self.structure = prim.repeat(3)
        for i, atom in enumerate(self.structure):
            if i % 3 == 0:
                if atom.symbol == 'Pd':
                    continue
                else:
                    atom.symbol = 'V'
        cutoffs = [5, 5, 4]
        elements = [['Pd'], ['H', 'V']]
        self.chemical_potentials = {'H': 5, 'V': 0}
        self.phis = {'H': -1.0}
        self.kappa = 200.0
        self.ensemble_specs = [{'ensemble': 'canonical', 'sublattice_index': 0},
                               {'ensemble': 'semi-grand', 'sublattice_index': 0,
                                'chemical_potentials': self.chemical_potentials},
                               {'ensemble': 'vcsgc', 'sublattice_index': 0,
                                'phis': self.phis, 'kappa': self.kappa}]
        self.cs = ClusterSpace(prim, cutoffs, elements)
        parameters = parameters = np.array([1.2] * len(self.cs))
        self.ce = ClusterExpansion(self.cs, parameters)
        self.temperature = 100.0
コード例 #17
0
    def test_sublattice_probabilities(self):
        """ Tests the sublattice_probabilities keyword argument. """

        # setup system with inactive sublattice
        prim = bulk('W', 'bcc', cubic=True)
        prim[1].symbol = 'C'
        chemical_symbols = [['W', 'Ti'], ['C', 'N']]
        cs = ClusterSpace(prim, cutoffs=[0], chemical_symbols=chemical_symbols)
        ce = ClusterExpansion(cs, [1] * len(cs))
        structure = prim.repeat(2)
        structure[0].symbol = 'Ti'
        structure[1].symbol = 'N'
        calculator = ClusterExpansionCalculator(structure, ce)

        # test default
        ensemble = WangLandauEnsemble(structure, calculator, energy_spacing=1)
        probs = ensemble._get_swap_sublattice_probabilities()
        self.assertEqual(len(probs), 2)
        self.assertAlmostEqual(probs[0], 0.5)
        self.assertAlmostEqual(probs[1], 0.5)

        # test override
        ensemble = WangLandauEnsemble(structure,
                                      calculator,
                                      energy_spacing=1,
                                      sublattice_probabilities=[0.2, 0.8])
        probs = ensemble._sublattice_probabilities
        self.assertEqual(len(probs), 2)
        self.assertAlmostEqual(probs[0], 0.2)
        self.assertAlmostEqual(probs[1], 0.8)
コード例 #18
0
def _concentrations_fit_structure(structure: Atoms,
                                  cluster_space: ClusterSpace,
                                  concentrations: Dict[str, Dict[str, float]],
                                  tol: float = 1e-5) -> bool:
    """
    Check if specified concentrations are commensurate with a
    certain supercell (including sublattices)

    Parameters
    ----------
    structure
        atomic configuration to be checked
    cluster_space
        corresponding cluster space
    concentrations
        which concentrations, per sublattice, e.g., ``{'A': {'Ag': 0.3, 'Au': 0.7}}``
    tol
        numerical tolerance
    """
    # Check that concentrations are OK in each sublattice
    for sublattice in cluster_space.get_sublattices(structure):
        if sublattice.symbol in concentrations:
            sl_conc = concentrations[sublattice.symbol]
            for conc in sl_conc.values():
                n_symbol = conc * len(sublattice.indices)
                if abs(int(round(n_symbol)) - n_symbol) > tol:
                    return False
    return True
コード例 #19
0
    def read(filename: str):
        """
        Reads ClusterExpansion object from file.

        Parameters
        ---------
        filename
            file from which to read
        """
        with tarfile.open(name=filename, mode='r') as tar_file:
            cs_file = tempfile.NamedTemporaryFile()
            cs_file.write(tar_file.extractfile('cluster_space').read())
            cs_file.seek(0)
            cs = ClusterSpace.read(cs_file.name)
            items = pickle.load(tar_file.extractfile('items'))

        ce = ClusterExpansion.__new__(ClusterExpansion)
        ce._cluster_space = cs
        ce._parameters = items['parameters']

        # TODO: remove if condition once metadata is firmly established
        if 'metadata' in items:
            ce._metadata = items['metadata']

        assert list(items['parameters']) == list(ce.parameters)
        return ce
コード例 #20
0
    def __init__(self, *args, **kwargs):
        super(TestSOFObserverClathrate, self).__init__(*args, **kwargs)

        filename = inspect.getframeinfo(inspect.currentframe()).filename
        path = os.path.dirname(os.path.abspath(filename))
        db = connect(
            os.path.join(path,
                         '../../structure_databases/primitive_clathrate.db'))

        self.cutoffs = [5] * 2
        self.structure_prim = db.get_atoms(id=1)
        self.chemical_symbols = [
            ['Ba'] if s == 'Ba' else ['Ga', 'Ge']
            for s in self.structure_prim.get_chemical_symbols()
        ]

        self.sites = {
            '6c': [24, 25, 26, 27, 28, 29],
            '16i':
            [8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23],
            '24k': [
                30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45,
                46, 47, 48, 49, 50, 51, 52, 53
            ]
        }

        self.cs = ClusterSpace(self.structure_prim, self.cutoffs,
                               self.chemical_symbols)
コード例 #21
0
    def __init__(self, *args, **kwargs):
        super(TestSOFObserverMultipleSites, self).__init__(*args, **kwargs)

        self.chemical_symbols = [['Ag', 'Au'], ['H', 'V']]
        self.cutoffs = [5] * 2
        self.structure_prim = bulk('Ag',
                                   a=4.09,
                                   crystalstructure='bcc',
                                   cubic=True).repeat([1, 1, 1])

        # 16 elements per super cell
        structure = self.structure_prim.repeat(2)
        symbols = [self.chemical_symbols[0][0], self.chemical_symbols[1][0]
                   ] * int(len(structure) / 2)
        for i in range(int(len(structure) / 2), len(structure), 2):
            symbols[i] = self.chemical_symbols[0][1]
            if i >= int(3 * len(structure) / 4):
                symbols[i + 1] = self.chemical_symbols[1][1]
        structure.set_chemical_symbols(symbols)
        self.structure = structure

        self.sites = {
            'a': list(range(0, len(structure), 2)),
            'b': list(range(1, len(structure), 2))
        }

        self.cs = ClusterSpace(self.structure_prim, self.cutoffs,
                               self.chemical_symbols)
コード例 #22
0
    def test_get_average_cluster_vectors_wl_fill_factor_limit(self):
        """Tests get_average_observables_wl function with fill factor limit."""

        fill_factor_limit = (self.fill_factor_history[20] + self.fill_factor_history[30]) / 2

        # generate target data
        cluster_space = ClusterSpace(self.prim, cutoffs=[1.1, 1.1], chemical_symbols=['Ag', 'Au'])
        temperatures = np.linspace(500, 1900, 4)
        dc = self.prepare_dc_fill_factor_limit_ref()
        target = get_average_cluster_vectors_wl(dc, cluster_space, temperatures)

        # test single container without observables
        dc = self.prepareDataContainer()
        ret = get_average_cluster_vectors_wl(dc, cluster_space, temperatures,
                                             fill_factor_limit=fill_factor_limit)
        self.assertIsInstance(ret, DataFrame)
        for key in target:
            for row_ret, row_target in zip(ret[key].tolist(), target[key]):
                self.assertTrue(np.all(np.abs(np.array(row_ret) - row_target) < 1e-8))

        # test with multiple containers
        dcs = {1: self.prepareDataContainer(energy_limit_left=None, energy_limit_right=4),
               2: self.prepareDataContainer(energy_limit_left=-4, energy_limit_right=None)}
        ret = get_average_cluster_vectors_wl(dcs, cluster_space, temperatures,
                                             fill_factor_limit=fill_factor_limit)
        self.assertIsInstance(ret, DataFrame)
        for key in target:
            for row_ret, row_target in zip(ret[key].tolist(), target[key]):
                self.assertTrue(np.all(np.abs(np.array(row_ret) - row_target) < 1e-8))
コード例 #23
0
    def __init__(self, *args, **kwargs):
        super(TestEnsemble, self).__init__(*args, **kwargs)

        # setup supercells
        self.prim = bulk('Al')
        self.structure = []
        structure = self.prim.repeat(4)
        for i, atom in enumerate(structure):
            if i % 2 == 0:
                atom.symbol = 'Ga'
        self.structure.append(structure)
        structure = self.prim.repeat(2)
        for i, atom in enumerate(structure):
            if i % 2 == 0:
                atom.symbol = 'Ga'
        self.structure.append(structure)

        # setup cluster expansion
        cutoffs = [5, 5, 4]
        elements = ['Al', 'Ga']
        cs = ClusterSpace(self.prim, cutoffs, elements)

        target_vector = np.linspace(-1, 1, len(cs))

        self.calculators = []
        for structure in self.structure:
            self.calculators.append(
                TargetVectorCalculator(structure, cs, target_vector))

        self.T_start = 3.0
        self.T_stop = 0.01
コード例 #24
0
    def test_get_swap_sublattice_probabilities(self):
        """ Tests the get_swap_sublattice_probabilities function. """

        # setup system with inactive sublattice
        prim = bulk('Al').repeat([2, 1, 1])
        chemical_symbols = [['Al'], ['Ag', 'Al']]
        cs = ClusterSpace(prim, cutoffs=[0], chemical_symbols=chemical_symbols)
        ce = ClusterExpansion(cs, [1] * len(cs))

        supercell = prim.repeat(2)
        supercell[1].symbol = 'Ag'
        ce_calc = ClusterExpansionCalculator(supercell, ce)
        ensemble = CanonicalEnsemble(supercell, ce_calc, temperature=100)

        # test get_swap_sublattice_probabilities
        probs = ensemble._get_swap_sublattice_probabilities()
        self.assertEqual(len(probs), 2)
        self.assertEqual(probs[0], 1)
        self.assertEqual(probs[1], 0)

        # test raise when swap not possible on either lattice
        supercell[1].symbol = 'Al'
        ce_calc = ClusterExpansionCalculator(supercell, ce)

        with self.assertRaises(ValueError) as context:
            ensemble = CanonicalEnsemble(supercell, ce_calc, temperature=100)
        self.assertIn('No canonical swaps are possible on any of the',
                      str(context.exception))
コード例 #25
0
    def __init__(self, *args, **kwargs):
        super(TestEnsemble, self).__init__(*args, **kwargs)

        # prepare cluster expansion
        self.prim = Atoms('Au',
                          positions=[[0, 0, 0]],
                          cell=[1, 1, 10],
                          pbc=True)
        cs = ClusterSpace(self.prim,
                          cutoffs=[1.1],
                          chemical_symbols=['Ag', 'Au'])
        self.ce = ClusterExpansion(cs, [0, 0, 2])

        # prepare initial configuration
        self.structure = self.prim.repeat((2, 2, 1))
        self.structure[0].symbol = 'Ag'
        self.structure[1].symbol = 'Ag'
        self.structure = self.structure.repeat((2, 2, 1))

        # other variables and parameters
        self.trial_move = 'swap'
        self.energy_spacing = 1
        self.flatness_limit = 0.8
        self.fill_factor_limit = 1e-4
        self.flatness_check_interval = 10
        self.data_container_write_period = 499
        self.ensemble_data_write_interval = 1
        self.trajectory_write_interval = 10
コード例 #26
0
    def __init__(self, *args, **kwargs):
        super(TestEnsemble, self).__init__(*args, **kwargs)

        prim = Atoms('Au', positions=[[0, 0, 0]], cell=[1, 1, 1], pbc=True)
        self.structure = prim.repeat(3)
        self.cs = ClusterSpace(prim,
                               cutoffs=[1.1],
                               chemical_symbols=['Ag', 'Au'])
        self.ce = ClusterExpansion(self.cs, [0, 0, 2])
コード例 #27
0
    def __init__(self, *args, **kwargs):
        super(TestClusterCountObserverMaxOrbit, self).__init__(*args, **kwargs)

        prim = bulk('Au')
        self.structure = prim.repeat(3)
        cutoffs = [6, 5]
        subelements = ['Au', 'Pd']
        self.cs = ClusterSpace(prim, cutoffs, subelements)
        self.interval = 10
コード例 #28
0
def get_sqs_hcp(conc):
    atoms = bulk('Mg')
    cs = ClusterSpace(atoms, [10.0, 7.0], [['Al', 'Mg'], ['O', 'H']])
    conc = {'Al': 0.25, 'Mg': 0.25, 'O': 0.25, 'H': 0.25}
    sqs = generate_sqs(cluster_space=cs,
                       max_size=16,
                       target_concentrations=conc,
                       include_smaller_cells=False)
    return sqs
コード例 #29
0
def get_sqs(conc):
    atoms = bulk("Al", a=4.05)
    cs = ClusterSpace(atoms, [5.0, 5.0], ['Al', 'Mg'])

    sqs = generate_sqs(cluster_space=cs,
                       max_size=16,
                       target_concentrations=conc,
                       include_smaller_cells=False)
    return sqs
コード例 #30
0
    def __init__(self, *args, **kwargs):
        super(TestClusterCountObserver, self).__init__(*args, **kwargs)

        self.structure = bulk('Al').repeat([2, 1, 1])
        self.structure[1].symbol = 'Ge'

        cutoffs = [3]
        subelements = ['Al', 'Ge', 'Si']
        self.cs = ClusterSpace(self.structure, cutoffs, subelements)
        self.interval = 10