From 4b00785aa200e57cd858925a6326064c515b28f3 Mon Sep 17 00:00:00 2001 From: Sarath Date: Tue, 2 Jul 2024 12:04:31 +0200 Subject: [PATCH 01/11] update convert method --- .ci_support/environment.yml | 3 ++- pyproject.toml | 2 +- structuretoolkit/common/pyscal.py | 8 ++------ 3 files changed, 5 insertions(+), 8 deletions(-) diff --git a/.ci_support/environment.yml b/.ci_support/environment.yml index 00412e575..9e9c17357 100644 --- a/.ci_support/environment.yml +++ b/.ci_support/environment.yml @@ -1,3 +1,4 @@ +name: pyiron-structuretoolkit channels: - conda-forge dependencies: @@ -12,7 +13,7 @@ dependencies: - phonopy =2.24.3 - plotly =5.22.0 - pymatgen =2024.6.10 -- pyscal =2.10.18 +- pyscal3 =3.2.2 - pyxtal =0.6.7 - scikit-learn =1.5.0 - scipy =1.14.0 diff --git a/pyproject.toml b/pyproject.toml index fe18e02d7..dbc14d47b 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -41,7 +41,7 @@ grainboundary = [ "aimsgb==1.1.1", "pymatgen==2024.6.10", ] -pyscal = ["pyscal2==2.10.18"] +pyscal = ["pyscal3==3.2.2"] nglview = ["nglview==3.1.2"] matplotlib = ["matplotlib==3.8.4"] plotly = ["plotly==5.22.0"] diff --git a/structuretoolkit/common/pyscal.py b/structuretoolkit/common/pyscal.py index 47e7a698d..41087805f 100644 --- a/structuretoolkit/common/pyscal.py +++ b/structuretoolkit/common/pyscal.py @@ -12,11 +12,7 @@ def ase_to_pyscal(structure: Atoms): Returns: Pyscal system: See the pyscal documentation. """ - import pyscal.core as pc + import pyscal3 as pc - sys = pc.System() - sys.read_inputfile( - filename=structure, - format="ase", - ) + sys = pc.System(structure, format='ase') return sys From 9a51284a1f8b0961f1b3f5f3f052b21a21e6c911 Mon Sep 17 00:00:00 2001 From: Sarath Date: Wed, 3 Jul 2024 11:25:37 +0200 Subject: [PATCH 02/11] update pyscal methods --- structuretoolkit/analyse/pyscal.py | 19 ++++++++----------- 1 file changed, 8 insertions(+), 11 deletions(-) diff --git a/structuretoolkit/analyse/pyscal.py b/structuretoolkit/analyse/pyscal.py index e6119807c..86a5be227 100644 --- a/structuretoolkit/analyse/pyscal.py +++ b/structuretoolkit/analyse/pyscal.py @@ -47,11 +47,8 @@ def get_steinhardt_parameters( sys = ase_to_pyscal(structure) q = (4, 6) if q is None else q - sys.find_neighbors(method=neighbor_method, cutoff=cutoff) - - sys.calculate_q(q, averaged=averaged) - - sysq = np.array(sys.get_qvals(q, averaged=averaged)) + sys.find.neighbors(method=neighbor_method, cutoff=cutoff) + sysq = sys.calculate.steinhardt_parameter(q, averaged=averaged) if n_clusters is not None: from sklearn import cluster @@ -78,7 +75,7 @@ def get_centro_symmetry_descriptors( csm (list) : list of centrosymmetry parameter """ sys = ase_to_pyscal(structure) - return np.array(sys.calculate_centrosymmetry(nmax=num_neighbors)) + return np.array(sys.calculate.centrosymmetry(nmax=num_neighbors)) def get_diamond_structure_descriptors( @@ -101,7 +98,7 @@ def get_diamond_structure_descriptors( (depends on `mode`) """ sys = ase_to_pyscal(structure) - diamond_dict = sys.identify_diamond() + diamond_dict = sys.analyze.diamond_structure() ovito_identifiers = [ "Cubic diamond", @@ -217,7 +214,7 @@ def get_adaptive_cna_descriptors( "CommonNeighborAnalysis.counts.ICO", ] - cna = sys.calculate_cna() + cna = sys.analyze.common_neighbor_analysis() if mode == "total": if not ovito_compatibility: @@ -250,7 +247,7 @@ def get_voronoi_volumes(structure: Atoms) -> np.ndarray: structure : (ase.atoms.Atoms): The structure to analyze. """ sys = ase_to_pyscal(structure) - sys.find_neighbors(method="voronoi") + sys.find.neighbors(method="voronoi") structure = sys.atoms return np.array([atom.volume for atom in structure]) @@ -287,8 +284,8 @@ def find_solids( pyscal system: pyscal system when return_sys=True """ sys = ase_to_pyscal(structure) - sys.find_neighbors(method=neighbor_method, cutoff=cutoff) - sys.find_solids( + sys.find.neighbors(method=neighbor_method, cutoff=cutoff) + sys.find.solids( bonds=bonds, threshold=threshold, avgthreshold=avgthreshold, From 40c82afd5f7b1103265d54d4ccfa3a50b17b4a83 Mon Sep 17 00:00:00 2001 From: Sarath Date: Wed, 3 Jul 2024 11:42:03 +0200 Subject: [PATCH 03/11] change output access methods --- structuretoolkit/analyse/pyscal.py | 20 ++++++++------------ tests/test_pyscal.py | 4 ++-- 2 files changed, 10 insertions(+), 14 deletions(-) diff --git a/structuretoolkit/analyse/pyscal.py b/structuretoolkit/analyse/pyscal.py index 86a5be227..5db00e899 100644 --- a/structuretoolkit/analyse/pyscal.py +++ b/structuretoolkit/analyse/pyscal.py @@ -163,17 +163,17 @@ def get_diamond_structure_descriptors( } elif mode == "numeric": if not ovito_compatibility: - return np.array([atom.structure for atom in sys.atoms]) + return np.array(sys.atoms.structure) else: - return np.array([convert_to_ovito[atom.structure] for atom in sys.atoms]) + return np.array([convert_to_ovito[structure] for structure in sys.atoms.structure]) elif mode == "str": if not ovito_compatibility: - return np.array([pyscal_identifiers[atom.structure] for atom in sys.atoms]) + return np.array([pyscal_identifiers[structure] for structure in sys.atoms.structure]) else: return np.array( [ - ovito_identifiers[convert_to_ovito[atom.structure]] - for atom in sys.atoms + ovito_identifiers[convert_to_ovito[structure]] + for structure in sys.atoms.structure ] ) else: @@ -222,8 +222,7 @@ def get_adaptive_cna_descriptors( else: return {o: cna[p] for o, p in zip(ovito_parameter, pyscal_parameter)} else: - structure = sys.atoms - cnalist = np.array([atom.structure for atom in structure]) + cnalist = np.array(sys.atoms.structure) if mode == "numeric": return cnalist elif mode == "str": @@ -248,8 +247,7 @@ def get_voronoi_volumes(structure: Atoms) -> np.ndarray: """ sys = ase_to_pyscal(structure) sys.find.neighbors(method="voronoi") - structure = sys.atoms - return np.array([atom.volume for atom in structure]) + return np.array(sys.atoms.voronoi.volume) def find_solids( @@ -296,6 +294,4 @@ def find_solids( ) if return_sys: return sys - structure = sys.atoms - solids = [atom for atom in structure if atom.solid] - return len(solids) + return np.sum(sys.atoms.solid) diff --git a/tests/test_pyscal.py b/tests/test_pyscal.py index c2f454647..d716f7cea 100644 --- a/tests/test_pyscal.py +++ b/tests/test_pyscal.py @@ -9,7 +9,7 @@ import structuretoolkit as stk try: - import pyscal + import pyscal3 as pyscal skip_pyscal_test = False except ImportError: @@ -17,7 +17,7 @@ @unittest.skipIf( - skip_pyscal_test, "pyscal is not installed, so the pyscal tests are skipped." + skip_pyscal_test, "pyscal3 is not installed, so the pyscal3 tests are skipped." ) class Testpyscal(unittest.TestCase): @classmethod From a2090865f36c82b2529124ecec49e080002473ca Mon Sep 17 00:00:00 2001 From: Sarath Date: Tue, 9 Jul 2024 15:13:09 +0200 Subject: [PATCH 04/11] update min pyscal3 version --- .ci_support/environment.yml | 2 +- pyproject.toml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/.ci_support/environment.yml b/.ci_support/environment.yml index 9e9c17357..6a52cc792 100644 --- a/.ci_support/environment.yml +++ b/.ci_support/environment.yml @@ -13,7 +13,7 @@ dependencies: - phonopy =2.24.3 - plotly =5.22.0 - pymatgen =2024.6.10 -- pyscal3 =3.2.2 +- pyscal3 =3.2.3 - pyxtal =0.6.7 - scikit-learn =1.5.0 - scipy =1.14.0 diff --git a/pyproject.toml b/pyproject.toml index dbc14d47b..86e42571b 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -41,7 +41,7 @@ grainboundary = [ "aimsgb==1.1.1", "pymatgen==2024.6.10", ] -pyscal = ["pyscal3==3.2.2"] +pyscal = ["pyscal3==3.2.3"] nglview = ["nglview==3.1.2"] matplotlib = ["matplotlib==3.8.4"] plotly = ["plotly==5.22.0"] From d1dd6545a127b57313cb90e39599424cf519f94f Mon Sep 17 00:00:00 2001 From: Sarath Date: Tue, 9 Jul 2024 15:14:13 +0200 Subject: [PATCH 05/11] return np arrays --- structuretoolkit/analyse/pyscal.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/structuretoolkit/analyse/pyscal.py b/structuretoolkit/analyse/pyscal.py index 5db00e899..0ad6b5881 100644 --- a/structuretoolkit/analyse/pyscal.py +++ b/structuretoolkit/analyse/pyscal.py @@ -48,7 +48,7 @@ def get_steinhardt_parameters( q = (4, 6) if q is None else q sys.find.neighbors(method=neighbor_method, cutoff=cutoff) - sysq = sys.calculate.steinhardt_parameter(q, averaged=averaged) + sysq = np.array(sys.calculate.steinhardt_parameter(q, averaged=averaged)) if n_clusters is not None: from sklearn import cluster From d094d44a40f191910e3ffc8294303601001e0e84 Mon Sep 17 00:00:00 2001 From: Sarath Date: Tue, 9 Jul 2024 15:16:37 +0200 Subject: [PATCH 06/11] update diamond keys in tests --- tests/test_pyscal.py | 4 ---- 1 file changed, 4 deletions(-) diff --git a/tests/test_pyscal.py b/tests/test_pyscal.py index d716f7cea..75231888c 100644 --- a/tests/test_pyscal.py +++ b/tests/test_pyscal.py @@ -394,10 +394,6 @@ def test_analyse_pyscal_cna_adaptive(self): def test_analyse_pyscal_diamond_structure(self): pyscal_keys = [ "others", - "fcc", - "hcp", - "bcc", - "ico", "cubic diamond", "cubic diamond 1NN", "cubic diamond 2NN", From edb6abfa7365606c243e2f76ff19357d1caae073 Mon Sep 17 00:00:00 2001 From: Sarath Date: Tue, 9 Jul 2024 15:30:24 +0200 Subject: [PATCH 07/11] remove dict conversions --- structuretoolkit/analyse/pyscal.py | 8 -------- tests/test_pyscal.py | 2 +- 2 files changed, 1 insertion(+), 9 deletions(-) diff --git a/structuretoolkit/analyse/pyscal.py b/structuretoolkit/analyse/pyscal.py index 0ad6b5881..2eec03252 100644 --- a/structuretoolkit/analyse/pyscal.py +++ b/structuretoolkit/analyse/pyscal.py @@ -111,10 +111,6 @@ def get_diamond_structure_descriptors( ] pyscal_identifiers = [ "others", - "fcc", - "hcp", - "bcc", - "ico", "cubic diamond", "cubic diamond 1NN", "cubic diamond 2NN", @@ -156,10 +152,6 @@ def get_diamond_structure_descriptors( "hex diamond 2NN" ], "IdentifyDiamond.counts.OTHER": diamond_dict["others"] - + diamond_dict["fcc"] - + diamond_dict["hcp"] - + diamond_dict["bcc"] - + diamond_dict["ico"], } elif mode == "numeric": if not ovito_compatibility: diff --git a/tests/test_pyscal.py b/tests/test_pyscal.py index 75231888c..034d3515c 100644 --- a/tests/test_pyscal.py +++ b/tests/test_pyscal.py @@ -437,7 +437,7 @@ def test_analyse_pyscal_diamond_structure(self): self.assertEqual( sum([k in res_dict_total.keys() for k in pyscal_keys]), len(pyscal_keys) ) - self.assertEqual(res_dict_total[pyscal_keys[5]], len(self.si_dia)) + self.assertEqual(res_dict_total[pyscal_keys[1]], len(self.si_dia)) res_numeric = stk.analyse.get_diamond_structure_descriptors( structure=self.al_fcc, mode="numeric", ovito_compatibility=False From 351ec6a0445840de46419f1d6c34839be1cc5ead Mon Sep 17 00:00:00 2001 From: Sarath Date: Tue, 9 Jul 2024 16:13:20 +0200 Subject: [PATCH 08/11] update numeric keys --- .ci_support/environment.yml | 2 +- pyproject.toml | 2 +- structuretoolkit/analyse/pyscal.py | 25 +++++-------------------- 3 files changed, 7 insertions(+), 22 deletions(-) diff --git a/.ci_support/environment.yml b/.ci_support/environment.yml index 6a52cc792..0e1fc4665 100644 --- a/.ci_support/environment.yml +++ b/.ci_support/environment.yml @@ -13,7 +13,7 @@ dependencies: - phonopy =2.24.3 - plotly =5.22.0 - pymatgen =2024.6.10 -- pyscal3 =3.2.3 +- pyscal3 =3.2.4 - pyxtal =0.6.7 - scikit-learn =1.5.0 - scipy =1.14.0 diff --git a/pyproject.toml b/pyproject.toml index 86e42571b..f765e460d 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -41,7 +41,7 @@ grainboundary = [ "aimsgb==1.1.1", "pymatgen==2024.6.10", ] -pyscal = ["pyscal3==3.2.3"] +pyscal = ["pyscal3==3.2.4"] nglview = ["nglview==3.1.2"] matplotlib = ["matplotlib==3.8.4"] plotly = ["plotly==5.22.0"] diff --git a/structuretoolkit/analyse/pyscal.py b/structuretoolkit/analyse/pyscal.py index 2eec03252..15c118198 100644 --- a/structuretoolkit/analyse/pyscal.py +++ b/structuretoolkit/analyse/pyscal.py @@ -101,13 +101,13 @@ def get_diamond_structure_descriptors( diamond_dict = sys.analyze.diamond_structure() ovito_identifiers = [ + "Other", "Cubic diamond", "Cubic diamond (1st neighbor)", "Cubic diamond (2nd neighbor)", "Hexagonal diamond", "Hexagonal diamond (1st neighbor)", "Hexagonal diamond (2nd neighbor)", - "Other", ] pyscal_identifiers = [ "others", @@ -118,19 +118,6 @@ def get_diamond_structure_descriptors( "hex diamond 1NN", "hex diamond 2NN", ] - convert_to_ovito = { - 0: 6, - 1: 6, - 2: 6, - 3: 6, - 4: 6, - 5: 0, - 6: 1, - 7: 2, - 8: 3, - 9: 4, - 10: 5, - } if mode == "total": if not ovito_compatibility: @@ -154,17 +141,15 @@ def get_diamond_structure_descriptors( "IdentifyDiamond.counts.OTHER": diamond_dict["others"] } elif mode == "numeric": - if not ovito_compatibility: - return np.array(sys.atoms.structure) - else: - return np.array([convert_to_ovito[structure] for structure in sys.atoms.structure]) + return np.array(sys.atoms.structure) + elif mode == "str": if not ovito_compatibility: - return np.array([pyscal_identifiers[structure] for structure in sys.atoms.structure]) + return np.array([pyscal_identifiers.index(structure) for structure in sys.atoms.structure]) else: return np.array( [ - ovito_identifiers[convert_to_ovito[structure]] + ovito_identifiers.index(structure) for structure in sys.atoms.structure ] ) From 35be017295d7f1f3f66f3718b7d4ebc9c37bde59 Mon Sep 17 00:00:00 2001 From: Sarath Date: Tue, 9 Jul 2024 17:13:59 +0200 Subject: [PATCH 09/11] update to new version and final fixes --- .ci_support/environment.yml | 2 +- pyproject.toml | 2 +- structuretoolkit/analyse/pyscal.py | 10 ++++++---- tests/test_pyscal.py | 3 ++- 4 files changed, 10 insertions(+), 7 deletions(-) diff --git a/.ci_support/environment.yml b/.ci_support/environment.yml index 0e1fc4665..d6d71e1b2 100644 --- a/.ci_support/environment.yml +++ b/.ci_support/environment.yml @@ -13,7 +13,7 @@ dependencies: - phonopy =2.24.3 - plotly =5.22.0 - pymatgen =2024.6.10 -- pyscal3 =3.2.4 +- pyscal3 =3.2.5 - pyxtal =0.6.7 - scikit-learn =1.5.0 - scipy =1.14.0 diff --git a/pyproject.toml b/pyproject.toml index f765e460d..5b832cd34 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -41,7 +41,7 @@ grainboundary = [ "aimsgb==1.1.1", "pymatgen==2024.6.10", ] -pyscal = ["pyscal3==3.2.4"] +pyscal = ["pyscal3==3.2.5"] nglview = ["nglview==3.1.2"] matplotlib = ["matplotlib==3.8.4"] plotly = ["plotly==5.22.0"] diff --git a/structuretoolkit/analyse/pyscal.py b/structuretoolkit/analyse/pyscal.py index 15c118198..eefe89062 100644 --- a/structuretoolkit/analyse/pyscal.py +++ b/structuretoolkit/analyse/pyscal.py @@ -141,15 +141,17 @@ def get_diamond_structure_descriptors( "IdentifyDiamond.counts.OTHER": diamond_dict["others"] } elif mode == "numeric": - return np.array(sys.atoms.structure) + if not ovito_compatibility: + return np.array(sys.atoms.structure) + else: + return np.array([6 if x==0 else x-1 for x in sys.atoms.structure]) elif mode == "str": if not ovito_compatibility: - return np.array([pyscal_identifiers.index(structure) for structure in sys.atoms.structure]) + return np.array([pyscal_identifiers[structure] for structure in sys.atoms.structure]) else: return np.array( - [ - ovito_identifiers.index(structure) + [ovito_identifiers[structure] for structure in sys.atoms.structure ] ) diff --git a/tests/test_pyscal.py b/tests/test_pyscal.py index 034d3515c..152f8150d 100644 --- a/tests/test_pyscal.py +++ b/tests/test_pyscal.py @@ -434,6 +434,7 @@ def test_analyse_pyscal_diamond_structure(self): res_dict_total = stk.analyse.get_diamond_structure_descriptors( structure=self.si_dia, mode="total", ovito_compatibility=False ) + self.assertEqual( sum([k in res_dict_total.keys() for k in pyscal_keys]), len(pyscal_keys) ) @@ -458,7 +459,7 @@ def test_analyse_pyscal_diamond_structure(self): structure=self.si_dia, mode="numeric", ovito_compatibility=False ) self.assertEqual(len(res_numeric), len(self.si_dia)) - self.assertTrue(all([v == 5 for v in res_numeric])) + self.assertTrue(all([v == 1 for v in res_numeric])) res_str = stk.analyse.get_diamond_structure_descriptors( structure=self.al_fcc, mode="str", ovito_compatibility=False From 93b54aac43610c70f34791039cf03a63c360ca93 Mon Sep 17 00:00:00 2001 From: pyiron-runner Date: Tue, 9 Jul 2024 15:16:00 +0000 Subject: [PATCH 10/11] Format black --- structuretoolkit/analyse/pyscal.py | 14 +++++++------- structuretoolkit/common/pyscal.py | 2 +- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/structuretoolkit/analyse/pyscal.py b/structuretoolkit/analyse/pyscal.py index eefe89062..81f4e90ad 100644 --- a/structuretoolkit/analyse/pyscal.py +++ b/structuretoolkit/analyse/pyscal.py @@ -138,22 +138,22 @@ def get_diamond_structure_descriptors( "IdentifyDiamond.counts.HEX_DIAMOND_SECOND_NEIGHBOR": diamond_dict[ "hex diamond 2NN" ], - "IdentifyDiamond.counts.OTHER": diamond_dict["others"] + "IdentifyDiamond.counts.OTHER": diamond_dict["others"], } elif mode == "numeric": if not ovito_compatibility: return np.array(sys.atoms.structure) else: - return np.array([6 if x==0 else x-1 for x in sys.atoms.structure]) - + return np.array([6 if x == 0 else x - 1 for x in sys.atoms.structure]) + elif mode == "str": if not ovito_compatibility: - return np.array([pyscal_identifiers[structure] for structure in sys.atoms.structure]) + return np.array( + [pyscal_identifiers[structure] for structure in sys.atoms.structure] + ) else: return np.array( - [ovito_identifiers[structure] - for structure in sys.atoms.structure - ] + [ovito_identifiers[structure] for structure in sys.atoms.structure] ) else: raise ValueError( diff --git a/structuretoolkit/common/pyscal.py b/structuretoolkit/common/pyscal.py index 41087805f..b3070fa39 100644 --- a/structuretoolkit/common/pyscal.py +++ b/structuretoolkit/common/pyscal.py @@ -14,5 +14,5 @@ def ase_to_pyscal(structure: Atoms): """ import pyscal3 as pc - sys = pc.System(structure, format='ase') + sys = pc.System(structure, format="ase") return sys From 11ba694e3e004f43b3f1462bca59aaa561628b48 Mon Sep 17 00:00:00 2001 From: Jan Janssen Date: Tue, 9 Jul 2024 18:09:58 +0200 Subject: [PATCH 11/11] Update environment-old.yml --- .ci_support/environment-old.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.ci_support/environment-old.yml b/.ci_support/environment-old.yml index 2ba8f506c..37dbdb3fa 100644 --- a/.ci_support/environment-old.yml +++ b/.ci_support/environment-old.yml @@ -9,7 +9,7 @@ dependencies: - phonopy =2.16.2 - plotly =4.14.3 - pymatgen =2022.2.1 -- pyscal =2.10.4 +- pyscal3 =3.2.5 - pyxtal =0.5.5 - scikit-learn =1.2.1 - scipy =1.9.3