Xmipp  v3.23.11-Nereus
symmetry.cpp
Go to the documentation of this file.
1 /*-
2  * SPDX-License-Identifier: BSD-2-Clause
3  *
4  * Copyright (c) 2020 NKI/AVL, Netherlands Cancer Institute
5  *
6  * Redistribution and use in source and binary forms, with or without
7  * modification, are permitted provided that the following conditions are met:
8  *
9  * 1. Redistributions of source code must retain the above copyright notice, this
10  * list of conditions and the following disclaimer
11  * 2. Redistributions in binary form must reproduce the above copyright notice,
12  * this list of conditions and the following disclaimer in the documentation
13  * and/or other materials provided with the distribution.
14  *
15  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
16  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
17  * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
18  * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
19  * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
20  * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
21  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
22  * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
23  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
24  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
25  */
26 
27 #include "cif++/symmetry.hpp"
28 
29 #include <stdexcept>
30 
31 #include "symop_table_data.hpp"
32 
33 namespace cif
34 {
35 
36 // --------------------------------------------------------------------
37 // Unfortunately, clipper has a different numbering scheme than PDB
38 // for rotation numbers. So we created a table to map those.
39 // Perhaps a bit over the top, but hey....
40 
41 // --------------------------------------------------------------------
42 
43 int get_space_group_number(std::string spacegroup)
44 {
45  if (spacegroup == "P 21 21 2 A")
46  spacegroup = "P 21 21 2 (a)";
47  else if (spacegroup.empty())
48  throw std::runtime_error("No spacegroup, cannot continue");
49 
50  int result = 0;
51 
52  const size_t N = kNrOfSpaceGroups;
53  int32_t L = 0, R = static_cast<int32_t>(N - 1);
54  while (L <= R)
55  {
56  int32_t i = (L + R) / 2;
57 
58  int d = spacegroup.compare(kSpaceGroups[i].name);
59 
60  if (d > 0)
61  L = i + 1;
62  else if (d < 0)
63  R = i - 1;
64  else
65  {
66  result = kSpaceGroups[i].nr;
67  break;
68  }
69  }
70 
71  // not found, see if we can find a match based on xHM name
72  if (result == 0)
73  {
74  for (size_t i = 0; i < kNrOfSpaceGroups; ++i)
75  {
76  auto& sp = kSpaceGroups[i];
77  if (sp.xHM == spacegroup)
78  {
79  result = sp.nr;
80  break;
81  }
82  }
83  }
84 
85  if (result == 0)
86  throw std::runtime_error("Spacegroup name " + spacegroup + " was not found in table");
87 
88  return result;
89 }
90 
91 // --------------------------------------------------------------------
92 
93 int get_space_group_number(std::string spacegroup, space_group_name type)
94 {
95  if (spacegroup == "P 21 21 2 A")
96  spacegroup = "P 21 21 2 (a)";
97  else if (spacegroup.empty())
98  throw std::runtime_error("No spacegroup, cannot continue");
99 
100  int result = 0;
101 
102  if (type == space_group_name::full)
103  {
104  const size_t N = kNrOfSpaceGroups;
105  int32_t L = 0, R = static_cast<int32_t>(N - 1);
106  while (L <= R)
107  {
108  int32_t i = (L + R) / 2;
109 
110  int d = spacegroup.compare(kSpaceGroups[i].name);
111 
112  if (d > 0)
113  L = i + 1;
114  else if (d < 0)
115  R = i - 1;
116  else
117  {
118  result = kSpaceGroups[i].nr;
119  break;
120  }
121  }
122  }
123  else if (type == space_group_name::xHM)
124  {
125  for (auto &sg : kSpaceGroups)
126  {
127  if (sg.xHM == spacegroup)
128  {
129  result = sg.nr;
130  break;
131  }
132  }
133  }
134  else
135  {
136  for (auto &sg : kSpaceGroups)
137  {
138  if (sg.Hall == spacegroup)
139  {
140  result = sg.nr;
141  break;
142  }
143  }
144  }
145 
146  // not found, see if we can find a match based on xHM name
147  if (result == 0)
148  throw std::runtime_error("Spacegroup name " + spacegroup + " was not found in table");
149 
150  return result;
151 }
152 
153 }
#define i
doublereal * d
viol type
int get_space_group_number(std::string spacegroup)
Definition: symmetry.cpp:43