Exemplo n.º 1
0
def test_methods():
    tr = crys.Trajectory(coords=rand(100, 10, 3),
                         cell=rand(100, 3, 3),
                         symbols=['H'] * 10)
    st = crys.Structure(coords=rand(10, 3),
                        cell=rand(3, 3),
                        symbols=['H'] * 10)

    for obj, indices in [(st, [0, 1, 2]), (tr, [0, 0, 1, 2])]:
        if obj.is_traj:
            v0 = obj.coords[indices[0], indices[1], ...]
            v1 = obj.coords[indices[0], indices[2], ...]
            v2 = obj.coords[indices[0], indices[3], ...]
        else:
            v0 = obj.coords[indices[0], ...]
            v1 = obj.coords[indices[1], ...]
            v2 = obj.coords[indices[2], ...]
        # use eps=0 since the new system is not orthogonal, only test API
        o1 = crys.align_cart(obj, x=v1 - v0, y=v2 - v0, eps=0)
        o2 = crys.align_cart(obj, vecs=np.array([v0, v1, v2]), eps=0)
        o3 = crys.align_cart(obj, indices=indices, eps=0)
        tools.assert_dict_with_all_types_almost_equal(o1.__dict__,
                                                      o2.__dict__,
                                                      keys=o1.attr_lst)
        tools.assert_dict_with_all_types_almost_equal(o1.__dict__,
                                                      o3.__dict__,
                                                      keys=o1.attr_lst)
Exemplo n.º 2
0
def test_methods():
    tr = crys.Trajectory(coords=rand(100,10,3),
                         cell=rand(100,3,3),
                         symbols=['H']*10)
    st = crys.Structure(coords=rand(10,3),
                        cell=rand(3,3),
                        symbols=['H']*10)
    
    for obj,indices in [(st, [0,1,2]), (tr, [0,0,1,2])]:
        if obj.is_traj:
            v0 = obj.coords[indices[0],indices[1],...]
            v1 = obj.coords[indices[0],indices[2],...]
            v2 = obj.coords[indices[0],indices[3],...]
        else:            
            v0 = obj.coords[indices[0],...]
            v1 = obj.coords[indices[1],...]
            v2 = obj.coords[indices[2],...]
        # use eps=0 since the new system is not orthogonal, only test API            
        o1 = crys.align_cart(obj, x=v1-v0, y=v2-v0, eps=0)
        o2 = crys.align_cart(obj, vecs=np.array([v0,v1,v2]), eps=0)
        o3 = crys.align_cart(obj, indices=indices, eps=0)
        tools.assert_dict_with_all_types_almost_equal(o1.__dict__, 
                                                      o2.__dict__, 
                                                      keys=o1.attr_lst)
        tools.assert_dict_with_all_types_almost_equal(o1.__dict__, 
                                                      o3.__dict__, 
                                                      keys=o1.attr_lst)
Exemplo n.º 3
0
def test_correct():
    coords = rand(20, 3)
    cell = rand(3, 3)
    st = crys.Structure(coords=coords, cell=cell, symbols=['H'])
    # new cartesian coord sys, created by rotating the old E=identity(3) by 3
    # random angles
    angles = [rand() * 360, rand() * 180, rand() * 360]
    rmat = euler_rotation(*tuple(angles))
    newcoords = np.array([np.dot(rmat, x) for x in st.coords])
    newcell = np.array([np.dot(rmat, x) for x in st.cell])
    st2 = crys.align_cart(st, cart=rmat, eps=1e-3)
    assert np.allclose(newcoords, np.dot(st.coords, rmat.T))
    assert np.allclose(
        newcoords, crys.coord_trans(st.coords, old=np.identity(3), new=rmat))
    assert np.allclose(newcell, np.dot(st.cell, rmat.T))
    assert np.allclose(newcell,
                       crys.coord_trans(st.cell, old=np.identity(3), new=rmat))
    assert np.allclose(st2.coords, newcoords)
Exemplo n.º 4
0
def test_correct():
    coords = rand(20,3)
    cell = rand(3,3)
    st = crys.Structure(coords=coords,
                        cell=cell,
                        symbols=['H'])
    # new cartesian coord sys, created by rotating the old E=identity(3) by 3
    # random angles
    angles = [rand()*360, rand()*180, rand()*360]
    rmat = euler_rotation(*tuple(angles))
    newcoords = np.array([np.dot(rmat, x) for x in st.coords])
    newcell = np.array([np.dot(rmat, x) for x in st.cell])
    st2 = crys.align_cart(st, cart=rmat, eps=1e-3)
    assert np.allclose(newcoords, np.dot(st.coords, rmat.T))
    assert np.allclose(newcoords, crys.coord_trans(st.coords,
                                                   old=np.identity(3),
                                                   new=rmat))
    assert np.allclose(newcell, np.dot(st.cell, rmat.T))
    assert np.allclose(newcell, crys.coord_trans(st.cell,
                                                 old=np.identity(3),
                                                 new=rmat))
    assert np.allclose(st2.coords, newcoords)