Skip to content

Commit 0dddda0

Browse files
committed
Factor new atom initialization to a local function.
1 parent 9dbf9a4 commit 0dddda0

1 file changed

Lines changed: 12 additions & 6 deletions

File tree

diffpy/pdfgui/gui/phaseconfigurepanel.py

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -559,8 +559,7 @@ def onKey(self, event):
559559
elif self.structure:
560560
pos = len(self.structure)
561561
# insert "rows" atoms into the structure
562-
atoms = [Atom("C",[0.0,0.0,0.0],
563-
U=[[0.003,0,0],[0,0.003,0],[0,0,0.003]])]
562+
atoms = [_defaultNewAtom()]
564563
self.structure.insertAtoms(pos, atoms)
565564
self.refresh()
566565
self.mainFrame.needsSave()
@@ -649,10 +648,7 @@ def onPopupInsert(self, event):
649648
self._row += 1
650649

651650
# insert "rows" atoms into the structure
652-
atoms = []
653-
for i in xrange(rows):
654-
atoms.append( Atom("C",[0.0,0.0,0.0],
655-
U=[[0.003,0,0],[0,0.003,0],[0,0,0.003]]))
651+
atoms = [_defaultNewAtom() for i in range(rows)]
656652
self.structure.insertAtoms(self._row, atoms)
657653
self.refresh()
658654
self.mainFrame.needsSave()
@@ -724,3 +720,13 @@ def onPopupSpaceGroup(self, event):
724720
return
725721

726722
# end of class PhaseConfigurePanel
723+
724+
# Local helpers --------------------------------------------------------------
725+
726+
def _defaultNewAtom():
727+
"""Create new atom instance with non-zero initial U.
728+
"""
729+
uii = 0.003
730+
rv = Atom("C", [0.0, 0.0, 0.0],
731+
U=[[uii, 0, 0], [0, uii, 0], [0, 0, uii]])
732+
return rv

0 commit comments

Comments
 (0)