Skip to content

Commit f339f4e

Browse files
committed
get_fractional_coordinates code and test
1 parent b252ea3 commit f339f4e

2 files changed

Lines changed: 22 additions & 23 deletions

File tree

src/diffpy/structure/structure.py

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -178,21 +178,14 @@ def get_chemical_symbols(self, include_charge_state=False):
178178
"""Return list of chemical symbols for all `Atoms` in this
179179
structure.
180180
181-
Parameters
182-
----------
183-
include_charge_state : bool, optional
184-
If ``True``, include charge state in the chemical symbol (e.g., "Fe2+").
185181
Returns
186182
-------
187183
list of str
188184
The list of chemical symbols for all `Atoms` in this structure.
189185
"""
190186
symbols_with_charge = [a.element for a in self]
191-
if include_charge_state:
192-
return symbols_with_charge
193-
else:
194-
symbols = [atomBareSymbol(sym) for sym in symbols_with_charge]
195-
return symbols
187+
symbols = [atomBareSymbol(sym) for sym in symbols_with_charge]
188+
return symbols
196189

197190
def get_fractional_coordinates(self):
198191
"""Return array of fractional coordinates of all `Atoms` in this

tests/test_structure.py

Lines changed: 20 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -610,25 +610,31 @@ def test_pickling(self):
610610
# End of class TestStructure
611611

612612

613-
@pytest.mark.parametrize(
614-
"include_charge_state,expected",
615-
[
616-
(False, ["Pb"] * 4 + ["Te"] * 4),
617-
(True, ["Pb"] * 4 + ["Te"] * 4),
618-
],
619-
)
620-
def test_get_chemical_symbols(datafile, include_charge_state, expected):
613+
def test_get_chemical_symbols(datafile):
621614
"""Check Structure.get_chemical_symbols()"""
622615
pbte_stru = Structure(filename=datafile("PbTe.cif"))
623-
actual_chemical_symbols = pbte_stru.get_chemical_symbols(include_charge_state=include_charge_state)
624-
expected_chemical_symbols = expected
616+
actual_chemical_symbols = pbte_stru.get_chemical_symbols()
617+
expected_chemical_symbols = ["Pb"] * 4 + ["Te"] * 4
625618
assert actual_chemical_symbols == expected_chemical_symbols
626619

627620

628-
# def test_get_fractional_coordinates(datafile):
629-
# """Check Structure.get_fractional_coordinates()"""
630-
# pbte_cif = Structure(filename=datafile("PbTe.cif"))
631-
# assert False
621+
def test_get_fractional_coordinates(datafile):
622+
"""Check Structure.get_fractional_coordinates()"""
623+
pbte_stru = Structure(filename=datafile("PbTe.cif"))
624+
actual_fractional_coords = pbte_stru.get_fractional_coordinates()
625+
expected_fractional_coords = numpy.array(
626+
[
627+
[0.5, 0.5, 0.5],
628+
[0.5, 0.0, 0.0],
629+
[0.0, 0.5, 0.0],
630+
[0.0, 0.0, 0.5],
631+
[0.0, 0.0, 0.0],
632+
[0.0, 0.5, 0.5],
633+
[0.5, 0.0, 0.5],
634+
[0.5, 0.5, 0.0],
635+
]
636+
)
637+
assert actual_fractional_coords.tolist() == expected_fractional_coords.tolist()
632638

633639

634640
# def test_get_cartesian_coordinates(datafile):

0 commit comments

Comments
 (0)