def phases(self, value): if isinstance(value, Phase): value = Phases('Phases', value) if not isinstance(value, Phases): raise ValueError self._phases = value self._borg.map.add_edge(self, value) self._phases.interface = self.interface
def __init__(self, phases: Union[Phase, Phases] = None, parameters=None, pattern=None, calculator=None, interface=None, name: str = 'easySample'): if isinstance(phases, Phase): phases = Phases('Phases', phases) elif phases is None: phases = Phases('Phases') if not isinstance(phases, Phases): raise AttributeError('`phases` must be a Crystal or Crystals') if parameters is None: parameters = Instrument1DCWParameters.default() if pattern is None: pattern = Pattern1D.default() super(Sample, self).__init__(name, _phases=phases, _parameters=parameters, _pattern=pattern) self.filename = os.path.join(tempfile.gettempdir(), 'easydiffraction_temp.cif') print(f"Temp CIF: {self.filename}") self.output_index = None if calculator is not None: self.interface = calculator elif interface is not None: self.interface = interface else: self.interface = InterfaceFactory()
def __init__(self, name: str = '', job_type=None, datastore: xr.Dataset = None, phases: Union[Phase, Phases] = None, parameters=None, pattern=None, interface=None): if isinstance(phases, Phase): phases = Phases('Phases', phases) elif phases is None: phases = Phases('Phases') if not isinstance(phases, Phases): raise AttributeError('`phases` must be a Crystal or Crystals') if parameters is None: parameters = job_type.pattern_class.default() if pattern is None: pattern = job_type.instrumental_parameter_class.default() super(_PowderBase, self).__init__(name, _phases=phases, _parameters=parameters, _pattern=pattern) self.__constituting_classes = job_type self.__dataset = datastore self.datastore = DataContainer.prepare(self.__dataset, *job_type.datastore_classes) self.filename = os.path.join(tempfile.gettempdir(), 'easydiffraction_temp.cif') self.output_index = None self.interface = interface
__author__ = 'github.com/wardsimon' __version__ = '0.0.1' from easyCore import np from easyDiffractionLib.sample import Sample from easyDiffractionLib import Phases from easyDiffractionLib.interface import InterfaceFactory from easyDiffractionLib.Elements.Experiments.Experiment import Pars1D from easyDiffractionLib.Elements.Experiments.Pattern import Pattern1D from easyDiffractionLib.Elements.Backgrounds.Point import PointBackground, BackgroundPoint from easyCore.Fitting.Fitting import Fitter from easyCore.Datasets.xarray import xr interface = InterfaceFactory() c = Phases.from_cif_file('PbSO4.cif') S = Sample(phases=c, parameters=Pars1D.default(), pattern=Pattern1D.default(), interface=interface) file_path = 'PbSO4_neutrons_short.xye' data_x, data_y, data_e = np.loadtxt(file_path, unpack=True) data_set = xr.Dataset() data_set.easyCore.add_coordinate('tth', data_x) data_set.easyCore.add_variable('I', ['tth'], data_y) data_set.easyCore.sigma_attach('I', data_e) S.parameters.wavelength = 1.912 S.parameters.u_resolution = 1.4
__author__ = 'github.com/wardsimon' __version__ = '0.0.1' from easyCore import np from easyDiffractionLib.sample import Sample from easyDiffractionLib import Phase, Phases from easyDiffractionLib.interface import InterfaceFactory from easyDiffractionLib.Profiles.P1D import Instrument1DCWParameters import matplotlib.pyplot as plt i = InterfaceFactory() c = Phases.from_cif_file('tests/SrTiO3.cif') S = Sample(phases=c, parameters=Instrument1DCWParameters.default(), interface=i) x_data = np.linspace(5, 150, 10000) y_data = i.fit_func(x_data) i.switch('CrysPy') S._updateInterface() y_data2 = np.array(i.fit_func(x_data)) fig = plt.figure() axprops = dict() ax1 = fig.add_axes([0.1, 0.5, 0.8, 0.4], **axprops) ax1.plot(x_data, y_data, label="CrysFML")
calculator = Calculator() calculator.switch('CrysPy') atom = Site.from_pars(label="Cl1", specie='Cl', fract_x=0.1250, fract_y=0.1670, fract_z=0.1070) atom.add_adp('Uiso', Uiso=0.0) phase = Phase(name="p1") phase.spacegroup.space_group_HM_name = "P 42/n c m" phase.add_atom(atom) phases = Phases() phases.append(phase) parameters = CWParams.default() parameters.length_a = 8.56 parameters.length_c = 6.12 parameters.length_b = 8.56 parameters.resolution_u = 0.1447 parameters.resolution_v = -0.4252 parameters.resolution_w = 0.3864 parameters.resolution_x = 0.0 parameters.resolution_y = 0.0 pattern = Powder1DParameters.default() pattern.zero_shift = 0.0
def phasesAsCif(self, phases_as_cif): if self._phases_as_cif == phases_as_cif: return self._sample.phases = Phases.from_cif_str(phases_as_cif)
def addSampleFromCif(self, cif_url): cif_path = generalizePath(cif_url) borg.stack.enabled = False self._sample.phases = Phases.from_cif_file(cif_path) borg.stack.enabled = True