Skip to content

Commit 38c0897

Browse files
Merge pull request SSCHAcode#401 from SSCHAcode/spglib_fix
Fixed the spglib compatibility with version >2.2 Also fix the SSCHAcode#362
2 parents c2e18bc + 1b62b40 commit 38c0897

File tree

3 files changed

+18
-9
lines changed

3 files changed

+18
-9
lines changed

Modules/Ensemble.py

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1439,7 +1439,7 @@ class is created.
14391439

14401440
# # Get the symmetries from spglib
14411441
# super_structure = self.current_dyn.structure.generate_supercell(self.supercell)
1442-
# spglib_syms = spglib.get_symmetry(super_structure.get_ase_atoms())
1442+
# spglib_syms = spglib.get_symmetry(super_structure.get_spglib_cell())
14431443

14441444
# # Convert them into the cellconstructor format
14451445
# cc_syms = CC.symmetries.GetSymmetriesFromSPGLIB(spglib_syms, False)
@@ -1534,7 +1534,7 @@ def _unwrap_symmetries_(self):
15341534

15351535
# Get the symmetries from spglib
15361536
super_structure = self.current_dyn.structure.generate_supercell(self.supercell)
1537-
spglib_syms = spglib.get_symmetry(super_structure.get_ase_atoms())
1537+
spglib_syms = spglib.get_symmetry(super_structure.get_spglib_cell())
15381538

15391539
# Convert them into the cellconstructor format
15401540
cc_syms = CC.symmetries.GetSymmetriesFromSPGLIB(spglib_syms, False)
@@ -3655,6 +3655,15 @@ def get_free_energy_hessian(self, include_v4 = False, get_full_hessian = True, v
36553655
# """
36563656
# raise NotImplementedError(ERROR_MSG)
36573657

3658+
# Check if the ensemble has been initialized
3659+
if len(self.forces) == 0:
3660+
n_forces = len(self.forces)
3661+
raise ValueError(
3662+
f"Cannot evaluate free-energy Hessian: 'self.forces' is empty (len={n_forces}). "
3663+
"Initialize or load the ensemble and compute energies and forces first."
3664+
)
3665+
3666+
36583667
# Convert anything into the Ha units
36593668
# This is needed for the Fortran subroutines
36603669
self.convert_units(UNITS_HARTREE)

Modules/SchaMinimizer.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -948,7 +948,7 @@ def print_info(self):
948948
print (" use spglib = ", self.use_spglib)
949949
if self.use_spglib:
950950
import spglib
951-
print (" Symmetry group = {}".format(spglib.get_spacegroup(self.dyn.structure.get_ase_atoms())))
951+
print (" Symmetry group = {}".format(spglib.get_spacegroup(self.dyn.structure.get_spglib_cell())))
952952
print (" Number of symmetries in the unit cell = ", self.N_symmetries)
953953

954954
print ()
@@ -1097,7 +1097,7 @@ def init(self, verbosity = False, delete_previous_data = True, init_timer = True
10971097

10981098
import spglib
10991099
if verbosity:
1100-
print("Symmetry group: ", spglib.get_spacegroup(self.dyn.structure.get_ase_atoms()))
1100+
print("Symmetry group: ", spglib.get_spacegroup(self.dyn.structure.get_spglib_cell()))
11011101

11021102
self.N_symmetries = qe_sym.QE_nsym
11031103

@@ -1337,7 +1337,7 @@ def run(self, verbose = 1, custom_function_pre = None, custom_function_post = No
13371337
print ("")
13381338
print("Number of symmetries before the step: ", self.N_symmetries)
13391339
if self.use_spglib:
1340-
print("Group space: ", spglib.get_spacegroup(self.dyn.structure.get_ase_atoms()))
1340+
print("Group space: ", spglib.get_spacegroup(self.dyn.structure.get_spglib_cell()))
13411341
print ("Harmonic contribution to free energy = %16.8f meV" % (harm_fe * __RyTomev__))
13421342
print ("Anharmonic contribution to free energy = %16.8f +- %16.8f meV" % (anharm_fe * __RyTomev__,
13431343
np.real(err) * __RyTomev__))

Tutorials/LaH10/VariableCellRelaxation.ipynb

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -222,7 +222,7 @@
222222
],
223223
"source": [
224224
"import spglib\n",
225-
"print (\"The original spacegroup is:\", spglib.get_spacegroup(dyn.structure.get_ase_atoms(), 0.05))"
225+
"print (\"The original spacegroup is:\", spglib.get_spacegroup(dyn.structure.get_spglib_cell(), 0.05))"
226226
]
227227
},
228228
{
@@ -244,7 +244,7 @@
244244
"# we define a function that prints the space group during the optimization\n",
245245
"space_groups = []\n",
246246
"def print_spacegroup(minim):\n",
247-
" spgroup = spglib.get_spacegroup(minim.dyn.structure.get_ase_atoms(), 0.05)\n",
247+
" spgroup = spglib.get_spacegroup(minim.dyn.structure.get_spglib_cell(), 0.05)\n",
248248
" space_groups.append(spgroup)\n",
249249
" \n",
250250
" # We can save them in the output at each minimization step\n",
@@ -370,7 +370,7 @@
370370
}
371371
],
372372
"source": [
373-
"spglib.get_spacegroup(relax.minim.dyn.structure.get_ase_atoms(), 0.05)"
373+
"spglib.get_spacegroup(relax.minim.dyn.structure.get_spglib_cell(), 0.05)"
374374
]
375375
},
376376
{
@@ -390,7 +390,7 @@
390390
}
391391
],
392392
"source": [
393-
"spglib.get_spacegroup(dyn.structure.get_ase_atoms(), 0.1)"
393+
"spglib.get_spacegroup(dyn.structure.get_spglib_cell(), 0.1)"
394394
]
395395
},
396396
{

0 commit comments

Comments
 (0)