def test_rand(self): st1 = rc.get_rand_struct() st2 = rc.get_rand_struct() assert not np.allclose(st1.volume, st2.volume) assert not np.allclose(st1.coords_frac, st2.coords_frac) assert not np.allclose(st1.cryst_const, st2.cryst_const) assert not symmetry.is_same_struct(st1, st2)
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_same_rotate_cell(self): st1 = rc.get_rand_struct() st2 = st1.copy() st2.cell = None st2.coords = None st2.set_all() assert not np.allclose(st1.coords, st2.coords) assert not np.allclose(st1.cell, st2.cell) assert symmetry.is_same_struct(st1, st1)
def test(): # Explicit code duplication even though we could use [...,0,:] which should # work for (natoms,3) and (nstep,natoms,3) arrays [we use it in # center_on_atom()], but check if it really does. st = rc.get_rand_struct() stc = center_on_atom(st, idx=0, copy=True) assert (st.coords_frac != stc.coords_frac).all() assert (st.coords != stc.coords).all() assert (st.coords_frac[0, :] != np.array([0.5] * 3)).all() assert (stc.coords_frac[0, :] == np.array([0.5] * 3)).all() assert (stc.coords_frac[1:, :] != np.array([0.5] * 3)).all() tr = rc.get_rand_traj() trc = center_on_atom(tr, idx=0, copy=True) assert (tr.coords_frac != trc.coords_frac).all() assert (tr.coords != trc.coords).all() assert (tr.coords_frac[:, 0, :] != np.array([0.5] * 3)).all() assert (trc.coords_frac[:, 0, :] == np.array([0.5] * 3)).all() assert (trc.coords_frac[:, 1:, :] != np.array([0.5] * 3)).all()
def test_api(): tr = get_rand_traj() st = get_rand_struct() for name in st.attr_lst: assert getattr(tr, name) is not None for name in tr.attrs_only_traj: assert getattr(st, name) is None aa = tr[0] # Structure bb = tr[0:1] # Trajectory keys = set.difference(set(aa.attr_lst), set(aa.attrs_only_traj)) assert aa.is_struct assert bb.is_traj # remove timeaxis before comparing arrays for name in bb.attrs_nstep: attr = getattr(bb, name) if attr.ndim == 1: setattr(bb, name, attr[0]) else: setattr(bb, name, attr[0, ...]) assert_dict_with_all_types_equal(aa.__dict__, bb.__dict__, keys=keys)
def test_get_fake_ase_atoms(): st = get_rand_struct() atoms = st.get_fake_ase_atoms() assert (st.coords_frac == atoms.get_scaled_positions()).all() assert (st.cell == atoms.get_cell()).all() assert (atoms.get_atomic_numbers() == np.array(st.get_znucl())).all()
def test_same(self): st1 = rc.get_rand_struct() assert symmetry.is_same_struct(st1, st1)