diffpy.structure 3.5.0rc0__tar.gz → 3.5.1__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (98) hide show
  1. {diffpy_structure-3.5.0rc0 → diffpy_structure-3.5.1}/PKG-INFO +1 -1
  2. {diffpy_structure-3.5.0rc0 → diffpy_structure-3.5.1}/src/diffpy/structure/parsers/p_cif.py +35 -1
  3. {diffpy_structure-3.5.0rc0 → diffpy_structure-3.5.1}/src/diffpy.structure.egg-info/PKG-INFO +1 -1
  4. {diffpy_structure-3.5.0rc0 → diffpy_structure-3.5.1}/tests/test_p_cif.py +108 -0
  5. {diffpy_structure-3.5.0rc0 → diffpy_structure-3.5.1}/AUTHORS.rst +0 -0
  6. {diffpy_structure-3.5.0rc0 → diffpy_structure-3.5.1}/LICENSE-DANSE.rst +0 -0
  7. {diffpy_structure-3.5.0rc0 → diffpy_structure-3.5.1}/LICENSE-pymmlib.rst +0 -0
  8. {diffpy_structure-3.5.0rc0 → diffpy_structure-3.5.1}/LICENSE.rst +0 -0
  9. {diffpy_structure-3.5.0rc0 → diffpy_structure-3.5.1}/MANIFEST.in +0 -0
  10. {diffpy_structure-3.5.0rc0 → diffpy_structure-3.5.1}/README.rst +0 -0
  11. {diffpy_structure-3.5.0rc0 → diffpy_structure-3.5.1}/pyproject.toml +0 -0
  12. {diffpy_structure-3.5.0rc0 → diffpy_structure-3.5.1}/requirements/build.txt +0 -0
  13. {diffpy_structure-3.5.0rc0 → diffpy_structure-3.5.1}/requirements/conda.txt +0 -0
  14. {diffpy_structure-3.5.0rc0 → diffpy_structure-3.5.1}/requirements/docs.txt +0 -0
  15. {diffpy_structure-3.5.0rc0 → diffpy_structure-3.5.1}/requirements/pip.txt +0 -0
  16. {diffpy_structure-3.5.0rc0 → diffpy_structure-3.5.1}/requirements/tests.txt +0 -0
  17. {diffpy_structure-3.5.0rc0 → diffpy_structure-3.5.1}/setup.cfg +0 -0
  18. {diffpy_structure-3.5.0rc0 → diffpy_structure-3.5.1}/src/diffpy/__init__.py +0 -0
  19. {diffpy_structure-3.5.0rc0 → diffpy_structure-3.5.1}/src/diffpy/structure/__init__.py +0 -0
  20. {diffpy_structure-3.5.0rc0 → diffpy_structure-3.5.1}/src/diffpy/structure/_legacy_importer.py +0 -0
  21. {diffpy_structure-3.5.0rc0 → diffpy_structure-3.5.1}/src/diffpy/structure/apps/__init__.py +0 -0
  22. {diffpy_structure-3.5.0rc0 → diffpy_structure-3.5.1}/src/diffpy/structure/apps/anyeye.py +0 -0
  23. {diffpy_structure-3.5.0rc0 → diffpy_structure-3.5.1}/src/diffpy/structure/apps/transtru.py +0 -0
  24. {diffpy_structure-3.5.0rc0 → diffpy_structure-3.5.1}/src/diffpy/structure/apps/vesta_viewer.py +0 -0
  25. {diffpy_structure-3.5.0rc0 → diffpy_structure-3.5.1}/src/diffpy/structure/atom.py +0 -0
  26. {diffpy_structure-3.5.0rc0 → diffpy_structure-3.5.1}/src/diffpy/structure/expansion/__init__.py +0 -0
  27. {diffpy_structure-3.5.0rc0 → diffpy_structure-3.5.1}/src/diffpy/structure/expansion/makeellipsoid.py +0 -0
  28. {diffpy_structure-3.5.0rc0 → diffpy_structure-3.5.1}/src/diffpy/structure/expansion/shapeutils.py +0 -0
  29. {diffpy_structure-3.5.0rc0 → diffpy_structure-3.5.1}/src/diffpy/structure/expansion/supercell_mod.py +0 -0
  30. {diffpy_structure-3.5.0rc0 → diffpy_structure-3.5.1}/src/diffpy/structure/lattice.py +0 -0
  31. {diffpy_structure-3.5.0rc0 → diffpy_structure-3.5.1}/src/diffpy/structure/mmlibspacegroups.py +0 -0
  32. {diffpy_structure-3.5.0rc0 → diffpy_structure-3.5.1}/src/diffpy/structure/parsers/__init__.py +0 -0
  33. {diffpy_structure-3.5.0rc0 → diffpy_structure-3.5.1}/src/diffpy/structure/parsers/p_auto.py +0 -0
  34. {diffpy_structure-3.5.0rc0 → diffpy_structure-3.5.1}/src/diffpy/structure/parsers/p_discus.py +0 -0
  35. {diffpy_structure-3.5.0rc0 → diffpy_structure-3.5.1}/src/diffpy/structure/parsers/p_pdb.py +0 -0
  36. {diffpy_structure-3.5.0rc0 → diffpy_structure-3.5.1}/src/diffpy/structure/parsers/p_pdffit.py +0 -0
  37. {diffpy_structure-3.5.0rc0 → diffpy_structure-3.5.1}/src/diffpy/structure/parsers/p_rawxyz.py +0 -0
  38. {diffpy_structure-3.5.0rc0 → diffpy_structure-3.5.1}/src/diffpy/structure/parsers/p_vesta.py +0 -0
  39. {diffpy_structure-3.5.0rc0 → diffpy_structure-3.5.1}/src/diffpy/structure/parsers/p_xcfg.py +0 -0
  40. {diffpy_structure-3.5.0rc0 → diffpy_structure-3.5.1}/src/diffpy/structure/parsers/p_xyz.py +0 -0
  41. {diffpy_structure-3.5.0rc0 → diffpy_structure-3.5.1}/src/diffpy/structure/parsers/parser_index_mod.py +0 -0
  42. {diffpy_structure-3.5.0rc0 → diffpy_structure-3.5.1}/src/diffpy/structure/parsers/structureparser.py +0 -0
  43. {diffpy_structure-3.5.0rc0 → diffpy_structure-3.5.1}/src/diffpy/structure/pdffitstructure.py +0 -0
  44. {diffpy_structure-3.5.0rc0 → diffpy_structure-3.5.1}/src/diffpy/structure/sgtbxspacegroups.py +0 -0
  45. {diffpy_structure-3.5.0rc0 → diffpy_structure-3.5.1}/src/diffpy/structure/spacegroupmod.py +0 -0
  46. {diffpy_structure-3.5.0rc0 → diffpy_structure-3.5.1}/src/diffpy/structure/spacegroups.py +0 -0
  47. {diffpy_structure-3.5.0rc0 → diffpy_structure-3.5.1}/src/diffpy/structure/structure.py +0 -0
  48. {diffpy_structure-3.5.0rc0 → diffpy_structure-3.5.1}/src/diffpy/structure/structure_app.py +0 -0
  49. {diffpy_structure-3.5.0rc0 → diffpy_structure-3.5.1}/src/diffpy/structure/structureerrors.py +0 -0
  50. {diffpy_structure-3.5.0rc0 → diffpy_structure-3.5.1}/src/diffpy/structure/symmetryutilities.py +0 -0
  51. {diffpy_structure-3.5.0rc0 → diffpy_structure-3.5.1}/src/diffpy/structure/utils.py +0 -0
  52. {diffpy_structure-3.5.0rc0 → diffpy_structure-3.5.1}/src/diffpy/structure/version.py +0 -0
  53. {diffpy_structure-3.5.0rc0 → diffpy_structure-3.5.1}/src/diffpy.structure.egg-info/SOURCES.txt +0 -0
  54. {diffpy_structure-3.5.0rc0 → diffpy_structure-3.5.1}/src/diffpy.structure.egg-info/dependency_links.txt +0 -0
  55. {diffpy_structure-3.5.0rc0 → diffpy_structure-3.5.1}/src/diffpy.structure.egg-info/entry_points.txt +0 -0
  56. {diffpy_structure-3.5.0rc0 → diffpy_structure-3.5.1}/src/diffpy.structure.egg-info/requires.txt +0 -0
  57. {diffpy_structure-3.5.0rc0 → diffpy_structure-3.5.1}/src/diffpy.structure.egg-info/top_level.txt +0 -0
  58. {diffpy_structure-3.5.0rc0 → diffpy_structure-3.5.1}/tests/conftest.py +0 -0
  59. {diffpy_structure-3.5.0rc0 → diffpy_structure-3.5.1}/tests/test_atom.py +0 -0
  60. {diffpy_structure-3.5.0rc0 → diffpy_structure-3.5.1}/tests/test_expansion.py +0 -0
  61. {diffpy_structure-3.5.0rc0 → diffpy_structure-3.5.1}/tests/test_lattice.py +0 -0
  62. {diffpy_structure-3.5.0rc0 → diffpy_structure-3.5.1}/tests/test_loadstructure.py +0 -0
  63. {diffpy_structure-3.5.0rc0 → diffpy_structure-3.5.1}/tests/test_p_discus.py +0 -0
  64. {diffpy_structure-3.5.0rc0 → diffpy_structure-3.5.1}/tests/test_p_pdffit.py +0 -0
  65. {diffpy_structure-3.5.0rc0 → diffpy_structure-3.5.1}/tests/test_parsers.py +0 -0
  66. {diffpy_structure-3.5.0rc0 → diffpy_structure-3.5.1}/tests/test_spacegroups.py +0 -0
  67. {diffpy_structure-3.5.0rc0 → diffpy_structure-3.5.1}/tests/test_structure.py +0 -0
  68. {diffpy_structure-3.5.0rc0 → diffpy_structure-3.5.1}/tests/test_supercell.py +0 -0
  69. {diffpy_structure-3.5.0rc0 → diffpy_structure-3.5.1}/tests/test_symmetryutilities.py +0 -0
  70. {diffpy_structure-3.5.0rc0 → diffpy_structure-3.5.1}/tests/test_utils.py +0 -0
  71. {diffpy_structure-3.5.0rc0 → diffpy_structure-3.5.1}/tests/test_version.py +0 -0
  72. {diffpy_structure-3.5.0rc0 → diffpy_structure-3.5.1}/tests/testdata/BubbleRaftShort.xcfg +0 -0
  73. {diffpy_structure-3.5.0rc0 → diffpy_structure-3.5.1}/tests/testdata/CdSe_bulk.stru +0 -0
  74. {diffpy_structure-3.5.0rc0 → diffpy_structure-3.5.1}/tests/testdata/LiCl-bad.cif +0 -0
  75. {diffpy_structure-3.5.0rc0 → diffpy_structure-3.5.1}/tests/testdata/Ni-bad.stru +0 -0
  76. {diffpy_structure-3.5.0rc0 → diffpy_structure-3.5.1}/tests/testdata/Ni-discus.stru +0 -0
  77. {diffpy_structure-3.5.0rc0 → diffpy_structure-3.5.1}/tests/testdata/Ni.stru +0 -0
  78. {diffpy_structure-3.5.0rc0 → diffpy_structure-3.5.1}/tests/testdata/Ni_prim123.stru +0 -0
  79. {diffpy_structure-3.5.0rc0 → diffpy_structure-3.5.1}/tests/testdata/Ni_ref.cif +0 -0
  80. {diffpy_structure-3.5.0rc0 → diffpy_structure-3.5.1}/tests/testdata/PbTe.cif +0 -0
  81. {diffpy_structure-3.5.0rc0 → diffpy_structure-3.5.1}/tests/testdata/TeI-unkocc.cif +0 -0
  82. {diffpy_structure-3.5.0rc0 → diffpy_structure-3.5.1}/tests/testdata/TeI.cif +0 -0
  83. {diffpy_structure-3.5.0rc0 → diffpy_structure-3.5.1}/tests/testdata/ZnSb_RT_Q28X_VM_20_fxiso.rstr +0 -0
  84. {diffpy_structure-3.5.0rc0 → diffpy_structure-3.5.1}/tests/testdata/arginine.pdb +0 -0
  85. {diffpy_structure-3.5.0rc0 → diffpy_structure-3.5.1}/tests/testdata/badspacegroup.cif +0 -0
  86. {diffpy_structure-3.5.0rc0 → diffpy_structure-3.5.1}/tests/testdata/bucky-bad1.xyz +0 -0
  87. {diffpy_structure-3.5.0rc0 → diffpy_structure-3.5.1}/tests/testdata/bucky-bad2.xyz +0 -0
  88. {diffpy_structure-3.5.0rc0 → diffpy_structure-3.5.1}/tests/testdata/bucky-plain-bad.xyz +0 -0
  89. {diffpy_structure-3.5.0rc0 → diffpy_structure-3.5.1}/tests/testdata/bucky-plain.xyz +0 -0
  90. {diffpy_structure-3.5.0rc0 → diffpy_structure-3.5.1}/tests/testdata/bucky-raw.xyz +0 -0
  91. {diffpy_structure-3.5.0rc0 → diffpy_structure-3.5.1}/tests/testdata/bucky.xyz +0 -0
  92. {diffpy_structure-3.5.0rc0 → diffpy_structure-3.5.1}/tests/testdata/curlybrackets.cif +0 -0
  93. {diffpy_structure-3.5.0rc0 → diffpy_structure-3.5.1}/tests/testdata/customsg.cif +0 -0
  94. {diffpy_structure-3.5.0rc0 → diffpy_structure-3.5.1}/tests/testdata/graphite.cif +0 -0
  95. {diffpy_structure-3.5.0rc0 → diffpy_structure-3.5.1}/tests/testdata/hexagon-raw-bad.xyz +0 -0
  96. {diffpy_structure-3.5.0rc0 → diffpy_structure-3.5.1}/tests/testdata/hexagon-raw.xy +0 -0
  97. {diffpy_structure-3.5.0rc0 → diffpy_structure-3.5.1}/tests/testdata/hexagon-raw.xyz +0 -0
  98. {diffpy_structure-3.5.0rc0 → diffpy_structure-3.5.1}/tests/testdata/nosites.cif +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: diffpy.structure
3
- Version: 3.5.0rc0
3
+ Version: 3.5.1
4
4
  Summary: Crystal structure container and parsers for structure formats.
5
5
  Author-email: Simon Billinge <sbillinge@ucsb.edu>
6
6
  Maintainer-email: Simon Billinge <sbillinge@ucsb.edu>
@@ -888,6 +888,35 @@ symvec["+y"] = symvec["y"]
888
888
  symvec["+z"] = symvec["z"]
889
889
 
890
890
 
891
+ _symop_number = r"(?:\d+\.?\d*|\.\d+)"
892
+ _symop_term = rf"{_symop_number}(?:/{_symop_number})?"
893
+ _rx_symop_translation = re.compile(rf"[+-]?{_symop_term}(?:[+-]{_symop_term})*")
894
+ _rx_symop_term = re.compile(rf"([+-]?)({_symop_number})(?:/({_symop_number}))?")
895
+
896
+
897
+ def _get_symop_translation(tpart, s):
898
+ # Sum the numeric terms in tpart without evaluating it as Python code.
899
+ # Only signed integers, decimals and fractions such as 1/2 are accepted.
900
+ emsg = (
901
+ f"Cannot read the symmetry operation {s!r} because {tpart!r} is not a number or a fraction. "
902
+ "Please correct the symmetry operations in the CIF file so that each one "
903
+ "looks like 'x,1/2-y,1/2+z' and try again."
904
+ )
905
+ if not tpart:
906
+ return 0.0
907
+ if not _rx_symop_translation.fullmatch(tpart):
908
+ raise StructureFormatError(emsg)
909
+ translation = 0.0
910
+ for sign, numerator, denominator in _rx_symop_term.findall(tpart):
911
+ value = float(numerator)
912
+ if denominator:
913
+ if float(denominator) == 0:
914
+ raise StructureFormatError(emsg)
915
+ value /= float(denominator)
916
+ translation += -value if sign == "-" else value
917
+ return translation
918
+
919
+
891
920
  @deprecated(getSymOp_deprecation_msg)
892
921
  def getSymOp(s):
893
922
  """This function has been deprecated and will be removed in version
@@ -910,6 +939,11 @@ def get_symop(s):
910
939
  -------
911
940
  SymOp
912
941
  Instance of `SymOp`.
942
+
943
+ Raises
944
+ ------
945
+ StructureFormatError
946
+ The translation part of the formula is not a number or a fraction.
913
947
  """
914
948
  from diffpy.structure.spacegroups import SymOp
915
949
 
@@ -922,7 +956,7 @@ def get_symop(s):
922
956
  for Rpart in eqparts[1::2]:
923
957
  R[i, :] += symvec[Rpart.lower()]
924
958
  for tpart in eqparts[::2]:
925
- t[i] += eval("1.0*%s+0" % tpart)
959
+ t[i] += _get_symop_translation(tpart, s)
926
960
  t -= numpy.floor(t)
927
961
  rv = SymOp(R, t)
928
962
  return rv
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: diffpy.structure
3
- Version: 3.5.0rc0
3
+ Version: 3.5.1
4
4
  Summary: Crystal structure container and parsers for structure formats.
5
5
  Author-email: Simon Billinge <sbillinge@ucsb.edu>
6
6
  Maintainer-email: Simon Billinge <sbillinge@ucsb.edu>
@@ -15,6 +15,7 @@
15
15
  """Unit tests for diffpy.structure.parsers.p_cif module."""
16
16
 
17
17
  import unittest
18
+ from pathlib import Path
18
19
 
19
20
  import numpy
20
21
  import pytest
@@ -496,6 +497,113 @@ class TestP_cif(unittest.TestCase):
496
497
 
497
498
  # End of class TestP_cif
498
499
 
500
+
501
+ # Test that get_symop reads the rotation and translation of a symmetry
502
+ # operation formula.
503
+ # C1: fraction before and after the coordinate, expect the fractions as
504
+ # translations
505
+ # C2: mixed coordinates in one component, expect off-diagonal rotation
506
+ # C3: decimal translations with and without leading zero, expect the same
507
+ # values as floats
508
+ # C4: blanks, upper case and explicit plus signs, expect them to be ignored
509
+ # C5: negative translations, expect them wrapped into the unit cell
510
+ # C6: several numeric terms in one component, expect their sum
511
+ @pytest.mark.parametrize(
512
+ "symop_string, expected_rotation, expected_translation",
513
+ [
514
+ pytest.param(
515
+ "x,1/2-y,1/2+z",
516
+ [[1, 0, 0], [0, -1, 0], [0, 0, 1]],
517
+ [0, 0.5, 0.5],
518
+ id="fractions",
519
+ ),
520
+ pytest.param(
521
+ "-x,-x+y,z+1/2",
522
+ [[-1, 0, 0], [-1, 1, 0], [0, 0, 1]],
523
+ [0, 0, 0.5],
524
+ id="mixed-coordinates",
525
+ ),
526
+ pytest.param(
527
+ "x+0.25,y+.5,z+1.",
528
+ [[1, 0, 0], [0, 1, 0], [0, 0, 1]],
529
+ [0.25, 0.5, 0],
530
+ id="decimals",
531
+ ),
532
+ pytest.param(
533
+ " +X, +1/4 + Y, -Z ",
534
+ [[1, 0, 0], [0, 1, 0], [0, 0, -1]],
535
+ [0, 0.25, 0],
536
+ id="blanks-case-plus-signs",
537
+ ),
538
+ pytest.param(
539
+ "x-1/4,-3/4+y,z",
540
+ [[1, 0, 0], [0, 1, 0], [0, 0, 1]],
541
+ [0.75, 0.25, 0],
542
+ id="negative-translations",
543
+ ),
544
+ pytest.param(
545
+ "1/2+x+1/4,y,z",
546
+ [[1, 0, 0], [0, 1, 0], [0, 0, 1]],
547
+ [0.75, 0, 0],
548
+ id="several-numeric-terms",
549
+ ),
550
+ ],
551
+ )
552
+ def test_get_symop_values(symop_string, expected_rotation, expected_translation):
553
+ actual_symop = get_symop(symop_string)
554
+ numpy.testing.assert_allclose(actual_symop.R, expected_rotation)
555
+ numpy.testing.assert_allclose(actual_symop.t, expected_translation)
556
+
557
+
558
+ # Test that get_symop rejects translations that are not plain numbers
559
+ # instead of evaluating them as Python code.
560
+ # C1: Python call in a component, expect StructureFormatError and no
561
+ # code execution
562
+ # C2: arithmetic that is not a sum of numbers, expect StructureFormatError
563
+ # C3: letters other than the coordinates, expect StructureFormatError
564
+ # C4: fraction with zero denominator, expect StructureFormatError
565
+ # The code avoids blanks, commas and the letters of the coordinates so
566
+ # that it would be executed if the formula were evaluated.
567
+ symop_code = "__import__('builtins').__dict__.update(_cif_pwned=1)"
568
+
569
+
570
+ @pytest.mark.parametrize(
571
+ "symop_string",
572
+ [
573
+ pytest.param(f"x,y,{symop_code}", id="python-call"),
574
+ pytest.param("x,2**8+y,z", id="non-sum-arithmetic"),
575
+ pytest.param("x,y,z+a", id="unknown-letter"),
576
+ pytest.param("x,y+1/0,z", id="zero-denominator"),
577
+ ],
578
+ )
579
+ def test_get_symop_bad(symop_string, monkeypatch):
580
+ import builtins
581
+
582
+ monkeypatch.delattr(builtins, "_cif_pwned", raising=False)
583
+ try:
584
+ with pytest.raises(StructureFormatError, match="Cannot read the symmetry operation"):
585
+ get_symop(symop_string)
586
+ assert not hasattr(builtins, "_cif_pwned")
587
+ finally:
588
+ vars(builtins).pop("_cif_pwned", None)
589
+
590
+
591
+ def test_parse_cif_does_not_execute_symop(datafile, tmp_path):
592
+ """Check that code in a CIF symmetry operation is never executed."""
593
+ import builtins
594
+
595
+ cif_text = Path(datafile("graphite.cif")).read_text()
596
+ assert "'x,y,z'" in cif_text
597
+ bad_cif = tmp_path / "bad.cif"
598
+ bad_cif.write_text(cif_text.replace("'x,y,z'", f'"x,y,z+{symop_code}"', 1))
599
+ try:
600
+ with pytest.raises(StructureFormatError):
601
+ get_parser("cif").parse_file(str(bad_cif))
602
+ assert not hasattr(builtins, "_cif_pwned")
603
+ finally:
604
+ vars(builtins).pop("_cif_pwned", None)
605
+
606
+
499
607
  # ----------------------------------------------------------------------------
500
608
 
501
609
  if __name__ == "__main__":