Skip to content

Commit

Permalink
Merge branch 'develop' into rc
Browse files Browse the repository at this point in the history
  • Loading branch information
atztogo committed Nov 6, 2022
2 parents 8408825 + 2c516fe commit d426421
Show file tree
Hide file tree
Showing 12 changed files with 180 additions and 14 deletions.
33 changes: 33 additions & 0 deletions .github/ISSUE_TEMPLATE/bug_report.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
---
name: Bug report
about: Create a report to help us improve
title: ''
labels: ''
assignees: ''

---

## Describe the bug

<!-- A clear and concise description of what the bug is. -->

## To Reproduce

<!--
If you use spglib's Python API, please do not use ASE or Pymatgen's wrapper to make it easier to identify your problem.
The format for crystal structures is shown here: https://spglib.github.io/spglib/python-spglib.html#variables
If spglib returns different results by changing `symprec`, `angle_tolerance`, or `mag_symprec`, please report it too.
-->

## Expected behavior

<!-- A clear and concise description of what you expected to happen. -->

## Environment

- Python version:
- Spglib's version:

## Additional context

<!-- Add any other context about the problem here. -->
24 changes: 24 additions & 0 deletions .github/ISSUE_TEMPLATE/feature_request.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
---
name: Feature request
about: Suggest an idea for this project
title: ''
labels: ''
assignees: ''

---

## Is your feature request related to a problem? Please describe.

<!-- A clear and concise description of what the problem is. Ex. I'm always frustrated when [...] -->

## Describe the solution you'd like

<!-- A clear and concise description of what you want to happen. -->

## Describe alternatives you've considered

<!-- A clear and concise description of any alternative solutions or features you've considered. -->

## Additional context

<!-- Add any other context or screenshots about the feature request here. -->
11 changes: 11 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,17 @@ set(SOURCES ${PROJECT_SOURCE_DIR}/src/arithmetic.c
${PROJECT_SOURCE_DIR}/src/spin.c
${PROJECT_SOURCE_DIR}/src/symmetry.c)

# avoid One Definition Rule problems
# only available since 3.16.0
# VERSION_GREATER_EQUAL only available since 3.7.0, so let's do it manually
if (NOT CMAKE_MAJOR_VERSION LESS "3")
if (CMAKE_MAJOR_VERSION GREATER "3" OR NOT CMAKE_MINOR_VERSION LESS "16")
set_source_files_properties(
${SOURCES} PROPERTIES SKIP_UNITY_BUILD_INCLUSION ON
)
endif()
endif()

# Shared library
add_library(symspg SHARED ${SOURCES})

Expand Down
6 changes: 6 additions & 0 deletions admin.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
# Releasing a new Spglib version

1. Update <doc/releases.md>
2. Increment version at <src/version.h>
3. Push the commit to `rc` branch (Github actions publishes the package to TestPyPI automatically)
4. Push the commit to `master` branch (Github actions publishes the package to PyPI automatically)
4 changes: 2 additions & 2 deletions doc/magnetic_symmetry_flags.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,10 @@
- `tensor_rank=1`
- `with_time_reversal=true`: {math}`1' \circ \mathbf{m} = -\mathbf{m}`
- `is_axial=true`: {math}`(\mathbf{R}, \mathbf{v}) \circ \mathbf{m} = (\mathrm{det} \mathbf{R}) \mathbf{R} \mathbf{m}`
- `is_axial=true`: {math}`(\mathbf{R}, \mathbf{v}) \circ \mathbf{m} = \mathbf{R} \mathbf{m}`
- `is_axial=false`: {math}`(\mathbf{R}, \mathbf{v}) \circ \mathbf{m} = \mathbf{R} \mathbf{m}`
- `with_time_reversal=false`: {math}`1' \circ \mathbf{m} = \mathbf{m}`
- `is_axial=true`: {math}`(\mathbf{R}, \mathbf{v}) \circ \mathbf{m} = (\mathrm{det} \mathbf{R}) \mathbf{R} \mathbf{m}`
- `is_axial=true`: {math}`(\mathbf{R}, \mathbf{v}) \circ \mathbf{m} = \mathbf{R} \mathbf{m}`
- `is_axial=false`: {math}`(\mathbf{R}, \mathbf{v}) \circ \mathbf{m} = \mathbf{R} \mathbf{m}`

<!-- ### Correspondence
Expand Down
5 changes: 5 additions & 0 deletions doc/releases.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@

# Summary of releases

## V2.0.2 (6 Nov. 2022)

- Fix segmentation fault in `spgms_get_symmetry_with_site_tensors` with high symprec [[#195]](https://github.com/spglib/spglib/pull/195)
- Fix possible segmentation fault in `get_magnetic_dataset` with high symprec [[#196]](https://github.com/spglib/spglib/pull/196)

## V2.0.1 (31 Aug. 2022)

- Fix magnetic tolerance for judging type-II MSG (#187)
Expand Down
4 changes: 3 additions & 1 deletion python/pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,6 @@
requires = ["setuptools", "wheel", "numpy"]

[tool.cibuildwheel]
skip = ["pp*", "*-win32", "*-manylinux_i686"]
skip = ["pp*", "*-win32", "*-manylinux_i686", "*-musllinux*"]
manylinux-x86_64-image = "manylinux2014"
manylinux-aarch64-image = "manylinux2014"
2 changes: 1 addition & 1 deletion src/overlap.c
Original file line number Diff line number Diff line change
Expand Up @@ -641,7 +641,7 @@ static int check_total_overlap_for_sorted(
search_start = 0;
for (i_orig = 0; i_orig < num_pos; i_orig++) {
/* Permanently skip positions filled near the beginning. */
while (found[search_start]) {
while ((search_start < num_pos) && found[search_start]) {
search_start++;
}

Expand Down
13 changes: 10 additions & 3 deletions src/spglib.c
Original file line number Diff line number Diff line change
Expand Up @@ -1316,6 +1316,7 @@ static SpglibMagneticDataset *get_magnetic_dataset(
if (spglib_error_code == SPGLIB_SUCCESS) {
return dataset;
} else {
spg_free_magnetic_dataset(dataset);
return NULL;
}
}
Expand Down Expand Up @@ -1779,9 +1780,15 @@ static MagneticSymmetry *get_symmetry_with_site_tensors(
spg_free_dataset(dataset);
dataset = NULL;

magnetic_symmetry = spn_get_operations_with_site_tensors(
&equiv_atoms, permutations, primitive_lattice, sym_nonspin, cell,
with_time_reversal, is_axial, symprec, angle_tolerance, mag_symprec);
if ((magnetic_symmetry = spn_get_operations_with_site_tensors(
&equiv_atoms, permutations, primitive_lattice, sym_nonspin, cell,
with_time_reversal, is_axial, symprec, angle_tolerance,
mag_symprec)) == NULL) {
sym_free_symmetry(sym_nonspin);
sym_nonspin = NULL;
goto err;
}

/* Set equivalent_atoms */
for (i = 0; i < cell->size; i++) {
equivalent_atoms[i] = equiv_atoms[i];
Expand Down
17 changes: 11 additions & 6 deletions src/spin.c
Original file line number Diff line number Diff line change
Expand Up @@ -408,8 +408,13 @@ static MagneticSymmetry *get_operations(
}
}
if (k == cell->size) {
/* Unreachable here! */
return NULL;
// Unreachable here in theory, but we rarely fail to overlap
// atoms possibly due to too high symprec. In that case, skip
// the symmetry operation.
debug_print("Failed to overlap atom-%d by operation-%d\n", j,
i);
found = 0;
break;
}

// Skip if relevant tensors are zeros because they have nothing to
Expand Down Expand Up @@ -558,9 +563,9 @@ static MagneticSymmetry *get_operations(
return NULL;
}

/* Return permutation tables `permutations` such that the p-th operation */
/* in `magnetic_symmetry` maps site-`i` to site-`permutations[p * cell->size +
* i]`. */
// Return permutation tables `permutations` such that the p-th operation
// in `magnetic_symmetry` maps site-`i` to site-`permutations[p * cell->size +
// * i]`. If failed, return NULL.
static int *get_symmetry_permutations(const MagneticSymmetry *magnetic_symmetry,
const Cell *cell,
const int with_time_reversal,
Expand Down Expand Up @@ -655,7 +660,7 @@ static int *get_symmetry_permutations(const MagneticSymmetry *magnetic_symmetry,
return permutations;
}

/* Return equivalent_atoms */
// Return equivalent_atoms. If failed, return NULL.
static int *get_orbits(const int *permutations, const int num_sym,
const int num_atoms) {
int s, i;
Expand Down
2 changes: 1 addition & 1 deletion src/version.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,6 @@

#define SPGLIB_MAJOR_VERSION 2
#define SPGLIB_MINOR_VERSION 0
#define SPGLIB_MICRO_VERSION 1
#define SPGLIB_MICRO_VERSION 2

#endif
73 changes: 73 additions & 0 deletions test/test_magnetic_symmetry.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -360,6 +360,79 @@ TEST(
free(time_reversals);
}

TEST(
test_magnetic_symmetry,
test_with_broken_symmetry) {
// https://github.com/spglib/spglib/issues/194
// Part of "mp-806965" in the Materials Project database
double lattice[][3] = { // column-wise!
{5.24191, -0.003459, -2.618402},
{0, 5.600534, -1.87898},
{0, 0, 11.148141},
};
double positions[][3] = {
{0.829407, 0.834674, 0.662821},
{0.665078, 0.665214, 0.316142},
{0.001174, 0.996383, 0.002809},
{0.181127, 0.169218, 0.349259},
};
int types[] = {0, 0, 0, 0};
double tensors[] = {1.927, 1.947, 1.928, 1.949};
int num_atoms = 4;
int max_size = num_atoms * 96;

double symprec = 0.1; // with very high symprec
double mag_symprec = symprec;

int i, size;
int equivalent_atoms[4];
double primitive_lattice[3][3];
int(*rotations)[3][3];
double(*translations)[3];
int *spin_flips;
int *time_reversals;

rotations = (int(*)[3][3])malloc(sizeof(int[3][3]) * max_size);
translations = (double(*)[3])malloc(sizeof(double[3]) * max_size);
spin_flips = (int *)malloc(sizeof(int *) * max_size);
time_reversals = (int *)malloc(sizeof(int *) * max_size);

// Check magnetic symmetry search
// spg_get_symmetry returns four operations, but spgms_get_symmetry_with_site_tensors
// only returns three of them. This is due to too high symprec: detected operations
// in `sym_get_operation` follow `symprec`, but refined operations in
// `ref_get_exact_structure_and_symmetry` does not.
size = spgms_get_symmetry_with_site_tensors(
rotations, translations, equivalent_atoms, primitive_lattice, spin_flips,
max_size, lattice, positions, types, tensors,
0 /* tensor_rank */ , num_atoms,
1 /* with_time_reversal */,
0 /* is_axial */,
symprec, -1 /* angle_tolerance */, mag_symprec);

for (i = 0; i < size; i++) {
time_reversals[i] = (1 - spin_flips[i]) / 2;
}
show_magnetic_symmetry_operations(rotations, translations, time_reversals, size);
ASSERT_TRUE(size >= 1);

// Check magnetic dataset construction
// Since detected magnetic symmetry operations do not form a group due to high symprec,
// we fail to get magnetic dataset for now.
SpglibMagneticDataset *dataset;
dataset = spg_get_magnetic_dataset(lattice, positions, types, tensors,
0 /* tensor_rank */, num_atoms,
0 /* is_axial */, symprec);
ASSERT_TRUE(dataset == NULL);

free(rotations);
free(translations);
free(spin_flips);
free(time_reversals);
if (dataset != NULL) spg_free_magnetic_dataset(dataset);
free(dataset);
}

// TODO: test get_magnetic_dataset with distorted positions

// ****************************************************************************
Expand Down

0 comments on commit d426421

Please sign in to comment.