Ejemplo n.º 1
0
def test_concatenate():
    st = get_rand_struct()
    nstep = 5
    
    # cat Structure
    tr_cat = crys.concatenate([st]*nstep)
    keys = tr_cat.attr_lst
    assert tr_cat.nstep == nstep
    for x in tr_cat:
        assert_dict_with_all_types_equal(x.__dict__, st.__dict__,
                                         keys=keys)
    none_attrs = ['ekin', 'timestep', 'velocity', 'temperature', 'time']
    for attr_name in tr_cat.attrs_nstep:
        if attr_name in none_attrs:
            assert getattr(tr_cat, attr_name) is None
        else:
            print "test_concatenate: shape[0] == nstep:", attr_name
            assert getattr(tr_cat, attr_name).shape[0] == nstep
            print "test_concatenate: shape[0] == nstep:", attr_name, "...ok"
    
    # cat Trajectory
    tr = get_rand_traj()
    tr_cat = crys.concatenate([tr]*3)
    assert tr_cat.nstep == 3*tr.nstep
    none_attrs = ['timestep', 'time']
    keys = remove_from_lst(tr_cat.attr_lst, none_attrs)
    for x in [tr_cat[0:tr.nstep], 
              tr_cat[tr.nstep:2*tr.nstep], 
              tr_cat[2*tr.nstep:3*tr.nstep]]:
        assert_dict_with_all_types_equal(x.__dict__, tr.__dict__,
                                         keys=keys) 
    for attr_name in tr_cat.attrs_nstep:
        if attr_name in none_attrs:
            assert getattr(tr_cat, attr_name) is None
        else:
            assert getattr(tr_cat, attr_name).shape[0] == 3*tr.nstep

    # cat mixed, Structure is minimal API
    st = get_rand_struct()
    tr = crys.concatenate([st]*5)
    tr_cat = crys.concatenate([st]*5 + [tr])
    assert tr_cat.nstep == 10
    none_attrs = ['ekin', 'timestep', 'velocity', 'temperature', 'time']
    keys = remove_from_lst(tr_cat.attr_lst, none_attrs)
    for x in tr_cat:
        assert_dict_with_all_types_equal(x.__dict__, st.__dict__,
                                         keys=keys)
    for attr_name in tr_cat.attrs_nstep:
        if attr_name in none_attrs:
            assert getattr(tr_cat, attr_name) is None
        else:
            assert getattr(tr_cat, attr_name).shape[0] == 10
Ejemplo n.º 2
0
def test_concatenate():
    st = get_rand_struct()
    nstep = 5

    # cat Structure
    tr_cat = crys.concatenate([st] * nstep)
    keys = tr_cat.attr_lst
    assert tr_cat.nstep == nstep
    for x in tr_cat:
        assert_dict_with_all_types_equal(x.__dict__, st.__dict__, keys=keys)
    none_attrs = ['ekin', 'timestep', 'velocity', 'temperature', 'time']
    for attr_name in tr_cat.attrs_nstep:
        if attr_name in none_attrs:
            assert getattr(tr_cat, attr_name) is None
        else:
            print("test_concatenate: shape[0] == nstep:", attr_name)
            assert getattr(tr_cat, attr_name).shape[0] == nstep
            print("test_concatenate: shape[0] == nstep:", attr_name, "...ok")

    # cat Trajectory
    tr = get_rand_traj()
    tr_cat = crys.concatenate([tr] * 3)
    assert tr_cat.nstep == 3 * tr.nstep
    none_attrs = ['timestep', 'time']
    keys = remove_from_lst(tr_cat.attr_lst, none_attrs)
    for x in [
            tr_cat[0:tr.nstep], tr_cat[tr.nstep:2 * tr.nstep],
            tr_cat[2 * tr.nstep:3 * tr.nstep]
    ]:
        assert_dict_with_all_types_equal(x.__dict__, tr.__dict__, keys=keys)
    for attr_name in tr_cat.attrs_nstep:
        if attr_name in none_attrs:
            assert getattr(tr_cat, attr_name) is None
        else:
            assert getattr(tr_cat, attr_name).shape[0] == 3 * tr.nstep

    # cat mixed, Structure is minimal API
    st = get_rand_struct()
    tr = crys.concatenate([st] * 5)
    tr_cat = crys.concatenate([st] * 5 + [tr])
    assert tr_cat.nstep == 10
    none_attrs = ['ekin', 'timestep', 'velocity', 'temperature', 'time']
    keys = remove_from_lst(tr_cat.attr_lst, none_attrs)
    for x in tr_cat:
        assert_dict_with_all_types_equal(x.__dict__, st.__dict__, keys=keys)
    for attr_name in tr_cat.attrs_nstep:
        if attr_name in none_attrs:
            assert getattr(tr_cat, attr_name) is None
        else:
            assert getattr(tr_cat, attr_name).shape[0] == 10
def test_scf_cell():
    filename = 'files/pw.vc_relax_coords_fixed.out'
    common.system('gunzip %s.gz' %filename)
    
    pp = parse.PwSCFOutputFile(filename, use_alat=False)
    cell_2d_red = pp.get_cell()
    assert np.allclose(cell_2d_red, cell_2d_red_ref, atol=1e-15, rtol=0)
    
    pp = parse.PwSCFOutputFile(filename, use_alat=True)
    assert np.allclose(pp.get_cell(), 
                       cell_2d_red*pp.get_alat(), 
                       atol=1e-15,
                       rtol=0)
    
    st = io.read_pw_scf(filename)
    tr = io.read_pw_md(filename)

    # tr is from a vc-relax w/ fixed fractional coords, check that
    assert np.allclose(np.zeros((tr.nstep,tr.natoms,3)), 
                       tr.coords_frac - tr.coords_frac[0,...].copy(),
                       rtol=0, atol=1e-15)

    # check if scf parser gets the same coords_frac as the trajectory parser
    # Note: this and the next test have the same max error of
    # 4.33868466709e-08 (b/c of limited accuracy in printed numbers in
    # pwscf output)
    assert np.allclose(st.coords_frac,tr.coords_frac[0,...], atol=1e-7, rtol=0)
    
    # same test, plus test of concatenate() works
    trcat = crys.concatenate((st,tr))
    assert np.allclose(np.zeros((trcat.nstep,trcat.natoms,3)), 
                       trcat.coords_frac - trcat.coords_frac[0,...].copy(),
                       rtol=0, atol=1e-7)
Ejemplo n.º 4
0
def test_scf_cell():
    filename = 'files/pw.vc_relax_coords_fixed.out'
    common.system('gunzip %s.gz' % filename)

    pp = parse.PwSCFOutputFile(filename, use_alat=False)
    cell_2d_red = pp.get_cell()
    assert np.allclose(cell_2d_red, cell_2d_red_ref, atol=1e-15, rtol=0)

    pp = parse.PwSCFOutputFile(filename, use_alat=True)
    assert np.allclose(pp.get_cell(),
                       cell_2d_red * pp.get_alat(),
                       atol=1e-15,
                       rtol=0)

    st = io.read_pw_scf(filename)
    tr = io.read_pw_md(filename)

    # tr is from a vc-relax w/ fixed fractional coords, check that
    assert np.allclose(np.zeros((tr.nstep, tr.natoms, 3)),
                       tr.coords_frac - tr.coords_frac[0, ...].copy(),
                       rtol=0,
                       atol=1e-15)

    # check if scf parser gets the same coords_frac as the trajectory parser
    # Note: this and the next test have the same max error of
    # 4.33868466709e-08 (b/c of limited accuracy in printed numbers in
    # pwscf output)
    assert np.allclose(st.coords_frac,
                       tr.coords_frac[0, ...],
                       atol=1e-7,
                       rtol=0)

    # same test, plus test of concatenate() works
    trcat = crys.concatenate((st, tr))
    assert np.allclose(np.zeros((trcat.nstep, trcat.natoms, 3)),
                       trcat.coords_frac - trcat.coords_frac[0, ...].copy(),
                       rtol=0,
                       atol=1e-7)
Ejemplo n.º 5
0
{st}

only in Trajectory:
{onlytr}

only in Structure:
{onlyst}

Attributes which are None w.r.t. the Trajectory API after the following
operation, starting with a fully populated struct or traj (all attrs not None):
""".format(st=st.attr_lst, tr=tr.attr_lst, onlytr=list(onlytr), 
           onlyst=list(onlyst))

items = [\
    ('tr', tr),
    ('tr.copy', tr.copy()),
    ('tr[0:5]', tr[0:5]),
    ('st', st),
    ('st.copy', st.copy()),
    ('tr[0]', tr[0]),
    ('mean(tr)', crys.mean(tr)),
    ('concatenate([st,st])', crys.concatenate([st,st])),
    ('concatenate([st,tr])', crys.concatenate([st,tr])),
    ('concatenate([tr,tr])', crys.concatenate([tr,tr])),
    ]
for name,obj in items:
    none_attrs = set.difference(set(tr.attr_lst),
                                crys.populated_attrs([obj]))
    typ = 'traj' if obj.is_traj else 'struct'                                          
    print "{:25} {:7} {}".format(name, typ, list(none_attrs))
Ejemplo n.º 6
0
{st}

only in Trajectory:
{onlytr}

only in Structure:
{onlyst}

Attributes which are None w.r.t. the Trajectory API after the following
operation, starting with a fully populated struct or traj (all attrs not None):
""".format(st=st.attr_lst, tr=tr.attr_lst, onlytr=list(onlytr), 
           onlyst=list(onlyst)))

items = [\
    ('tr', tr),
    ('tr.copy', tr.copy()),
    ('tr[0:5]', tr[0:5]),
    ('st', st),
    ('st.copy', st.copy()),
    ('tr[0]', tr[0]),
    ('mean(tr)', crys.mean(tr)),
    ('concatenate([st,st])', crys.concatenate([st,st])),
    ('concatenate([st,tr])', crys.concatenate([st,tr])),
    ('concatenate([tr,tr])', crys.concatenate([tr,tr])),
    ]
for name,obj in items:
    none_attrs = set.difference(set(tr.attr_lst),
                                crys.populated_attrs([obj]))
    typ = 'traj' if obj.is_traj else 'struct'                                          
    print("{:25} {:7} {}".format(name, typ, list(none_attrs)))