def test_Atoms_copy_from(): """Tests the mothed Atoms.copy_from to copy from an matdb.atoms """ from matdb.atoms import Atoms from numpy import array_equal at1 = Atoms("Co3W2V3",positions=[[0,0,0],[0.25,0.25,0.25],[0.5,0.5,0],[1.75,1.75,1.25], [1.5,1,1.5],[2.75,2.25,2.75],[2,2.5,2.5],[2.25,2.75,2.75]], cell=[5.43,5.43,5.43],info={"rand":10, "params":{"vasp_energy": 1234}, "properties":{}}) at1.__setattr__("magnetic_moments", [1.2,2.3,3.4,4.5,5.6,6.7,7.8,8.9]) at2 = Atoms() at2.copy_from(at1) assert at1.info["params"] == at2.info["params"] assert at1.info["properties"] == at2.info["properties"] # make sure the symbols and positions are still match assert at1.get_chemical_symbols() == at2.get_chemical_symbols() assert array_equal(at1.positions, at2.positions) assert array_equal(at1.cell, at2.cell)
def test_Atoms__setattr__(): """Tests the mothed Atoms.__setattr__ """ from matdb.atoms import Atoms at1 = Atoms("Co3W2V3") at1.__setattr__("params", {"vasp_energy": 1234}) at1.__setattr__("properties", {"rank": 21}) at1.__setattr__("cell", [[5.43, 0. , 0. ], [0. , 5.43, 0. ], [0. , 0. , 5.43]]) at1.__setattr__("positions", [[0,0,0],[0.25,0.25,0.25],[0.5,0.5,0],[1.75,1.75,1.25], [1.5,1,1.5],[2.75,2.25,2.75],[2,2.5,2.5],[2.25,2.75,2.75]]) assert at1.__getattr__("params") == {"vasp_energy": 1234} assert at1.__getattr__("properties") == {"rank": 21} assert np.allclose(at1.__getattr__("cell"), [[5.43, 0. , 0. ], [0. , 5.43, 0. ], [0. , 0. , 5.43]]) assert np.allclose(at1.__getattr__("positions"), [[0,0,0],[0.25,0.25,0.25],[0.5,0.5,0],[1.75,1.75,1.25], [1.5,1,1.5],[2.75,2.25,2.75],[2,2.5,2.5],[2.25,2.75,2.75]]) at1.__setattr__("rank", 22) assert at1.__getattr__("rank") == 22 at1.__setattr__("vasp_energy", 4321) assert at1.__getattr__("vasp_energy") == 4321