Skip to content

Commit

Permalink
WIP: add extra tests for to_from ase atoms
Browse files Browse the repository at this point in the history
  • Loading branch information
DanielYang59 committed Mar 11, 2025
1 parent 7ffec98 commit b079afa
Showing 1 changed file with 29 additions and 1 deletion.
30 changes: 29 additions & 1 deletion tests/core/test_structure.py
Original file line number Diff line number Diff line change
Expand Up @@ -956,6 +956,18 @@ def test_to_file_alias(self):
assert self.struct.to(out_path) == self.struct.to_file(out_path)
assert os.path.isfile(out_path)

def test_to_from_ase_atoms(self):
pytest.importorskip("ase")

atoms = self.struct.to_ase_atoms()
assert isinstance(atoms, Atoms)
assert len(atoms) == len(self.struct)

assert AseAtomsAdaptor.get_structure(atoms) == self.struct

assert IStructure.from_ase_atoms(atoms) == self.struct
assert type(IStructure.from_ase_atoms(atoms)) is IStructure

def test_pbc(self):
assert self.struct.pbc == (True, True, True)
assert self.struct.is_3d_periodic
Expand Down Expand Up @@ -2106,11 +2118,15 @@ def test_to_conventional(self):

def test_to_from_ase_atoms(self):
pytest.importorskip("ase")

atoms = self.struct.to_ase_atoms()
assert isinstance(atoms, Atoms)
assert len(atoms) == len(self.struct)

assert AseAtomsAdaptor.get_structure(atoms) == self.struct

assert Structure.from_ase_atoms(atoms) == self.struct
assert type(Structure.from_ase_atoms(atoms)) is Structure

labeled_atoms = self.labeled_structure.to_ase_atoms()
assert Structure.from_ase_atoms(labeled_atoms) == self.labeled_structure
Expand Down Expand Up @@ -2429,6 +2445,14 @@ def test_to_file_alias(self):
assert self.mol.to(out_path) == self.mol.to_file(out_path)
assert os.path.isfile(out_path)

def test_to_from_ase_atoms(self):
pytest.importorskip("ase")

atoms = self.mol.to_ase_atoms()
assert isinstance(atoms, Atoms)

assert type(IMolecule.from_ase_atoms(atoms)) is IMolecule


class TestMolecule(PymatgenTest):
def setUp(self):
Expand Down Expand Up @@ -2687,9 +2711,13 @@ def test_relax_gfnxtb(self):
assert relaxed.dynamics == {"type": "optimization", "optimizer": "FIRE"}
assert relaxed.calc.results["energy"] == approx(-113.61346199239306)

def test_to_ase_atoms(self):
def test_to_from_ase_atoms(self):
pytest.importorskip("ase")

atoms = self.mol.to_ase_atoms()
assert isinstance(atoms, Atoms)
assert len(atoms) == len(self.mol)

assert AseAtomsAdaptor.get_molecule(atoms) == self.mol

assert type(Molecule.from_ase_atoms(atoms)) is Molecule

0 comments on commit b079afa

Please sign in to comment.