From 222517153001a8b7bce78d74bbde0fda3b260593 Mon Sep 17 00:00:00 2001 From: rozyczko Date: Fri, 15 Nov 2024 11:25:18 +0100 Subject: [PATCH 1/4] add proper handling of CIF-read it_coordinate_system_code value --- easydiffraction/Interfaces/cryspyV2.py | 6 ++++-- easydiffraction/calculators/cryspy.py | 21 ++++++++++++++++++++- 2 files changed, 24 insertions(+), 3 deletions(-) diff --git a/easydiffraction/Interfaces/cryspyV2.py b/easydiffraction/Interfaces/cryspyV2.py index 83961eac..573a0852 100644 --- a/easydiffraction/Interfaces/cryspyV2.py +++ b/easydiffraction/Interfaces/cryspyV2.py @@ -126,8 +126,10 @@ 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 = {"hermann_mauguin": "name_hm_alt"} + name = model.name_hm_alt.raw_value + s_key = self.calculator.createSpaceGroup(key=model_key, name_hm_alt=name) + keys = {"hermann_mauguin": "name_hm_alt", "coordinate-code": "it_code"} + r_list.append( ItemContainer( s_key, diff --git a/easydiffraction/calculators/cryspy.py b/easydiffraction/calculators/cryspy.py index 9e9d9fe3..1b6bf706 100644 --- a/easydiffraction/calculators/cryspy.py +++ b/easydiffraction/calculators/cryspy.py @@ -116,6 +116,8 @@ def __init__(self): self._first_experiment_name = "" self.exp_obj = None self.chisq = None + self.hm_symbol = "" + self.it_code = "" self.excluded_points = [] self._cryspyData = Data() # {phase_name: CryspyPhase, exp_name: CryspyExperiment} self._cryspyObject = self._cryspyData._cryspyObj @@ -218,8 +220,25 @@ def assignCell_toCrystal(self, cell_name: str, crystal_name: str): crystal.cell = cell def createSpaceGroup( - self, key: str = "spacegroup", name_hm_alt: str = "P 1" + self, key: str = "spacegroup", name_hm_alt: str = "", it_code: Optional[str] = "" ) -> str: + if not name_hm_alt and not self.hm_symbol: + self.hm_symbol = "P 1" + if not name_hm_alt: + name_hm_alt = self.hm_symbol + else: + self.hm_symbol = name_hm_alt + + if not it_code and not self.it_code: + self.it_code = "1" + if not it_code: + it_code = self.it_code + else: + self.it_code = it_code + + if it_code: + name_hm_alt += ":" + it_code + sg_split = name_hm_alt.split(":") opts = {"name_hm_alt": sg_split[0]} if len(sg_split) > 1: From 3a6cad37f436851a670c31bcb6d8d4ae8b084175 Mon Sep 17 00:00:00 2001 From: rozyczko Date: Mon, 18 Nov 2024 13:49:39 +0900 Subject: [PATCH 2/4] Now with handling of explicit changes of the group code --- easydiffraction/calculators/cryspy.py | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/easydiffraction/calculators/cryspy.py b/easydiffraction/calculators/cryspy.py index 1b6bf706..14ab927e 100644 --- a/easydiffraction/calculators/cryspy.py +++ b/easydiffraction/calculators/cryspy.py @@ -281,6 +281,13 @@ def updateSpacegroup(self, sg_key: str, **kwargs): break sg_key = self.createSpaceGroup(key=sg_key, **kwargs) self.assignSpaceGroup_toCrystal(sg_key, previous_key) + # here, the CIF has the new group, so reload + if not self.current_crystal: + return + if 'it_code' in kwargs: + cif = self.cif_str + self.updateModelCif(cif) + pass def createAtom(self, atom_name: str, **kwargs) -> str: atom = cryspy.AtomSite(**kwargs) From ddcd259469ac52406c12d58b2a2b61bd26407240 Mon Sep 17 00:00:00 2001 From: rozyczko Date: Tue, 19 Nov 2024 11:47:28 +0900 Subject: [PATCH 3/4] CR related fixes --- easydiffraction/calculators/cryspy.py | 21 +++++++++------------ pyproject.toml | 2 +- 2 files changed, 10 insertions(+), 13 deletions(-) diff --git a/easydiffraction/calculators/cryspy.py b/easydiffraction/calculators/cryspy.py index 14ab927e..31a9551a 100644 --- a/easydiffraction/calculators/cryspy.py +++ b/easydiffraction/calculators/cryspy.py @@ -13,7 +13,9 @@ import cryspy import numpy as np from cryspy.procedure_rhochi.rhochi_by_dictionary import rhochi_calc_chi_sq_by_dictionary +from easycrystallography.Components.SpaceGroup import SpaceGroup from easyscience import global_object as borg +from gemmi import find_spacegroup_by_name from easydiffraction.io.cif import cifV2ToV1 from easydiffraction.io.cif import cifV2ToV1_tof @@ -116,7 +118,7 @@ def __init__(self): self._first_experiment_name = "" self.exp_obj = None self.chisq = None - self.hm_symbol = "" + self.name_hm_alt = "" self.it_code = "" self.excluded_points = [] self._cryspyData = Data() # {phase_name: CryspyPhase, exp_name: CryspyExperiment} @@ -222,19 +224,14 @@ def assignCell_toCrystal(self, cell_name: str, crystal_name: str): def createSpaceGroup( self, key: str = "spacegroup", name_hm_alt: str = "", it_code: Optional[str] = "" ) -> str: - if not name_hm_alt and not self.hm_symbol: - self.hm_symbol = "P 1" - if not name_hm_alt: - name_hm_alt = self.hm_symbol - else: - self.hm_symbol = name_hm_alt + self.name_hm_alt = name_hm_alt or self.name_hm_alt or "P 1" + name_hm_alt = self.name_hm_alt - if not it_code and not self.it_code: - self.it_code = "1" if not it_code: - it_code = self.it_code - else: - self.it_code = it_code + sg = find_spacegroup_by_name(name_hm_alt) + settings = SpaceGroup.find_settings_by_number(sg.number) + self.it_code = settings[0] if settings else "" + it_code = it_code or self.it_code if it_code: name_hm_alt += ":" + it_code diff --git a/pyproject.toml b/pyproject.toml index a0853712..86efdb3a 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -23,7 +23,7 @@ requires-python = '>=3.9,<3.13' dependencies = [ 'cryspy', 'easyscience', - 'easycrystallography', + 'easycrystallography @ git+https://github.com/easyscience/EasyCrystallography.git@it_system_fix', ] [project.optional-dependencies] From da9b5685169ba31cba3bdb5db0dbc959547881ac Mon Sep 17 00:00:00 2001 From: rozyczko Date: Wed, 20 Nov 2024 14:41:56 +0900 Subject: [PATCH 4/4] assign default settings based on cryspy algorithm --- easydiffraction/calculators/cryspy.py | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/easydiffraction/calculators/cryspy.py b/easydiffraction/calculators/cryspy.py index 31a9551a..d37282c7 100644 --- a/easydiffraction/calculators/cryspy.py +++ b/easydiffraction/calculators/cryspy.py @@ -12,8 +12,8 @@ import cryspy import numpy as np +from cryspy.A_functions_base.function_2_space_group import get_default_it_coordinate_system_code_by_it_number from cryspy.procedure_rhochi.rhochi_by_dictionary import rhochi_calc_chi_sq_by_dictionary -from easycrystallography.Components.SpaceGroup import SpaceGroup from easyscience import global_object as borg from gemmi import find_spacegroup_by_name @@ -229,8 +229,7 @@ def createSpaceGroup( if not it_code: sg = find_spacegroup_by_name(name_hm_alt) - settings = SpaceGroup.find_settings_by_number(sg.number) - self.it_code = settings[0] if settings else "" + self.it_code = get_default_it_coordinate_system_code_by_it_number(sg.number) it_code = it_code or self.it_code if it_code: