Example #1
0
def test_struc_to_ase():
    from ase import Atoms
    uc = Structure(species=['Pd' for i in range(10)]+['Ag' for i in range(10)],
                   positions=np.random.rand(20, 3),
                   cell=np.random.rand(3, 3))
    new_atoms = Structure.to_ase_atoms(uc)
    assert np.all(uc.species_labels == new_atoms.get_chemical_symbols())
    assert np.all(uc.positions == new_atoms.get_positions())
    assert np.all(uc.cell == new_atoms.get_cell())
Example #2
0
def test_struc_to_ase():
    uc = Structure(
        species=["Pd" for i in range(10)] + ["Ag" for i in range(10)],
        positions=np.random.rand(20, 3),
        cell=np.random.rand(3, 3),
    )

    uc.forces = np.random.randn(20, 3)
    uc.energy = np.random.rand()
    uc.stress = np.random.randn(6)

    new_atoms = Structure.to_ase_atoms(uc)
    assert np.all(uc.species_labels == new_atoms.get_chemical_symbols())
    assert np.all(uc.positions == new_atoms.get_positions())
    assert np.all(uc.cell == new_atoms.get_cell())
    assert np.all(new_atoms.get_forces() == uc.forces)
    assert np.all(new_atoms.get_potential_energy() == uc.energy)
    assert np.all(new_atoms.get_stress() == uc.stress)