Skip to content

Conversation

@rozyczko
Copy link
Member

@rozyczko rozyczko commented Oct 4, 2022

This moves the experiment cif reader from the app to the lib.

Example usage:

from easyCore import np
from easyDiffractionLib import Phases
from easyDiffractionLib.Jobs import get_job_from_file


phase_cif_name = "D:\\projects\\easyScience\\easyDiffractionLib\\examples\\Fe3O4.cif"
exp_cif_name = "D:\\projects\\easyScience\\easyDiffractionLib\\examples\\test_exp.cif"

phases = Phases.from_cif_file(phase_cif_name)

job_name = phases[0].name
exp_name = job_name

ds, job = get_job_from_file(exp_cif_name, exp_name=exp_name, phases=phases)

job.phases[0].scale = 10.0

job.simulate_experiment(exp_name, 'up', pol_fn=lambda up, down: up)


############ Vizualization
from bokeh.plotting import figure, show
import hvplot.xarray
hvplot.extension('bokeh')
from bokeh.io import show
from bokeh.plotting import figure
from bokeh.palettes import Spectral6

FIGURE_WIDTH = 990
FIGURE_HEIGHT = 300
opts = dict(width=FIGURE_WIDTH, height=FIGURE_HEIGHT, min_border=0)

p1 = figure(**opts, title=exp_name)
x_data = np.array(ds['Fe3O4_Fe3O4_tth'])
p1.line(x_data, np.array(ds['Fe3O4_Fe3O4_I0']), legend='Experimental Spin Up', line_width=2, color=Spectral6[0])
p1.line(x_data, np.array(ds['sim_Fe3O4_Fe3O4_Fe3O4up']),  legend='Simulated Spin Up', line_width=2, color=Spectral6[-1])

p1.yaxis.axis_label = 'Intensity'
p1.legend.location = 'top_right'
p1.xaxis.axis_label = '2theta'
show(p1)

Copy link

@github-actions github-actions bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This pull request does not contain a valid label. Please add one of the following labels: ['chore', 'fix', 'bugfix', 'bug', 'enhancement', 'feature', 'dependencies', 'documentation']

@rozyczko rozyczko added the [scope] enhancement Adds/improves features (major.MINOR.patch) label Oct 4, 2022
@rozyczko
Copy link
Member Author

rozyczko commented Nov 14, 2022

Merging so that subsequent work on adapting the new xml parser is based on develop.

@rozyczko rozyczko merged commit ec19a19 into develop Nov 14, 2022
rozyczko added a commit that referenced this pull request Mar 28, 2023
* Modify background label

* Fix build script

* Fixup build scripts

* Update for specie work

* Recalculate sin(Th)/Lambda

* Set some experimental parameters

* Fixup some serialization

* Keep temp.cif file for fitting process

* Fix sinTh/Lambda for CFML

* Keep temp.cif for fitting with CFML

* Update to new CFML api

* Tidy up background work

* More background tidying

* Revert BG changes

* Debugging info for y_calc

* Add fitting notebook

* More fitting work

* Add CFML fitting notebook

* Update branches

* Update sin(theta)/lambda

* Example bug fixes

* disable ubuntu ci

* Use new CFML api

* Add ubuntu ci

* Make libs repos public

* macOS CI only

* Temporarily disable libs

* Remove poetry.lock

* Try windows CI

* Update RelinkCrysfml

* Add linux and macos to CI

* Install libgfortran4 on ubuntu

* Update CFML jupyter notebook example

* More x-array examples

* Add  setup and requirements for binder

* Move to easyCore develop

* Undo/Redo stack work

* Initial implementation of get_hkl

* Set default hkl arrays empty

* Rename stack_deco to property_stack_deco

* Change cryspy handling

* Merge the interfacing work of Sprint13 (#8)

* Update reflection list generation

* Some changes related to new interface

* self.conditions to job_info

* More changes related to new CFML interface

* Adjust resolution parameters

* Use new_cfml branch of libs

* Bump Cryspy from ^0.4 to ^0.5

* Use develop branch of libsWin32/libsLinux/libsDarwin

* Temporarily fix for bravis_type in cryspy

* Use new CrysFML with Bragg peaks

* First work on new interface

This is a test implementation where only experimental parameters are properly bound in the cryspy engine.
```
from easyDiffractionLib.interface import InterfaceFactory
from easyDiffractionLib.Elements.Experiments.Experiment import Pars1D
p = Pars1D.default()
i = InterfaceFactory()
p.interface = i
p.generate_bindings()
p.resolution_u = 0.2
```

* More interfacing

Continuing the cryspy interface with more details

* More interfacing work

* More interfacing work

* Atom linking via ID

* Hack to interface

* Update fileless cryspy

* File based CFML interface

* File based GSAS2 interface

* Fix BG issues with file based calculators

* Fix a mistake (removal of phases)

* Fix linking error (cryspy resolution and setup)

* Reduce BG and HKL (CrysFML) computation time

* Add matplotlib for cryspy

* Fix for cryspy spacegroups (kinda) and GSAS peak HKL indexes

* Modify MonkeyPatching of Phases

The monkey patch of `Phases` to support the appending of interfaces was referencing the wrong append fn, hence the proper interfacing was not established.
Modification of the sample, now when you do `obj.phases = phase` the phase is appended and `obj.phases = new_phases` overwrites the `obj.phases` field. sw

* Fix Point BG evaluation when zero points

Co-authored-by: Andrew Sazonov <AndrewSazonov@users.noreply.github.com>

* Use 'develop' branch of easyCore

* Update pyproject.toml

* Update pyproject.toml

* Update __init__.py

* Update test.yml

* Update pyproject.toml

* Update GSASII.py

* ReflectionList nrefs to nref

* Moving to a more module based scheme

* TOF support

As easy as:


```
from easyCore import np
from easyDiffractionLib import Phase
from easyDiffractionLib.Runner import Runner
import matplotlib.pyplot as plt

r = Runner()
p = Phase.from_cif_file('tests/PbSO4.cif')
r.add_job('testing', job_type='powder1dTOF')
r.add_phase(p, 'testing')
job = r.jobs['testing']

job.pattern.zero_shift = 2.9121
job.create_simulation(np.linspace(3000, 11000, 801))
job.plot_simulation()
plt.show()
```

* Decouple phases and EXP in cryspy

* Fix legacy mode loading

* Use the correct references for legacy mode

* Unification of naming conventions

* Fix TOF generation

* Fix changing from TOF->CW

* Fix  all interfaces to use new schema

* Update interface and exp_type verification logic

* cryspy multiprocess support

* Change mp pool methodology

* Add scaling parameters for phases

* Initial Polarization work

* Work on obtaining HKL

* Fix get HKL

* Update requirements

* Add TOF calculation for cryspy (#10)

* Update pyproject.toml

* Update __init__.py

* Update test.yml

* Update pyproject.toml

* Update GSASII.py

* ReflectionList nrefs to nref

* Moving to a more module based scheme

* TOF support

As easy as:


```
from easyCore import np
from easyDiffractionLib import Phase
from easyDiffractionLib.Runner import Runner
import matplotlib.pyplot as plt

r = Runner()
p = Phase.from_cif_file('tests/PbSO4.cif')
r.add_job('testing', job_type='powder1dTOF')
r.add_phase(p, 'testing')
job = r.jobs['testing']

job.pattern.zero_shift = 2.9121
job.create_simulation(np.linspace(3000, 11000, 801))
job.plot_simulation()
plt.show()
```

* Decouple phases and EXP in cryspy

* Fix legacy mode loading

* Use the correct references for legacy mode

* Unification of naming conventions

* Fix TOF generation

* Fix changing from TOF->CW

* Fix  all interfaces to use new schema

* Update interface and exp_type verification logic

* Fix get HKL

* Update requirements

Co-authored-by: Andrew Sazonov <AndrewSazonov@users.noreply.github.com>

* Delete .devcontainer directory

* Delete tools directory

* Tests base and README

* Update LICENSE

* fixed/updated FittingData notebook

* more updates for new eC and eDL

* Disable Lorentzian coefficients

* Added CreateSample notebook, added structure show to existing notebooks.

* Cleaned up outputs

* Temporary workaround to get ADP value

* easyCore dependence temporarily changed

* Minor changes to the notebooks. Updated toml and fixed CFML interface

* Separated working notebooks to a different directory.

* Temporary workaround to get ADP value (GSASII)

* Fix return value; back to develop branch

* Add PbSO4 fitting notebook

* Updated notebooks, corrected dependency for easyCore

* Auto stash before merge of "more_notebooks" and "origin/more_notebooks"

* Disable debug output for CFML

* Use easyCore from the develop branch

* Update fitting notebook

* Move notebooks into 'examples' folder

* Add instruction on how to run Jupyter Notebook examples

* Update fitting example

* A bit better README

* Add contributing details

* Start with tests

* Delete setup.py

* Update README.md

* Update both `simulation` and `fitting` examples

* Update README.md

* Delete unused files

* Added modified fix from the mp_mc branch to enable proper phase removal
and profile calculation on experiment type change

* Update both `simulation` and `fitting` examples

* Fix up Docs and files

* Update badge

* Add generators

* Update self_publish_alpha.yml

* Auto stash before merge of "develop" and "origin/develop"

* Update self_publish_alpha.yml

* Update generate_html.py

* Update self_publish_alpha.yml

* Update self_publish_alpha.yml

* Update self_publish_alpha.yml

* Auto stash before merge of "develop" and "origin/develop"

* Update self_publish_alpha.yml

* Try to create tagged realease

* Rename from easyDiffractionLib to easyDiffraction

* Modify project and requirements

* Use easysciencecore >= 0.1.1a0

* Only push if changes

* Add `v` to tag

* Update README.md

* Write all packages

* Add PR validation (needs labels)

* Add more branch protection stuff

* Add documentation label

* Add the ability to launch examples on Binder (#12)

* Create binder scripts

* Remove unnecessary jupyter

* Explicit external libs

* Add correct path when using binder

* Update readme [ci skip]

* Switch from `matplotlib` to `bokeh` in notebooks

* Update requirements to use `bokeh` instead of `matplotlib`

* Add links to non-interactive preview for notebooks

* Fix import `easyDiffractionLib`

* Update notebooks

* Update notebook

* Update postBuild

* Update Simulation.ipynb

* Update notebooks

* Add patch to autobuild (fix pypi arguments)

* Create pypi_publish.yml

* Modified mp_mc branch with pathos multiprocessing commented out

* Added convencience methods for single phase profiles

* Redefine additional_data['components'] with scaled values

* typo in toml

* Implement multiphase with CFML

* More CFML multiphase changes

Now phases are in the correct order and no memloc errors

* Fix memory issues again

* Fix spacegroup errors for multiphase

* Add support for the multiple HKL sets

* x_array is unnecessary for cryspy - hkl has already been calculated in
the profile run

* Fix for getting HKL's

* Use easyCrystallography

* Added a multiphase fitting example

* fix a "typo".

* fixed method signatures.

* Update requirements

* Test pre-release branch of easyCore

* Updated copyright year

* Try to use the release version of easyCore

* update poetry
force rebuild for testing easyCrystallography branch

* Fetch easyCrystallography from pypi

* Remove multiphase temp files on CFML calculator initialize #190 (#36)

* Update pytest requirement from ^5.2 to ^7.1 (#37)

Updates the requirements on [pytest](https://github.com/pytest-dev/pytest) to permit the latest version.
- [Release notes](https://github.com/pytest-dev/pytest/releases)
- [Changelog](https://github.com/pytest-dev/pytest/blob/main/CHANGELOG.rst)
- [Commits](pytest-dev/pytest@5.2.0...7.1.0)

---
updated-dependencies:
- dependency-name: pytest
  dependency-type: direct:development
...

Signed-off-by: dependabot[bot] <support@github.com>

Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>

* Update pyproject.toml (#38)

Change classifier to reflect BSD

* Updated pypi-publish step (#55)

* Implement peak asymmetries for CrysPy P1D (#57)

Co-authored-by: Andrew Sazonov <andrew.sazonov@esss.eu>

* Experiment cif reader (#58)

* Initial implementation. Things break.

* prettify the code

* Get the job object directly on reading the exp file

* cherrypicked remaining changes from IOTake2.

* More fixes

* Update from_cif_file signature. Added case for xml-fied phase

* Added a crutch for updating the background dict repr with the linked
experiment item

* Switch to pre-release-fixes branch of Core

* Bump cfml from 0.0.1 to 0.0.3 (#44)

Bumps [cfml]() from 0.0.1 to 0.0.3.

---
updated-dependencies:
- dependency-name: cfml
  dependency-type: direct:production
  update-type: version-update:semver-patch
...

Signed-off-by: dependabot[bot] <support@github.com>

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>

* Temporarily lock easyCore version after API breaking changes in 0.3.0.
This will be removed on merging of IOTake3

* Update bokeh requirement from ^2.4.0 to ^3.0.3 (#65)

Updates the requirements on [bokeh](https://github.com/bokeh/bokeh) to permit the latest version.
- [Release notes](https://github.com/bokeh/bokeh/releases)
- [Changelog](https://github.com/bokeh/bokeh/blob/3.0.3/docs/CHANGELOG)
- [Commits](bokeh/bokeh@2.4.0...3.0.3)

---
updated-dependencies:
- dependency-name: bokeh
  dependency-type: direct:development
...

Signed-off-by: dependabot[bot] <support@github.com>

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>

* Corrected space group key

* initial version of the pdffit interface. Works for profile calculations.
Loads cif files and pdffit-specific .gr files with experimental PDF

* Added diffpy module dependencies

* point to released version of core and cryst

* Add fitting example, fixed minor issues

* initial version, not much here yet

* move bindings update from sample to job

* return ndarray rather that xarray from fitting
start improving serialization

* Fixes for serialization of the job object

* set default linked experiment for serialized no-exp loaded cases

* Invoke bindings change properly

* Added notebooks for profile calc and fitting

* Bump cfml from 0.0.1 to 0.0.3 (#67)

Bumps [cfml]() from 0.0.1 to 0.0.3.

---
updated-dependencies:
- dependency-name: cfml
  dependency-type: direct:production
  update-type: version-update:semver-patch
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>

* Try getting pdffit2 from local pypi

* attempt at fixing dependencies

* Updates from job_based branch.

* make pdffit2 dependency optional, as gsas/cfml

* Updated/fixed pdf interface, now conforming to the job based runs.
Updated python scripts

* Silence the diffpy backend STDOUT

* branch update

* Updated notebooks

* Update py3dmol requirement from ^1.7.0 to ^2.0.1 (#69)

Updates the requirements on [py3dmol](https://3dmol.org) to permit the latest version.

---
updated-dependencies:
- dependency-name: py3dmol
  dependency-type: direct:development
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>

* dep update

* added delta1, delta2 parameters
apply scale properly
apply Uiso values properly
modify initial parameters for fitting example so it converges nicely

* Prettified the notebook and the script

* Rename CrysPyV2 -> CrysPy
Remove GSASII dependency. It will be made delayed import later

* Update pyproject.toml

* phase without exp - sim range param update causes errors
CFML output parsing fails on certain systems

* debug weird update issue

* Workaround for resized coords

* Add pdffit dependency so pip install doesn't complain

* update requirements.txt

* Minor updates. Moved xarray checks to app.
bumped release number
added contributor

* Make sure interface bindings are properly set on job instantiation

* pdf changes after Celine's comments

* add dependency on pycifrw, required by pdffit2

* delta1 and delta2 have units

* parameter name should be prettyfied

* check if setting pip config helps with module installation

* Modify wavelength to correspond to the gr input file.
Add unit to Q_damp

* notebook and example script updates

* Added "spdiameter" parameter, as per GSASII examples

* added spdiameter parameter to the notebook examples

* update initial values for spdiameter and update the examples

* don't update atoms without adp

* workaround for CFML failures

* Bumped release version
Commented out GSAS in toml/requirements
Try linking pypi versions of EX and EC

* Updated notebooks and added missed method in CryspyV2 interface

* Added minor updates about the current release

* Do not patch the version but take it directly from poetry

---------

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: Andrew Sazonov <AndrewSazonov@users.noreply.github.com>
Co-authored-by: Simon Ward <2798086+wardsimon@users.noreply.github.com>
Co-authored-by: Andrew Sazonov <Andrew.Sazonov@icloud.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Co-authored-by: Andrew McCluskey <andrew@mccluskey.scot>
Co-authored-by: Andrew Sazonov <andrew.sazonov@esss.eu>
@rozyczko rozyczko deleted the experiment_cif_reader branch March 30, 2023 11:37
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

[scope] enhancement Adds/improves features (major.MINOR.patch)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants