Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
58 commits
Select commit Hold shift + click to select a range
ea49820
cherrypicked remaining changes from IOTake2.
rozyczko Nov 14, 2022
1c2272a
More fixes
rozyczko Nov 21, 2022
c06b1d1
Update from_cif_file signature. Added case for xml-fied phase
rozyczko Nov 30, 2022
027ca1c
Added a crutch for updating the background dict repr with the linked
rozyczko Dec 2, 2022
2d7e104
Switch to pre-release-fixes branch of Core
rozyczko Dec 3, 2022
0021e52
Corrected space group key
rozyczko Dec 12, 2022
56c0b6f
Merge branch 'develop' into IOTake3
rozyczko Dec 12, 2022
f185966
initial version of the pdffit interface. Works for profile calculations.
rozyczko Jan 5, 2023
f3919b6
Added diffpy module dependencies
rozyczko Jan 5, 2023
5545bf0
point to released version of core and cryst
rozyczko Jan 13, 2023
0cebec1
Add fitting example, fixed minor issues
rozyczko Jan 16, 2023
d7fb03c
initial version, not much here yet
rozyczko Jan 17, 2023
2402a1a
move bindings update from sample to job
rozyczko Jan 18, 2023
763d035
return ndarray rather that xarray from fitting
rozyczko Jan 19, 2023
b8f458e
Fixes for serialization of the job object
rozyczko Jan 23, 2023
1e48fd7
set default linked experiment for serialized no-exp loaded cases
rozyczko Jan 24, 2023
95b0b83
Invoke bindings change properly
rozyczko Jan 27, 2023
fdeabe8
Added notebooks for profile calc and fitting
rozyczko Feb 10, 2023
89cd7be
Merge branch 'pdf' into release-0.8.5
rozyczko Feb 13, 2023
d8595d6
Try getting pdffit2 from local pypi
rozyczko Feb 17, 2023
3bbe934
attempt at fixing dependencies
rozyczko Feb 17, 2023
9f04495
Updates from job_based branch.
rozyczko Feb 20, 2023
4385696
make pdffit2 dependency optional, as gsas/cfml
rozyczko Feb 20, 2023
bf1a9d5
Updated/fixed pdf interface, now conforming to the job based runs.
rozyczko Feb 21, 2023
6634a01
Silence the diffpy backend STDOUT
rozyczko Feb 21, 2023
6fc883b
branch update
rozyczko Feb 21, 2023
970221b
Updated notebooks
rozyczko Feb 23, 2023
da1dfc3
dep update
rozyczko Feb 24, 2023
3bec9ba
added delta1, delta2 parameters
rozyczko Feb 26, 2023
c9b346e
Prettified the notebook and the script
rozyczko Feb 27, 2023
7d93858
Rename CrysPyV2 -> CrysPy
rozyczko Feb 27, 2023
5dbd4dc
Update pyproject.toml
wardsimon Mar 1, 2023
51071b9
phase without exp - sim range param update causes errors
rozyczko Mar 2, 2023
974c013
Merge branch 'release-0.8.5' of https://github.com/easyScience/easyDi…
rozyczko Mar 2, 2023
93ce43a
debug weird update issue
rozyczko Mar 7, 2023
445dc05
Workaround for resized coords
rozyczko Mar 8, 2023
fd617fd
Add pdffit dependency so pip install doesn't complain
rozyczko Mar 9, 2023
a76bf85
update requirements.txt
rozyczko Mar 9, 2023
afc8e6f
Minor updates. Moved xarray checks to app.
rozyczko Mar 13, 2023
48a5d7a
Make sure interface bindings are properly set on job instantiation
rozyczko Mar 13, 2023
9788ecb
pdf changes after Celine's comments
rozyczko Mar 14, 2023
b4cc135
add dependency on pycifrw, required by pdffit2
rozyczko Mar 14, 2023
70bbebb
delta1 and delta2 have units
rozyczko Mar 15, 2023
f2d0b02
parameter name should be prettyfied
rozyczko Mar 15, 2023
d882046
check if setting pip config helps with module installation
rozyczko Mar 15, 2023
3932e75
Modify wavelength to correspond to the gr input file.
rozyczko Mar 16, 2023
4ef2bd5
notebook and example script updates
rozyczko Mar 16, 2023
7b43ad6
Added "spdiameter" parameter, as per GSASII examples
rozyczko Mar 16, 2023
192c89a
added spdiameter parameter to the notebook examples
rozyczko Mar 16, 2023
31bd259
update initial values for spdiameter and update the examples
rozyczko Mar 16, 2023
3fbf825
don't update atoms without adp
rozyczko Mar 17, 2023
41eec31
Merge pull request #74 from easyScience/additional_pypi_org
rozyczko Mar 20, 2023
f76c08b
workaround for CFML failures
rozyczko Mar 20, 2023
81a28a5
Bumped release version
rozyczko Mar 21, 2023
5cbc4dd
Merge branch 'develop' into release-0.8.5
rozyczko Mar 23, 2023
d756369
Updated notebooks and added missed method in CryspyV2 interface
rozyczko Mar 24, 2023
763f134
Added minor updates about the current release
rozyczko Mar 27, 2023
c82835b
Merge branch 'release-0.8.5' of https://github.com/easyScience/easyDi…
rozyczko Mar 27, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions .github/workflows/unit_test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,12 @@ jobs:
with:
python-version: 3.8

- name: Enable extra repository
shell: bash
run: |
pip config --user set global.extra-index-url https://easyscience.github.io/pypi/
pip config --user set global.trusted-host easyscience.github.io

- name: Some logging
shell: bash
run: |
Expand Down
14 changes: 14 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1 +1,15 @@
# Version 0.0.9-beta (28 Mar 2023)

### New Features

- Simulating and fitting Pair Distribution Function data using the [PDFFIT](https://github.com/diffpy/diffpy.pdffit2) calculation engine.

### Changes

- GSASII calculation engine has been removed.
- Changed API to define `Job` object as no longer based on the `Sample` class.
- [Xarray objects](https://github.com/pydata/xarray) are now used to store the calculation engine results.
- Overall performance has been improved.

-

2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
**easydiffractionLib** is a Python library which provides:
* Scripting interface to simulate and analyse neutron diffraction patterns.
* Multiple optimization algorithms to minimize models to experimental data: [Lmfit](https://lmfit.github.io/lmfit-py/), [Bumps](https://github.com/bumps/bumps) and [DFO_LS](https://github.com/numericalalgorithmsgroup/dfols).
* Multiple calculation engines: [CrysPy](https://github.com/ikibalin/cryspy), [CrysFML](https://www.ill.eu/sites/fullprof/php/programs24b7.html?pagina=Crysfml), [GSAS-II](https://subversion.xray.aps.anl.gov/trac/pyGSAS).
* Multiple calculation engines: [CrysPy](https://github.com/ikibalin/cryspy), [CrysFML](https://www.ill.eu/sites/fullprof/php/programs24b7.html?pagina=Crysfml).

**easydiffractionLib** is the foundation of [**easyDiffraction**](https://github.com/easyScience/easyDiffraction), an intuitive application which endeavors simplifying and accelerating the analysis of diffraction experiments.

Expand Down
11 changes: 9 additions & 2 deletions easyDiffractionLib/Interfaces/CFML.py
Original file line number Diff line number Diff line change
Expand Up @@ -162,14 +162,21 @@ def dump_cif(self, *args, **kwargs):
return
# delete preexising cif files
self.remove_cif()
# naive and silly workaround for something mysterious happening in easyCrystallography
content = str(self._phase.cif)
content = content.replace("H-M_ref", "H-M_alt")
with open(self._filename, "w") as fid:
fid.write(str(self._phase.cif))
# fid.write(str(self._phase.cif))
fid.write(content)
base, file = os.path.split(self._filename)
ext = file[-3:]
file = file[:-4]
for idx, phase in enumerate(self._phase):
content = str(phase.cif)
content = content.replace("H-M_ref", "H-M_alt")
with open(f"{os.path.join(base, file)}_{idx}.{ext}", "w") as fid:
fid.write(str(phase.cif))
#fid.write(str(phase.cif))
fid.write(content)

def remove_cif(self):
if self._filename is None:
Expand Down
4 changes: 2 additions & 2 deletions easyDiffractionLib/Interfaces/GSASII.py
Original file line number Diff line number Diff line change
Expand Up @@ -110,8 +110,8 @@ def create(self, model):
elif issubclass(t_, Phases):
self._phase = model
elif t_.__name__ in ['Powder1DCW', 'powder1DCW', 'Npowder1DCW', 'Npowder1DCWunp']:
# #TODO Check to see if parameters and pattern should be initialized here.
self.__createModel(model_key, 'powder1DCW')
#TODO Check to see if parameters and pattern should be initialized here.
self.__createModel(model)
elif issubclass(t_, Sample):
self.__createModel(model)
else:
Expand Down
28 changes: 16 additions & 12 deletions easyDiffractionLib/Interfaces/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,30 +6,34 @@
import traceback


try:
from easyDiffractionLib.Interfaces.cryspy import Cryspy # noqa: F401
except ImportError:
# TODO make this a proper message (use logging?)
print('Warning: CrysPy is not installed')


# try:
# from easyDiffractionLib.Interfaces.cryspyV2 import CryspyBase # noqa: F401
# from easyDiffractionLib.Interfaces.cryspy import Cryspy # noqa: F401
# except ImportError:
# # TODO make this a proper message (use logging?)
# print('Warning: CrysPy is not installed')


try:
from easyDiffractionLib.Interfaces.CFML import CFML # noqa: F401
from easyDiffractionLib.Interfaces.cryspyV2 import CryspyBase # noqa: F401
except ImportError:
# TODO make this a proper message (use logging?)
print('Warning: CrysFML is not installed')
print('Warning: CrysPy is not installed')

try:
from easyDiffractionLib.Interfaces.GSASII import GSASII # noqa: F401
from easyDiffractionLib.Interfaces.CFML import CFML # noqa: F401
except ImportError:
# TODO make this a proper message (use logging?)
print('Warning: GSAS-2 is not installed')
print('Warning: CrysFML is not installed')

# try:
# from easyDiffractionLib.Interfaces.GSASII import GSASII # noqa: F401
# except ImportError:
# # TODO make this a proper message (use logging?)
# print('Warning: GSAS-2 is not installed')

try:
from easyDiffractionLib.Interfaces.pdffit2 import Pdffit2 # noqa: F401
except ImportError:
print('Warning: PdfFit2 is not installed')

from easyDiffractionLib.Interfaces.interfaceTemplate import InterfaceTemplate
54 changes: 52 additions & 2 deletions easyDiffractionLib/Interfaces/cryspyV2.py
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ def create(self, model: B) -> List[ItemContainer]:
# Interface with Spacegroup
elif issubclass(t_, SpaceGroup):
s_key = self.calculator.createSpaceGroup(key=model_key, name_hm_alt="P 1")
keys = {"_space_group_HM_name": "name_hm_alt"}
keys = {"hermann_mauguin": "name_hm_alt"}
r_list.append(
ItemContainer(
s_key,
Expand Down Expand Up @@ -598,6 +598,7 @@ def create(self, model: B) -> List[ItemContainer]:
model_key = self._identify(model)
base = "powder1DCWpol"
if t_.__name__ == "Sample" or t_.__name__ in [
"PolPowder1DCW",
"Powder1DCWpol",
"powder1DCWpol",
"Npowder1DCWpol",
Expand Down Expand Up @@ -644,7 +645,7 @@ def create(self, model: B) -> List[ItemContainer]:
## This is the main class which is called, implementing one of the above classes.
##
class CryspyV2(InterfaceTemplate):
name = "CrysPyV2"
name = "CrysPy"

feature_available = {
"Npowder1DCWunp": True,
Expand Down Expand Up @@ -710,6 +711,36 @@ def fit_func(self, x_array: np.ndarray, *args, **kwargs) -> Union[np.ndarray, No
)
return calculation

def generate_pol_fit_func(
self,
x_array: np.ndarray,
spin_up: np.ndarray,
spin_down: np.ndarray,
components: List[Callable],
) -> Callable:
num_components = len(components)
dummy_x = np.repeat(x_array[..., np.newaxis], num_components, axis=x_array.ndim)
calculated_y = np.array(
[fun(spin_up, spin_down) for fun in components]
).swapaxes(0, x_array.ndim)

def pol_fit_fuction(dummy_x: np.ndarray, **kwargs) -> np.ndarray:
results, results_dict = self.calculator.full_calculate(
x_array, pol_fn=components[0], **kwargs
)
phases = list(results_dict["phases"].keys())[0]
up, down = (
results_dict["phases"][phases]["components"]["up"],
results_dict["phases"][phases]["components"]["down"],
)
bg = results_dict["f_background"]
sim_y = np.array(
[fun(up, down) + fun(bg, bg) for fun in components]
).swapaxes(0, x_array.ndim)
return sim_y.flatten()

return dummy_x.flatten(), calculated_y.flatten(), pol_fit_fuction

def get_hkl(
self,
x_array: np.ndarray = None,
Expand Down Expand Up @@ -739,3 +770,22 @@ def get_phase_components(self, phase_name: str) -> dict:
if self._internal is not None:
data = self._internal.get_phase_components(phase_name)
return data

def full_callback(
self,
x_array: np.ndarray,
pol_fn: Optional[Callable[[np.ndarray, np.ndarray], np.ndarray]] = None,
**kwargs,
) -> np.ndarray:
"""
Calculate the polarization components.
:param x_array: points to be calculated at
:return: calculated points
"""
if pol_fn is None:
pol_fn = self.up_plus_down
result = None
if self.calculator is not None:
result = self.calculator.full_calculate(x_array, pol_fn=pol_fn, **kwargs)
return result

4 changes: 2 additions & 2 deletions easyDiffractionLib/Interfaces/interfaceTemplate.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
from abc import ABCMeta, abstractmethod
from typing import Tuple, List
from easyCore import np, borg
from easyCore.Utils.json import MSONable
from easyCore.Objects.core import ComponentSerializer

exp_type_strings = {
'radiation_options': ['N', 'X'],
Expand All @@ -15,7 +15,7 @@
}


class InterfaceTemplate(MSONable, metaclass=ABCMeta):
class InterfaceTemplate(ComponentSerializer, metaclass=ABCMeta):
"""
This class is a template and defines all properties that an interface should have.
"""
Expand Down
Loading