Skip to content

Commit bf6acd3

Browse files
authored
Merge pull request #209 from pyiron/update_to_pyscal3
Update to pyscal3
2 parents 50f7361 + 11ba694 commit bf6acd3

File tree

6 files changed

+31
-65
lines changed

6 files changed

+31
-65
lines changed

.ci_support/environment-old.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ dependencies:
99
- phonopy =2.16.2
1010
- plotly =4.14.3
1111
- pymatgen =2022.2.1
12-
- pyscal =2.10.4
12+
- pyscal3 =3.2.5
1313
- pyxtal =0.5.5
1414
- scikit-learn =1.2.1
1515
- scipy =1.9.3

.ci_support/environment.yml

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
name: pyiron-structuretoolkit
12
channels:
23
- conda-forge
34
dependencies:
@@ -12,7 +13,7 @@ dependencies:
1213
- phonopy =2.26.3
1314
- plotly =5.22.0
1415
- pymatgen =2024.6.10
15-
- pyscal =2.10.18
16+
- pyscal3 =3.2.5
1617
- pyxtal =0.6.7
1718
- scikit-learn =1.5.1
1819
- scipy =1.14.0

pyproject.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ grainboundary = [
4141
"aimsgb==1.1.1",
4242
"pymatgen==2024.6.10",
4343
]
44-
pyscal = ["pyscal2==2.10.18"]
44+
pyscal = ["pyscal3==3.2.5"]
4545
nglview = ["nglview==3.1.2"]
4646
matplotlib = ["matplotlib==3.8.4"]
4747
plotly = ["plotly==5.22.0"]

structuretoolkit/analyse/pyscal.py

+20-48
Original file line numberDiff line numberDiff line change
@@ -47,11 +47,8 @@ def get_steinhardt_parameters(
4747
sys = ase_to_pyscal(structure)
4848
q = (4, 6) if q is None else q
4949

50-
sys.find_neighbors(method=neighbor_method, cutoff=cutoff)
51-
52-
sys.calculate_q(q, averaged=averaged)
53-
54-
sysq = np.array(sys.get_qvals(q, averaged=averaged))
50+
sys.find.neighbors(method=neighbor_method, cutoff=cutoff)
51+
sysq = np.array(sys.calculate.steinhardt_parameter(q, averaged=averaged))
5552

5653
if n_clusters is not None:
5754
from sklearn import cluster
@@ -78,7 +75,7 @@ def get_centro_symmetry_descriptors(
7875
csm (list) : list of centrosymmetry parameter
7976
"""
8077
sys = ase_to_pyscal(structure)
81-
return np.array(sys.calculate_centrosymmetry(nmax=num_neighbors))
78+
return np.array(sys.calculate.centrosymmetry(nmax=num_neighbors))
8279

8380

8481
def get_diamond_structure_descriptors(
@@ -101,43 +98,26 @@ def get_diamond_structure_descriptors(
10198
(depends on `mode`)
10299
"""
103100
sys = ase_to_pyscal(structure)
104-
diamond_dict = sys.identify_diamond()
101+
diamond_dict = sys.analyze.diamond_structure()
105102

106103
ovito_identifiers = [
104+
"Other",
107105
"Cubic diamond",
108106
"Cubic diamond (1st neighbor)",
109107
"Cubic diamond (2nd neighbor)",
110108
"Hexagonal diamond",
111109
"Hexagonal diamond (1st neighbor)",
112110
"Hexagonal diamond (2nd neighbor)",
113-
"Other",
114111
]
115112
pyscal_identifiers = [
116113
"others",
117-
"fcc",
118-
"hcp",
119-
"bcc",
120-
"ico",
121114
"cubic diamond",
122115
"cubic diamond 1NN",
123116
"cubic diamond 2NN",
124117
"hex diamond",
125118
"hex diamond 1NN",
126119
"hex diamond 2NN",
127120
]
128-
convert_to_ovito = {
129-
0: 6,
130-
1: 6,
131-
2: 6,
132-
3: 6,
133-
4: 6,
134-
5: 0,
135-
6: 1,
136-
7: 2,
137-
8: 3,
138-
9: 4,
139-
10: 5,
140-
}
141121

142122
if mode == "total":
143123
if not ovito_compatibility:
@@ -158,26 +138,22 @@ def get_diamond_structure_descriptors(
158138
"IdentifyDiamond.counts.HEX_DIAMOND_SECOND_NEIGHBOR": diamond_dict[
159139
"hex diamond 2NN"
160140
],
161-
"IdentifyDiamond.counts.OTHER": diamond_dict["others"]
162-
+ diamond_dict["fcc"]
163-
+ diamond_dict["hcp"]
164-
+ diamond_dict["bcc"]
165-
+ diamond_dict["ico"],
141+
"IdentifyDiamond.counts.OTHER": diamond_dict["others"],
166142
}
167143
elif mode == "numeric":
168144
if not ovito_compatibility:
169-
return np.array([atom.structure for atom in sys.atoms])
145+
return np.array(sys.atoms.structure)
170146
else:
171-
return np.array([convert_to_ovito[atom.structure] for atom in sys.atoms])
147+
return np.array([6 if x == 0 else x - 1 for x in sys.atoms.structure])
148+
172149
elif mode == "str":
173150
if not ovito_compatibility:
174-
return np.array([pyscal_identifiers[atom.structure] for atom in sys.atoms])
151+
return np.array(
152+
[pyscal_identifiers[structure] for structure in sys.atoms.structure]
153+
)
175154
else:
176155
return np.array(
177-
[
178-
ovito_identifiers[convert_to_ovito[atom.structure]]
179-
for atom in sys.atoms
180-
]
156+
[ovito_identifiers[structure] for structure in sys.atoms.structure]
181157
)
182158
else:
183159
raise ValueError(
@@ -217,16 +193,15 @@ def get_adaptive_cna_descriptors(
217193
"CommonNeighborAnalysis.counts.ICO",
218194
]
219195

220-
cna = sys.calculate_cna()
196+
cna = sys.analyze.common_neighbor_analysis()
221197

222198
if mode == "total":
223199
if not ovito_compatibility:
224200
return cna
225201
else:
226202
return {o: cna[p] for o, p in zip(ovito_parameter, pyscal_parameter)}
227203
else:
228-
structure = sys.atoms
229-
cnalist = np.array([atom.structure for atom in structure])
204+
cnalist = np.array(sys.atoms.structure)
230205
if mode == "numeric":
231206
return cnalist
232207
elif mode == "str":
@@ -250,9 +225,8 @@ def get_voronoi_volumes(structure: Atoms) -> np.ndarray:
250225
structure : (ase.atoms.Atoms): The structure to analyze.
251226
"""
252227
sys = ase_to_pyscal(structure)
253-
sys.find_neighbors(method="voronoi")
254-
structure = sys.atoms
255-
return np.array([atom.volume for atom in structure])
228+
sys.find.neighbors(method="voronoi")
229+
return np.array(sys.atoms.voronoi.volume)
256230

257231

258232
def find_solids(
@@ -287,8 +261,8 @@ def find_solids(
287261
pyscal system: pyscal system when return_sys=True
288262
"""
289263
sys = ase_to_pyscal(structure)
290-
sys.find_neighbors(method=neighbor_method, cutoff=cutoff)
291-
sys.find_solids(
264+
sys.find.neighbors(method=neighbor_method, cutoff=cutoff)
265+
sys.find.solids(
292266
bonds=bonds,
293267
threshold=threshold,
294268
avgthreshold=avgthreshold,
@@ -299,6 +273,4 @@ def find_solids(
299273
)
300274
if return_sys:
301275
return sys
302-
structure = sys.atoms
303-
solids = [atom for atom in structure if atom.solid]
304-
return len(solids)
276+
return np.sum(sys.atoms.solid)

structuretoolkit/common/pyscal.py

+2-6
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,7 @@ def ase_to_pyscal(structure: Atoms):
1212
Returns:
1313
Pyscal system: See the pyscal documentation.
1414
"""
15-
import pyscal.core as pc
15+
import pyscal3 as pc
1616

17-
sys = pc.System()
18-
sys.read_inputfile(
19-
filename=structure,
20-
format="ase",
21-
)
17+
sys = pc.System(structure, format="ase")
2218
return sys

tests/test_pyscal.py

+5-8
Original file line numberDiff line numberDiff line change
@@ -9,15 +9,15 @@
99
import structuretoolkit as stk
1010

1111
try:
12-
import pyscal
12+
import pyscal3 as pyscal
1313

1414
skip_pyscal_test = False
1515
except ImportError:
1616
skip_pyscal_test = True
1717

1818

1919
@unittest.skipIf(
20-
skip_pyscal_test, "pyscal is not installed, so the pyscal tests are skipped."
20+
skip_pyscal_test, "pyscal3 is not installed, so the pyscal3 tests are skipped."
2121
)
2222
class Testpyscal(unittest.TestCase):
2323
@classmethod
@@ -394,10 +394,6 @@ def test_analyse_pyscal_cna_adaptive(self):
394394
def test_analyse_pyscal_diamond_structure(self):
395395
pyscal_keys = [
396396
"others",
397-
"fcc",
398-
"hcp",
399-
"bcc",
400-
"ico",
401397
"cubic diamond",
402398
"cubic diamond 1NN",
403399
"cubic diamond 2NN",
@@ -438,10 +434,11 @@ def test_analyse_pyscal_diamond_structure(self):
438434
res_dict_total = stk.analyse.get_diamond_structure_descriptors(
439435
structure=self.si_dia, mode="total", ovito_compatibility=False
440436
)
437+
441438
self.assertEqual(
442439
sum([k in res_dict_total.keys() for k in pyscal_keys]), len(pyscal_keys)
443440
)
444-
self.assertEqual(res_dict_total[pyscal_keys[5]], len(self.si_dia))
441+
self.assertEqual(res_dict_total[pyscal_keys[1]], len(self.si_dia))
445442

446443
res_numeric = stk.analyse.get_diamond_structure_descriptors(
447444
structure=self.al_fcc, mode="numeric", ovito_compatibility=False
@@ -462,7 +459,7 @@ def test_analyse_pyscal_diamond_structure(self):
462459
structure=self.si_dia, mode="numeric", ovito_compatibility=False
463460
)
464461
self.assertEqual(len(res_numeric), len(self.si_dia))
465-
self.assertTrue(all([v == 5 for v in res_numeric]))
462+
self.assertTrue(all([v == 1 for v in res_numeric]))
466463

467464
res_str = stk.analyse.get_diamond_structure_descriptors(
468465
structure=self.al_fcc, mode="str", ovito_compatibility=False

0 commit comments

Comments
 (0)