Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 23 additions & 0 deletions news/deprecate-getLastAtom.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
**Added:**

* Added `diffpy.structure.Structure.get_last_atom` in replace of `getLastAtom`

**Changed:**

* <news item>

**Deprecated:**

* Deprecated `diffpy.structure.Structure.getLastAtom` for removal in version 4.0.0

**Removed:**

* <news item>

**Fixed:**

* <news item>

**Security:**

* <news item>
2 changes: 1 addition & 1 deletion src/diffpy/structure/parsers/p_cif.py
Original file line number Diff line number Diff line change
Expand Up @@ -498,7 +498,7 @@ def _parse_atom_site_label(self, block):
continue
self.labelindex[curlabel] = len(self.stru)
self.stru.add_new_atom()
a = self.stru.getLastAtom()
a = self.stru.get_last_atom()
for fset, val in zip(prop_setters, values):
fset(a, val)
if does_adp_type:
Expand Down
2 changes: 1 addition & 1 deletion src/diffpy/structure/parsers/p_discus.py
Original file line number Diff line number Diff line change
Expand Up @@ -265,7 +265,7 @@ def _parse_atom(self, words):
xyz = [float(w) for w in words[1:4]]
Biso = float(words[4])
self.stru.add_new_atom(element, xyz)
a = self.stru.getLastAtom()
a = self.stru.get_last_atom()
a.Bisoequiv = Biso
return

Expand Down
2 changes: 1 addition & 1 deletion src/diffpy/structure/parsers/p_pdb.py
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,7 @@ def parseLines(self, lines):
element = line[12:14].strip()
element = element[0].upper() + element[1:].lower()
stru.add_new_atom(element, occupancy=occupancy, label=name)
last_atom = stru.getLastAtom()
last_atom = stru.get_last_atom()
last_atom.xyz_cartn = rc
last_atom.Uisoequiv = uiso
elif record == "SIGATM":
Expand Down
2 changes: 1 addition & 1 deletion src/diffpy/structure/parsers/p_pdffit.py
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ def parseLines(self, lines):
xyz = [float(w) for w in wl1[1:4]]
occ = float(wl1[4])
stru.add_new_atom(element, xyz=xyz, occupancy=occ)
a = stru.getLastAtom()
a = stru.get_last_atom()
p_nl += 1
wl2 = next(ilines).split()
a.sigxyz = [float(w) for w in wl2[0:3]]
Expand Down
15 changes: 15 additions & 0 deletions src/diffpy/structure/structure.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,12 @@
"add_new_atom",
removal_version,
)
getLastAtom_deprecation_msg = build_deprecation_message(
base,
"getLastAtom",
"get_last_atom",
removal_version,
)


class Structure(list):
Expand Down Expand Up @@ -192,7 +198,16 @@ def add_new_atom(self, *args, **kwargs):
self.append(atom, copy=False)
return

@deprecated(getLastAtom_deprecation_msg)
def getLastAtom(self):
"""This function has been deprecated and will be removed in
version 4.0.0.

Please use diffpy.structure.Structure.get_last_atom instead.
"""
return self.get_last_atom()

def get_last_atom(self):
"""Return Reference to the last `Atom` in this structure."""
last_atom = self[-1]
return last_atom
Expand Down
17 changes: 17 additions & 0 deletions tests/test_structure.py
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,23 @@ def test___copy__(self):
# def test_getLastAtom(self):
# """check Structure.getLastAtom()"""
# return
def test_getLastAtom(self):
"""Check Structure.getLastAtom()"""
s_lat = Lattice()
expected = Atom("C", [0, 0, 0])
structure = Structure(atoms=[Atom("C", [0, 0, 0])], lattice=s_lat)
actual = structure.getLastAtom()
assert actual.element == expected.element
assert numpy.allclose(expected.xyz, actual.xyz)

def test_get_last_atom(self):
"""Check Structure.get_last_atom()"""
s_lat = Lattice()
expected = Atom("C", [0, 0, 0])
structure = Structure(atoms=[Atom("C", [0, 0, 0])], lattice=s_lat)
actual = structure.get_last_atom()
assert actual.element == expected.element
assert numpy.allclose(expected.xyz, actual.xyz)

def test_addNewAtom(self):
"""Duplicate test for the deprecated addNewAtom method.
Expand Down
Loading