diffpy.structure 3.2.1rc1__tar.gz → 3.2.2rc0__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 (64) hide show
  1. {diffpy_structure-3.2.1rc1 → diffpy_structure-3.2.2rc0}/PKG-INFO +2 -2
  2. {diffpy_structure-3.2.1rc1 → diffpy_structure-3.2.2rc0}/pyproject.toml +2 -2
  3. diffpy_structure-3.2.2rc0/requirements/run.txt +2 -0
  4. {diffpy_structure-3.2.1rc1 → diffpy_structure-3.2.2rc0}/src/diffpy/structure/atom.py +1 -1
  5. {diffpy_structure-3.2.1rc1 → diffpy_structure-3.2.2rc0}/src/diffpy/structure/structure.py +6 -4
  6. {diffpy_structure-3.2.1rc1 → diffpy_structure-3.2.2rc0}/src/diffpy.structure.egg-info/PKG-INFO +2 -2
  7. {diffpy_structure-3.2.1rc1 → diffpy_structure-3.2.2rc0}/src/diffpy.structure.egg-info/SOURCES.txt +14 -1
  8. diffpy_structure-3.2.2rc0/src/diffpy.structure.egg-info/requires.txt +2 -0
  9. diffpy_structure-3.2.2rc0/tests/test_atom.py +155 -0
  10. diffpy_structure-3.2.2rc0/tests/test_lattice.py +261 -0
  11. diffpy_structure-3.2.2rc0/tests/test_loadstructure.py +68 -0
  12. diffpy_structure-3.2.2rc0/tests/test_oldimports.py +77 -0
  13. diffpy_structure-3.2.2rc0/tests/test_p_cif.py +390 -0
  14. diffpy_structure-3.2.2rc0/tests/test_p_discus.py +151 -0
  15. diffpy_structure-3.2.2rc0/tests/test_p_pdffit.py +246 -0
  16. diffpy_structure-3.2.2rc0/tests/test_parsers.py +340 -0
  17. diffpy_structure-3.2.2rc0/tests/test_spacegroups.py +129 -0
  18. diffpy_structure-3.2.2rc0/tests/test_structure.py +605 -0
  19. diffpy_structure-3.2.2rc0/tests/test_supercell.py +91 -0
  20. diffpy_structure-3.2.2rc0/tests/test_symmetryutilities.py +511 -0
  21. diffpy_structure-3.2.2rc0/tests/test_version.py +10 -0
  22. diffpy_structure-3.2.1rc1/requirements/run.txt +0 -2
  23. diffpy_structure-3.2.1rc1/src/diffpy.structure.egg-info/requires.txt +0 -2
  24. {diffpy_structure-3.2.1rc1 → diffpy_structure-3.2.2rc0}/AUTHORS.rst +0 -0
  25. {diffpy_structure-3.2.1rc1 → diffpy_structure-3.2.2rc0}/LICENSE.rst +0 -0
  26. {diffpy_structure-3.2.1rc1 → diffpy_structure-3.2.2rc0}/LICENSE_DANSE.rst +0 -0
  27. {diffpy_structure-3.2.1rc1 → diffpy_structure-3.2.2rc0}/LICENSE_pymmlib.rst +0 -0
  28. {diffpy_structure-3.2.1rc1 → diffpy_structure-3.2.2rc0}/MANIFEST.in +0 -0
  29. {diffpy_structure-3.2.1rc1 → diffpy_structure-3.2.2rc0}/README.rst +0 -0
  30. {diffpy_structure-3.2.1rc1 → diffpy_structure-3.2.2rc0}/setup.cfg +0 -0
  31. {diffpy_structure-3.2.1rc1 → diffpy_structure-3.2.2rc0}/src/diffpy/Structure.py +0 -0
  32. {diffpy_structure-3.2.1rc1 → diffpy_structure-3.2.2rc0}/src/diffpy/__init__.py +0 -0
  33. {diffpy_structure-3.2.1rc1 → diffpy_structure-3.2.2rc0}/src/diffpy/structure/__init__.py +0 -0
  34. {diffpy_structure-3.2.1rc1 → diffpy_structure-3.2.2rc0}/src/diffpy/structure/_legacy_importer.py +0 -0
  35. {diffpy_structure-3.2.1rc1 → diffpy_structure-3.2.2rc0}/src/diffpy/structure/apps/__init__.py +0 -0
  36. {diffpy_structure-3.2.1rc1 → diffpy_structure-3.2.2rc0}/src/diffpy/structure/apps/anyeye.py +0 -0
  37. {diffpy_structure-3.2.1rc1 → diffpy_structure-3.2.2rc0}/src/diffpy/structure/apps/transtru.py +0 -0
  38. {diffpy_structure-3.2.1rc1 → diffpy_structure-3.2.2rc0}/src/diffpy/structure/expansion/__init__.py +0 -0
  39. {diffpy_structure-3.2.1rc1 → diffpy_structure-3.2.2rc0}/src/diffpy/structure/expansion/makeellipsoid.py +0 -0
  40. {diffpy_structure-3.2.1rc1 → diffpy_structure-3.2.2rc0}/src/diffpy/structure/expansion/shapeutils.py +0 -0
  41. {diffpy_structure-3.2.1rc1 → diffpy_structure-3.2.2rc0}/src/diffpy/structure/expansion/supercell_mod.py +0 -0
  42. {diffpy_structure-3.2.1rc1 → diffpy_structure-3.2.2rc0}/src/diffpy/structure/lattice.py +0 -0
  43. {diffpy_structure-3.2.1rc1 → diffpy_structure-3.2.2rc0}/src/diffpy/structure/mmlibspacegroups.py +0 -0
  44. {diffpy_structure-3.2.1rc1 → diffpy_structure-3.2.2rc0}/src/diffpy/structure/parsers/__init__.py +0 -0
  45. {diffpy_structure-3.2.1rc1 → diffpy_structure-3.2.2rc0}/src/diffpy/structure/parsers/p_auto.py +0 -0
  46. {diffpy_structure-3.2.1rc1 → diffpy_structure-3.2.2rc0}/src/diffpy/structure/parsers/p_cif.py +0 -0
  47. {diffpy_structure-3.2.1rc1 → diffpy_structure-3.2.2rc0}/src/diffpy/structure/parsers/p_discus.py +0 -0
  48. {diffpy_structure-3.2.1rc1 → diffpy_structure-3.2.2rc0}/src/diffpy/structure/parsers/p_pdb.py +0 -0
  49. {diffpy_structure-3.2.1rc1 → diffpy_structure-3.2.2rc0}/src/diffpy/structure/parsers/p_pdffit.py +0 -0
  50. {diffpy_structure-3.2.1rc1 → diffpy_structure-3.2.2rc0}/src/diffpy/structure/parsers/p_rawxyz.py +0 -0
  51. {diffpy_structure-3.2.1rc1 → diffpy_structure-3.2.2rc0}/src/diffpy/structure/parsers/p_xcfg.py +0 -0
  52. {diffpy_structure-3.2.1rc1 → diffpy_structure-3.2.2rc0}/src/diffpy/structure/parsers/p_xyz.py +0 -0
  53. {diffpy_structure-3.2.1rc1 → diffpy_structure-3.2.2rc0}/src/diffpy/structure/parsers/parser_index_mod.py +0 -0
  54. {diffpy_structure-3.2.1rc1 → diffpy_structure-3.2.2rc0}/src/diffpy/structure/parsers/structureparser.py +0 -0
  55. {diffpy_structure-3.2.1rc1 → diffpy_structure-3.2.2rc0}/src/diffpy/structure/pdffitstructure.py +0 -0
  56. {diffpy_structure-3.2.1rc1 → diffpy_structure-3.2.2rc0}/src/diffpy/structure/sgtbxspacegroups.py +0 -0
  57. {diffpy_structure-3.2.1rc1 → diffpy_structure-3.2.2rc0}/src/diffpy/structure/spacegroupmod.py +0 -0
  58. {diffpy_structure-3.2.1rc1 → diffpy_structure-3.2.2rc0}/src/diffpy/structure/spacegroups.py +0 -0
  59. {diffpy_structure-3.2.1rc1 → diffpy_structure-3.2.2rc0}/src/diffpy/structure/structureerrors.py +0 -0
  60. {diffpy_structure-3.2.1rc1 → diffpy_structure-3.2.2rc0}/src/diffpy/structure/symmetryutilities.py +0 -0
  61. {diffpy_structure-3.2.1rc1 → diffpy_structure-3.2.2rc0}/src/diffpy/structure/utils.py +0 -0
  62. {diffpy_structure-3.2.1rc1 → diffpy_structure-3.2.2rc0}/src/diffpy/structure/version.py +0 -0
  63. {diffpy_structure-3.2.1rc1 → diffpy_structure-3.2.2rc0}/src/diffpy.structure.egg-info/dependency_links.txt +0 -0
  64. {diffpy_structure-3.2.1rc1 → diffpy_structure-3.2.2rc0}/src/diffpy.structure.egg-info/top_level.txt +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: diffpy.structure
3
- Version: 3.2.1rc1
3
+ Version: 3.2.2rc0
4
4
  Summary: Crystal structure container and parsers for structure formats.
5
5
  Author-email: "Simon J.L. Billinge group" <simon.billinge@gmail.com>
6
6
  Maintainer-email: "Simon J.L. Billinge group" <simon.billinge@gmail.com>
@@ -27,7 +27,7 @@ License-File: LICENSE.rst
27
27
  License-File: LICENSE_DANSE.rst
28
28
  License-File: LICENSE_pymmlib.rst
29
29
  License-File: AUTHORS.rst
30
- Requires-Dist: numpy<2.0.0
30
+ Requires-Dist: numpy
31
31
  Requires-Dist: pycifrw
32
32
 
33
33
  |Icon| |title|_
@@ -1,5 +1,5 @@
1
1
  [build-system]
2
- requires = ["setuptools>=62.0", "setuptools-git-versioning<2"]
2
+ requires = ["setuptools>=62.0", "setuptools-git-versioning>=2.0"]
3
3
  build-backend = "setuptools.build_meta"
4
4
 
5
5
  [project]
@@ -45,7 +45,7 @@ dirty_template = "{tag}"
45
45
  [tool.setuptools.packages.find]
46
46
  where = ["src"] # list of folders that contain the packages (["."] by default)
47
47
  include = ["*"] # package names should match these glob patterns (["*"] by default)
48
- exclude = ["diffpy.structure.tests*"] # exclude packages matching these glob patterns (empty by default)
48
+ exclude = [] # exclude packages matching these glob patterns (empty by default)
49
49
  namespaces = false # to disable scanning PEP 420 namespaces (true by default)
50
50
 
51
51
  [tool.setuptools.dynamic]
@@ -0,0 +1,2 @@
1
+ numpy
2
+ pycifrw
@@ -536,7 +536,7 @@ class _AtomCartesianCoordinates(numpy.ndarray):
536
536
  self._atom.xyz[:] = self._atom.lattice.fractional(self)
537
537
  return
538
538
 
539
- def __array_wrap__(self, out_arr, context=None):
539
+ def __array_wrap__(self, out_arr, context=None, return_scalar=None):
540
540
  """Ensure math operations on this type yield standard numpy array."""
541
541
  return out_arr.view(numpy.ndarray)
542
542
 
@@ -711,8 +711,9 @@ class Structure(list):
711
711
  element = _linkAtomAttribute(
712
712
  "element",
713
713
  """Character array of `Atom` types. Assignment updates
714
- the element attribute of the respective `Atoms`.""",
715
- toarray=numpy.char.array,
714
+ the element attribute of the respective `Atoms`.
715
+ Set the maximum length of the element string to 5 characters.""",
716
+ toarray=lambda items: numpy.char.array(items, itemsize=5),
716
717
  )
717
718
 
718
719
  xyz = _linkAtomAttribute(
@@ -742,8 +743,9 @@ class Structure(list):
742
743
  label = _linkAtomAttribute(
743
744
  "label",
744
745
  """Character array of `Atom` names. Assignment updates
745
- the label attribute of all `Atoms`.""",
746
- toarray=numpy.char.array,
746
+ the label attribute of all `Atoms`.
747
+ Set the maximum length of the label string to 5 characters.""",
748
+ toarray=lambda items: numpy.char.array(items, itemsize=5),
747
749
  )
748
750
 
749
751
  occupancy = _linkAtomAttribute(
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: diffpy.structure
3
- Version: 3.2.1rc1
3
+ Version: 3.2.2rc0
4
4
  Summary: Crystal structure container and parsers for structure formats.
5
5
  Author-email: "Simon J.L. Billinge group" <simon.billinge@gmail.com>
6
6
  Maintainer-email: "Simon J.L. Billinge group" <simon.billinge@gmail.com>
@@ -27,7 +27,7 @@ License-File: LICENSE.rst
27
27
  License-File: LICENSE_DANSE.rst
28
28
  License-File: LICENSE_pymmlib.rst
29
29
  License-File: AUTHORS.rst
30
- Requires-Dist: numpy<2.0.0
30
+ Requires-Dist: numpy
31
31
  Requires-Dist: pycifrw
32
32
 
33
33
  |Icon| |title|_
@@ -44,4 +44,17 @@ src/diffpy/structure/parsers/p_rawxyz.py
44
44
  src/diffpy/structure/parsers/p_xcfg.py
45
45
  src/diffpy/structure/parsers/p_xyz.py
46
46
  src/diffpy/structure/parsers/parser_index_mod.py
47
- src/diffpy/structure/parsers/structureparser.py
47
+ src/diffpy/structure/parsers/structureparser.py
48
+ tests/test_atom.py
49
+ tests/test_lattice.py
50
+ tests/test_loadstructure.py
51
+ tests/test_oldimports.py
52
+ tests/test_p_cif.py
53
+ tests/test_p_discus.py
54
+ tests/test_p_pdffit.py
55
+ tests/test_parsers.py
56
+ tests/test_spacegroups.py
57
+ tests/test_structure.py
58
+ tests/test_supercell.py
59
+ tests/test_symmetryutilities.py
60
+ tests/test_version.py
@@ -0,0 +1,155 @@
1
+ #!/usr/bin/env python
2
+ ##############################################################################
3
+ #
4
+ # diffpy.structure Complex Modeling Initiative
5
+ # (c) 2016 Brookhaven Science Associates,
6
+ # Brookhaven National Laboratory.
7
+ # All rights reserved.
8
+ #
9
+ # File coded by: Pavol Juhas
10
+ #
11
+ # See AUTHORS.txt for a list of people who contributed.
12
+ # See LICENSE.txt for license information.
13
+ #
14
+ ##############################################################################
15
+
16
+ """
17
+ Unit tests for the Atom class.
18
+ """
19
+
20
+
21
+ import unittest
22
+
23
+ import numpy
24
+
25
+ from diffpy.structure.atom import Atom
26
+ from diffpy.structure.lattice import Lattice
27
+
28
+ # ----------------------------------------------------------------------------
29
+
30
+
31
+ class TestAtom(unittest.TestCase):
32
+
33
+ def test___init__(self):
34
+ """check Atom.__init__()"""
35
+ a = Atom()
36
+ self.assertEqual("", a.element)
37
+ self.assertTrue((a.xyz == 0).all())
38
+ self.assertEqual("", a.label)
39
+ self.assertEqual(1.0, a.occupancy)
40
+ self.assertFalse(a.anisotropy)
41
+ self.assertTrue((a.U == 0).all())
42
+ self.assertTrue(a.lattice is None)
43
+ # check initialization with arguments
44
+ a1 = Atom("C", xyz=(1, 2, 3), Uisoequiv=0.005)
45
+ self.assertEqual("C", a1.element)
46
+ self.assertTrue(numpy.array_equal([1, 2, 3], a1.xyz))
47
+ self.assertFalse(a1.anisotropy)
48
+ self.assertEqual(0.005, a1.Uisoequiv)
49
+ # initialize with anisotropic displacement parameters
50
+ uani = numpy.identity(3, dtype=float) * numpy.array([1, 2, 3]) * 0.01
51
+ a2 = Atom("C", U=uani)
52
+ self.assertTrue(numpy.array_equal(uani, a2.U))
53
+ self.assertTrue(a2.anisotropy)
54
+ a3 = Atom("C", Uisoequiv=0.02, anisotropy=True)
55
+ self.assertTrue(a3.anisotropy)
56
+ self.assertEqual(a3.U[2, 2], 0.02)
57
+ self.assertRaises(ValueError, Atom, "C", Uisoequiv=0.02, U=uani)
58
+ return
59
+
60
+ # def test_msdLat(self):
61
+ # """check Atom.msdLat()
62
+ # """
63
+ # return
64
+ #
65
+ # def test_msdCart(self):
66
+ # """check Atom.msdCart()
67
+ # """
68
+ # return
69
+ #
70
+ # def test___repr__(self):
71
+ # """check Atom.__repr__()
72
+ # """
73
+ # return
74
+ #
75
+ # def test___copy__(self):
76
+ # """check Atom.__copy__()
77
+ # """
78
+ # return
79
+
80
+ def test_xyz_cartn(self):
81
+ """check Atom.xyz_cartn property"""
82
+ hexagonal = Lattice(1, 1, 1, 90, 90, 120)
83
+ a0 = Atom("C", [0, 0, 0], lattice=hexagonal)
84
+ a1 = Atom("C", [1, 1, 1], lattice=hexagonal)
85
+ self.assertTrue(all(a0.xyz_cartn == 0))
86
+ rc1 = numpy.array([0.75**0.5, 0.5, 1])
87
+ self.assertTrue(numpy.allclose(rc1, a1.xyz_cartn))
88
+ a1.xyz_cartn[2] = 0
89
+ self.assertTrue(numpy.allclose([1, 1, 0], a1.xyz))
90
+ a1.xyz_cartn[:2] = 0
91
+ self.assertTrue(all(a1.xyz == 0))
92
+ a3 = Atom("C", [1, 2, 3])
93
+ self.assertTrue(numpy.array_equal(a3.xyz, a3.xyz_cartn))
94
+ a3.xyz_cartn = 1.3
95
+ self.assertTrue(all(1.3 == a3.xyz_cartn))
96
+ self.assertTrue(all(1.3 == a3.xyz))
97
+ return
98
+
99
+
100
+ # def test__get_anisotropy(self):
101
+ # """check Atom._get_anisotropy()
102
+ # """
103
+ # return
104
+ #
105
+ # def test__set_anisotropy(self):
106
+ # """check Atom._set_anisotropy()
107
+ # """
108
+ # return
109
+ #
110
+ # def test__get_U(self):
111
+ # """check Atom._get_U()
112
+ # """
113
+ # return
114
+ #
115
+ # def test__set_U(self):
116
+ # """check Atom._set_U()
117
+ # """
118
+ # return
119
+ #
120
+ # def test__get_Uij(self):
121
+ # """check Atom._get_Uij()
122
+ # """
123
+ # return
124
+ #
125
+ # def test__set_Uij(self):
126
+ # """check Atom._set_Uij()
127
+ # """
128
+ # return
129
+ #
130
+ # def test__get_Uisoequiv(self):
131
+ # """check Atom._get_Uisoequiv()
132
+ # """
133
+ # return
134
+ #
135
+ # def test__set_Uisoequiv(self):
136
+ # """check Atom._set_Uisoequiv()
137
+ # """
138
+ # return
139
+ #
140
+ # def test__get_Bisoequiv(self):
141
+ # """check Atom._get_Bisoequiv()
142
+ # """
143
+ # return
144
+ #
145
+ # def test__set_Bisoequiv(self):
146
+ # """check Atom._set_Bisoequiv()
147
+ # """
148
+ # return
149
+
150
+ # End of class TestAtom
151
+
152
+ # ----------------------------------------------------------------------------
153
+
154
+ if __name__ == "__main__":
155
+ unittest.main()
@@ -0,0 +1,261 @@
1
+ #!/usr/bin/env python
2
+ ##############################################################################
3
+ #
4
+ # diffpy.structure by DANSE Diffraction group
5
+ # Simon J. L. Billinge
6
+ # (c) 2006 trustees of the Michigan State University.
7
+ # All rights reserved.
8
+ #
9
+ # File coded by: Pavol Juhas
10
+ #
11
+ # See AUTHORS.txt for a list of people who contributed.
12
+ # See LICENSE_DANSE.txt for license information.
13
+ #
14
+ ##############################################################################
15
+
16
+ """Unit tests for Lattice class.
17
+ """
18
+
19
+ import unittest
20
+
21
+ import numpy
22
+ import numpy.linalg as numalg
23
+
24
+ from diffpy.structure import Lattice, LatticeError
25
+
26
+ # ----------------------------------------------------------------------------
27
+
28
+
29
+ class TestLattice(unittest.TestCase):
30
+ """test methods of Lattice class"""
31
+
32
+ def setUp(self):
33
+ self.lattice = Lattice()
34
+ self.places = 12
35
+ return
36
+
37
+ def test___init__(self):
38
+ """Check Lattice.__init__ processing of arguments."""
39
+ self.assertRaises(ValueError, Lattice, self.lattice, c=4)
40
+ self.assertRaises(ValueError, Lattice, base=self.lattice.base, baserot=self.lattice.baserot)
41
+ self.assertRaises(ValueError, Lattice, 1, 2, 3)
42
+ self.assertRaises(ValueError, Lattice, 1, 2, 3, 80, 90)
43
+ L0 = self.lattice
44
+ L0.setLatBase(L0.cartesian([[1, 1, 0], [0, 1, 1], [1, 0, 1]]))
45
+ L1 = Lattice(L0)
46
+ self.assertTrue(numpy.array_equal(L0.base, L1.base))
47
+ L2 = Lattice(base=L0.base)
48
+ self.assertTrue(numpy.array_equal(L0.base, L2.base))
49
+ self.assertTrue(numpy.array_equal(L0.isotropicunit, L2.isotropicunit))
50
+ L3 = Lattice(*L0.abcABG(), baserot=L0.baserot)
51
+ self.assertTrue(numpy.allclose(L0.base, L3.base))
52
+ self.assertTrue(numpy.allclose(L0.isotropicunit, L3.isotropicunit))
53
+ return
54
+
55
+ def test_setLatPar(self):
56
+ """check calculation of standard unit cell vectors"""
57
+ from math import cos, radians, sqrt
58
+
59
+ from numpy import dot
60
+
61
+ def norm(x):
62
+ return sqrt(sum([xi**2 for xi in x]))
63
+
64
+ def cosd(x):
65
+ return cos(radians(x))
66
+
67
+ self.lattice.setLatPar(1.0, 2.0, 3.0, 80, 100, 120)
68
+ base = self.lattice.base
69
+ self.assertAlmostEqual(1.0, norm(base[0]), self.places)
70
+ self.assertAlmostEqual(2.0, norm(base[1]), self.places)
71
+ self.assertAlmostEqual(3.0, norm(base[2]), self.places)
72
+ self.assertAlmostEqual(cosd(80.0), dot(base[1], base[2]) / (2 * 3), self.places)
73
+ self.assertAlmostEqual(cosd(100.0), dot(base[0], base[2]) / (1 * 3), self.places)
74
+ self.assertAlmostEqual(cosd(120.0), dot(base[0], base[1]) / (1 * 2), self.places)
75
+ return
76
+
77
+ def test_latpar_properties(self):
78
+ """check assignment to a, b, c, alpha, beta, gamma."""
79
+ lat = self.lattice
80
+ lat.a = 2
81
+ lat.b = 4
82
+ lat.c = 6
83
+ lat.alpha = 80
84
+ lat.beta = 100
85
+ lat.gamma = 120
86
+ lat1 = Lattice(2, 4, 6, 80, 100, 120)
87
+ self.assertAlmostEqual(-0.5, lat.cg, self.places)
88
+ self.assertTrue(numpy.array_equal(lat1.base, lat.base))
89
+ return
90
+
91
+ def test_readonly_properties(self):
92
+ """Check that read-only properties are indeed such."""
93
+ lat = self.lattice
94
+ lat.b = 2
95
+ lat.c = 6
96
+ self.assertEqual(1.0, lat.unitvolume)
97
+ self.assertRaises(AttributeError, setattr, lat, "unitvolume", 3.33)
98
+ self.assertEqual(12, lat.volume)
99
+ self.assertRaises(AttributeError, setattr, lat, "volume", 3.33)
100
+ self.assertEqual(0.0, lat.ca)
101
+ self.assertRaises(AttributeError, setattr, lat, "ca", 3.33)
102
+ self.assertEqual(0.0, lat.cb)
103
+ self.assertRaises(AttributeError, setattr, lat, "cb", 3.33)
104
+ self.assertEqual(0.0, lat.cg)
105
+ self.assertRaises(AttributeError, setattr, lat, "cg", 3.33)
106
+ self.assertEqual(1.0, lat.sa)
107
+ self.assertRaises(AttributeError, setattr, lat, "sa", 3.33)
108
+ self.assertEqual(1.0, lat.sb)
109
+ self.assertRaises(AttributeError, setattr, lat, "sb", 3.33)
110
+ self.assertEqual(1.0, lat.sg)
111
+ self.assertRaises(AttributeError, setattr, lat, "sg", 3.33)
112
+ self.assertEqual(1.0, lat.ar)
113
+ self.assertRaises(AttributeError, setattr, lat, "ar", 3.33)
114
+ self.assertEqual(0.5, lat.br)
115
+ self.assertRaises(AttributeError, setattr, lat, "br", 3.33)
116
+ self.assertAlmostEqual(1.0 / 6, lat.cr, self.places)
117
+ self.assertRaises(AttributeError, setattr, lat, "cr", 3.33)
118
+ self.assertEqual(90.0, lat.alphar)
119
+ self.assertRaises(AttributeError, setattr, lat, "alphar", 3.33)
120
+ self.assertEqual(90.0, lat.betar)
121
+ self.assertRaises(AttributeError, setattr, lat, "betar", 3.33)
122
+ self.assertEqual(90.0, lat.gammar)
123
+ self.assertRaises(AttributeError, setattr, lat, "gammar", 3.33)
124
+ self.assertEqual(0.0, lat.car)
125
+ self.assertRaises(AttributeError, setattr, lat, "car", 3.33)
126
+ self.assertEqual(0.0, lat.cbr)
127
+ self.assertRaises(AttributeError, setattr, lat, "cbr", 3.33)
128
+ self.assertEqual(0.0, lat.cgr)
129
+ self.assertRaises(AttributeError, setattr, lat, "cgr", 3.33)
130
+ self.assertEqual(1.0, lat.sar)
131
+ self.assertRaises(AttributeError, setattr, lat, "sar", 3.33)
132
+ self.assertEqual(1.0, lat.sbr)
133
+ self.assertRaises(AttributeError, setattr, lat, "sbr", 3.33)
134
+ self.assertEqual(1.0, lat.sgr)
135
+ self.assertRaises(AttributeError, setattr, lat, "sgr", 3.33)
136
+ return
137
+
138
+ def test_setLatBase(self):
139
+ """check calculation of unit cell rotation"""
140
+ base = numpy.array([[1.0, 1.0, 0.0], [0.0, 1.0, 1.0], [1.0, 0.0, 1.0]])
141
+ self.lattice.setLatBase(base)
142
+ self.assertAlmostEqual(self.lattice.a, numpy.sqrt(2.0), self.places)
143
+ self.assertAlmostEqual(self.lattice.b, numpy.sqrt(2.0), self.places)
144
+ self.assertAlmostEqual(self.lattice.c, numpy.sqrt(2.0), self.places)
145
+ self.assertAlmostEqual(self.lattice.alpha, 60.0, self.places)
146
+ self.assertAlmostEqual(self.lattice.beta, 60.0, self.places)
147
+ self.assertAlmostEqual(self.lattice.gamma, 60.0, self.places)
148
+ detR0 = numalg.det(self.lattice.baserot)
149
+ self.assertAlmostEqual(detR0, 1.0, self.places)
150
+ # try if rotation matrix works
151
+ self.assertEqual(numpy.all(base == self.lattice.base), True)
152
+ self.lattice.setLatPar(alpha=44, beta=66, gamma=88)
153
+ self.assertNotEqual(numpy.all(base == self.lattice.base), True)
154
+ self.lattice.setLatPar(alpha=60, beta=60, gamma=60)
155
+ self.assertTrue(numpy.allclose(base[0], self.lattice.base[0]))
156
+ self.assertTrue(numpy.allclose(base[1], self.lattice.base[1]))
157
+ self.assertTrue(numpy.allclose(base[2], self.lattice.base[2]))
158
+ # try base checking
159
+ self.assertRaises(LatticeError, self.lattice.setLatBase, [[1, 0, 0], [1, 0, 0], [0, 0, 1]])
160
+ self.assertRaises(LatticeError, self.lattice.setLatBase, [[1, 0, 0], [0, 0, 1], [0, 1, 0]])
161
+ return
162
+
163
+ def test_reciprocal(self):
164
+ """check calculation of reciprocal lattice."""
165
+ r1 = self.lattice.reciprocal()
166
+ self.assertEqual((1, 1, 1, 90, 90, 90), r1.abcABG())
167
+ L2 = Lattice(2, 4, 8, 90, 90, 90)
168
+ r2 = L2.reciprocal()
169
+ self.assertEqual((0.5, 0.25, 0.125, 90, 90, 90), r2.abcABG())
170
+ rr2 = r2.reciprocal()
171
+ self.assertTrue(numpy.array_equal(L2.base, rr2.base))
172
+ return
173
+
174
+ def test_dot(self):
175
+ """check dot product of lattice vectors."""
176
+ L = self.lattice
177
+ L.setLatPar(gamma=120)
178
+ self.assertAlmostEqual(-0.5, L.dot([1, 0, 0], [0, 1, 0]), self.places)
179
+ va5 = numpy.tile([1.0, 0.0, 0.0], (5, 1))
180
+ vb5 = numpy.tile([0.0, 1.0, 0.0], (5, 1))
181
+ self.assertTrue(numpy.array_equal(5 * [-0.5], L.dot(va5, vb5)))
182
+ self.assertTrue(numpy.array_equal(5 * [-0.5], L.dot(va5[0], vb5)))
183
+ self.assertTrue(numpy.array_equal(5 * [-0.5], L.dot(va5, vb5[0])))
184
+ return
185
+
186
+ def test_norm(self):
187
+ """check norm of a lattice vector."""
188
+ self.assertEqual(1, self.lattice.norm([1, 0, 0]))
189
+ u = numpy.array([[3, 4, 0], [1, 1, 1]])
190
+ self.assertTrue(numpy.allclose([5, 3**0.5], self.lattice.norm(u)))
191
+ self.lattice.setLatPar(gamma=120)
192
+ self.assertAlmostEqual(1, self.lattice.norm([1, 1, 0]), self.places)
193
+ return
194
+
195
+ def test_rnorm(self):
196
+ """check norm of a reciprocal vector."""
197
+ L = self.lattice
198
+ L.setLatPar(1, 1.5, 2.3, 80, 95, 115)
199
+ r = L.reciprocal()
200
+ hkl = [0.5, 0.3, 0.2]
201
+ self.assertAlmostEqual(r.norm(hkl), L.rnorm(hkl), self.places)
202
+ hkl5 = numpy.tile(hkl, (5, 1))
203
+ self.assertTrue(numpy.allclose(5 * [r.norm(hkl)], L.rnorm(hkl5)))
204
+ return
205
+
206
+ def test_dist(self):
207
+ """check dist function for distance between lattice points."""
208
+ L = self.lattice
209
+ L.setLatPar(1, 1.5, 2.3, 80, 95, 115)
210
+ u = [0.1, 0.3, 0.7]
211
+ v = [0.3, 0.7, 0.7]
212
+ d0 = numalg.norm(L.cartesian(numpy.array(u) - v))
213
+ self.assertAlmostEqual(d0, L.dist(u, v), self.places)
214
+ self.assertAlmostEqual(d0, L.dist(v, u), self.places)
215
+ u5 = numpy.tile(u, (5, 1))
216
+ v5 = numpy.tile(v, (5, 1))
217
+ self.assertTrue(numpy.allclose(5 * [d0], L.dist(u, v5)))
218
+ self.assertTrue(numpy.allclose(5 * [d0], L.dist(u5, v)))
219
+ self.assertTrue(numpy.allclose(5 * [d0], L.dist(v5, u5)))
220
+ return
221
+
222
+ def test_angle(self):
223
+ """check angle calculation between lattice vectors."""
224
+ from math import acos, degrees
225
+
226
+ L = self.lattice
227
+ L.setLatPar(1, 1.5, 2.3, 80, 95, 115)
228
+ u = [0.1, 0.3, 0.7]
229
+ v = [0.3, 0.7, 0.7]
230
+ uc = L.cartesian(u)
231
+ vc = L.cartesian(v)
232
+ a0 = degrees(acos(numpy.dot(uc, vc) / (numalg.norm(uc) * numalg.norm(vc))))
233
+ self.assertAlmostEqual(a0, L.angle(u, v), self.places)
234
+ self.assertAlmostEqual(a0, L.angle(v, u), self.places)
235
+ u5 = numpy.tile(u, (5, 1))
236
+ v5 = numpy.tile(v, (5, 1))
237
+ self.assertTrue(numpy.allclose(5 * [a0], L.angle(u, v5)))
238
+ self.assertTrue(numpy.allclose(5 * [a0], L.angle(u5, v)))
239
+ self.assertTrue(numpy.allclose(5 * [a0], L.angle(v5, u5)))
240
+ return
241
+
242
+ def test_repr(self):
243
+ """check string representation of this lattice"""
244
+ r = repr(self.lattice)
245
+ self.assertEqual(r, "Lattice()")
246
+ self.lattice.setLatPar(1, 2, 3, 10, 20, 30)
247
+ r = repr(self.lattice)
248
+ r0 = "Lattice(a=1, b=2, c=3, alpha=10, beta=20, gamma=30)"
249
+ self.assertEqual(r, r0)
250
+ base = [[1.0, 1.0, 0.0], [0.0, 2.0, 2.0], [3.0, 0.0, 3.0]]
251
+ self.lattice.setLatBase(base)
252
+ r = repr(self.lattice)
253
+ self.assertEqual(r, "Lattice(base=%r)" % self.lattice.base)
254
+
255
+
256
+ # End of class TestLattice
257
+
258
+ # ----------------------------------------------------------------------------
259
+
260
+ if __name__ == "__main__":
261
+ unittest.main()
@@ -0,0 +1,68 @@
1
+ #!/usr/bin/env python
2
+
3
+ """Unit tests for the loadStructure factory.
4
+ """
5
+
6
+ import unittest
7
+
8
+ import pytest
9
+
10
+ from diffpy.structure import PDFFitStructure, Structure, loadStructure
11
+ from diffpy.structure.structureerrors import StructureFormatError
12
+
13
+
14
+ ##############################################################################
15
+ class TestLoadStructure(unittest.TestCase):
16
+ @pytest.fixture(autouse=True)
17
+ def prepare_fixture(self, datafile):
18
+ self.datafile = datafile
19
+
20
+ def test_xcfg(self):
21
+ """check loading of atomeye xcfg format"""
22
+ f = self.datafile("BubbleRaftShort.xcfg")
23
+ stru = loadStructure(f)
24
+ self.assertTrue(type(stru) is Structure)
25
+ self.assertRaises(StructureFormatError, loadStructure, f, "xyz")
26
+ return
27
+
28
+ def test_discus(self):
29
+ """check loading of discus file format"""
30
+ f = self.datafile("Ni-discus.stru")
31
+ stru = loadStructure(f)
32
+ self.assertTrue(type(stru) is PDFFitStructure)
33
+ return
34
+
35
+ def test_cif(self):
36
+ """check loading of CIF file format"""
37
+ f = self.datafile("PbTe.cif")
38
+ stru = loadStructure(f)
39
+ self.assertTrue(isinstance(stru, Structure))
40
+ self.assertFalse(isinstance(stru, PDFFitStructure))
41
+ return
42
+
43
+ def test_badfile(self):
44
+ """check loading of CIF file format"""
45
+ f = self.datafile("Ni-bad.stru")
46
+ self.assertRaises(StructureFormatError, loadStructure, f)
47
+ return
48
+
49
+ def test_goodkwarg(self):
50
+ """check loading of CIF file and passing of parser keyword argument."""
51
+ f = self.datafile("graphite.cif")
52
+ stru = loadStructure(f, eps=1e-10)
53
+ self.assertEqual(8, len(stru))
54
+ return
55
+
56
+ def test_badkwarg(self):
57
+ """check loading of xyz file format with invalid keyword argument"""
58
+ f = self.datafile("bucky.xyz")
59
+ self.assertRaises(TypeError, loadStructure, f, eps=1e-10)
60
+ return
61
+
62
+
63
+ # End of class TestLoadStructure
64
+
65
+ # ----------------------------------------------------------------------------
66
+
67
+ if __name__ == "__main__":
68
+ unittest.main()
@@ -0,0 +1,77 @@
1
+ #!/usr/bin/env python
2
+ ##############################################################################
3
+ #
4
+ # diffpy.structure Complex Modeling Initiative
5
+ # (c) 2017 Brookhaven Science Associates,
6
+ # Brookhaven National Laboratory.
7
+ # All rights reserved.
8
+ #
9
+ # File coded by: Pavol Juhas
10
+ #
11
+ # See AUTHORS.txt for a list of people who contributed.
12
+ # See LICENSE.txt for license information.
13
+ #
14
+ ##############################################################################
15
+
16
+ """
17
+ Unit tests for imports of old camel-case names.
18
+ """
19
+
20
+
21
+ import importlib
22
+ import sys
23
+ import unittest
24
+ import warnings
25
+
26
+ import diffpy
27
+
28
+ # ----------------------------------------------------------------------------
29
+
30
+
31
+ class TestOldImports(unittest.TestCase):
32
+
33
+ @classmethod
34
+ def setUpClass(cls):
35
+ "Uncache any already-imported old modules."
36
+ for modname in tuple(sys.modules):
37
+ if modname.startswith("diffpy.Structure"):
38
+ del sys.modules[modname] # pragma: no cover
39
+ return
40
+
41
+ def test_00TopImport(self):
42
+ """check import of diffpy.Structure"""
43
+ with warnings.catch_warnings():
44
+ warnings.simplefilter("ignore", category=DeprecationWarning)
45
+ import diffpy.Structure as m0
46
+ self.assertIs(diffpy.structure, m0)
47
+ # second import should raise no warning
48
+ with warnings.catch_warnings():
49
+ warnings.simplefilter("error")
50
+ import diffpy.Structure as m1
51
+ self.assertIs(diffpy.structure, m1)
52
+ return
53
+
54
+ def test_O1SubmoduleImport(self):
55
+ """check import of diffpy.Structure submodules."""
56
+ with warnings.catch_warnings(record=True) as w:
57
+ warnings.simplefilter("always", category=DeprecationWarning)
58
+ import diffpy.Structure.SymmetryUtilities as symutil
59
+
60
+ self.assertIs(DeprecationWarning, w[0].category)
61
+ self.assertIs(diffpy.structure.symmetryutilities, symutil)
62
+ with warnings.catch_warnings(record=True) as w:
63
+ warnings.simplefilter("always", category=DeprecationWarning)
64
+ import diffpy.Structure.Parsers.P_cif as pcif
65
+
66
+ self.assertIs(DeprecationWarning, w[0].category)
67
+ self.assertIs(diffpy.structure.parsers.p_cif, pcif)
68
+ self.assertRaises(ImportError, importlib.import_module, "diffpy.Structure.SSpaceGroups")
69
+ return
70
+
71
+
72
+ # End of class TestOldImports
73
+
74
+ # ----------------------------------------------------------------------------
75
+
76
+ if __name__ == "__main__":
77
+ unittest.main()