def lattice_to_dict(lattice: SrRealParSet, angunits="rad") -> dict: """Convert lattice parameter set to dictionary. If angle is in radian, convert it to degree.""" dct = dict(zip(lattice.getNames(), lattice.getValues())) if angunits == "rad": for angle in ('alpha', 'beta', 'gamma'): dct[angle] = math.degrees(dct[angle]) return dct
def __init__(self, name, stru): """Initialize name -- A name for the structure stru -- A diffpy.structure.Structure instance """ SrRealParSet.__init__(self, name) self.stru = stru self.addParameterSet(DiffpyLatticeParSet(stru.lattice)) self.atoms = [] cdict = {} for a in stru: el = a.element.title() # Try to sanitize the name. el = el.replace("+","p") el = el.replace("-","m") i = cdict.get(el, 0) aname = "%s%i"%(el,i) cdict[el] = i+1 atom = DiffpyAtomParSet(aname, a) self.addParameterSet(atom) self.atoms.append(atom) return
def __init__(self, name, stru): """Initialize name -- A name for the structure stru -- A diffpy.Structure.Structure instance """ SrRealParSet.__init__(self, name) self.stru = stru self.addParameterSet(DiffpyLatticeParSet(stru.lattice)) self.atoms = [] cdict = {} for a in stru: el = a.element.title() # Try to sanitize the name. el = el.replace("+", "p") el = el.replace("-", "m") i = cdict.get(el, 0) aname = "%s%i" % (el, i) cdict[el] = i + 1 atom = DiffpyAtomParSet(aname, a) self.addParameterSet(atom) self.atoms.append(atom) return
def phase_to_dict(phase: SrRealParSet) -> dict: """Convert structure parameter set to dictionary.""" return { 'lattice': lattice_to_dict(phase.getLattice(), angunits=getattr(phase, 'angunits', 'deg')), 'atoms': [atom_to_dict(atom) for atom in phase.getScatterers()], 'space_group': get_space_group_number(phase) }
def get_space_group_number(phase: SrRealParSet) -> int: """Get the space group number of the structure parameter.""" # if symmetry is not used or the structure object is from diffpy.structure if not phase.usingSymmetry() or isinstance(phase.stru, Structure): return 1 stru: Crystal = phase.stru # noinspection PyArgumentList space_group: SpaceGroup = stru.GetSpaceGroup() # noinspection PyArgumentList return space_group.GetSpaceGroupNumber()
def _getSrRealStructure(self): """Get the structure object for use with SrReal calculators. If this is periodic, then return the structure, otherwise, pass it inside of a nosymmetry wrapper. This takes the extra step of wrapping the structure in a nometa wrapper. """ stru = SrRealParSet._getSrRealStructure(self) return nometa(stru)
def _getSrRealStructure(self): """Get the structure object for use with SrReal calculators. If this is periodic, then return the structure, otherwise, pass it inside of a nosymmetry wrapper. This takes the extra step of wrapping the structure in a nometa wrapper. """ from diffpy.srreal.structureadapter import nometa stru = SrRealParSet._getSrRealStructure(self) return nometa(stru)
def __init__(self, name, stru): SrRealParSet.__init__(self, name) self.stru = stru self.lat = stru.lat stru = self.stru occ = ParameterAdapterExt("occ", stru, getter=_getValue, setter=self._updateOcc, attr="occ") self.addParameter(occ) self.addParameter(ParameterProxy("occupancy", occ)) uij = ParameterAdapterExt('uij', stru, getter=_getValue, setter=self._updateUij, attr='uij_c') self.addParameter(uij) self.addParameter(ParameterProxy('U', uij)) xyz = ParameterAdapterExt('xyz', stru, getter=_getValue, setter=self._updateXYZ, attr='xyz_c') self.addParameter(xyz) uiso = ParameterAdapterExt('uiso', stru, getter=_getValue, setter=self._updateUiso, attr='uiso') self.addParameter(uiso) self._zoomscale = 1.0 self.addParameter(ParameterAdapter('zoomscale', self, getter=_getValue, setter=self._updateZoomscale, attr='_zoomscale')) self._initSrRealStructure() return
def atom_to_dict(atom: SrRealParSet) -> dict: """Convert atom parameter set to dictionary.""" dct = dict(zip(atom.getNames(), atom.getValues())) dct.update({'name': atom.name, 'element': atom.element}) return dct