How to use the pyiron.atomistics.structure.atom.Atom function in pyiron

To help you get started, we’ve selected a few pyiron examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github pyiron / pyiron / tests / atomistics / structure / test_atoms.py View on Github external
self.assertTrue(
            np.allclose(
                b.get_scaled_positions()[b.select_index("O")],
                [[0.5, 0.5, 0.5], [0.0, 0.0, 0.0]],
            )
        )
        b.set_repeat([2, 2, 2])
        self.assertEqual(b.get_chemical_formula(), "H24N8O16")
        b += basis_4
        self.assertEqual(b.get_chemical_formula(), "H24N8O16O_up")
        self.assertTrue(
            np.allclose(
                b.get_scaled_positions()[b.select_index(o_up)], [[0.27, 0.27, 0.27]]
            )
        )
        COX = self.C2 + Atom("O", position=[0, 0, -2])
        COX += Atom("O", position=[0, 0, -4])
        COX += COX
        n_objects = len(set(COX.get_species_objects()))
        n_species = len(set(COX.get_chemical_elements()))
        self.assertEqual(n_objects, n_species)
        self.assertEqual(n_objects, 2)
        self.assertEqual(n_species, 2)
        basis_Mg = CrystalStructure("Mg", bravais_basis="fcc", lattice_constant=4.2)
        basis_O = CrystalStructure("O", bravais_basis="fcc", lattice_constant=4.2)
        # basis_O.set_relative()
        basis_O.set_scaled_positions([0.0, 0.0, 0.5] + basis_O.get_scaled_positions())
        basis = basis_Mg + basis_O
        self.assertEqual(
            len(basis._tag_list), len(basis_Mg._tag_list) + len(basis_O._tag_list)
        )
        basis.center_coordinates_in_unit_cell()
github pyiron / pyiron / tests / atomistics / structure / test_atoms.py View on Github external
def setUpClass(cls):
        C = Atom("C").element
        cls.C3 = Atoms([C, C, C], positions=[[0, 0, 0], [0, 0, 2], [0, 2, 0]])
        cls.C2 = Atoms(2 * [Atom("C")])
github pyiron / pyiron / tests / atomistics / structure / test_atoms.py View on Github external
def setUpClass(cls):
        C = Atom("C").element
        cls.C3 = Atoms([C, C, C], positions=[[0, 0, 0], [0, 0, 2], [0, 2, 0]])
        cls.C2 = Atoms(2 * [Atom("C")])
github pyiron / pyiron / tests / atomistics / structure / test_atom.py View on Github external
def test__init__(self):
        self.Fe_atom.rel = True
        self.assertEqual(self.Fe_atom.element.Abbreviation, "Fe")
        self.assertEqual(self.Fe_atom.position.tolist(), [0, 0, 0])
        self.assertEqual(self.Fe_atom.rel, True)

        self.assertEqual(Atom(Z=13).element.Abbreviation, "Al")
        self.assertRaises(ValueError, Atom)
        self.assertRaises(ValueError, Atom, 13)
        self.assertEqual(Atom('Si', (0, 0, 0)).position.tolist(), [0, 0, 0])

        self.assertEqual(self.Al_atom.symbol, 'Al')
        self.assertEqual(self.Al_atom.element.tags["spin"], -1)
github pyiron / pyiron / pyiron / atomistics / structure / atoms.py View on Github external
def __getitem__(self, item):
        new_dict = dict()
        if isinstance(item, int):
            for key, value in self._tag_list.items():
                if item < len(value):
                    if value[item] is not None:
                        new_dict[key] = value[item]
            element = self.species[self.indices[item]]
            index = item
            position = self.positions[item]
            return Atom(element=element, position=position, pse=self._pse, index=index, atoms=self, **new_dict)

        new_array = copy(self)
        new_array.positions = self.positions[item]

        new_indices = self.indices[item].copy()
        new_species_indices, new_proper_indices = np.unique(new_indices, return_inverse=True)
        new_species = [self.species[ind] for ind in new_species_indices]
        new_array.set_species(new_species)
        new_array.indices = new_proper_indices
        new_array._tag_list = self._tag_list[item]
        # new_array._tag_list._length = self._tag_list._length
        new_array._tag_list._length = len(new_array)
        if isinstance(new_array, Atom):
            natoms = len(self)
            if item < -natoms or item >= natoms:
                raise IndexError('Index out of range.')
github pyiron / pyiron / pyiron / atomistics / structure / atoms.py View on Github external
Args:
            el (str/atomistics.structure.atom.Atom): String or atom instance from which the element should
                                                            be generated
            pse (atomistics.structure.periodictable.PeriodicTable): PeriodicTable instance from which the element
                                                                           is generated (optional)

        Returns:

            atomistics.structure.periodictable.ChemicalElement: The required chemical element

        """
        if el in list(self._store_elements.keys()):
            return self._store_elements[el]

        if isinstance(el, string_types):  # as symbol
            element = Atom(el, pse=pse).element
        elif isinstance(el, Atom):
            element = el.element
            el = el.element.Abbreviation
        elif isinstance(el, ChemicalElement):
            element = el
            el = el.Abbreviation
        else:
            raise ValueError('Unknown static type to specify a element')

        self._store_elements[el] = element
        if hasattr(self, 'species'):
            if element not in self.species:
                self._species.append(element)
                self.set_species(self._species)
        return element
github pyiron / pyiron / pyiron / atomistics / structure / atoms.py View on Github external
Args:
            el (str/atomistics.structure.atom.Atom): String or atom instance from which the element should
                                                            be generated
            pse (atomistics.structure.periodictable.PeriodicTable): PeriodicTable instance from which the element
                                                                           is generated (optional)

        Returns:

            atomistics.structure.periodictable.ChemicalElement: The required chemical element

        """
        if el in list(self._store_elements.keys()):
            return self._store_elements[el]

        if isinstance(el, string_types):  # as symbol
            element = Atom(el, pse=pse).element
        elif isinstance(el, Atom):
            element = el.element
            el = el.element.Abbreviation
        elif isinstance(el, ChemicalElement):
            element = el
            el = el.Abbreviation
        else:
            raise ValueError('Unknown static type to specify a element')

        self._store_elements[el] = element
        if hasattr(self, 'species'):
            if element not in self.species:
                self._species.append(element)
                self.set_species(self._species)
        return element
github pyiron / pyiron / pyiron / atomistics / structure / atom.py View on Github external
def __eq__(self, other):
        if not (isinstance(other, Atom)):
            return False
        conditions = [np.allclose(self.position, other.position), self.symbol == other.symbol]
        return all(conditions)