How to use the pyiron.atomistics.structure.sparse_list.SparseList 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_sparse_list.py View on Github external
def setUp(self):
        aList = SparseList({1: True, 4: True}, length=6)
        cList = SparseList({1: 0.2, 3: 0.5}, default=0, length=6)
        list_1 = [5, 4, 3, 4, 5, 6]
        self.aMatrix = SparseArray(list_1=list_1, aList=aList, cList=cList)
github pyiron / pyiron / tests / atomistics / structure / test_sparse_list.py View on Github external
def setUp(self):
        self.aList = SparseList({1: True, 4: True}, length=7)
        self.cList = SparseList({1: 0.2, 3: 0.5}, default=0, length=5)
github pyiron / pyiron / tests / atomistics / structure / test_atoms.py View on Github external
def test_get_tags(self):
        self.CO2.add_tag(test_tag="a")
        self.assertIsInstance(self.CO2.test_tag, SparseList)
        self.assertIsInstance(self.CO2.get_tags(), type(dict().keys()))
github pyiron / pyiron / tests / atomistics / structure / test_sparse_list.py View on Github external
def test_add_tag(self):
        self.aMatrix.add_tag("coordinates")
        self.assertTrue("coordinates" in self.aMatrix.keys())
        self.assertTrue(len(self.aMatrix.coordinates) == 6)
        self.assertTrue(isinstance(self.aMatrix.coordinates, SparseList))

        self.aMatrix.add_tag(rel=[True, True, True])
        self.assertTrue(self.aMatrix.rel[1] == [True, True, True])
github pyiron / pyiron / tests / atomistics / structure / test_sparse_list.py View on Github external
def setUpClass(cls):
        cls.aList = SparseList({1: True, 4: True}, length=7)
        cls.cList = SparseList({1: 0.2, 3: 0.5}, default=0, length=5)
github pyiron / pyiron / tests / atomistics / structure / test_sparse_list.py View on Github external
def setUp(self):
        aList = SparseList({1: True, 4: True}, length=6)
        cList = SparseList({1: 0.2, 3: 0.5}, default=0, length=6)
        list_1 = [5, 4, 3, 4, 5, 6]
        self.aMatrix = SparseArray(list_1=list_1, aList=aList, cList=cList)
github pyiron / pyiron / pyiron / atomistics / structure / sparse_list.py View on Github external
def __copy__(self):
        return SparseList(sparse_list=self._dict, default=self._default, length=self._length)
github pyiron / pyiron / pyiron / atomistics / structure / sparse_list.py View on Github external
def __add__(self, other):
        # print "__add__.new_elements"
        # assert(isinstance(other, self.__class__))
        new_array = self.__copy__()
        for key, val in other.items():
            if key not in self.keys():
                if isinstance(val, SparseList):
                    new_array._lists[key] = SparseList({}, default=other._lists[key]._default, length=len(self))
                else:
                    raise ValueError('Incompatible lists (for non-sparse lists keys must be identical (1)' + str(key))

        new_length = len(self) + len(other)
        for key, val in new_array.items():
            # print "key: ", key, val.__class__, isinstance(new_array, SparseList)
            if key in other.keys():
                if isinstance(new_array._lists[key], np.ndarray):
                    new_array._lists[key] = np.append(new_array._lists[key], other._lists[key], axis=0)
                elif isinstance(new_array._lists[key], (list, SparseList)):
                    new_array._lists[key] += other._lists[key]
                else:
                    raise ValueError("Type not implemented " + str(type(new_array._lists[key])))
            elif isinstance(val, SparseList):
                new_array._lists[key]._length = new_length  # TODO: default extends to all elements (may be undesired)
            else:
github pyiron / pyiron / pyiron / atomistics / structure / atoms.py View on Github external
self._tag_list._length = len(self)

                self.set_species(el_object_list)
                self.bonds = None
                if "explicit_bonds" in hdf_atoms.list_nodes():
                    # print "bonds: "
                    self.bonds = hdf_atoms["explicit_bonds"]

                if "tags" in hdf_atoms.list_groups():
                    with hdf_atoms.open("tags") as hdf_tags:
                        tags = hdf_tags.list_nodes()
                        for tag in tags:
                            # tr_dict = {'0': False, '1': True}
                            if isinstance(hdf_tags[tag], (list, np.ndarray)):
                                my_list = hdf_tags[tag]
                                self._tag_list[tag] = SparseList(my_list, length=len(self))

                            else:
                                my_dict = hdf_tags.get_pandas(tag).to_dict()
                                my_dict = {i: val for i, val in zip(my_dict["index"], my_dict["values"])}
                                self._tag_list[tag] = SparseList(my_dict, length=len(self))

                tr_dict = {1: True, 0: False}
                self.dimension = hdf_atoms["dimension"]
                self.units = hdf_atoms["units"]

                self.cell = None
                if "cell" in hdf_atoms.list_groups():
                    with hdf_atoms.open("cell") as hdf_cell:
                        self.cell = hdf_cell["cell"]
                        self.pbc = hdf_cell["pbc"]