Skip to content

Commit

Permalink
debugging multiple k-vectors in bumps model
Browse files Browse the repository at this point in the history
  • Loading branch information
jlesniewski committed Aug 13, 2015
1 parent c66711d commit 111cbff
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 30 deletions.
10 changes: 3 additions & 7 deletions hklgen/examples/dy/dy.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
def fit():
cell = Mod.makeCell(crystalCell, xtalsys(spaceGroup))
cell.a.pm(0.5)
cell.b.pm(0.5)
# cell.b.pm(0.5)
cell.c.pm(0.5)
m = Mod.Model(tt, observed, backg, 1.814691, -1.482098, 0.447632 , wavelength, spaceGroup, cell,
(atomList, magAtomList), exclusions, magnetic=True,
Expand All @@ -50,19 +50,15 @@ def fit():
coeff.range(-20,20)
#pass
#atomModel.phase.range(-np.pi*2, np.pi*2)
m.atomListModel["Mn1"].phase.range(0, np.pi*2)
m.atomListModel["Mn2"].phase.range(-2*np.pi, 0)
#m.atomListModel["Mn1"].phase.range(0, np.pi*2)
#m.atomListModel["Mn2"].phase.range(-2*np.pi, 0)
M = bumps.FitProblem(m)
M.model_update()
return M

def main():
uvw = [1.814655, -1.482037, 0.447617 ]
cell = crystalCell
for i in range(len(magAtomList)):
matom = magAtomList[i]
matom.set_phase(matom.phase[0])
magAtomList[i] = matom
H.diffPattern(infoFile=infoFile, uvw=uvw, cell=cell, scale=94.5,
ttMin=ttMin, ttMax=ttMax, ttStep=ttStep, wavelength = wavelength,
basisSymmetry=basisSymmetry, magAtomList=magAtomList,
Expand Down
72 changes: 49 additions & 23 deletions hklgen/hkl_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -400,9 +400,11 @@ def _rebuild_object(self, atoms):
for model in self.atomModels:
if (magAtom.label().rstrip() == model.atom.label().rstrip() and \
magAtom.sameSite(model.atom)):
model.addMagAtom(magAtom, self.symmetry)
model.addMagAtom(magAtom, self.symmetry)
print magAtom.label()
index = 0
for magAtom in self.magAtoms:
print index, magAtom.label()
self.magAtomList[index] = magAtom
self.magAtoms[index] = magAtom
index += 1
Expand Down Expand Up @@ -438,11 +440,12 @@ def update(self):
atomModel.update()
self.atomList[I2] = atomModel.atom
I2 += 1
if hasattr(atomModel, 'magAtom'):
self.magAtomList[index] = atomModel.magAtom
self.magAtoms[index] = atomModel.magAtom
#print atomModel.magAtom.basis()
index += 1
if hasattr(atomModel, 'magAtoms') and atomModel.magAtoms != None:
for matom in atomModel.magAtoms:
self.magAtomList[index] = matom
self.magAtoms[index] = matom
#print atomModel.magAtom.basis()
index += 1
# update basis vectors instead of coefficients (only needed in special
# circumstances)
#if self.magnetic:
Expand Down Expand Up @@ -474,6 +477,10 @@ def __init__(self, atom, sgmultip):
# else:
self.atom = atom
self.magnetic = False
self.magAtoms = None
self.matom_index = -1
self.coeffs = None
self.phases = None
self.sgmultip = sgmultip
self.atom.set_atom_lab(rstrip(self.atom.label()))
self.B = Parameter(self.atom.BIso(), name=self.atom.label() + " B")
Expand All @@ -485,23 +492,41 @@ def __init__(self, atom, sgmultip):

def addMagAtom(self, magAtom, symmetry):
# add a secondary magnetic atom object to the model
self.magAtom = magAtom
self.magAtom.setLabel(rstrip(self.magAtom.label()))
if self.magAtoms != None:
self.magAtoms.append(magAtom)
else:
self.magAtoms = [magAtom]
self.matom_index += 1
matom = self.magAtoms[self.matom_index]
matom.setLabel(rstrip(matom.label()))
self.symmetry = symmetry
self.magnetic = True
self.numVectors = self.symmetry.numBasisFunc()[self.magAtom.irrepNum()[0]-1]
self.coeffs = [None] * self.numVectors
self.numVectors = self.symmetry.numBasisFunc()[self.magAtoms[self.matom_index].irrepNum()[0]-1]
if self.matom_index != 0:
param_label = " kvect: " + str(self.matom_index+1)
else:
param_label = ""
if self.coeffs == None:
self.coeffs = [None] * self.numVectors
j = 0
else:
self.coeffs.extend([None] * self.numVectors)
j = len(self.coeffs)
for i in xrange(self.numVectors):
self.coeffs[i] = Parameter(self.magAtom.basis()[0][i],
name=self.atom.label() + " C" + str(i))
self.phase = Parameter(0, name=self.atom.label() + " phase")
self.coeffs[i+j] = Parameter(matom.basis()[0][i], name=self.atom.label() + " C" + str(i) + param_label)
if self.phases == None:
self.phases = [Parameter(matom.phase[0], name=self.atom.label() + " phase"+param_label)]
else:
self.phases.append(Parameter(matom.phase[0], name=self.atom.label() + " phase"+param_label))
self.magAtoms[self.matom_index] = matom

def parameters(self):
params = {self.B.name: self.B, self.occ.name: self.occ,
self.x.name: self.x, self.y.name: self.y, self.z.name: self.z}
if self.magnetic:
params.update([(coeff.name, coeff) for coeff in self.coeffs])
params.update([(self.phase.name, self.phase)])
for phase in self.phases:
params.update([(phase.name, phase)])
return params

def update(self):
Expand All @@ -511,14 +536,15 @@ def update(self):
self.atom.setCoords([float(self.x), float(self.y), float(self.z)])

if self.magnetic:
self.magAtom.setBIso(self.B.value)
for i in range(len(self.magAtoms)):
matom = self.magAtoms[i]
matom.setBIso(self.B.value)
matom.setCoords([float(self.x), float(self.y), float(self.z)])
for j in xrange(self.numVectors):
#self.magAtom.basis[0][i] = self.coeffs[i].value
matom.setBasis_ind(0,j, self.coeffs[j+i].value)
matom.set_phase(self.phases[i].value)
self.magAtoms[i] = matom
# following line breaks magnetism if magnetic occupancies are different from nuclear occupancies
# It may however, be needed in order to fit the occupancy
# self.magAtom.setOccupancy(occ)
self.magAtom.setCoords([float(self.x), float(self.y), float(self.z)])
for i in xrange(self.numVectors):
#self.magAtom.basis[0][i] = self.coeffs[i].value
self.magAtom.setBasis_ind(0,i, self.coeffs[i].value)
# print >>sys.stderr, self.magAtom.label(), self.magAtom.basis()
self.magAtom.set_phase(self.phase.value)

# self.magAtom.setOccupancy(occ)

0 comments on commit 111cbff

Please sign in to comment.