Ejemplo n.º 1
0
def test_Atoms__getattr__():
    """Tests the mothed Atoms.__getattr__
    """
    from matdb.atoms import Atoms

    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={"params":{"vasp_energy": 1234}, "properties":{}})
    assert at1.__getattr__("params") == {"vasp_energy": 1234}
    assert at1.__getattr__("properties") == {}
    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]])

    at2 = Atoms("Co3W2V3", cell=[5.43,5.43,5.43])
    del at2.__dict__["info"]
    assert not hasattr(at2,"info")
    assert np.allclose(at2.__getattr__("cell"), [[5.43, 0.  , 0.  ], [0.  , 5.43, 0.  ], [0.  , 0.  , 5.43]])
Ejemplo n.º 2
0
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