Skip to content

Commit

Permalink
update unittest
Browse files Browse the repository at this point in the history
  • Loading branch information
MoseyQAQ committed Apr 3, 2024
1 parent 45c5a2f commit 1a34fc9
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 7 deletions.
8 changes: 3 additions & 5 deletions dpdata/pymatgen/structure.py
Original file line number Diff line number Diff line change
@@ -1,26 +1,24 @@
import numpy as np

try:
from pymatgen.core import Structure
from pymatgen.core import Structure # noqa: F401
except ImportError:
pass


def from_system_data(structure):
def from_system_data(structure) -> dict:
symbols = [site.species_string for site in structure]
atom_names = list(structure.symbol_set)
atom_numbs = [symbols.count(symbol) for symbol in atom_names]
atom_types = np.array([atom_names.index(symbol) for symbol in symbols]).astype(int)
coords = structure.cart_coords
cells = structure.lattice.matrix
nopbc = not np.any(structure.pbc)

info_dict = {
"atom_names": atom_names,
"atom_numbs": atom_numbs,
"atom_types": atom_types,
"coords": np.array([coords]),
"cells": np.array([cells]),
"nopbc": nopbc,
"cells": np.array([cells])
}
return info_dict
2 changes: 1 addition & 1 deletion tests/test_from_pymatgen.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@


@unittest.skipIf(not exist_module, "skip pymatgen")
class TestFormPytmatgen(unittest.TestCase, CompSys, IsPBC):
class TestFormPytmatgen(unittest.TestCase, CompSys):
def setUp(self):
structure = Structure.from_file(os.path.join("poscars", "POSCAR.P42nmc"))
self.system_1 = dpdata.System(structure, fmt="pymatgen/structure")
Expand Down
2 changes: 1 addition & 1 deletion tests/test_to_pymatgen.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ def setUp(self):
system_1.from_lammps_lmp(
os.path.join("poscars", "conf.lmp"), type_map=["O", "H"]
)
system_1.to_pymatgen_structure()[0].to("tmp.POSCAR", "poscar")
system_1.to_pymatgen_structure()[0].to(filename="tmp.POSCAR", fmt="poscar")
self.system_1 = system_1
self.system_2 = dpdata.System("tmp.POSCAR")
self.places = 6
Expand Down

0 comments on commit 1a34fc9

Please sign in to comment.